Putting some of the required data structures together for imperfect lookup.

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1647 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
hanna 2009-09-17 22:43:11 +00:00
parent 355136928e
commit b4df089b59
4 changed files with 160 additions and 0 deletions

View File

@ -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<Alignment> align( SAMRecord read ) {
List<LowerBound> lowerBounds = LowerBound.create(read,reverseBWT);
return null;
}
}

View File

@ -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<Alignment> {
/**
* Gets the score of this alignment.
* @return The score.
*/
public int getScore();
}

View File

@ -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());
}
}

View File

@ -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<LowerBound> create( SAMRecord read, BWT reverseBWT ) {
List<LowerBound> bounds = new ArrayList<LowerBound>();
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;
}
}