2009-09-18 07:28:47 +08:00
|
|
|
package org.broadinstitute.sting.alignment;
|
2009-09-18 06:43:11 +08:00
|
|
|
|
2009-10-29 05:37:49 +08:00
|
|
|
import net.sf.samtools.Cigar;
|
|
|
|
|
import net.sf.samtools.CigarOperator;
|
|
|
|
|
import net.sf.samtools.CigarElement;
|
|
|
|
|
|
2009-09-18 06:43:11 +08:00
|
|
|
/**
|
|
|
|
|
* Represents an alignment of a read to a site in the reference genome.
|
|
|
|
|
*
|
|
|
|
|
* @author mhanna
|
|
|
|
|
* @version 0.1
|
|
|
|
|
*/
|
2009-10-29 05:37:49 +08:00
|
|
|
public class Alignment {
|
|
|
|
|
protected int contigIndex;
|
|
|
|
|
protected long alignmentStart;
|
|
|
|
|
protected boolean negativeStrand;
|
|
|
|
|
protected int mappingQuality;
|
|
|
|
|
|
2009-11-20 03:03:43 +08:00
|
|
|
protected char[] cigarOperators;
|
|
|
|
|
protected int[] cigarLengths;
|
|
|
|
|
|
|
|
|
|
protected int numMismatches;
|
|
|
|
|
protected int numGapOpens;
|
|
|
|
|
protected int numGapExtensions;
|
|
|
|
|
protected int bestCount;
|
|
|
|
|
protected int secondBestCount;
|
2009-10-29 05:37:49 +08:00
|
|
|
|
2009-09-24 07:44:59 +08:00
|
|
|
/**
|
2009-10-29 05:37:49 +08:00
|
|
|
* Gets the index of the given contig.
|
|
|
|
|
* @return the inde
|
2009-09-24 07:44:59 +08:00
|
|
|
*/
|
2009-10-29 05:37:49 +08:00
|
|
|
public int getContigIndex() { return contigIndex; }
|
2009-09-24 07:44:59 +08:00
|
|
|
|
2009-09-25 05:03:02 +08:00
|
|
|
/**
|
|
|
|
|
* Gets the starting position for the given alignment.
|
|
|
|
|
* @return Starting position.
|
|
|
|
|
*/
|
2009-10-29 05:37:49 +08:00
|
|
|
public long 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-25 05:03:02 +08:00
|
|
|
|
2009-09-18 06:43:11 +08:00
|
|
|
/**
|
|
|
|
|
* Gets the score of this alignment.
|
|
|
|
|
* @return The score.
|
|
|
|
|
*/
|
2009-10-29 05:37:49 +08:00
|
|
|
public int getMappingQuality() { return mappingQuality; }
|
|
|
|
|
|
2009-11-20 03:03:43 +08:00
|
|
|
/**
|
|
|
|
|
* Gets the number of mismatches in the read.
|
|
|
|
|
* @return Number of mismatches.
|
|
|
|
|
*/
|
|
|
|
|
public int getNumMismatches() { return numMismatches; }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the number of gap opens.
|
|
|
|
|
* @return Number of gap opens.
|
|
|
|
|
*/
|
|
|
|
|
public int getNumGapOpens() { return numGapOpens; }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the number of gap extensions.
|
|
|
|
|
* @return Number of gap extensions.
|
|
|
|
|
*/
|
|
|
|
|
public int getNumGapExtensions() { return numGapExtensions; }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the number of best alignments.
|
|
|
|
|
* @return Number of top scoring alignments.
|
|
|
|
|
*/
|
|
|
|
|
public int getBestCount() { return bestCount; }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the number of second best alignments.
|
|
|
|
|
* @return Number of second best scoring alignments.
|
|
|
|
|
*/
|
|
|
|
|
public int getSecondBestCount() { return secondBestCount; }
|
|
|
|
|
|
2009-10-29 05:37:49 +08:00
|
|
|
/**
|
|
|
|
|
* Gets the cigar for this alignment.
|
|
|
|
|
* @return sam-jdk formatted alignment.
|
|
|
|
|
*/
|
|
|
|
|
public Cigar getCigar() {
|
|
|
|
|
Cigar cigar = new Cigar();
|
|
|
|
|
for(int i = 0; i < cigarOperators.length; i++) {
|
|
|
|
|
CigarOperator operator = CigarOperator.characterToEnum(cigarOperators[i]);
|
|
|
|
|
cigar.add(new CigarElement(cigarLengths[i],operator));
|
|
|
|
|
}
|
|
|
|
|
return cigar;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Temporarily implement getCigarString() for debugging; the TextCigarCodec is unfortunately
|
|
|
|
|
* package-protected.
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public String getCigarString() {
|
|
|
|
|
Cigar cigar = getCigar();
|
|
|
|
|
if(cigar.isEmpty()) return "*";
|
|
|
|
|
|
|
|
|
|
StringBuilder cigarString = new StringBuilder();
|
|
|
|
|
for(CigarElement element: cigar.getCigarElements()) {
|
|
|
|
|
cigarString.append(element.getLength());
|
|
|
|
|
cigarString.append(element.getOperator());
|
|
|
|
|
}
|
|
|
|
|
return cigarString.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Stub for inheritance.
|
|
|
|
|
*/
|
|
|
|
|
public Alignment() {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new alignment object.
|
|
|
|
|
* @param contigIndex The contig to which this read aligned.
|
|
|
|
|
* @param alignmentStart The point within the contig to which this read aligned.
|
|
|
|
|
* @param negativeStrand Forward or reverse alignment of the given read.
|
|
|
|
|
* @param mappingQuality How good does BWA think this mapping is?
|
|
|
|
|
* @param cigarOperators The ordered operators in the cigar string.
|
|
|
|
|
* @param cigarLengths The lengths to which each operator applies.
|
|
|
|
|
*/
|
2009-11-20 03:03:43 +08:00
|
|
|
public Alignment(int contigIndex,
|
|
|
|
|
int alignmentStart,
|
|
|
|
|
boolean negativeStrand,
|
|
|
|
|
int mappingQuality,
|
|
|
|
|
char[] cigarOperators,
|
|
|
|
|
int[] cigarLengths,
|
|
|
|
|
int numMismatches,
|
|
|
|
|
int numGapOpens,
|
|
|
|
|
int numGapExtensions,
|
|
|
|
|
int bestCount,
|
|
|
|
|
int secondBestCount) {
|
2009-10-29 05:37:49 +08:00
|
|
|
this.contigIndex = contigIndex;
|
|
|
|
|
this.alignmentStart = alignmentStart;
|
|
|
|
|
this.negativeStrand = negativeStrand;
|
|
|
|
|
this.mappingQuality = mappingQuality;
|
|
|
|
|
this.cigarOperators = cigarOperators;
|
|
|
|
|
this.cigarLengths = cigarLengths;
|
2009-11-20 03:03:43 +08:00
|
|
|
this.numMismatches = numMismatches;
|
|
|
|
|
this.numGapOpens = numGapOpens;
|
|
|
|
|
this.numGapExtensions = numGapExtensions;
|
|
|
|
|
this.bestCount = bestCount;
|
|
|
|
|
this.secondBestCount = secondBestCount;
|
2009-10-29 05:37:49 +08:00
|
|
|
}
|
2009-09-18 06:43:11 +08:00
|
|
|
}
|