File tree 2 files changed +48
-8
lines changed
5-string-processing-and-pattern-matching-algorithms/2-burrows-wheeler-suffix-arrays
2 files changed +48
-8
lines changed Original file line number Diff line number Diff line change 1
1
# python3
2
2
import sys
3
3
4
- def InverseBWT (bwt ):
5
- # write your code here
6
- return ""
4
+ class Burrows_Wheeler_Inverse :
7
5
6
+ def inverse (self , bwt_text ):
7
+
8
+ last_column = [c for c in bwt_text ]
9
+ first_column = [c for c in bwt_text ]
10
+ first_column .sort ()
11
+ last_to_first = self .build_last_to_first (first_column , last_column )
12
+
13
+ origin_text_list = []
14
+ origin_text_list .append (first_column [0 ])
15
+
16
+ i = 0
17
+ while last_to_first [i ] != 0 :
18
+ i = last_to_first [i ]
19
+ origin_text_list .append (first_column [i ])
20
+
21
+ origin_text_list .reverse ()
22
+
23
+ return '' .join (origin_text_list )
24
+
25
+ def build_last_to_first (self , first_column , last_column ):
26
+ last_to_first = []
27
+
28
+ first_occurence = dict ()
29
+ for i in range (len (first_column )):
30
+ c = first_column [i ]
31
+ if not c in first_occurence :
32
+ first_occurence [c ] = i
33
+
34
+ char_count = dict ()
35
+ for i in range (len (last_column )):
36
+ c = last_column [i ]
37
+
38
+ if c in char_count :
39
+ count = char_count [c ]
40
+ char_count [c ] += 1
41
+ else :
42
+ char_count [c ] = 1
43
+ count = 0
44
+
45
+ last_to_first .append (first_occurence [c ] + count )
46
+
47
+ return last_to_first
8
48
9
49
if __name__ == '__main__' :
10
50
bwt = sys .stdin .readline ().strip ()
11
- print (InverseBWT (bwt ))
51
+
52
+ bwt_inverse = Burrows_Wheeler_Inverse ()
53
+
54
+ print (bwt_inverse .inverse (bwt ))
Original file line number Diff line number Diff line change 1
- 3
2
- ATAGA
3
- ATC
4
- GAT
1
+ ATG$CAAA
You can’t perform that action at this time.
0 commit comments