-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpart1.java
62 lines (57 loc) · 1.87 KB
/
part1.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
/**
* Write a description of part1 here.
*
* @author Jiyang Zhang
* @version (a2018.03.13)
*/
public class part1 {
private class innerPart1 {
/** test for inner class.
* Test method
*/
private void testInner() {
System.out.println("Test the parser.");
}
}
/** This is findStopCodon method */
public int findStopCodon(int startIndex, String dna){
int taaIndex = dna.indexOf("TAA", startIndex+1);
if (taaIndex == -1
|| (taaIndex - startIndex) % 3 != 0) taaIndex = dna.length();
int tagIndex = dna.indexOf("TAG", startIndex+1);
if(tagIndex == -1
|| (tagIndex - startIndex) % 3 != 0) tagIndex = dna.length();
int tgaIndex = dna.indexOf("TGA", startIndex+1);
if(tgaIndex == -1
|| (tgaIndex - startIndex) % 3 != 0) tgaIndex = dna.length();
int minIndex = Math.min(taaIndex, tagIndex);
minIndex = Math.min(minIndex, tgaIndex);
if (minIndex == dna.length()) return -1;
else return minIndex;
}
public String findGene(String dna, int startIndex){
int endCodon = findStopCodon(startIndex, dna);
if (endCodon != -1){
return dna.substring(startIndex, endCodon + 3);
}
else return "";
}
public void printAllGenes(String dna){
int startIndex = dna.indexOf("ATG");
int currIndex = startIndex;
while(true){
if (currIndex == -1){
System.out.println("");
break;
}
else {
System.out.println(findGene(dna, currIndex));
currIndex = findStopCodon(currIndex, dna);
}
}
}
public void test(){
String dna = "AATGCTAACTAGCTGACTAAT";
printAllGenes(dna);
}
}