-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfixFastq.cpp
More file actions
61 lines (58 loc) · 1.51 KB
/
fixFastq.cpp
File metadata and controls
61 lines (58 loc) · 1.51 KB
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
//David van IJzendoorn, 2017
//clang++ -std=c++0x fixFastq.cpp -o fixFastq && ./fixFastq
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <iostream>
#include <regex>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/lexical_cast.hpp>
using namespace std;
int main(int argc, char* argv[]) {
//declare variables
cout << "infile = " << argv[1] << endl << "outfile = " << argv[2] << endl;
ifstream infileFastq(argv[1]); //L4052-N_R2.fastq
ofstream outfileFastq(argv[2]);
string lineFastq;
//loop through file and save good reads
int i = 0;
string identifier;
string sequence;
string sep;
string quality;
while(getline(infileFastq, lineFastq)){
switch(i) {
case 0:
identifier = lineFastq;
break;
case 1:
sequence = lineFastq;
break;
case 2:
sep = lineFastq;
break;
case 3:
quality = lineFastq;
if(regex_match(sequence, regex("[CGATNcgatn]*")) && boost::starts_with(identifier, "@") && boost::starts_with(sep, "+") && quality.length() > 0 && sequence.length() == quality.length()) {
outfileFastq << identifier << endl;
outfileFastq << sequence << endl;
outfileFastq << sep << endl;
outfileFastq << quality << endl;
} else {
break;
}
break;
default:
break;
}
if(i < 3) {
i++;
} else {
i = 0;
}
}
outfileFastq.close();
return 0;
}