-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCircularDNA.java
79 lines (70 loc) · 1.99 KB
/
CircularDNA.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
74
75
76
77
78
79
import java.util.ArrayList;
public class CircularDNA extends DNA {
public CircularDNA(ArrayList<Object> cDNA) {
super(cDNA);
}
public CircularDNA(String inp) {
super(inp);
}
public CircularDNA(Electrophoresis ele) {
super(ele);
}
public void setCuts() {
if (getDNA().size() > 0) {
super.setCuts();
} else {
for (Enzyme enzyme : getEnzymes()) {
setTotalCuts(getTotalCuts() + enzyme.getNumFragments());
enzyme.setNumCuts(enzyme.getNumFragments());
}
}
}
public void codeRepresentation() {
super.codeRepresentation();
setRep(getRep() + ">");
}
public static boolean isValidInput(String inp) {
if (!DNA.isValidInput(inp)) {
return false;
}
if (!(Character.isUpperCase(inp.charAt(0)) && inp.charAt(inp.length()-2) == '-' && inp.charAt(inp.length()-1) == '>')) {
return false;
}
return true;
}
public void decodeRepresentation(String inp) {
super.decodeRepresentation(inp.substring(0, inp.length()-1));
}
public String testTrack(String enzymeName, int[] perm, int max, String longestTest) {
String res = testTrack(enzymeName, perm, (perm[perm.length-1] == max) ? true : false);
for (int i = 0; i < longestTest.length(); i++) {
char c1 = longestTest.charAt(i);
char c2 = res.charAt(i);
if (c1 == '-' && c2 == '-') {
continue;
} else if (c1 == '!' && Character.isAlphabetic(c2)) {
continue;
} else if (c1 == '!' && c2 == '-') {
res = res.substring(0, i) + " " + res.substring(i);
} else {
if (perm[perm.length-1] == max) {
int[] permTmp = new int[perm.length+1];
permTmp[0] = 1;
for (int j = 1; j < permTmp.length; j++) {
permTmp[j] = perm[j-1];
}
permTmp[permTmp.length-1]--;
return testTrack(enzymeName, permTmp, max, longestTest);
} else if (perm[0] < max-1) {
int[] permTmp = perm.clone();
permTmp[0]++;
permTmp[permTmp.length-1]--;
return testTrack(enzymeName, permTmp, max, longestTest);
} else {
return null;
}
}
}
return res;
}
}