In java only public class Part1 { public String findSimpleGene (String dna) { St
ID: 3880462 • Letter: I
Question
In java only
public class Part1 {
public String findSimpleGene (String dna) {
String Gene =""; //Null string
int startdna = dna.indexOf("ATG"); //start codon
if (startdna ==-1){
//if no ATG
return "";
}
int stopdna = dna.indexOf("TAA", startdna + 3);
//stop codon - start at index and take next 3 characters
if (stopdna ==-1){
//if no TAA
return "";
}
Gene = dna.substring(startdna, stopdna+3);
//collect characters between startdna & stop at stopdna
//index and take next 3 characters
int g = Gene.length();
//Find length of Gene with int g
if (g % 3 == 0){
//find if g is divisible by 3
return Gene ;
}
if (g % 3 != 0){
//find if g is divisible by 3
return "" ;
}
return Gene;
}
public void testSimpleGene(){
String dna="AACGTCATGGAATCAATCTAA";
System.out.println("DNA strand is " + dna);
String gene= findSimpleGene(dna);
System.out.println("Gene is " + gene);
dna="AACATGTGCGTA";
System.out.println("DNA strand is " + dna);
gene= findSimpleGene(dna);
System.out.println("Gene is " + gene);
} }
Then
Modify the findSimpleGene method to work with DNA strings that are either all uppercase letters such as “ATGGGTTAAGTC” or all lowercase letters such as “gatgctataat”. Calling findSimpleGene with “ATGGGTTAAGTC” should return the answer with uppercase letters, the gene “ATGGGTTAA”, and calling findSimpleGene with “gatgctataat” should return the answer with lowercase letters, the gene “atgctataa”. HINT: there are two string methods toUpperCase() and toLowerCase(). If dna is the string “ATGTAA” then dna.toLowerCase() results in the string “atgtaa”.
3. The method findSimpleGene has one parameter for the DNA string named dna. Modify findSimpleGene to add two additional arameters, one named startCodon for the start codon and one named stopCodon for the stop codon. What additional changes do you need to make for the program to compile? After making all changes, run your program to check that you get the same output as beforeExplanation / Answer
Below is your updated program: -
public class Part1 {
public String findSimpleGene(String dna, int startCodon, int stopCodon) {
String Gene = ""; // Null string
int startdna = startCodon; // start codon
if (Character.isUpperCase(dna.charAt(0))) {
dna = dna.toUpperCase();
} else {
dna = dna.toLowerCase();
}
if (startdna == -1) {
// if no ATG
return "";
}
int stopdna = stopCodon;
// stop codon - start at index and take next 3 characters
if (stopdna == -1) {
// if no TAA
return "";
}
Gene = dna.substring(startdna, stopdna + 3);
// collect characters between startdna & stop at stopdna
// index and take next 3 characters
int g = Gene.length();
// Find length of Gene with int g
if (g % 3 == 0) {
// find if g is divisible by 3
return Gene;
}
if (g % 3 != 0) {
// find if g is divisible by 3
return "";
}
return Gene;
}
public int getStartCodon(String dna) {
if (Character.isUpperCase(dna.charAt(0))) {
return dna.indexOf("ATG");
} else {
return dna.indexOf("atg");
}
}
public int getStopCodon(String dna) {
if (Character.isUpperCase(dna.charAt(0))) {
return dna.indexOf("TAA", getStartCodon(dna) + 3);
} else {
return dna.indexOf("taa", getStartCodon(dna) + 3);
}
}
public void testSimpleGene() {
String dna = "AACGTCATGGAATCAATCTAA";
System.out.println("DNA strand is " + dna);
String gene = findSimpleGene(dna, getStartCodon(dna), getStopCodon(dna));
System.out.println("Gene is " + gene);
dna = "AACATGTGCGTA";
System.out.println("DNA strand is " + dna);
gene = findSimpleGene(dna, getStartCodon(dna), getStopCodon(dna));
System.out.println("Gene is " + gene);
dna = "ATGGGTTAAGTC";
System.out.println("DNA strand is " + dna);
gene = findSimpleGene(dna, getStartCodon(dna), getStopCodon(dna));
System.out.println("Gene is " + gene);
dna = "gatgctataat";
System.out.println("DNA strand is " + dna);
gene = findSimpleGene(dna, getStartCodon(dna), getStopCodon(dna));
System.out.println("Gene is " + gene);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.