iVar

primer_bed.cpp
1 #include <iostream>
2 #include <vector>
3 #include <sstream>
4 #include <fstream>
5
6 #include "primer_bed.h"
7
8 std::string primer::get_name(){
9 return name;
10 }
11
12 std::string primer::get_region(){
13 return region;
14 }
15
16 int primer::get_score(){
17 return score;
18 }
19
20 unsigned int primer::get_start(){
21 return start;
22 }
23
24 unsigned int primer::get_end(){
25 return end;
26 }
27
28 char primer::get_strand(){
29 return strand;
30 }
31
32 int primer::get_length(){
33 return end - start + 1;
34 }
35
36 void primer::set_start(unsigned int s){
37 start = s;
38 }
39
40 void primer::set_end(unsigned int e){
41 end = e;
42 }
43
44 void primer::set_strand(char s){
45 strand = s;
46 }
47
48 void primer::set_region(std::string r){
49 region = r;
50 }
51
52 void primer::set_name(std::string n){
53 name = n;
54 }
55
56 void primer::set_score(int s){
57 score = s;
58 }
59
60 std::vector<primer> populate_from_file(std::string path){
61 std::ifstream data(path);
62 std::string line;
63 std::vector<primer> primers;
64 while(std::getline(data,line)){ // Remove extra lineStream
65 std::stringstream lineStream(line);
66 std::string cell;
67 int ctr = 0;
68 primer p;
69 while(std::getline(lineStream,cell,'\t')){
70 switch(ctr){
71 case 0:
72 p.set_region(cell);
73 break;
74 case 1:
75 p.set_start(std::stoul(cell));
76 break;
77 case 2:
78 p.set_end(std::stoul(cell)-1); // Bed format - End is not 0 based
79 break;
80 case 3:
81 p.set_name(cell);
82 break;
83 case 4:
84 p.set_score(std::stoi(cell));
85 break;
86 case 5:
87 p.set_strand(cell[0]);
88 }
89 ctr++;
90 }
91 primers.push_back(p);
92 }
93 return primers;
94 }
primer
Definition: primer_bed.h:7