Debian Codegraph @

sub_example.c

raw
1 /* sub_example.c libabpoa usage example
2 To compile:
3 gcc -g sub_example.c -I ./include -L ./lib -labpoa -lz -lm -o sub_example
4 or:
5 gcc -g sub_example.c -I ./include ./lib/libabpoa.a -lz -lm -o sub_example
6 */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <stdint.h>
11 #include "include/abpoa.h"
12
13 // AaCcGgTtNn ... ==> 0,1,2,3,4 ...
14 // BbDdEeFf ... ==> 5,6,7,8 ...
15 unsigned char _char26_table[256] = {
16 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
17 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 26, 26, 26, 26, 26,
18 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
19 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
20 26, 0, 5, 1, 6, 7, 8, 2, 9, 10, 11, 12, 13, 14, 4, 15,
21 16, 17, 18, 19, 3, 20, 21, 22, 23, 24, 25, 26, 26, 26, 26, 26,
22 26, 0, 5, 1, 6, 7, 8, 2, 9, 10, 11, 12, 13, 14, 4, 15,
23 16, 17, 18, 19, 3, 20, 21, 22, 23, 24, 25, 26, 26, 26, 26, 26,
24 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
25 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
26 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
27 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
28 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
29 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
30 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
31 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26
32 };
33
34 int main(void) {
35 int i, j, n_seqs = 5;
36 char seqs[100][1000] = {
37 // 0 1 2 3
38 // 23456789012345678901234567890123
39 "CGTCAATCTATCGAAGCATACGCGGGCAGAGC",
40 "CCACGTCAATCTATCGAAGCATACGCGGCAGC",
41 "AATCTATCGAAGCATACG",
42 "CAATGCTAGTCGAAGCAGCTGCGGCAG",
43 "CAATGCTAGTCGAAGCAGCTGCGGCAG",
44 "CGTCAATCTATCGAAGCATTCTACGCGGCAGAGC",
45 "CGTCAATCTAGAAGCATACGCGGCAAGAGC",
46 "CGTCAATCTATCGGTAAAGCATACGCTCTGTAGC",
47 "CGTCAATCTATCTTCAAGCATACGCGGCAGAGC",
48 "CGTCAATGGATCGAGTACGCGGCAGAGC",
49 "CGTCAATCTAATCGAAGCATACGCGGCAGAGC"
50 };
51
52 int beg_end_id[100][2] = {
53 {0, 1},
54 {2, 33},
55 {6, 23},
56 {5, 30},
57 {5, 30},
58 {0, 1},
59 {0, 1},
60 {0, 1},
61 {0, 1},
62 {0, 1},
63 {0, 1},
64 //{2, 52},
65 //{2, 52},
66 //{2, 52},
67 //{2, 52},
68 //{2, 52},
69 //{2, 52},
70 //{2, 52},
71 //{2, 52},
72 //{2, 52}
73 };
74
75 // initialize variables
76 abpoa_t *ab = abpoa_init();
77 abpoa_para_t *abpt = abpoa_init_para();
78
79 // alignment parameters
80 // abpt->align_mode = 0; // 0:global 1:local, 2:extension
81 // abpt->match = 2; // match score
82 // abpt->mismatch = 4; // mismatch penalty
83 // abpt->gap_mode = ABPOA_CONVEX_GAP; // gap penalty mode
84 // abpt->gap_open1 = 4; // gap open penalty #1
85 // abpt->gap_ext1 = 2; // gap extension penalty #1
86 // abpt->gap_open2 = 24; // gap open penalty #2
87 // abpt->gap_ext2 = 1; // gap extension penalty #2
88 // gap_penalty = min{gap_open1 + gap_len * gap_ext1, gap_open2 + gap_len * gap_ext2}
89 // abpt->bw = 10; // extra band used in adaptive banded DP
90 // abpt->bf = 0.01;
91
92 // output options
93 abpt->out_msa = 1; // generate Row-Column multiple sequence alignment(RC-MSA), set 0 to disable
94 abpt->out_cons = 1; // generate consensus sequence, set 0 to disable
95 abpt->cons_algrm = ABPOA_MF; // most frequent base
96 abpt->inc_path_score = 1;
97 abpt->sub_aln = 1;
98 // abpt->max_n_cons = 2;
99
100 abpoa_post_set_para(abpt);
101
102 // collect sequence length, trasform ACGT to 0123
103 int *seq_lens = (int*)malloc(sizeof(int) * n_seqs);
104 uint8_t **bseqs = (uint8_t**)malloc(sizeof(uint8_t*) * n_seqs);
105 for (i = 0; i < n_seqs; ++i) {
106 seq_lens[i] = strlen(seqs[i]);
107 bseqs[i] = (uint8_t*)malloc(sizeof(uint8_t) * seq_lens[i]);
108 for (j = 0; j < seq_lens[i]; ++j)
109 bseqs[i][j] = _char26_table[(int)seqs[i][j]];
110 }
111
112 // perform abpoa-msa
113 ab->abs->n_seq = n_seqs;
114 abpoa_res_t res;
115 for (i = 0; i < n_seqs; ++i) {
116 res.graph_cigar = 0, res.n_cigar = 0;
117 int exc_beg, exc_end;
118 if (i != 0) abpoa_subgraph_nodes(ab, abpt, beg_end_id[i][0], beg_end_id[i][1], &exc_beg, &exc_end);
119 else exc_beg = 0, exc_end = 1;
120 fprintf(stderr, "i: %d, beg: %d, end: %d\n", i, exc_beg, exc_end);
121 abpoa_align_sequence_to_subgraph(ab, abpt, exc_beg, exc_end, bseqs[i], seq_lens[i], &res);
122 abpoa_add_subgraph_alignment(ab, abpt, exc_beg, exc_end, bseqs[i], NULL, seq_lens[i], NULL, res, i, n_seqs, 0);
123 if (res.n_cigar) free(res.graph_cigar);
124 }
125
126 abpoa_output(ab, abpt, stdout);
127
128 /* generate DOT partial order graph plot */
129 abpt->out_pog = strdup("sub_example.png"); // dump parital order graph to file
130 if (abpt->out_pog != NULL) abpoa_dump_pog(ab, abpt);
131 for (i = 0; i < n_seqs; ++i) free(bseqs[i]); free(bseqs); free(seq_lens);
132 abpoa_free(ab); abpoa_free_para(abpt);
133 return 0;
134 }