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

intro to Computer science java/bluej problem using knowledge of DNA sequences: P

ID: 3787135 • Letter: I

Question

intro to Computer science java/bluej problem using knowledge of DNA sequences:

Please only use the basics such as for loops, while loops, break, continue,switch,etc. if possible since I am sitll fairly new to computer science.

"Your program will first prompt the user to enter a single DNA sequence, which it should validate for legality (i.e., only the four valid bases) — you might do this validation by writing a function that takes a String as a parameter and returns a boolean. Re-prompt the user if the input was invalid. Once you have a valid input, compute the following statistics (each should be implemented as a separate function, called from main())."

1. Count the number of occurrences of “C”.

2. Determine the fraction of cytosine and guanine nucleotides. For example, if half of the nucleotides in the sequence are either “C” or “G”, the fraction should be 0.5.

3. A DNA strand is actually made up of pairs of bases — in effect, two strands that are crosslinked together. These two strands are complementary: if you know one, you can always determine the other, or complement, because each nucleotide only pairs up with one other. In particular, “A” and “T” are complements, as are “C” and “G”. So, for example, the complement of the sequence “AAGGTCT” would be “TTCCAGA”. Compute the complement of the input sequence.

Explanation / Answer


import java.util.*;
public class DNAsequence {
   static Scanner sc=new Scanner(System.in);
static   int countc=0;
static   int countg=0;
static float fraction=0.0f;
   public static void main(String[] args) {
       boolean valid;
       System.out.println("enter valid sequence:");
       String seq=sc.next();
       valid= chkvalid(seq);
       if(valid==true){
           countss(seq);
       detfraction(seq);
       } else{
           System.out.println("INvalid sequence:");
  
       }
             
         
          
      

OUTPUT:
enter valid sequence:
CCCCATCGGAAT
0.0
GGGGTAGCCTTA

OUTPUT: