-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRead.cpp
74 lines (60 loc) · 1.46 KB
/
Read.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
/*
* Read.cpp
*
* Created on: Mar 3, 2010
* Author: marcus
*/
#include "Read.h"
Read::Read(int offs) {
offset = offs;
quality = NULL;
}
Read::Read(string name, string seq, string qual, int offs) {
if(id[0] == '@') {
id = name.substr(1, name.length() - 1);
} else {
id = name;
}
base_id = id.substr(0, id.size() - 2);
sequence = seq;
quality = new Quality(qual, offs);
offset = offs;
}
Read::~Read() {
// cout << "Deleting a read" << endl;
delete quality;
}
istream& operator>>(istream &stream, Read& rd) {
char fastqline[1500];
string id;
string seq;
string qual;
stream.getline(fastqline, (streamsize)1500);
while(fastqline[0] != '@' && !stream.eof()){
stream.getline(fastqline, (streamsize)1500);
}
if(stream.eof()) return stream;
assert(fastqline[0] == '@');
id = string(fastqline).substr(1, string(fastqline).length());
stream.getline(fastqline, (streamsize)1500);
seq = string(fastqline);
stream.getline(fastqline, (streamsize)2);
stream.getline(fastqline, (streamsize)1500);
qual = string(fastqline);
delete rd.quality;
rd.id = id;
rd.sequence = seq;
rd.quality = new Quality(qual, rd.offset);
rd.base_id = id.substr(0, id.size() - 2);
return stream;
}
void Read::write_as_fasta(ostream & stream) {
stream << ">" << id << endl;
stream << sequence << endl;
}
void Read::write_as_fastq(ostream & stream) {
stream << "@" << id << endl;
stream << sequence << endl;
stream << "+" << endl;
stream << quality->quality_str << endl;
}