-
Notifications
You must be signed in to change notification settings - Fork 4
/
make_partition_line.py
executable file
·49 lines (41 loc) · 1.37 KB
/
make_partition_line.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
#!/usr/bin/env python
#
# make_partition_line.py
# python3 update 2022-04-26
'''make_partition_line.py last modified 2022-04-26
make fasta format line to add to an alignment,
indicating where partitions start and stop for easy viewing
appearing like:
>Partitions
-------------XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX------------------XXXXXXXXXXXXXX
make_partition_line.py partitions.txt > partition_line.fasta
'''
import sys
if len(sys.argv) < 2:
sys.exit( __doc__ )
else:
partitions = [] # list of tuples of intervals
partition_file = sys.argv[1]
sys.stderr.write( "# reading partitions from {}\n".format( partition_file ) )
for line in open(partition_file,'r'):
line = line.strip()
if line:
blocks = line.split(",") # split "1:136,137:301,..." into ['1:136', '137:301',...]
for block in blocks:
alignindex = tuple( int(i) for i in block.split(":") ) # split '1:136' into ( 1,136 )
partitions.append(alignindex)
partition_count = len(partitions)
sys.stderr.write( "# found {} partitions\n".format( partition_count ) )
fastastring = ""
for i,part in enumerate(partitions):
if partition_count < 11:
symbol = str(i)
else:
if i % 2: # meaning odd
symbol = "X"
else:
symbol = "-"
partlength = part[1] - part[0] + 1
fastastring += partlength * symbol
sys.stdout.write( ">Partitions_{}\n{}\n".format(partition_count, fastastring) )
#