-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter_edit.cc
118 lines (91 loc) · 3.12 KB
/
filter_edit.cc
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <map>
#include <utility>
#include <vector>
#include <iostream>
#include <functional>
#include <algorithm>
#include <limits>
#include <iostream>
#include <fstream>
#include <cassert>
#include <boost/bind.hpp>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <utility>
#include <sstream>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/device/file.hpp>
#include <cctype>
#include <isbinary.hpp>
using namespace std;
using namespace boost;
using namespace boost::iostreams;
void read_file (const char * file, char * outfile, int filter);
int main(int argc, char ** argv)
{
int argn = 1;
const char * file = argv[argn++];
char * outfile = argv[argn++];//for novel
const int filter = atoi(argv[argn++]);
read_file(file, outfile, filter);
}
template<typename streamtype>
void printout( streamtype & in, char * outfile, int filter)
{
int nplus, nminus;
string temp, pdist, mdist, mfirst, mlast, chromo, pfirst, plast, pin, min;
filtering_ostream outstream;
outstream.push(gzip_compressor());
outstream.push(file_sink(outfile,ios_base::out|ios_base::binary));
getline(in, temp);
int maxdist;
string na = ("NA");
maxdist = 1000;
outstream << "chromo" << "\t" << "nplus" << "\t" << "nminus" << "\t" << "pfirst" << "\t" << "plast" << "\t" << "pdist" << "\t" << "pin" << "\t" << "mfirst" << "\t" << "mlast" << "\t" << "mdist" << "\t" << "min" << endl;
while(! in.eof() )
{
int pdisttemp, mdisttemp, pintemp, mintemp;
pdisttemp = -1;
mdisttemp = -1;
pintemp = -1;
mintemp = -1;
in >> chromo >> nplus >> nminus >> pfirst >> plast >> pdist >> pin >> mfirst >> mlast >> mdist >> min >> ws;
// cout << chromo << "\t" << nplus << "\t" << nminus << "\t" << pfirst << "\t" << plast << "\t" << pdist << "\t" << pin << "\t" << mfirst << "\t" << mlast << "\t" << mdist << "\t" << min << endl;
//first check to see if pdist and mdist are NA or values
if(pdist.compare(na) != 0) {//not the same
pdisttemp = atoi(pdist.c_str());
}
if(mdist.compare(na) != 0) {//not the same
mdisttemp = atoi(mdist.c_str());
}
if(pin.compare(na) != 0) {//not the same
pintemp = atoi(pin.c_str());
}
if(min.compare(na) != 0) {//not the same
mintemp = atoi(min.c_str());
}
if( (nplus >= filter ) and (nminus >= filter)) // first filter on required number of reads
{
if((pdisttemp >= maxdist) and (mdisttemp >= maxdist) and (pintemp == 0) and (mintemp == 0)) {
outstream << chromo << "\t" << nplus << "\t" << nminus << "\t" << pfirst << "\t" << plast << "\t" << pdist << "\t" << pin << "\t" << mfirst << "\t" << mlast << "\t" << mdist << "\t" << min << endl;
}
}
}
}
void read_file (const char * file, char * outfile, int filter)
{
if( isbinary(file) )
{
filtering_istream in;
in.push(gzip_decompressor());
in.push(file_source(file,ios_base::in|ios_base::binary));
printout(in,outfile,filter);
}
else
{
ifstream in(file);
printout(in,outfile, filter);
}
}