forked from sequencing/NxTrim
/
mergeReads.cpp
executable file
·76 lines (64 loc) · 2.05 KB
/
mergeReads.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
75
76
#include "version.h"
#include "githash.h"
#include "fastqlib.h"
#include <boost/program_options.hpp>
namespace po = boost::program_options;
using namespace std;
string percent(int num,int den) {
char buffer[100];
sprintf(buffer,"%d / %d\t( %.2f %% )\t",num,den,100. * float(num)/float(den));
return(buffer);
}
int checkParameters(int argc,char **argv,po::variables_map & vm) {
po::options_description desc("Allowed options");
desc.add_options()
("help,h", "produce help message")
("r1,1", po::value<string>(), "read 1 in fastq format (gzip allowed)")
("r2,2", po::value<string>(), "read 2 in fastq format (gzip allowed)")
("output-prefix,O", po::value<string>(), "output prefix")
("rc", "reverse-complement reads");
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
if (vm.count("help") || argc==1) {
cout << desc << "\n";
exit(1);
}
if (!vm.count("r1") || !vm.count("r2") || !vm.count("output-prefix")) {
cout << "Missing input!"<<endl;
exit(1);
}
return(0);
}
int main(int argc,char **argv) {
cout << "\nmergeReads "<<VERSION<<" "<<HASH<<"\nSimple utility for creating an interleaved fastq file from two separate R1/R2 files."<<endl<<endl;
po::variables_map opt;
checkParameters(argc,argv,opt);
string r1 = opt["r1"].as<string>();
string r2 = opt["r2"].as<string>();
string prefix = opt["output-prefix"].as<string>();
bool rc = opt.count("rc");
cout << "Merging:\nR1:\t" <<r1<<"\nR2:\t"<<r2<<endl;
cout << "Output: " << prefix <<".fastq.gz"<<endl;
if(rc)
cout << "Reads will be reverse-complemented."<<endl;
pairReader infile(r1,r2);
fastqWriter outfile(prefix+".fastq.gz");
readPair p;
int npass=0;
int nread=0;
while(infile.getPair(p)) {
if(!p.filtered) {
if(rc) {
p.rc();
outfile.write(p);
}
else outfile.write(p);
npass++;
}
nread++;
if(nread%10000==0)
cout << "READ PAIR "<<nread<<endl;
}
cout << percent(npass,nread) << "reads passed chastity/purity filters."<<endl;
return(0);
}