2009-09-18 07:28:47 +08:00
|
|
|
package org.broadinstitute.sting.alignment.bwa;
|
|
|
|
|
|
|
|
|
|
import org.broadinstitute.sting.alignment.Alignment;
|
2009-09-18 06:43:11 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* An alignment object to be used incrementally as the BWA aligner
|
|
|
|
|
* inspects the read.
|
|
|
|
|
*
|
|
|
|
|
* @author mhanna
|
|
|
|
|
* @version 0.1
|
|
|
|
|
*/
|
|
|
|
|
public class BWAAlignment implements Alignment {
|
2009-09-24 07:44:59 +08:00
|
|
|
/**
|
|
|
|
|
* Start of the final alignment.
|
|
|
|
|
*/
|
|
|
|
|
protected int alignmentStart;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Working variable. Is this match being treated as a negative or positive strand?
|
|
|
|
|
*/
|
|
|
|
|
protected boolean negativeStrand;
|
|
|
|
|
|
2009-09-23 03:05:10 +08:00
|
|
|
/**
|
|
|
|
|
* Working variable. How many bases have been matched at this point.
|
|
|
|
|
*/
|
|
|
|
|
protected int position;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Working variable. How many mismatches have been encountered at this point.
|
|
|
|
|
*/
|
|
|
|
|
protected int mismatches;
|
|
|
|
|
|
2009-09-25 05:03:02 +08:00
|
|
|
/**
|
|
|
|
|
* Number of gap opens in alignment.
|
|
|
|
|
*/
|
|
|
|
|
protected int gapOpens;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Number of gap extensions in alignment.
|
|
|
|
|
*/
|
|
|
|
|
protected int gapExtensions;
|
|
|
|
|
|
2009-09-18 06:43:11 +08:00
|
|
|
/**
|
|
|
|
|
* Working variable. The lower bound of the alignment within the BWT.
|
|
|
|
|
*/
|
|
|
|
|
protected int loBound;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Working variable. The upper bound of the alignment within the BWT.
|
|
|
|
|
*/
|
|
|
|
|
protected int hiBound;
|
|
|
|
|
|
|
|
|
|
/**
|
2009-09-23 03:05:10 +08:00
|
|
|
* Indicates the current state of an alignment. Are we in an insertion? Deletion?
|
2009-09-18 06:43:11 +08:00
|
|
|
*/
|
2009-09-25 05:03:02 +08:00
|
|
|
protected AlignmentState state;
|
2009-09-24 07:44:59 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the starting position for the given alignment.
|
|
|
|
|
* @return Starting position.
|
|
|
|
|
*/
|
|
|
|
|
public int getAlignmentStart() {
|
|
|
|
|
return alignmentStart;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Is the given alignment on the reverse strand?
|
|
|
|
|
* @return True if the alignment is on the reverse strand.
|
|
|
|
|
*/
|
|
|
|
|
public boolean isNegativeStrand() {
|
|
|
|
|
return negativeStrand;
|
|
|
|
|
}
|
2009-09-18 06:43:11 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the BWA score of this alignment.
|
|
|
|
|
* @return BWA-style scores. 0 is best.
|
|
|
|
|
*/
|
|
|
|
|
public int getScore() {
|
2009-09-25 05:03:02 +08:00
|
|
|
return mismatches + gapOpens + gapExtensions;
|
2009-09-18 06:43:11 +08:00
|
|
|
}
|
|
|
|
|
|
2009-09-25 05:03:02 +08:00
|
|
|
public int getMismatches() { return mismatches; }
|
|
|
|
|
public int getGapOpens() { return gapOpens; }
|
|
|
|
|
public int getGapExtensions() { return gapExtensions; }
|
|
|
|
|
|
2009-09-18 06:43:11 +08:00
|
|
|
/**
|
|
|
|
|
* Compare this alignment to another alignment.
|
|
|
|
|
* @param other Other alignment to which to compare.
|
|
|
|
|
* @return < 0 if this < other, == 0 if this == other, > 0 if this > other
|
|
|
|
|
*/
|
2009-09-23 03:05:10 +08:00
|
|
|
public int compareTo(Alignment other) {
|
|
|
|
|
// If the scores are equal, use the position to disambiguate order.
|
|
|
|
|
int scoreComparison = Integer.valueOf(getScore()).compareTo(other.getScore());
|
|
|
|
|
if( scoreComparison != 0 )
|
|
|
|
|
return scoreComparison;
|
|
|
|
|
else
|
2009-09-24 07:44:59 +08:00
|
|
|
return -Integer.valueOf(position).compareTo(((BWAAlignment)other).position);
|
2009-09-23 03:05:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String toString() {
|
2009-09-25 05:03:02 +08:00
|
|
|
return String.format("position: %d, state: %s, mismatches: %d, gap opens: %d, gap extensions: %d, loBound: %d, hiBound: %d, score: %d", position, state, mismatches, gapOpens, gapExtensions, loBound, hiBound, getScore());
|
2009-09-18 06:43:11 +08:00
|
|
|
}
|
|
|
|
|
}
|