Class ThinRichSequence
- java.lang.Object
-
- org.biojava.utils.AbstractChangeable
-
- org.biojavax.bio.SimpleBioEntry
-
- org.biojavax.bio.seq.ThinRichSequence
-
- All Implemented Interfaces:
Comparable
,Annotatable
,FeatureHolder
,Sequence
,SymbolList
,Changeable
,BioEntry
,RichSequence
,RankedCrossRefable
,RichAnnotatable
- Direct Known Subclasses:
SimpleRichSequence
public class ThinRichSequence extends SimpleBioEntry implements RichSequence
A simple implementation of RichSequence. It has no sequence data, and delegates to a RichSequenceHandler to do sequence handling.- Since:
- 1.5
- Author:
- Richard Holland
-
-
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.FeatureHolder
FeatureHolder.EmptyFeatureHolder
-
Nested classes/interfaces inherited from interface org.biojavax.bio.seq.RichSequence
RichSequence.IOTools, RichSequence.Terms, RichSequence.Tools
-
-
Field Summary
-
Fields inherited from interface org.biojava.bio.Annotatable
ANNOTATION
-
Fields inherited from interface org.biojavax.bio.BioEntry
COMMENT, DESCRIPTION, DIVISION, IDENTIFIER, RANKEDCROSSREF, RANKEDDOCREF, RELATIONS, SEQVERSION, TAXON
-
Fields inherited from interface org.biojava.bio.seq.FeatureHolder
EMPTY_FEATURE_HOLDER, FEATURES, SCHEMA
-
Fields inherited from interface org.biojavax.bio.seq.RichSequence
CIRCULAR, SYMLISTVERSION
-
Fields inherited from interface org.biojava.bio.symbol.SymbolList
EDIT, EMPTY_LIST
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ThinRichSequence()
ThinRichSequence(Namespace ns, String name, String accession, int version, Alphabet alpha, Double seqversion)
Creates a new instance of ThinRichSequence.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.void
edit(Edit edit)
Apply an edit to the SymbolList as specified by the edit object.Iterator<Feature>
features()
Iterate over the features in no well defined order.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.Alphabet
getAlphabet()
The alphabet that this SymbolList is over.protected String
getAlphabetName()
boolean
getCircular()
Is the sequence circular?Set<Feature>
getFeatureSet()
The features for this sequence.SymbolList
getInternalSymbolList()
A special function that returns the SymbolList that this RichSequence is based around.FeatureFilter
getSchema()
Return a schema-filter for thisFeatureHolder
.protected int
getSequenceLength()
Double
getSeqVersion()
The version of the associated symbol list.String
getURN()
A Uniform Resource Identifier (URI) which identifies the sequence represented by this object.Iterator
iterator()
An Iterator over all Symbols in this SymbolList.int
length()
The number of symbols in this SymbolList.void
removeFeature(Feature f)
Remove a feature from this FeatureHolder.String
seqString()
Stringify this symbol list.protected void
setAlphabetName(String alphaname)
void
setCircular(boolean circular)
Circularises theSequence
.void
setFeatureSet(Set<Feature> features)
Sets the features of this sequence.protected void
setSequenceLength(int length)
void
setSeqVersion(Double seqVersion)
Sets the version of the associated symbol list.SymbolList
subList(int start, int end)
Return a new SymbolList for the symbols start to end inclusive.String
subStr(int start, int end)
Return a region of this symbol list as a String.Symbol
symbolAt(int index)
Return the symbol at index, counting from 1.List
toList()
Returns a List of symbols.-
Methods inherited from class org.biojavax.bio.SimpleBioEntry
addComment, addRankedCrossRef, addRankedDocRef, addRelationship, compareTo, equals, getAccession, getAnnotation, getComments, getDescription, getDivision, getId, getIdentifier, getName, getNamespace, getNoteSet, getRankedCrossRefs, getRankedDocRefs, getRelationships, getRichAnnotation, getTaxon, getVersion, hashCode, removeComment, removeRankedCrossRef, removeRankedDocRef, removeRelationship, setDescription, setDivision, setId, setIdentifier, setNoteSet, setRankedCrossRefs, setTaxon, toString
-
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.bio.Annotatable
getAnnotation
-
Methods inherited from interface org.biojavax.bio.BioEntry
addComment, addRankedDocRef, addRelationship, getAccession, getComments, getDescription, getDivision, getIdentifier, getName, getNamespace, getRankedDocRefs, getRelationships, getTaxon, getVersion, removeComment, removeRankedDocRef, removeRelationship, setDescription, setDivision, setIdentifier, setTaxon
-
Methods inherited from interface org.biojava.utils.Changeable
addChangeListener, addChangeListener, isUnchanging, removeChangeListener, removeChangeListener
-
Methods inherited from interface java.lang.Comparable
compareTo
-
Methods inherited from interface org.biojavax.RankedCrossRefable
addRankedCrossRef, getRankedCrossRefs, removeRankedCrossRef, setRankedCrossRefs
-
Methods inherited from interface org.biojavax.RichAnnotatable
getNoteSet, getRichAnnotation, setNoteSet
-
-
-
-
Constructor Detail
-
ThinRichSequence
public ThinRichSequence(Namespace ns, String name, String accession, int version, Alphabet alpha, Double seqversion)
Creates a new instance of ThinRichSequence. Note the use of Double for seqversion, which indicates that it is nullable.- Parameters:
ns
- the namespace for this sequence.name
- the name of the sequence.accession
- the accession of the sequence.version
- the version of the sequence.seqversion
- the version of the symbols for the sequence.
-
ThinRichSequence
protected ThinRichSequence()
-
-
Method Detail
-
getSeqVersion
public Double getSeqVersion()
The version of the associated symbol list. Note the use of an object for the value means that it can be nulled.- Specified by:
getSeqVersion
in interfaceRichSequence
- Returns:
- the version
-
setSeqVersion
public void setSeqVersion(Double seqVersion) throws ChangeVetoException
Sets the version of the associated symbol list. Note the use of an object for the value means that it can be nulled.- Specified by:
setSeqVersion
in interfaceRichSequence
- Parameters:
seqVersion
- the version to set.- Throws:
ChangeVetoException
- if it doesn't want to change.
-
setCircular
public void setCircular(boolean circular) throws ChangeVetoException
Circularises theSequence
. The circular length can then be said to be the length of the sequence itself.- Specified by:
setCircular
in interfaceRichSequence
- Parameters:
circular
- set to true if you want it to be circular- Throws:
ChangeVetoException
- if the change is blocked. Some implementations may choose not to support circularisation and should throw an exception here. Some implementations may only support this method for certain Alphabets.
-
getCircular
public boolean getCircular()
Is the sequence circular? Circularity has implications for work with locations and any coordinate work eg symbolAt(int i). Classes that allow it should test this method when working with coordinates or locations / features.- Specified by:
getCircular
in interfaceRichSequence
- Returns:
- true if the this is circular else false.
-
edit
public void edit(Edit edit) throws IndexOutOfBoundsException, IllegalAlphabetException, ChangeVetoException
Apply an edit to the SymbolList as specified by the edit object.Description
All edits can be broken down into a series of operations that change contiguous blocks of the sequence. This represent a one of those operations.
When applied, this Edit will replace 'length' number of symbols starting a position 'pos' by the SymbolList 'replacement'. This allow to do insertions (length=0), deletions (replacement=SymbolList.EMPTY_LIST) and replacements (length>=1 and replacement.length()>=1).
The pos and pos+length should always be valid positions on the SymbolList to:
- be edited (between 0 and symL.length()+1).
- To append to a sequence, pos=symL.length()+1, pos=0.
- To insert something at the beginning of the sequence, set pos=1 and length=0.
Examples
SymbolList seq = DNATools.createDNA("atcaaaaacgctagc"); System.out.println(seq.seqString()); // delete 5 bases from position 4 Edit ed = new Edit(4, 5, SymbolList.EMPTY_LIST); seq.edit(ed); System.out.println(seq.seqString()); // delete one base from the start ed = new Edit(1, 1, SymbolList.EMPTY_LIST); seq.edit(ed); // delete one base from the end ed = new Edit(seq.length(), 1, SymbolList.EMPTY_LIST); seq.edit(ed); System.out.println(seq.seqString()); // overwrite 2 bases from position 3 with "tt" ed = new Edit(3, 2, DNATools.createDNA("tt")); seq.edit(ed); System.out.println(seq.seqString()); // add 6 bases to the start ed = new Edit(1, 0, DNATools.createDNA("aattgg"); seq.edit(ed); System.out.println(seq.seqString()); // add 4 bases to the end ed = new Edit(seq.length() + 1, 0, DNATools.createDNA("tttt")); seq.edit(ed); System.out.println(seq.seqString()); // full edit ed = new Edit(3, 2, DNATools.createDNA("aatagaa"); seq.edit(ed); System.out.println(seq.seqString());
- Specified by:
edit
in interfaceSymbolList
- Parameters:
edit
- the Edit to perform- Throws:
IndexOutOfBoundsException
- if the edit does not lie within the SymbolListIllegalAlphabetException
- if the SymbolList to insert has an incompatible alphabetChangeVetoException
- if either the SymboList does not support the edit, or if the change was vetoed
-
symbolAt
public Symbol symbolAt(int index) throws IndexOutOfBoundsException
Return the symbol at index, counting from 1.- Specified by:
symbolAt
in interfaceSymbolList
- Parameters:
index
- the offset into this SymbolList- Returns:
- the Symbol at that index
- Throws:
IndexOutOfBoundsException
- if index is less than 1, or greater than the length of the symbol list
-
toList
public List toList()
Returns a List of symbols.This is an immutable list of symbols. Do not edit it.
- Specified by:
toList
in interfaceSymbolList
- Returns:
- a List of Symbols
-
subStr
public String subStr(int start, int end) throws IndexOutOfBoundsException
Return a region of this symbol list as a String.This should use the same rules as seqString.
- Specified by:
subStr
in interfaceSymbolList
- Parameters:
start
- the first symbol to includeend
- the last symbol to include- Returns:
- the string representation
- Throws:
IndexOutOfBoundsException
- if either start or end are not within the SymbolList
-
subList
public SymbolList subList(int start, int end) throws IndexOutOfBoundsException
Return a new SymbolList for the symbols start to end inclusive.The resulting SymbolList will count from 1 to (end-start + 1) inclusive, and refer to the symbols start to end of the original sequence.
- Specified by:
subList
in interfaceSymbolList
- Parameters:
start
- the first symbol of the new SymbolListend
- the last symbol (inclusive) of the new SymbolList- Throws:
IndexOutOfBoundsException
-
seqString
public String seqString()
Stringify this symbol list.It is expected that this will use the symbol's token to render each symbol. It should be parsable back into a SymbolList using the default token parser for this alphabet.
- Specified by:
seqString
in interfaceSymbolList
- Returns:
- a string representation of the symbol list
-
length
public int length()
The number of symbols in this SymbolList.- Specified by:
length
in interfaceSymbolList
- Returns:
- the length
-
iterator
public Iterator iterator()
An Iterator over all Symbols in this SymbolList.This is an ordered iterator over the Symbols. It cannot be used to edit the underlying symbols.
- Specified by:
iterator
in interfaceSymbolList
- Returns:
- an iterator
-
getAlphabet
public Alphabet getAlphabet()
The alphabet that this SymbolList is over.Every symbol within this SymbolList is a member of this alphabet.
alphabet.contains(symbol) == true
for each symbol that is within this sequence.- Specified by:
getAlphabet
in interfaceSymbolList
- Returns:
- the alphabet
-
setAlphabetName
protected void setAlphabetName(String alphaname) throws IllegalSymbolException, BioException
- Throws:
IllegalSymbolException
BioException
-
getAlphabetName
protected String getAlphabetName()
-
setSequenceLength
protected void setSequenceLength(int length)
-
getSequenceLength
protected int getSequenceLength()
-
getURN
public String getURN()
A Uniform Resource Identifier (URI) which identifies the sequence represented by this object. For sequences in well-known database, this may be a URN, e.g.urn:sequence/embl:AL121903
It may also be a URL identifying a specific resource, either locally or over the networkfile:///home/thomas/myseq.fa|seq22 http://www.mysequences.net/chr22.seq
-
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.
-
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
-
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
-
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
-
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
.
-
getFeatureSet
public Set<Feature> getFeatureSet()
The features for this sequence. 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:
getFeatureSet
in interfaceRichSequence
- Returns:
- a set of RichFeature objects.
-
setFeatureSet
public void setFeatureSet(Set<Feature> features) throws ChangeVetoException
Sets the features of this sequence. Note that it is not checked to see if the features actually belong to this sequence, you'd best check that yourself and make changes using feature.setParent() if necessary. 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:
setFeatureSet
in interfaceRichSequence
- Parameters:
features
- the features to assign to this sequence, replacing all others. Must be a set of RichFeature objects.- Throws:
ChangeVetoException
- if they could not be assigned.
-
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
-
features
public Iterator<Feature> features()
Iterate over the features in no well defined order. 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:
features
in interfaceFeatureHolder
- Returns:
- an Iterator
-
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
-
getInternalSymbolList
public SymbolList getInternalSymbolList()
A special function that returns the SymbolList that this RichSequence is based around. This should _not_ be the RichSequence object itself, as this function is used to perform actions on the symbol list without referring to the RichSequence object directly.- Specified by:
getInternalSymbolList
in interfaceRichSequence
- Returns:
- the internal SymbolList of the RichSequence, NOT the RichSequence object itself.
-
-