-
Notifications
You must be signed in to change notification settings - Fork 7
/
parseVCF.py
67 lines (55 loc) · 2.21 KB
/
parseVCF.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
65
66
67
#!/usr/bin/python -u
import os
import argparse
#
if __name__ == '__main__':
#
parser = argparse.ArgumentParser(
description = """
This program will parse the annotations provided by the Ensembl Variant Predictor (VEP)
and create a list of protein consequences which can then be submitted to the
Functional Analysis through Hidden Markov Models (FATHMM) software and server.
""",
epilog = """
Note: in order for this script to work, the VEP must be called using the additional --protein parameter.
""",
)
group = parser.add_argument_group('required arguments')
group.add_argument(
"-i",
dest = "input",
help = "a file containing the VEP annotations to parse",
metavar = "<INPUT>",
default = None,
required = True
)
group.add_argument(
"-o",
dest = "output",
help = "where the protein consequences should be written to",
metavar = "<OUTPUT>",
default = None,
required = True
)
arguments = parser.parse_args()
#
try:
Consequence = {}
for record in open(arguments.input, "r"):
if record.startswith("#") or not record.find("missense_variant") >= 0:
continue
record = record.strip().split("\t")
x = record[10].split("/")
Var = x[0] + record[9] + x[1]
Info = dict([ x.split("=") for x in record[-1].split(";") ])
if not Info.has_key("ENSP"):
continue
if not Consequence.has_key(Info['ENSP']):
Consequence[Info['ENSP']] = []
Consequence[Info['ENSP']].append(Var)
Processed = open(arguments.output, "w")
for id in Consequence:
Processed.write(id + " " + ",".join(set(Consequence[id])) + "\n")
#
except:
raise