Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java for DNA sequences 1)design a DNA sequence class called DNA with a validatio

ID: 3850928 • Letter: J

Question

Java for DNA sequences

1)design a DNA sequence class called DNA with a validation method called IsDNAvalid() to validate if the DNA sequence contains any invalid letter (not A, C, G, T). You can use the charAt() method of the String class to loop through a sequence string to check if each letter is valid. Design another class which contains the main() method, and create a DNA object inside the main method, then call the IsDNAvalid() method to validate the DNA sequence input.

2. Add two more methods to the DNA class in question #1, getSize() to return the length of the DNA sequence, and baseCount() to count the number of a particular base nucleotide. The baseCount() method will take in one parameter, a base nucleotide (A, T, G, or C), and return a number count of that nucleotide in the DNA sequence, such as:

count_of_A = dna.baseCount('A');
count_of_C = dna.baseCount('C');

Using these two new methods in your program to calculate the percentage of GC contents in the DNA sequence you entered. Round your answer to 2 decimal places.

(question #1 and 2 can be combined into a single DNA class to contain all the required methods) (with comments)

Explanation / Answer

Create file with name validity.java and paste below code into it!

import java.util.Scanner;
import java.lang.*;
public class validity {

public static void main(String[] args)
{
System.out.println("Enter the DNA Sequence");
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
System.out.println(input.length());
DNA d = new DNA(input);
if(d.IsDNAvalid())
{
System.out.println("This is a valid DNA Sequence");
char base1 = 'G';
char base2 = 'C';
System.out.println( "Length of DNA sequence is = " + d.getSize() );
System.out.println( "Basecount for " + base1 + " = " + d.baseCount(base1) );
System.out.println( "Basecount for " + base2 + " = " + d.baseCount(base2) );
float gc_content = ((float)(d.baseCount(base1) + (float) d.baseCount(base2))*100)/(d.getSize());
System.out.println( "GC content = " + Math.round(gc_content*100.0)/100.0 );   
}
else
{
System.out.println("This is an invalid DNA Sequence");
}
}
  
}

Create file with name DNA.java and paste below code into it!

public class DNA {
public String input;
public DNA(String tmp)
{
this.input = tmp;
}
public boolean IsDNAvalid()
{
for(int i = 0; i< this.input.length();i++)
{
if(this.input.charAt(i) != 'A' && this.input.charAt(i) != 'C' && this.input.charAt(i) != 'G' && this.input.charAt(i) != 'T' )
{
return false;
}
}
return true;
}
  
public int getSize()
{
return this.input.length();
}
public int baseCount(char base)
{
int count = 0;
for(int i = 0; i< this.input.length();i++)
{
if(this.input.charAt(i) == base )
{
count++;
}
}
return count;
}
}

Sample Output:

Enter the DNA Sequence
ACG
3
This is a valid DNA Sequence
Length of DNA sequence is = 3
Basecount for G = 1
Basecount for C = 1
GC content = 66.67

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote