forked from hyilai/adna
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
97 lines (68 loc) · 1.63 KB
/
test.cpp
File metadata and controls
97 lines (68 loc) · 1.63 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
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 <cstdlib>
#include <cstdio>
#include <string.h>
#include <vector>
#include <iomanip>
#include <iostream>
#include <fstream>
#include "SmithWaterman.hpp"
// #include <pthread.h>
using namespace std;
class SmithWaterman;
int main (int argc, char** argv) {
if (argc != 3) {
cerr << "Arguments: <fastq_file> <adapter_file>" << endl;
exit(1);
}
ifstream file(argv[1]);
ifstream adpt(argv[2]);
vector<string> trimmed_seq;
vector<string> adapters;
// get the list of adapters
string ad;
while (1) {
if (adpt.peek() == EOF) {
break;
}
//discard first line
getline(adpt, ad);
//get adapter sequence in the second line
getline(adpt, ad);
adapters.push_back(ad);
}
while(1) {
if (file.peek() == EOF) {
break;
}
string line1, line2, line3, line4, trimmed;
// first line of read
// information of the read
getline(file, line1);
// second line of read
// sequence read
getline(file, line2);
for (int i = 0; i < adapters.size(); i++) {
SmithWaterman* sw = new SmithWaterman(line2,adapters[i], 0);
string temp = sw->trim_both_sides();
if (temp.length() < line2.length()) {
trimmed = temp;
}
delete sw;
}
trimmed_seq.push_back(trimmed);
// third line of read
// skip this line
getline(file, line3);
// fourth line of read
// quality control
getline(file, line4);
}
file.close();
string outfile("test_output.txt");
ofstream out(outfile.c_str());
for (int i = 0; i < trimmed_seq.size(); i++) {
out << trimmed_seq[i] << "\n";
}
out.close();
return 0;
}