Package org.biojava.nbio.core.alignment
Class SimpleAlignedSequence<S extends Sequence<C>,C extends Compound>
java.lang.Object
org.biojava.nbio.core.alignment.SimpleAlignedSequence<S,C>
- All Implemented Interfaces:
Serializable
,Iterable<C>
,AlignedSequence<S,
,C> Accessioned
,Sequence<C>
public class SimpleAlignedSequence<S extends Sequence<C>,C extends Compound>
extends Object
implements Serializable, AlignedSequence<S,C>
Implements a data structure for a
Sequence
within an alignment.- Author:
- Mark Chapman
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.biojava.nbio.core.alignment.template.AlignedSequence
AlignedSequence.Step
-
Constructor Summary
ConstructorDescriptionSimpleAlignedSequence
(AlignedSequence<S, C> prev, List<AlignedSequence.Step> steps) Creates a newAlignedSequence
for the givenAlignedSequence
in a global alignment.SimpleAlignedSequence
(AlignedSequence<S, C> prev, List<AlignedSequence.Step> steps, int numBefore, int numAfter) Creates a newAlignedSequence
for the givenAlignedSequence
in a local alignment.SimpleAlignedSequence
(S original, List<AlignedSequence.Step> steps) Creates anAlignedSequence
for the givenSequence
in a global alignment.SimpleAlignedSequence
(S original, List<AlignedSequence.Step> steps, int numBefore, int numAfter) Creates anAlignedSequence
for the givenSequence
in a local alignment. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Nullifies cached arrays/objects.int
countCompounds
(C... compounds) Returns the number of times we found a compound in the Sequenceboolean
Returns the AccessionID this location is currently bound withint[]
Returns the alignment.int
getAlignmentIndexAt
(int sequenceIndex) Returns the column index within an alignment corresponding to the given index in the originalSequence
.Returns the Sequence as a List of compoundsgetCompoundAt
(int alignmentIndex) Returns the Compound at the given biological indexGets the compound set used to back this Sequencedouble
Returns the coverage, as a fraction between 0 and 1, of thisAlignedSequence
with respect to the original sequence.getEnd()
int
getIndexOf
(C compound) Scans through the Sequence looking for the first occurrence of the given compoundDoes 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 compoundint
Returns the length of the Sequenceint
Returns number of gap positions (gap openings and extensions) in the sequence.int
Returns number of gaps in the sequence.Returns the originalSequence
before alignment.int
Returns the maximum number of elements contributed to a column of an alignment by thisSequence
.Returns the String representation of the Sequenceint[]
Returns the sequence positions at each alignment indexint
getSequenceIndexAt
(int alignmentIndex) Returns the index in the originalSequence
corresponding to the given index within an alignment.getStart()
getSubSequence
(Integer start, Integer end) Returns a portion of the sequence from the different positions.int
hashCode()
boolean
Returns true if thisSequence
wraps around from the last alignment column back to the first.boolean
isGap
(int alignmentIndex) Returns true if thisSequence
has a gap at a particular alignment column.iterator()
toString()
Provides standard Java language access to results ofgetSequenceAsString()
.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
SimpleAlignedSequence
Creates anAlignedSequence
for the givenSequence
in a global alignment.- Parameters:
original
- the originalSequence
before alignmentsteps
- lists whether the sequence aligns aCompound
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 anAlignedSequence
for the givenSequence
in a local alignment.- Parameters:
original
- the originalSequence
before alignmentsteps
- lists whether the sequence aligns aCompound
or gap at each index of the alignmentnumBefore
- number ofCompound
s before a local alignmentnumAfter
- number ofCompound
s after a local alignment- Throws:
IllegalArgumentException
- if given sequence does not fit in alignment
-
SimpleAlignedSequence
Creates a newAlignedSequence
for the givenAlignedSequence
in a global alignment.- Parameters:
prev
- the previousAlignedSequence
before this alignmentsteps
- lists whether the sequence aligns aCompound
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 newAlignedSequence
for the givenAlignedSequence
in a local alignment.- Parameters:
prev
- the previousAlignedSequence
before this alignmentsteps
- lists whether the sequence aligns aCompound
or gap at each index of the alignmentnumBefore
- number ofCompound
s before a local alignmentnumAfter
- number ofCompound
s after a local alignment- Throws:
IllegalArgumentException
- if given sequence does not fit in alignment
-
-
Method Details
-
clearCache
public void clearCache()Description copied from interface:AlignedSequence
Nullifies cached arrays/objects.- Specified by:
clearCache
in interfaceAlignedSequence<S extends Sequence<C>,
C extends Compound>
-
getAlignmentFromSequence
public int[] getAlignmentFromSequence()Description copied from interface:AlignedSequence
Returns the alignment.- Specified by:
getAlignmentFromSequence
in interfaceAlignedSequence<S extends Sequence<C>,
C extends Compound> - Returns:
- the alignment
-
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 originalSequence
. Both indices are 1-indexed and inclusive.- Specified by:
getAlignmentIndexAt
in interfaceAlignedSequence<S extends Sequence<C>,
C extends Compound> - Parameters:
sequenceIndex
- index in the originalSequence
- Returns:
- column index within an alignment
-
getEnd
Description copied from interface:AlignedSequence
-
getLocationInAlignment
Description copied from interface:AlignedSequence
Returns theLocation
of the originalSequence
within an alignment. This provides access to additional substructure beyond start and end points.- Specified by:
getLocationInAlignment
in interfaceAlignedSequence<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 theLocation
information or from gapCompound
s, which may not necessarily result in the same number.- Specified by:
getNumGaps
in interfaceAlignedSequence<S extends Sequence<C>,
C extends Compound> - Returns:
- number of gaps in the sequence
-
getOriginalSequence
Description copied from interface:AlignedSequence
Returns the originalSequence
before alignment.- Specified by:
getOriginalSequence
in interfaceAlignedSequence<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 thisSequence
. If thisSequence
is circular, this number is >= 1. If not, this overlap count is definitely 1.- Specified by:
getOverlapCount
in interfaceAlignedSequence<S extends Sequence<C>,
C extends Compound> - Returns:
- the most elements contributed to any alignment column
-
getSequenceFromAlignment
public int[] getSequenceFromAlignment()Description copied from interface:AlignedSequence
Returns the sequence positions at each alignment index- Specified by:
getSequenceFromAlignment
in interfaceAlignedSequence<S extends Sequence<C>,
C extends Compound> - Returns:
- array of the sequence positions
-
getSequenceIndexAt
public int getSequenceIndexAt(int alignmentIndex) Description copied from interface:AlignedSequence
Returns the index in the originalSequence
corresponding to the given index within an alignment. Both indices are 1-indexed and inclusive.- Specified by:
getSequenceIndexAt
in interfaceAlignedSequence<S extends Sequence<C>,
C extends Compound> - Parameters:
alignmentIndex
- column index within an alignment- Returns:
- index in the original
Sequence
-
getStart
Description copied from interface:AlignedSequence
-
isCircular
public boolean isCircular()Description copied from interface:AlignedSequence
Returns true if thisSequence
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 interfaceAlignedSequence<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 thisSequence
has a gap at a particular alignment column. -
countCompounds
Description copied from interface:Sequence
Returns the number of times we found a compound in the Sequence- Specified by:
countCompounds
in interfaceSequence<S extends Sequence<C>>
- Parameters:
compounds
- Vargs of the compounds to count- Returns:
- Number of times a compound was found
-
getAccession
Description copied from interface:Accessioned
Returns the AccessionID this location is currently bound with- Specified by:
getAccession
in interfaceAccessioned
-
getAsList
Description copied from interface:Sequence
Returns the Sequence as a List of compounds -
equals
-
hashCode
public int hashCode() -
getCompoundAt
Description copied from interface:Sequence
Returns the Compound at the given biological index- Specified by:
getCompoundAt
in interfaceSequence<S extends Sequence<C>>
- Parameters:
alignmentIndex
- Biological index (1 to n)- Returns:
- Compound at the specified position
-
getCompoundSet
Description copied from interface:Sequence
Gets the compound set used to back this Sequence- Specified by:
getCompoundSet
in interfaceSequence<S extends Sequence<C>>
-
getIndexOf
Description copied from interface:Sequence
Scans through the Sequence looking for the first occurrence of the given compound- Specified by:
getIndexOf
in interfaceSequence<S extends Sequence<C>>
- Parameters:
compound
- Compounds to look for- Returns:
- Index of the first position of the compound in the sequence (1 to n)
-
getLastIndexOf
Description copied from interface:Sequence
Scans through the Sequence looking for the last occurrence of the given compound- Specified by:
getLastIndexOf
in interfaceSequence<S extends Sequence<C>>
- 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 -
getSequenceAsString
Description copied from interface:Sequence
Returns the String representation of the Sequence- Specified by:
getSequenceAsString
in interfaceSequence<S extends Sequence<C>>
-
getSubSequence
Description copied from interface:Sequence
Returns a portion of the sequence from the different positions. This is indexed from 1- Specified by:
getSubSequence
in interfaceSequence<S extends Sequence<C>>
- Parameters:
start
- Biological index start; must be greater than 0end
- Biological end; must be less than length + 1- Returns:
- A SequenceView of the offset
-
iterator
-
toString
Provides standard Java language access to results ofgetSequenceAsString()
. -
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 interfaceSequence<S extends Sequence<C>>
-
getNumGapPositions
public int getNumGapPositions()Description copied from interface:AlignedSequence
Returns number of gap positions (gap openings and extensions) in the sequence. This could be determined from theLocation
information or from gapCompound
s, which may not necessarily result in the same number.- Specified by:
getNumGapPositions
in interfaceAlignedSequence<S extends Sequence<C>,
C extends Compound> - Returns:
- number of gap positions in the sequence
-
getCoverage
public double getCoverage()Description copied from interface:AlignedSequence
Returns the coverage, as a fraction between 0 and 1, of thisAlignedSequence
with respect to the original sequence. This is equivalent to (Sequence.getLength()
-AlignedSequence.getNumGapPositions()
) / getOriginalSequence().getLength().- Specified by:
getCoverage
in interfaceAlignedSequence<S extends Sequence<C>,
C extends Compound> - Returns:
- coverage of the original sequence by the aligned sequence
-