-
Notifications
You must be signed in to change notification settings - Fork 1
/
GPDToBEDLR.cpp
97 lines (76 loc) · 2.38 KB
/
GPDToBEDLR.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
97
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#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;
struct GPD {
string gname;
string tname;
string chro;
string strand;
int start;
int end;
//int cstart;
//int cend;
int nblock;
vector<int> vec_exon_start;
vector<int> vec_exon_end;
};
void BuildGPDFromString (string &str, GPD &gpd) {
vector<string> vec_temp;
boost::split(vec_temp, str, boost::is_any_of("\t"));
gpd.gname = vec_temp[0];
gpd.tname = vec_temp[1];
int L = vec_temp[2].length();
gpd.chro = vec_temp[2];
gpd.strand = vec_temp[3];
gpd.start = lexical_cast<int>(vec_temp[4]);
gpd.end = lexical_cast<int>(vec_temp[5]);
//gpd.cstart = lexical_cast<int>(vec_temp[6]);
//gpd.cend = lexical_cast<int>(vec_temp[7]);
gpd.nblock = lexical_cast<int>(vec_temp[8]);
vector<string> vec1;
boost::split(vec1, vec_temp[9], boost::is_any_of(","));
for(int i = 0; i < vec1.size() - 1; ++i) (gpd.vec_exon_start).push_back(lexical_cast<int>(vec1[i]));
vector<string> vec2;
boost::split(vec2, vec_temp[10], boost::is_any_of(","));
for(int i = 0; i < vec2.size() - 1; ++i) (gpd.vec_exon_end).push_back(lexical_cast<int>(vec2[i]));
}
void ChangeToBEDExon (GPD gpd) {
if(gpd.strand == "+"){
for(int i = 0; i < gpd.nblock; ++i){
int left = gpd.vec_exon_start[i] - 200 * (i == 0);
if(left < 1) left = 1;
int right = gpd.vec_exon_end[i];
cout << gpd.chro << '\t' << left << '\t' << right << "\t.\t0\t" << gpd.strand << endl;
}
}
else{
for(int i = 0; i < gpd.nblock; ++i){
int left = gpd.vec_exon_start[i];
int right = gpd.vec_exon_end[i] + 200 * (i == gpd.nblock - 1);
cout << gpd.chro << '\t' << left << '\t' << right << "\t.\t0\t" << gpd.strand << endl;
}
}
}
int main (int argc, char **argv) {
ifstream inf(argv[1]);
while(inf){
string strInput;
getline(inf, strInput);
if(strInput.length() > 0){
GPD gpd;
BuildGPDFromString(strInput, gpd);
ChangeToBEDExon(gpd);
}
}
inf.close();
return 0;
}