-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBurrowsWheeler.java
73 lines (58 loc) · 2 KB
/
BurrowsWheeler.java
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
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.lang.*;
import java.util.stream.IntStream;
import java.util.Arrays;
public class BurrowsWheeler {
private String sequence;
public BurrowsWheeler() {
this.setSequence(sequence);
}
public char[] appendDollarToString() {
String new_string = this.getSequence()+"$";
char[] char_array = new char[new_string.length()];
for(int i=0; i <new_string.length();i++) {
char_array[i] = new Character(new_string.charAt(i));
}
return char_array;
}
public String createSingleRotation(char[] any_char_list) {
char[] rotated_array = new char[any_char_list.length];
for(int i=0; i < any_char_list.length;i++) {
if(i==any_char_list.length-1) {
rotated_array[0] = any_char_list[any_char_list.length-1];
} else {
rotated_array[i+1] = any_char_list[i];
}
}
return new String(rotated_array);
}
public String[] createCompletetRotationString() {
char[] char_array = new char[this.getSequence().length()];
char_array = this.appendDollarToString();
String[] bwt_strings = new String[char_array.length];
for(int i=0; i < char_array.length;i++) {
String rotated = this.createSingleRotation(char_array);
bwt_strings[i] = rotated;
char_array =rotated.toCharArray();
}
String[] bwt_strings_sorted = new String[bwt_strings.length];
Arrays.sort(bwt_strings);
return bwt_strings;
}
public String returnBurrowsWheelerString() {
String[] bwt_matrix = new String[this.sequence.length()+1];
bwt_matrix = this.createCompletetRotationString();
String burrows_wheeler_transform = "";
for(int i = 0; i < bwt_matrix.length;i++) {
String bwt_matrix_string=bwt_matrix[i];
String last_char=Character.toString(bwt_matrix_string.charAt(bwt_matrix_string.length()-1));
burrows_wheeler_transform+=last_char;
}
return burrows_wheeler_transform;
}
public String getSequence() {
return sequence;
}
public void setSequence(String sequence) {
this.sequence = sequence;
}
}