From 2df5be702cf91510d2b3775db555813bc0a24638 Mon Sep 17 00:00:00 2001 From: Eric Banks Date: Fri, 28 Sep 2012 11:44:25 -0400 Subject: [PATCH] Added an argument to RR to allow polyploid consensus creation (by default it is turned off). This will eventually be replaced by the known SNPs track trigger. --- .../reducereads/MultiSampleCompressor.java | 5 +-- .../compression/reducereads/ReduceReads.java | 8 ++++- .../reducereads/SingleSampleCompressor.java | 7 ++-- .../reducereads/SlidingWindow.java | 35 +++++++++++-------- 4 files changed, 36 insertions(+), 19 deletions(-) diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/MultiSampleCompressor.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/MultiSampleCompressor.java index 9b2f0bc12..7c9fc101b 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/MultiSampleCompressor.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/MultiSampleCompressor.java @@ -54,11 +54,12 @@ public class MultiSampleCompressor implements Compressor { final double minIndelProportionToTriggerVariant, final int minBaseQual, final ReduceReads.DownsampleStrategy downsampleStrategy, - final int nContigs) { + final int nContigs, + final boolean allowPolyploidReduction) { for ( String name : SampleUtils.getSAMFileSamples(header) ) { compressorsPerSample.put(name, new SingleSampleCompressor(contextSize, downsampleCoverage, - minMappingQuality, minAltProportionToTriggerVariant, minIndelProportionToTriggerVariant, minBaseQual, downsampleStrategy, nContigs)); + minMappingQuality, minAltProportionToTriggerVariant, minIndelProportionToTriggerVariant, minBaseQual, downsampleStrategy, nContigs, allowPolyploidReduction)); } } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/ReduceReads.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/ReduceReads.java index 1beee3cbe..1b3e68647 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/ReduceReads.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/ReduceReads.java @@ -117,6 +117,12 @@ public class ReduceReads extends ReadWalker, ReduceRea @Argument(fullName = "minimum_tail_qualities", shortName = "mintail", doc = "", required = false) private byte minTailQuality = 2; + /** + * Allow the experimental polyploid-based reduction capabilities of this tool + */ + @Argument(fullName = "allow_polyploid_reduction", shortName = "polyploid", doc = "", required = false) + private boolean USE_POLYPLOID_REDUCTION = false; + /** * Do not simplify read (strip away all extra information of the read -- anything other than bases, quals * and read group). @@ -323,7 +329,7 @@ public class ReduceReads extends ReadWalker, ReduceRea */ @Override public ReduceReadsStash reduceInit() { - return new ReduceReadsStash(new MultiSampleCompressor(getToolkit().getSAMFileHeader(), contextSize, downsampleCoverage, minMappingQuality, minAltProportionToTriggerVariant, minIndelProportionToTriggerVariant, minBaseQual, downsampleStrategy, nContigs)); + return new ReduceReadsStash(new MultiSampleCompressor(getToolkit().getSAMFileHeader(), contextSize, downsampleCoverage, minMappingQuality, minAltProportionToTriggerVariant, minIndelProportionToTriggerVariant, minBaseQual, downsampleStrategy, nContigs, USE_POLYPLOID_REDUCTION)); } /** diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/SingleSampleCompressor.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/SingleSampleCompressor.java index f1a7b248f..6a086c53b 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/SingleSampleCompressor.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/SingleSampleCompressor.java @@ -19,6 +19,7 @@ public class SingleSampleCompressor implements Compressor { final private int minBaseQual; final private ReduceReads.DownsampleStrategy downsampleStrategy; final private int nContigs; + final private boolean allowPolyploidReduction; private SlidingWindow slidingWindow; private int slidingWindowCounter; @@ -31,7 +32,8 @@ public class SingleSampleCompressor implements Compressor { final double minIndelProportionToTriggerVariant, final int minBaseQual, final ReduceReads.DownsampleStrategy downsampleStrategy, - final int nContigs) { + final int nContigs, + final boolean allowPolyploidReduction) { this.contextSize = contextSize; this.downsampleCoverage = downsampleCoverage; this.minMappingQuality = minMappingQuality; @@ -41,6 +43,7 @@ public class SingleSampleCompressor implements Compressor { this.minBaseQual = minBaseQual; this.downsampleStrategy = downsampleStrategy; this.nContigs = nContigs; + this.allowPolyploidReduction = allowPolyploidReduction; } /** @@ -62,7 +65,7 @@ public class SingleSampleCompressor implements Compressor { } if ( slidingWindow == null) { // this is the first read - slidingWindow = new SlidingWindow(read.getReferenceName(), read.getReferenceIndex(), contextSize, read.getHeader(), read.getReadGroup(), slidingWindowCounter, minAltProportionToTriggerVariant, minIndelProportionToTriggerVariant, minBaseQual, minMappingQuality, downsampleCoverage, downsampleStrategy, read.hasBaseIndelQualities(), nContigs); + slidingWindow = new SlidingWindow(read.getReferenceName(), read.getReferenceIndex(), contextSize, read.getHeader(), read.getReadGroup(), slidingWindowCounter, minAltProportionToTriggerVariant, minIndelProportionToTriggerVariant, minBaseQual, minMappingQuality, downsampleCoverage, downsampleStrategy, read.hasBaseIndelQualities(), nContigs, allowPolyploidReduction); slidingWindowCounter++; } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/SlidingWindow.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/SlidingWindow.java index 6d6cbce04..6c588898c 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/SlidingWindow.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/SlidingWindow.java @@ -55,6 +55,8 @@ public class SlidingWindow { private final int nContigs; + private boolean allowPolyploidReduction; + /** * The types of synthetic reads to use in the finalizeAndAdd method */ @@ -85,7 +87,7 @@ public class SlidingWindow { } - public SlidingWindow(String contig, int contigIndex, int contextSize, SAMFileHeader samHeader, GATKSAMReadGroupRecord readGroupAttribute, int windowNumber, final double minAltProportionToTriggerVariant, final double minIndelProportionToTriggerVariant, int minBaseQual, int minMappingQuality, int downsampleCoverage, final ReduceReads.DownsampleStrategy downsampleStrategy, boolean hasIndelQualities, int nContigs) { + public SlidingWindow(String contig, int contigIndex, int contextSize, SAMFileHeader samHeader, GATKSAMReadGroupRecord readGroupAttribute, int windowNumber, final double minAltProportionToTriggerVariant, final double minIndelProportionToTriggerVariant, int minBaseQual, int minMappingQuality, int downsampleCoverage, final ReduceReads.DownsampleStrategy downsampleStrategy, boolean hasIndelQualities, int nContigs, boolean allowPolyploidReduction) { this.contextSize = contextSize; this.downsampleCoverage = downsampleCoverage; @@ -114,6 +116,8 @@ public class SlidingWindow { this.downsampleStrategy = downsampleStrategy; this.hasIndelQualities = hasIndelQualities; this.nContigs = nContigs; + + this.allowPolyploidReduction = allowPolyploidReduction; } /** @@ -485,23 +489,26 @@ public class SlidingWindow { boolean canCompress = true; boolean foundEvent = false; Object[] header = windowHeader.toArray(); - for (int i = start; i<=stop; i++) { - nHaplotypes = ((HeaderElement) header[i]).getNumberOfHaplotypes(MIN_ALT_BASE_PROPORTION_TO_TRIGGER_VARIANT); - if (nHaplotypes > nContigs) { - canCompress = false; - break; - } - // guarantees that there is only 1 site in the variant region that needs more than one haplotype - if (nHaplotypes > 1) { - if (!foundEvent) { - foundEvent = true; - hetRefPosition = i; - } - else { + if ( allowPolyploidReduction ) { // foundEvent will remain false if we don't allow polyploid reduction + for (int i = start; i<=stop; i++) { + nHaplotypes = ((HeaderElement) header[i]).getNumberOfHaplotypes(MIN_ALT_BASE_PROPORTION_TO_TRIGGER_VARIANT); + if (nHaplotypes > nContigs) { canCompress = false; break; } + + // guarantees that there is only 1 site in the variant region that needs more than one haplotype + if (nHaplotypes > 1) { + if (!foundEvent) { + foundEvent = true; + hetRefPosition = i; + } + else { + canCompress = false; + break; + } + } } }