-
Notifications
You must be signed in to change notification settings - Fork 1
/
filter_snp.cpp
118 lines (79 loc) · 2.09 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
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
// 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" << endl << endl <<
"Input: a .snp file. Filters out only pairs with at least coverage M (in both variants). Output to stdout." << endl;
exit(0);
}
int main(int argc, char** argv){
if(argc != 3) help();
string infile = argv[1];
int M = atoi(argv[2]);
ifstream is(infile);
string str;
unsigned int idx=0;
string event_type;
string event_number;
string snp_pos;
string cov0;
string cov1;
string event;
string line1;
string line2;
string line3;
string line4;
while(getline(is, str)){
if(idx%4==0){//first line of call
line1 = str;
std::istringstream iss_bar(str);
std::string token;
getline(iss_bar, token, '|');
token = token.substr(1);
{
std::istringstream iss_underscore(token);
getline(iss_underscore, event_type, '_');
getline(iss_underscore, token, '_');
getline(iss_underscore, token, '_');
getline(iss_underscore, event_number, '_');
}
getline(iss_bar, token, '|');
{
std::istringstream iss_dots(token);
getline(iss_dots, token, ':');
getline(iss_dots, token, ':');
std::istringstream iss_underscore(token);
getline(iss_underscore, snp_pos, '_');
getline(iss_underscore, event, '_');
}
getline(iss_bar, cov0, '|');
}
if(idx%4==1){//DNA of first individual (the reference)
line2 = str;
}
if(idx%4==2){//header second individual
line3 = str;
std::istringstream iss_bar(str);
getline(iss_bar, cov1, '|');
getline(iss_bar, cov1, '|');
getline(iss_bar, cov1, '|');
}
if(idx%4==3){//DNA of second individual (ALT)
line4 = str;
if(atoi(cov0.c_str())>=M and atoi(cov1.c_str())>=M){
cout << line1 << endl << line2 << endl << line3 << endl << line4 << endl;
}
}
idx++;
}
is.close();
}