Question: Write these 6 classes according to the specifications. DNARecord is given: package dna; public interface DNARecord { String getDefline(); String getSequence(); } FastqRecord This class

Write these 6 classes according to the specifications.

DNARecord is given:

package dna;

public interface DNARecord

{

String getDefline();

String getSequence();

}

FastqRecord This class should implement DNARecord and should have: 3 String instance variables: defline, sequence, and quality. A constructor that initializes the instance variables. If the defline does not start with the correct character, the ctor should throw RecordFormatException with a helpful message "Bad 1st char in defline in fastq record: saw X, expected @" (If youre not sure how to get the 1st character of a string, check out the charAt(int) method of String on the API page.) Yes, ctors can throw exceptions just like methods; be sure to add throws RecordFormatException to the ctor declaration. Provide the 2 methods that satisfy the DNARecord interface. An equals() method that checks for deep equality of all 3 instance variables. A boolean qualityIsLow() method that returns true if and only if the quality contains at least one exclamation mark (!). In real life this method would be a lot more complicated. A hashCode() method that returns the sum of the hash codes of defline, sequence, and quality.

FastaRecord This class should implement DNARecord and should have:

2 String instance variables: defline and sequence. A constructor that takes 2 args the defline and the sequence and initializes the instance variables. As with FastqRecord, check to make sure the defline starts with the correct character (its > for fasta records rather than "@"). Throw RecordFormatException if it doesnt. Another ctor with 1 arg a FastqRecord that initializes the instances variables with values from the FastqRecord. Youll have to change the 1st char of the defline. If youre not sure how to do this, look up the substring() methods on the String API page. Provide the 2 methods that satisfy the DNARecord interface. An equals() method that checks for deep equality of the 2 instance variables. A hashCode() method that returns the sum of the hash codes of defline, and sequence.

FastqReader FastqReader should not extend any superclasses or implement any interfaces. It should have one instance variable: a BufferedReader named theBufferedReader. This class should provide a single-arg ctor that initializes theBufferedReader from the ctor arg. The class should also have the following method: public FastqRecord readRecord() throws IOException, RecordFormatException This method should read a line from the buffered reader. If that line is null, the input file is at the end, and the method should return null. Otherwise the method should read 3 more lines and return a FastqRecord. The method should throw a RecordFormatException with a useful message if the 4 input lines dont constitute a valid fastq record. Note that this happens automatically if you call the FastqRecord ctor with invalid args. You can assume that the + line is ok.

FastaWriter FastaWriter should not extend any superclasses or implement any interfaces. It should have one instance variable: a PrintWriter named thePrintWriter. This class should provide a single-arg ctor that initializes thePrintWriter from its arg. The class should also have the following method: public void writeRecord(FastaRecord rec) throws IOException This method should write the fasta record, in correct fasta format, to thePrintWriter. Write the record as 2 separate lines: first the defline, then the sequence. To write something ona separate line, use the println() method of PrintWriter.

FileConverter

The skeleton of this class is given, utilize the comments and the instructions to complete:

package dna; import java.io.*; import java.util.*; public class FileConverter { // // Writes a fasta file consisting of conversion of all records from the fastq with // sufficient quality and unique defline. // public void convert() throws IOException { // Build chain of readers. FileReader fr = BufferedReader br = FastqReader fqr =

// Build chain of writers. FileWriter fw = PrintWriter pw = FastaWriter faw =

// Read, translate, write.

// Close fr, br, fw, and pw in reverse order of creation. }

public static void main(String[] args) { System.out.println("Starting"); try { File fastq = new File("data/HW4.fastq"); if (!fastq.exists()) { System.out.println("Can't find input file " + fastq.getAbsolutePath()); System.exit(1); } File fasta = new File("data/HW4.fasta"); FileConverter converter = new FileConverter(fastq, fasta); converter.convert(); } catch (IOException x) { System.out.println(x.getMessage()); } System.out.println("Done"); } }

This class should have 2 instance variables of type File, named fastq and fasta. Provide a ctor that has 2 File args and initializes the instance variables. The class should have a convert() method and a main() method. The convert() method should declare that it throws IOException. Any other exception types thrown in the body of convert() should be caught and handled inside convert(). The method should 1) Create a FastqReader that reads from the fastq file specified by the fastq instance variable. 2) Create a FastaWriter that writes to the fasta file specified by the fasta instance variable. 3) Read each fastq record until the end of the fastq file is reached. Do nothing with any invalid records (i.e. records where the defline didnt start with @). For valid records where the quality isnt low, create a fasta record and write it using the FastaWriter. 4) Close all readers and writers that have close() methods, in reverse order of creation.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!