[Biojava-l] subsequences
Thomas Down
td2@sanger.ac.uk
Wed, 16 Jan 2002 10:28:53 +0000
On Wed, Jan 16, 2002 at 10:45:59AM +0100, Stein Aerts wrote:
> Hello,
> The SubSequence class is very usefull, but I have some problems when I use
> it:
> - If I create a subsequence of a sequence A, then all locations of the
> features in the subsequence are the locations of the original sequence A. Is
> there an easy way to overcome this problem?
This isn't true -- all features on a subsequence should be
`projected' onto the subsequence coordinate system. This means
that unless your subsequence starts at offset 1 on the parent
sequence, the features should have different locations.
I've just written an extra test module which checks this (and
a few other aspects of SubSequence function). The locations
are definitely being mapped as expected. If you are using a
CVS version of BioJava, this should be picked up next time
you update
If you're still having trouble, could you send me an example
which demonstrates the problem?
[Aside: I did actually find one minor bug affecting SubSequence --
the countFeatures method could potentially return an incorrect
value. This is fixed now, and all the other methods seem to be
behaving correctly].
> - I cannot create features on a subsequence (ChangeVetoException). Can a
> subsequence not be casted to a sequence?
Perhaps we should allow createFeatures on a SubSequence, and
create the requested feature at the appropriate (mapped)
position on the parent sequence (would this be useful to you?).
I think the reason this wasn't done originally is that, while
creating top level features on a SubSequence in this was is
reasonably simple to implement, creating new child features
of an existing feature would be rather harder. However, since
I refactored the feature projection system a couple of months
it's now rather easier to hook this functionality in.
An alternative solution which will work right now is:
Sequence seq1 = // ...whatever...
Sequence seq2 = new SubSequence(seq1, 1000, 2000);
Sequence seq3 = new ViewSequence(seq2);
seq3.createFeature(myTemplate);
This only creates new features on a VIEW of the sequence,
rather than writing them back to the parent sequence. However,
in many cases this might be the behaviour you want anyway.
Does this help at all?
Thomas.