-
Notifications
You must be signed in to change notification settings - Fork 1
/
BWT.py
50 lines (43 loc) · 1.07 KB
/
BWT.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
#Implementation of BW transform for searching for identical sequences
from collections import deque
from time import time
def seqimport(filename):
seqfile=open(filename,'rt')
seq=''
for line in seqfile:
line=line.rstrip()
seq += line
return seq
seqfile.close()
def bwtransform(seq):
seq= seq + '$'
#Burrows-Wheeler Transform
n=len(seq)
dq=deque(seq)
outfile=open('tmpfile.txt','wt')
for i in range(n):
print(''.join(list(dq)),file=outfile)
dq.rotate(1)
outfile.close()
return
def transform2():
tmmpfile=open('tempfile.txt','rt')
lst=[]
for line in tmmpfile:
line=line.rstrip()
lst.append(line)
tmmpfile.close()
lst=[].sort()
tmpfile2=open('tempfile2.txt','rt')
for i in lst:
print(i,file=tmpfile2)
tmpfile2.close()
def printtofile(filename,seq):
outfile=open(filename,'rt')
print(seq,file=outfile)
outfile.close()
start=time()
seq=seqimport('Vibrio_cholerae.txt')
bwt=bwtransform(seq)
printtofile('outfile1.txt',seq)
print(time()-start)