Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Help Make a copy of the printAll method called getAll Instead of printing the genes found, this method should create and return a StorageResource

Java Help

Make a copy of the printAll method called getAll Instead of printing the genes found, this method should create and return a StorageResource containing the genes found.

import edu.duke.*

public class Part1 { public int findStop(String dnaStr, int startIndex, String stopCodon){ //Find stop codon from end of ATG int currIndex=dnaStr.indexOf(stopCodon, startIndex+3); //as long as curr index not -1 while(currIndex !=-1){ //check for multiple of 3 if((currIndex - startIndex) % 3==0){ //if so, text between is substring return currIndex; } else{ //if not,Update currIndex currIndex=dnaStr.indexOf(stopCodon,currIndex+1); } } return dnaStr.length();

}

public String findGene(String dna){ //First occurrence of ATG int startIndex =dna.indexOf("ATG"); //if no ATG is found return null if(startIndex == -1){ return ""; } //stop codons to look for in index of dna string int taaIndex=findStop(dna, startIndex, "TAA"); int tagIndex=findStop(dna, startIndex, "TAG"); int tgaIndex=findStop(dna, startIndex, "TGA"); //store smallest index of ending codon values int min1; int min2=0;

if(taaIndex == -1 ||(tgaIndex!=-1 && tgaIndex< taaIndex)){ min2 = tgaIndex; } else{ min2 = taaIndex; } if(min2 ==-1 ||(tagIndex!=-1 && tagIndex < min2)){ min2=tagIndex; }

//is full dna string none were found so print null if(min2 == -1){ return ""; } else{ return dna.substring(startIndex, min2+3); } }

public void printGenes(String dna) { //set start index int startIndex =0; //loop while (true){ //find next gene after start index String currGene =findGene(dna); // no gene found leave loop if(currGene.isEmpty()){ break; } //Print gene out System.out.println(currGene); //Set start index to 1 past end of last gene startIndex= dna.indexOf(currGene, startIndex) + currGene.length(); } }

public void testfindStop(){ String dna="ACTATGGAAGCATAA"; System.out.println("DNA strand is "+ dna); int gene=findStop(dna,0,"TAA"); System.out.println("Gene is "+ gene);

dna="ACTATGTAAGCATGATAA"; System.out.println("DNA strand is "+ dna); gene=findStop(dna,0,"TGA"); System.out.println("Gene is "+ gene);

dna="ACTATGTACCATAACTAG"; System.out.println("DNA strand is "+ dna); gene=findStop(dna,0,"TAG"); System.out.println("Gene is "+ gene);

}

public void testfindGene(){ String dna = "ATTATGGTCTAGTAAATGTAA"; System.out.println("DNA strand is "+ dna); String gene= findGene(dna); if(gene.isEmpty()){ System.out.println ("");} else{ System.out.println("Gene is "+ gene); } }

public void testprintGenes(String dna){ System.out.println("DNA strand is "+ dna); printGenes(dna); }

public void printAll(String dna){ int index=0; while(true){ int startIndex=dna.indexOf("ATG",index); if(startIndex!=-1) System.out.println("start:" + startIndex); index+=startIndex+3; if(startIndex ==-1){ System.out.println(""); break; } } }

public void testprintAll(){ String dna = "ATGGAATAGTCGATGGCTTAA"; System.out.println("DNA is "+ dna); printAll(dna);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions