Documentation and cleanup.

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1946 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
hanna 2009-10-30 15:40:28 +00:00
parent 2d15891719
commit a3da475c88
2 changed files with 64 additions and 11 deletions

View File

@ -14,12 +14,20 @@ import net.sf.samtools.SAMRecord;
* @version 0.1
*/
public class AlignmentValidationWalker extends ReadWalker<Integer,Integer> {
/**
* The supporting BWT index generated using BWT.
*/
@Argument(fullName="BWTPrefix",shortName="BWT",doc="Index files generated by bwa index -d bwtsw",required=false)
String prefix = "/Users/mhanna/reference/Ecoli/Escherichia_coli_K12_MG1655.fasta";
/**
* The instance used to generate alignments.
*/
private BWACAligner aligner = null;
/**
* Create an aligner object. The aligner object will load and hold the BWT until close() is called.
*/
@Override
public void initialize() {
aligner = new BWACAligner(prefix + ".ann",
@ -31,8 +39,12 @@ public class AlignmentValidationWalker extends ReadWalker<Integer,Integer> {
prefix + ".rsa");
}
public Integer reduceInit() { return 0; }
/**
* Aligns a read to the given reference.
* @param ref Reference over the read. Read will most likely be unmapped, so ref will be null.
* @param read Read to align.
* @return Number of reads aligned by this map (aka 1).
*/
@Override
public Integer map(char[] ref, SAMRecord read) {
byte[] bases = read.getReadBases();
@ -45,7 +57,8 @@ public class AlignmentValidationWalker extends ReadWalker<Integer,Integer> {
matches = false;
else {
for(Alignment alignment: alignments) {
matches = (alignment.getAlignmentStart() == read.getAlignmentStart());
matches = (alignment.getContigIndex() == read.getReferenceIndex());
matches &= (alignment.getAlignmentStart() == read.getAlignmentStart());
matches &= (alignment.isNegativeStrand() == read.getReadNegativeStrandFlag());
matches &= (alignment.getCigar().equals(read.getCigar()));
matches &= (alignment.getMappingQuality() == read.getMappingQuality());
@ -59,10 +72,28 @@ public class AlignmentValidationWalker extends ReadWalker<Integer,Integer> {
return 1;
}
/**
* Initial value for reduce. In this case, validated reads will be counted.
* @return 0, indicating no reads yet validated.
*/
@Override
public Integer reduceInit() { return 0; }
/**
* Calculates the number of reads processed.
* @param value Number of reads processed by this map.
* @param sum Number of reads processed before this map.
* @return Number of reads processed up to and including this map.
*/
@Override
public Integer reduce(Integer value, Integer sum) {
return value + sum;
}
/**
* Cleanup.
* @param result Number of reads processed.
*/
@Override
public void onTraversalDone(Integer result) {
aligner.close();

View File

@ -1,16 +1,13 @@
package org.broadinstitute.sting.alignment.bwa;
import org.broadinstitute.sting.utils.cmdLine.Argument;
import org.broadinstitute.sting.utils.BaseUtils;
import org.broadinstitute.sting.utils.StingException;
import org.broadinstitute.sting.alignment.Alignment;
import org.broadinstitute.sting.gatk.walkers.ReadWalker;
import net.sf.samtools.SAMRecord;
import java.util.Random;
/**
* Javadoc goes here.
* Align reads to the reference specified by BWTPrefix.
*
* @author mhanna
* @version 0.1
@ -29,6 +26,9 @@ public class AlignmentWalker extends ReadWalker<Integer,Integer> {
*/
private Random random = new Random();
/**
* Create an aligner object. The aligner object will load and hold the BWT until close() is called.
*/
@Override
public void initialize() {
aligner = new BWACAligner(prefix + ".ann",
@ -40,20 +40,42 @@ public class AlignmentWalker extends ReadWalker<Integer,Integer> {
prefix + ".rsa");
}
public Integer reduceInit() { return 0; }
/**
* Aligns a read to the given reference.
* @param ref Reference over the read. Read will most likely be unmapped, so ref will be null.
* @param read Read to align.
* @return Number of alignments found for this read.
*/
@Override
public Integer map(char[] ref, SAMRecord read) {
SAMRecord[] alignedReads = aligner.align(read);
SAMRecord selectedRead = alignedReads[random.nextInt(alignedReads.length)];
out.println(selectedRead.format());
return 1;
return alignedReads.length;
}
/**
* Initial value for reduce. In this case, alignments will be counted.
* @return 0, indicating no alignments yet found.
*/
@Override
public Integer reduceInit() { return 0; }
/**
* Calculates the number of alignments found.
* @param value Number of alignments found by this map.
* @param sum Number of alignments found before this map.
* @return Number of alignments found up to and including this map.
*/
@Override
public Integer reduce(Integer value, Integer sum) {
return value + sum;
}
/**
* Cleanup.
* @param result Number of reads processed.
*/
@Override
public void onTraversalDone(Integer result) {
aligner.close();