-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfix-vcf.py
More file actions
executable file
·41 lines (38 loc) · 1.53 KB
/
fix-vcf.py
File metadata and controls
executable file
·41 lines (38 loc) · 1.53 KB
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
#!/usr/bin/env python
#=========================================================================
# This is OPEN SOURCE SOFTWARE governed by the Gnu General Public
# License (GPL) version 3, as described at www.opensource.org.
#=========================================================================
from __future__ import (absolute_import, division, print_function,
unicode_literals, generators, nested_scopes, with_statement)
from builtins import (bytes, dict, int, list, object, range, str, ascii,
chr, hex, input, next, oct, open, pow, round, super, filter, map, zip)
# The above imports should allow this program to run in both Python 2 and
# Python 3. You might need to update your version of module "future".
import sys
import ProgramName
import gzip
#=========================================================================
# main()
#=========================================================================
if(len(sys.argv)!=2):
exit(ProgramName.get()+" <in.vcf.gz>\n")
(infile,)=sys.argv[1:]
variants={}
for line in gzip.open(infile):
line=line.decode("utf-8").rstrip()
if(len(line)>0 and line[0]=="#"):
print(line)
continue
fields=line.split("\t")
if(len(fields)>=9):
if(len(fields[0])<3 or fields[0][:3]!="chr"):
fields[0]="chr"+fields[0]
if(fields[2]=="."): fields[2]=fields[0]+"@"+fields[1]
line=""
for field in fields[:len(fields)-1]: line+=field+"\t"
line+=fields[len(fields)-1]
print(line)
else:
print(line)
continue