[Biojava-l] Constructing features

Thomas Down td2@sanger.ac.uk
Tue, 29 May 2001 09:48:12 +0100


On Tue, May 29, 2001 at 09:30:48AM +0100, Dr S.M. Huen wrote:
> I have been trying to figure out how to construct a hierarchical tree of
> Features.  This is a consequence of trying to write a SeqIOListener
> that takes a stream of events generated from an XML parse and
> constructs an in-memory sequence with nested Features on it. Can you tell
> me whether I understand this correctly?
> 
> A feature can only be added by calling createFeature with a
> Feature.Template on a class that has a FeatureHolder.  Once done, you
> cannot add to the annonation bundle.  If this is the case, then when I
> receive startFeature events from the XML parser, I need to defer creation
> of the feature until the corresponding endFeature event as I may receive
> an addFeatureProperty I might want to add to the annotation field in the
> interim.

Yes, features are created by calling createFeature on a sequence
(for a top level feature) or on another feature (for nested
features).

The annotation issue is a bit awkward, since if you create
a feature with the annotation set to Annotation.EMPTY_ANNOTATION,
you /can't/ add extra annotation properties.  However, if you make
sure that the annotation is set to SimpleAnnotation or SmallAnnotation
(the latter is preferable, unless you're using more than about 15-20
properties), you can add extra properties at /any/ time (unless
somebody has added a listener which is vetoing your changes).

Take a look at the class SimpleSequenceBuilder for an example
of how to build trees like this, and some idea of how to
handle the properties.

> Does all this apply to ComponentFeatures too?

Pretty much, except that you can't create ComponentFeatures
on just any old sequence.  Currently the only implementation
which allows user-created components in SimpleAssembly.


   Thomas.