String s="CCATGTTGGCCTAGGTGACAC";
I am trying to find an Open reading frame from above DNA sequence. First I have to find whether there is "ATG" present as a sub string. If it is there then I have to find out whether any one of these sub strings is present "TAA", "TAG", "TGA". Among these three sub strings whichever comes first is to be taken into considerartion and then I would print the string from "ATG" to "TAA" or "TAG" or "TGA" whichever comes first.
From above string output should be "ATG TTGGCC TAG".
You can get the index of each substring..
System.out.println(s.indexOf("ax"));
The one whose index is minimum is the one who comes first.
String testString = "ddddeeaxgghnnnbykkkkkklllllczfr";
String[] frags = testString.split("(ax|by|cz)");
if(frags.length >= 1) {
System.out.println("first=" + frags[0]);
if(frags.length >= 2) {
System.out.println("second=" + frags[1]);
if(frags.length >= 3) {
System.out.println("third=" + frags[2]);
}
}
} else {
System.out.println("nothing found");
}
It prints:
first=ddddee
second=gghnnn
third=kkkkkklllll