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 aSequencewithin an alignment.- Author:
- Mark Chapman
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.biojava.nbio.core.alignment.template.AlignedSequence
AlignedSequence.Step
-
-
Constructor Summary
Constructors Constructor Description SimpleAlignedSequence(AlignedSequence<S,C> prev, List<AlignedSequence.Step> steps)Creates a newAlignedSequencefor the givenAlignedSequencein a global alignment.SimpleAlignedSequence(AlignedSequence<S,C> prev, List<AlignedSequence.Step> steps, int numBefore, int numAfter)Creates a newAlignedSequencefor the givenAlignedSequencein a local alignment.SimpleAlignedSequence(S original, List<AlignedSequence.Step> steps)Creates anAlignedSequencefor the givenSequencein a global alignment.SimpleAlignedSequence(S original, List<AlignedSequence.Step> steps, int numBefore, int numAfter)Creates anAlignedSequencefor the givenSequencein a local alignment.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearCache()Nullifies cached arrays/objects.intcountCompounds(C... compounds)Returns the number of times we found a compound in the Sequencebooleanequals(Object o)AccessionIDgetAccession()Returns the AccessionID this location is currently bound withint[]getAlignmentFromSequence()Returns the alignment.intgetAlignmentIndexAt(int sequenceIndex)Returns the column index within an alignment corresponding to the given index in the originalSequence.List<C>getAsList()Returns the Sequence as a List of compoundsCgetCompoundAt(int alignmentIndex)Returns the Compound at the given biological indexCompoundSet<C>getCompoundSet()Gets the compound set used to back this SequencedoublegetCoverage()Returns the coverage, as a fraction between 0 and 1, of thisAlignedSequencewith respect to the original sequence.PointgetEnd()intgetIndexOf(C compound)Scans through the Sequence looking for the first occurrence of the given compoundSequenceView<C>getInverse()Does the right thing to get the inverse of the current Sequence.intgetLastIndexOf(C compound)Scans through the Sequence looking for the last occurrence of the given compoundintgetLength()Returns the length of the SequenceLocationgetLocationInAlignment()intgetNumGapPositions()Returns number of gap positions (gap openings and extensions) in the sequence.intgetNumGaps()Returns number of gaps (gap openings) in the sequence.SgetOriginalSequence()Returns the originalSequencebefore alignment.intgetOverlapCount()Returns the maximum number of elements contributed to a column of an alignment by thisSequence.StringgetSequenceAsString()Returns the String representation of the Sequenceint[]getSequenceFromAlignment()Returns the sequence positions at each alignment indexintgetSequenceIndexAt(int alignmentIndex)Returns the index in the originalSequencecorresponding to the given index within an alignment.PointgetStart()SequenceView<C>getSubSequence(Integer start, Integer end)Returns a portion of the sequence from the different positions.inthashCode()booleanisCircular()Returns true if thisSequencewraps around from the last alignment column back to the first.booleanisGap(int alignmentIndex)Returns true if thisSequencehas a gap at a particular alignment column.Iterator<C>iterator()StringtoString()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 Detail
-
SimpleAlignedSequence
public SimpleAlignedSequence(S original, List<AlignedSequence.Step> steps)
Creates anAlignedSequencefor the givenSequencein a global alignment.- Parameters:
original- the originalSequencebefore alignmentsteps- lists whether the sequence aligns aCompoundor 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 anAlignedSequencefor the givenSequencein a local alignment.- Parameters:
original- the originalSequencebefore alignmentsteps- lists whether the sequence aligns aCompoundor gap at each index of the alignmentnumBefore- number ofCompounds before a local alignmentnumAfter- number ofCompounds 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 newAlignedSequencefor the givenAlignedSequencein a global alignment.- Parameters:
prev- the previousAlignedSequencebefore this alignmentsteps- lists whether the sequence aligns aCompoundor 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 newAlignedSequencefor the givenAlignedSequencein a local alignment.- Parameters:
prev- the previousAlignedSequencebefore this alignmentsteps- lists whether the sequence aligns aCompoundor gap at each index of the alignmentnumBefore- number ofCompounds before a local alignmentnumAfter- number ofCompounds after a local alignment- Throws:
IllegalArgumentException- if given sequence does not fit in alignment
-
-
Method Detail
-
clearCache
public void clearCache()
Description copied from interface:AlignedSequenceNullifies cached arrays/objects.- Specified by:
clearCachein interfaceAlignedSequence<S extends Sequence<C>,C extends Compound>
-
getAlignmentFromSequence
public int[] getAlignmentFromSequence()
Description copied from interface:AlignedSequenceReturns the alignment.- Specified by:
getAlignmentFromSequencein interfaceAlignedSequence<S extends Sequence<C>,C extends Compound>- Returns:
- the alignment
-
getAlignmentIndexAt
public int getAlignmentIndexAt(int sequenceIndex)
Description copied from interface:AlignedSequenceReturns the column index within an alignment corresponding to the given index in the originalSequence. Both indices are 1-indexed and inclusive.- Specified by:
getAlignmentIndexAtin interfaceAlignedSequence<S extends Sequence<C>,C extends Compound>- Parameters:
sequenceIndex- index in the originalSequence- Returns:
- column index within an alignment
-
getEnd
public Point getEnd()
Description copied from interface:AlignedSequence
-
getLocationInAlignment
public Location getLocationInAlignment()
Description copied from interface:AlignedSequenceReturns theLocationof the originalSequencewithin an alignment. This provides access to additional substructure beyond start and end points.- Specified by:
getLocationInAlignmentin interfaceAlignedSequence<S extends Sequence<C>,C extends Compound>- Returns:
- location within an alignment
-
getNumGaps
public int getNumGaps()
Description copied from interface:AlignedSequenceReturns number of gaps (gap openings) in the sequence. This could be determined from theLocationinformation or from gapCompounds, which may not necessarily result in the same number.- Specified by:
getNumGapsin interfaceAlignedSequence<S extends Sequence<C>,C extends Compound>- Returns:
- number of gaps in the sequence
-
getOriginalSequence
public S getOriginalSequence()
Description copied from interface:AlignedSequenceReturns the originalSequencebefore alignment.- Specified by:
getOriginalSequencein interfaceAlignedSequence<S extends Sequence<C>,C extends Compound>- Returns:
- the original sequence
-
getOverlapCount
public int getOverlapCount()
Description copied from interface:AlignedSequenceReturns the maximum number of elements contributed to a column of an alignment by thisSequence. If thisSequenceis circular, this number is >= 1. If not, this overlap count is definitely 1.- Specified by:
getOverlapCountin 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:AlignedSequenceReturns the sequence positions at each alignment index- Specified by:
getSequenceFromAlignmentin interfaceAlignedSequence<S extends Sequence<C>,C extends Compound>- Returns:
- array of the sequence positions
-
getSequenceIndexAt
public int getSequenceIndexAt(int alignmentIndex)
Description copied from interface:AlignedSequenceReturns the index in the originalSequencecorresponding to the given index within an alignment. Both indices are 1-indexed and inclusive.- Specified by:
getSequenceIndexAtin interfaceAlignedSequence<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
-
isCircular
public boolean isCircular()
Description copied from interface:AlignedSequenceReturns true if thisSequencewraps around from the last alignment column back to the first. This makes overlap possible, but does not require an overlap count > 1.- Specified by:
isCircularin interfaceAlignedSequence<S extends Sequence<C>,C extends Compound>- Returns:
- true for circular alignment elements
-
isGap
public boolean isGap(int alignmentIndex)
Description copied from interface:AlignedSequenceReturns true if thisSequencehas a gap at a particular alignment column.
-
countCompounds
public int countCompounds(C... compounds)
Description copied from interface:SequenceReturns the number of times we found a compound in the Sequence- Specified by:
countCompoundsin interfaceSequence<S extends Sequence<C>>- Parameters:
compounds- Vargs of the compounds to count- Returns:
- Number of times a compound was found
-
getAccession
public AccessionID getAccession()
Description copied from interface:AccessionedReturns the AccessionID this location is currently bound with- Specified by:
getAccessionin interfaceAccessioned
-
getAsList
public List<C> getAsList()
Description copied from interface:SequenceReturns the Sequence as a List of compounds
-
getCompoundAt
public C getCompoundAt(int alignmentIndex)
Description copied from interface:SequenceReturns the Compound at the given biological index- Specified by:
getCompoundAtin interfaceSequence<S extends Sequence<C>>- Parameters:
alignmentIndex- Biological index (1 to n)- Returns:
- Compound at the specified position
-
getCompoundSet
public CompoundSet<C> getCompoundSet()
Description copied from interface:SequenceGets the compound set used to back this Sequence- Specified by:
getCompoundSetin interfaceSequence<S extends Sequence<C>>
-
getIndexOf
public int getIndexOf(C compound)
Description copied from interface:SequenceScans through the Sequence looking for the first occurrence of the given compound- Specified by:
getIndexOfin 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
public int getLastIndexOf(C compound)
Description copied from interface:SequenceScans through the Sequence looking for the last occurrence of the given compound- Specified by:
getLastIndexOfin 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:SequenceReturns the length of the Sequence
-
getSequenceAsString
public String getSequenceAsString()
Description copied from interface:SequenceReturns the String representation of the Sequence- Specified by:
getSequenceAsStringin interfaceSequence<S extends Sequence<C>>
-
getSubSequence
public SequenceView<C> getSubSequence(Integer start, Integer end)
Description copied from interface:SequenceReturns a portion of the sequence from the different positions. This is indexed from 1- Specified by:
getSubSequencein 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
-
toString
public String toString()
Provides standard Java language access to results ofgetSequenceAsString().
-
getInverse
public SequenceView<C> getInverse()
Description copied from interface:SequenceDoes the right thing to get the inverse of the current Sequence. This means either reversing the Sequence and optionally complementing the Sequence.- Specified by:
getInversein interfaceSequence<S extends Sequence<C>>
-
getNumGapPositions
public int getNumGapPositions()
Description copied from interface:AlignedSequenceReturns number of gap positions (gap openings and extensions) in the sequence. This could be determined from theLocationinformation or from gapCompounds, which may not necessarily result in the same number.- Specified by:
getNumGapPositionsin interfaceAlignedSequence<S extends Sequence<C>,C extends Compound>- Returns:
- number of gap positions in the sequence
-
getCoverage
public double getCoverage()
Description copied from interface:AlignedSequenceReturns the coverage, as a fraction between 0 and 1, of thisAlignedSequencewith respect to the original sequence. This is equivalent to (Sequence.getLength()-AlignedSequence.getNumGapPositions()) / getOriginalSequence().getLength().- Specified by:
getCoveragein interfaceAlignedSequence<S extends Sequence<C>,C extends Compound>- Returns:
- coverage of the original sequence by the aligned sequence
-
-