Cleanup existing speedups. Minor performance improvements.
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1823 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
837ae1d33a
commit
a76fac4687
|
|
@ -47,7 +47,7 @@ public class AlignerTestHarness {
|
||||||
|
|
||||||
for(SAMRecord read: reader) {
|
for(SAMRecord read: reader) {
|
||||||
count++;
|
count++;
|
||||||
if( count > 100000 ) break;
|
if( count > 200000 ) break;
|
||||||
//if( count < 366000 ) continue;
|
//if( count < 366000 ) continue;
|
||||||
//if( count != 2 ) continue;
|
//if( count != 2 ) continue;
|
||||||
//if( !read.getReadName().endsWith("SL-XBC:1:82:506:404#0") )
|
//if( !read.getReadName().endsWith("SL-XBC:1:82:506:404#0") )
|
||||||
|
|
|
||||||
|
|
@ -82,8 +82,8 @@ public class BWAAligner implements Aligner {
|
||||||
public List<Alignment> align( SAMRecord read ) {
|
public List<Alignment> align( SAMRecord read ) {
|
||||||
List<Alignment> successfulMatches = new ArrayList<Alignment>();
|
List<Alignment> successfulMatches = new ArrayList<Alignment>();
|
||||||
|
|
||||||
byte[] uncomplementedBases = read.getReadBases();
|
Byte[] uncomplementedBases = normalizeBases(read.getReadBases());
|
||||||
byte[] complementedBases = BaseUtils.reverse(BaseUtils.simpleReverseComplement(uncomplementedBases));
|
Byte[] complementedBases = normalizeBases(BaseUtils.reverse(BaseUtils.simpleReverseComplement(read.getReadBases())));
|
||||||
|
|
||||||
List<LowerBound> forwardLowerBounds = LowerBound.create(uncomplementedBases,forwardBWT);
|
List<LowerBound> forwardLowerBounds = LowerBound.create(uncomplementedBases,forwardBWT);
|
||||||
List<LowerBound> reverseLowerBounds = LowerBound.create(complementedBases,reverseBWT);
|
List<LowerBound> reverseLowerBounds = LowerBound.create(complementedBases,reverseBWT);
|
||||||
|
|
@ -107,7 +107,7 @@ public class BWAAligner implements Aligner {
|
||||||
if( alignment.getScore() > bestScore + MISMATCH_PENALTY )
|
if( alignment.getScore() > bestScore + MISMATCH_PENALTY )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
byte[] bases = alignment.negativeStrand ? complementedBases : uncomplementedBases;
|
Byte[] bases = alignment.negativeStrand ? complementedBases : uncomplementedBases;
|
||||||
BWT bwt = alignment.negativeStrand ? forwardBWT : reverseBWT;
|
BWT bwt = alignment.negativeStrand ? forwardBWT : reverseBWT;
|
||||||
List<LowerBound> lowerBounds = alignment.negativeStrand ? reverseLowerBounds : forwardLowerBounds;
|
List<LowerBound> lowerBounds = alignment.negativeStrand ? reverseLowerBounds : forwardLowerBounds;
|
||||||
|
|
||||||
|
|
@ -236,11 +236,11 @@ public class BWAAligner implements Aligner {
|
||||||
* @param allowMismatch Should mismatching bases be allowed?
|
* @param allowMismatch Should mismatching bases be allowed?
|
||||||
* @return New alignment representing this position if valid; null otherwise.
|
* @return New alignment representing this position if valid; null otherwise.
|
||||||
*/
|
*/
|
||||||
private List<BWAAlignment> createMatchedAlignments( BWT bwt, BWAAlignment alignment, byte[] bases, boolean allowMismatch ) {
|
private List<BWAAlignment> createMatchedAlignments( BWT bwt, BWAAlignment alignment, Byte[] bases, boolean allowMismatch ) {
|
||||||
List<BWAAlignment> newAlignments = new ArrayList<BWAAlignment>();
|
List<BWAAlignment> newAlignments = new ArrayList<BWAAlignment>();
|
||||||
|
|
||||||
List<Byte> baseChoices = new ArrayList<Byte>();
|
List<Byte> baseChoices = new ArrayList<Byte>();
|
||||||
Byte thisBase = Bases.fromASCII(bases[alignment.position+1]);
|
Byte thisBase = bases[alignment.position+1];
|
||||||
|
|
||||||
if( allowMismatch )
|
if( allowMismatch )
|
||||||
baseChoices.addAll(Bases.allOf());
|
baseChoices.addAll(Bases.allOf());
|
||||||
|
|
@ -269,7 +269,7 @@ public class BWAAligner implements Aligner {
|
||||||
|
|
||||||
newAlignment.position++;
|
newAlignment.position++;
|
||||||
newAlignment.addState(AlignmentState.MATCH_MISMATCH);
|
newAlignment.addState(AlignmentState.MATCH_MISMATCH);
|
||||||
if( Bases.fromASCII(bases[newAlignment.position]) == null || base != Bases.fromASCII(bases[newAlignment.position]) )
|
if( bases[newAlignment.position] == null || base != bases[newAlignment.position] )
|
||||||
newAlignment.incrementMismatches();
|
newAlignment.incrementMismatches();
|
||||||
|
|
||||||
newAlignments.add(newAlignment);
|
newAlignments.add(newAlignment);
|
||||||
|
|
@ -323,13 +323,25 @@ public class BWAAligner implements Aligner {
|
||||||
* @param bases Bases to use.
|
* @param bases Bases to use.
|
||||||
* @param bwt BWT to use.
|
* @param bwt BWT to use.
|
||||||
*/
|
*/
|
||||||
private void exactMatch( BWAAlignment alignment, byte[] bases, BWT bwt ) {
|
private void exactMatch( BWAAlignment alignment, Byte[] bases, BWT bwt ) {
|
||||||
while( ++alignment.position < bases.length ) {
|
while( ++alignment.position < bases.length ) {
|
||||||
byte base = Bases.fromASCII(bases[alignment.position]);
|
byte base = bases[alignment.position];
|
||||||
alignment.loBound = bwt.counts(base) + bwt.occurrences(base,alignment.loBound-1) + 1;
|
alignment.loBound = bwt.counts(base) + bwt.occurrences(base,alignment.loBound-1) + 1;
|
||||||
alignment.hiBound = bwt.counts(base) + bwt.occurrences(base,alignment.hiBound);
|
alignment.hiBound = bwt.counts(base) + bwt.occurrences(base,alignment.hiBound);
|
||||||
if( alignment.loBound > alignment.hiBound )
|
if( alignment.loBound > alignment.hiBound )
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make each base into A/C/G/T or null if unknown.
|
||||||
|
* @param bases Base string to normalize.
|
||||||
|
* @return Array of normalized bases.
|
||||||
|
*/
|
||||||
|
private Byte[] normalizeBases( byte[] bases ) {
|
||||||
|
Byte[] normalBases = new Byte[bases.length];
|
||||||
|
for(int i = 0; i < bases.length; i++)
|
||||||
|
normalBases[i] = Bases.fromASCII(bases[i]);
|
||||||
|
return normalBases;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -196,8 +196,8 @@ public class BWAAlignment implements Alignment, Cloneable {
|
||||||
return score > other.score ? 1 : -1;
|
return score > other.score ? 1 : -1;
|
||||||
|
|
||||||
// Otherwise, use the order in which the elements were created.
|
// Otherwise, use the order in which the elements were created.
|
||||||
if(this.creationNumber != other.creationNumber)
|
if(creationNumber != other.creationNumber)
|
||||||
return this.creationNumber > other.creationNumber ? -1 : 1;
|
return creationNumber > other.creationNumber ? -1 : 1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,12 +48,12 @@ public class LowerBound {
|
||||||
/**
|
/**
|
||||||
* Create a non-optimal bound according to the algorithm specified in Figure 3 of the BWA paper.
|
* Create a non-optimal bound according to the algorithm specified in Figure 3 of the BWA paper.
|
||||||
*/
|
*/
|
||||||
public static List<LowerBound> create( byte[] bases, BWT bwt ) {
|
public static List<LowerBound> create( Byte[] bases, BWT bwt ) {
|
||||||
List<LowerBound> bounds = new ArrayList<LowerBound>();
|
List<LowerBound> bounds = new ArrayList<LowerBound>();
|
||||||
|
|
||||||
int loIndex = 0, hiIndex = bwt.length(), mismatches = 0;
|
int loIndex = 0, hiIndex = bwt.length(), mismatches = 0;
|
||||||
for( int i = bases.length-1; i >= 0; i-- ) {
|
for( int i = bases.length-1; i >= 0; i-- ) {
|
||||||
Byte base = Bases.fromASCII(bases[i]);
|
Byte base = bases[i];
|
||||||
|
|
||||||
// Ignore non-ACGT bases.
|
// Ignore non-ACGT bases.
|
||||||
if( base != null ) {
|
if( base != null ) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue