iVar: src/get_masked_amplicons.cpp Source File

iVar

get_masked_amplicons.cpp
1 #include <iostream>
2 #include <fstream>
3 #include <sstream>
4 #include <algorithm>
5
6 #include "primer_bed.h"
7
8 int get_primer_indice(std::vector<primer> p, unsigned int pos){
9 for(std::vector<primer>::iterator it = p.begin(); it != p.end(); ++it) {
10 if(it->get_start() <= pos && it->get_end() >= pos){
11 return it - p.begin();
12 }
13 }
14 return -1;
15 }
16
17 int get_primers_with_mismatches(std::string bed, std::string vpath){
18 std::vector<primer> primers = populate_from_file(bed);
19 std::vector<unsigned int> indices;
20 std::string line, cell;
21 std::ifstream fin(vpath);
22 unsigned int ctr, pos;
23 int ind;
24 std::stringstream line_stream;
25 while (std::getline(fin, line)){
26 line_stream << line;
27 ctr = 0;
28 pos = 0;
29 while(std::getline(line_stream,cell,'\t')){
30 switch(ctr){
31 case 1:
32 if(cell != "POS")
33 pos = stoi(cell);
34 break;
35 default:
36 break;
37 }
38 ctr++;
39 }
40 if(pos == 0){
41 line_stream.clear();
42 continue;
43 }
44 ind = get_primer_indice(primers, pos);
45 if(std::find(indices.begin(), indices.end(), ind) == indices.end() && ind != -1){
46 indices.push_back(ind);
47 }
48 line_stream.clear();
49 }
50 for(std::vector<unsigned int>::iterator it = indices.begin(); it != indices.end(); ++it) {
51 std::cout << *it;
52 if(it != indices.end() - 1)
53 std::cout << " ";
54 }
55 std::cout << std::endl;
56 return 0;
57 }