To find a gene in a genome, we scan for the start codon, ATG, remember its index, then scan from the next stop codon, TAG. If the length of the intervening sequence is a multiple of 3, we have found a gene. Return the gene
Here's what I've gotten so far:
public static void main(String[] args) {
System.out.println("This is a gene finder program.");
Scanner scan = new Scanner(System.in);
System.out.println("Enter the string that you want to locate genes:");
String geneString = scan.nextLine();
System.out.println(scanGene(geneString));
}
public static String scanGene(String geneString) {
int i = 0;
int x = 3;
int y = 3;
double startCondon, endCondon;
while (i < geneString.length() - 3) {
i = i+1;
x = x+1;
if(geneString.substring(i,x) == "ATG") {
startCondon = geneString.indexOf(x+1);
while (y<geneString.length()) {
y = y+1;
if (geneString.substring(y,y+4) == "TAG") {
endCondon = geneString.indexOf(y-1);
if ((endCondon - startCondon) % 3 == 0)
System.out.println("We have found a gene!");
}
}
}
}
return geneString.substring(x+1,y);
}
Help please? It doesn't seem to be working...for some reason it gives me an error "Out of range" the index is a negative number or something. I've looked over the code but can't seem to find anything too wrong with it.... Thanks