-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpart3.java
55 lines (49 loc) · 1.69 KB
/
part3.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
/**
* Write a description of part3 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class part3 {
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 int countGenes(String dna){
int startIndex = dna.indexOf("ATG");
int currIndex = startIndex;
int count = 0;
while(true){
if (currIndex == -1){
return count;
}
else {
count = count + 1;
//System.out.println(findGene(dna, currIndex));
currIndex = findStopCodon(currIndex, dna);
}
}
}
public void testCoutGenes(){
String dna1 = "ATGTAAGATGCCCTAGT";
System.out.println(countGenes(dna1));
}
}