-
Notifications
You must be signed in to change notification settings - Fork 0
/
RetainReads.cpp
96 lines (66 loc) · 2.02 KB
/
RetainReads.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>
#include <map>
#include <algorithm>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
using namespace std;
using namespace boost;
struct ISOFORM {
int tss;
int polya;
string tname;
string strand;
};
map<string,vector<ISOFORM> > BuildIsoformMap (ifstream &inf) {
map<string,vector<ISOFORM> > isoform_map;
while(inf){
string strInput;
getline(inf, strInput);
if(strInput.length() > 0){
vector<string> vec;
split(vec, strInput, is_any_of("\t"));
ISOFORM isoform;
isoform.tname = vec[1];
isoform.strand = vec[2];
isoform.tss = lexical_cast<int>(vec[4]);
isoform.polya = lexical_cast<int>(vec[6]);
isoform_map[isoform.tname].push_back(isoform);
}
}
return isoform_map;
}
int main (int argc, char **argv) {
ifstream isoforminf(argv[1]);
map<string,vector<ISOFORM> > isoform_map = BuildIsoformMap(isoforminf);
map<string,vector<ISOFORM> >::iterator it;
isoforminf.close();
ifstream inf(argv[2]);
while(inf){
string strInput;
getline(inf, strInput);
if(strInput.length() > 0){
vector<string> vec;
split(vec, strInput, is_any_of("\t"));
string tname = vec[2];
string strand = vec[3];
int tss = lexical_cast<int>(vec[5]);
int polya = lexical_cast<int>(vec[7]);
it = isoform_map.find(tname);
if(it != isoform_map.end()){
for(int i = 0; i < (it->second).size(); ++i){
if((it->second)[i].strand == strand && (it->second)[i].tss == tss && (it->second)[i].polya == polya){
cout << strInput << endl;
break;
}
}
}
}
}
inf.close();
return 0;
}