- java.lang.Object
-
- org.biojava.nbio.alignment.template.AbstractScorer
-
- org.biojava.nbio.alignment.template.AbstractMatrixAligner<S,C>
-
- Type Parameters:
S
- each element of the alignmentProfile
is of type SC
- each element of anAlignedSequence
is aCompound
of type C
- All Implemented Interfaces:
Aligner<S,C>
,MatrixAligner<S,C>
,Scorer
- Direct Known Subclasses:
AbstractPairwiseSequenceAligner
,AbstractProfileProfileAligner
public abstract class AbstractMatrixAligner<S extends Sequence<C>,C extends Compound> extends AbstractScorer implements MatrixAligner<S,C>
Implements common code for anAligner
which builds a score matrix during computation.- Author:
- Mark Chapman, Daniel Cameron
-
-
Field Summary
Fields Modifier and Type Field Description protected List<AlignerHelper.Anchor>
anchors
protected int
cutsPerSection
protected GapPenalty
gapPenalty
protected int
max
protected int
min
protected Profile<S,C>
profile
protected int
score
protected int[][][]
scores
Dynamic programming score matrix The first dimension has the length of the first (query) sequence + 1 The second has the length of the second (target) sequence + 1 The third has length 1 for linear gap penalty and 3 for affine/constant gap (one each for match/substitution, deletion, insertion)protected long
time
protected int[]
xyMax
End position of the aligned sequence in the query and target respectivelyprotected int[]
xyStart
Start position of the aligned sequence in the query and target respectively
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractMatrixAligner()
Before running an alignment, data must be sent in via calls tosetGapPenalty(GapPenalty)
andsetSubstitutionMatrix(SubstitutionMatrix)
.protected
AbstractMatrixAligner(GapPenalty gapPenalty, SubstitutionMatrix<C> subMatrix)
Prepares for an alignment.protected
AbstractMatrixAligner(GapPenalty gapPenalty, SubstitutionMatrix<C> subMatrix, boolean local)
Prepares for an alignment.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
align()
Performs alignmentprotected abstract CompoundSet<C>
getCompoundSet()
protected abstract List<C>
getCompoundsOfQuery()
protected abstract List<C>
getCompoundsOfTarget()
long
getComputationTime()
Returns the computation time needed for an alignment computed in nanoseconds.GapPenalty
getGapPenalty()
Returns the gap penalties.double
getMaxScore()
Returns maximum possible score.double
getMinScore()
Returns minimum possible score.Profile<S,C>
getProfile()
Returns the alignmentProfile
produced by this alignment algorithm.double
getScore()
Returns score resulting from algorithm.int[][][]
getScoreMatrix()
Returns the entire score matrix built during alignment.String
getScoreMatrixAsString()
Returns a depiction of the score matrix as aString
.protected abstract int[]
getScoreMatrixDimensions()
SubstitutionMatrix<C>
getSubstitutionMatrix()
Returns the substitution matrix.protected abstract int
getSubstitutionScore(int queryColumn, int targetColumn)
protected int[]
getSubstitutionScoreVector(int queryColumn)
Returns score for the alignment of the query column to all target columnsprotected int[]
getSubstitutionScoreVector(int queryColumn, AlignerHelper.Subproblem subproblem)
Returns score for the alignment of the query column to all target columnsboolean
isLocal()
Returns whether alignment finds a region of similarity rather than aligning every compound.protected abstract boolean
isReady()
boolean
isStoringScoreMatrix()
Returns choice to cache the score matrix or to save memory by deleting score matrix after alignment.protected void
reset()
Resets output fields; should be overridden to set max and minvoid
setGapPenalty(GapPenalty gapPenalty)
Sets the gap penalties.protected abstract void
setProfile(List<AlignedSequence.Step> sx, List<AlignedSequence.Step> sy)
void
setStoringScoreMatrix(boolean storingScoreMatrix)
Sets choice to cache the score matrix or to save memory by deleting score matrix after alignment.void
setSubstitutionMatrix(SubstitutionMatrix<C> subMatrix)
Sets the substitution matrix.-
Methods inherited from class org.biojava.nbio.alignment.template.AbstractScorer
getDistance, getDistance, getSimilarity, getSimilarity
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.biojava.nbio.alignment.template.Scorer
getDistance, getDistance, getSimilarity, getSimilarity
-
-
-
-
Field Detail
-
gapPenalty
protected GapPenalty gapPenalty
-
anchors
protected List<AlignerHelper.Anchor> anchors
-
cutsPerSection
protected int cutsPerSection
-
xyStart
protected int[] xyStart
Start position of the aligned sequence in the query and target respectively
-
xyMax
protected int[] xyMax
End position of the aligned sequence in the query and target respectively
-
max
protected int max
-
min
protected int min
-
score
protected int score
-
scores
protected int[][][] scores
Dynamic programming score matrix The first dimension has the length of the first (query) sequence + 1 The second has the length of the second (target) sequence + 1 The third has length 1 for linear gap penalty and 3 for affine/constant gap (one each for match/substitution, deletion, insertion)
-
time
protected long time
-
-
Constructor Detail
-
AbstractMatrixAligner
protected AbstractMatrixAligner()
Before running an alignment, data must be sent in via calls tosetGapPenalty(GapPenalty)
andsetSubstitutionMatrix(SubstitutionMatrix)
.
-
AbstractMatrixAligner
protected AbstractMatrixAligner(GapPenalty gapPenalty, SubstitutionMatrix<C> subMatrix)
Prepares for an alignment.- Parameters:
gapPenalty
- the gap penalties used during alignmentsubMatrix
- the set of substitution scores used during alignment
-
AbstractMatrixAligner
protected AbstractMatrixAligner(GapPenalty gapPenalty, SubstitutionMatrix<C> subMatrix, boolean local)
Prepares for an alignment.- Parameters:
gapPenalty
- the gap penalties used during alignmentsubMatrix
- the set of substitution scores used during alignmentlocal
- if true, find a region of similarity rather than aligning every compound
-
-
Method Detail
-
getGapPenalty
public GapPenalty getGapPenalty()
Returns the gap penalties.- Returns:
- the gap penalties used during alignment
-
getSubstitutionMatrix
public SubstitutionMatrix<C> getSubstitutionMatrix()
Returns the substitution matrix.- Returns:
- the set of substitution scores used during alignment
-
isLocal
public boolean isLocal()
Returns whether alignment finds a region of similarity rather than aligning every compound.- Returns:
- true if alignment finds a region of similarity rather than aligning every compound
-
isStoringScoreMatrix
public boolean isStoringScoreMatrix()
Returns choice to cache the score matrix or to save memory by deleting score matrix after alignment.- Returns:
- choice to cache the score matrix
-
setGapPenalty
public void setGapPenalty(GapPenalty gapPenalty)
Sets the gap penalties.- Parameters:
gapPenalty
- the gap penalties used during alignment
-
setSubstitutionMatrix
public void setSubstitutionMatrix(SubstitutionMatrix<C> subMatrix)
Sets the substitution matrix.- Parameters:
subMatrix
- the set of substitution scores used during alignment
-
setStoringScoreMatrix
public void setStoringScoreMatrix(boolean storingScoreMatrix)
Sets choice to cache the score matrix or to save memory by deleting score matrix after alignment.- Parameters:
storingScoreMatrix
- choice to cache the score matrix
-
getScoreMatrix
public int[][][] getScoreMatrix()
Description copied from interface:MatrixAligner
Returns the entire score matrix built during alignment. The first dimension has the length of the first (query) sequence + 1; the second has the length of the second (target) sequence + 1; the third has length equal to the number of scores stored per pairing of an element from eachSequence
.- Specified by:
getScoreMatrix
in interfaceMatrixAligner<S extends Sequence<C>,C extends Compound>
- Returns:
- the score matrix
-
getScoreMatrixAsString
public String getScoreMatrixAsString()
Description copied from interface:MatrixAligner
Returns a depiction of the score matrix as aString
. This may include additional description such as labels for each dimension: element from query sequence, element from target sequence, and meaning of each score.- Specified by:
getScoreMatrixAsString
in interfaceMatrixAligner<S extends Sequence<C>,C extends Compound>
- Returns:
- the score matrix as a character sequence
-
getComputationTime
public long getComputationTime()
Description copied from interface:Aligner
Returns the computation time needed for an alignment computed in nanoseconds.
-
getProfile
public Profile<S,C> getProfile()
Description copied from interface:Aligner
Returns the alignmentProfile
produced by this alignment algorithm.
-
getMaxScore
public double getMaxScore()
Description copied from interface:Scorer
Returns maximum possible score.- Specified by:
getMaxScore
in interfaceScorer
- Returns:
- maximum possible score
-
getMinScore
public double getMinScore()
Description copied from interface:Scorer
Returns minimum possible score.- Specified by:
getMinScore
in interfaceScorer
- Returns:
- minimum possible score
-
getScore
public double getScore()
Description copied from interface:Scorer
Returns score resulting from algorithm. This should normalize between 0 and 1 by calculating (Scorer.getScore()
-Scorer.getMinScore()
) / (Scorer.getMaxScore()
-Scorer.getMinScore()
).
-
align
protected void align()
Performs alignment
-
getSubstitutionScoreVector
protected int[] getSubstitutionScoreVector(int queryColumn)
Returns score for the alignment of the query column to all target columns- Parameters:
queryColumn
-- Returns:
-
getSubstitutionScoreVector
protected int[] getSubstitutionScoreVector(int queryColumn, AlignerHelper.Subproblem subproblem)
Returns score for the alignment of the query column to all target columns- Parameters:
queryColumn
-subproblem
-- Returns:
-
reset
protected void reset()
Resets output fields; should be overridden to set max and min
-
getCompoundSet
protected abstract CompoundSet<C> getCompoundSet()
-
getCompoundsOfQuery
protected abstract List<C> getCompoundsOfQuery()
-
getCompoundsOfTarget
protected abstract List<C> getCompoundsOfTarget()
-
getScoreMatrixDimensions
protected abstract int[] getScoreMatrixDimensions()
-
getSubstitutionScore
protected abstract int getSubstitutionScore(int queryColumn, int targetColumn)
-
isReady
protected abstract boolean isReady()
-
setProfile
protected abstract void setProfile(List<AlignedSequence.Step> sx, List<AlignedSequence.Step> sy)
-
-