-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtractGwasClinvarINFO.py
executable file
·52 lines (40 loc) · 1.77 KB
/
ExtractGwasClinvarINFO.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
import sys
from collections import defaultdict
vcf = sys.argv[1]
vcfout = '.'.join(vcf.split('.')[:-1]) + 'GWAS_SUM.tsv'
traitsout = '.'.join(vcf.split('.')[:-1]) + '.GWAS.tsv'
traits_list = []
with open(vcf) as f, open(vcfout, 'w') as w:
for line in f:
# Header
if line.startswith('##'):
continue
elif line.startswith('#C'):
header = ['CHROM', 'POS', 'ID', 'REF', 'ALT',
'GWASCAT_REPORTED_GENE',
'GWASCAT_TRAIT(pval)', 'GWASCAT_PUBMED_ID']
w.write('\t'.join(header) + '\n')
# GWAS
elif 'GWASCAT_TRAIT' in line: # or 'CLNSIGINCL' in line:
line_splt = line.split('\t')
base = '\t'.join(line_splt[0:5])
ann = dict(map(lambda x: x.split('='), line_splt[7].split(';')))
gene = ','.join(set(ann['GWASCAT_REPORTED_GENE'].split(',')))
trait = ann['GWASCAT_TRAIT'].split(',')
pval = ann['GWASCAT_P_VALUE'].split(',')
[traits_list.append((el[0], el[1])) for el in zip(trait, pval)]
trait_pval = ','.join([el[0] + '=' + el[1] for el in zip(trait, pval)])
w.write( base + '\t' +
gene + '\t' +
trait_pval + '\t' +
ann['GWASCAT_PUBMED_ID'] + '\n')
with open(traitsout, 'w') as w:
trait_combine = defaultdict(list)
for trait, pval in traits_list:
trait_combine[trait].append(pval)
trait_combine_sort = sorted(trait_combine.items(), key=lambda x: len(x[1]), reverse=True)
w.write('TRAIT\tMUTNUMBER\tPVAL\n')
for trait, pval in trait_combine_sort:
w.write(trait + '\t' + str(len(pval)) + '\t' + ','.join(pval) + '\n')
# ClinVar
vcfout = '.'.join(vcf.split('.')[:-1]) + 'ClinVar_SUM.tsv'