forked from OpenGenomics/vcf-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter_vcf.py
executable file
·33 lines (28 loc) · 1.17 KB
/
filter_vcf.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
#!/usr/bin/env python
import argparse
import vcf
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--tumor", default="TUMOR")
parser.add_argument("--normal", default="NORMAL")
parser.add_argument("--no-ad", action="store_true")
parser.add_argument("--cutoff", type=int, default=None)
parser.add_argument("vcf")
parser.add_argument("out")
args = parser.parse_args()
vcf_reader = vcf.Reader(open(args.vcf, 'r'))
vcf_writer = vcf.Writer(open(args.out, 'w'), vcf_reader)
for record in vcf_reader:
keep = True
if args.cutoff is not None:
for call in record.samples:
if call.sample == args.tumor and args.no_ad == False:
for n, d in call.data._asdict().items():
if n == "AD" and int(d[1]) < args.cutoff:
keep = False
elif call.sample == args.tumor and args.no_ad == True:
for n, d in record.INFO.items():
if n == "T_DP" and int(d) < args.cutoff:
keep = False
if keep:
vcf_writer.write_record(record)