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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.biojava.bio.Annotatable
Annotatable.AnnotationForwarder
-
Nested classes/interfaces inherited from interface org.biojava.bio.seq.Feature
Feature.ByLocationComparator
-
Nested classes/interfaces inherited from interface org.biojava.bio.seq.FeatureHolder
FeatureHolder.EmptyFeatureHolder
-
Nested classes/interfaces inherited from interface org.biojavax.bio.seq.RichFeature
RichFeature.Template, RichFeature.Tools
-
Nested classes/interfaces inherited from interface org.biojava.bio.seq.StrandedFeature
StrandedFeature.Strand
-
-
Field Summary
-
Fields inherited from interface org.biojava.bio.Annotatable
ANNOTATION
-
Fields inherited from interface org.biojava.bio.seq.Feature
byLocationOrder, PROPERTY_DATA_KEY, SOURCE, TYPE
-
Fields inherited from interface org.biojava.bio.seq.FeatureHolder
EMPTY_FEATURE_HOLDER, FEATURES, SCHEMA
-
Fields inherited from interface org.biojavax.bio.seq.RichFeature
CROSSREF, LOCATION, NAME, PARENT, RANK, RELATION, SOURCETERM, TYPETERM
-
Fields inherited from interface org.biojava.bio.seq.StrandedFeature
NEGATIVE, POSITIVE, STRAND, UNKNOWN
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
SimpleRichFeature()
SimpleRichFeature(FeatureHolder parent, Feature.Template templ)
Creates a new instance of SimpleRichFeature based on a template.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addFeatureRelationship(RichFeatureRelationship relationship)
Adds a relationship to this feature holder.void
addRankedCrossRef(RankedCrossRef crossref)
Adds a ranked cross reference to the existing set.int
compareTo(Object o)
Features are sorted first by rank, then parent, type, and source.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 ft)
Create a new Feature, and add it to this FeatureHolder.boolean
equals(Object o)
Features are equal when they have the same rank, parent, type, and source.Iterator
features()
Iterate over any child features which are held by this feature.FeatureHolder
filter(FeatureFilter filter)
Query this set of features using a suppliedFeatureFilter
.FeatureHolder
filter(FeatureFilter fc, boolean recurse)
Return a new FeatureHolder that contains all of the children of this one that passed the filter fc.Annotation
getAnnotation()
Should return the associated annotation object.Set<RichFeatureRelationship>
getFeatureRelationshipSet()
Returns the set of relationships held in this feature holder.Integer
getId()
Gets the Hibernate ID.Location
getLocation()
The location of this feature.String
getName()
Returns the name of this feature.Set
getNoteSet()
Returns the set of notes associated with this object.FeatureHolder
getParent()
Return theFeatureHolder
to which this feature has been attached.int
getRank()
Returns the rank of this feature.Set<RankedCrossRef>
getRankedCrossRefs()
Returns the set of all ranked cross references associated with an object.RichAnnotation
getRichAnnotation()
Return the associated annotation object.FeatureFilter
getSchema()
Return a schema-filter for thisFeatureHolder
.Sequence
getSequence()
Return theSequence
object to which this feature is (ultimately) attached.String
getSource()
The source of the feature.Term
getSourceTerm()
An ontology term defining the source of this feature.StrandedFeature.Strand
getStrand()
Retrieve the strand that this feature lies upon.SymbolList
getSymbols()
Return a list of symbols that are contained in this feature.String
getType()
The type of the feature.Term
getTypeTerm()
An ontology term defining the type of feature.int
hashCode()
Feature.Template
makeTemplate()
Create a new Template that could be used to generate a feature identical to this one.void
removeFeature(Feature f)
Remove a feature from this FeatureHolder.void
removeFeatureRelationship(RichFeatureRelationship relationship)
Removes a relationship from this feature holder.void
removeRankedCrossRef(RankedCrossRef crossref)
Removes a ranked cross reference from the existing set.void
setFeatureRelationshipSet(Set<RichFeatureRelationship> relationships)
Clears the relations from this feature holder and replaces them with a new set.void
setId(Integer id)
Sets the Hibernate ID.void
setLocation(Location loc)
The new location for this feature.void
setName(String name)
Sets the name of this feature.void
setNoteSet(Set notes)
Clears the notes associated with this object and replaces them with the contents of this set.void
setParent(FeatureHolder parent)
Sets the parent of this feature.void
setRank(int rank)
Sets the rank of this feature.void
setRankedCrossRefs(Set crossrefs)
Sets the ranked cross references associated with an object.void
setSource(String source)
Change the source of the Feature.void
setSourceTerm(Term t)
Set the source ontology-term for this feature.void
setStrand(StrandedFeature.Strand strand)
Set the strand that this feature lies upon.void
setType(String type)
Change the type of this feature.void
setTypeTerm(Term t)
Set the type ontology-term for this feature.String
toString()
Form: "(#rank) parent:type,source(location)"-
Methods inherited from class org.biojava.utils.AbstractChangeable
addChangeListener, addChangeListener, generateChangeSupport, getChangeSupport, hasListeners, hasListeners, isUnchanging, removeChangeListener, removeChangeListener
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.biojava.utils.Changeable
addChangeListener, addChangeListener, isUnchanging, removeChangeListener, removeChangeListener
-
-
-
-
Constructor Detail
-
SimpleRichFeature
public SimpleRichFeature(FeatureHolder parent, Feature.Template templ) throws ChangeVetoException, InvalidTermException
Creates a new instance of SimpleRichFeature based on a template.- Parameters:
parent
- The parent feature holder.templ
- The template to construct the feature from.- Throws:
ChangeVetoException
- if we don't want to be like the template.InvalidTermException
- if any of the template terms are bad.
-
SimpleRichFeature
protected SimpleRichFeature()
-
-
Method Detail
-
makeTemplate
public Feature.Template 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 interfaceFeature
- Returns:
- a new Template that would make a feature like this one
-
getAnnotation
public Annotation getAnnotation()
Should return the associated annotation object.- Specified by:
getAnnotation
in interfaceAnnotatable
- Returns:
- an Annotation object, never null
-
getRichAnnotation
public RichAnnotation getRichAnnotation()
Return the associated annotation object.- Specified by:
getRichAnnotation
in interfaceRichAnnotatable
- 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 interfaceRichAnnotatable
- Returns:
- set a set of Note objects.
- See Also:
Note
-
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 interfaceRichAnnotatable
- 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:
Note
-
setName
public void setName(String name) throws ChangeVetoException
Sets the name of this feature.- Specified by:
setName
in interfaceRichFeature
- 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 interfaceRichFeature
- Returns:
- the name.
-
setRank
public void setRank(int rank) throws ChangeVetoException
Sets the rank of this feature.- Specified by:
setRank
in interfaceRichFeature
- 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 interfaceRichFeature
- Returns:
- the rank.
-
getSequence
public Sequence getSequence()
Return theSequence
object to which this feature is (ultimately) attached. For top level features, this will be equal to theFeatureHolder
returned bygetParent
.- Specified by:
getSequence
in interfaceFeature
- Returns:
- the ultimate parent Sequence
-
setSource
public void setSource(String source) throws ChangeVetoException
Change the source of the Feature.- Specified by:
setSource
in interfaceFeature
- 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 toOntoTools.ANY
in implementations which aren't ontology aware.- Specified by:
getSourceTerm
in interfaceFeature
-
setSourceTerm
public void setSourceTerm(Term t) throws ChangeVetoException, InvalidTermException
Set the source ontology-term for this feature. If this succeeds, it will generally also change the source name.- Specified by:
setSourceTerm
in interfaceFeature
- Throws:
ChangeVetoException
- if changes are not allowedInvalidTermException
- if the specified term is not an acceptable type for this feature.
-
setType
public void setType(String type) throws ChangeVetoException
Change the type of this feature.- Specified by:
setType
in interfaceFeature
- 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 toOntoTools.ANY
in implementations which aren't ontology aware.- Specified by:
getTypeTerm
in interfaceFeature
-
setTypeTerm
public void setTypeTerm(Term t) throws ChangeVetoException, InvalidTermException
Set the type ontology-term for this feature. If this succeeds, it will generally also change the source name.- Specified by:
setTypeTerm
in interfaceFeature
- Throws:
ChangeVetoException
- if changes are not allowedInvalidTermException
- if the specified term is not an acceptable type for this feature.
-
getSymbols
public SymbolList 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 interfaceFeature
- Specified by:
getSymbols
in interfaceStrandedFeature
- Returns:
- a SymbolList containing each symbol of the parent sequence contained within this feature in the order they appear in the parent
-
getLocation
public Location 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 interfaceFeature
- 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 interfaceFeature
- Parameters:
loc
- the new Location for this feature- Throws:
ChangeVetoException
- if the location can't be altered
-
getParent
public FeatureHolder getParent()
Return theFeatureHolder
to which this feature has been attached. This will be aSequence
object for top level features, and aFeature
object for features further down the tree.
-
setParent
public void setParent(FeatureHolder parent) throws ChangeVetoException
Sets the parent of this feature.- Specified by:
setParent
in interfaceRichFeature
- Parameters:
parent
- the parent the feature should identify itself with.- Throws:
ChangeVetoException
- if the new value is unacceptable.
-
getRankedCrossRefs
public Set<RankedCrossRef> 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 interfaceRankedCrossRefable
- 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 interfaceRankedCrossRefable
- 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 interfaceRankedCrossRefable
- Parameters:
crossref
- the ranked cross reference to add.- Throws:
ChangeVetoException
- if the parameter is null.
-
removeRankedCrossRef
public void removeRankedCrossRef(RankedCrossRef crossref) throws ChangeVetoException
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 interfaceRankedCrossRefable
- Parameters:
crossref
- the ranked cross reference to remove.- Throws:
ChangeVetoException
- if the parameter is null.
-
getFeatureRelationshipSet
public Set<RichFeatureRelationship> 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 interfaceRichFeatureRelationshipHolder
- Returns:
- a set of RichFeatureRelationship objects.
-
setFeatureRelationshipSet
public void setFeatureRelationshipSet(Set<RichFeatureRelationship> relationships) throws ChangeVetoException
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 interfaceRichFeatureRelationshipHolder
- 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
public void addFeatureRelationship(RichFeatureRelationship relationship) throws ChangeVetoException
Adds a relationship to this feature holder.- Specified by:
addFeatureRelationship
in interfaceRichFeatureRelationshipHolder
- Parameters:
relationship
- the relationship to add.- Throws:
ChangeVetoException
- if the relationship is unacceptable.
-
removeFeatureRelationship
public void removeFeatureRelationship(RichFeatureRelationship relationship) throws ChangeVetoException
Removes a relationship from this feature holder.- Specified by:
removeFeatureRelationship
in interfaceRichFeatureRelationshipHolder
- 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 interfaceFeatureHolder
- 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 interfaceFeatureHolder
- Returns:
- a positive integer or zero, equal to the number of features contained
-
createFeature
public Feature createFeature(Feature.Template ft) throws BioException, ChangeVetoException
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 interfaceFeatureHolder
- Throws:
BioException
- if something went wrong during creating the featureChangeVetoException
- 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 interfaceFeature
- Specified by:
features
in interfaceFeatureHolder
- Returns:
- an Iterator
-
filter
public FeatureHolder filter(FeatureFilter filter)
Query this set of features using a suppliedFeatureFilter
.- Specified by:
filter
in interfaceFeatureHolder
- Parameters:
filter
- theFeatureFilter
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 interfaceFeatureHolder
- Parameters:
fc
- the FeatureFilter to applyrecurse
- 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
public FeatureFilter getSchema()
Return a schema-filter for thisFeatureHolder
. This is a filter which allFeature
s immediately contained by thisFeatureHolder
will match. It need not directly match their child features, but it can (and should!) provide information about them usingFeatureFilter.OnlyChildren
filters. In cases where there is no feature hierarchy, this can be indicated by includingFeatureFilter.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, returnFeatureFilter.top_level
.Feature
objects should, as a minimum, returnFeatureFilter.ByParent(new FeatureFilter.ByFeature(this))
.- Specified by:
getSchema
in interfaceFeatureHolder
- Returns:
- the schema filter
-
removeFeature
public void removeFeature(Feature f) throws ChangeVetoException, BioException
Remove a feature from this FeatureHolder.- Specified by:
removeFeature
in interfaceFeatureHolder
- Throws:
ChangeVetoException
- if this FeatureHolder does not support feature removal or if the change was vetoedBioException
- if there was an error removing the feature
-
setStrand
public void setStrand(StrandedFeature.Strand strand) throws ChangeVetoException
Set the strand that this feature lies upon.This will be one of StrandedFeature.POSITIVE or NEGATIVE. NOT IMPLEMENTED.
- Specified by:
setStrand
in interfaceStrandedFeature
- Parameters:
strand
- aStrand
.- Throws:
ChangeVetoException
- if the strand may not be changed.
-
getStrand
public StrandedFeature.Strand getStrand()
Retrieve the strand that this feature lies upon.This will be one of StrandedFeature.POSITIVE or NEGATIVE.
- Specified by:
getStrand
in interfaceStrandedFeature
- Returns:
- one of the Strand constants
-
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.
-
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 interfaceComparable
-
getId
public Integer getId()
Gets the Hibernate ID. Should be used with caution.- Returns:
- the Hibernate ID, if using Hibernate.
-
-