-
Notifications
You must be signed in to change notification settings - Fork 10
Read SequenceIO
Laurent Jourdren edited this page Mar 13, 2015
·
1 revision
Files with ReadSequence
data can be read with a class implementing the ReadSequenceReader
interface and written with a class implementing the ReadSequenceWriter
interface. Currently the Fasta format and TFQ (see Read Sequence) are handled in Eoulsan.
As the ReadSequenceReader
extends the Iterable
and Iterator
interface, it is quite easy to read the entries of a FASTQ using a for
loop:
ReadSequenceReader reader = new FastqReader(new File("in.fastq");
for (ReadSequence read : reader) {
System.out.println(read);
}
// Throw an exception if an error has occurred while reading data
reader.throwException();
reader.close();
The reading of a TFQ works like reading a FASTQ file:
ReadSequenceReader reader = new TFQReader(new File("in.tfq");
for (ReadSequence read : reader) {
System.out.println(read);
}
reader.close();
Writing a FASTQ file is also very easy, you just have to create the FastqWriter
and call the write(ReadSequence)
method to add the sequences to the file. Don't forget to close the file after adding the last sequence of the file.
ReadSequence read1 = new Sequence(1, "seq1", "AAAATTTT", "!''*((((");
ReadSequence read2 = new Sequence(2, "seq2", "GGGGCCCC", "***+))%%");
ReadSequenceWriter writer = new FastqWriter(new File("out.fasta");
writer.write(read1);
writer.write(read2);
writer.close();
The writing of a TFQ works like writing a FASTQ file:
ReadSequence read1 = new Sequence(1, "seq1", "AAAATTTT", "!''*((((");
ReadSequence read2 = new Sequence(2, "seq2", "GGGGCCCC", "***+))%%");
ReadSequenceWriter writer = new TFQWriter(new File("out.fasta");
writer.write(read1);
writer.write(read2);
writer.close();