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

In addition to the two problems, you will also have to create another java appli

ID: 3729301 • Letter: I

Question

In addition to the two problems, you will also have to create another java application named, DNA.java. This implementation will take an String as a command line parameter, NOT INTERACTIVELY. The string will contain a single or multiple DNA sequence/s (You define how they are to be separated and don’t forget to tell the user in your documentation). The program should then print the complement and reverse complement of the DNA sequence to standard output. Make sure to include a DNADriver class that includes the main method. In your code implementation, create a method, complement, that returns the complement of a DNA string. Also provide a method, reverseComplement(), that takes a DNA sequence as string input and returns the reverse complement of the sequence as a string. Please, develop whatever other helper functions you deem necessary. Recall that the valid alphabet is {A,C,T,G} and that A-T and G-C are complements. A reverse complement is found by reversing the input string and replacing every nucleotide with its complement. This means that your revComplement method should use your complement method internally rather than duplicating code. Your methods should do appropriate error checking and return an error message as appropriate.

Explanation / Answer

import java.util.StringTokenizer;

public class DNA
{
   //doComplent() method contains main logic that converts sequnce into its complent one
  
   public String doComplent(String seq) throws Throwable{
       StringBuilder temp= new StringBuilder(seq);
       for(int i=0;i<temp.length();i++){
              if(temp.charAt(i) =='A')
                  temp.setCharAt(i,'T');
              else if(temp.charAt(i) =='T')
                  temp.setCharAt(i,'A');
              else if(temp.charAt(i) =='G')
                  temp.setCharAt(i,'C');
              else if(temp.charAt(i) =='C')
                  temp.setCharAt(i,'G');
              else
                  throw new Exception("Invalid input ; nucleotides should be in {A,C,T,G} format");// error message incase invalid characters used.
          }
       return temp.toString();
   }
  
   //from here we access doComplent() method to perform operation
   public String complement(String seq) throws Throwable{
           String comp="";
           StringTokenizer st = new StringTokenizer(seq,"|"); // using tokenizer we are seperating multiple Sequnces (seperated by '|')
             while (st.hasMoreTokens()) {
               comp= comp+" "+doComplent(st.nextToken());
             }
       return comp;
          
   }
  
   // here after reversing sequnce we are calling doComplement()
   public String reverseComplement(String seq) throws Throwable{
       String comp="";
           StringTokenizer st = new StringTokenizer(seq,"|");
             while (st.hasMoreTokens()) {
               comp= comp+" "+doComplent(new StringBuilder(st.nextToken()).reverse().toString());// here we are performing 3 operations reverse-calling doComplent()
             }
       return comp;
   }
}

public class DnaDriver {
/**
* this program takes input form command line
* multiple sequences can be accepted by separating them with "|" (no spaces , special keys, small characters are allowed)
* example input : ATGCATGA|CTGCA
* Out put will be in the same order separated by space
* example output : complement        : TACGTACT GACGT
                    reverseComplement : TCATGCAT TGCAG
* @param args
* @throws Throwable
*/

   public static void main(String[] args) throws Throwable {
       DNA dna= new DNA();
       for (String str: args) {// iterator for accessing inputs from commandline
           System.out.println("****for : "+str);
           System.out.println("complement        :"+dna.complement(str));
           System.out.println("reverseComplement :"+dna.reverseComplement(str));
           System.out.println("*******************");
           }

   }

}

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