-
Notifications
You must be signed in to change notification settings - Fork 0
/
num_breakpoints.py
53 lines (45 loc) · 1017 Bytes
/
num_breakpoints.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
53
import string
import sys
import re
def GetSequence(filename):
f=open (filename, "r")
genome=''
while True:
s=f.readline()
try:
if len(s)>0:
s=s.strip()
sequences=re.split('[( )]',s)
#genome=''.join([genome, s])
else:
break
except:
break
#sequences=genome.split(' ')
del sequences[0]
del sequences[-1]
#sequences=map(int, sequences)
f.close()
#print sequences
return sequences
def BreakpointsNum(P):
L=map(int, P)
points=0
if ((L[0]-0) != 1):
points+=1
for i in range(1,len(P)):
if (L[i]-L[i-1] != 1):
points+=1
#print len(P),L[-1]
if (len(P)+1-L[-1] != 1):
points+=1
return points
def main():
file1=sys.argv[1]
#out=open("out.txt","w")
seq=GetSequence(file1)
#print seq
num=BreakpointsNum(seq)
print num
#P=GreedySorting(seq,out)
main()