-
Notifications
You must be signed in to change notification settings - Fork 0
/
crg.variants.filter.py
executable file
·40 lines (30 loc) · 1.1 KB
/
crg.variants.filter.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
#!/bin/env python
# reports variants only in a gene panel using csv report on rare variants as input
import csv
import sys
import re
original_report = sys.argv[1]
panel_report = original_report.replace("csv","panel.csv")
gene_panel_file_name = sys.args[2]
with open(gene_panel_file_name,'rb') as f_gene_panel:
genes = f_gene_panel.readlines()
f_gene_panel.close()
genes = [x.strip() for x in genes]
with open(original_report,'rb') as f_original_report:
header_line = f_original_report.readline().strip().replace('"','')
header = header_line.split(',')
f_original_report.close()
with open(original_report,'rb') as f_original_report:
reader = csv.DictReader(f_original_report)
with open(panel_report,'w') as f_panel_report:
f_panel_report.write('"'+'","'.join(header)+'"')
for row in reader:
if (row['Gene'] in genes):
row['UCSC_Link'] = 'UCSC_Link' #a bug with quotes
values = []
for column in header:
values.append(row[column])
f_panel_report.write('"'+'","'.join(values)+'"')
f_panel_report.write('\n')
f_original_report.close()
f_panel_report.close()