-
Notifications
You must be signed in to change notification settings - Fork 1
/
GffRecord.cpp
72 lines (64 loc) · 1.99 KB
/
GffRecord.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
/*******************************************************************************
+
+ GffRecord.cpp
+
+ Copyright (c) 2017 Genoscope, CEA, CNS, Evry, France
+ Author : Marion Dubarry, [email protected]
+
*******************************************************************************/
#include "GffRecord.h"
using namespace std;
GffRecord::GffRecord(string line, s8 datatype) {
string tmp;
stringstream ss,ss2;
vector<string> tmpV;
ss<< line ;
while(std::getline(ss, tmp, '\t')) {
tmpV.push_back(tmp);
}
_seqname = tmpV[0];
_method = tmpV[1];
_type = tmpV[2];
_start = atoi(tmpV[3].c_str());
_end = atoi(tmpV[4].c_str());
_score = atoi(tmpV[5].c_str());
_strand = tmpV[6];
_phase = tmpV[7];
_attribute = tmpV[8];
prepareAttribute(_attribute);
_color=0;
_datatype = datatype;
}
void GffRecord::prepareAttribute(string& attribute){
//std::replace( attribute.begin(), attribute.end(), '=', ' ');
string delimiter;
size_t pos = 0;
if((pos = attribute.find("Parent=")) != string::npos){
delimiter = "Parent";
s32 start= pos + delimiter.length()+1;
attribute.erase(0, start);
}
else if ((pos = attribute.find("ID=")) != string::npos){
delimiter="ID";
s32 start= pos + delimiter.length()+1;
attribute.erase(0, start);
}
else if ((pos = attribute.find(' ')) != string::npos){
delimiter='=';
s32 start= pos + delimiter.length();
attribute.erase(0, start);
}
//remove all ';' in string
std::replace( attribute.begin(), attribute.end(), ';', ' ');
//clean after if there is still some spaces
if((pos = attribute.find(' ')) != string::npos){
attribute.erase(pos,attribute.length());
}
}
// to print the GffRecord
ostream& operator<<(ostream& ostr, const GffRecord& r) {
ostr << r.getSeqName()<< "\t" << r.getMethod() << "\t";
ostr << r.getType() << "\t" << r.getStart() << "\t" << r.getEnd() << "\t" << r.getScore() << "\t";
ostr << r.getStrand() << "\t" << r.getPhase() << "\t" << r.getAttribute() ;
return ostr;
}