2009-09-23 03:05:10 +08:00
|
|
|
package org.broadinstitute.sting.alignment.bwa;
|
|
|
|
|
|
2009-09-24 07:44:59 +08:00
|
|
|
import org.broadinstitute.sting.alignment.bwa.bwt.*;
|
2009-09-23 03:05:10 +08:00
|
|
|
import org.broadinstitute.sting.alignment.Alignment;
|
|
|
|
|
import org.broadinstitute.sting.alignment.Aligner;
|
|
|
|
|
import org.broadinstitute.sting.utils.BaseUtils;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
2009-09-30 23:19:31 +08:00
|
|
|
import java.util.*;
|
2009-09-23 03:05:10 +08:00
|
|
|
|
|
|
|
|
import net.sf.samtools.SAMRecord;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create imperfect alignments from the read to the genome represented by the given BWT / suffix array.
|
|
|
|
|
*
|
|
|
|
|
* @author mhanna
|
|
|
|
|
* @version 0.1
|
|
|
|
|
*/
|
|
|
|
|
public class BWAAligner implements Aligner {
|
|
|
|
|
/**
|
|
|
|
|
* BWT in the forward direction.
|
|
|
|
|
*/
|
|
|
|
|
private BWT forwardBWT;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* BWT in the reverse direction.
|
|
|
|
|
*/
|
|
|
|
|
private BWT reverseBWT;
|
|
|
|
|
|
2009-09-24 07:44:59 +08:00
|
|
|
/**
|
|
|
|
|
* Suffix array in the forward direction.
|
|
|
|
|
*/
|
2009-10-01 02:10:26 +08:00
|
|
|
private SuffixArray forwardSuffixArray;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Suffix array in the reverse direction.
|
|
|
|
|
*/
|
2009-09-24 07:44:59 +08:00
|
|
|
private SuffixArray reverseSuffixArray;
|
|
|
|
|
|
2009-09-23 03:05:10 +08:00
|
|
|
/**
|
|
|
|
|
* Maximum edit distance (-n option from original BWA).
|
|
|
|
|
*/
|
2009-09-25 07:19:15 +08:00
|
|
|
private final int MAXIMUM_EDIT_DISTANCE = 4;
|
2009-09-23 03:05:10 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Maximum number of gap opens (-o option from original BWA).
|
|
|
|
|
*/
|
2009-09-25 07:19:15 +08:00
|
|
|
private final int MAXIMUM_GAP_OPENS = 1;
|
2009-09-23 03:05:10 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Maximum number of gap extensions (-e option from original BWA).
|
|
|
|
|
*/
|
2009-09-25 07:19:15 +08:00
|
|
|
private final int MAXIMUM_GAP_EXTENSIONS = 6;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Penalty for straight mismatches (-M option from original BWA).
|
|
|
|
|
*/
|
|
|
|
|
public final int MISMATCH_PENALTY = 3;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Penalty for gap opens (-O option from original BWA).
|
|
|
|
|
*/
|
|
|
|
|
public final int GAP_OPEN_PENALTY = 11;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Penalty for gap extensions (-E option from original BWA).
|
|
|
|
|
*/
|
|
|
|
|
public final int GAP_EXTENSION_PENALTY = 4;
|
2009-09-23 03:05:10 +08:00
|
|
|
|
2009-10-04 05:55:18 +08:00
|
|
|
/**
|
|
|
|
|
* Skip the ends of indels.
|
|
|
|
|
*/
|
|
|
|
|
public final int INDEL_END_SKIP = 5;
|
|
|
|
|
|
2009-10-01 02:10:26 +08:00
|
|
|
public BWAAligner( File forwardBWTFile, File reverseBWTFile, File forwardSuffixArrayFile, File reverseSuffixArrayFile ) {
|
2009-09-23 03:05:10 +08:00
|
|
|
forwardBWT = new BWTReader(forwardBWTFile).read();
|
|
|
|
|
reverseBWT = new BWTReader(reverseBWTFile).read();
|
2009-10-01 02:10:26 +08:00
|
|
|
forwardSuffixArray = new SuffixArrayReader(forwardSuffixArrayFile).read();
|
2009-09-24 07:44:59 +08:00
|
|
|
reverseSuffixArray = new SuffixArrayReader(reverseSuffixArrayFile).read();
|
2009-09-23 03:05:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Alignment> align( SAMRecord read ) {
|
2009-10-04 05:55:18 +08:00
|
|
|
List<Alignment> successfulMatches = new ArrayList<Alignment>();
|
|
|
|
|
|
2009-10-14 05:51:18 +08:00
|
|
|
Byte[] uncomplementedBases = normalizeBases(read.getReadBases());
|
|
|
|
|
Byte[] complementedBases = normalizeBases(BaseUtils.reverse(BaseUtils.simpleReverseComplement(read.getReadBases())));
|
2009-09-23 03:05:10 +08:00
|
|
|
|
2009-10-01 02:10:26 +08:00
|
|
|
List<LowerBound> forwardLowerBounds = LowerBound.create(uncomplementedBases,forwardBWT);
|
|
|
|
|
List<LowerBound> reverseLowerBounds = LowerBound.create(complementedBases,reverseBWT);
|
2009-09-30 23:19:31 +08:00
|
|
|
|
2009-10-04 05:55:18 +08:00
|
|
|
// Seed the best score with any score that won't overflow on comparison.
|
|
|
|
|
int bestScore = Integer.MAX_VALUE - MISMATCH_PENALTY;
|
|
|
|
|
int bestDiff = MAXIMUM_EDIT_DISTANCE+1;
|
|
|
|
|
int maxDiff = MAXIMUM_EDIT_DISTANCE;
|
|
|
|
|
|
2009-09-23 03:05:10 +08:00
|
|
|
PriorityQueue<BWAAlignment> alignments = new PriorityQueue<BWAAlignment>();
|
|
|
|
|
|
|
|
|
|
// Create a fictional initial alignment, with the position just off the end of the read, and the limits
|
|
|
|
|
// set as the entire BWT.
|
2009-10-01 02:10:26 +08:00
|
|
|
alignments.add(createSeedAlignment(reverseBWT));
|
2009-10-04 05:55:18 +08:00
|
|
|
alignments.add(createSeedAlignment(forwardBWT));
|
2009-09-23 03:05:10 +08:00
|
|
|
|
|
|
|
|
while(!alignments.isEmpty()) {
|
|
|
|
|
BWAAlignment alignment = alignments.remove();
|
|
|
|
|
|
2009-10-04 05:55:18 +08:00
|
|
|
// From bwtgap.c in the original BWT; if the rank is worse than the best score + the mismatch PENALTY, move on.
|
|
|
|
|
if( alignment.getScore() > bestScore + MISMATCH_PENALTY )
|
|
|
|
|
break;
|
|
|
|
|
|
2009-10-14 05:51:18 +08:00
|
|
|
Byte[] bases = alignment.negativeStrand ? complementedBases : uncomplementedBases;
|
2009-10-01 02:10:26 +08:00
|
|
|
BWT bwt = alignment.negativeStrand ? forwardBWT : reverseBWT;
|
|
|
|
|
List<LowerBound> lowerBounds = alignment.negativeStrand ? reverseLowerBounds : forwardLowerBounds;
|
2009-09-24 07:44:59 +08:00
|
|
|
|
2009-10-13 23:50:04 +08:00
|
|
|
// if z < D(i) then return {}
|
2009-10-14 04:59:29 +08:00
|
|
|
int mismatches = maxDiff - alignment.getMismatches() - alignment.getGapOpens() - alignment.getGapExtensions();
|
2009-10-13 23:50:04 +08:00
|
|
|
if( alignment.position < lowerBounds.size()-1 && mismatches < lowerBounds.get(alignment.position+1).value )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if(mismatches == 0) {
|
|
|
|
|
exactMatch(alignment,bases,bwt);
|
|
|
|
|
if(alignment.loBound > alignment.hiBound)
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-04 05:55:18 +08:00
|
|
|
// Found a valid alignment; store it and move on.
|
2009-10-13 23:50:04 +08:00
|
|
|
if(alignment.position >= read.getReadLength()-1) {
|
2009-10-05 02:20:20 +08:00
|
|
|
for( int bwtIndex = alignment.loBound; bwtIndex <= alignment.hiBound; bwtIndex++ ) {
|
|
|
|
|
BWAAlignment finalAlignment = alignment.clone();
|
|
|
|
|
|
|
|
|
|
if( finalAlignment.isNegativeStrand() )
|
|
|
|
|
finalAlignment.alignmentStart = forwardSuffixArray.get(bwtIndex) + 1;
|
|
|
|
|
else {
|
2009-10-09 03:45:30 +08:00
|
|
|
int sizeAlongReference = read.getReadLength() -
|
|
|
|
|
finalAlignment.getNumberOfBasesMatchingState(AlignmentState.INSERTION) +
|
|
|
|
|
finalAlignment.getNumberOfBasesMatchingState(AlignmentState.DELETION);
|
2009-10-05 02:20:20 +08:00
|
|
|
finalAlignment.alignmentStart = reverseBWT.length() - reverseSuffixArray.get(bwtIndex) - sizeAlongReference + 1;
|
|
|
|
|
}
|
2009-10-09 03:45:30 +08:00
|
|
|
|
2009-10-05 02:20:20 +08:00
|
|
|
successfulMatches.add(finalAlignment);
|
|
|
|
|
|
|
|
|
|
bestScore = Math.min(finalAlignment.getScore(),bestScore);
|
2009-10-14 04:59:29 +08:00
|
|
|
bestDiff = Math.min(finalAlignment.getMismatches()+finalAlignment.getGapOpens()+finalAlignment.getGapExtensions(),bestDiff);
|
2009-10-05 02:20:20 +08:00
|
|
|
maxDiff = bestDiff + 1;
|
2009-10-04 05:55:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
continue;
|
2009-09-24 07:44:59 +08:00
|
|
|
}
|
2009-09-23 03:05:10 +08:00
|
|
|
|
2009-10-04 05:55:18 +08:00
|
|
|
//System.out.printf("Processing alignments; queue size = %d, alignment = %s, bound = %d, base = %s%n", alignments.size(), alignment, lowerBounds.get(alignment.position+1).value, alignment.position >= 0 ? (char)bases[alignment.position] : "");
|
2009-10-13 23:50:04 +08:00
|
|
|
/*
|
|
|
|
|
System.out.printf("#1\t[%d,%d,%d,%c]\t[%d,%d,%d]\t[%d,%d]\t[%d,%d]%n",alignments.size(),
|
|
|
|
|
alignment.negativeStrand?1:0,
|
|
|
|
|
bases.length-alignment.position-1,
|
|
|
|
|
alignment.getCurrentState().toString().charAt(0),
|
|
|
|
|
alignment.getMismatches(),
|
|
|
|
|
alignment.getGapOpens(),
|
|
|
|
|
alignment.getGapExtensions(),
|
|
|
|
|
lowerBounds.get(alignment.position+1).value,
|
|
|
|
|
lowerBounds.get(alignment.position+1).width,
|
|
|
|
|
alignment.loBound,
|
|
|
|
|
alignment.hiBound);
|
2009-10-14 02:07:15 +08:00
|
|
|
*/
|
2009-09-23 03:05:10 +08:00
|
|
|
|
2009-10-13 23:50:04 +08:00
|
|
|
// Temporary -- look ahead to see if the next alignment is bounded.
|
|
|
|
|
boolean allowDifferences = mismatches > 0;
|
|
|
|
|
boolean allowMismatches = mismatches > 0;
|
|
|
|
|
if( alignment.position+1 < read.getReadLength()-1 ) {
|
|
|
|
|
allowDifferences &= lowerBounds.get(alignment.position+2).value <= mismatches - 1;
|
|
|
|
|
allowMismatches &=
|
|
|
|
|
!(lowerBounds.get(alignment.position+2).value == mismatches-1 && lowerBounds.get(alignment.position+1).value == mismatches-1 &&
|
|
|
|
|
lowerBounds.get(alignment.position+2).width == lowerBounds.get(alignment.position+1).width);
|
|
|
|
|
}
|
2009-09-23 03:05:10 +08:00
|
|
|
|
2009-10-13 23:50:04 +08:00
|
|
|
if( allowDifferences &&
|
2009-10-14 04:59:29 +08:00
|
|
|
alignment.position+1 >= INDEL_END_SKIP-1+alignment.getGapOpens()+alignment.getGapExtensions() &&
|
|
|
|
|
read.getReadLength()-1-(alignment.position+1) >= INDEL_END_SKIP+alignment.getGapOpens()+alignment.getGapExtensions() ) {
|
2009-10-04 05:55:18 +08:00
|
|
|
if( alignment.getCurrentState() == AlignmentState.MATCH_MISMATCH ) {
|
2009-10-14 04:59:29 +08:00
|
|
|
if( alignment.getGapOpens() < MAXIMUM_GAP_OPENS ) {
|
2009-10-04 05:55:18 +08:00
|
|
|
// Add a potential insertion extension.
|
|
|
|
|
BWAAlignment insertionAlignment = createInsertionAlignment(alignment);
|
2009-10-14 04:59:29 +08:00
|
|
|
insertionAlignment.incrementGapOpens();
|
2009-10-04 05:55:18 +08:00
|
|
|
alignments.add(insertionAlignment);
|
|
|
|
|
|
|
|
|
|
// Add a potential deletion by marking a deletion and augmenting the position.
|
|
|
|
|
List<BWAAlignment> deletionAlignments = createDeletionAlignments(bwt,alignment);
|
|
|
|
|
for( BWAAlignment deletionAlignment: deletionAlignments )
|
2009-10-14 04:59:29 +08:00
|
|
|
deletionAlignment.incrementGapOpens();
|
2009-10-04 05:55:18 +08:00
|
|
|
alignments.addAll(deletionAlignments);
|
|
|
|
|
}
|
2009-09-25 05:03:02 +08:00
|
|
|
}
|
2009-10-04 05:55:18 +08:00
|
|
|
else if( alignment.getCurrentState() == AlignmentState.INSERTION ) {
|
2009-10-14 04:59:29 +08:00
|
|
|
if( alignment.getGapExtensions() < MAXIMUM_GAP_EXTENSIONS && mismatches > 0 ) {
|
2009-10-04 05:55:18 +08:00
|
|
|
// Add a potential insertion extension.
|
|
|
|
|
BWAAlignment insertionAlignment = createInsertionAlignment(alignment);
|
2009-10-14 04:59:29 +08:00
|
|
|
insertionAlignment.incrementGapExtensions();
|
2009-10-04 05:55:18 +08:00
|
|
|
alignments.add(insertionAlignment);
|
|
|
|
|
}
|
2009-09-25 05:03:02 +08:00
|
|
|
}
|
2009-10-04 05:55:18 +08:00
|
|
|
else if( alignment.getCurrentState() == AlignmentState.DELETION ) {
|
2009-10-14 04:59:29 +08:00
|
|
|
if( alignment.getGapExtensions() < MAXIMUM_GAP_EXTENSIONS && mismatches > 0 ) {
|
2009-10-04 05:55:18 +08:00
|
|
|
// Add a potential deletion by marking a deletion and augmenting the position.
|
|
|
|
|
List<BWAAlignment> deletionAlignments = createDeletionAlignments(bwt,alignment);
|
|
|
|
|
for( BWAAlignment deletionAlignment: deletionAlignments )
|
2009-10-14 04:59:29 +08:00
|
|
|
deletionAlignment.incrementGapExtensions();
|
2009-10-04 05:55:18 +08:00
|
|
|
alignments.addAll(deletionAlignments);
|
|
|
|
|
}
|
2009-09-25 05:03:02 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Mismatches
|
2009-10-13 23:50:04 +08:00
|
|
|
alignments.addAll(createMatchedAlignments(bwt,alignment,bases,allowDifferences&&allowMismatches));
|
2009-09-23 03:05:10 +08:00
|
|
|
}
|
|
|
|
|
|
2009-10-04 05:55:18 +08:00
|
|
|
return successfulMatches;
|
2009-09-23 03:05:10 +08:00
|
|
|
}
|
|
|
|
|
|
2009-09-30 23:19:31 +08:00
|
|
|
/**
|
|
|
|
|
* Create an seeding alignment to use as a starting point when traversing.
|
|
|
|
|
* @param bwt source BWT.
|
|
|
|
|
* @return Seed alignment.
|
|
|
|
|
*/
|
|
|
|
|
private BWAAlignment createSeedAlignment(BWT bwt) {
|
|
|
|
|
BWAAlignment seed = new BWAAlignment(this);
|
|
|
|
|
seed.negativeStrand = (bwt == forwardBWT);
|
2009-10-04 05:55:18 +08:00
|
|
|
seed.position = -1;
|
2009-09-30 23:19:31 +08:00
|
|
|
seed.loBound = 0;
|
|
|
|
|
seed.hiBound = bwt.length();
|
|
|
|
|
return seed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a new alignments representing direct matches / mismatches.
|
|
|
|
|
* @param bwt Source BWT with which to work.
|
|
|
|
|
* @param alignment Alignment for the previous position.
|
|
|
|
|
* @param bases The bases in the read.
|
2009-10-04 05:55:18 +08:00
|
|
|
* @param allowMismatch Should mismatching bases be allowed?
|
2009-09-30 23:19:31 +08:00
|
|
|
* @return New alignment representing this position if valid; null otherwise.
|
|
|
|
|
*/
|
2009-10-14 05:51:18 +08:00
|
|
|
private List<BWAAlignment> createMatchedAlignments( BWT bwt, BWAAlignment alignment, Byte[] bases, boolean allowMismatch ) {
|
2009-09-30 23:19:31 +08:00
|
|
|
List<BWAAlignment> newAlignments = new ArrayList<BWAAlignment>();
|
2009-10-04 05:55:18 +08:00
|
|
|
|
2009-10-14 02:07:15 +08:00
|
|
|
List<Byte> baseChoices = new ArrayList<Byte>();
|
2009-10-14 05:51:18 +08:00
|
|
|
Byte thisBase = bases[alignment.position+1];
|
2009-10-04 05:55:18 +08:00
|
|
|
|
|
|
|
|
if( allowMismatch )
|
2009-10-14 02:07:15 +08:00
|
|
|
baseChoices.addAll(Bases.allOf());
|
2009-10-04 05:55:18 +08:00
|
|
|
else
|
|
|
|
|
baseChoices.add(thisBase);
|
|
|
|
|
|
|
|
|
|
if( thisBase != null ) {
|
|
|
|
|
// Keep rotating the current base to the last position until we've hit the current base.
|
|
|
|
|
for( ;; ) {
|
|
|
|
|
baseChoices.add(baseChoices.remove(0));
|
|
|
|
|
if( thisBase.equals(baseChoices.get(baseChoices.size()-1)) )
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-14 02:07:15 +08:00
|
|
|
for(byte base: baseChoices) {
|
2009-09-30 23:19:31 +08:00
|
|
|
BWAAlignment newAlignment = alignment.clone();
|
|
|
|
|
|
|
|
|
|
newAlignment.loBound = bwt.counts(base) + bwt.occurrences(base,alignment.loBound-1) + 1;
|
|
|
|
|
newAlignment.hiBound = bwt.counts(base) + bwt.occurrences(base,alignment.hiBound);
|
|
|
|
|
|
|
|
|
|
// If this alignment is valid, skip it.
|
|
|
|
|
if( newAlignment.loBound > newAlignment.hiBound )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
newAlignment.position++;
|
2009-10-04 05:55:18 +08:00
|
|
|
newAlignment.addState(AlignmentState.MATCH_MISMATCH);
|
2009-10-14 05:51:18 +08:00
|
|
|
if( bases[newAlignment.position] == null || base != bases[newAlignment.position] )
|
2009-10-14 04:59:29 +08:00
|
|
|
newAlignment.incrementMismatches();
|
2009-09-30 23:19:31 +08:00
|
|
|
|
|
|
|
|
newAlignments.add(newAlignment);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return newAlignments;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new alignment representing an insertion at this point in the read.
|
|
|
|
|
* @param alignment Alignment from which to derive the insertion.
|
|
|
|
|
* @return New alignment reflecting the insertion.
|
|
|
|
|
*/
|
|
|
|
|
private BWAAlignment createInsertionAlignment( BWAAlignment alignment ) {
|
|
|
|
|
// Add a potential insertion extension.
|
|
|
|
|
BWAAlignment newAlignment = alignment.clone();
|
|
|
|
|
newAlignment.position++;
|
2009-10-04 05:55:18 +08:00
|
|
|
newAlignment.addState(AlignmentState.INSERTION);
|
2009-09-30 23:19:31 +08:00
|
|
|
return newAlignment;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2009-10-04 05:55:18 +08:00
|
|
|
* Create new alignments representing a deletion at this point in the read.
|
2009-10-01 02:10:26 +08:00
|
|
|
* @param bwt source BWT for inferring deletion info.
|
2009-09-30 23:19:31 +08:00
|
|
|
* @param alignment Alignment from which to derive the deletion.
|
|
|
|
|
* @return New alignments reflecting all possible deletions.
|
|
|
|
|
*/
|
|
|
|
|
private List<BWAAlignment> createDeletionAlignments( BWT bwt, BWAAlignment alignment) {
|
|
|
|
|
List<BWAAlignment> newAlignments = new ArrayList<BWAAlignment>();
|
2009-10-14 02:07:15 +08:00
|
|
|
for(byte base: Bases.instance) {
|
2009-09-30 23:19:31 +08:00
|
|
|
BWAAlignment newAlignment = alignment.clone();
|
|
|
|
|
|
|
|
|
|
newAlignment.loBound = bwt.counts(base) + bwt.occurrences(base,alignment.loBound-1) + 1;
|
|
|
|
|
newAlignment.hiBound = bwt.counts(base) + bwt.occurrences(base,alignment.hiBound);
|
|
|
|
|
|
|
|
|
|
// If this alignment is valid, skip it.
|
|
|
|
|
if( newAlignment.loBound > newAlignment.hiBound )
|
|
|
|
|
continue;
|
|
|
|
|
|
2009-10-04 05:55:18 +08:00
|
|
|
newAlignment.addState(AlignmentState.DELETION);
|
2009-09-30 23:19:31 +08:00
|
|
|
|
|
|
|
|
newAlignments.add(newAlignment);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return newAlignments;
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-13 23:50:04 +08:00
|
|
|
/**
|
|
|
|
|
* Exactly match the given alignment against the given BWT.
|
|
|
|
|
* @param alignment Alignment to match.
|
|
|
|
|
* @param bases Bases to use.
|
|
|
|
|
* @param bwt BWT to use.
|
|
|
|
|
*/
|
2009-10-14 05:51:18 +08:00
|
|
|
private void exactMatch( BWAAlignment alignment, Byte[] bases, BWT bwt ) {
|
2009-10-13 23:50:04 +08:00
|
|
|
while( ++alignment.position < bases.length ) {
|
2009-10-14 05:51:18 +08:00
|
|
|
byte base = bases[alignment.position];
|
2009-10-13 23:50:04 +08:00
|
|
|
alignment.loBound = bwt.counts(base) + bwt.occurrences(base,alignment.loBound-1) + 1;
|
|
|
|
|
alignment.hiBound = bwt.counts(base) + bwt.occurrences(base,alignment.hiBound);
|
|
|
|
|
if( alignment.loBound > alignment.hiBound )
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-10-14 05:51:18 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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;
|
|
|
|
|
}
|
2009-09-23 03:05:10 +08:00
|
|
|
}
|