forked from jclev-uga/SWEEP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFilterDepth.py
64 lines (51 loc) · 1.84 KB
/
FilterDepth.py
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
import sys
import math
import re
def main():
records = open(sys.argv[1], "r")
outfile = open(sys.argv[2], "w")
filter = int(sys.argv[3])
alleles = float(sys.argv[4])
cont = int(sys.argv[5])
for record in records:
record = record.strip()
record = record.split()
if record[0].startswith('#'):
for x in record:
outfile.write("%s\t" % x)
outfile.write('\n')
continue
Info = record[7].split(';')
if Info[0] == "INDEL":
for x in record:
outfile.write("%s\t" % x)
outfile.write('\n')
continue
for i in range(len(Info)):
if Info[i].startswith('DP='):
DP = Info[i].split('=')
Depth = DP[1]
Total = Depth
ratio = alleles
break
if Info[i].startswith('DP4'):
DP = Info[i].split('=')
Depth = DP[1].split(',')
Total = int(Depth[0]) + int(Depth[1]) + int(Depth[2]) + int(Depth[3])
ratio = float(((float(Depth[2]) + float(Depth[3])+1))/((float(Depth[0]) + float(Depth[1])+1)))
break
if Total > filter:
if ratio >= alleles:
if cont == 1:
if p < 0.05:
for x in record:
outfile.write("%s\t" % x)
outfile.write('\n')
elif cont == 0:
for x in record:
outfile.write("%s\t" % x)
outfile.write('\n')
records.close()
outfile.close()
if __name__ == '__main__':
main()