-
Notifications
You must be signed in to change notification settings - Fork 0
/
TagFinder.java
43 lines (41 loc) · 1.03 KB
/
TagFinder.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
/**
* Finds a protein within a strand of DNA represented as a string of c,g,t,a letters.
* A protein is a part of the DNA strand marked by start and stop codons (DNA triples)
* that is a multiple of 3 letters long.
*
* @author Duke Software Team
*/
import edu.duke.*;
import java.io.*;
public class TagFinder {
public String findProtein(String dna) {
int start = dna.indexOf("atg");
if (start == -1) {
return "";
}
int stop = dna.indexOf("tag", start+3);
if ((stop - start) % 3 == 0) {
return dna.substring(start, stop+3);
}
else {
return "";
}
}
public void testing() {
String a = "";
String ap = "atggggtttaaataataatag";
//String a = "atgcctag";
//String ap = "";
//String a = "ATGCCCTAG";
//String ap = "ATGCCCTAG";
String result = findProtein(a);
if (ap.equals(result)) {
System.out.println("success for " + ap + " length " + ap.length());
}
else {
System.out.println("mistake for input: " + a);
System.out.println("got: " + result);
System.out.println("not: " + ap);
}
}
}