-
Notifications
You must be signed in to change notification settings - Fork 10
SequenceIO
Laurent Jourdren edited this page Mar 26, 2015
·
2 revisions
WARNING: This documentation is outdated and will soon be updated.
Files with Sequence
data can be read with a class implementing the SequenceReader
interface and written with a class implementing the SequenceWriter
interface. Currently only the Fasta format is handled in Eoulsan.
As the SequenceReader
extends the Iterable
and Iterator
interface, it is quite easy to read the entries of a FASTA using a for
loop:
SequenceReader reader = new FastaReader(new File("in.fasta");
for (Sequence seq : reader) {
System.out.println(seq);
}
// Throw an exception if an error has occured while reading data
reader.throwException();
reader.close();
Writing a FASTA file is also very easy, you just have to create the FastaWriter
and call the write(Sequence)
method to add the sequences to the file. Don't forget to close the file after adding the last sequence of the file.
Sequence seq1 = new Sequence(1, "seq1", "AAAATTTT");
Sequence seq2 = new Sequence(2, "seq2", "GGGGCCCC");
SequenceWriter writer = new FastaWriter(new File("out.fasta");
writer.write(seq1);
writer.write(seq2);
writer.close();