-
Notifications
You must be signed in to change notification settings - Fork 2
/
maf_windows.py
executable file
·50 lines (41 loc) · 1.45 KB
/
maf_windows.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
#!/usr/bin/env python
from __future__ import print_function
import sys
import argparse
def main():
# arguments
parser = argparse.ArgumentParser()
parser.add_argument('-s', '--species', help='Species coordinates to use, currently reference only', required=True)
parser.add_argument('-r', '--region', help='Region to extract in form chr:start-stop', required=True)
args = parser.parse_args()
# variables
spp = args.species
region = args.region.replace('-', ':').split(':')
region = [region[0], int(region[1]), int(region[2])]
# process piped maf
align_block = []
printable = False
for line in sys.stdin:
# print header
if line.startswith('#'):
print(line.rstrip())
# write old block and store new
elif line.startswith('a'):
if printable:
print(''.join(align_block))
align_block = [line]
printable = False
elif line.startswith('s'):
species = line.split()[1].split('.')[0]
chromo = line.split()[1].split('.')[1]
# if reference spp and chromo
if spp == species and chromo == region[0]:
pos = int(line.split()[2])
if region[1] <= pos < region[2]:
printable = True
align_block.append(line)
# write last block if in region
if printable:
print(''.join(align_block))
if __name__ == '__main__':
main()