-
Notifications
You must be signed in to change notification settings - Fork 2
/
maf_extract_ref_chr.py
executable file
·55 lines (43 loc) · 1.38 KB
/
maf_extract_ref_chr.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
#!/usr/bin/env python
from __future__ import print_function
import argparse
import sys
def main():
parser = argparse.ArgumentParser(description="Extract a reference chromosome from a WGA MAF file")
parser.add_argument('-c', '--chromosome',
required=True,
help="Specify which chromosome to extract")
parser.add_argument('-H', '--header',
help='If specified will print header in output',
default=False,
action='store_true')
args = parser.parse_args()
chromo = args.chromosome
header = args.header
# loop through maf in stdin
block = []
spp_counter = 0
ref_chr = 'none'
for line in sys.stdin:
# process header
if line.startswith('#'):
if header is True:
print(line.replace('\n', ''))
else:
continue
# process block
elif line.startswith('a'):
block.append(line)
elif line.startswith('s'):
if spp_counter == 0:
ref_chr = line.split()[1].split('.')[1]
spp_counter += 1
block.append(line)
# print block
else:
if ref_chr == chromo:
print(''.join(block))
block = []
spp_counter = 0
if __name__ == '__main__':
main()