org.biojava3.alignment
Class SimpleAlignedSequence<S extends Sequence<C>,C extends Compound>

java.lang.Object
  extended by org.biojava3.alignment.SimpleAlignedSequence<S,C>
Type Parameters:
C - each element of the Sequence is a Compound of type C
All Implemented Interfaces:
Iterable<C>, AlignedSequence<S,C>, Accessioned, Sequence<C>

public class SimpleAlignedSequence<S extends Sequence<C>,C extends Compound>
extends Object
implements AlignedSequence<S,C>

Implements a data structure for a Sequence within an alignment.

Author:
Mark Chapman

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.biojava3.alignment.template.AlignedSequence
AlignedSequence.Step
 
Constructor Summary
SimpleAlignedSequence(AlignedSequence<S,C> prev, List<AlignedSequence.Step> steps)
          Creates a new AlignedSequence for the given AlignedSequence in a global alignment.
SimpleAlignedSequence(AlignedSequence<S,C> prev, List<AlignedSequence.Step> steps, int numBefore, int numAfter)
          Creates a new AlignedSequence for the given AlignedSequence in a local alignment.
SimpleAlignedSequence(S original, List<AlignedSequence.Step> steps)
          Creates an AlignedSequence for the given Sequence in a global alignment.
SimpleAlignedSequence(S original, List<AlignedSequence.Step> steps, int numBefore, int numAfter)
          Creates an AlignedSequence for the given Sequence in a local alignment.
 
Method Summary
 void clearCache()
          Nullifies cached arrays/objects.
 int countCompounds(C... compounds)
          Returns the number of times we found a compound in the Sequence
 AccessionID getAccession()
          Returns the AccessionID this location is currently bound with
 int getAlignmentIndexAt(int sequenceIndex)
          Returns the column index within an alignment corresponding to the given index in the original Sequence.
 List<C> getAsList()
          Returns the Sequence as a List of compounds
 C getCompoundAt(int alignmentIndex)
          Returns the Compound at the given biological index
 CompoundSet<C> getCompoundSet()
          Gets the compound set used to back this Sequence
 Point getEnd()
          Returns the Point within an alignment of the last element of the original Sequence.
 int getIndexOf(C compound)
          Scans through the Sequence looking for the first occurrence of the given compound
 SequenceView<C> getInverse()
          Does the right thing to get the inverse of the current Sequence.
 int getLastIndexOf(C compound)
          Scans through the Sequence looking for the last occurrence of the given compound
 int getLength()
          Returns the length of the Sequence
 Location getLocationInAlignment()
          Returns the Location of the original Sequence within an alignment.
 int getNumGaps()
          Returns number of gaps in the sequence.
 S getOriginalSequence()
          Returns the original Sequence before alignment.
 int getOverlapCount()
          Returns the maximum number of elements contributed to a column of an alignment by this Sequence.
 String getSequenceAsString()
          Returns the String representation of the Sequence
 int getSequenceIndexAt(int alignmentIndex)
          Returns the index in the original Sequence corresponding to the given index within an alignment.
 Point getStart()
          Returns the Point within an alignment of the first element of the original Sequence.
 SequenceView<C> getSubSequence(Integer start, Integer end)
          Returns a portion of the sequence from the different positions.
 boolean isCircular()
          Returns true if this Sequence wraps around from the last alignment column back to the first.
 boolean isGap(int alignmentIndex)
          Returns true if this Sequence has a gap at a particular alignment column.
 Iterator<C> iterator()
           
 String toString()
          Provides standard Java language access to results of getSequenceAsString().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SimpleAlignedSequence

public SimpleAlignedSequence(S original,
                             List<AlignedSequence.Step> steps)
Creates an AlignedSequence for the given Sequence in a global alignment.

Parameters:
original - the original Sequence before alignment
steps - lists whether the sequence aligns a Compound or gap at each index of the alignment
Throws:
IllegalArgumentException - if given sequence does not fit in alignment

SimpleAlignedSequence

public SimpleAlignedSequence(S original,
                             List<AlignedSequence.Step> steps,
                             int numBefore,
                             int numAfter)
Creates an AlignedSequence for the given Sequence in a local alignment.

Parameters:
original - the original Sequence before alignment
steps - lists whether the sequence aligns a Compound or gap at each index of the alignment
numBefore - number of Compounds before a local alignment
numAfter - number of Compounds after a local alignment
Throws:
IllegalArgumentException - if given sequence does not fit in alignment

SimpleAlignedSequence

public SimpleAlignedSequence(AlignedSequence<S,C> prev,
                             List<AlignedSequence.Step> steps)
Creates a new AlignedSequence for the given AlignedSequence in a global alignment.

Parameters:
prev - the previous AlignedSequence before this alignment
steps - lists whether the sequence aligns a Compound or gap at each index of the alignment
Throws:
IllegalArgumentException - if given sequence does not fit in alignment

SimpleAlignedSequence

public SimpleAlignedSequence(AlignedSequence<S,C> prev,
                             List<AlignedSequence.Step> steps,
                             int numBefore,
                             int numAfter)
Creates a new AlignedSequence for the given AlignedSequence in a local alignment.

Parameters:
prev - the previous AlignedSequence before this alignment
steps - lists whether the sequence aligns a Compound or gap at each index of the alignment
numBefore - number of Compounds before a local alignment
numAfter - number of Compounds after a local alignment
Throws:
IllegalArgumentException - if given sequence does not fit in alignment
Method Detail

clearCache

public void clearCache()
Description copied from interface: AlignedSequence
Nullifies cached arrays/objects.

Specified by:
clearCache in interface AlignedSequence<S extends Sequence<C>,C extends Compound>

getAlignmentIndexAt

public int getAlignmentIndexAt(int sequenceIndex)
Description copied from interface: AlignedSequence
Returns the column index within an alignment corresponding to the given index in the original Sequence. Both indices are 1-indexed and inclusive.

Specified by:
getAlignmentIndexAt in interface AlignedSequence<S extends Sequence<C>,C extends Compound>
Parameters:
sequenceIndex - index in the original Sequence
Returns:
column index within an alignment

getEnd

public Point getEnd()
Description copied from interface: AlignedSequence
Returns the Point within an alignment of the last element of the original Sequence.

Specified by:
getEnd in interface AlignedSequence<S extends Sequence<C>,C extends Compound>
Returns:
position within an alignment of final original Sequence element

getLocationInAlignment

public Location getLocationInAlignment()
Description copied from interface: AlignedSequence
Returns the Location of the original Sequence within an alignment. This provides access to additional substructure beyond start and end points.

Specified by:
getLocationInAlignment in interface AlignedSequence<S extends Sequence<C>,C extends Compound>
Returns:
location within an alignment

getNumGaps

public int getNumGaps()
Description copied from interface: AlignedSequence
Returns number of gaps in the sequence. This could be determined from the Location information or from gap Compounds, which may not necessarily result in the same number.

Specified by:
getNumGaps in interface AlignedSequence<S extends Sequence<C>,C extends Compound>
Returns:
number of gaps in the sequence

getOriginalSequence

public S getOriginalSequence()
Description copied from interface: AlignedSequence
Returns the original Sequence before alignment.

Specified by:
getOriginalSequence in interface AlignedSequence<S extends Sequence<C>,C extends Compound>
Returns:
the original sequence

getOverlapCount

public int getOverlapCount()
Description copied from interface: AlignedSequence
Returns the maximum number of elements contributed to a column of an alignment by this Sequence. If this Sequence is circular, this number is >= 1. If not, this overlap count is definitely 1.

Specified by:
getOverlapCount in interface AlignedSequence<S extends Sequence<C>,C extends Compound>
Returns:
the most elements contributed to any alignment column

getSequenceIndexAt

public int getSequenceIndexAt(int alignmentIndex)
Description copied from interface: AlignedSequence
Returns the index in the original Sequence corresponding to the given index within an alignment. Both indices are 1-indexed and inclusive.

Specified by:
getSequenceIndexAt in interface AlignedSequence<S extends Sequence<C>,C extends Compound>
Parameters:
alignmentIndex - column index within an alignment
Returns:
index in the original Sequence

getStart

public Point getStart()
Description copied from interface: AlignedSequence
Returns the Point within an alignment of the first element of the original Sequence.

Specified by:
getStart in interface AlignedSequence<S extends Sequence<C>,C extends Compound>
Returns:
position within an alignment of first original Sequence element

isCircular

public boolean isCircular()
Description copied from interface: AlignedSequence
Returns true if this Sequence wraps around from the last alignment column back to the first. This makes overlap possible, but does not require an overlap count > 1.

Specified by:
isCircular in interface AlignedSequence<S extends Sequence<C>,C extends Compound>
Returns:
true for circular alignment elements

isGap

public boolean isGap(int alignmentIndex)
Description copied from interface: AlignedSequence
Returns true if this Sequence has a gap at a particular alignment column.

Specified by:
isGap in interface AlignedSequence<S extends Sequence<C>,C extends Compound>
Parameters:
alignmentIndex - column index within an alignment
Returns:
true if this column has a gap

countCompounds

public int countCompounds(C... compounds)
Description copied from interface: Sequence
Returns the number of times we found a compound in the Sequence

Specified by:
countCompounds in interface Sequence<C extends Compound>
Parameters:
compounds - Vargs of the compounds to count
Returns:
Number of times a compound was found

getAccession

public AccessionID getAccession()
Description copied from interface: Accessioned
Returns the AccessionID this location is currently bound with

Specified by:
getAccession in interface Accessioned

getAsList

public List<C> getAsList()
Description copied from interface: Sequence
Returns the Sequence as a List of compounds

Specified by:
getAsList in interface Sequence<C extends Compound>

getCompoundAt

public C getCompoundAt(int alignmentIndex)
Description copied from interface: Sequence
Returns the Compound at the given biological index

Specified by:
getCompoundAt in interface Sequence<C extends Compound>
Parameters:
alignmentIndex - Biological index (1 to n)
Returns:
Compound at the specified position

getCompoundSet

public CompoundSet<C> getCompoundSet()
Description copied from interface: Sequence
Gets the compound set used to back this Sequence

Specified by:
getCompoundSet in interface Sequence<C extends Compound>

getIndexOf

public int getIndexOf(C compound)
Description copied from interface: Sequence
Scans through the Sequence looking for the first occurrence of the given compound

Specified by:
getIndexOf in interface Sequence<C extends Compound>
Parameters:
compound - Compounds to look for
Returns:
Index of the first position of the compound in the sequence (1 to n)

getLastIndexOf

public int getLastIndexOf(C compound)
Description copied from interface: Sequence
Scans through the Sequence looking for the last occurrence of the given compound

Specified by:
getLastIndexOf in interface Sequence<C extends Compound>
Parameters:
compound - Compounds to look for
Returns:
Index of the last position of the compound in the sequence (1 to n)

getLength

public int getLength()
Description copied from interface: Sequence
Returns the length of the Sequence

Specified by:
getLength in interface Sequence<C extends Compound>

getSequenceAsString

public String getSequenceAsString()
Description copied from interface: Sequence
Returns the String representation of the Sequence

Specified by:
getSequenceAsString in interface Sequence<C extends Compound>

getSubSequence

public SequenceView<C> getSubSequence(Integer start,
                                      Integer end)
Description copied from interface: Sequence
Returns a portion of the sequence from the different positions. This is indexed from 1

Specified by:
getSubSequence in interface Sequence<C extends Compound>
Parameters:
start - Biological index start; must be greater than 0
end - Biological end; must be less than length + 1
Returns:
A SequenceView of the offset

iterator

public Iterator<C> iterator()
Specified by:
iterator in interface Iterable<C extends Compound>

toString

public String toString()
Provides standard Java language access to results of getSequenceAsString().

Overrides:
toString in class Object

getInverse

public SequenceView<C> getInverse()
Description copied from interface: Sequence
Does the right thing to get the inverse of the current Sequence. This means either reversing the Sequence and optionally complementing the Sequence.

Specified by:
getInverse in interface Sequence<C extends Compound>