-
Notifications
You must be signed in to change notification settings - Fork 3
/
fixTrackLabels.py
executable file
·52 lines (41 loc) · 1.22 KB
/
fixTrackLabels.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
#!/usr/bin/env python3
import sys
import os
def help():
print('''
Usage:
------------
fixTrackLabels.py -track <file> -karyotype <file>
Description:
------------
Replaces track labels with integer IDs found in karyotype file.
Example:
------------
karyotype file:
chr - 0 scaffold00001_v1.0 0 1291680 0
track file:
scaffold00001_v1.0 0 99999 63.2241
new track file:
0 0 99999 63.2241
''', file=sys.stderr)
sys.exit()
# output help information if missing command line arguments
args = sys.argv
if not '-track' in args and not '-karyotype' in args:
help()
# read command line arguments
trackFl = args[args.index('-track') +1]
karyotypeFl = args[args.index('-karyotype') +1]
# read karyotype file and create map of old identifier to new identifier
_map = {}
with open(karyotypeFl, 'r') as inFl:
for line in inFl:
_line = line.strip().split()
_map[_line[3]] = _line[2]
# for each line in the track file, modify accordingly and output new
# line
with open(trackFl, 'r') as inFl:
for line in inFl:
_line = line.strip().split()
_line[0] = _map[_line[0]]
print('\t'.join(_line))