From 9d69bd2c8436e45fab7b81076e489c51f9a1ae67 Mon Sep 17 00:00:00 2001 From: chartl Date: Wed, 9 Sep 2009 15:49:52 +0000 Subject: [PATCH] Modifications: @CoverageAndPowerWalker - removed a hanging colon that was being printed after the reference position @VariantEvalWalker - added a command line argument for pool size for eventual use in doing pooled caller evaluations. As now, the variable is unused. @AlignmentContext - altered the scope of class variables from private to protected in order that child objects might have access to them New Additions: Filtered Contexts Sometimes we want to filter or partition reads by some aspect (quality score, read direction, current base, whatever) and use only those reads as part of the alignment context. Prior to this I've been doing the split externally and creating a new AlignmentContext object. This new approach makes it a bit easier, as each of these objects are children of AlignmentContext, and can be instantiated from a "raw" AlignmentContext. @FilteredAlignmentContext is an abstract class that defines the behavior. The abstract method 'filter' is called on the input AlignmentContext, filtering those reads and offsets by whatever you can think of. The filtered reads/offsets are then maintained in the reads and offsets fields. These classes can be passed around as AlignmentContexts themselves. Writing a new kind of read-filtered alignment context boils down to implementing the filter method. @ReverseReadsContext - a FilteredAlignmentContext that takes only reads in the reverse direction @ForwardReadsContext - a FilteredAlignmentContext that takes only reads in the forward direction @QualityScoreThresholdContext - a FilteredAlignmentContext that takes only reads above a given quality score threshold (defaults to 22 if none provided). A unit test bamfile and associated unit tests for these are in the works. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1559 348d0f76-0448-11de-a6fe-93d51630548a --- .../sting/gatk/contexts/AlignmentContext.java | 13 +++-- .../contexts/FilteredAlignmentContext.java | 41 +++++++++++++++ .../contexts/ForwardReadsContext.java | 34 +++++++++++++ .../QualityScoreThresholdContext.java | 51 +++++++++++++++++++ .../contexts/ReverseReadsContext.java | 35 +++++++++++++ .../poolseq/CoverageAndPowerWalker.java | 2 +- .../varianteval/VariantEvalWalker.java | 3 ++ 7 files changed, 175 insertions(+), 4 deletions(-) create mode 100755 java/src/org/broadinstitute/sting/playground/contexts/FilteredAlignmentContext.java create mode 100755 java/src/org/broadinstitute/sting/playground/contexts/ForwardReadsContext.java create mode 100755 java/src/org/broadinstitute/sting/playground/contexts/QualityScoreThresholdContext.java create mode 100755 java/src/org/broadinstitute/sting/playground/contexts/ReverseReadsContext.java diff --git a/java/src/org/broadinstitute/sting/gatk/contexts/AlignmentContext.java b/java/src/org/broadinstitute/sting/gatk/contexts/AlignmentContext.java index 8f4fe5bb6..c6ed4d6a4 100755 --- a/java/src/org/broadinstitute/sting/gatk/contexts/AlignmentContext.java +++ b/java/src/org/broadinstitute/sting/gatk/contexts/AlignmentContext.java @@ -41,9 +41,16 @@ import java.util.*; * To change this template use File | Settings | File Templates. */ public class AlignmentContext { - private GenomeLoc loc = null; - private List reads = null; - private List offsets = null; + protected GenomeLoc loc = null; + protected List reads = null; + protected List offsets = null; + + /** + * Default constructor for AlignmentContext object + * since private objects are already set to null we + * don't need to do anything + */ + public AlignmentContext() { /* private objects already set to null */ } /** * Create a new AlignmentContext object diff --git a/java/src/org/broadinstitute/sting/playground/contexts/FilteredAlignmentContext.java b/java/src/org/broadinstitute/sting/playground/contexts/FilteredAlignmentContext.java new file mode 100755 index 000000000..9b50b5870 --- /dev/null +++ b/java/src/org/broadinstitute/sting/playground/contexts/FilteredAlignmentContext.java @@ -0,0 +1,41 @@ +package org.broadinstitute.sting.playground.contexts; + +import org.broadinstitute.sting.gatk.contexts.AlignmentContext; +import org.broadinstitute.sting.utils.Pair; + +import java.util.List; + +import net.sf.samtools.SAMRecord; + +/** + * Created by IntelliJ IDEA. + * User: chartl + * Date: Sep 9, 2009 + * Time: 10:43:23 AM + * To change this template use File | Settings | File Templates. + */ +public abstract class FilteredAlignmentContext extends AlignmentContext{ + + public FilteredAlignmentContext() { /* super method is called */ } + + /* A partitioned alignment context must have a constructor + * method that generates the object from another alignment + * context + */ + + public FilteredAlignmentContext(AlignmentContext context) { + Pair, List> partitionedReads = filter(context); + this.reads = partitionedReads.getFirst(); + this.offsets = partitionedReads.getSecond(); + this.loc = context.getLocation(); + + } + + /* + * A new partitioned alignment object need only specify how the reads from an Alignmentcontext + * are to be partitioned, and return the new partition in a pair. + * @Param: context - an alignment context containing reads to be partitioned + */ + public abstract Pair, List> filter(AlignmentContext context); + +} diff --git a/java/src/org/broadinstitute/sting/playground/contexts/ForwardReadsContext.java b/java/src/org/broadinstitute/sting/playground/contexts/ForwardReadsContext.java new file mode 100755 index 000000000..97571468b --- /dev/null +++ b/java/src/org/broadinstitute/sting/playground/contexts/ForwardReadsContext.java @@ -0,0 +1,34 @@ +package org.broadinstitute.sting.playground.contexts; + +import org.broadinstitute.sting.utils.Pair; +import org.broadinstitute.sting.gatk.contexts.AlignmentContext; +import net.sf.samtools.SAMRecord; + +import java.util.List; +import java.util.ArrayList; + +/** + * Created by IntelliJ IDEA. + * User: chartl + * Date: Sep 9, 2009 + * Time: 11:01:53 AM + * To change this template use File | Settings | File Templates. + */ +public class ForwardReadsContext extends FilteredAlignmentContext { + + public Pair,List> filter(AlignmentContext context) { + List inReads = context.getReads(); + List inOffsets = context.getOffsets(); + List filteredReads = new ArrayList(); + List filteredOffsets = new ArrayList(); + + for( int i = 0; i < inReads.size(); i++ ) { + if( ! inReads.get(i).getReadNegativeStrandFlag() ) { + filteredReads.add(inReads.get(i)); + filteredOffsets.add(inOffsets.get(i)); + } + } + + return new Pair,List>(filteredReads,filteredOffsets); + } +} diff --git a/java/src/org/broadinstitute/sting/playground/contexts/QualityScoreThresholdContext.java b/java/src/org/broadinstitute/sting/playground/contexts/QualityScoreThresholdContext.java new file mode 100755 index 000000000..606407ffd --- /dev/null +++ b/java/src/org/broadinstitute/sting/playground/contexts/QualityScoreThresholdContext.java @@ -0,0 +1,51 @@ +package org.broadinstitute.sting.playground.contexts; + +import org.broadinstitute.sting.gatk.contexts.AlignmentContext; +import org.broadinstitute.sting.utils.Pair; + +import java.util.List; +import java.util.ArrayList; + +import net.sf.samtools.SAMRecord; + +/** + * Created by IntelliJ IDEA. + * User: chartl + * Date: Sep 9, 2009 + * Time: 11:17:30 AM + * To change this template use File | Settings | File Templates. + */ +public class QualityScoreThresholdContext extends FilteredAlignmentContext{ + /* + * @Param: qThresh - default value for thresholding + */ + protected byte qThresh = 22; + + public QualityScoreThresholdContext(AlignmentContext context, byte qThresh) { + this.qThresh = qThresh; + Pair, List> filteredRO = filter(context); + this.reads = filteredRO.getFirst(); + this.offsets = filteredRO.getSecond(); + this.loc = context.getLocation(); + } + + public byte getQualityScoreThreshold() { + return this.qThresh; + } + + public Pair,List> filter(AlignmentContext context) { + List inReads = context.getReads(); + List inOffsets = context.getOffsets(); + List outReads = new ArrayList(); + List outOffsets = new ArrayList(); + + for( int i = 0; i < inReads.size(); i++) { + if(inReads.get(i).getBaseQualities()[inOffsets.get(i)] >= this.qThresh) { + outReads.add(inReads.get(i)); + outOffsets.add(inOffsets.get(i)); + } + } + + return new Pair,List>(outReads,outOffsets); + } +} diff --git a/java/src/org/broadinstitute/sting/playground/contexts/ReverseReadsContext.java b/java/src/org/broadinstitute/sting/playground/contexts/ReverseReadsContext.java new file mode 100755 index 000000000..c65d52118 --- /dev/null +++ b/java/src/org/broadinstitute/sting/playground/contexts/ReverseReadsContext.java @@ -0,0 +1,35 @@ +package org.broadinstitute.sting.playground.contexts; + +import net.sf.samtools.SAMRecord; + +import java.util.List; +import java.util.ArrayList; + +import org.broadinstitute.sting.utils.Pair; +import org.broadinstitute.sting.gatk.contexts.AlignmentContext; + +/** + * Created by IntelliJ IDEA. + * User: chartl + * Date: Sep 9, 2009 + * Time: 11:09:32 AM + * To change this template use File | Settings | File Templates. + */ +public class ReverseReadsContext extends FilteredAlignmentContext { + + public Pair,List> filter(AlignmentContext context) { + List inReads = context.getReads(); + List inOffsets = context.getOffsets(); + List filteredReads = new ArrayList(); + List filteredOffsets = new ArrayList(); + + for( int i = 0; i < inReads.size(); i++ ) { + if( inReads.get(i).getReadNegativeStrandFlag() ) { + filteredReads.add(inReads.get(i)); + filteredOffsets.add(inOffsets.get(i)); + } + } + + return new Pair,List>(filteredReads,filteredOffsets); + } +} diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/poolseq/CoverageAndPowerWalker.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/poolseq/CoverageAndPowerWalker.java index b704c2913..830f8bdb0 100755 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/poolseq/CoverageAndPowerWalker.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/poolseq/CoverageAndPowerWalker.java @@ -71,7 +71,7 @@ public class CoverageAndPowerWalker extends LocusWalker, Pair,List>,Pair,List>> readsByDirection = PoolUtils.splitReadsByReadDirection(filteredContext.getReads(),filteredContext.getOffsets()); if ( ! suppress_printing) { Pair powers = calculatePower(readsByDirection, useBootstrap, filteredContext); - out.printf("%s: %d %d %d %d %d %d %f %f %f%n", filteredContext.getLocation(), readsByDirection.getFirst().getFirst().size(), readsByDirection.getFirst().getSecond().size(), + out.printf("%s %d %d %d %d %d %d %f %f %f%n", filteredContext.getLocation(), readsByDirection.getFirst().getFirst().size(), readsByDirection.getFirst().getSecond().size(), filteredContext.getReads().size(), powers.getSecond()[0], powers.getSecond()[1], powers.getSecond()[2], powers.getFirst()[0], powers.getFirst()[1], powers.getFirst()[2]); } diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/varianteval/VariantEvalWalker.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/varianteval/VariantEvalWalker.java index 4882d4a65..59465ed4e 100755 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/varianteval/VariantEvalWalker.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/varianteval/VariantEvalWalker.java @@ -55,6 +55,9 @@ public class VariantEvalWalker extends RefWalker { @Argument(fullName="supressDateInformation", doc="This flag indicates that we want to suppress the date information from the output, so that if can be diff'ed against previous evals.", required=false) public boolean supressDateInformation = false; + @Argument(fullName = "numPeopleInPool", shortName="S", doc="If using a variant file from a pooled caller, this field provides the number of individuals in each pool", required=false) + public int numPeopleInPool = 1; + String analysisFilenameBase = null; final String knownSNPDBName = "dbSNP";