-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformatMTS.py
More file actions
60 lines (54 loc) · 1.41 KB
/
formatMTS.py
File metadata and controls
60 lines (54 loc) · 1.41 KB
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
56
57
58
59
60
import sys
File=open(sys.argv[1])
out=[]
lastlg=0
for line in File:
line=line.strip('\n').split()
if len(line)>1:
if line[0]=="group":
LG=line[1]
elif line[0][0:2]=="sc":
scf=line[0].split('_')[0]
start=int(line[0].split('_')[1])
stop=int(line[0].split('_')[2])
cm=float(line[1])
bpcode=start+10**8*int(scf[2:])
lgcode=cm+10**5*int(LG[2:])
if lastlg!=lgcode:
out.append([LG, scf, start, stop, cm, 0, bpcode, lgcode] )
lastlg=lgcode
out=sorted(out,key=lambda x: x[6])
for x in range(1, len(out) ):
out[x][5]=out[x-1][5]+1
out=sorted(out,key=lambda x: x[7])
start_bp=out[0][2]
stop_bp=out[0][3]
start_cm=out[0][4]
forward=False
reverse=False
for x in range(1, len(out) ):
#print out[x]
if (forward):
if out[x][5]!=(out[x-1][5]+1):
print ','.join(map(str, [out[x][0], out[x][1], start_bp, out[x][3], start_cm, out[x][4]]))
start_bp=out[x][2]
stop_bp=out[x][3]
start_cm=out[x][4]
foward=False
elif (reverse):
if out[x][5]!=(out[x-1][5]-1):
print ','.join(map(str, [out[x][0], out[x][1], start_bp, out[x][2], start_cm, out[x][4]]))
start_bp=out[x][2]
stop_bp=out[x][3]
start_cm=out[x][4]
foward=False
else:
if out[x][5]==(out[x-1][5]-1):
reverse=True
if out[x][5]==(out[x-1][5]-1):
forward=True
else:
print ','.join(map(str, [out[x][0], out[x][1], start_bp, stop_bp, start_cm, start_cm]))
start_bp=out[x][2]
stop_bp=out[x][3]
start_cm=out[x][4]