org.biojava.bio.seq
Class ProjectedFeatureHolder

java.lang.Object
  extended byorg.biojava.utils.AbstractChangeable
      extended byorg.biojava.bio.seq.AbstractFeatureHolder
          extended byorg.biojava.bio.seq.ProjectedFeatureHolder
All Implemented Interfaces:
Changeable, FeatureHolder, ProjectionContext

public class ProjectedFeatureHolder
extends AbstractFeatureHolder
implements FeatureHolder, ProjectionContext

Helper class for projecting Feature objects into an alternative coordinate system. This class offers a view onto a set of features, projecting them into a different coordinate system, and also changing their parent property. The destination coordinate system can run in the opposite direction from the source, in which case the strand property of StrandedFeatures is flipped.

The projected features returned by this class are small proxy objects. Proxy classes are autogenerated on demand for any sub-interface of Feature by the ProjectionEngine class.

Since:
1.1
Author:
Thomas Down, Matthew Pocock

Nested Class Summary
 
Nested classes inherited from class org.biojava.bio.seq.FeatureHolder
FeatureHolder.EmptyFeatureHolder
 
Field Summary
 
Fields inherited from interface org.biojava.bio.seq.FeatureHolder
EMPTY_FEATURE_HOLDER, FEATURES, SCHEMA
 
Constructor Summary
ProjectedFeatureHolder(FeatureHolder fh, FeatureFilter filter, FeatureHolder parent, int translation, boolean oppositeStrand)
          Deprecated. Now just wraps up a LazyFilterFeatureHolder
ProjectedFeatureHolder(FeatureHolder fh, FeatureHolder parent, int translation, boolean oppositeStrand)
          Construct a new FeatureHolder which projects a set of features into a new coordinate system.
 
Method Summary
 void addChangeListener(Feature f, ChangeListener cl, ChangeType ct)
          Delegate for addChangeListener
 boolean containsFeature(Feature f)
          Check if the feature is present in this holder.
 int countFeatures()
          Count how many features are contained.
 Feature createFeature(Feature.Template templ)
          Create a new Feature, and add it to this FeatureHolder.
 Feature createFeature(Feature f, Feature.Template templ)
          Delegate for createFeature
 java.util.Iterator features()
          Iterate over the features in no well defined order.
 FeatureHolder filter(FeatureFilter ff)
          Query this set of features using a supplied FeatureFilter.
 FeatureHolder filter(FeatureFilter ff, boolean recurse)
          Return a new FeatureHolder that contains all of the children of this one that passed the filter fc.
protected  ChangeEvent forwardChangeEvent(ChangeEvent cev)
          Called internally to generate a forwarded version of a ChangeEvent from our underlying FeatureHolder
protected  ChangeEvent forwardFeatureChangeEvent(Feature f, ChangeEvent cev)
          Called internally to generate a forwarded version of a ChangeEvent from a ProjectedFeature
 Annotation getAnnotation(Feature f)
          Get the annotation bundle of the projected feature.
 Location getLocation(Feature f)
          Get the location of the projected feature
 FeatureHolder getParent()
          Return the parent of all top-level features in this FeatureHolder.
 FeatureHolder getParent(Feature f)
          Get the parent FeatureHolder into which a feature should be projected
 FeatureFilter getSchema()
          Return a schema-filter for this FeatureHolder.
 FeatureFilter getSchema(Feature f)
          Delegate for getSchema
 Sequence getSequence(Feature f)
          Get the Sequence which defines the coordinate system for the projected feature.
 StrandedFeature.Strand getStrand(StrandedFeature sf)
          Get the strand of the projected feature.
 int getTranslation()
          Return the translation component of the transformation applied by this FeatureHolder
protected  FeatureHolder getWrapped()
           
 boolean isOppositeStrand()
          Return true if projected features should be flipped to the opposite strand
protected  FeatureHolder makeProjectionSet(FeatureHolder fh)
          Called internally to construct a lightweight projected view of a set of features
 FeatureHolder projectChildFeatures(Feature f, FeatureHolder parent)
          Get the child features of the projected feature.
 Feature projectFeature(Feature f)
          Create a single projected feature using the rules of this ProjectedFeatureHolder.
 void removeChangeListener(Feature f, ChangeListener cl, ChangeType ct)
          Delegate for removeChangeListener
 void removeFeature(Feature f)
          Remove a feature from this FeatureHolder.
 void removeFeature(Feature f, Feature f2)
          Delegate for removeFeature
protected  FeatureFilter transformFilter(FeatureFilter ff)
          Called to transform a FeatureFilter applying to our parent FeatureHolder into the coordinate system of our parent.
protected  Location transformLocation(Location oldLoc)
          Called to transform a location from underlying to projection coordinates.
protected  StrandedFeature.Strand transformStrand(StrandedFeature.Strand strand)
          Called to transform a strand property between projection and underlying coordinates.
protected  FeatureFilter untransformFilter(FeatureFilter ff)
          Called to transform a FeatureFilter applying to our projections into a corresponding filter on the parent FeatureHolder.
protected  Location untransformLocation(Location oldLoc)
          Called to transform a location from projection to underlying coordinates.
 
Methods inherited from class org.biojava.utils.AbstractChangeable
addChangeListener, addChangeListener, generateChangeSupport, getChangeSupport, hasListeners, isUnchanging, removeChangeListener, removeChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.biojava.utils.Changeable
addChangeListener, addChangeListener, isUnchanging, removeChangeListener, removeChangeListener
 

Constructor Detail

ProjectedFeatureHolder

public ProjectedFeatureHolder(FeatureHolder fh,
                              FeatureFilter filter,
                              FeatureHolder parent,
                              int translation,
                              boolean oppositeStrand)
Deprecated. Now just wraps up a LazyFilterFeatureHolder

Construct a new FeatureHolder which projects a set of features into a new coordinate system. If translation is 0 and oppositeStrand is false, the features are simply reparented without any transformation.

Parameters:
fh - The set of features to project.
filter - A FeatureFilter to apply to the set of features before projection.
parent - The FeatureHolder which is to act as parent for the projected features.
translation - The translation to apply to map locations into the projected coordinate system. This is the point in the destination coordinate system which is equivalent to 0 in the source coordinate system.
oppositeStrand - true if translating into the opposite coordinate system. This alters the transformation applied to locations, and also flips the strand property of StrandedFeatures.

ProjectedFeatureHolder

public ProjectedFeatureHolder(FeatureHolder fh,
                              FeatureHolder parent,
                              int translation,
                              boolean oppositeStrand)
Construct a new FeatureHolder which projects a set of features into a new coordinate system. If translation is 0 and oppositeStrand is false, the features are simply reparented without any transformation.

Parameters:
fh - The set of features to project.
parent - The FeatureHolder which is to act as parent for the projected features.
translation - The translation to apply to map locations into the projected coordinate system. This is the point in the destination coordinate system which is equivalent to 0 in the source coordinate system.
oppositeStrand - true if translating into the opposite coordinate system. This alters the transformation applied to locations, and also flips the strand property of StrandedFeatures.
Method Detail

getWrapped

protected FeatureHolder getWrapped()

features

public java.util.Iterator features()
Description copied from interface: FeatureHolder
Iterate over the features in no well defined order.

Specified by:
features in interface FeatureHolder
Returns:
an Iterator

countFeatures

public int countFeatures()
Description copied from interface: FeatureHolder
Count how many features are contained.

Specified by:
countFeatures in interface FeatureHolder
Returns:
a positive integer or zero, equal to the number of features contained

containsFeature

public boolean containsFeature(Feature f)
Description copied from interface: FeatureHolder
Check if the feature is present in this holder.

Specified by:
containsFeature in interface FeatureHolder
Parameters:
f - the Feature to check
Returns:
true if f is in this set

filter

public FeatureHolder filter(FeatureFilter ff)
Description copied from interface: FeatureHolder
Query this set of features using a supplied FeatureFilter.

Specified by:
filter in interface FeatureHolder
Overrides:
filter in class AbstractFeatureHolder

filter

public FeatureHolder filter(FeatureFilter ff,
                            boolean recurse)
Description copied from interface: FeatureHolder
Return a new FeatureHolder that contains all of the children of this one that passed the filter fc. This method is scheduled for deprecation. Use the 1-arg filter instead.

Specified by:
filter in interface FeatureHolder
Overrides:
filter in class AbstractFeatureHolder

createFeature

public Feature createFeature(Feature.Template templ)
                      throws ChangeVetoException,
                             BioException
Description copied from interface: FeatureHolder
Create a new Feature, and add it to this FeatureHolder. This method will generally only work on Sequences, and on some Features which have been attached to Sequences.

Specified by:
createFeature in interface FeatureHolder
Overrides:
createFeature in class AbstractFeatureHolder
Throws:
ChangeVetoException
BioException

removeFeature

public void removeFeature(Feature f)
                   throws ChangeVetoException
Description copied from interface: FeatureHolder
Remove a feature from this FeatureHolder.

Specified by:
removeFeature in interface FeatureHolder
Overrides:
removeFeature in class AbstractFeatureHolder
Throws:
ChangeVetoException

getSchema

public FeatureFilter getSchema()
Description copied from interface: FeatureHolder
Return a schema-filter for this FeatureHolder. This is a filter which all Features immediately contained by this FeatureHolder will match. It need not directly match their child features, but it can (and should!) provide information about them using FeatureFilter.OnlyChildren filters. In cases where there is no feature hierarchy, this can be indicated by including FeatureFilter.leaf in the schema filter.

For the truly non-informative case, it is possible to return FeatureFilter.all. However, it is almost always possible to provide slightly more information that this. For example, Sequence objects should, at a minimum, return FeatureFilter.top_level. Feature objects should, as a minimum, return FeatureFilter.ByParent(new FeatureFilter.ByFeature(this)).

Specified by:
getSchema in interface FeatureHolder
Returns:
the schema filter

untransformFilter

protected FeatureFilter untransformFilter(FeatureFilter ff)
Called to transform a FeatureFilter applying to our projections into a corresponding filter on the parent FeatureHolder.

Since:
1.3

transformFilter

protected FeatureFilter transformFilter(FeatureFilter ff)
Called to transform a FeatureFilter applying to our parent FeatureHolder into the coordinate system of our parent.

Since:
1.3

transformStrand

protected StrandedFeature.Strand transformStrand(StrandedFeature.Strand strand)
Called to transform a strand property between projection and underlying coordinates.


transformLocation

protected Location transformLocation(Location oldLoc)
Called to transform a location from underlying to projection coordinates.


untransformLocation

protected Location untransformLocation(Location oldLoc)
Called to transform a location from projection to underlying coordinates.


projectFeature

public Feature projectFeature(Feature f)
Create a single projected feature using the rules of this ProjectedFeatureHolder.


getTranslation

public int getTranslation()
Return the translation component of the transformation applied by this FeatureHolder


isOppositeStrand

public boolean isOppositeStrand()
Return true if projected features should be flipped to the opposite strand


getParent

public FeatureHolder getParent()
Return the parent of all top-level features in this FeatureHolder.


makeProjectionSet

protected FeatureHolder makeProjectionSet(FeatureHolder fh)
Called internally to construct a lightweight projected view of a set of features


getParent

public FeatureHolder getParent(Feature f)
Description copied from interface: ProjectionContext
Get the parent FeatureHolder into which a feature should be projected

Specified by:
getParent in interface ProjectionContext

getSequence

public Sequence getSequence(Feature f)
Description copied from interface: ProjectionContext
Get the Sequence which defines the coordinate system for the projected feature. This should be reachable by one or more getParent operations.

Specified by:
getSequence in interface ProjectionContext

getLocation

public Location getLocation(Feature f)
Description copied from interface: ProjectionContext
Get the location of the projected feature

Specified by:
getLocation in interface ProjectionContext

getStrand

public StrandedFeature.Strand getStrand(StrandedFeature sf)
Description copied from interface: ProjectionContext
Get the strand of the projected feature.

Specified by:
getStrand in interface ProjectionContext

getAnnotation

public Annotation getAnnotation(Feature f)
Description copied from interface: ProjectionContext
Get the annotation bundle of the projected feature. This will often (but not always) be identical to that of the underlying feature.

Specified by:
getAnnotation in interface ProjectionContext

projectChildFeatures

public FeatureHolder projectChildFeatures(Feature f,
                                          FeatureHolder parent)
Description copied from interface: ProjectionContext
Get the child features of the projected feature.

Specified by:
projectChildFeatures in interface ProjectionContext

createFeature

public Feature createFeature(Feature f,
                             Feature.Template templ)
                      throws BioException,
                             ChangeVetoException
Description copied from interface: ProjectionContext
Delegate for createFeature

Specified by:
createFeature in interface ProjectionContext
Throws:
BioException
ChangeVetoException

removeFeature

public void removeFeature(Feature f,
                          Feature f2)
                   throws ChangeVetoException
Description copied from interface: ProjectionContext
Delegate for removeFeature

Specified by:
removeFeature in interface ProjectionContext
Throws:
ChangeVetoException

getSchema

public FeatureFilter getSchema(Feature f)
Description copied from interface: ProjectionContext
Delegate for getSchema

Specified by:
getSchema in interface ProjectionContext

addChangeListener

public void addChangeListener(Feature f,
                              ChangeListener cl,
                              ChangeType ct)
Description copied from interface: ProjectionContext
Delegate for addChangeListener

Specified by:
addChangeListener in interface ProjectionContext

removeChangeListener

public void removeChangeListener(Feature f,
                                 ChangeListener cl,
                                 ChangeType ct)
Description copied from interface: ProjectionContext
Delegate for removeChangeListener

Specified by:
removeChangeListener in interface ProjectionContext

forwardFeatureChangeEvent

protected ChangeEvent forwardFeatureChangeEvent(Feature f,
                                                ChangeEvent cev)
Called internally to generate a forwarded version of a ChangeEvent from a ProjectedFeature

Parameters:
f - the feature who's projection is due to receive an event.
Returns:
a tranformed event, or null to cancel the event.

forwardChangeEvent

protected ChangeEvent forwardChangeEvent(ChangeEvent cev)
Called internally to generate a forwarded version of a ChangeEvent from our underlying FeatureHolder