Debian Codegraph @

tests/test_amplicon_search.cpp

raw
1 #include <iostream>
2 #include <vector>
3
4 #include "../src/interval_tree.h"
5 #include "../src/primer_bed.h"
6 #include "../src/trim_primer_quality.h"
7
8 int test_amplicon_search(std::string bam_file, std::string bed_file,
9 std::string pair_info_file, int32_t primer_offset,
10 bool expected[]) {
11 std::vector<primer> primers;
12 IntervalTree amplicons;
13 primers = populate_from_file(bed_file, primer_offset);
14 std::cout << "Total Number of primers: " << primers.size() << std::endl;
15 amplicons = populate_amplicons(pair_info_file, primers);
16 samFile *in = hts_open(bam_file.c_str(), "r");
17 sam_hdr_t *hdr = sam_hdr_read(in);
18 bam1_t *aln = bam_init1();
19 int cnt = 0;
20 int res = 0;
21 while (sam_read1(in, hdr, aln) >= 0) {
22 res = amplicon_filter(amplicons, aln);
23 if (res != expected[cnt]) {
24 std::cout << "Amplicon filter output did not match " << bam_get_qname(aln)
25 << " Expected " << expected[cnt] << " "
26 << "Got " << res << std::endl;
27 std::cout << "Read intervals: " << aln->core.pos << ":" << bam_endpos(aln)
28 << std::endl;
29 return -1;
30 }
31 cnt++;
32 }
33 return 0;
34 }
35
36 int main() {
37 int success;
38 std::string bam = "../data/test_amplicon.sorted.bam";
39 std::string pair_indice = "../data/pair_info_2.tsv";
40 int32_t primer_offset = 0;
41 std::string bed = "../data/test_isize.bed";
42 std::string prefix = "/tmp/data/trim_amplicon";
43 std::string bam_out = "/tmp/trim_amplicon.bam";
44
45 IntervalTree amplicons;
46 bool expected[8] = {true, false, true, false, true, false, true, false};
47 success =
48 test_amplicon_search(bam, bed, pair_indice, primer_offset, expected);
49 amplicons.inOrder();
50 return success;
51 }