-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfilter_snp.cpp
81 lines (54 loc) · 1.33 KB
/
filter_snp.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
77
78
79
80
81
// Copyright (c) 2018, Nicola Prezza. All rights reserved.
// Use of this source code is governed
// by a MIT license that can be found in the LICENSE file.
#include <iostream>
#include <fstream>
#include <assert.h>
#include <vector>
#include <unistd.h>
#include <sstream>
#include <set>
#include <cstring>
using namespace std;
void help(){
cout << "filter_snp calls.snp m [M]" << endl << endl <<
"Input: a .snp file. Keep only reads with at least coverage m and at most M. Output to stdout." << endl;
exit(0);
}
int main(int argc, char** argv){
if(argc != 3 and argc != 4) help();
string infile = argv[1];
int m = atoi(argv[2]);
int M = 0;
if(argc==4) M = atoi(argv[3]);
ifstream is(infile);
string str;
unsigned int idx=0;
int cov=0;
string header;
while(getline(is, str)){
if(idx%2==0){//header
header = str;
std::istringstream iss1(str);
std::string token;
getline(iss1, token, '_');//cluster
getline(iss1, token, '_');//id
getline(iss1, token, '_');//right
getline(iss1, token, '_');//cov
{
std::istringstream iss2(token);
getline(iss2, token, ':');//cov
getline(iss2, token, ':');//value
cov = atoi(token.c_str());
}
}else{
if(cov>=m and (M==0 or cov <= M)){
cout << header << endl << str << endl;
}
header="";
cov=0;
}
idx++;
}
is.close();
}