[Biojava-l] implementing writeSequence for EMBL/Genbank
Keith James
kdj@sanger.ac.uk
26 Feb 2001 10:15:36 +0000
>>>>> "Simon" == Simon Brocklehurst <simon.brocklehurst@CambridgeAntibody.com> writes:
[...]
Simon> Passing in an arbritray formatting object certainly doesn't
Simon> seem the right thing to do - in principle, I think you know
Simon> in advance the precise details of the information you want
Simon> to dispatch? I'm not convinced, however, that
Simon> parameterising the writeSequence method in a different way
Simon> is a bad thing to do though i.e. by a discriminator String
Simon> or integer constant.
Simon> I'm sure you know it well, but in case you don't you might
Simon> want to have a look at the Factory Method design pattern.
Simon> This is well suited to your problem - which seems to be one
Simon> of essentially creating a multiple, fixed number of types
Simon> of object - EMBL, SwissProt etc.
Thanks for the pointer. I don't have a programming background, so I'm
still picking up things like this. Luckily there seem to be loads of
web sites on design patterns.
Simon> Without thinking about it too hard, it seems to me that
Simon> adding a method such as:
Simon> void writeSequence(Sequence seq, String discriminator,
Simon> java.io.PrintStream os)
Simon> or
Simon> void writeSequence(Sequence seq, int discriminator,
Simon> java.io.PrintStream os)
Simon> to the SequenceFormat interface won't break any existing
Simon> code?
You're right. I've had a look under the hood of EmblLikeFormat and
added a new writeSequence(Sequence seq, String format, PrintStream
os). The correct file-former then gets loaded dynamically.
I've made the classes which convert Sequence objects back into files
implement SeqIOListener with the eventual hope of being able to
round-trip between file formats without instantiating anything. This
also makes it possible to filter on the way out. Currently I'm using
an adapter which takes Sequence objects and breaks them into stream of
SeqIO events to test this and the skeleton code seems to be working.
cheers,
--
-= Keith James - kdj@sanger.ac.uk - http://www.sanger.ac.uk/Users/kdj =-
The Sanger Centre, Wellcome Trust Genome Campus, Hinxton, Cambs CB10 1SA