-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathselectSample.py
More file actions
29 lines (27 loc) · 846 Bytes
/
selectSample.py
File metadata and controls
29 lines (27 loc) · 846 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
import argparse
import gzip
parser = argparse.ArgumentParser(description='Filter/edit sample name in VCF.')
parser.add_argument('-v', help='the VCF file', required=True)
parser.add_argument('-s', help='the sample', required=True)
args = parser.parse_args()
sampcol = -1
vcff = gzip.open(args.v, 'r')
for line in vcff:
line = line.rstrip()
# write headers
if line[:2] == '##':
if '##SAMPLE=' in line:
continue
print line
continue
line = line.split('\t')
if '#CHROM'in line[0]:
print '##SAMPLE=<ID={}>'.format(args.s)
for ii in range(len(line)):
if line[ii] == args.s:
sampcol = ii
if sampcol == -1:
sampcol = 9
line[sampcol] = args.s
print '\t'.join(line[:8]) + '\t' + line[8] + '\t' + line[sampcol]
vcff.close()