Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this assignment you will write a Java app that reads a fastq file and creates a fasta file. Records in the fastq might or

For this assignment you will write a Java app that reads a fastq file and creates a fasta file. Records in the fastq might or might not meet some quality threshold, and might or might not have unique deflines. Records in the fasta will all meet or exceed a quality threshold, and will all have unique deflines. In class, you saw a method that almost does that, while reading from a BufferedReader and writing to a PrintWriter. For this assignment, you will use a different approach. You will create classes FastqReader (which will read from a BufferedReader) and FastaWriter (which will write to a PrintWriter).

complete the starter files as described below. All classes, and all methods that you write, should be public. Comments and Style The comments in the starter files are instructions to you. After you finish the assignment, they arent meaningful or relevant. So as you write each method, replace the starter comment with comments of your own that describe your code. Put a comment at the beginning of each class, at the beginning of most methods, and within methods if the method proceeds in several steps. For example, your convert() method will build its input stream, build its output stream, do the work, and then close its resources; each of those steps should start with a comment, and the steps should be separated by exactly 1 blank line. The grader bot will give you 90 points for a perfectly working app. The remaining 10 points are for comments and coding style. Make sure your source code is neat and correctly indented. Make sure your variables have helpful names. Comment any class, method, or block of code within a method whose action isnt obvious. RecordFormatException This class should extend Exception (not RuntimeException, because we want it to be checked). Provide one constructor whose arg is a String. Pass the String to the superclass constructor that takes a single String arg. DNARecord This interface doesnt need to be changed. Just read it and understand it. 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. (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. Here are some possible messages, in increasing order of helpfulness: o An empty or null string o Zzup yo? o Oops o Bad fastq record o Bad defline in fastq record o Bad 1st char in defline in fastq record o Bad 1st char in defline in fastq record: saw X, expected @ 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). 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. 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. FileConverter 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.

The main() method is provided for you. It reads and converts the fastq file that you downloaded with this assignment. The next section tells you what to do with the fastq file. The Input File Notice that the main() method reads a fastq file in a directory called data, and writes a fasta file in the same directory. You will need to create this directory in Eclipse, and import HW4.fastq into it. To create the data directory, right-click on your project name in the package explorer and select New -> Folder in the popup menu. When prompted for the folder name, enter data. You should see the new directory in the Package Explorer, at the same level as src. If it isnt at the right level, delete it and start again; it has to be in the right place for main() and the grader bot to find it.

--------------------------------------------------------------------------------------------------------

Should pass this grader code below

package dna;

import java.io.*;

import java.lang.reflect.*;

import java.util.*;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class DNAGrader

{

private final static Class[] EMPTY_ARGSLIST = { };

private final static Class[] STRING_ARGSLIST = { String.class };

private final static Class[] STRING_2_ARGSLIST = { String.class, String.class };

private final static Class[] STRING_3_ARGSLIST = { String.class, String.class, String.class };

private final static Class[] BR_ARGSLIST = { BufferedReader.class };

private final static Class[] PW_ARGSLIST = { PrintWriter.class };

private Class fastqRecordClass;

private Map> catToDeductions = new LinkedHashMap<>();

private int commentDeduction;

private int styleDeduction;

private String gradersNotes;

private enum Category

{

// For each category, student can't lose > maxDeductions.

DNARecord(10),

FastqException(10),

FastqRecord(18),

FastaRecord(10),

FastqReader(10),

FastaWriter(10),

FileConverter(24),

Style(5),

Comments(3);

private int maxDeductions;

Category(int maxDeductions)

{

this.maxDeductions = maxDeductions;

}

int getMaxDeductions()

{

return maxDeductions;

}

}

static

{

int maxPoints = 0;

for (Category cat: Category.values())

maxPoints += cat.getMaxDeductions();

assert maxPoints == 100 : maxPoints;

}

private class Deduction

{

private String reason;

private int pointsOff;

Deduction(String reason, int pointsOff)

{

this.reason = reason;

this.pointsOff = pointsOff;

}

public String toString()

{

return reason + ": -" + pointsOff;

}

}

private void deduct(Category cat, String reason, int pointsOff)

{

ArrayList dedsForCat = catToDeductions.get(cat);

if (dedsForCat == null)

catToDeductions.put(cat, (dedsForCat= new ArrayList<>()));

dedsForCat.add(new Deduction(reason, pointsOff));

}

private void deductMax(Category cat, String reason)

{

deduct(cat, reason, cat.getMaxDeductions());

}

private void grade()

{

gradeFormatException();

gradeDNARecord();

gradeFastqRecord();

gradeFastaRecord();

gradeFastqReader();

gradeFastaWriter();

gradeConverter();

testSubjective();

int score = 100;

for (Category cat: catToDeductions.keySet())

{

if (cat == Category.Style || cat == Category.Comments)

continue;

ArrayList dedns = catToDeductions.get(cat);

if (dedns.isEmpty())

continue;

sop("--------");

sop(cat + ":");

int totalDeductionsThisCategory = 0;

for (Deduction dedn: dedns)

{

sop(dedn);

totalDeductionsThisCategory += dedn.pointsOff;

}

totalDeductionsThisCategory = Math.min(totalDeductionsThisCategory, cat.maxDeductions);

sop("TOTAL DEDUCTIONS THIS CATEGORY (max=-" + cat.maxDeductions + "): -" + totalDeductionsThisCategory);

score -= totalDeductionsThisCategory;

}

if (styleDeduction > 0)

sop("Style: -" + styleDeduction);

score -= styleDeduction;

if (commentDeduction > 0)

sop("Comments: -" + commentDeduction);

score -= commentDeduction;

sop("--------------------------- ");

sop("SCORE: " + score);

sop(" " + gradersNotes);

}

private Class getClass(String name)

{

if (!name.startsWith("dna."))

name = "dna." + name;

try

{

return Class.forName(name);

}

catch (ClassNotFoundException x)

{

return null;

}

}

private void gradeFormatException()

{

// Does class exist?

Class clazz = getClass("dna.RecordFormatException");

if (clazz == null)

{

deductMax(Category.FastqException, "No dna.RecordFormatException class");

return;

}

// Does FastqException(String) ctor exist?

try

{

clazz.getConstructor(STRING_ARGSLIST);

}

catch (NoSuchMethodException x)

{

deduct(Category.FastqException, "No RecordFormatException(String) constructor", 8);

}

}

private void gradeDNARecord()

{

// Does class exist?

Class clazz = getClass("dna.DNARecord");

if (clazz == null)

{

deductMax(Category.DNARecord, "No dna.DNARecord class");

return;

}

// Does class define getDefline() and getSequence()?

String[] names = { "getDefline", "getSequence" };

for (String name: names)

{

try

{

Method m = clazz.getDeclaredMethod(name, EMPTY_ARGSLIST);

if (m.getReturnType() != String.class)

deduct(Category.DNARecord, name + "() does not return String", 4);

}

catch (NoSuchMethodException x)

{

deduct(Category.DNARecord, "No " + name + "() method", 5);

}

}

}

private void gradeFastqRecord()

{

String err;

// Does class exist?

fastqRecordClass = getClass("dna.FastqRecord");

if (fastqRecordClass == null)

{

deductMax(Category.FastqRecord, "No dna.FastqRecord interface");

return;

}

// Does class declare it implements DNARecord?

boolean implementsDNARecord = false;

for (Class c: fastqRecordClass.getInterfaces())

{

if (c.getName().equals("dna.DNARecord"))

{

implementsDNARecord = true;

break;

}

}

if (!implementsDNARecord)

{

deduct(Category.FastqRecord, "DNARecord doesn't declare that it implements DNARecord.", 2);

}

// Does class define getDefline() and getSequence()?

String[] names = { "getDefline", "getSequence" };

for (String name: names)

{

try

{

Method m = fastqRecordClass.getDeclaredMethod(name, EMPTY_ARGSLIST);

if (m.getReturnType() != String.class)

deduct(Category.FastqRecord, name + "() does not return String", 4);

}

catch (NoSuchMethodException x)

{

deduct(Category.FastqRecord, "No " + name + "() method", 5);

}

}

// Does class have instance vars defline, sequence, and quality?

String[] expectedFields = { "defline", "sequence", "quality" };

for (String s: expectedFields)

{

try

{

fastqRecordClass.getDeclaredField(s);

}

catch (NoSuchFieldException x)

{

deduct(Category.FastqRecord, "No field " + s, 4);

}

}

// Does class have (String, String, String) ctor that throws RecirdFormatException?

Constructor ctor = null;

try

{

ctor = fastqRecordClass.getConstructor(STRING_3_ARGSLIST);

Class[] exceptionTypes = ctor.getExceptionTypes();

switch (exceptionTypes.length)

{

case 0:

deduct(Category.FastqRecord, "FastqRecord ctor should throw checked type RecordFormatException", 5);

break;

case 1:

if (!exceptionTypes[0].getName().endsWith("RecordFormatException"))

deduct(Category.FastqRecord, "FastqRecord ctor should throw checked type RecordFormatException", 5);

break;

default:

err = "FastqRecord ctor throws multipl exception types, should only throw RecordFormatException";

deduct(Category.FastqRecord, err, 5);

break;

}

}

catch (NoSuchMethodException x)

{

deduct(Category.FastqRecord, "No (String,String,String) constructor", 5);

}

// Check ctor.

FastqRecord rec1AX = null;

try

{

rec1AX = new FastqRecord("@Rec1", "AAAA", "XXXX");

}

catch (RecordFormatException x)

{

deduct(Category.FastqRecord, "FastqRecord ctor threw exception on valid input (@Rec1, AAAA, XXXX)", 3);

}

try

{

new FastqRecord(">Rec1", "AAAA", "XXXX");

deduct(Category.FastqRecord, "FastqRecord ctor did not throw exception on invalid input (>Rec1, AAAA, XXXX)", 3);

}

catch (RecordFormatException x)

{

// Should get here.

}

// Check equals.

FastqRecord rec2AX = null;

FastqRecord rec1CX = null;

FastqRecord rec1AY = null;

FastqRecord rec2TY = null;

FastqRecord anotherRec1AX = null;

FastqRecord hiQualRec = null;

try

{

rec2AX = new FastqRecord("@Rec2", "AAAA", "XXXX");

rec1CX = new FastqRecord("@Rec1", "CCCC", "XXXX");

rec1AY = new FastqRecord("@Rec1", "AAAA", "YYYY");

rec2TY = new FastqRecord("@Rec2", "TTTT", "YYYY");

anotherRec1AX = new FastqRecord("@Rec1", "AAAA", "XXXX");

hiQualRec = new FastqRecord("@RecN", "ACGT", "!!!!");

}

catch (RecordFormatException x) { }

if (rec1AX == null || rec2AX == null || rec1CX == null || rec1AY == null || rec2TY == null)

{

err = "FastqRecord ctor is incorrect, can't create test instances to test equals()";

deduct(Category.FastqRecord, err, 6);

}

else

{

if (rec1AX.equals(rec2AX))

{

err = "equals returned true for (@Rec1, AAAA, XXXX) : (@Rec2, AAAA, XXXX)";

deduct(Category.FastqRecord, err, 2);

}

if (rec1AX.equals(rec1CX))

{

err = "equals returned true for (@Rec1, AAAA, XXXX) : (@Rec1, CCCC, XXXX)";

deduct(Category.FastqRecord, err, 2);

}

if (rec1AX.equals(rec1AY))

{

err = "equals returned true for (@Rec1, AAAA, XXXX) : (@Rec1, AAAA, YYYY)";

deduct(Category.FastqRecord, err, 2);

}

if (rec1AX.equals(rec2TY))

{

err = "equals returned true for (@Rec1, AAAA, XXXX) : (@Rec2, TTTT, YYYY)";

deduct(Category.FastqRecord, err, 2);

}

if (!rec1AX.equals(anotherRec1AX))

{

err = "equals returned false for 2 deeply equal instances (@Rec1, AAAA, XXXX)";

deduct(Category.FastqRecord, err, 2);

}

}

// Check qualityIsLow.

if (!hiQualRec.qualityIsLow())

deduct(Category.FastqRecord, "qualityIsLow is false for (@RecN, ACGT, !!!!)", 2);

if (rec1AX.qualityIsLow())

deduct(Category.FastqRecord, "qualityIsLow is true for (@Rec1, AAAA, XXXX)", 2);

// Check hash code.

int expected = "@Rec1".hashCode() + "AAAA".hashCode() + "XXXX".hashCode();

if (rec1AX.hashCode() != expected)

deduct(Category.FastqRecord, "hashCode() is not exactly as specified", 3);

}

public void gradeFastaRecord()

{

// Does class exist?

Class clazz = getClass("dna.FastaRecord");

if (clazz == null)

{

deductMax(Category.FastaRecord, "No dna.FastaRecord class");

return;

}

// Does class declare it implements DNARecord?

boolean implementsDNARecord = false;

for (Class c: clazz.getInterfaces())

{

if (c.getName().equals("dna.DNARecord"))

{

implementsDNARecord = true;

break;

}

}

if (!implementsDNARecord)

{

deduct(Category.FastaRecord, "DNARecord doesn't declare that it implements DNARecord.", 2);

}

// Does class define getDefline() and getSequence()?

String[] names = { "getDefline", "getSequence" };

for (String name: names)

{

try

{

Method m = clazz.getDeclaredMethod(name, EMPTY_ARGSLIST);

if (m.getReturnType() != String.class)

deduct(Category.FastaRecord, name + "() does not return String", 4);

}

catch (NoSuchMethodException x)

{

deduct(Category.FastaRecord, "No " + name + "() method", 5);

}

}

// Check (String, String) and (FastqRecord) ctors.

try

{

clazz.getConstructor(STRING_2_ARGSLIST);

}

catch (NoSuchMethodException x)

{

deduct(Category.FastaRecord, "No FastaRecord(String, String) constructor", 5);

}

try

{

clazz.getConstructor(new Class[] { fastqRecordClass });

}

catch (NoSuchMethodException x)

{

deduct(Category.FastaRecord, "No FastaRecord(FastqRecord) constructor", 5);

}

}

private void gradeFastqReader()

{

// Just make sure the class exists and has the right methods.

Class clazz = getClass("dna.FastqReader");

if (clazz == null)

{

deductMax(Category.FastqReader, "No dna.FastqReader class");

return;

}

// Check for (BufferedReader) ctor

try

{

clazz.getConstructor(BR_ARGSLIST);

}

catch (NoSuchMethodException x)

{

deduct(Category.FastqReader, "No FastqReader(BufferedReader) constructor", 5);

}

// Check for readRecord() method.

try

{

Method readRecordMethod = clazz.getDeclaredMethod("readRecord",EMPTY_ARGSLIST);

boolean throwsIOException = false;

boolean throwsFastqException = false;

for (Class xtype: readRecordMethod.getExceptionTypes())

{

if (xtype == java.io.IOException.class)

throwsIOException = true;

else if (xtype == dna.RecordFormatException.class)

throwsFastqException = true;

}

if (!throwsIOException)

deduct(Category.FastqReader, "readRecord() doesn't throw IOException", 3);

if (!throwsFastqException)

deduct(Category.FastqReader, "readRecord() doesn't throw RecordFormatException", 3);

}

catch (NoSuchMethodException x)

{

deduct(Category.FastqReader, "No readRecord() method", 5);

}

}

private void gradeFastaWriter()

{

// Just make sure the class exists and has the right methods.

Class clazz = getClass("dna.FastaWriter");

if (clazz == null)

{

deductMax(Category.FastaWriter, "No dna.FastaWriter class");

return;

}

// Check for (PrintWriter) ctor

try

{

clazz.getConstructor(PW_ARGSLIST);

}

catch (NoSuchMethodException x)

{

deduct(Category.FastaWriter, "No FastaWriter(PrintWriter) constructor", 5);

}

// Check for writeRecord()

Class[] argtype = new Class[] { FastaRecord.class };

try

{

clazz.getDeclaredMethod("writeRecord", argtype);

}

catch (NoSuchMethodException x)

{

deduct(Category.FastaWriter, "No writeRecord(FastaRecord) method", 5);

}

}

private final static String[] GOLDEN_FASTA_LINES =

{

">Record3",

"TATTAATCTGACT",

">Record4",

"TATTAATCTGACT",

">Record5",

"GTGATATCGACGTACGTACGTCATGCATGACTGCAGTCAGTACGTCATCAG",

">Record7",

"GTACTACGTACGTTGGACTAGTACGTACGT",

};

private void gradeConverter()

{

// Convert.

File fasta = null;

try

{

File ifile = new File("data/HW4.fastq");

if (!ifile.exists())

{

sop("Can't find HW4.fastq. Please put it in . or ./data");

System.exit(1);

}

File parent = ifile.getParentFile();

fasta = new File(parent, "HW4.fasta");

FileConverter converter = new FileConverter(ifile, fasta);

converter.convert();

}

catch (Exception x)

{

if (x instanceof IOException)

{

sop("IO Exception while converting ... shouldn't happen");

sop(x.getMessage());

x.printStackTrace();

System.out.println(x);

}

else

{

String err = "convert() throws unexpected " + x.getClass().getName() + " exception";

deduct(Category.FileConverter, err, 10);

}

}

// Check output. All records should be fasta (2 lines), with no duplicates. Don't check

// anything else.

Set observedDeflines = new HashSet<>();

try

(

FileReader fr = new FileReader(fasta);

BufferedReader br = new BufferedReader(fr);

)

{

String defline;

while ((defline = br.readLine()) != null)

{

if (defline == null || defline.trim().isEmpty())

break;

br.readLine();

if (observedDeflines.contains(defline))

{

String err = "Duplicate defline in fasta file: " + defline;

deduct(Category.FileConverter, err, 10);

break;

}

observedDeflines.add(defline);

}

}

catch (IOException x)

{

sop("Trouble reading fasta file, please run grader again.");

sop(x.getMessage());

x.printStackTrace();

System.exit(2);

}

// Check content of output.

ArrayList lines = new ArrayList<>();

try

(

FileReader fr1 = new FileReader(fasta);

BufferedReader br1 = new BufferedReader(fr1);

)

{

String line;

while ((line = br1.readLine()) != null)

lines.add(line);

}

catch (IOException x)

{

sop("Trouble reading fasta file, please run grader again.");

sop(x.getMessage());

x.printStackTrace();

System.exit(2);

}

if (lines.size() != GOLDEN_FASTA_LINES.length)

{

String err = "Wrong number of lines in HW4.fasta: saw " + lines.size() + ", expected " + GOLDEN_FASTA_LINES.length;

deduct(Category.FileConverter, err, 10);

}

else

{

for (int i=0; i

{

if (lines.get(i).equals(GOLDEN_FASTA_LINES[i]))

continue;

String err = "Unexpected line " + (i+1) + " in output: saw "+ lines.get(i) + ", expected " + GOLDEN_FASTA_LINES[i];

deduct(Category.FileConverter, err, 10);

}

}

}

private void testSubjective()

{

SubjectiveDialog dia = new SubjectiveDialog();

dia.setModal(true);

dia.setVisible(true);

gradersNotes = dia.getSubjectivePanel().getNotes();

int readabilityScore = dia.getSubjectivePanel().getReadabilityScore();

styleDeduction = Category.Style.getMaxDeductions() - readabilityScore;

int commentsScore = dia.getSubjectivePanel().getCommentsScore();

commentDeduction = Category.Comments.getMaxDeductions() - commentsScore;

}

private class SubjectivePanel extends JPanel

{

private ArrayList sliders;

private JTextArea notesTA;

SubjectivePanel()

{

sliders = new ArrayList<>();

setLayout(new BorderLayout());

setLayout(new GridLayout(1, 3));

Category[] cats = { Category.Style, Category.Comments };

for (Category cat: cats)

{

JPanel pan = new JPanel(new BorderLayout());

pan.add(new JLabel(cat.name()), BorderLayout.NORTH);

JSlider slider = new JSlider(0, cat.getMaxDeductions(), cat.getMaxDeductions());

slider.setMajorTickSpacing(1);

slider.setPaintTicks(true);

slider.setPaintLabels(true);

slider.setSnapToTicks(true);

pan.add(slider, BorderLayout.SOUTH);

sliders.add(slider);

add(pan);

}

notesTA = new JTextArea(10, 25);

JPanel commentsPan = new JPanel(new BorderLayout());

commentsPan.add(new JLabel("Your notes"), BorderLayout.NORTH);

commentsPan.add(notesTA, BorderLayout.CENTER);

add(commentsPan);

}

int getReadabilityScore()

{

return sliders.get(0).getValue();

}

int getCommentsScore()

{

return sliders.get(1).getValue();

}

String getNotes()

{

return notesTA.getText().trim();

}

}

private class SubjectiveDialog extends JDialog implements ActionListener

{

private SubjectivePanel subjPan;

SubjectiveDialog()

{

subjPan = new SubjectivePanel();

add(subjPan, BorderLayout.CENTER);

JPanel okPan = new JPanel();

JButton okBtn = new JButton("Ok");

okBtn.addActionListener(this);

okPan.add(okBtn);

add(okPan, BorderLayout.SOUTH);

pack();

}

public void actionPerformed(ActionEvent e)

{

setVisible(false);

}

SubjectivePanel getSubjectivePanel()

{

return subjPan;

}

}

private static void sop(Object x)

{

System.out.println(x);

}

public static void main(String[] args)

{

new DNAGrader().grade();

}

}

------------------------------

package dna;

//

// FastqRecord and FastaRecord should implement this.

//

// Remember that in implementing classes, the methods

// listed in the interface have to be public.

//

public interface DNARecord

{

String getDefline();

String getSequence();

}

------------------------------

package dna;

public class FastaRecord implements DNARecord

{

//

// Add a precondition check: throw RecordGFormatException if the 1st char of the defline is

// not '>'. You will have to change the ctor declaration to say that it throws

// the exception. The exception should contain a useful informative message.

//

public FastaRecord(String defline, String sequence)

{

}

// Initialize defline and sequence from the input record. The defline should be the

// defline of the fastq record, but with a '>' in the first position rather than a '@'.

// If you?e not sure how to do this, look up the substring method on the String API page.

public FastaRecord(FastqRecord fastqRec)

{

}

//

// Provide the 2 methods that satisfy the interface.

//

//

// Provide an equals() method.

//

//

// Provide a hashCode() method that returns the sum of the hashcodes of

// defline and sequence.

//

}

---------------------------------------------

package dna;

import java.io.*;

//

// Writes a fasta record to a print writer.

//

public class FastaWriter

{

// Write the rec as 2 separate lines: first the defline, then the sequence.

// To write something on a separate line, use the println() method of PrintWriter.

public void writeRecord(FastaRecord rec) throws IOException

{

}

}

----------------------------------------

package dna;

import java.io.*;

//

// Reads lines from a BufferedReader and builds a FastqReader.

//

public class FastqReader

{

// Returns next record in the file, or null if EOF (end-of-file).

public FastqRecord readRecord() throws IOException, RecordFormatException

{

// Read the defline from the BufferedReader. Return null if you read null,

// indicating end of file.

// Read the next 3 lines from the buffered reader. Construct and return

// a FastqRecord.

}

}

-----------------------------------------

package dna;

//

// FastqRecord contains the defline, sequence, and quality string

// from a record in a fastq file.

//

public class FastqRecord implements DNARecord

{

//

// Add a precondition check: throw FastqException if the 1st char of the defline is

// not '@'. You will have to change the ctor declaration to say that it throws

// the exception. The exception should contain a useful informative message.

//

public FastqRecord(String defline, String sequence, String quality)

{

}

//

// Provide the 2 methods that satisfy the interface.

//

//

// Provide an equals() method that checks for deep equality of all 3 instance variables.

// When checking string variables, be sure to do it like this:

// this.defline.equals(that.defline)

// and not like this:

// this.defline == that.defline

//

//

// Provide a hashCode() method that returns the sum of the hashcodes of

// defline, sequence, and quality.

//

//

// Complete this. Return true if quality contains at least one '!' char.

//

public boolean qualityIsLow()

{

}

//

// Complete this. Return the sum of the hash codes of defline, sequence, and quality.

//

public boolean hashCode()

{

}

}

-----------------------------

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");

}

}

---------------------------------

package dna;

public class RecordFormatException extends Exception

{

// Complete this.

public RecordFormatException(String message)

}

----------------------------

[HW4.fastq]

@Record1 ACGTACGTACGTACGTACGT + !82r8!!efidfiuwfgw77 @Record2 ACGTATTCGACGACTCGTACGTACGT + !!!!!!!!!!!!!!!!!!!!!!!!!! @Record3 TATTAATCTGACT + +880%^$^^*877 @Record4 TATTAATCTGACT + +*%^$^^^^*877 @Record5 GTGATATCGACGTACGTACGTCATGCATGACTGCAGTCAGTACGTCATCAG + 8887876987678#$%^#876585#$6758758753327857657576578 >Record6 GTACTACGTACGTTGGACTAGTACGTACGT + !@67898687IUTUYT86!!%66%%^^%^^ @Record7 GTACTACGTACGTTGGACTAGTACGTACGT + [@678922287IUTUYT869%%66%%^^%^^

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications 9th International Conference Dasfaa 2004 Jeju Island Korea March 2004 Proceedings Lncs 2973

Authors: YoonJoon Lee ,Jianzhong Li ,Kyu-Young Whang

2004th Edition

3540210474, 978-3540210474

More Books

Students also viewed these Databases questions

Question

Amides, Quick Review

Answered: 1 week ago

Question

Solve for x: 2(3x 1)2(x + 5) = 12

Answered: 1 week ago