[Biojava-l] Re: problem with accessing the fasta format files written using biojava
Thomas Down
td2@sanger.ac.uk
Wed, 20 Jun 2001 14:51:27 +0100
On Wed, Jun 20, 2001 at 03:52:08PM +0200, Sarath wrote:
> hi
> has anybody encountered a problem while accessing files written in fasta
> format using biojava .. following is a piece a code which i used
> in a program to redirect a sequence to a text file and then when i try to
> use the file it gives exceptions
> while (stream.hasNext()) {
>
> Sequence seq = stream.nextSequence();
> SequenceFormat seqFormat=new FastaFormat();
> PrintStream str = new PrintStream(System.out);
> seqFormat.writeSequence(seq, str);
> str.println(seq);
> }
That last line `str.println(seq)' is your problem. You're
writing the sequence in Fasta format in the normal BioJava-ish
way. You then try to write the Sequence object directly to
the output stream. Since the Java I/O code doesn't know any
special behaviour for printing BioJava sequences, it calls
the toString() method, which gives you a string like:
> org.biojava.bio.seq.impl.SimpleSequence@2697a1
(which isn't hugely helpful -- we should override toString
to return something a bit more useful. But this isn't
strictly speaking a bug).
If you remove that `println' call, you'll get the output you
expect.
Thomas.