diff --git a/java/src/org/broadinstitute/sting/bwa/Aligner.java b/java/src/org/broadinstitute/sting/bwa/Aligner.java new file mode 100644 index 000000000..b55619e75 --- /dev/null +++ b/java/src/org/broadinstitute/sting/bwa/Aligner.java @@ -0,0 +1,53 @@ +package org.broadinstitute.sting.bwa; + +import net.sf.samtools.SAMRecord; + +import java.io.File; +import java.util.List; + +/** + * Create perfect alignments from the read to the genome represented by the given BWT / suffix array. + * + * @author mhanna + * @version 0.1 + */ +public class Aligner { + /** + * BWT in the forward direction. + */ + private BWT forwardBWT; + + /** + * Suffix array in the forward direction. + */ + private SuffixArray forwardSuffixArray; + + /** + * BWT in the reverse direction. + */ + private BWT reverseBWT; + + /** + * Suffix array in the reverse direction. + */ + private SuffixArray reverseSuffixArray; + + public Aligner( File forwardBWTFile, File forwardSuffixArrayFile, File reverseBWTFile, File reverseSuffixArrayFile ) { + forwardBWT = new BWTReader(forwardBWTFile).read(); + forwardSuffixArray = new SuffixArrayReader(forwardSuffixArrayFile).read(); + + reverseBWT = new BWTReader(reverseBWTFile).read(); + reverseSuffixArray = new SuffixArrayReader(reverseSuffixArrayFile).read(); + } + + /** + * Align the read to the given reference. + * @param read Read to align. + * @return A list of the alignments. + */ + public List align( SAMRecord read ) { + List lowerBounds = LowerBound.create(read,reverseBWT); + return null; + } +} + diff --git a/java/src/org/broadinstitute/sting/bwa/Alignment.java b/java/src/org/broadinstitute/sting/bwa/Alignment.java new file mode 100644 index 000000000..c6098464a --- /dev/null +++ b/java/src/org/broadinstitute/sting/bwa/Alignment.java @@ -0,0 +1,15 @@ +package org.broadinstitute.sting.bwa; + +/** + * Represents an alignment of a read to a site in the reference genome. + * + * @author mhanna + * @version 0.1 + */ +public interface Alignment extends Comparable { + /** + * Gets the score of this alignment. + * @return The score. + */ + public int getScore(); +} diff --git a/java/src/org/broadinstitute/sting/bwa/BWAAlignment.java b/java/src/org/broadinstitute/sting/bwa/BWAAlignment.java new file mode 100644 index 000000000..83f27c307 --- /dev/null +++ b/java/src/org/broadinstitute/sting/bwa/BWAAlignment.java @@ -0,0 +1,42 @@ +package org.broadinstitute.sting.bwa; + +/** + * An alignment object to be used incrementally as the BWA aligner + * inspects the read. + * + * @author mhanna + * @version 0.1 + */ +public class BWAAlignment implements Alignment { + /** + * 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; + + /** + * Current score for this alignment. + */ + protected int score; + + /** + * Gets the BWA score of this alignment. + * @return BWA-style scores. 0 is best. + */ + public int getScore() { + return score; + } + + /** + * 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 + */ + public int compareTo( Alignment other ) { + return Integer.valueOf(score).compareTo(other.getScore()); + } +} diff --git a/java/src/org/broadinstitute/sting/bwa/LowerBound.java b/java/src/org/broadinstitute/sting/bwa/LowerBound.java new file mode 100644 index 000000000..587847ea0 --- /dev/null +++ b/java/src/org/broadinstitute/sting/bwa/LowerBound.java @@ -0,0 +1,50 @@ +package org.broadinstitute.sting.bwa; + +import net.sf.samtools.SAMRecord; + +import java.util.List; +import java.util.ArrayList; + +/** + * At any point along the given read, what is a good lower bound for the + * total number of differences? + * + * @author mhanna + * @version 0.1 + */ +public class LowerBound { + /** + * The lower bound at the given point. + */ + public final int value; + + /** + * Create a new lower bound with the given value. + * @param value Value for the lower bound at this site. + */ + private LowerBound(int value) { + this.value = value; + } + + /** + * Create a non-optimal bound according to the algorithm specified in Figure 3 of the BWA paper. + */ + public static List create( SAMRecord read, BWT reverseBWT ) { + List bounds = new ArrayList(); + + int loIndex = 0, hiIndex = reverseBWT.length(), mismatches = 0; + for( int i = 0; i < read.getReadBases().length; i++ ) { + Base base = Base.fromASCII(read.getReadBases()[i]); + loIndex = reverseBWT.counts(base) + reverseBWT.occurrences(base,loIndex-1) + 1; + hiIndex = reverseBWT.counts(base) + reverseBWT.occurrences(base,hiIndex); + if( loIndex > hiIndex ) { + loIndex = 0; + hiIndex = reverseBWT.length(); + mismatches++; + } + bounds.add(new LowerBound(mismatches)); + } + + return bounds; + } +}