Debian Codegraph @

python/cabpoa.pxd

raw
1 from libc.stdint cimport int8_t, uint8_t, int32_t, int64_t, uint32_t, uint64_t
2 from libc.stdio cimport FILE
3
4 cdef extern from "simd_instruction.h":
5 int simd_check()
6
7 cdef extern from "abpoa.h":
8 cdef int ABPOA_GLOBAL_MODE "ABPOA_GLOBAL_MODE"
9 cdef int ABPOA_LOCAL_MODE "ABPOA_LOCAL_MODE"
10 cdef int ABPOA_EXTEND_MODE "ABPOA_EXTEND_MODE"
11
12 # gap mode
13 cdef int ABPOA_LINEAR_GAP "ABPOA_LINEAR_GAP"
14 cdef int ABPOA_AFFINE_GAP "ABPOA_AFFINE_GAP"
15 cdef int ABPOA_CONVEX_GAP "ABPOA_CONVEX_GAP"
16
17 cdef int ABPOA_EXTRA_B "ABPOA_EXTRA_B"
18 cdef float ABPOA_EXTRA_F "ABPOA_EXTRA_F"
19
20 cdef char *ABPOA_CIGAR_STR "ABPOA_CIGAR_STR"
21 cdef int ABPOA_CMATCH "ABPOA_CMATCH"
22 cdef int ABPOA_CINS "ABPOA_CINS"
23 cdef int ABPOA_CDEL "ABPOA_CDEL"
24 cdef int ABPOA_CDIFF "ABPOA_CDIFF"
25 cdef int ABPOA_CSOFT_CLIP "ABPOA_CSOFT_CLIP"
26 cdef int ABPOA_CHARD_CLIP "ABPOA_CHARD_CLIP"
27
28 cdef int ABPOA_SRC_NODE_ID "ABPOA_SRC_NODE_ID"
29 cdef int ABPOA_SINK_NODE_ID "ABPOA_SINK_NODE_ID"
30
31 cdef int ABPOA_OUT_CONS "ABPOA_OUT_CONS"
32 cdef int ABPOA_OUT_MSA "ABPOA_OUT_MSA"
33 cdef int ABPOA_OUT_CONS_MSA "ABPOA_OUT_CONS_MSA"
34 cdef int ABPOA_OUT_GFA "ABPOA_OUT_GFA"
35 cdef int ABPOA_OUT_CONS_GFA "ABPOA_OUT_CONS_GFA"
36
37 cdef int ABPOA_HB "ABPOA_HB"
38 cdef int ABPOA_MF "ABPOA_MF"
39
40 ctypedef struct abpoa_res_t:
41 int n_cigar, m_cigar
42 uint64_t *graph_cigar
43 int node_s, node_e, query_s, query_e # for local and extension mode
44 int n_aln_bases, n_matched_bases
45 uint32_t best_score
46
47
48 ctypedef struct abpoa_para_t:
49 int m
50 int *mat # score matrix
51 char *mat_fn
52 int use_score_matrix
53 int match, max_mat, mismatch, min_mis, gap_open1, gap_open2, gap_ext1, gap_ext2
54 int inf_min
55 int k, w, min_w
56 int wb # 1st part of extra band width
57 float wf # 2nd part of extra band width. w=wb+wf*L (L is sequence length)
58 int zdrop, end_bonus # from minimap2
59 # int simd_flag # available SIMD instruction
60 # alignment mode
61 uint8_t ret_cigar, rev_cigar, out_msa, out_cons, out_gfa, out_fq, use_read_ids, amb_strand # mode: 0: global, 1: local, 2: extend
62 uint8_t sub_aln, use_qv, disable_seeding, progressive_poa
63 char *incr_fn
64 char *out_pog
65 int align_mode, gap_mode, max_n_cons, cons_algrm
66 double min_freq # for diploid data
67 int verbose
68 # int batch_index # index of current file in batch mode (for output header), not used now
69
70
71 ctypedef struct abpoa_node_t:
72 int node_id
73 int in_edge_n, in_edge_m
74 int *in_id
75 int out_edge_n, out_edge_m
76 int *out_id
77 int *out_weight
78 int *read_weight
79 int n_read, m_read, n_span_read
80 uint64_t **read_ids
81 int read_ids_n # for diploid
82 int aligned_node_n, aligned_node_m
83 int *aligned_node_id # mismatch; aligned node will have same rank
84 uint8_t base # 0~m
85
86 ctypedef struct abpoa_graph_t:
87 abpoa_node_t *node
88 int node_n, node_m, index_rank_m
89 int *index_to_node_id
90 int *node_id_to_index
91 int *node_id_to_max_pos_left
92 int *node_id_to_max_pos_right
93 int *node_id_to_max_remain
94 int *node_id_to_msa_rank
95 uint8_t is_topological_sorted, is_called_cons, is_set_msa_rank
96
97 ctypedef struct abpoa_cons_t:
98 int n_cons, n_seq, msa_len
99 int *clu_n_seq
100 int **clu_read_ids
101 int *cons_len
102 int **cons_node_ids
103 uint8_t **cons_base
104 uint8_t **msa_base
105 int **cons_cov
106 int **cons_phred_score;
107
108 ctypedef struct abpoa_str_t:
109 int l, m
110 char *s
111
112 ctypedef struct abpoa_seq_t:
113 int n_seq, m_seq
114 abpoa_str_t *seq
115 abpoa_str_t *name
116 abpoa_str_t *comment
117 abpoa_str_t *qual
118 uint8_t *is_rc
119
120 ctypedef struct abpoa_simd_matrix_t:
121 pass
122
123 ctypedef struct abpoa_t:
124 abpoa_graph_t *abg
125 abpoa_seq_t *abs
126 abpoa_simd_matrix_t *abm
127 abpoa_cons_t *abc
128
129 # init for abpoa parameters
130 abpoa_para_t *abpoa_init_para()
131 void abpoa_set_mat_from_file(abpoa_para_t *abpt, char *mtx_fn)
132 void abpoa_post_set_para(abpoa_para_t *abpt)
133 void abpoa_free_para(abpoa_para_t *abpt)
134
135
136 # init for alignment
137 abpoa_t *abpoa_init()
138 void abpoa_free(abpoa_t *ab)
139
140 # do msa for a set of input sequences
141 int abpoa_msa(abpoa_t *ab, abpoa_para_t *abpt, int n_seqs, char **seq_names, int *seq_lens, uint8_t **seqs, int ** qual_weights, FILE *out_fp)
142 void abpoa_clean_msa_cons(abpoa_t *ab)
143 int abpoa_msa1(abpoa_t *ab, abpoa_para_t *abpt, char *read_fn, FILE *out_fp)
144
145 # clean alignment graph
146 void abpoa_reset(abpoa_t *ab, abpoa_para_t *abpt, int qlen)
147
148 # restore graph from GFA/MSA file
149 abpoa_t *abpoa_restore_graph(abpoa_t *ab, abpoa_para_t *abpt)
150
151 # align a sequence to a graph
152 int abpoa_align_sequence_to_graph(abpoa_t *ab, abpoa_para_t *abpt, uint8_t *query, int qlen, abpoa_res_t *res)
153
154 # align to sub-graph
155 void abpoa_subgraph_nodes(abpoa_t *ab, abpoa_para_t *abpt, int inc_beg, int inc_end, int *exc_beg, int *exc_end)
156 int abpoa_align_sequence_to_subgraph(abpoa_t *ab, abpoa_para_t *abpt, int beg_node_id, int end_node_id, uint8_t *query, int qlen, abpoa_res_t *res)
157
158 # add an alignment to a graph
159 int abpoa_add_graph_node(abpoa_graph_t *abg, uint8_t base)
160 void abpoa_add_graph_edge(abpoa_graph_t *abg, int from_id, int to_id, int check_edge, int w, uint8_t add_read_id, uint8_t add_read_weight, int read_id, int read_ids_n, int tot_read_n)
161 int abpoa_add_graph_alignment(abpoa_t *ab, abpoa_para_t *abpt, uint8_t *query, int *weight, int qlen, int *qpos_to_node_id, abpoa_res_t res, int read_id, int tot_read_n, int inc_both_ends)
162 int abpoa_add_subgraph_alignment(abpoa_t *ab, abpoa_para_t *abpt, int beg_node_id, int end_node_id, uint8_t *query, int *weight, int qlen, int *qpos_to_node_id, abpoa_res_t res, int read_id, int tot_read_n, int inc_both_ends)
163
164 void abpoa_BFS_set_node_index(abpoa_graph_t *abg, int src_id, int sink_id)
165 void abpoa_BFS_set_node_remain(abpoa_graph_t *abg, int src_id, int sink_id)
166 void abpoa_topological_sort(abpoa_graph_t *abg, abpoa_para_t *abpt)
167
168 # generate consensus sequence from graph
169 # para:
170 # out_fp: consensus sequence output in FASTA format, set as NULL to disable
171 void abpoa_generate_consensus(abpoa_t *ab, abpoa_para_t *abpt)
172 void abpoa_output_fx_consensus(abpoa_t *ab, abpoa_para_t *abpt, FILE *out_fp)
173
174
175 # generate column multiple sequence alignment from graph
176 void abpoa_generate_rc_msa(abpoa_t *ab, abpoa_para_t *abpt)
177 void abpoa_output_rc_msa(abpoa_t *ab, abpoa_para_t *abpt, FILE *out_fp)
178
179 # generate full graph in GFA format
180 void abpoa_generate_gfa(abpoa_t *ab, abpoa_para_t *abpt, FILE *out_fp)
181
182 # output to out_fp
183 void abpoa_output(abpoa_t *ab, abpoa_para_t *abpt, FILE *out_fp)
184
185 # generate DOT graph plot
186 void abpoa_dump_pog(abpoa_t *ab, abpoa_para_t *abpt)