Class SimpleRichFeature

java.lang.Object
org.biojava.utils.AbstractChangeable
org.biojavax.bio.seq.SimpleRichFeature
All Implemented Interfaces:
Comparable, Annotatable, Feature, FeatureHolder, StrandedFeature, Changeable, RichFeature, RichFeatureRelationshipHolder, RankedCrossRefable, RichAnnotatable

public class SimpleRichFeature extends AbstractChangeable implements RichFeature
A simple implementation of RichFeature.
Since:
1.5
Author:
Richard Holland, Mark Schreiber, Bubba Puryear, George Waldon
  • Constructor Details

  • Method Details

    • makeTemplate

      Create a new Template that could be used to generate a feature identical to this one. The fields of the template can be edited without changing the feature.
      Specified by:
      makeTemplate in interface Feature
      Returns:
      a new Template that would make a feature like this one
    • getAnnotation

      Should return the associated annotation object.
      Specified by:
      getAnnotation in interface Annotatable
      Returns:
      an Annotation object, never null
    • getRichAnnotation

      Return the associated annotation object.
      Specified by:
      getRichAnnotation in interface RichAnnotatable
      Returns:
      a RichAnnotation object, never null
    • getNoteSet

      public Set getNoteSet()
      Returns the set of notes associated with this object. Would normally delegate call to internal RichAnnotation instance. Warning this method gives access to the original Collection not a copy. This is required by Hibernate. If you modify the object directly the behaviour may be unpredictable.
      Specified by:
      getNoteSet in interface RichAnnotatable
      Returns:
      set a set of Note objects.
      See Also:
    • setNoteSet

      public void setNoteSet(Set notes) throws ChangeVetoException
      Clears the notes associated with this object and replaces them with the contents of this set. Would normally delegate call to internal RichAnnotation instance. Warning this method gives access to the original Collection not a copy. This is required by Hibernate. If you modify the object directly the behaviour may be unpredictable.
      Specified by:
      setNoteSet in interface RichAnnotatable
      Parameters:
      notes - the set of Note objects to replace the existing ones with.
      Throws:
      ChangeVetoException - if the set is null or contains any objects that are not Note objects.
      See Also:
    • setName

      public void setName(String name) throws ChangeVetoException
      Sets the name of this feature.
      Specified by:
      setName in interface RichFeature
      Parameters:
      name - the name the feature should identify itself with.
      Throws:
      ChangeVetoException - if the new value is unacceptable.
    • getName

      public String getName()
      Returns the name of this feature.
      Specified by:
      getName in interface RichFeature
      Returns:
      the name.
    • setRank

      public void setRank(int rank) throws ChangeVetoException
      Sets the rank of this feature.
      Specified by:
      setRank in interface RichFeature
      Parameters:
      rank - the rank the feature should identify itself with.
      Throws:
      ChangeVetoException - if the new value is unacceptable.
    • getRank

      public int getRank()
      Returns the rank of this feature.
      Specified by:
      getRank in interface RichFeature
      Returns:
      the rank.
    • getSequence

      Return the Sequence object to which this feature is (ultimately) attached. For top level features, this will be equal to the FeatureHolder returned by getParent.
      Specified by:
      getSequence in interface Feature
      Returns:
      the ultimate parent Sequence
    • getSource

      public String getSource()
      The source of the feature. This may be a program or process.
      Specified by:
      getSource in interface Feature
      Returns:
      the source, or generator
    • setSource

      public void setSource(String source) throws ChangeVetoException
      Change the source of the Feature.
      Specified by:
      setSource in interface Feature
      Parameters:
      source - the new source String
      Throws:
      ChangeVetoException - if the source can't be altered
    • getSourceTerm

      public Term getSourceTerm()
      An ontology term defining the source of this feature. This is optional, and will default to OntoTools.ANY in implementations which aren't ontology aware.
      Specified by:
      getSourceTerm in interface Feature
    • setSourceTerm

      Set the source ontology-term for this feature. If this succeeds, it will generally also change the source name.
      Specified by:
      setSourceTerm in interface Feature
      Throws:
      ChangeVetoException - if changes are not allowed
      InvalidTermException - if the specified term is not an acceptable type for this feature.
    • getType

      public String getType()
      The type of the feature.
      Specified by:
      getType in interface Feature
      Returns:
      the type of this sequence
    • setType

      public void setType(String type) throws ChangeVetoException
      Change the type of this feature.
      Specified by:
      setType in interface Feature
      Parameters:
      type - new type String
      Throws:
      ChangeVetoException - if the type can't be altered
    • getTypeTerm

      public Term getTypeTerm()
      An ontology term defining the type of feature. This is optional, and will default to OntoTools.ANY in implementations which aren't ontology aware.
      Specified by:
      getTypeTerm in interface Feature
    • setTypeTerm

      Set the type ontology-term for this feature. If this succeeds, it will generally also change the source name.
      Specified by:
      setTypeTerm in interface Feature
      Throws:
      ChangeVetoException - if changes are not allowed
      InvalidTermException - if the specified term is not an acceptable type for this feature.
    • getSymbols

      Return a list of symbols that are contained in this feature.

      The symbols may not be contiguous in the original sequence, but they will be concatenated together in the resulting SymbolList.

      The order of the Symbols within the resulting symbol list will be according to the concept of ordering within the location object.

      If the feature is on the negative strand then the SymbolList will be reverse-complemented as appropriate.

      Specified by:
      getSymbols in interface Feature
      Specified by:
      getSymbols in interface StrandedFeature
      Returns:
      a SymbolList containing each symbol of the parent sequence contained within this feature in the order they appear in the parent
    • getLocation

      The location of this feature.

      The location may be complicated, or simply a range. The annotation is assumed to apply to all the region contained within the location.

      Specified by:
      getLocation in interface Feature
      Returns:
      a Location anchoring this feature
    • setLocation

      public void setLocation(Location loc) throws ChangeVetoException
      The new location for this feature.

      The location may be complicated or simply a range. The annotation is assumed to apply to the entire region contained within the location. Any values returned from methods that rely on the old location must not be affected.

      Specified by:
      setLocation in interface Feature
      Parameters:
      loc - the new Location for this feature
      Throws:
      ChangeVetoException - if the location can't be altered
    • getParent

      Return the FeatureHolder to which this feature has been attached. This will be a Sequence object for top level features, and a Feature object for features further down the tree.
      Specified by:
      getParent in interface Feature
    • setParent

      public void setParent(FeatureHolder parent) throws ChangeVetoException
      Sets the parent of this feature.
      Specified by:
      setParent in interface RichFeature
      Parameters:
      parent - the parent the feature should identify itself with.
      Throws:
      ChangeVetoException - if the new value is unacceptable.
    • getRankedCrossRefs

      Returns the set of all ranked cross references associated with an object. Warning this method gives access to the original Collection not a copy. This is required by Hibernate. If you modify the object directly the behaviour may be unpredictable.
      Specified by:
      getRankedCrossRefs in interface RankedCrossRefable
      Returns:
      a set of RankedCrossRef objects.
    • setRankedCrossRefs

      public void setRankedCrossRefs(Set crossrefs) throws ChangeVetoException
      Sets the ranked cross references associated with an object. Null will throw an exception but the empty set is fine. Warning this method gives access to the original Collection not a copy. This is required by Hibernate. If you modify the object directly the behaviour may be unpredictable.
      Specified by:
      setRankedCrossRefs in interface RankedCrossRefable
      Parameters:
      crossrefs - a set of RankedCrossRef objects.
      Throws:
      ChangeVetoException - if the set was null or any of its contents were not RankedCrossRef objects.
    • addRankedCrossRef

      public void addRankedCrossRef(RankedCrossRef crossref) throws ChangeVetoException
      Adds a ranked cross reference to the existing set. If already present, this call is ignored. Null values are not acceptable.
      Specified by:
      addRankedCrossRef in interface RankedCrossRefable
      Parameters:
      crossref - the ranked cross reference to add.
      Throws:
      ChangeVetoException - if the parameter is null.
    • removeRankedCrossRef

      Removes a ranked cross reference from the existing set. If not present, this call is ignored. Null values are not acceptable.
      Specified by:
      removeRankedCrossRef in interface RankedCrossRefable
      Parameters:
      crossref - the ranked cross reference to remove.
      Throws:
      ChangeVetoException - if the parameter is null.
    • getFeatureRelationshipSet

      Returns the set of relationships held in this feature holder. Warning this method gives access to the original Collection not a copy. This is required by Hibernate. If you modify the object directly the behaviour may be unpredictable.
      Specified by:
      getFeatureRelationshipSet in interface RichFeatureRelationshipHolder
      Returns:
      a set of RichFeatureRelationship objects.
    • setFeatureRelationshipSet

      Clears the relations from this feature holder and replaces them with a new set. Warning this method gives access to the original Collection not a copy. This is required by Hibernate. If you modify the object directly the behaviour may be unpredictable.
      Specified by:
      setFeatureRelationshipSet in interface RichFeatureRelationshipHolder
      Parameters:
      relationships - the new set of features this holder should have. The set must contain only RichFeatureRelationship objects.
      Throws:
      ChangeVetoException - if the new set could not be installed.
    • addFeatureRelationship

      Adds a relationship to this feature holder.
      Specified by:
      addFeatureRelationship in interface RichFeatureRelationshipHolder
      Parameters:
      relationship - the relationship to add.
      Throws:
      ChangeVetoException - if the relationship is unacceptable.
    • removeFeatureRelationship

      Removes a relationship from this feature holder.
      Specified by:
      removeFeatureRelationship in interface RichFeatureRelationshipHolder
      Parameters:
      relationship - the relationship to remove.
      Throws:
      ChangeVetoException - if it cannot be removed.
    • containsFeature

      public boolean containsFeature(Feature f)
      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
    • countFeatures

      public int countFeatures()
      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
    • createFeature

      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
      Throws:
      BioException - if something went wrong during creating the feature
      ChangeVetoException - if this FeatureHolder does not support creation of new features, or if the change was vetoed
    • features

      public Iterator features()
      Iterate over any child features which are held by this feature. The order of iteration MAY be significant for some types of Feature.
      Specified by:
      features in interface Feature
      Specified by:
      features in interface FeatureHolder
      Returns:
      an Iterator
    • filter

      Query this set of features using a supplied FeatureFilter.
      Specified by:
      filter in interface FeatureHolder
      Parameters:
      filter - the FeatureFilter to apply.
      Returns:
      all features in this container which match filter.
    • filter

      public FeatureHolder filter(FeatureFilter fc, boolean recurse)
      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
      Parameters:
      fc - the FeatureFilter to apply
      recurse - true if all features-of-features should be scanned, and a single flat collection of features returned, or false if just immediate children should be filtered.
    • getSchema

      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
    • removeFeature

      Remove a feature from this FeatureHolder.
      Specified by:
      removeFeature in interface FeatureHolder
      Throws:
      ChangeVetoException - if this FeatureHolder does not support feature removal or if the change was vetoed
      BioException - if there was an error removing the feature
    • setStrand

      Set the strand that this feature lies upon.

      This will be one of StrandedFeature.POSITIVE or NEGATIVE. NOT IMPLEMENTED.

      Specified by:
      setStrand in interface StrandedFeature
      Parameters:
      strand - a Strand.
      Throws:
      ChangeVetoException - if the strand may not be changed.
    • getStrand

      Retrieve the strand that this feature lies upon.

      This will be one of StrandedFeature.POSITIVE or NEGATIVE.

      Specified by:
      getStrand in interface StrandedFeature
      Returns:
      one of the Strand constants
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Features are equal when they have the same rank, parent, type, and source. Features which are not instance of RichFeature are given a rank of zero.
      Overrides:
      equals in class Object
    • compareTo

      public int compareTo(Object o)
      Features are sorted first by rank, then parent, type, and source. If both parents are not comparable then this part of the sorting is skipped. Features which are not instance of RichFeature are given a rank of zero.
      Specified by:
      compareTo in interface Comparable
    • toString

      public String toString()
      Form: "(#rank) parent:type,source(location)"
      Overrides:
      toString in class Object
    • getId

      public Integer getId()
      Gets the Hibernate ID. Should be used with caution.
      Returns:
      the Hibernate ID, if using Hibernate.
    • setId

      public void setId(Integer id)
      Sets the Hibernate ID. Should be used with caution.
      Parameters:
      id - the Hibernate ID, if using Hibernate.