From a3da475c88ad92e0233385e61a913260b7d450c0 Mon Sep 17 00:00:00 2001 From: hanna Date: Fri, 30 Oct 2009 15:40:28 +0000 Subject: [PATCH] Documentation and cleanup. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1946 348d0f76-0448-11de-a6fe-93d51630548a --- .../bwa/AlignmentValidationWalker.java | 39 +++++++++++++++++-- .../sting/alignment/bwa/AlignmentWalker.java | 36 +++++++++++++---- 2 files changed, 64 insertions(+), 11 deletions(-) diff --git a/java/src/org/broadinstitute/sting/alignment/bwa/AlignmentValidationWalker.java b/java/src/org/broadinstitute/sting/alignment/bwa/AlignmentValidationWalker.java index b3b629e85..018149c5f 100644 --- a/java/src/org/broadinstitute/sting/alignment/bwa/AlignmentValidationWalker.java +++ b/java/src/org/broadinstitute/sting/alignment/bwa/AlignmentValidationWalker.java @@ -14,12 +14,20 @@ import net.sf.samtools.SAMRecord; * @version 0.1 */ public class AlignmentValidationWalker extends ReadWalker { + /** + * 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 { 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 { 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 { 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(); diff --git a/java/src/org/broadinstitute/sting/alignment/bwa/AlignmentWalker.java b/java/src/org/broadinstitute/sting/alignment/bwa/AlignmentWalker.java index 8be6fad88..a4224be85 100644 --- a/java/src/org/broadinstitute/sting/alignment/bwa/AlignmentWalker.java +++ b/java/src/org/broadinstitute/sting/alignment/bwa/AlignmentWalker.java @@ -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 { */ 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 { 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();