## org.biojava.bio.seq
Class SimpleSequence

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

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

A basic implementation of the `Sequence` interface.

This class now implements all methods in the SymbolList interface by delegating to another SymbolList object. This avoids unnecessary copying, but means that any changes in the underlying SymbolList will be silently reflected in the SimpleSequence. In general, SimpleSequences should only be constructed from SymbolLists which are known to be immutable.

By default, features attached to a SimpleSequence are realized as simple in-memory implementations using `SimpleFeatureRealizer.DEFAULT`. If you need alternative feature realization behaviour, any `FeatureRealizer` implementation may be supplied at construction-time.

Author:
  Matthew Pocock, 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
`SimpleSequence(SymbolList res, java.lang.String urn, java.lang.String name, Annotation annotation)` Create a SimpleSequence with the symbols and alphabet of res, and the sequence properties listed.
`SimpleSequence(SymbolList res, java.lang.String urn, java.lang.String name, Annotation annotation, FeatureRealizer realizer)` Create a SimpleSequence using a specified 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 new 1-arg createFeature instead.
`protected boolean` `featureHolderAllocated()`
`java.util.Iterator` `features()` Iterate over the features in no well defined order.
`FeatureHolder` `filter(FeatureFilter ff, 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.
`protected SimpleFeatureHolder` `getFeatureHolder()`
`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 attached to this sequence.
`java.lang.String` `seqString()` Stringify this symbol list.
`void` `setName(java.lang.String name)` Assign a name to this sequence
`void` `setURN(java.lang.String urn)` Provide the URN for this sequence
`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 index)` 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

### SimpleSequence

    public SimpleSequence(SymbolList res,
                          java.lang.String urn,
                          java.lang.String name,
                          Annotation annotation)

  Create a SimpleSequence with the symbols and alphabet of res, and the sequence properties listed.
  Parameters:
    `res` - the SymbolList to wrap as a sequence
    `urn` - the URN
    `name` - the name - should be unique if practical
    `annotation` - the annotation object to use or null

### SimpleSequence

    public SimpleSequence(SymbolList res,
                          java.lang.String urn,
                          java.lang.String name,
                          Annotation annotation,
                          FeatureRealizer realizer)

  Create a SimpleSequence using a specified FeatureRealizer.
  Parameters:
    `res` - the SymbolList to wrap as a sequence
    `urn` - the URN
    `name` - the name - should be unique if practical
    `annotation` - the annotation object to use or null
    `realizer` - the FeatureRealizer implemetation to use when adding features

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 index)

  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

### getFeatureHolder

    protected SimpleFeatureHolder getFeatureHolder()

### featureHolderAllocated

    protected boolean featureHolderAllocated()

### 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

### setURN

    public void setURN(java.lang.String urn)

  Provide the URN for this sequence

### 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

### setName

    public void setName(java.lang.String name)

  Assign a name to this sequence

### 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

### 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 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.
  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.

### 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 new 1-arg createFeature instead.

  Create a new feature in any FeatureHolder associated with this sequence.

### removeFeature

    public void removeFeature(Feature f)

  Remove a feature attached to this sequence.
  Tags copied from interface: FeatureHolder
  Throws:
    java.lang.UnsupportedOperationException - if this FeatureHolder does not support feature removal.