org.biojava.bio.seq
Class ViewSequence

java.lang.Object
  |
  +--org.biojava.bio.seq.ViewSequence

public class ViewSequence
extends java.lang.Object
implements Sequence, RealizingFeatureHolder

A view onto another Sequence object. This class allows new features and annotations to be overlayed onto an existing Sequence without modifying it.

Author:
Thomas Down

Inner classes inherited from class org.biojava.bio.symbol.SymbolList
SymbolList.EmptySymbolList
 
Inner classes inherited from class org.biojava.bio.seq.FeatureHolder
FeatureHolder.EmptyFeatureHolder
 
Inner classes inherited from class org.biojava.bio.seq.FeatureHolder
FeatureHolder.EmptyFeatureHolder
 
Fields inherited from interface org.biojava.bio.symbol.SymbolList
EMPTY_LIST
 
Fields inherited from interface org.biojava.bio.seq.FeatureHolder
EMPTY_FEATURE_HOLDER
 
Fields inherited from interface org.biojava.bio.seq.FeatureHolder
EMPTY_FEATURE_HOLDER
 
Constructor Summary
ViewSequence(Sequence seq)
          Construct a view onto an existing sequence.
ViewSequence(Sequence seq, FeatureRealizer fr)
          Construct a view onto a sequence, using a specific FeatureRealizer
 
Method Summary
 int countFeatures()
          Count how many features are contained.
 Feature createFeature(Feature.Template template)
          Create a new Feature, and add it to this FeatureHolder.
 Feature createFeature(FeatureHolder fh, Feature.Template template)
          Deprecated. Please use 1-arg createFeature instead.
 java.util.Iterator features()
          Iterate over the features in no well defined order.
 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.
 Annotation getAnnotation()
          Should return the associated annotation object.
 java.lang.String getName()
          The name of this sequence.
 java.lang.String getURN()
          The URN for this sequence.
 java.util.Iterator iterator()
          An Iterator over all Symbols in this SymbolList.
 int length()
          The number of symbols in this SymbolList.
 Feature realizeFeature(FeatureHolder parent, Feature.Template template)
          Realize a feature template.
 void removeFeature(Feature f)
          Remove a feature from this sequence.
 java.lang.String seqString()
          Stringify this symbol list.
 SymbolList subList(int start, int end)
          Return a new SymbolList for the symbols start to end inclusive.
 java.lang.String subStr(int start, int end)
          Return a region of this symbol list as a String.
 Symbol symbolAt(int indx)
          Return the symbol at index, counting from 1.
 java.util.List toList()
          Returns a List of symbols.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ViewSequence

public ViewSequence(Sequence seq)
Construct a view onto an existing sequence.

ViewSequence

public ViewSequence(Sequence seq,
                    FeatureRealizer fr)
Construct a view onto a sequence, using a specific FeatureRealizer
Method Detail

getAlphabet

public Alphabet getAlphabet()
Description copied from interface: SymbolList
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.

Tags copied from interface: SymbolList
Returns:
the alphabet

iterator

public java.util.Iterator iterator()
Description copied from interface: SymbolList
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.

Tags copied from interface: SymbolList
Returns:
an iterator

length

public int length()
Description copied from interface: SymbolList
The number of symbols in this SymbolList.
Tags copied from interface: SymbolList
Returns:
the length

seqString

public java.lang.String seqString()
Description copied from interface: SymbolList
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.

Tags copied from interface: SymbolList
Returns:
a string representation of the symbol list

subStr

public java.lang.String subStr(int start,
                               int end)
Description copied from interface: SymbolList
Return a region of this symbol list as a String.

This should use the same rules as seqString.

Tags copied from interface: SymbolList
Parameters:
start - the first symbol to include
end - the last symbol to include
Returns:
the string representation
Throws:
java.lang.IndexOutOfBoundsException - if either start or end are not within the sequence

subList

public SymbolList subList(int start,
                          int end)
Description copied from interface: SymbolList
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.

Tags copied from interface: SymbolList
Parameters:
start - the first symbol of the new SymbolList
end - the last symbol (inclusive) of the new SymbolList

symbolAt

public Symbol symbolAt(int indx)
Description copied from interface: SymbolList
Return the symbol at index, counting from 1.
Tags copied from interface: SymbolList
Parameters:
index - the ofset into this SymbolList
Returns:
the Symbol at that index
Throws:
java.lang.IndexOutOfBoundsException - if index is less than 1, or greater than the length of the symbol list

toList

public java.util.List toList()
Description copied from interface: SymbolList
Returns a List of symbols.

This is an immutable list of symbols. Do not edit it.

Tags copied from interface: SymbolList
Returns:
a List of Symbols

getURN

public java.lang.String getURN()
Description copied from interface: Sequence
The URN for this sequence. This will be something like urn:sequence/embl:U32766 or urn:sequence/fasta:sequences.fasta|hox3.
Specified by:
getURN in interface Sequence
Tags copied from interface: Sequence
Returns:
the urn as a String

getName

public java.lang.String getName()
Description copied from interface: Sequence
The name of this sequence.

The name may contain spaces or odd characters.

Specified by:
getName in interface Sequence
Tags copied from interface: Sequence
Returns:
the name as a String

countFeatures

public int countFeatures()
Description copied from interface: FeatureHolder
Count how many features are contained.
Tags copied from interface: FeatureHolder
Returns:
a positive integer or zero, equal to the number of features contained

features

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

filter

public FeatureHolder filter(FeatureFilter fc,
                            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.
Tags copied from 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.

removeFeature

public void removeFeature(Feature f)
Remove a feature from this sequence. NOTE: This method will only succeed for features which were added to this ViewSequence. Trying to remove a Feature from the underlying sequence will cause an IllegalArgumentException. I think this is the correct behaviour.
Tags copied from interface: FeatureHolder
Throws:
java.lang.UnsupportedOperationException - if this FeatureHolder does not support feature removal.

getAnnotation

public Annotation getAnnotation()
Description copied from interface: Annotatable
Should return the associated annotation object.
Tags copied from interface: Annotatable
Returns:
an Annotation object, never null

realizeFeature

public Feature realizeFeature(FeatureHolder parent,
                              Feature.Template template)
                       throws BioException
Description copied from interface: RealizingFeatureHolder
Realize a feature template. This will be a template which has been passed to the createFeature method of either this FeatureHolder or one of our child Features.
Specified by:
realizeFeature in interface RealizingFeatureHolder

createFeature

public Feature createFeature(Feature.Template template)
                      throws 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.
Tags copied from interface: FeatureHolder
Throws:
java.lang.UnsupportedOperationException - if this FeatureHolder does not support addition of new features.

createFeature

public Feature createFeature(FeatureHolder fh,
                             Feature.Template template)
                      throws BioException
Deprecated. Please use 1-arg createFeature instead.