-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathibs_from_ms_output.py
More file actions
32 lines (29 loc) · 856 Bytes
/
ibs_from_ms_output.py
File metadata and controls
32 lines (29 loc) · 856 Bytes
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
import sys
infile=open(sys.argv[1]) ## an ms format file
seq_length=int(sys.argv[2])
lines=infile.readlines() ## read all the lines in the ms infile
infile.close()
lengths=[]
length_out=0
for line in lines:
if line.startswith('positions:'):
line.strip('\n')
seg_sites=line.split(' ')
for i in range(2,len(seg_sites)-1):
length=seq_length*(float(seg_sites[i])-float(seg_sites[i-1])) ## this is calculating the distance between segsites
length_out+=length
if length>=1:
lengths.append(int(length))
lengths.sort()
outfile=open(sys.argv[3],'w') ## a list file
i=1
count=0
curr_length=1
for l in lengths:
if l==curr_length:
count+=1
else:
outfile.write(str(count)+'\t'+str(curr_length)+'\n')
curr_length=l
count=1
outfile.close()