-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIntactEndsIsoform.cpp
80 lines (57 loc) · 1.97 KB
/
IntactEndsIsoform.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
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <map>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
using namespace std;
using namespace boost;
map<string,vector<pair<int,int> > > BuildEndsMapFromFile (ifstream &inf) {
map<string,vector<pair<int,int> > > ends_map;
while(inf){
string strInput;
getline(inf, strInput);
if(strInput.length() > 0){
vector<string> vec;
split(vec, strInput, is_any_of("\t"));
if(vec[2] != "-1"){
ends_map[vec[0]].push_back(pair<int,int>(lexical_cast<int>(vec[2]), lexical_cast<int>(vec[3])));
}
}
}
return ends_map;
}
int main (int argc, char **argv) {
cerr << "IntactEndsIsoform <ends_isoform.txt> <intact-rd_ends.txt>" << endl;
ifstream endsinf(argv[1]);
map<string,vector<pair<int,int> > > ends_map = BuildEndsMapFromFile(endsinf);
endsinf.close();
map<string,vector<pair<int,int> > >::iterator it;
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"));
it = ends_map.find(vec[1]);
if(it != ends_map.end()){
int tss = lexical_cast<int>(vec[3]);
int polya = lexical_cast<int>(vec[4]);
for(vector<pair<int,int> >::iterator it_vec = (it->second).begin(); it_vec != (it->second).end(); ++it_vec){
if(abs((*it_vec).first - tss) < 30 && abs((*it_vec).second - polya) < 30){
cout << strInput << '\t' << (*it_vec).first << '\t' << (*it_vec).second << endl;
break;
}
}
}
}
}
inf.close();
return 0;
}