-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfastq.cpp
62 lines (54 loc) · 1.52 KB
/
fastq.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
#include "fastq.h"
#include "exceptions.h"
#include "str.h"
#include <fstream>
#include <sstream>
#include <cstring>
#include <string>
using namespace std;
vector<Read> Fastq::read(const char* filePath) {
ifstream input(filePath);
if (!input.is_open()) {
throw FileNotFoundException(filePath);
}
vector<Read> result;
ReaderState next = ID;
unsigned lineCnt = 0;
string line;
ostringstream iss;
Str ident, seq, qual;
while(getline(input, line)) {
/* cout << */ ++lineCnt /* << endl*/ ;
if (!line.empty()) { // skip empty lines
switch (next) {
case ID:
if (line[0] != '@') { // must start with a '@'
throw ReadIllegalDefException(lineCnt);
}
ident = Str(line.c_str() + 1, line.length() - 1);
next = SEQ;
break;
case SEQ:
seq = Str(line);
next = PLUS;
break;
case PLUS:
if (line[0] != '+') { // must be '+'
throw ReadIllegalDefException(lineCnt);
}
next = QUAL;
break;
case QUAL:
qual = Str(line);
next = ID;
result.push_back(Read(ident, seq, qual));
break;
}
}
}
if (next != ID) {
throw ReadIllegalDefException(lineCnt);
}
input.close();
return result;
}