-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathMedicago_VCF_recode.py
More file actions
46 lines (36 loc) · 940 Bytes
/
Medicago_VCF_recode.py
File metadata and controls
46 lines (36 loc) · 940 Bytes
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
#!/usr/bin/env python
# extract data from VCF file
# VCF.py
"""
python VCF.py VCF_file_name > output
"""
from sys import argv, stdout, stderr
def _util(line, w=stdout):
items = line.rstrip().split("\t")
out = [items[1], items[2]]
for i in items[9:]:
temp = i.split(":")[0]
assert len(temp) == 3
out.append(temp[0])
out.append(temp[-1])
w.write("\t".join(out) + "\n")
w.flush()
return
def main():
with open(argv[1]) as f:
for line in f:
if not line.startswith("#"):
try:
_util(line)
except Exception as e:
stderr.write(line)
exit(1)
break
for line in f:
try:
_util(line)
except Exception as e:
stderr.write(line)
exit(1)
if __name__ == '__main__':
main()