From cf7afc1ad4476d069744858b2bbbcf9bb6a650e7 Mon Sep 17 00:00:00 2001 From: Mauricio Carneiro Date: Sat, 20 Apr 2013 00:28:35 -0400 Subject: [PATCH 1/8] Fixed "skipped intervals" bug on DiagnoseTargets Problem ------- Diagnose targets was skipping intervals when they were not covered by any reads. Solution -------- Rework the interval iteration logic to output all intervals as they're skipped over by the traversal, as well as adding a loop on traversal done to finish outputting intervals past the coverage of teh BAM file. Summarized Changes ------------------ * Outputs all intervals it iterates over, even if uncovered * Outputs leftover intervals in the end of the traversal * Updated integration tests [fixes #47813825] --- .../diagnostics/targets/DiagnoseTargets.java | 104 ++++++++---------- .../DiagnoseTargetsIntegrationTest.java | 4 +- 2 files changed, 49 insertions(+), 59 deletions(-) diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargets.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargets.java index b302a967c..33c7e7a1b 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargets.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargets.java @@ -152,11 +152,14 @@ public class DiagnoseTargets extends LocusWalker { @Argument(fullName = "print_debug_log", shortName = "dl", doc = "Used only for debugging the walker. Prints extra info to screen", required = false) private boolean debug = false; - private HashMap intervalMap = null; // maps each interval => statistics - private PeekableIterator intervalListIterator; // an iterator to go over all the intervals provided as we traverse the genome - private Set samples = null; // all the samples being processed - private final Allele SYMBOLIC_ALLELE = Allele.create("
", false); // avoid creating the symbolic allele multiple times - private ThresHolder thresholds = null; + private Map intervalMap = null; // maps each interval => statistics + private PeekableIterator intervalListIterator; // an iterator to go over all the intervals provided as we traverse the genome + private Set samples = null; // all the samples being processed + private static final Allele SYMBOLIC_ALLELE = Allele.create("
", false); // avoid creating the symbolic allele multiple times + private static final Allele UNCOVERED_ALLELE = Allele.create("A", true); // avoid creating the 'fake' ref allele for uncovered intervals multiple times + private ThresHolder thresholds = null; // object that holds all the thresholds for Diagnose Targets (todo -- should become a plugin based system) + + private static final int INITIAL_HASH_SIZE = 500000; @Override public void initialize() { @@ -165,24 +168,32 @@ public class DiagnoseTargets extends LocusWalker { if (getToolkit().getIntervals() == null) throw new UserException("This tool only works if you provide one or more intervals. ( Use the -L argument )"); - thresholds = new ThresHolder(minimumBaseQuality, minimumMappingQuality, minimumCoverage, maximumCoverage, minMedianDepth, maxInsertSize, votePercentage, lowMedianDepthPercentage, badMateStatusThreshold, coverageStatusThreshold, excessiveCoverageThreshold, qualityStatusThreshold); + thresholds = new ThresHolder(minimumBaseQuality, minimumMappingQuality, minimumCoverage, maximumCoverage, + minMedianDepth, maxInsertSize, votePercentage, lowMedianDepthPercentage, + badMateStatusThreshold, coverageStatusThreshold, excessiveCoverageThreshold, + qualityStatusThreshold); - intervalMap = new HashMap(); + intervalMap = new HashMap(INITIAL_HASH_SIZE); intervalListIterator = new PeekableIterator(getToolkit().getIntervals().iterator()); - samples = SampleUtils.getSAMFileSamples(getToolkit().getSAMFileHeader()); // get all of the unique sample names for the VCF Header - vcfWriter.writeHeader(new VCFHeader(ThresHolder.getHeaderInfo(), samples)); // initialize the VCF header + // get all of the unique sample names for the VCF Header + samples = SampleUtils.getSAMFileSamples(getToolkit().getSAMFileHeader()); + vcfWriter.writeHeader(new VCFHeader(ThresHolder.getHeaderInfo(), samples)); } @Override public Long map(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) { GenomeLoc refLocus = ref.getLocus(); - removePastIntervals(refLocus, ref.getBase()); // process and remove any intervals in the map that are don't overlap the current locus anymore - addNewOverlappingIntervals(refLocus); // add all new intervals that may overlap this reference locus + // process and remove any intervals in the map that are don't overlap the current locus anymore + // and add all new intervals that may overlap this reference locus + outputFinishedIntervals(refLocus, ref.getBase()); + addNewOverlappingIntervals(refLocus); + // at this point, all intervals in intervalMap overlap with this locus, so update all of them for (IntervalStatistics intervalStatistics : intervalMap.values()) - intervalStatistics.addLocus(context, ref, thresholds); // Add current locus to stats + intervalStatistics.addLocus(context, ref, thresholds); + return 1L; } @@ -212,53 +223,40 @@ public class DiagnoseTargets extends LocusWalker { @Override public void onTraversalDone(Long result) { for (GenomeLoc interval : intervalMap.keySet()) - outputStatsToVCF(intervalMap.get(interval), Allele.create("A", true)); - } + outputStatsToVCF(intervalMap.get(interval), UNCOVERED_ALLELE); - private GenomeLoc getIntervalMapSpan() { - GenomeLoc loc = null; - for (GenomeLoc interval : intervalMap.keySet()) { - if (loc == null) { - loc = interval; - } else - loc = interval.union(loc); + GenomeLoc interval = intervalListIterator.peek(); + while (interval != null) { + outputStatsToVCF(createIntervalStatistic(interval), UNCOVERED_ALLELE); + intervalListIterator.next(); + interval = intervalListIterator.peek(); } - - return loc; - } - - private GenomeLoc getFinishedIntervalSpan(GenomeLoc pos) { - GenomeLoc loc = null; - for (GenomeLoc interval : intervalMap.keySet()) { - if (interval.isBefore(pos)) { - if (loc == null) - loc = interval; - else - loc = interval.union(loc); - } - } - - return loc; } /** - * Removes all intervals that are behind the current reference locus from the intervalMap + * Outputs all intervals that are behind the current reference locus * * @param refLocus the current reference locus * @param refBase the reference allele */ - private void removePastIntervals(GenomeLoc refLocus, byte refBase) { - // if there are statistics to output/ check to see that we can output them in order - if (getFinishedIntervalSpan(refLocus) != null && - getIntervalMapSpan().getStart() == getFinishedIntervalSpan(refLocus).getStart()) { + private void outputFinishedIntervals(final GenomeLoc refLocus, final byte refBase) { + GenomeLoc interval = intervalListIterator.peek(); - for (GenomeLoc interval : intervalMap.keySet()) { - if (interval.isBefore(refLocus)) { - outputStatsToVCF(intervalMap.get(interval), Allele.create(refBase, true)); - intervalMap.remove(interval); - } + // output empty statistics for uncovered intervals + while (interval != null && interval.isBefore(refLocus)) { + final IntervalStatistics stats = intervalMap.get(interval); + outputStatsToVCF(stats != null ? stats : createIntervalStatistic(interval), UNCOVERED_ALLELE); + if (stats != null) intervalMap.remove(interval); + intervalListIterator.next(); + interval = intervalListIterator.peek(); + } + + // remove any potential leftover interval in intervalMap (this will only happen when we have overlapping intervals) + for (GenomeLoc key : intervalMap.keySet()) { + if (key.isBefore(refLocus)) { + outputStatsToVCF(intervalMap.get(key), Allele.create(refBase, true)); + intervalMap.remove(key); } - } } @@ -269,17 +267,9 @@ public class DiagnoseTargets extends LocusWalker { */ private void addNewOverlappingIntervals(GenomeLoc refLocus) { GenomeLoc interval = intervalListIterator.peek(); - - // skip any intervals with no coverage that we have passed - while (interval != null && interval.isBefore(refLocus)) { - intervalListIterator.next(); // discard the interval (we've already added it to the map) - interval = intervalListIterator.peek(); - } - - // add any intervals that overlap this one while (interval != null && !interval.isPast(refLocus)) { intervalMap.put(interval, createIntervalStatistic(interval)); - intervalListIterator.next(); // discard the interval (we've already added it to the map) + intervalListIterator.next(); interval = intervalListIterator.peek(); } } diff --git a/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargetsIntegrationTest.java b/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargetsIntegrationTest.java index 6a52a42e5..2875e10d7 100644 --- a/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargetsIntegrationTest.java +++ b/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargetsIntegrationTest.java @@ -66,11 +66,11 @@ public class DiagnoseTargetsIntegrationTest extends WalkerTest { @Test(enabled = true) public void testSingleSample() { - DTTest("testSingleSample ", "-I " + singleSample + " -max 75", "9954b21163d3e66db232938ec509067f"); + DTTest("testSingleSample ", "-I " + singleSample + " -max 75", "9b51561bcf248da70a4d711380b04f7b"); } @Test(enabled = true) public void testMultiSample() { - DTTest("testMultiSample ", "-I " + multiSample, "7c5277261e8e9dd74666f04843ffb09c"); + DTTest("testMultiSample ", "-I " + multiSample, "925f88f0c41c6a9ac479be34e052dc5d"); } } From 2b923f1568329ce3af4d1953746e74e327ea0c44 Mon Sep 17 00:00:00 2001 From: Mauricio Carneiro Date: Sat, 20 Apr 2013 13:05:14 -0400 Subject: [PATCH 2/8] fix for DiagnoseTargets multiple filter output Problem ------- Diagnose targets is outputting both LOW_MEDIAN_COVERAGE and NO_READS when no reads are covering the interval Solution -------- Only allow low median coverage check if there are reads [fixes #48442675] --- .../targets/IntervalStatistics.java | 20 ++++++++++++++----- .../diagnostics/targets/SampleStatistics.java | 2 +- .../DiagnoseTargetsIntegrationTest.java | 4 ++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/IntervalStatistics.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/IntervalStatistics.java index 0aea54fa0..0a6b73dae 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/IntervalStatistics.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/IntervalStatistics.java @@ -148,24 +148,34 @@ class IntervalStatistics { votes.put(status, votes.get(status) + 1); // output tall values above the threshold + final double minVotesNeeded = thresholds.getVotePercentageThreshold() * samples.size(); for (CallableStatus status : votes.keySet()) { - if (votes.get(status) > (samples.size() * thresholds.getVotePercentageThreshold()) && !(status.equals(CallableStatus.PASS))) + if (!status.equals((CallableStatus.PASS)) && votes.get(status) > minVotesNeeded) output.add(status); } - if (hasNref) output.add(CallableStatus.REF_N); // get median DP of each sample + final double minMedianDepth = thresholds.getLowMedianDepthThreshold() * samples.size(); + final int nSamples = samples.size(); int nLowMedianDepth = 0; + int samplesSeen = 0; for (SampleStatistics sample : samples.values()) { - if (sample.getQuantileDepth(0.5) < thresholds.getMinimumMedianDepth()) + samplesSeen++; + final double medianDepth = sample.getQuantileDepth(0.5); + if (medianDepth > 0 && medianDepth < thresholds.getMinimumMedianDepth()) { nLowMedianDepth++; + } + if (nLowMedianDepth > minMedianDepth) { + output.add(CallableStatus.LOW_MEDIAN_DEPTH); + break; + } + if (nSamples - samplesSeen + nLowMedianDepth < minMedianDepth) + break; } - if (nLowMedianDepth > (samples.size() * thresholds.getLowMedianDepthThreshold())) - output.add(CallableStatus.LOW_MEDIAN_DEPTH); return output; } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/SampleStatistics.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/SampleStatistics.java index ad9f287d2..9efdbefe1 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/SampleStatistics.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/SampleStatistics.java @@ -101,7 +101,7 @@ class SampleStatistics { * @return the callable statuses of the entire sample */ public Set getCallableStatuses(ThresHolder thresholds) { - // We check if reads are present ot prevent div / 0 exceptions + // We check if reads are present to prevent div / 0 exceptions if (nReads == 0) { return Collections.singleton(CallableStatus.NO_READS); } diff --git a/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargetsIntegrationTest.java b/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargetsIntegrationTest.java index 2875e10d7..a9330f2dd 100644 --- a/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargetsIntegrationTest.java +++ b/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargetsIntegrationTest.java @@ -66,11 +66,11 @@ public class DiagnoseTargetsIntegrationTest extends WalkerTest { @Test(enabled = true) public void testSingleSample() { - DTTest("testSingleSample ", "-I " + singleSample + " -max 75", "9b51561bcf248da70a4d711380b04f7b"); + DTTest("testSingleSample ", "-I " + singleSample + " -max 75", "bd614643284a849724bf8ee6bc4df8bf"); } @Test(enabled = true) public void testMultiSample() { - DTTest("testMultiSample ", "-I " + multiSample, "925f88f0c41c6a9ac479be34e052dc5d"); + DTTest("testMultiSample ", "-I " + multiSample, "145f5d4641abfdeadbc59ee74ce1560f"); } } From b3c0abd9e8bc2c8565afcf1eb90b6d8633aa3d67 Mon Sep 17 00:00:00 2001 From: Mauricio Carneiro Date: Sat, 20 Apr 2013 14:42:33 -0400 Subject: [PATCH 3/8] Remove REF_N status from DiagnoseTargets This is not really feasible with the current mandate of this walker. We would have to traverse by reference and that would make the runtime much higher, and we are not really interested in the status 99% of the time anyway. There are other walkers that can report this, and just this, status more cheaply. [fixes #48442663] --- .../gatk/walkers/diagnostics/targets/CallableStatus.java | 2 -- .../gatk/walkers/diagnostics/targets/IntervalStatistics.java | 3 --- .../gatk/walkers/diagnostics/targets/SampleStatistics.java | 4 ---- .../diagnostics/targets/DiagnoseTargetsIntegrationTest.java | 4 ++-- 4 files changed, 2 insertions(+), 11 deletions(-) diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/CallableStatus.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/CallableStatus.java index 4bc318b02..959c002ad 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/CallableStatus.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/CallableStatus.java @@ -54,8 +54,6 @@ package org.broadinstitute.sting.gatk.walkers.diagnostics.targets; */ public enum CallableStatus { - REF_N("the reference base was an N, which is not considered callable the GATK"), - PASS("the base satisfied the min. depth for calling but had less than maxDepth to avoid having EXCESSIVE_COVERAGE"), COVERAGE_GAPS("absolutely no coverage was observed at a locus, regardless of the filtering parameters"), diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/IntervalStatistics.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/IntervalStatistics.java index 0a6b73dae..4fd9a20ef 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/IntervalStatistics.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/IntervalStatistics.java @@ -154,9 +154,6 @@ class IntervalStatistics { output.add(status); } - if (hasNref) - output.add(CallableStatus.REF_N); - // get median DP of each sample final double minMedianDepth = thresholds.getLowMedianDepthThreshold() * samples.size(); final int nSamples = samples.size(); diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/SampleStatistics.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/SampleStatistics.java index 9efdbefe1..051369b94 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/SampleStatistics.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/SampleStatistics.java @@ -139,10 +139,6 @@ class SampleStatistics { if ((totals.get(CallableStatus.POOR_QUALITY) / intervalSize) >= thresholds.getQualityStatusThreshold()) output.add(CallableStatus.POOR_QUALITY); - if (totals.get(CallableStatus.REF_N) > 0) - output.add(CallableStatus.REF_N); - - if (output.isEmpty()) { output.add(CallableStatus.PASS); } diff --git a/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargetsIntegrationTest.java b/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargetsIntegrationTest.java index a9330f2dd..a435a33ad 100644 --- a/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargetsIntegrationTest.java +++ b/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargetsIntegrationTest.java @@ -66,11 +66,11 @@ public class DiagnoseTargetsIntegrationTest extends WalkerTest { @Test(enabled = true) public void testSingleSample() { - DTTest("testSingleSample ", "-I " + singleSample + " -max 75", "bd614643284a849724bf8ee6bc4df8bf"); + DTTest("testSingleSample ", "-I " + singleSample + " -max 75", "3d558ec8828c269774ee45e5df086a5f"); } @Test(enabled = true) public void testMultiSample() { - DTTest("testMultiSample ", "-I " + multiSample, "145f5d4641abfdeadbc59ee74ce1560f"); + DTTest("testMultiSample ", "-I " + multiSample, "d40cf1f1daf68f2740cd411e2cf361fc"); } } From eb6308a0e4eeaf2f06bfd3cd9e0d9c219b18140f Mon Sep 17 00:00:00 2001 From: Mauricio Carneiro Date: Sat, 20 Apr 2013 18:34:03 -0400 Subject: [PATCH 4/8] General DiagnoseTargets documentation cleanup * remove interval statistic low_median_coverage -- it is already captured by low coverage and coverage gaps. * add gatkdocs to all the parameters * clean up the logic on callable status a bit (still need to be re-worked into a plugin system) * update integration tests --- .../diagnostics/targets/CallableStatus.java | 7 +-- .../diagnostics/targets/DiagnoseTargets.java | 57 +++++++++++++------ .../targets/IntervalStatistics.java | 20 ------- .../diagnostics/targets/SampleStatistics.java | 10 +--- .../diagnostics/targets/ThresHolder.java | 37 ++++-------- .../DiagnoseTargetsIntegrationTest.java | 4 +- .../targets/LocusStatisticsUnitTest.java | 2 +- .../targets/SampleStatisticsUnitTest.java | 4 +- 8 files changed, 60 insertions(+), 81 deletions(-) diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/CallableStatus.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/CallableStatus.java index 959c002ad..32c0c339d 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/CallableStatus.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/CallableStatus.java @@ -66,12 +66,7 @@ public enum CallableStatus { BAD_MATE("the reads are not properly mated, suggesting mapping errors"), - NO_READS("there are no reads contained in the interval"), - - // - // Interval-level statuses - // - LOW_MEDIAN_DEPTH("interval has insufficient median depth across samples"); + NO_READS("there are no reads contained in the interval"); public final String description; diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargets.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargets.java index 33c7e7a1b..5bdb81906 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargets.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargets.java @@ -48,6 +48,7 @@ package org.broadinstitute.sting.gatk.walkers.diagnostics.targets; import net.sf.picard.util.PeekableIterator; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.commandline.Hidden; import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.gatk.CommandLineGATK; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; @@ -110,45 +111,71 @@ import java.util.*; @PartitionBy(PartitionType.INTERVAL) public class DiagnoseTargets extends LocusWalker { - @Output(doc = "File to which variants should be written") + @Output(doc = "File to which interval statistics should be written") private VariantContextWriter vcfWriter = null; + /** + * Only bases with quality greater than this will be considered in the coverage metrics. + */ @Argument(fullName = "minimum_base_quality", shortName = "BQ", doc = "The minimum Base Quality that is considered for calls", required = false) private int minimumBaseQuality = 20; + /** + * Only reads with mapping quality greater than this will be considered in the coverage metrics. + */ @Argument(fullName = "minimum_mapping_quality", shortName = "MQ", doc = "The minimum read mapping quality considered for calls", required = false) private int minimumMappingQuality = 20; + /** + * If at any locus, a sample has less coverage than this, it will be reported as LOW_COVERAGE + */ @Argument(fullName = "minimum_coverage", shortName = "min", doc = "The minimum allowable coverage, used for calling LOW_COVERAGE", required = false) private int minimumCoverage = 5; + /** + * If at any locus, a sample has more coverage than this, it will be reported as EXCESSIVE_COVERAGE + */ @Argument(fullName = "maximum_coverage", shortName = "max", doc = "The maximum allowable coverage, used for calling EXCESSIVE_COVERAGE", required = false) private int maximumCoverage = 700; - @Argument(fullName = "minimum_median_depth", shortName = "med", doc = "The minimum allowable median coverage, used for calling LOW_MEDIAN_DEPTH", required = false) - private int minMedianDepth = 10; - + /** + * If any sample has a paired read whose distance between alignment starts (between the pairs) is greater than this, it will be reported as BAD_MATE + */ @Argument(fullName = "maximum_insert_size", shortName = "ins", doc = "The maximum allowed distance between a read and its mate", required = false) private int maxInsertSize = 500; - @Argument(fullName = "voting_status_threshold", shortName = "stV", doc = "The needed percentage of samples containing a call for the interval to adopt the call ", required = false) + /** + * The proportion of samples that must have a status for it to filter the entire interval. Example: 8 out of 10 samples have low coverage status on the interval, + * with a threshold higher than 0.2, this interval will be filtered as LOW_COVERAGE. + */ + @Argument(fullName = "voting_status_threshold", shortName = "stV", doc = "The needed proportion of samples containing a call for the interval to adopt the call ", required = false) private double votePercentage = 0.50; - @Argument(fullName = "low_median_depth_status_threshold", shortName = "stMED", doc = "The percentage of the loci needed for calling LOW_MEDIAN_DEPTH", required = false) - private double lowMedianDepthPercentage = 0.20; - - @Argument(fullName = "bad_mate_status_threshold", shortName = "stBM", doc = "The percentage of the loci needed for calling BAD_MATE", required = false) + /** + * The proportion of reads in the loci that must have bad mates for the sample to be reported as BAD_MATE + */ + @Argument(fullName = "bad_mate_status_threshold", shortName = "stBM", doc = "The proportion of the loci needed for calling BAD_MATE", required = false) private double badMateStatusThreshold = 0.50; - @Argument(fullName = "coverage_status_threshold", shortName = "stC", doc = "The percentage of the loci needed for calling LOW_COVERAGE and COVERAGE_GAPS", required = false) + /** + * The proportion of loci in a sample that must fall under the LOW_COVERAGE or COVERAGE_GAPS category for the sample to be reported as either (or both) + */ + @Argument(fullName = "coverage_status_threshold", shortName = "stC", doc = "The proportion of the loci needed for calling LOW_COVERAGE and COVERAGE_GAPS", required = false) private double coverageStatusThreshold = 0.20; - @Argument(fullName = "excessive_coverage_status_threshold", shortName = "stXC", doc = "The percentage of the loci needed for calling EXCESSIVE_COVERAGE", required = false) + /** + * The proportion of loci in a sample that must fall under the EXCESSIVE_COVERAGE category for the sample to be reported as EXCESSIVE_COVERAGE + */ + @Argument(fullName = "excessive_coverage_status_threshold", shortName = "stXC", doc = "The proportion of the loci needed for calling EXCESSIVE_COVERAGE", required = false) private double excessiveCoverageThreshold = 0.20; - @Argument(fullName = "quality_status_threshold", shortName = "stQ", doc = "The percentage of the loci needed for calling POOR_QUALITY", required = false) + /** + * The proportion of loci in a sample that must fall under the LOW_QUALITY category for the sample to be reported as LOW_QUALITY + */ + @Argument(fullName = "quality_status_threshold", shortName = "stQ", doc = "The proportion of the loci needed for calling POOR_QUALITY", required = false) private double qualityStatusThreshold = 0.50; + @Hidden @Argument(fullName = "print_debug_log", shortName = "dl", doc = "Used only for debugging the walker. Prints extra info to screen", required = false) private boolean debug = false; @@ -168,10 +195,8 @@ public class DiagnoseTargets extends LocusWalker { if (getToolkit().getIntervals() == null) throw new UserException("This tool only works if you provide one or more intervals. ( Use the -L argument )"); - thresholds = new ThresHolder(minimumBaseQuality, minimumMappingQuality, minimumCoverage, maximumCoverage, - minMedianDepth, maxInsertSize, votePercentage, lowMedianDepthPercentage, - badMateStatusThreshold, coverageStatusThreshold, excessiveCoverageThreshold, - qualityStatusThreshold); + thresholds = new ThresHolder(minimumBaseQuality, minimumMappingQuality, minimumCoverage, maximumCoverage, maxInsertSize, votePercentage, + badMateStatusThreshold, coverageStatusThreshold, excessiveCoverageThreshold, qualityStatusThreshold); intervalMap = new HashMap(INITIAL_HASH_SIZE); intervalListIterator = new PeekableIterator(getToolkit().getIntervals().iterator()); diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/IntervalStatistics.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/IntervalStatistics.java index 4fd9a20ef..0f4b33747 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/IntervalStatistics.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/IntervalStatistics.java @@ -154,26 +154,6 @@ class IntervalStatistics { output.add(status); } - // get median DP of each sample - final double minMedianDepth = thresholds.getLowMedianDepthThreshold() * samples.size(); - final int nSamples = samples.size(); - int nLowMedianDepth = 0; - int samplesSeen = 0; - for (SampleStatistics sample : samples.values()) { - samplesSeen++; - final double medianDepth = sample.getQuantileDepth(0.5); - if (medianDepth > 0 && medianDepth < thresholds.getMinimumMedianDepth()) { - nLowMedianDepth++; - } - if (nLowMedianDepth > minMedianDepth) { - output.add(CallableStatus.LOW_MEDIAN_DEPTH); - break; - } - if (nSamples - samplesSeen + nLowMedianDepth < minMedianDepth) - break; - } - - return output; } } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/SampleStatistics.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/SampleStatistics.java index 051369b94..afde93ea3 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/SampleStatistics.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/SampleStatistics.java @@ -293,17 +293,11 @@ class SampleStatistics { if (read.getReadNegativeStrandFlag() == read.getMateNegativeStrandFlag()) return false; - // inverted - if (read.getReadNegativeStrandFlag() == - read.getAlignmentStart() < read.getMateAlignmentStart()) - return false; + // todo -- inverted ? - // TODO note: IGV uses a different algorithm for insert size, there should be a common util class that does this for you // mates are too far apart - if (Math.abs(read.getAlignmentStart() - read.getMateAlignmentStart()) > thresholds.getMaximumInsertSize()) - return false; + return Math.abs(read.getAlignmentStart() - read.getMateAlignmentStart()) <= thresholds.getMaximumInsertSize(); - return true; } public int getnReads() { diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/ThresHolder.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/ThresHolder.java index fc4954f3b..c2dd2f4ff 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/ThresHolder.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/ThresHolder.java @@ -54,44 +54,38 @@ import java.util.Set; class ThresHolder { public static final String AVG_INTERVAL_DP_KEY = "AVG_INTERVAL_DP"; - public static final ThresHolder DEFAULTS = new ThresHolder(20, 20, 5, 700, 20, 50, 0.5, 0.2, 0.5, 0.2, 0.2, 0.5); + public static final ThresHolder DEFAULTS = new ThresHolder(20, 20, 5, 700, 50, 0.5, 0.5, 0.2, 0.2, 0.5); private final int minimumBaseQuality; private final int minimumMappingQuality; private final int minimumCoverage; private final int maximumCoverage; - private final int minimumMedianDepth; private final int maximumInsertSize; private final double votePercentageThreshold; - private final double lowMedianDepthThreshold; private final double badMateStatusThreshold; private final double coverageStatusThreshold; private final double excessiveCoverageThreshold; private final double qualityStatusThreshold; - public ThresHolder(int minimumBaseQuality, - int minimumMappingQuality, - int minimumCoverage, - int maximumCoverage, - int minimumMedianDepth, - int maximumInsertSize, - double votePercentageThreshold, - double lowMedianDepthThreshold, - double badMateStatusThreshold, - double coverageStatusThreshold, - double excessiveCoverageThreshold, - double qualityStatusThreshold) { + public ThresHolder(final int minimumBaseQuality, + final int minimumMappingQuality, + final int minimumCoverage, + final int maximumCoverage, + final int maximumInsertSize, + final double votePercentageThreshold, + final double badMateStatusThreshold, + final double coverageStatusThreshold, + final double excessiveCoverageThreshold, + final double qualityStatusThreshold) { this.minimumBaseQuality = minimumBaseQuality; this.minimumMappingQuality = minimumMappingQuality; this.minimumCoverage = minimumCoverage; this.maximumCoverage = maximumCoverage; - this.minimumMedianDepth = minimumMedianDepth; this.maximumInsertSize = maximumInsertSize; this.votePercentageThreshold = votePercentageThreshold; - this.lowMedianDepthThreshold = lowMedianDepthThreshold; this.badMateStatusThreshold = badMateStatusThreshold; this.coverageStatusThreshold = coverageStatusThreshold; this.excessiveCoverageThreshold = excessiveCoverageThreshold; @@ -106,10 +100,6 @@ class ThresHolder { return maximumCoverage; } - public int getMinimumMedianDepth() { - return minimumMedianDepth; - } - public int getMaximumInsertSize() { return maximumInsertSize; } @@ -118,10 +108,6 @@ class ThresHolder { return votePercentageThreshold; } - public double getLowMedianDepthThreshold() { - return lowMedianDepthThreshold; - } - public double getBadMateStatusThreshold() { return badMateStatusThreshold; } @@ -156,7 +142,6 @@ class ThresHolder { headerLines.add(new VCFInfoHeaderLine("Diagnose Targets", 0, VCFHeaderLineType.Flag, "DiagnoseTargets mode")); // FORMAT fields for each genotype - // todo -- find the appropriate VCF constants headerLines.add(VCFStandardHeaderLines.getFormatLine(VCFConstants.GENOTYPE_FILTER_KEY)); headerLines.add(new VCFFormatHeaderLine(AVG_INTERVAL_DP_KEY, 1, VCFHeaderLineType.Float, "Average depth across the interval. Sum of the depth in a loci divided by interval size.")); headerLines.add(new VCFFormatHeaderLine("Q1", 1, VCFHeaderLineType.Float, "Lower Quartile of depth distribution.")); diff --git a/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargetsIntegrationTest.java b/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargetsIntegrationTest.java index a435a33ad..ef14f8386 100644 --- a/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargetsIntegrationTest.java +++ b/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargetsIntegrationTest.java @@ -66,11 +66,11 @@ public class DiagnoseTargetsIntegrationTest extends WalkerTest { @Test(enabled = true) public void testSingleSample() { - DTTest("testSingleSample ", "-I " + singleSample + " -max 75", "3d558ec8828c269774ee45e5df086a5f"); + DTTest("testSingleSample ", "-I " + singleSample + " -max 75", "742c13fc092b42f9ff71fc3fff4a95cc"); } @Test(enabled = true) public void testMultiSample() { - DTTest("testMultiSample ", "-I " + multiSample, "d40cf1f1daf68f2740cd411e2cf361fc"); + DTTest("testMultiSample ", "-I " + multiSample, "7083cc720a2caa02fb0fa8f49f94a826"); } } diff --git a/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/LocusStatisticsUnitTest.java b/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/LocusStatisticsUnitTest.java index 9ab4621b9..c86acebb9 100644 --- a/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/LocusStatisticsUnitTest.java +++ b/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/LocusStatisticsUnitTest.java @@ -57,7 +57,7 @@ public class LocusStatisticsUnitTest /*extends BaseTest*/ { @Test(dataProvider = "StatusTestValues") public void testCallableStatuses(int coverage, int rawCoverage, CallableStatus status) { // The min Coverage threshold is 10, the max is 100 - ThresHolder thresholds = new ThresHolder(20, 20, 10, 100, 20, 50, 0.5, 0.2, 0.5, 0.2, 0.2, 0.5); + ThresHolder thresholds = new ThresHolder(20, 20, 10, 100, 50, 0.5, 0.5, 0.2, 0.2, 0.5); Set statuses = new LocusStatistics(coverage, rawCoverage).callableStatuses(thresholds); // Check to make sure the status provides matches the actual Assert.assertTrue((status == null) ? statuses.isEmpty() : (statuses.contains(status) && statuses.size() == 1)); diff --git a/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/SampleStatisticsUnitTest.java b/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/SampleStatisticsUnitTest.java index 18e4bbfc2..dd9e1d86e 100644 --- a/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/SampleStatisticsUnitTest.java +++ b/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/SampleStatisticsUnitTest.java @@ -95,7 +95,7 @@ public class SampleStatisticsUnitTest/* extends BaseTest */ { GATKSAMRecord noPair = ArtificialSAMUtils.createArtificialRead(header, "test", 0, 100, 50); GATKSAMRecord good = ArtificialSAMUtils.createPair(header, "test", 30, 100, 150, true, false).get(0); GATKSAMRecord bigInsertSize = ArtificialSAMUtils.createPair(header, "test", 30, 100, 151, true, false).get(0); - GATKSAMRecord inverted = ArtificialSAMUtils.createPair(header, "test", 30, 151, 150, true, false).get(0); +// GATKSAMRecord inverted = ArtificialSAMUtils.createPair(header, "test", 30, 151, 150, true, false).get(0); GATKSAMRecord sameOrientation = ArtificialSAMUtils.createPair(header, "test", 30, 100, 151, true, true).get(0); GATKSAMRecord pairNotMapped = ArtificialSAMUtils.createPair(header, "test", 30, 100, 140, true, false).get(1); @@ -106,7 +106,7 @@ public class SampleStatisticsUnitTest/* extends BaseTest */ { new Object[]{noPair, false}, new Object[]{good, true}, new Object[]{bigInsertSize, false}, - new Object[]{inverted, false}, +// new Object[]{inverted, false}, new Object[]{sameOrientation, false}, new Object[]{pairNotMapped, false} }; From fdd16dc6f99eee6a866780540702b371d3abaf1d Mon Sep 17 00:00:00 2001 From: Mauricio Carneiro Date: Sat, 20 Apr 2013 21:49:50 -0400 Subject: [PATCH 5/8] DiagnoseTargets refactor A plugin enabled implementation of DiagnoseTargets Summarized Changes: ------------------- * move argument collection into Thresholder object * make thresholder object private member of all statistics classes * rework the logic of the mate pairing thresholds * update unit and integration tests to reflect the new behavior * Implements Locus Statistic plugins * Extend Locus Statistic plugins to determine sample status * Export all common plugin functionality into utility class * Update tests accordingly [fixes #48465557] --- .../diagnostics/targets/DiagnoseTargets.java | 183 ++++++------- .../targets/FindCoveredIntervals.java | 2 +- .../targets/IntervalStatistics.java | 71 +++-- .../diagnostics/targets/LocusStatistics.java | 48 ++-- .../diagnostics/targets/SampleStatistics.java | 259 ++++++------------ .../diagnostics/targets/ThresHolder.java | 152 +++++----- .../targets/statistics/Interval.java | 63 +++++ .../diagnostics/targets/statistics/Locus.java | 65 +++++ .../targets/statistics/LocusCoverageGap.java} | 88 ++---- .../statistics/LocusExcessiveCoverage.java | 79 ++++++ .../targets/statistics/LocusLowCoverage.java | 80 ++++++ .../targets/statistics/LocusPoorQuality.java | 79 ++++++ .../targets/statistics/PluginUtils.java | 66 +++++ .../targets/statistics/Sample.java | 63 +++++ .../targets/statistics/SampleBadMates.java | 76 +++++ .../targets/statistics/SampleNoReads.java | 73 +++++ .../DiagnoseTargetsIntegrationTest.java | 4 +- .../targets/LocusStatisticsUnitTest.java | 38 +-- 18 files changed, 983 insertions(+), 506 deletions(-) create mode 100644 protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/Interval.java create mode 100644 protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/Locus.java rename protected/java/{test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/SampleStatisticsUnitTest.java => src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/LocusCoverageGap.java} (73%) create mode 100644 protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/LocusExcessiveCoverage.java create mode 100644 protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/LocusLowCoverage.java create mode 100644 protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/LocusPoorQuality.java create mode 100644 protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/PluginUtils.java create mode 100644 protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/Sample.java create mode 100644 protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/SampleBadMates.java create mode 100644 protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/SampleNoReads.java diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargets.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargets.java index 5bdb81906..d90f2d1fa 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargets.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargets.java @@ -47,23 +47,26 @@ package org.broadinstitute.sting.gatk.walkers.diagnostics.targets; import net.sf.picard.util.PeekableIterator; -import org.broadinstitute.sting.commandline.Argument; -import org.broadinstitute.sting.commandline.Hidden; +import org.broadinstitute.sting.commandline.ArgumentCollection; import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.gatk.CommandLineGATK; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; import org.broadinstitute.sting.gatk.walkers.*; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics.Interval; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics.Locus; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics.Sample; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.SampleUtils; -import org.broadinstitute.sting.utils.help.HelpConstants; -import org.broadinstitute.variant.vcf.VCFConstants; -import org.broadinstitute.variant.vcf.VCFHeader; +import org.broadinstitute.sting.utils.classloader.PluginManager; +import org.broadinstitute.sting.utils.exceptions.DynamicClassResolutionException; import org.broadinstitute.sting.utils.exceptions.UserException; import org.broadinstitute.sting.utils.help.DocumentedGATKFeature; +import org.broadinstitute.sting.utils.help.HelpConstants; import org.broadinstitute.variant.variantcontext.*; import org.broadinstitute.variant.variantcontext.writer.VariantContextWriter; +import org.broadinstitute.variant.vcf.*; import java.util.*; @@ -111,80 +114,19 @@ import java.util.*; @PartitionBy(PartitionType.INTERVAL) public class DiagnoseTargets extends LocusWalker { + private static final String AVG_INTERVAL_DP_KEY = "IDP"; + @Output(doc = "File to which interval statistics should be written") private VariantContextWriter vcfWriter = null; - /** - * Only bases with quality greater than this will be considered in the coverage metrics. - */ - @Argument(fullName = "minimum_base_quality", shortName = "BQ", doc = "The minimum Base Quality that is considered for calls", required = false) - private int minimumBaseQuality = 20; - - /** - * Only reads with mapping quality greater than this will be considered in the coverage metrics. - */ - @Argument(fullName = "minimum_mapping_quality", shortName = "MQ", doc = "The minimum read mapping quality considered for calls", required = false) - private int minimumMappingQuality = 20; - - /** - * If at any locus, a sample has less coverage than this, it will be reported as LOW_COVERAGE - */ - @Argument(fullName = "minimum_coverage", shortName = "min", doc = "The minimum allowable coverage, used for calling LOW_COVERAGE", required = false) - private int minimumCoverage = 5; - - /** - * If at any locus, a sample has more coverage than this, it will be reported as EXCESSIVE_COVERAGE - */ - @Argument(fullName = "maximum_coverage", shortName = "max", doc = "The maximum allowable coverage, used for calling EXCESSIVE_COVERAGE", required = false) - private int maximumCoverage = 700; - - /** - * If any sample has a paired read whose distance between alignment starts (between the pairs) is greater than this, it will be reported as BAD_MATE - */ - @Argument(fullName = "maximum_insert_size", shortName = "ins", doc = "The maximum allowed distance between a read and its mate", required = false) - private int maxInsertSize = 500; - - /** - * The proportion of samples that must have a status for it to filter the entire interval. Example: 8 out of 10 samples have low coverage status on the interval, - * with a threshold higher than 0.2, this interval will be filtered as LOW_COVERAGE. - */ - @Argument(fullName = "voting_status_threshold", shortName = "stV", doc = "The needed proportion of samples containing a call for the interval to adopt the call ", required = false) - private double votePercentage = 0.50; - - /** - * The proportion of reads in the loci that must have bad mates for the sample to be reported as BAD_MATE - */ - @Argument(fullName = "bad_mate_status_threshold", shortName = "stBM", doc = "The proportion of the loci needed for calling BAD_MATE", required = false) - private double badMateStatusThreshold = 0.50; - - /** - * The proportion of loci in a sample that must fall under the LOW_COVERAGE or COVERAGE_GAPS category for the sample to be reported as either (or both) - */ - @Argument(fullName = "coverage_status_threshold", shortName = "stC", doc = "The proportion of the loci needed for calling LOW_COVERAGE and COVERAGE_GAPS", required = false) - private double coverageStatusThreshold = 0.20; - - /** - * The proportion of loci in a sample that must fall under the EXCESSIVE_COVERAGE category for the sample to be reported as EXCESSIVE_COVERAGE - */ - @Argument(fullName = "excessive_coverage_status_threshold", shortName = "stXC", doc = "The proportion of the loci needed for calling EXCESSIVE_COVERAGE", required = false) - private double excessiveCoverageThreshold = 0.20; - - /** - * The proportion of loci in a sample that must fall under the LOW_QUALITY category for the sample to be reported as LOW_QUALITY - */ - @Argument(fullName = "quality_status_threshold", shortName = "stQ", doc = "The proportion of the loci needed for calling POOR_QUALITY", required = false) - private double qualityStatusThreshold = 0.50; - - @Hidden - @Argument(fullName = "print_debug_log", shortName = "dl", doc = "Used only for debugging the walker. Prints extra info to screen", required = false) - private boolean debug = false; + @ArgumentCollection + private ThresHolder thresholds = new ThresHolder(); private Map intervalMap = null; // maps each interval => statistics private PeekableIterator intervalListIterator; // an iterator to go over all the intervals provided as we traverse the genome private Set samples = null; // all the samples being processed private static final Allele SYMBOLIC_ALLELE = Allele.create("
", false); // avoid creating the symbolic allele multiple times private static final Allele UNCOVERED_ALLELE = Allele.create("A", true); // avoid creating the 'fake' ref allele for uncovered intervals multiple times - private ThresHolder thresholds = null; // object that holds all the thresholds for Diagnose Targets (todo -- should become a plugin based system) private static final int INITIAL_HASH_SIZE = 500000; @@ -192,18 +134,18 @@ public class DiagnoseTargets extends LocusWalker { public void initialize() { super.initialize(); - if (getToolkit().getIntervals() == null) - throw new UserException("This tool only works if you provide one or more intervals. ( Use the -L argument )"); - - thresholds = new ThresHolder(minimumBaseQuality, minimumMappingQuality, minimumCoverage, maximumCoverage, maxInsertSize, votePercentage, - badMateStatusThreshold, coverageStatusThreshold, excessiveCoverageThreshold, qualityStatusThreshold); + if (getToolkit().getIntervals() == null || getToolkit().getIntervals().isEmpty()) + throw new UserException("This tool only works if you provide one or more intervals (use the -L argument). If you want to run whole genome, use -T DepthOfCoverage instead."); intervalMap = new HashMap(INITIAL_HASH_SIZE); intervalListIterator = new PeekableIterator(getToolkit().getIntervals().iterator()); // get all of the unique sample names for the VCF Header samples = SampleUtils.getSAMFileSamples(getToolkit().getSAMFileHeader()); - vcfWriter.writeHeader(new VCFHeader(ThresHolder.getHeaderInfo(), samples)); + vcfWriter.writeHeader(new VCFHeader(getHeaderInfo(), samples)); + + // pre load all the statistics classes because it is costly to operate on the JVM and we only want to do it once. + loadAllPlugins(thresholds); } @Override @@ -217,8 +159,7 @@ public class DiagnoseTargets extends LocusWalker { // at this point, all intervals in intervalMap overlap with this locus, so update all of them for (IntervalStatistics intervalStatistics : intervalMap.values()) - intervalStatistics.addLocus(context, ref, thresholds); - + intervalStatistics.addLocus(context); return 1L; } @@ -317,37 +258,26 @@ public class DiagnoseTargets extends LocusWalker { alleles.add(SYMBOLIC_ALLELE); VariantContextBuilder vcb = new VariantContextBuilder("DiagnoseTargets", interval.getContig(), interval.getStart(), interval.getStop(), alleles); - vcb = vcb.log10PError(VariantContext.NO_LOG10_PERROR); // QUAL field makes no sense in our VCF - vcb.filters(new HashSet(statusesToStrings(stats.callableStatuses(thresholds), true))); + vcb = vcb.log10PError(VariantContext.NO_LOG10_PERROR); + vcb.filters(new HashSet(statusesToStrings(stats.callableStatuses(), true))); attributes.put(VCFConstants.END_KEY, interval.getStop()); - attributes.put(ThresHolder.AVG_INTERVAL_DP_KEY, stats.averageCoverage()); + attributes.put(AVG_INTERVAL_DP_KEY, stats.averageCoverage()); vcb = vcb.attributes(attributes); - if (debug) { - System.out.printf("Output -- Interval: %s, Coverage: %.2f%n", stats.getInterval(), stats.averageCoverage()); - } for (String sample : samples) { final GenotypeBuilder gb = new GenotypeBuilder(sample); - SampleStatistics sampleStat = stats.getSample(sample); - gb.attribute(ThresHolder.AVG_INTERVAL_DP_KEY, sampleStat.averageCoverage()); - gb.attribute("Q1", sampleStat.getQuantileDepth(0.25)); - gb.attribute("MED", sampleStat.getQuantileDepth(0.50)); - gb.attribute("Q3", sampleStat.getQuantileDepth(0.75)); + SampleStatistics sampleStat = stats.getSampleStatics(sample); + gb.attribute(AVG_INTERVAL_DP_KEY, sampleStat.averageCoverage()); - if (debug) { - System.out.printf("Found %d bad mates out of %d reads %n", sampleStat.getnBadMates(), sampleStat.getnReads()); - } - gb.filters(statusesToStrings(stats.getSample(sample).getCallableStatuses(thresholds), false)); + gb.filters(statusesToStrings(stats.getSampleStatics(sample).getCallableStatuses(), false)); genotypes.add(gb.make()); } vcb = vcb.genotypes(genotypes); - vcfWriter.add(vcb.make()); - } /** @@ -356,17 +286,74 @@ public class DiagnoseTargets extends LocusWalker { * @param statuses the set of statuses to be converted * @return a matching set of strings */ - private List statusesToStrings(Set statuses, final boolean includePASS) { + private List statusesToStrings(Set statuses, final boolean isInfoField) { List output = new ArrayList(statuses.size()); for (CallableStatus status : statuses) - if ( includePASS || status != CallableStatus.PASS ) // adding pass => results in a filter for genotypes + if ( isInfoField || status != CallableStatus.PASS ) output.add(status.name()); return output; } private IntervalStatistics createIntervalStatistic(GenomeLoc interval) { - return new IntervalStatistics(samples, interval); + return new IntervalStatistics(samples, interval, thresholds); } + + protected static void loadAllPlugins(final ThresHolder thresholds) { + for (Class stat : new PluginManager(Locus.class).getPlugins()) { + try { + final Locus stats = (Locus) stat.newInstance(); + stats.initialize(thresholds); + thresholds.locusStatisticList.add(stats); + } catch (Exception e) { + throw new DynamicClassResolutionException(stat, e); + } + } + + for (Class stat : new PluginManager(Sample.class).getPlugins()) { + try { + final Sample stats = (Sample) stat.newInstance(); + stats.initialize(thresholds); + thresholds.sampleStatisticList.add(stats); + } catch (Exception e) { + throw new DynamicClassResolutionException(stat, e); + } + } + + for (Class stat : new PluginManager(Interval.class).getPlugins()) { + try { + final Interval stats = (Interval) stat.newInstance(); + stats.initialize(thresholds); + thresholds.intervalStatisticList.add(stats); + } catch (Exception e) { + throw new DynamicClassResolutionException(stat, e); + } + } + } + + /** + * Gets the header lines for the VCF writer + * + * @return A set of VCF header lines + */ + private static Set getHeaderInfo() { + Set headerLines = new HashSet(); + + // INFO fields for overall data + headerLines.add(VCFStandardHeaderLines.getInfoLine(VCFConstants.END_KEY)); + headerLines.add(new VCFInfoHeaderLine(AVG_INTERVAL_DP_KEY, 1, VCFHeaderLineType.Float, "Average depth across the interval. Sum of the depth in a loci divided by interval size.")); + headerLines.add(new VCFInfoHeaderLine("Diagnose Targets", 0, VCFHeaderLineType.Flag, "DiagnoseTargets mode")); + + // FORMAT fields for each genotype + headerLines.add(VCFStandardHeaderLines.getFormatLine(VCFConstants.GENOTYPE_FILTER_KEY)); + headerLines.add(new VCFFormatHeaderLine(AVG_INTERVAL_DP_KEY, 1, VCFHeaderLineType.Float, "Average sample depth across the interval. Sum of the sample specific depth in all loci divided by interval size.")); + + // FILTER fields + for (CallableStatus stat : CallableStatus.values()) + headerLines.add(new VCFFilterHeaderLine(stat.name(), stat.description)); + + return headerLines; + } + } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/FindCoveredIntervals.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/FindCoveredIntervals.java index eef581160..1c9751c5b 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/FindCoveredIntervals.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/FindCoveredIntervals.java @@ -105,7 +105,7 @@ public class FindCoveredIntervals extends ActiveRegionWalker { // Look to see if the region has sufficient coverage public ActivityProfileState isActive(final RefMetaDataTracker tracker, final ReferenceContext ref, final AlignmentContext context) { - int depth = ThresHolder.DEFAULTS.getFilteredCoverage(context.getBasePileup()); + int depth = context.getBasePileup().getBaseFilteredPileup(coverageThreshold).depthOfCoverage(); // note the linear probability scale return new ActivityProfileState(ref.getLocus(), Math.min(depth / coverageThreshold, 1)); diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/IntervalStatistics.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/IntervalStatistics.java index 0f4b33747..2e7333cc6 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/IntervalStatistics.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/IntervalStatistics.java @@ -47,7 +47,7 @@ package org.broadinstitute.sting.gatk.walkers.diagnostics.targets; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; -import org.broadinstitute.sting.gatk.contexts.ReferenceContext; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics.Interval; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.exceptions.ReviewedStingException; import org.broadinstitute.sting.utils.pileup.ReadBackedPileup; @@ -57,27 +57,23 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; -class IntervalStatistics { +public class IntervalStatistics { private final Map samples; private final GenomeLoc interval; - private boolean hasNref = false; + private final ThresHolder thresholds; - private int preComputedTotalCoverage = -1; // avoids re-calculating the total sum (-1 means we haven't pre-computed it yet) + private int preComputedTotalCoverage = -1; - /* - private double minMedianDepth = 20.0; - private double badMedianDepthPercentage = 0.20; - private double votePercentage = 0.50; - */ - public IntervalStatistics(Set samples, GenomeLoc interval/*, int minimumCoverageThreshold, int maximumCoverageThreshold, int minimumMappingQuality, int minimumBaseQuality*/) { + public IntervalStatistics(Set samples, GenomeLoc interval, ThresHolder thresholds) { this.interval = interval; + this.thresholds = thresholds; this.samples = new HashMap(samples.size()); for (String sample : samples) - this.samples.put(sample, new SampleStatistics(interval /*, minimumCoverageThreshold, maximumCoverageThreshold, minimumMappingQuality, minimumBaseQuality*/)); + this.samples.put(sample, new SampleStatistics(interval, thresholds)); } - public SampleStatistics getSample(String sample) { + public SampleStatistics getSampleStatics(String sample) { return samples.get(sample); } @@ -85,19 +81,19 @@ class IntervalStatistics { return interval; } + public int getNSamples() { + return samples.size(); + } + /** * The function to populate data into the Statistics from the walker. * This takes the input and manages passing the data to the SampleStatistics and Locus Statistics * * @param context The alignment context given from the walker - * @param ref the reference context given from the walker - * @param thresholds the class contains the statistical threshold for making calls */ - public void addLocus(AlignmentContext context, ReferenceContext ref, ThresHolder thresholds) { + public void addLocus(AlignmentContext context) { ReadBackedPileup pileup = context.getBasePileup(); - //System.out.println(ref.getLocus().toString()); - Map samplePileups = pileup.getPileupsForSamples(samples.keySet()); for (Map.Entry entry : samplePileups.entrySet()) { @@ -108,11 +104,9 @@ class IntervalStatistics { if (sampleStatistics == null) throw new ReviewedStingException(String.format("Trying to add locus statistics to a sample (%s) that doesn't exist in the Interval.", sample)); - sampleStatistics.addLocus(context.getLocation(), samplePileup, thresholds); + sampleStatistics.addLocus(context.getLocation(), samplePileup); } - if (!hasNref && ref.getBase() == 'N') - hasNref = true; } public double averageCoverage() { @@ -129,29 +123,34 @@ class IntervalStatistics { /** * Return the Callable statuses for the interval as a whole - * todo -- add missingness filter * - * @param thresholds the class contains the statistical threshold for making calls * @return the callable status(es) for the whole interval */ - public Set callableStatuses(ThresHolder thresholds) { - Set output = new HashSet(); + public Set callableStatuses() { + final Set output = new HashSet(); - // Initialize the Map - Map votes = new HashMap(); - for (CallableStatus status : CallableStatus.values()) - votes.put(status, 0); + // sum up all the callable status for each sample + final Map sampleStatusTally = new HashMap(CallableStatus.values().length); + for (SampleStatistics sampleStatistics : samples.values()) { + for (CallableStatus status : sampleStatistics.getCallableStatuses()) { + sampleStatusTally.put(status, !sampleStatusTally.containsKey(status) ? 1 : sampleStatusTally.get(status) + 1); + } + } - // tally up the votes - for (SampleStatistics sample : samples.values()) - for (CallableStatus status : sample.getCallableStatuses(thresholds)) - votes.put(status, votes.get(status) + 1); + // check if any of the votes pass the threshold + final int nSamples = getNSamples(); + for (Map.Entry entry : sampleStatusTally.entrySet()) { + if ((double) entry.getValue() / nSamples > thresholds.votePercentageThreshold) { + output.add(entry.getKey()); + } + } - // output tall values above the threshold - final double minVotesNeeded = thresholds.getVotePercentageThreshold() * samples.size(); - for (CallableStatus status : votes.keySet()) { - if (!status.equals((CallableStatus.PASS)) && votes.get(status) > minVotesNeeded) + // add the interval specific statitics statuses + for (Interval intervalStat : thresholds.intervalStatisticList) { + final CallableStatus status = intervalStat.status(this); + if (status != null) { output.add(status); + } } return output; diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/LocusStatistics.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/LocusStatistics.java index 5ec1a1608..e85f3d9c1 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/LocusStatistics.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/LocusStatistics.java @@ -46,21 +46,25 @@ package org.broadinstitute.sting.gatk.walkers.diagnostics.targets; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics.Locus; + import java.util.HashSet; +import java.util.List; import java.util.Set; -class LocusStatistics { - private final int coverage; - private final int rawCoverage; +public class LocusStatistics { + private int coverage; + private int rawCoverage; + private final List locusStatisticsList; - public LocusStatistics() { - this.coverage = 0; - this.rawCoverage = 0; + public LocusStatistics(ThresHolder thresholds) { + this(0,0,thresholds); } - public LocusStatistics(int coverage, int rawCoverage) { + protected LocusStatistics(int coverage, int rawCoverage, ThresHolder thresholds) { this.coverage = coverage; this.rawCoverage = rawCoverage; + this.locusStatisticsList = thresholds.locusStatisticList; } public int getCoverage() { @@ -74,31 +78,21 @@ class LocusStatistics { /** * Generates all applicable statuses from the coverages in this locus * - * @param thresholds the class contains the statistical threshold for making calls * @return a set of all statuses that apply */ - public Set callableStatuses(ThresHolder thresholds) { + public Set callableStatuses() { Set output = new HashSet(); - - // if too much coverage - if (getCoverage() > thresholds.getMaximumCoverage()) - output.add(CallableStatus.EXCESSIVE_COVERAGE); - - // if not enough coverage - if (getCoverage() < thresholds.getMinimumCoverage()) { - // was there a lot of low Qual coverage? - if (getRawCoverage() >= thresholds.getMinimumCoverage()) - output.add(CallableStatus.POOR_QUALITY); - // no? - else { - // is there any coverage? - if (getRawCoverage() > 0) - output.add(CallableStatus.LOW_COVERAGE); - else - output.add(CallableStatus.COVERAGE_GAPS); + for (Locus stats : locusStatisticsList) { + CallableStatus status = stats.status(this); + if (status != null) { + output.add(status); } } - return output; } + + public void set(final int coverage, final int rawCoverage) { + this.coverage = coverage; + this.rawCoverage = rawCoverage; + } } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/SampleStatistics.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/SampleStatistics.java index afde93ea3..c05feebbd 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/SampleStatistics.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/SampleStatistics.java @@ -46,6 +46,8 @@ package org.broadinstitute.sting.gatk.walkers.diagnostics.targets; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics.Locus; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics.Sample; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.exceptions.ReviewedStingException; import org.broadinstitute.sting.utils.pileup.ReadBackedPileup; @@ -56,93 +58,100 @@ import java.util.*; /** * The statistics calculator for a specific sample given the interval */ -class SampleStatistics { +public class SampleStatistics { private final GenomeLoc interval; private final ArrayList loci; + private final ThresHolder thresholds; - private int[] preSortedDepths = null; - private int preComputedTotalCoverage = -1; // avoids re-calculating the total sum (-1 means we haven't pre-computed it yet) - + // avoids re-calculating these sums over loci + private int preComputedTotalCoverage = -1; + private Map locusStatusTally = null; private int nReads = -1; private int nBadMates = -1; - private SampleStatistics(GenomeLoc interval, ArrayList loci) { + public SampleStatistics(final GenomeLoc interval, final ThresHolder thresholds) { this.interval = interval; - this.loci = loci; + this.loci = new ArrayList(interval.size()); + this.thresholds = thresholds; nReads = 0; nBadMates = 0; - } - - public SampleStatistics(GenomeLoc interval) { - this(interval, new ArrayList(interval.size())); // Initialize every loci (this way we don't have to worry about non-existent loci in the object for (int i = 0; i < interval.size(); i++) - this.loci.add(new LocusStatistics()); + this.loci.add(new LocusStatistics(thresholds)); } + /** + * Calculates the total "good" coverage of this sample. Good means "passes the base and + * mapping quality requirements. + * + * @return the total "good" coverage across the interval for this sample + */ public long totalCoverage() { if (preComputedTotalCoverage < 0) calculateTotalCoverage(); return preComputedTotalCoverage; } + /** + * Calculates the average "good" coverage of this sample. Good means "passes the base and + * mapping quality requirements. + * + * @return the average "good" coverage + */ public double averageCoverage() { - if (preComputedTotalCoverage < 0) - calculateTotalCoverage(); - return (double) preComputedTotalCoverage / loci.size(); + return (double) totalCoverage() / loci.size(); + } + + /** + * Tally up all the callable status of all the loci in this sample. + * + * @return a map of callable status and counts + */ + public Map getLocusStatusTally() { + if (locusStatusTally == null) { + locusStatusTally = new HashMap(CallableStatus.values().length); + + // sum up all the callable statuses for each locus + for (int i = 0; i < interval.size(); i++) { + LocusStatistics locus = loci.get(i); + for (CallableStatus status : locus.callableStatuses()) { + locusStatusTally.put(status, !locusStatusTally.containsKey(status) ? 1 : locusStatusTally.get(status) + 1); + } + } + } + return locusStatusTally; } /** * Calculates the callable statuses of the entire sample * - * @param thresholds the class contains the statistical threshold for making calls * @return the callable statuses of the entire sample */ - public Set getCallableStatuses(ThresHolder thresholds) { - // We check if reads are present to prevent div / 0 exceptions - if (nReads == 0) { - return Collections.singleton(CallableStatus.NO_READS); - } + public Set getCallableStatuses() { + final Set output = new HashSet(); - Set output = new HashSet(); - Map totals = new HashMap(CallableStatus.values().length); - - // initialize map - for (CallableStatus status : CallableStatus.values()) - totals.put(status, 0.0); - - // sum up all the callable statuses for each locus - for (int i = 0; i < interval.size(); i++) { - for (CallableStatus status : callableStatus(i, thresholds)) { - double count = totals.get(status); - - totals.put(status, count + 1); + // get the tally of all the locus callable statuses + for (Locus locusStat : thresholds.locusStatisticList) { + final CallableStatus status = locusStat.sampleStatus(this); + if (status != null) { + output.add(status); } } - double intervalSize = interval.size(); - - if (((double) nBadMates / nReads) >= thresholds.getBadMateStatusThreshold()) - output.add(CallableStatus.BAD_MATE); - - if ((totals.get(CallableStatus.COVERAGE_GAPS) / intervalSize) >= thresholds.getCoverageStatusThreshold()) - output.add(CallableStatus.COVERAGE_GAPS); - - if ((totals.get(CallableStatus.LOW_COVERAGE) / intervalSize) >= thresholds.getCoverageStatusThreshold()) - output.add(CallableStatus.LOW_COVERAGE); - - if ((totals.get(CallableStatus.EXCESSIVE_COVERAGE) / intervalSize) >= thresholds.getExcessiveCoverageThreshold()) - output.add(CallableStatus.EXCESSIVE_COVERAGE); - - if ((totals.get(CallableStatus.POOR_QUALITY) / intervalSize) >= thresholds.getQualityStatusThreshold()) - output.add(CallableStatus.POOR_QUALITY); - - if (output.isEmpty()) { - output.add(CallableStatus.PASS); + // get the sample specific statitics statuses + for (Sample sampleStat : thresholds.sampleStatisticList) { + final CallableStatus status = sampleStat.status(this); + if (status != null) { + output.add(status); + } } + // special case, if there are no reads, then there is no sense reporting coverage gaps. + if (output.contains(CallableStatus.NO_READS) && output.contains(CallableStatus.COVERAGE_GAPS)) + output.remove(CallableStatus.COVERAGE_GAPS); + return output; } @@ -151,50 +160,37 @@ class SampleStatistics { * * @param locus The locus given as a GenomeLoc * @param pileup The pileup of that locus, this exclusively contains the sample - * @param thresholds the class contains the statistical threshold for making calls */ - public void addLocus(GenomeLoc locus, ReadBackedPileup pileup, ThresHolder thresholds) { + public void addLocus(GenomeLoc locus, ReadBackedPileup pileup) { if (!interval.containsP(locus)) throw new ReviewedStingException(String.format("Locus %s is not part of the Interval %s", locus, interval)); // a null pileup means there nothing ot add if (pileup != null) { - - int locusIndex = locus.getStart() - interval.getStart(); - - int rawCoverage = pileup.depthOfCoverage(); - int coverage = thresholds.getFilteredCoverage(pileup); - - LocusStatistics locusData = new LocusStatistics(coverage, rawCoverage); - - loci.set(locusIndex, locusData); + final int locusIndex = locus.getStart() - interval.getStart(); + final int rawCoverage = pileup.depthOfCoverage(); + final int coverage = pileup.getBaseAndMappingFilteredPileup(thresholds.minimumBaseQuality, thresholds.minimumMappingQuality).depthOfCoverage(); + final LocusStatistics locusData = loci.get(locusIndex); + locusData.set(coverage, rawCoverage); for (GATKSAMRecord read : pileup.getReads()) - processRead(read, thresholds); - } - } - - private void processRead(GATKSAMRecord read, ThresHolder thresholds) { - // Was this read already processed? - if (read.getTemporaryAttribute("checkedBadMate") == null) { - nReads++; - if (!hasValidMate(read, thresholds)) - nBadMates++; - read.setTemporaryAttribute("checkedBadMate", true); + processRead(read); } } /** - * returns the callable status of a given locus without taking the reference base into account. - * - * @param locusIndex location in the genome to inquire (only one locus) - * @param thresholds the class contains the statistical threshold for making calls - * @return the callable status of a locus + * Account for the read and check it for any statistics necessary. Reads are marked in the temporary + * attribute "seen" to make sure they're not counted twice. + * + * @param read the read */ - private Set callableStatus(int locusIndex, ThresHolder thresholds) { - LocusStatistics locus = loci.get(locusIndex); - - return locus.callableStatuses(thresholds); + private void processRead(GATKSAMRecord read) { + if (read.getTemporaryAttribute("seen") == null) { + nReads++; + if (read.getReadPairedFlag() && !read.getProperPairFlag()) + nBadMates++; + read.setTemporaryAttribute("seen", true); + } } private void calculateTotalCoverage() { @@ -203,101 +199,8 @@ class SampleStatistics { preComputedTotalCoverage += locus.getCoverage(); } - public double getQuantileDepth(double percentage) { - if (preSortedDepths == null) - getDepthsAsSortedArray(); - - return getQuartile(preSortedDepths, percentage); - } - - static double getQuartile(int[] data, double percentage) { - int size = data.length; - if (size == 1) - return (double) data[0]; - - if (percentage == 0.5) { - return getMedian(data); - } - - double position = (size - 1.0) / 2; - if (percentage == 0.25) { - // if the position is a whole number - return getMedian(Arrays.copyOfRange(data, 0, (int) position + 1)); - - } - if (percentage == 0.75) { - if (position % 1 == 0) { - return getMedian(Arrays.copyOfRange(data, (int) position, size)); - } else { - return getMedian(Arrays.copyOfRange(data, (int) position + 1, size)); - } - } - return -1; - } - - // Assumes data is sorted - private static double getMedian(int[] data) { - double size = (double) data.length; - if (size == 1) - return (double) data[0]; - - double position = (size - 1.0) / 2; - - if (position % 1 == 0) - return (double) data[(int) position]; - - else { - double high = (double) data[(int) Math.ceil(position)]; - double low = (double) data[(int) Math.floor(position)]; - - return (high + low) / 2; - - } - - } - - private void getDepthsAsSortedArray() { - preSortedDepths = new int[loci.size()]; - - for (int i = 0; i < loci.size(); i++) - preSortedDepths[i] = loci.get(i).getCoverage(); - - Arrays.sort(preSortedDepths); - } - - boolean hasValidMate(GATKSAMRecord read, ThresHolder thresholds) { - /** Check the following - * Does it have a pair? - * reasonable insert size? - * inverted? - * same orientation? - * same contig? - * is pair mapped? - * todo - is forced mate? - * - */ - - // has NO pair - if (!read.getReadPairedFlag()) - return false; - - // different contigs - if (!read.getMateReferenceIndex().equals(read.getReferenceIndex())) - return false; - - // unmapped - if (read.getMateUnmappedFlag() || read.getReadUnmappedFlag()) - return false; - - // same orientation - if (read.getReadNegativeStrandFlag() == read.getMateNegativeStrandFlag()) - return false; - - // todo -- inverted ? - - // mates are too far apart - return Math.abs(read.getAlignmentStart() - read.getMateAlignmentStart()) <= thresholds.getMaximumInsertSize(); - + public int getIntervalSize() { + return interval.size(); } public int getnReads() { diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/ThresHolder.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/ThresHolder.java index c2dd2f4ff..3b7626708 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/ThresHolder.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/ThresHolder.java @@ -46,29 +46,82 @@ package org.broadinstitute.sting.gatk.walkers.diagnostics.targets; -import org.broadinstitute.variant.vcf.*; -import org.broadinstitute.sting.utils.pileup.ReadBackedPileup; +import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics.Interval; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics.Locus; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics.Sample; -import java.util.HashSet; -import java.util.Set; +import java.util.LinkedList; +import java.util.List; -class ThresHolder { - public static final String AVG_INTERVAL_DP_KEY = "AVG_INTERVAL_DP"; - public static final ThresHolder DEFAULTS = new ThresHolder(20, 20, 5, 700, 50, 0.5, 0.5, 0.2, 0.2, 0.5); +public class ThresHolder { - private final int minimumBaseQuality; - private final int minimumMappingQuality; + /** + * Only bases with quality greater than this will be considered in the coverage metrics. + */ + @Argument(fullName = "minimum_base_quality", shortName = "BQ", doc = "The minimum Base Quality that is considered for calls", required = false) + public int minimumBaseQuality = 20; - private final int minimumCoverage; - private final int maximumCoverage; + /** + * Only reads with mapping quality greater than this will be considered in the coverage metrics. + */ + @Argument(fullName = "minimum_mapping_quality", shortName = "MQ", doc = "The minimum read mapping quality considered for calls", required = false) + public int minimumMappingQuality = 20; - private final int maximumInsertSize; + /** + * If at any locus, a sample has less coverage than this, it will be reported as LOW_COVERAGE + */ + @Argument(fullName = "minimum_coverage", shortName = "min", doc = "The minimum allowable coverage, used for calling LOW_COVERAGE", required = false) + public int minimumCoverage = 5; - private final double votePercentageThreshold; - private final double badMateStatusThreshold; - private final double coverageStatusThreshold; - private final double excessiveCoverageThreshold; - private final double qualityStatusThreshold; + /** + * If at any locus, a sample has more coverage than this, it will be reported as EXCESSIVE_COVERAGE + */ + @Argument(fullName = "maximum_coverage", shortName = "max", doc = "The maximum allowable coverage, used for calling EXCESSIVE_COVERAGE", required = false) + public int maximumCoverage = 700; + + /** + * If any sample has a paired read whose distance between alignment starts (between the pairs) is greater than this, it will be reported as BAD_MATE + */ + @Argument(fullName = "maximum_insert_size", shortName = "ins", doc = "The maximum allowed distance between a read and its mate", required = false) + public int maximumInsertSize = 500; + + /** + * The proportion of samples that must have a status for it to filter the entire interval. Example: 8 out of 10 samples have low coverage status on the interval, + * with a threshold higher than 0.2, this interval will be filtered as LOW_COVERAGE. + */ + @Argument(fullName = "voting_status_threshold", shortName = "stV", doc = "The needed proportion of samples containing a call for the interval to adopt the call ", required = false) + public double votePercentageThreshold = 0.50; + + /** + * The proportion of reads in the loci that must have bad mates for the sample to be reported as BAD_MATE + */ + @Argument(fullName = "bad_mate_status_threshold", shortName = "stBM", doc = "The proportion of the loci needed for calling BAD_MATE", required = false) + public double badMateStatusThreshold = 0.50; + + /** + * The proportion of loci in a sample that must fall under the LOW_COVERAGE or COVERAGE_GAPS category for the sample to be reported as either (or both) + */ + @Argument(fullName = "coverage_status_threshold", shortName = "stC", doc = "The proportion of the loci needed for calling LOW_COVERAGE and COVERAGE_GAPS", required = false) + public double coverageStatusThreshold = 0.20; + + /** + * The proportion of loci in a sample that must fall under the EXCESSIVE_COVERAGE category for the sample to be reported as EXCESSIVE_COVERAGE + */ + @Argument(fullName = "excessive_coverage_status_threshold", shortName = "stXC", doc = "The proportion of the loci needed for calling EXCESSIVE_COVERAGE", required = false) + public double excessiveCoverageThreshold = 0.20; + + /** + * The proportion of loci in a sample that must fall under the LOW_QUALITY category for the sample to be reported as LOW_QUALITY + */ + @Argument(fullName = "quality_status_threshold", shortName = "stQ", doc = "The proportion of the loci needed for calling POOR_QUALITY", required = false) + public double qualityStatusThreshold = 0.50; + + public final List locusStatisticList = new LinkedList(); + public final List sampleStatisticList = new LinkedList(); + public final List intervalStatisticList = new LinkedList(); + + public ThresHolder() {} public ThresHolder(final int minimumBaseQuality, final int minimumMappingQuality, @@ -91,69 +144,4 @@ class ThresHolder { this.excessiveCoverageThreshold = excessiveCoverageThreshold; this.qualityStatusThreshold = qualityStatusThreshold; } - - public int getMinimumCoverage() { - return minimumCoverage; - } - - public int getMaximumCoverage() { - return maximumCoverage; - } - - public int getMaximumInsertSize() { - return maximumInsertSize; - } - - public double getVotePercentageThreshold() { - return votePercentageThreshold; - } - - public double getBadMateStatusThreshold() { - return badMateStatusThreshold; - } - - public double getCoverageStatusThreshold() { - return coverageStatusThreshold; - } - - public double getExcessiveCoverageThreshold() { - return excessiveCoverageThreshold; - } - - public double getQualityStatusThreshold() { - return qualityStatusThreshold; - } - - public int getFilteredCoverage(ReadBackedPileup pileup) { - return pileup.getBaseAndMappingFilteredPileup(minimumBaseQuality, minimumMappingQuality).depthOfCoverage(); - } - - /** - * Gets the header lines for the VCF writer - * - * @return A set of VCF header lines - */ - public static Set getHeaderInfo() { - Set headerLines = new HashSet(); - - // INFO fields for overall data - headerLines.add(VCFStandardHeaderLines.getInfoLine(VCFConstants.END_KEY)); - headerLines.add(new VCFInfoHeaderLine(AVG_INTERVAL_DP_KEY, 1, VCFHeaderLineType.Float, "Average depth across the interval. Sum of the depth in a loci divided by interval size.")); - headerLines.add(new VCFInfoHeaderLine("Diagnose Targets", 0, VCFHeaderLineType.Flag, "DiagnoseTargets mode")); - - // FORMAT fields for each genotype - headerLines.add(VCFStandardHeaderLines.getFormatLine(VCFConstants.GENOTYPE_FILTER_KEY)); - headerLines.add(new VCFFormatHeaderLine(AVG_INTERVAL_DP_KEY, 1, VCFHeaderLineType.Float, "Average depth across the interval. Sum of the depth in a loci divided by interval size.")); - headerLines.add(new VCFFormatHeaderLine("Q1", 1, VCFHeaderLineType.Float, "Lower Quartile of depth distribution.")); - headerLines.add(new VCFFormatHeaderLine("MED", 1, VCFHeaderLineType.Float, "Median of depth distribution.")); - headerLines.add(new VCFFormatHeaderLine("Q3", 1, VCFHeaderLineType.Float, "Upper Quartile of depth Distribution.")); - - - // FILTER fields - for (CallableStatus stat : CallableStatus.values()) - headerLines.add(new VCFFilterHeaderLine(stat.name(), stat.description)); - - return headerLines; - } - } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/Interval.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/Interval.java new file mode 100644 index 000000000..3e8adc978 --- /dev/null +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/Interval.java @@ -0,0 +1,63 @@ +/* +* By downloading the PROGRAM you agree to the following terms of use: +* +* BROAD INSTITUTE - SOFTWARE LICENSE AGREEMENT - FOR ACADEMIC NON-COMMERCIAL RESEARCH PURPOSES ONLY +* +* This Agreement is made between the Broad Institute, Inc. with a principal address at 7 Cambridge Center, Cambridge, MA 02142 (BROAD) and the LICENSEE and is effective at the date the downloading is completed (EFFECTIVE DATE). +* +* WHEREAS, LICENSEE desires to license the PROGRAM, as defined hereinafter, and BROAD wishes to have this PROGRAM utilized in the public interest, subject only to the royalty-free, nonexclusive, nontransferable license rights of the United States Government pursuant to 48 CFR 52.227-14; and +* WHEREAS, LICENSEE desires to license the PROGRAM and BROAD desires to grant a license on the following terms and conditions. +* NOW, THEREFORE, in consideration of the promises and covenants made herein, the parties hereto agree as follows: +* +* 1. DEFINITIONS +* 1.1 PROGRAM shall mean copyright in the object code and source code known as GATK2 and related documentation, if any, as they exist on the EFFECTIVE DATE and can be downloaded from http://www.broadinstitute/GATK on the EFFECTIVE DATE. +* +* 2. LICENSE +* 2.1 Grant. Subject to the terms of this Agreement, BROAD hereby grants to LICENSEE, solely for academic non-commercial research purposes, a non-exclusive, non-transferable license to: (a) download, execute and display the PROGRAM and (b) create bug fixes and modify the PROGRAM. +* The LICENSEE may apply the PROGRAM in a pipeline to data owned by users other than the LICENSEE and provide these users the results of the PROGRAM provided LICENSEE does so for academic non-commercial purposes only. For clarification purposes, academic sponsored research is not a commercial use under the terms of this Agreement. +* 2.2 No Sublicensing or Additional Rights. LICENSEE shall not sublicense or distribute the PROGRAM, in whole or in part, without prior written permission from BROAD. LICENSEE shall ensure that all of its users agree to the terms of this Agreement. LICENSEE further agrees that it shall not put the PROGRAM on a network, server, or other similar technology that may be accessed by anyone other than the LICENSEE and its employees and users who have agreed to the terms of this agreement. +* 2.3 License Limitations. Nothing in this Agreement shall be construed to confer any rights upon LICENSEE by implication, estoppel, or otherwise to any computer software, trademark, intellectual property, or patent rights of BROAD, or of any other entity, except as expressly granted herein. LICENSEE agrees that the PROGRAM, in whole or part, shall not be used for any commercial purpose, including without limitation, as the basis of a commercial software or hardware product or to provide services. LICENSEE further agrees that the PROGRAM shall not be copied or otherwise adapted in order to circumvent the need for obtaining a license for use of the PROGRAM. +* +* 3. OWNERSHIP OF INTELLECTUAL PROPERTY +* LICENSEE acknowledges that title to the PROGRAM shall remain with BROAD. The PROGRAM is marked with the following BROAD copyright notice and notice of attribution to contributors. LICENSEE shall retain such notice on all copies. LICENSEE agrees to include appropriate attribution if any results obtained from use of the PROGRAM are included in any publication. +* Copyright 2012 Broad Institute, Inc. +* Notice of attribution: The GATK2 program was made available through the generosity of Medical and Population Genetics program at the Broad Institute, Inc. +* LICENSEE shall not use any trademark or trade name of BROAD, or any variation, adaptation, or abbreviation, of such marks or trade names, or any names of officers, faculty, students, employees, or agents of BROAD except as states above for attribution purposes. +* +* 4. INDEMNIFICATION +* LICENSEE shall indemnify, defend, and hold harmless BROAD, and their respective officers, faculty, students, employees, associated investigators and agents, and their respective successors, heirs and assigns, (Indemnitees), against any liability, damage, loss, or expense (including reasonable attorneys fees and expenses) incurred by or imposed upon any of the Indemnitees in connection with any claims, suits, actions, demands or judgments arising out of any theory of liability (including, without limitation, actions in the form of tort, warranty, or strict liability and regardless of whether such action has any factual basis) pursuant to any right or license granted under this Agreement. +* +* 5. NO REPRESENTATIONS OR WARRANTIES +* THE PROGRAM IS DELIVERED AS IS. BROAD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE PROGRAM OR THE COPYRIGHT, EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, WHETHER OR NOT DISCOVERABLE. BROAD EXTENDS NO WARRANTIES OF ANY KIND AS TO PROGRAM CONFORMITY WITH WHATEVER USER MANUALS OR OTHER LITERATURE MAY BE ISSUED FROM TIME TO TIME. +* IN NO EVENT SHALL BROAD OR ITS RESPECTIVE DIRECTORS, OFFICERS, EMPLOYEES, AFFILIATED INVESTIGATORS AND AFFILIATES BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING, WITHOUT LIMITATION, ECONOMIC DAMAGES OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER BROAD SHALL BE ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT SHALL KNOW OF THE POSSIBILITY OF THE FOREGOING. +* +* 6. ASSIGNMENT +* This Agreement is personal to LICENSEE and any rights or obligations assigned by LICENSEE without the prior written consent of BROAD shall be null and void. +* +* 7. MISCELLANEOUS +* 7.1 Export Control. LICENSEE gives assurance that it will comply with all United States export control laws and regulations controlling the export of the PROGRAM, including, without limitation, all Export Administration Regulations of the United States Department of Commerce. Among other things, these laws and regulations prohibit, or require a license for, the export of certain types of software to specified countries. +* 7.2 Termination. LICENSEE shall have the right to terminate this Agreement for any reason upon prior written notice to BROAD. If LICENSEE breaches any provision hereunder, and fails to cure such breach within thirty (30) days, BROAD may terminate this Agreement immediately. Upon termination, LICENSEE shall provide BROAD with written assurance that the original and all copies of the PROGRAM have been destroyed, except that, upon prior written authorization from BROAD, LICENSEE may retain a copy for archive purposes. +* 7.3 Survival. The following provisions shall survive the expiration or termination of this Agreement: Articles 1, 3, 4, 5 and Sections 2.2, 2.3, 7.3, and 7.4. +* 7.4 Notice. Any notices under this Agreement shall be in writing, shall specifically refer to this Agreement, and shall be sent by hand, recognized national overnight courier, confirmed facsimile transmission, confirmed electronic mail, or registered or certified mail, postage prepaid, return receipt requested. All notices under this Agreement shall be deemed effective upon receipt. +* 7.5 Amendment and Waiver; Entire Agreement. This Agreement may be amended, supplemented, or otherwise modified only by means of a written instrument signed by all parties. Any waiver of any rights or failure to act in a specific instance shall relate only to such instance and shall not be construed as an agreement to waive any rights or fail to act in any other instance, whether or not similar. This Agreement constitutes the entire agreement among the parties with respect to its subject matter and supersedes prior agreements or understandings between the parties relating to its subject matter. +* 7.6 Binding Effect; Headings. This Agreement shall be binding upon and inure to the benefit of the parties and their respective permitted successors and assigns. All headings are for convenience only and shall not affect the meaning of any provision of this Agreement. +* 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. +*/ + +package org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics; + +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.CallableStatus; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.IntervalStatistics; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.ThresHolder; + +/** + * Created with IntelliJ IDEA. + * User: carneiro + * Date: 4/20/13 + * Time: 11:30 PM + * To change this template use File | Settings | File Templates. + */ +public interface Interval { + public void initialize(ThresHolder thresholds); + public CallableStatus status (IntervalStatistics intervalStatistics); +} diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/Locus.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/Locus.java new file mode 100644 index 000000000..aee41846b --- /dev/null +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/Locus.java @@ -0,0 +1,65 @@ +/* +* By downloading the PROGRAM you agree to the following terms of use: +* +* BROAD INSTITUTE - SOFTWARE LICENSE AGREEMENT - FOR ACADEMIC NON-COMMERCIAL RESEARCH PURPOSES ONLY +* +* This Agreement is made between the Broad Institute, Inc. with a principal address at 7 Cambridge Center, Cambridge, MA 02142 (BROAD) and the LICENSEE and is effective at the date the downloading is completed (EFFECTIVE DATE). +* +* WHEREAS, LICENSEE desires to license the PROGRAM, as defined hereinafter, and BROAD wishes to have this PROGRAM utilized in the public interest, subject only to the royalty-free, nonexclusive, nontransferable license rights of the United States Government pursuant to 48 CFR 52.227-14; and +* WHEREAS, LICENSEE desires to license the PROGRAM and BROAD desires to grant a license on the following terms and conditions. +* NOW, THEREFORE, in consideration of the promises and covenants made herein, the parties hereto agree as follows: +* +* 1. DEFINITIONS +* 1.1 PROGRAM shall mean copyright in the object code and source code known as GATK2 and related documentation, if any, as they exist on the EFFECTIVE DATE and can be downloaded from http://www.broadinstitute/GATK on the EFFECTIVE DATE. +* +* 2. LICENSE +* 2.1 Grant. Subject to the terms of this Agreement, BROAD hereby grants to LICENSEE, solely for academic non-commercial research purposes, a non-exclusive, non-transferable license to: (a) download, execute and display the PROGRAM and (b) create bug fixes and modify the PROGRAM. +* The LICENSEE may apply the PROGRAM in a pipeline to data owned by users other than the LICENSEE and provide these users the results of the PROGRAM provided LICENSEE does so for academic non-commercial purposes only. For clarification purposes, academic sponsored research is not a commercial use under the terms of this Agreement. +* 2.2 No Sublicensing or Additional Rights. LICENSEE shall not sublicense or distribute the PROGRAM, in whole or in part, without prior written permission from BROAD. LICENSEE shall ensure that all of its users agree to the terms of this Agreement. LICENSEE further agrees that it shall not put the PROGRAM on a network, server, or other similar technology that may be accessed by anyone other than the LICENSEE and its employees and users who have agreed to the terms of this agreement. +* 2.3 License Limitations. Nothing in this Agreement shall be construed to confer any rights upon LICENSEE by implication, estoppel, or otherwise to any computer software, trademark, intellectual property, or patent rights of BROAD, or of any other entity, except as expressly granted herein. LICENSEE agrees that the PROGRAM, in whole or part, shall not be used for any commercial purpose, including without limitation, as the basis of a commercial software or hardware product or to provide services. LICENSEE further agrees that the PROGRAM shall not be copied or otherwise adapted in order to circumvent the need for obtaining a license for use of the PROGRAM. +* +* 3. OWNERSHIP OF INTELLECTUAL PROPERTY +* LICENSEE acknowledges that title to the PROGRAM shall remain with BROAD. The PROGRAM is marked with the following BROAD copyright notice and notice of attribution to contributors. LICENSEE shall retain such notice on all copies. LICENSEE agrees to include appropriate attribution if any results obtained from use of the PROGRAM are included in any publication. +* Copyright 2012 Broad Institute, Inc. +* Notice of attribution: The GATK2 program was made available through the generosity of Medical and Population Genetics program at the Broad Institute, Inc. +* LICENSEE shall not use any trademark or trade name of BROAD, or any variation, adaptation, or abbreviation, of such marks or trade names, or any names of officers, faculty, students, employees, or agents of BROAD except as states above for attribution purposes. +* +* 4. INDEMNIFICATION +* LICENSEE shall indemnify, defend, and hold harmless BROAD, and their respective officers, faculty, students, employees, associated investigators and agents, and their respective successors, heirs and assigns, (Indemnitees), against any liability, damage, loss, or expense (including reasonable attorneys fees and expenses) incurred by or imposed upon any of the Indemnitees in connection with any claims, suits, actions, demands or judgments arising out of any theory of liability (including, without limitation, actions in the form of tort, warranty, or strict liability and regardless of whether such action has any factual basis) pursuant to any right or license granted under this Agreement. +* +* 5. NO REPRESENTATIONS OR WARRANTIES +* THE PROGRAM IS DELIVERED AS IS. BROAD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE PROGRAM OR THE COPYRIGHT, EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, WHETHER OR NOT DISCOVERABLE. BROAD EXTENDS NO WARRANTIES OF ANY KIND AS TO PROGRAM CONFORMITY WITH WHATEVER USER MANUALS OR OTHER LITERATURE MAY BE ISSUED FROM TIME TO TIME. +* IN NO EVENT SHALL BROAD OR ITS RESPECTIVE DIRECTORS, OFFICERS, EMPLOYEES, AFFILIATED INVESTIGATORS AND AFFILIATES BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING, WITHOUT LIMITATION, ECONOMIC DAMAGES OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER BROAD SHALL BE ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT SHALL KNOW OF THE POSSIBILITY OF THE FOREGOING. +* +* 6. ASSIGNMENT +* This Agreement is personal to LICENSEE and any rights or obligations assigned by LICENSEE without the prior written consent of BROAD shall be null and void. +* +* 7. MISCELLANEOUS +* 7.1 Export Control. LICENSEE gives assurance that it will comply with all United States export control laws and regulations controlling the export of the PROGRAM, including, without limitation, all Export Administration Regulations of the United States Department of Commerce. Among other things, these laws and regulations prohibit, or require a license for, the export of certain types of software to specified countries. +* 7.2 Termination. LICENSEE shall have the right to terminate this Agreement for any reason upon prior written notice to BROAD. If LICENSEE breaches any provision hereunder, and fails to cure such breach within thirty (30) days, BROAD may terminate this Agreement immediately. Upon termination, LICENSEE shall provide BROAD with written assurance that the original and all copies of the PROGRAM have been destroyed, except that, upon prior written authorization from BROAD, LICENSEE may retain a copy for archive purposes. +* 7.3 Survival. The following provisions shall survive the expiration or termination of this Agreement: Articles 1, 3, 4, 5 and Sections 2.2, 2.3, 7.3, and 7.4. +* 7.4 Notice. Any notices under this Agreement shall be in writing, shall specifically refer to this Agreement, and shall be sent by hand, recognized national overnight courier, confirmed facsimile transmission, confirmed electronic mail, or registered or certified mail, postage prepaid, return receipt requested. All notices under this Agreement shall be deemed effective upon receipt. +* 7.5 Amendment and Waiver; Entire Agreement. This Agreement may be amended, supplemented, or otherwise modified only by means of a written instrument signed by all parties. Any waiver of any rights or failure to act in a specific instance shall relate only to such instance and shall not be construed as an agreement to waive any rights or fail to act in any other instance, whether or not similar. This Agreement constitutes the entire agreement among the parties with respect to its subject matter and supersedes prior agreements or understandings between the parties relating to its subject matter. +* 7.6 Binding Effect; Headings. This Agreement shall be binding upon and inure to the benefit of the parties and their respective permitted successors and assigns. All headings are for convenience only and shall not affect the meaning of any provision of this Agreement. +* 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. +*/ + +package org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics; + +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.CallableStatus; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.LocusStatistics; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.SampleStatistics; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.ThresHolder; + +/** + * Created with IntelliJ IDEA. + * User: carneiro + * Date: 4/20/13 + * Time: 11:29 PM + * To change this template use File | Settings | File Templates. + */ +public interface Locus { + public void initialize(ThresHolder thresholds); + public CallableStatus status (LocusStatistics locusStatistics); + public CallableStatus sampleStatus (SampleStatistics sampleStatistics); +} diff --git a/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/SampleStatisticsUnitTest.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/LocusCoverageGap.java similarity index 73% rename from protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/SampleStatisticsUnitTest.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/LocusCoverageGap.java index dd9e1d86e..effdd33b0 100644 --- a/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/SampleStatisticsUnitTest.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/LocusCoverageGap.java @@ -44,78 +44,34 @@ * 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. */ -package org.broadinstitute.sting.gatk.walkers.diagnostics.targets; +package org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics; -import net.sf.samtools.SAMFileHeader; -import org.broadinstitute.sting.utils.GenomeLoc; -import org.broadinstitute.sting.utils.sam.ArtificialSAMUtils; -import org.broadinstitute.sting.utils.sam.GATKSAMRecord; -import org.testng.Assert; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.CallableStatus; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.LocusStatistics; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.SampleStatistics; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.ThresHolder; -public class SampleStatisticsUnitTest/* extends BaseTest */ { +/** + * User: carneiro + * Date: 4/20/13 + * Time: 11:44 PM + */ +public class LocusCoverageGap implements Locus { + private double threshold; + private static final CallableStatus CALL = CallableStatus.COVERAGE_GAPS; - @DataProvider(name = "QuartileValues") - public Object[][] getQuantileValues() { - - int[] a1 = {5}; - int[] a2 = {1, 2}; - int[] a5 = {10, 20, 30, 40, 50}; - int[] a10 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - - - return new Object[][]{ - new Object[]{a1, 0.5, 5}, - new Object[]{a1, 0, 5}, - new Object[]{a1, 1, 5}, - new Object[]{a2, 0.5, 1.5}, - new Object[]{a2, 0.25, 1}, - new Object[]{a2, 0.75, 2}, - new Object[]{a5, 0.5, 30}, - new Object[]{a5, 0.25, 20}, - new Object[]{a5, 0.75, 40}, - new Object[]{a5, 0, -1}, - new Object[]{a10, 0.5, 5.5}, - new Object[]{a10, 0.25, 3}, - new Object[]{a10, 0.75, 8} - }; + @Override + public void initialize(ThresHolder thresholds) { + threshold = thresholds.coverageStatusThreshold; } - @Test(dataProvider = "QuartileValues") - public void testGetQuartile(int[] dataList, double percentage, double expected) { - Assert.assertEquals(SampleStatistics.getQuartile(dataList, percentage), expected); - + @Override + public CallableStatus status(LocusStatistics locusStatistics) { + return locusStatistics.getRawCoverage() == 0 ? CALL : null; } - @DataProvider(name = "ReadsAndMates") - public Object[][] getReadAndMates() { - SAMFileHeader header = ArtificialSAMUtils.createArtificialSamHeader(1, 1, 1000); - - GATKSAMRecord noPair = ArtificialSAMUtils.createArtificialRead(header, "test", 0, 100, 50); - GATKSAMRecord good = ArtificialSAMUtils.createPair(header, "test", 30, 100, 150, true, false).get(0); - GATKSAMRecord bigInsertSize = ArtificialSAMUtils.createPair(header, "test", 30, 100, 151, true, false).get(0); -// GATKSAMRecord inverted = ArtificialSAMUtils.createPair(header, "test", 30, 151, 150, true, false).get(0); - GATKSAMRecord sameOrientation = ArtificialSAMUtils.createPair(header, "test", 30, 100, 151, true, true).get(0); - - GATKSAMRecord pairNotMapped = ArtificialSAMUtils.createPair(header, "test", 30, 100, 140, true, false).get(1); - pairNotMapped.setMateUnmappedFlag(true); - - // finish test - return new Object[][]{ - new Object[]{noPair, false}, - new Object[]{good, true}, - new Object[]{bigInsertSize, false}, -// new Object[]{inverted, false}, - new Object[]{sameOrientation, false}, - new Object[]{pairNotMapped, false} - }; + @Override + public CallableStatus sampleStatus(SampleStatistics sampleStatistics) { + return PluginUtils.genericSampleStatus(sampleStatistics, CALL, threshold); } - - @Test(dataProvider = "ReadsAndMates") - public void testHasValidMate(GATKSAMRecord read, boolean expected) { - //50 is out maximum insert size - Assert.assertEquals(new SampleStatistics(GenomeLoc.UNMAPPED).hasValidMate(read, ThresHolder.DEFAULTS), expected); - } - } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/LocusExcessiveCoverage.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/LocusExcessiveCoverage.java new file mode 100644 index 000000000..72709a0f6 --- /dev/null +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/LocusExcessiveCoverage.java @@ -0,0 +1,79 @@ +/* +* By downloading the PROGRAM you agree to the following terms of use: +* +* BROAD INSTITUTE - SOFTWARE LICENSE AGREEMENT - FOR ACADEMIC NON-COMMERCIAL RESEARCH PURPOSES ONLY +* +* This Agreement is made between the Broad Institute, Inc. with a principal address at 7 Cambridge Center, Cambridge, MA 02142 (BROAD) and the LICENSEE and is effective at the date the downloading is completed (EFFECTIVE DATE). +* +* WHEREAS, LICENSEE desires to license the PROGRAM, as defined hereinafter, and BROAD wishes to have this PROGRAM utilized in the public interest, subject only to the royalty-free, nonexclusive, nontransferable license rights of the United States Government pursuant to 48 CFR 52.227-14; and +* WHEREAS, LICENSEE desires to license the PROGRAM and BROAD desires to grant a license on the following terms and conditions. +* NOW, THEREFORE, in consideration of the promises and covenants made herein, the parties hereto agree as follows: +* +* 1. DEFINITIONS +* 1.1 PROGRAM shall mean copyright in the object code and source code known as GATK2 and related documentation, if any, as they exist on the EFFECTIVE DATE and can be downloaded from http://www.broadinstitute/GATK on the EFFECTIVE DATE. +* +* 2. LICENSE +* 2.1 Grant. Subject to the terms of this Agreement, BROAD hereby grants to LICENSEE, solely for academic non-commercial research purposes, a non-exclusive, non-transferable license to: (a) download, execute and display the PROGRAM and (b) create bug fixes and modify the PROGRAM. +* The LICENSEE may apply the PROGRAM in a pipeline to data owned by users other than the LICENSEE and provide these users the results of the PROGRAM provided LICENSEE does so for academic non-commercial purposes only. For clarification purposes, academic sponsored research is not a commercial use under the terms of this Agreement. +* 2.2 No Sublicensing or Additional Rights. LICENSEE shall not sublicense or distribute the PROGRAM, in whole or in part, without prior written permission from BROAD. LICENSEE shall ensure that all of its users agree to the terms of this Agreement. LICENSEE further agrees that it shall not put the PROGRAM on a network, server, or other similar technology that may be accessed by anyone other than the LICENSEE and its employees and users who have agreed to the terms of this agreement. +* 2.3 License Limitations. Nothing in this Agreement shall be construed to confer any rights upon LICENSEE by implication, estoppel, or otherwise to any computer software, trademark, intellectual property, or patent rights of BROAD, or of any other entity, except as expressly granted herein. LICENSEE agrees that the PROGRAM, in whole or part, shall not be used for any commercial purpose, including without limitation, as the basis of a commercial software or hardware product or to provide services. LICENSEE further agrees that the PROGRAM shall not be copied or otherwise adapted in order to circumvent the need for obtaining a license for use of the PROGRAM. +* +* 3. OWNERSHIP OF INTELLECTUAL PROPERTY +* LICENSEE acknowledges that title to the PROGRAM shall remain with BROAD. The PROGRAM is marked with the following BROAD copyright notice and notice of attribution to contributors. LICENSEE shall retain such notice on all copies. LICENSEE agrees to include appropriate attribution if any results obtained from use of the PROGRAM are included in any publication. +* Copyright 2012 Broad Institute, Inc. +* Notice of attribution: The GATK2 program was made available through the generosity of Medical and Population Genetics program at the Broad Institute, Inc. +* LICENSEE shall not use any trademark or trade name of BROAD, or any variation, adaptation, or abbreviation, of such marks or trade names, or any names of officers, faculty, students, employees, or agents of BROAD except as states above for attribution purposes. +* +* 4. INDEMNIFICATION +* LICENSEE shall indemnify, defend, and hold harmless BROAD, and their respective officers, faculty, students, employees, associated investigators and agents, and their respective successors, heirs and assigns, (Indemnitees), against any liability, damage, loss, or expense (including reasonable attorneys fees and expenses) incurred by or imposed upon any of the Indemnitees in connection with any claims, suits, actions, demands or judgments arising out of any theory of liability (including, without limitation, actions in the form of tort, warranty, or strict liability and regardless of whether such action has any factual basis) pursuant to any right or license granted under this Agreement. +* +* 5. NO REPRESENTATIONS OR WARRANTIES +* THE PROGRAM IS DELIVERED AS IS. BROAD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE PROGRAM OR THE COPYRIGHT, EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, WHETHER OR NOT DISCOVERABLE. BROAD EXTENDS NO WARRANTIES OF ANY KIND AS TO PROGRAM CONFORMITY WITH WHATEVER USER MANUALS OR OTHER LITERATURE MAY BE ISSUED FROM TIME TO TIME. +* IN NO EVENT SHALL BROAD OR ITS RESPECTIVE DIRECTORS, OFFICERS, EMPLOYEES, AFFILIATED INVESTIGATORS AND AFFILIATES BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING, WITHOUT LIMITATION, ECONOMIC DAMAGES OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER BROAD SHALL BE ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT SHALL KNOW OF THE POSSIBILITY OF THE FOREGOING. +* +* 6. ASSIGNMENT +* This Agreement is personal to LICENSEE and any rights or obligations assigned by LICENSEE without the prior written consent of BROAD shall be null and void. +* +* 7. MISCELLANEOUS +* 7.1 Export Control. LICENSEE gives assurance that it will comply with all United States export control laws and regulations controlling the export of the PROGRAM, including, without limitation, all Export Administration Regulations of the United States Department of Commerce. Among other things, these laws and regulations prohibit, or require a license for, the export of certain types of software to specified countries. +* 7.2 Termination. LICENSEE shall have the right to terminate this Agreement for any reason upon prior written notice to BROAD. If LICENSEE breaches any provision hereunder, and fails to cure such breach within thirty (30) days, BROAD may terminate this Agreement immediately. Upon termination, LICENSEE shall provide BROAD with written assurance that the original and all copies of the PROGRAM have been destroyed, except that, upon prior written authorization from BROAD, LICENSEE may retain a copy for archive purposes. +* 7.3 Survival. The following provisions shall survive the expiration or termination of this Agreement: Articles 1, 3, 4, 5 and Sections 2.2, 2.3, 7.3, and 7.4. +* 7.4 Notice. Any notices under this Agreement shall be in writing, shall specifically refer to this Agreement, and shall be sent by hand, recognized national overnight courier, confirmed facsimile transmission, confirmed electronic mail, or registered or certified mail, postage prepaid, return receipt requested. All notices under this Agreement shall be deemed effective upon receipt. +* 7.5 Amendment and Waiver; Entire Agreement. This Agreement may be amended, supplemented, or otherwise modified only by means of a written instrument signed by all parties. Any waiver of any rights or failure to act in a specific instance shall relate only to such instance and shall not be construed as an agreement to waive any rights or fail to act in any other instance, whether or not similar. This Agreement constitutes the entire agreement among the parties with respect to its subject matter and supersedes prior agreements or understandings between the parties relating to its subject matter. +* 7.6 Binding Effect; Headings. This Agreement shall be binding upon and inure to the benefit of the parties and their respective permitted successors and assigns. All headings are for convenience only and shall not affect the meaning of any provision of this Agreement. +* 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. +*/ + +package org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics; + +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.CallableStatus; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.LocusStatistics; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.SampleStatistics; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.ThresHolder; + +/** + * User: carneiro + * Date: 4/20/13 + * Time: 11:44 PM + */ +public class LocusExcessiveCoverage implements Locus { + private int excessiveCoverage; + private double threshold; + private static final CallableStatus CALL = CallableStatus.EXCESSIVE_COVERAGE ; + + @Override + public void initialize(ThresHolder thresholds) { + this.excessiveCoverage = thresholds.maximumCoverage; + this.threshold = thresholds.coverageStatusThreshold; + } + + @Override + public CallableStatus status(LocusStatistics locusStatistics) { + return locusStatistics.getCoverage() > excessiveCoverage ? CALL : null; + } + + @Override + public CallableStatus sampleStatus(SampleStatistics sampleStatistics) { + return PluginUtils.genericSampleStatus(sampleStatistics, CALL, threshold); + } +} diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/LocusLowCoverage.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/LocusLowCoverage.java new file mode 100644 index 000000000..f3f181bd1 --- /dev/null +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/LocusLowCoverage.java @@ -0,0 +1,80 @@ +/* +* By downloading the PROGRAM you agree to the following terms of use: +* +* BROAD INSTITUTE - SOFTWARE LICENSE AGREEMENT - FOR ACADEMIC NON-COMMERCIAL RESEARCH PURPOSES ONLY +* +* This Agreement is made between the Broad Institute, Inc. with a principal address at 7 Cambridge Center, Cambridge, MA 02142 (BROAD) and the LICENSEE and is effective at the date the downloading is completed (EFFECTIVE DATE). +* +* WHEREAS, LICENSEE desires to license the PROGRAM, as defined hereinafter, and BROAD wishes to have this PROGRAM utilized in the public interest, subject only to the royalty-free, nonexclusive, nontransferable license rights of the United States Government pursuant to 48 CFR 52.227-14; and +* WHEREAS, LICENSEE desires to license the PROGRAM and BROAD desires to grant a license on the following terms and conditions. +* NOW, THEREFORE, in consideration of the promises and covenants made herein, the parties hereto agree as follows: +* +* 1. DEFINITIONS +* 1.1 PROGRAM shall mean copyright in the object code and source code known as GATK2 and related documentation, if any, as they exist on the EFFECTIVE DATE and can be downloaded from http://www.broadinstitute/GATK on the EFFECTIVE DATE. +* +* 2. LICENSE +* 2.1 Grant. Subject to the terms of this Agreement, BROAD hereby grants to LICENSEE, solely for academic non-commercial research purposes, a non-exclusive, non-transferable license to: (a) download, execute and display the PROGRAM and (b) create bug fixes and modify the PROGRAM. +* The LICENSEE may apply the PROGRAM in a pipeline to data owned by users other than the LICENSEE and provide these users the results of the PROGRAM provided LICENSEE does so for academic non-commercial purposes only. For clarification purposes, academic sponsored research is not a commercial use under the terms of this Agreement. +* 2.2 No Sublicensing or Additional Rights. LICENSEE shall not sublicense or distribute the PROGRAM, in whole or in part, without prior written permission from BROAD. LICENSEE shall ensure that all of its users agree to the terms of this Agreement. LICENSEE further agrees that it shall not put the PROGRAM on a network, server, or other similar technology that may be accessed by anyone other than the LICENSEE and its employees and users who have agreed to the terms of this agreement. +* 2.3 License Limitations. Nothing in this Agreement shall be construed to confer any rights upon LICENSEE by implication, estoppel, or otherwise to any computer software, trademark, intellectual property, or patent rights of BROAD, or of any other entity, except as expressly granted herein. LICENSEE agrees that the PROGRAM, in whole or part, shall not be used for any commercial purpose, including without limitation, as the basis of a commercial software or hardware product or to provide services. LICENSEE further agrees that the PROGRAM shall not be copied or otherwise adapted in order to circumvent the need for obtaining a license for use of the PROGRAM. +* +* 3. OWNERSHIP OF INTELLECTUAL PROPERTY +* LICENSEE acknowledges that title to the PROGRAM shall remain with BROAD. The PROGRAM is marked with the following BROAD copyright notice and notice of attribution to contributors. LICENSEE shall retain such notice on all copies. LICENSEE agrees to include appropriate attribution if any results obtained from use of the PROGRAM are included in any publication. +* Copyright 2012 Broad Institute, Inc. +* Notice of attribution: The GATK2 program was made available through the generosity of Medical and Population Genetics program at the Broad Institute, Inc. +* LICENSEE shall not use any trademark or trade name of BROAD, or any variation, adaptation, or abbreviation, of such marks or trade names, or any names of officers, faculty, students, employees, or agents of BROAD except as states above for attribution purposes. +* +* 4. INDEMNIFICATION +* LICENSEE shall indemnify, defend, and hold harmless BROAD, and their respective officers, faculty, students, employees, associated investigators and agents, and their respective successors, heirs and assigns, (Indemnitees), against any liability, damage, loss, or expense (including reasonable attorneys fees and expenses) incurred by or imposed upon any of the Indemnitees in connection with any claims, suits, actions, demands or judgments arising out of any theory of liability (including, without limitation, actions in the form of tort, warranty, or strict liability and regardless of whether such action has any factual basis) pursuant to any right or license granted under this Agreement. +* +* 5. NO REPRESENTATIONS OR WARRANTIES +* THE PROGRAM IS DELIVERED AS IS. BROAD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE PROGRAM OR THE COPYRIGHT, EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, WHETHER OR NOT DISCOVERABLE. BROAD EXTENDS NO WARRANTIES OF ANY KIND AS TO PROGRAM CONFORMITY WITH WHATEVER USER MANUALS OR OTHER LITERATURE MAY BE ISSUED FROM TIME TO TIME. +* IN NO EVENT SHALL BROAD OR ITS RESPECTIVE DIRECTORS, OFFICERS, EMPLOYEES, AFFILIATED INVESTIGATORS AND AFFILIATES BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING, WITHOUT LIMITATION, ECONOMIC DAMAGES OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER BROAD SHALL BE ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT SHALL KNOW OF THE POSSIBILITY OF THE FOREGOING. +* +* 6. ASSIGNMENT +* This Agreement is personal to LICENSEE and any rights or obligations assigned by LICENSEE without the prior written consent of BROAD shall be null and void. +* +* 7. MISCELLANEOUS +* 7.1 Export Control. LICENSEE gives assurance that it will comply with all United States export control laws and regulations controlling the export of the PROGRAM, including, without limitation, all Export Administration Regulations of the United States Department of Commerce. Among other things, these laws and regulations prohibit, or require a license for, the export of certain types of software to specified countries. +* 7.2 Termination. LICENSEE shall have the right to terminate this Agreement for any reason upon prior written notice to BROAD. If LICENSEE breaches any provision hereunder, and fails to cure such breach within thirty (30) days, BROAD may terminate this Agreement immediately. Upon termination, LICENSEE shall provide BROAD with written assurance that the original and all copies of the PROGRAM have been destroyed, except that, upon prior written authorization from BROAD, LICENSEE may retain a copy for archive purposes. +* 7.3 Survival. The following provisions shall survive the expiration or termination of this Agreement: Articles 1, 3, 4, 5 and Sections 2.2, 2.3, 7.3, and 7.4. +* 7.4 Notice. Any notices under this Agreement shall be in writing, shall specifically refer to this Agreement, and shall be sent by hand, recognized national overnight courier, confirmed facsimile transmission, confirmed electronic mail, or registered or certified mail, postage prepaid, return receipt requested. All notices under this Agreement shall be deemed effective upon receipt. +* 7.5 Amendment and Waiver; Entire Agreement. This Agreement may be amended, supplemented, or otherwise modified only by means of a written instrument signed by all parties. Any waiver of any rights or failure to act in a specific instance shall relate only to such instance and shall not be construed as an agreement to waive any rights or fail to act in any other instance, whether or not similar. This Agreement constitutes the entire agreement among the parties with respect to its subject matter and supersedes prior agreements or understandings between the parties relating to its subject matter. +* 7.6 Binding Effect; Headings. This Agreement shall be binding upon and inure to the benefit of the parties and their respective permitted successors and assigns. All headings are for convenience only and shall not affect the meaning of any provision of this Agreement. +* 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. +*/ + +package org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics; + +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.CallableStatus; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.LocusStatistics; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.SampleStatistics; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.ThresHolder; + +/** + * User: carneiro + * Date: 4/20/13 + * Time: 11:44 PM + */ +public class LocusLowCoverage implements Locus { + private int minCoverage; + private double threshold; + private static final CallableStatus CALL = CallableStatus.LOW_COVERAGE ; + + @Override + public void initialize(ThresHolder thresholds) { + this.minCoverage = thresholds.minimumCoverage; + this.threshold = thresholds.coverageStatusThreshold; + } + + @Override + public CallableStatus status(LocusStatistics locusStatistics) { + final int raw = locusStatistics.getRawCoverage(); + return raw > 0 && raw < minCoverage ? CALL: null; + } + + @Override + public CallableStatus sampleStatus(SampleStatistics sampleStatistics) { + return PluginUtils.genericSampleStatus(sampleStatistics, CALL, threshold); + } +} diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/LocusPoorQuality.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/LocusPoorQuality.java new file mode 100644 index 000000000..91d5f8c04 --- /dev/null +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/LocusPoorQuality.java @@ -0,0 +1,79 @@ +/* +* By downloading the PROGRAM you agree to the following terms of use: +* +* BROAD INSTITUTE - SOFTWARE LICENSE AGREEMENT - FOR ACADEMIC NON-COMMERCIAL RESEARCH PURPOSES ONLY +* +* This Agreement is made between the Broad Institute, Inc. with a principal address at 7 Cambridge Center, Cambridge, MA 02142 (BROAD) and the LICENSEE and is effective at the date the downloading is completed (EFFECTIVE DATE). +* +* WHEREAS, LICENSEE desires to license the PROGRAM, as defined hereinafter, and BROAD wishes to have this PROGRAM utilized in the public interest, subject only to the royalty-free, nonexclusive, nontransferable license rights of the United States Government pursuant to 48 CFR 52.227-14; and +* WHEREAS, LICENSEE desires to license the PROGRAM and BROAD desires to grant a license on the following terms and conditions. +* NOW, THEREFORE, in consideration of the promises and covenants made herein, the parties hereto agree as follows: +* +* 1. DEFINITIONS +* 1.1 PROGRAM shall mean copyright in the object code and source code known as GATK2 and related documentation, if any, as they exist on the EFFECTIVE DATE and can be downloaded from http://www.broadinstitute/GATK on the EFFECTIVE DATE. +* +* 2. LICENSE +* 2.1 Grant. Subject to the terms of this Agreement, BROAD hereby grants to LICENSEE, solely for academic non-commercial research purposes, a non-exclusive, non-transferable license to: (a) download, execute and display the PROGRAM and (b) create bug fixes and modify the PROGRAM. +* The LICENSEE may apply the PROGRAM in a pipeline to data owned by users other than the LICENSEE and provide these users the results of the PROGRAM provided LICENSEE does so for academic non-commercial purposes only. For clarification purposes, academic sponsored research is not a commercial use under the terms of this Agreement. +* 2.2 No Sublicensing or Additional Rights. LICENSEE shall not sublicense or distribute the PROGRAM, in whole or in part, without prior written permission from BROAD. LICENSEE shall ensure that all of its users agree to the terms of this Agreement. LICENSEE further agrees that it shall not put the PROGRAM on a network, server, or other similar technology that may be accessed by anyone other than the LICENSEE and its employees and users who have agreed to the terms of this agreement. +* 2.3 License Limitations. Nothing in this Agreement shall be construed to confer any rights upon LICENSEE by implication, estoppel, or otherwise to any computer software, trademark, intellectual property, or patent rights of BROAD, or of any other entity, except as expressly granted herein. LICENSEE agrees that the PROGRAM, in whole or part, shall not be used for any commercial purpose, including without limitation, as the basis of a commercial software or hardware product or to provide services. LICENSEE further agrees that the PROGRAM shall not be copied or otherwise adapted in order to circumvent the need for obtaining a license for use of the PROGRAM. +* +* 3. OWNERSHIP OF INTELLECTUAL PROPERTY +* LICENSEE acknowledges that title to the PROGRAM shall remain with BROAD. The PROGRAM is marked with the following BROAD copyright notice and notice of attribution to contributors. LICENSEE shall retain such notice on all copies. LICENSEE agrees to include appropriate attribution if any results obtained from use of the PROGRAM are included in any publication. +* Copyright 2012 Broad Institute, Inc. +* Notice of attribution: The GATK2 program was made available through the generosity of Medical and Population Genetics program at the Broad Institute, Inc. +* LICENSEE shall not use any trademark or trade name of BROAD, or any variation, adaptation, or abbreviation, of such marks or trade names, or any names of officers, faculty, students, employees, or agents of BROAD except as states above for attribution purposes. +* +* 4. INDEMNIFICATION +* LICENSEE shall indemnify, defend, and hold harmless BROAD, and their respective officers, faculty, students, employees, associated investigators and agents, and their respective successors, heirs and assigns, (Indemnitees), against any liability, damage, loss, or expense (including reasonable attorneys fees and expenses) incurred by or imposed upon any of the Indemnitees in connection with any claims, suits, actions, demands or judgments arising out of any theory of liability (including, without limitation, actions in the form of tort, warranty, or strict liability and regardless of whether such action has any factual basis) pursuant to any right or license granted under this Agreement. +* +* 5. NO REPRESENTATIONS OR WARRANTIES +* THE PROGRAM IS DELIVERED AS IS. BROAD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE PROGRAM OR THE COPYRIGHT, EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, WHETHER OR NOT DISCOVERABLE. BROAD EXTENDS NO WARRANTIES OF ANY KIND AS TO PROGRAM CONFORMITY WITH WHATEVER USER MANUALS OR OTHER LITERATURE MAY BE ISSUED FROM TIME TO TIME. +* IN NO EVENT SHALL BROAD OR ITS RESPECTIVE DIRECTORS, OFFICERS, EMPLOYEES, AFFILIATED INVESTIGATORS AND AFFILIATES BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING, WITHOUT LIMITATION, ECONOMIC DAMAGES OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER BROAD SHALL BE ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT SHALL KNOW OF THE POSSIBILITY OF THE FOREGOING. +* +* 6. ASSIGNMENT +* This Agreement is personal to LICENSEE and any rights or obligations assigned by LICENSEE without the prior written consent of BROAD shall be null and void. +* +* 7. MISCELLANEOUS +* 7.1 Export Control. LICENSEE gives assurance that it will comply with all United States export control laws and regulations controlling the export of the PROGRAM, including, without limitation, all Export Administration Regulations of the United States Department of Commerce. Among other things, these laws and regulations prohibit, or require a license for, the export of certain types of software to specified countries. +* 7.2 Termination. LICENSEE shall have the right to terminate this Agreement for any reason upon prior written notice to BROAD. If LICENSEE breaches any provision hereunder, and fails to cure such breach within thirty (30) days, BROAD may terminate this Agreement immediately. Upon termination, LICENSEE shall provide BROAD with written assurance that the original and all copies of the PROGRAM have been destroyed, except that, upon prior written authorization from BROAD, LICENSEE may retain a copy for archive purposes. +* 7.3 Survival. The following provisions shall survive the expiration or termination of this Agreement: Articles 1, 3, 4, 5 and Sections 2.2, 2.3, 7.3, and 7.4. +* 7.4 Notice. Any notices under this Agreement shall be in writing, shall specifically refer to this Agreement, and shall be sent by hand, recognized national overnight courier, confirmed facsimile transmission, confirmed electronic mail, or registered or certified mail, postage prepaid, return receipt requested. All notices under this Agreement shall be deemed effective upon receipt. +* 7.5 Amendment and Waiver; Entire Agreement. This Agreement may be amended, supplemented, or otherwise modified only by means of a written instrument signed by all parties. Any waiver of any rights or failure to act in a specific instance shall relate only to such instance and shall not be construed as an agreement to waive any rights or fail to act in any other instance, whether or not similar. This Agreement constitutes the entire agreement among the parties with respect to its subject matter and supersedes prior agreements or understandings between the parties relating to its subject matter. +* 7.6 Binding Effect; Headings. This Agreement shall be binding upon and inure to the benefit of the parties and their respective permitted successors and assigns. All headings are for convenience only and shall not affect the meaning of any provision of this Agreement. +* 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. +*/ + +package org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics; + +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.CallableStatus; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.LocusStatistics; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.SampleStatistics; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.ThresHolder; + +/** + * User: carneiro + * Date: 4/20/13 + * Time: 11:44 PM + */ +public class LocusPoorQuality implements Locus { + private int minCoverage; + private double threshold; + private static final CallableStatus CALL = CallableStatus.POOR_QUALITY ; + + @Override + public void initialize(ThresHolder thresholds) { + this.minCoverage = thresholds.minimumCoverage; + this.threshold = thresholds.coverageStatusThreshold; + } + + @Override + public CallableStatus status(LocusStatistics locusStatistics) { + return locusStatistics.getCoverage() < minCoverage && locusStatistics.getRawCoverage() >= minCoverage ? CALL: null; + } + + @Override + public CallableStatus sampleStatus(SampleStatistics sampleStatistics) { + return PluginUtils.genericSampleStatus(sampleStatistics, CALL, threshold); + } +} diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/PluginUtils.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/PluginUtils.java new file mode 100644 index 000000000..0a29aea4d --- /dev/null +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/PluginUtils.java @@ -0,0 +1,66 @@ +/* +* By downloading the PROGRAM you agree to the following terms of use: +* +* BROAD INSTITUTE - SOFTWARE LICENSE AGREEMENT - FOR ACADEMIC NON-COMMERCIAL RESEARCH PURPOSES ONLY +* +* This Agreement is made between the Broad Institute, Inc. with a principal address at 7 Cambridge Center, Cambridge, MA 02142 (BROAD) and the LICENSEE and is effective at the date the downloading is completed (EFFECTIVE DATE). +* +* WHEREAS, LICENSEE desires to license the PROGRAM, as defined hereinafter, and BROAD wishes to have this PROGRAM utilized in the public interest, subject only to the royalty-free, nonexclusive, nontransferable license rights of the United States Government pursuant to 48 CFR 52.227-14; and +* WHEREAS, LICENSEE desires to license the PROGRAM and BROAD desires to grant a license on the following terms and conditions. +* NOW, THEREFORE, in consideration of the promises and covenants made herein, the parties hereto agree as follows: +* +* 1. DEFINITIONS +* 1.1 PROGRAM shall mean copyright in the object code and source code known as GATK2 and related documentation, if any, as they exist on the EFFECTIVE DATE and can be downloaded from http://www.broadinstitute/GATK on the EFFECTIVE DATE. +* +* 2. LICENSE +* 2.1 Grant. Subject to the terms of this Agreement, BROAD hereby grants to LICENSEE, solely for academic non-commercial research purposes, a non-exclusive, non-transferable license to: (a) download, execute and display the PROGRAM and (b) create bug fixes and modify the PROGRAM. +* The LICENSEE may apply the PROGRAM in a pipeline to data owned by users other than the LICENSEE and provide these users the results of the PROGRAM provided LICENSEE does so for academic non-commercial purposes only. For clarification purposes, academic sponsored research is not a commercial use under the terms of this Agreement. +* 2.2 No Sublicensing or Additional Rights. LICENSEE shall not sublicense or distribute the PROGRAM, in whole or in part, without prior written permission from BROAD. LICENSEE shall ensure that all of its users agree to the terms of this Agreement. LICENSEE further agrees that it shall not put the PROGRAM on a network, server, or other similar technology that may be accessed by anyone other than the LICENSEE and its employees and users who have agreed to the terms of this agreement. +* 2.3 License Limitations. Nothing in this Agreement shall be construed to confer any rights upon LICENSEE by implication, estoppel, or otherwise to any computer software, trademark, intellectual property, or patent rights of BROAD, or of any other entity, except as expressly granted herein. LICENSEE agrees that the PROGRAM, in whole or part, shall not be used for any commercial purpose, including without limitation, as the basis of a commercial software or hardware product or to provide services. LICENSEE further agrees that the PROGRAM shall not be copied or otherwise adapted in order to circumvent the need for obtaining a license for use of the PROGRAM. +* +* 3. OWNERSHIP OF INTELLECTUAL PROPERTY +* LICENSEE acknowledges that title to the PROGRAM shall remain with BROAD. The PROGRAM is marked with the following BROAD copyright notice and notice of attribution to contributors. LICENSEE shall retain such notice on all copies. LICENSEE agrees to include appropriate attribution if any results obtained from use of the PROGRAM are included in any publication. +* Copyright 2012 Broad Institute, Inc. +* Notice of attribution: The GATK2 program was made available through the generosity of Medical and Population Genetics program at the Broad Institute, Inc. +* LICENSEE shall not use any trademark or trade name of BROAD, or any variation, adaptation, or abbreviation, of such marks or trade names, or any names of officers, faculty, students, employees, or agents of BROAD except as states above for attribution purposes. +* +* 4. INDEMNIFICATION +* LICENSEE shall indemnify, defend, and hold harmless BROAD, and their respective officers, faculty, students, employees, associated investigators and agents, and their respective successors, heirs and assigns, (Indemnitees), against any liability, damage, loss, or expense (including reasonable attorneys fees and expenses) incurred by or imposed upon any of the Indemnitees in connection with any claims, suits, actions, demands or judgments arising out of any theory of liability (including, without limitation, actions in the form of tort, warranty, or strict liability and regardless of whether such action has any factual basis) pursuant to any right or license granted under this Agreement. +* +* 5. NO REPRESENTATIONS OR WARRANTIES +* THE PROGRAM IS DELIVERED AS IS. BROAD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE PROGRAM OR THE COPYRIGHT, EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, WHETHER OR NOT DISCOVERABLE. BROAD EXTENDS NO WARRANTIES OF ANY KIND AS TO PROGRAM CONFORMITY WITH WHATEVER USER MANUALS OR OTHER LITERATURE MAY BE ISSUED FROM TIME TO TIME. +* IN NO EVENT SHALL BROAD OR ITS RESPECTIVE DIRECTORS, OFFICERS, EMPLOYEES, AFFILIATED INVESTIGATORS AND AFFILIATES BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING, WITHOUT LIMITATION, ECONOMIC DAMAGES OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER BROAD SHALL BE ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT SHALL KNOW OF THE POSSIBILITY OF THE FOREGOING. +* +* 6. ASSIGNMENT +* This Agreement is personal to LICENSEE and any rights or obligations assigned by LICENSEE without the prior written consent of BROAD shall be null and void. +* +* 7. MISCELLANEOUS +* 7.1 Export Control. LICENSEE gives assurance that it will comply with all United States export control laws and regulations controlling the export of the PROGRAM, including, without limitation, all Export Administration Regulations of the United States Department of Commerce. Among other things, these laws and regulations prohibit, or require a license for, the export of certain types of software to specified countries. +* 7.2 Termination. LICENSEE shall have the right to terminate this Agreement for any reason upon prior written notice to BROAD. If LICENSEE breaches any provision hereunder, and fails to cure such breach within thirty (30) days, BROAD may terminate this Agreement immediately. Upon termination, LICENSEE shall provide BROAD with written assurance that the original and all copies of the PROGRAM have been destroyed, except that, upon prior written authorization from BROAD, LICENSEE may retain a copy for archive purposes. +* 7.3 Survival. The following provisions shall survive the expiration or termination of this Agreement: Articles 1, 3, 4, 5 and Sections 2.2, 2.3, 7.3, and 7.4. +* 7.4 Notice. Any notices under this Agreement shall be in writing, shall specifically refer to this Agreement, and shall be sent by hand, recognized national overnight courier, confirmed facsimile transmission, confirmed electronic mail, or registered or certified mail, postage prepaid, return receipt requested. All notices under this Agreement shall be deemed effective upon receipt. +* 7.5 Amendment and Waiver; Entire Agreement. This Agreement may be amended, supplemented, or otherwise modified only by means of a written instrument signed by all parties. Any waiver of any rights or failure to act in a specific instance shall relate only to such instance and shall not be construed as an agreement to waive any rights or fail to act in any other instance, whether or not similar. This Agreement constitutes the entire agreement among the parties with respect to its subject matter and supersedes prior agreements or understandings between the parties relating to its subject matter. +* 7.6 Binding Effect; Headings. This Agreement shall be binding upon and inure to the benefit of the parties and their respective permitted successors and assigns. All headings are for convenience only and shall not affect the meaning of any provision of this Agreement. +* 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. +*/ + +package org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics; + +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.CallableStatus; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.SampleStatistics; + +import java.util.Map; + +/** + * User: carneiro + * Date: 4/21/13 + * Time: 11:23 AM + */ +public class PluginUtils { + public static CallableStatus genericSampleStatus (final SampleStatistics sampleStatistics, final CallableStatus CALL, final double threshold) { + final Map totals = sampleStatistics.getLocusStatusTally(); + final int size = sampleStatistics.getIntervalSize(); + final int statusCount = totals.containsKey(CALL) ? totals.get(CALL) : 0; + return ( (double) statusCount / size) >= threshold ? CALL: null; + } +} diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/Sample.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/Sample.java new file mode 100644 index 000000000..a33c33877 --- /dev/null +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/Sample.java @@ -0,0 +1,63 @@ +/* +* By downloading the PROGRAM you agree to the following terms of use: +* +* BROAD INSTITUTE - SOFTWARE LICENSE AGREEMENT - FOR ACADEMIC NON-COMMERCIAL RESEARCH PURPOSES ONLY +* +* This Agreement is made between the Broad Institute, Inc. with a principal address at 7 Cambridge Center, Cambridge, MA 02142 (BROAD) and the LICENSEE and is effective at the date the downloading is completed (EFFECTIVE DATE). +* +* WHEREAS, LICENSEE desires to license the PROGRAM, as defined hereinafter, and BROAD wishes to have this PROGRAM utilized in the public interest, subject only to the royalty-free, nonexclusive, nontransferable license rights of the United States Government pursuant to 48 CFR 52.227-14; and +* WHEREAS, LICENSEE desires to license the PROGRAM and BROAD desires to grant a license on the following terms and conditions. +* NOW, THEREFORE, in consideration of the promises and covenants made herein, the parties hereto agree as follows: +* +* 1. DEFINITIONS +* 1.1 PROGRAM shall mean copyright in the object code and source code known as GATK2 and related documentation, if any, as they exist on the EFFECTIVE DATE and can be downloaded from http://www.broadinstitute/GATK on the EFFECTIVE DATE. +* +* 2. LICENSE +* 2.1 Grant. Subject to the terms of this Agreement, BROAD hereby grants to LICENSEE, solely for academic non-commercial research purposes, a non-exclusive, non-transferable license to: (a) download, execute and display the PROGRAM and (b) create bug fixes and modify the PROGRAM. +* The LICENSEE may apply the PROGRAM in a pipeline to data owned by users other than the LICENSEE and provide these users the results of the PROGRAM provided LICENSEE does so for academic non-commercial purposes only. For clarification purposes, academic sponsored research is not a commercial use under the terms of this Agreement. +* 2.2 No Sublicensing or Additional Rights. LICENSEE shall not sublicense or distribute the PROGRAM, in whole or in part, without prior written permission from BROAD. LICENSEE shall ensure that all of its users agree to the terms of this Agreement. LICENSEE further agrees that it shall not put the PROGRAM on a network, server, or other similar technology that may be accessed by anyone other than the LICENSEE and its employees and users who have agreed to the terms of this agreement. +* 2.3 License Limitations. Nothing in this Agreement shall be construed to confer any rights upon LICENSEE by implication, estoppel, or otherwise to any computer software, trademark, intellectual property, or patent rights of BROAD, or of any other entity, except as expressly granted herein. LICENSEE agrees that the PROGRAM, in whole or part, shall not be used for any commercial purpose, including without limitation, as the basis of a commercial software or hardware product or to provide services. LICENSEE further agrees that the PROGRAM shall not be copied or otherwise adapted in order to circumvent the need for obtaining a license for use of the PROGRAM. +* +* 3. OWNERSHIP OF INTELLECTUAL PROPERTY +* LICENSEE acknowledges that title to the PROGRAM shall remain with BROAD. The PROGRAM is marked with the following BROAD copyright notice and notice of attribution to contributors. LICENSEE shall retain such notice on all copies. LICENSEE agrees to include appropriate attribution if any results obtained from use of the PROGRAM are included in any publication. +* Copyright 2012 Broad Institute, Inc. +* Notice of attribution: The GATK2 program was made available through the generosity of Medical and Population Genetics program at the Broad Institute, Inc. +* LICENSEE shall not use any trademark or trade name of BROAD, or any variation, adaptation, or abbreviation, of such marks or trade names, or any names of officers, faculty, students, employees, or agents of BROAD except as states above for attribution purposes. +* +* 4. INDEMNIFICATION +* LICENSEE shall indemnify, defend, and hold harmless BROAD, and their respective officers, faculty, students, employees, associated investigators and agents, and their respective successors, heirs and assigns, (Indemnitees), against any liability, damage, loss, or expense (including reasonable attorneys fees and expenses) incurred by or imposed upon any of the Indemnitees in connection with any claims, suits, actions, demands or judgments arising out of any theory of liability (including, without limitation, actions in the form of tort, warranty, or strict liability and regardless of whether such action has any factual basis) pursuant to any right or license granted under this Agreement. +* +* 5. NO REPRESENTATIONS OR WARRANTIES +* THE PROGRAM IS DELIVERED AS IS. BROAD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE PROGRAM OR THE COPYRIGHT, EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, WHETHER OR NOT DISCOVERABLE. BROAD EXTENDS NO WARRANTIES OF ANY KIND AS TO PROGRAM CONFORMITY WITH WHATEVER USER MANUALS OR OTHER LITERATURE MAY BE ISSUED FROM TIME TO TIME. +* IN NO EVENT SHALL BROAD OR ITS RESPECTIVE DIRECTORS, OFFICERS, EMPLOYEES, AFFILIATED INVESTIGATORS AND AFFILIATES BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING, WITHOUT LIMITATION, ECONOMIC DAMAGES OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER BROAD SHALL BE ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT SHALL KNOW OF THE POSSIBILITY OF THE FOREGOING. +* +* 6. ASSIGNMENT +* This Agreement is personal to LICENSEE and any rights or obligations assigned by LICENSEE without the prior written consent of BROAD shall be null and void. +* +* 7. MISCELLANEOUS +* 7.1 Export Control. LICENSEE gives assurance that it will comply with all United States export control laws and regulations controlling the export of the PROGRAM, including, without limitation, all Export Administration Regulations of the United States Department of Commerce. Among other things, these laws and regulations prohibit, or require a license for, the export of certain types of software to specified countries. +* 7.2 Termination. LICENSEE shall have the right to terminate this Agreement for any reason upon prior written notice to BROAD. If LICENSEE breaches any provision hereunder, and fails to cure such breach within thirty (30) days, BROAD may terminate this Agreement immediately. Upon termination, LICENSEE shall provide BROAD with written assurance that the original and all copies of the PROGRAM have been destroyed, except that, upon prior written authorization from BROAD, LICENSEE may retain a copy for archive purposes. +* 7.3 Survival. The following provisions shall survive the expiration or termination of this Agreement: Articles 1, 3, 4, 5 and Sections 2.2, 2.3, 7.3, and 7.4. +* 7.4 Notice. Any notices under this Agreement shall be in writing, shall specifically refer to this Agreement, and shall be sent by hand, recognized national overnight courier, confirmed facsimile transmission, confirmed electronic mail, or registered or certified mail, postage prepaid, return receipt requested. All notices under this Agreement shall be deemed effective upon receipt. +* 7.5 Amendment and Waiver; Entire Agreement. This Agreement may be amended, supplemented, or otherwise modified only by means of a written instrument signed by all parties. Any waiver of any rights or failure to act in a specific instance shall relate only to such instance and shall not be construed as an agreement to waive any rights or fail to act in any other instance, whether or not similar. This Agreement constitutes the entire agreement among the parties with respect to its subject matter and supersedes prior agreements or understandings between the parties relating to its subject matter. +* 7.6 Binding Effect; Headings. This Agreement shall be binding upon and inure to the benefit of the parties and their respective permitted successors and assigns. All headings are for convenience only and shall not affect the meaning of any provision of this Agreement. +* 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. +*/ + +package org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics; + +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.CallableStatus; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.SampleStatistics; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.ThresHolder; + +/** + * Created with IntelliJ IDEA. + * User: carneiro + * Date: 4/20/13 + * Time: 11:30 PM + * To change this template use File | Settings | File Templates. + */ +public interface Sample { + public void initialize(ThresHolder thresholds); + public CallableStatus status (SampleStatistics sampleStatistics); +} diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/SampleBadMates.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/SampleBadMates.java new file mode 100644 index 000000000..07e2cca5a --- /dev/null +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/SampleBadMates.java @@ -0,0 +1,76 @@ +/* +* By downloading the PROGRAM you agree to the following terms of use: +* +* BROAD INSTITUTE - SOFTWARE LICENSE AGREEMENT - FOR ACADEMIC NON-COMMERCIAL RESEARCH PURPOSES ONLY +* +* This Agreement is made between the Broad Institute, Inc. with a principal address at 7 Cambridge Center, Cambridge, MA 02142 (BROAD) and the LICENSEE and is effective at the date the downloading is completed (EFFECTIVE DATE). +* +* WHEREAS, LICENSEE desires to license the PROGRAM, as defined hereinafter, and BROAD wishes to have this PROGRAM utilized in the public interest, subject only to the royalty-free, nonexclusive, nontransferable license rights of the United States Government pursuant to 48 CFR 52.227-14; and +* WHEREAS, LICENSEE desires to license the PROGRAM and BROAD desires to grant a license on the following terms and conditions. +* NOW, THEREFORE, in consideration of the promises and covenants made herein, the parties hereto agree as follows: +* +* 1. DEFINITIONS +* 1.1 PROGRAM shall mean copyright in the object code and source code known as GATK2 and related documentation, if any, as they exist on the EFFECTIVE DATE and can be downloaded from http://www.broadinstitute/GATK on the EFFECTIVE DATE. +* +* 2. LICENSE +* 2.1 Grant. Subject to the terms of this Agreement, BROAD hereby grants to LICENSEE, solely for academic non-commercial research purposes, a non-exclusive, non-transferable license to: (a) download, execute and display the PROGRAM and (b) create bug fixes and modify the PROGRAM. +* The LICENSEE may apply the PROGRAM in a pipeline to data owned by users other than the LICENSEE and provide these users the results of the PROGRAM provided LICENSEE does so for academic non-commercial purposes only. For clarification purposes, academic sponsored research is not a commercial use under the terms of this Agreement. +* 2.2 No Sublicensing or Additional Rights. LICENSEE shall not sublicense or distribute the PROGRAM, in whole or in part, without prior written permission from BROAD. LICENSEE shall ensure that all of its users agree to the terms of this Agreement. LICENSEE further agrees that it shall not put the PROGRAM on a network, server, or other similar technology that may be accessed by anyone other than the LICENSEE and its employees and users who have agreed to the terms of this agreement. +* 2.3 License Limitations. Nothing in this Agreement shall be construed to confer any rights upon LICENSEE by implication, estoppel, or otherwise to any computer software, trademark, intellectual property, or patent rights of BROAD, or of any other entity, except as expressly granted herein. LICENSEE agrees that the PROGRAM, in whole or part, shall not be used for any commercial purpose, including without limitation, as the basis of a commercial software or hardware product or to provide services. LICENSEE further agrees that the PROGRAM shall not be copied or otherwise adapted in order to circumvent the need for obtaining a license for use of the PROGRAM. +* +* 3. OWNERSHIP OF INTELLECTUAL PROPERTY +* LICENSEE acknowledges that title to the PROGRAM shall remain with BROAD. The PROGRAM is marked with the following BROAD copyright notice and notice of attribution to contributors. LICENSEE shall retain such notice on all copies. LICENSEE agrees to include appropriate attribution if any results obtained from use of the PROGRAM are included in any publication. +* Copyright 2012 Broad Institute, Inc. +* Notice of attribution: The GATK2 program was made available through the generosity of Medical and Population Genetics program at the Broad Institute, Inc. +* LICENSEE shall not use any trademark or trade name of BROAD, or any variation, adaptation, or abbreviation, of such marks or trade names, or any names of officers, faculty, students, employees, or agents of BROAD except as states above for attribution purposes. +* +* 4. INDEMNIFICATION +* LICENSEE shall indemnify, defend, and hold harmless BROAD, and their respective officers, faculty, students, employees, associated investigators and agents, and their respective successors, heirs and assigns, (Indemnitees), against any liability, damage, loss, or expense (including reasonable attorneys fees and expenses) incurred by or imposed upon any of the Indemnitees in connection with any claims, suits, actions, demands or judgments arising out of any theory of liability (including, without limitation, actions in the form of tort, warranty, or strict liability and regardless of whether such action has any factual basis) pursuant to any right or license granted under this Agreement. +* +* 5. NO REPRESENTATIONS OR WARRANTIES +* THE PROGRAM IS DELIVERED AS IS. BROAD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE PROGRAM OR THE COPYRIGHT, EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, WHETHER OR NOT DISCOVERABLE. BROAD EXTENDS NO WARRANTIES OF ANY KIND AS TO PROGRAM CONFORMITY WITH WHATEVER USER MANUALS OR OTHER LITERATURE MAY BE ISSUED FROM TIME TO TIME. +* IN NO EVENT SHALL BROAD OR ITS RESPECTIVE DIRECTORS, OFFICERS, EMPLOYEES, AFFILIATED INVESTIGATORS AND AFFILIATES BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING, WITHOUT LIMITATION, ECONOMIC DAMAGES OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER BROAD SHALL BE ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT SHALL KNOW OF THE POSSIBILITY OF THE FOREGOING. +* +* 6. ASSIGNMENT +* This Agreement is personal to LICENSEE and any rights or obligations assigned by LICENSEE without the prior written consent of BROAD shall be null and void. +* +* 7. MISCELLANEOUS +* 7.1 Export Control. LICENSEE gives assurance that it will comply with all United States export control laws and regulations controlling the export of the PROGRAM, including, without limitation, all Export Administration Regulations of the United States Department of Commerce. Among other things, these laws and regulations prohibit, or require a license for, the export of certain types of software to specified countries. +* 7.2 Termination. LICENSEE shall have the right to terminate this Agreement for any reason upon prior written notice to BROAD. If LICENSEE breaches any provision hereunder, and fails to cure such breach within thirty (30) days, BROAD may terminate this Agreement immediately. Upon termination, LICENSEE shall provide BROAD with written assurance that the original and all copies of the PROGRAM have been destroyed, except that, upon prior written authorization from BROAD, LICENSEE may retain a copy for archive purposes. +* 7.3 Survival. The following provisions shall survive the expiration or termination of this Agreement: Articles 1, 3, 4, 5 and Sections 2.2, 2.3, 7.3, and 7.4. +* 7.4 Notice. Any notices under this Agreement shall be in writing, shall specifically refer to this Agreement, and shall be sent by hand, recognized national overnight courier, confirmed facsimile transmission, confirmed electronic mail, or registered or certified mail, postage prepaid, return receipt requested. All notices under this Agreement shall be deemed effective upon receipt. +* 7.5 Amendment and Waiver; Entire Agreement. This Agreement may be amended, supplemented, or otherwise modified only by means of a written instrument signed by all parties. Any waiver of any rights or failure to act in a specific instance shall relate only to such instance and shall not be construed as an agreement to waive any rights or fail to act in any other instance, whether or not similar. This Agreement constitutes the entire agreement among the parties with respect to its subject matter and supersedes prior agreements or understandings between the parties relating to its subject matter. +* 7.6 Binding Effect; Headings. This Agreement shall be binding upon and inure to the benefit of the parties and their respective permitted successors and assigns. All headings are for convenience only and shall not affect the meaning of any provision of this Agreement. +* 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. +*/ + +package org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics; + +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.CallableStatus; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.SampleStatistics; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.ThresHolder; + +/** + * User: carneiro + * Date: 4/20/13 + * Time: 11:44 PM + */ +public class SampleBadMates implements Sample { + private static final CallableStatus CALL = CallableStatus.NO_READS ; + + private double threshold; + private double votingThreshold; + + @Override + public void initialize(ThresHolder thresholds) { + threshold = thresholds.badMateStatusThreshold; + votingThreshold = thresholds.votePercentageThreshold; + } + + @Override + public CallableStatus status(SampleStatistics sampleStatistics) { + final int nReads = sampleStatistics.getnReads(); + return nReads > 0 && (double) sampleStatistics.getnBadMates() / nReads > threshold ? CALL : null; + } + +} diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/SampleNoReads.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/SampleNoReads.java new file mode 100644 index 000000000..30a6fbda3 --- /dev/null +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/SampleNoReads.java @@ -0,0 +1,73 @@ +/* +* By downloading the PROGRAM you agree to the following terms of use: +* +* BROAD INSTITUTE - SOFTWARE LICENSE AGREEMENT - FOR ACADEMIC NON-COMMERCIAL RESEARCH PURPOSES ONLY +* +* This Agreement is made between the Broad Institute, Inc. with a principal address at 7 Cambridge Center, Cambridge, MA 02142 (BROAD) and the LICENSEE and is effective at the date the downloading is completed (EFFECTIVE DATE). +* +* WHEREAS, LICENSEE desires to license the PROGRAM, as defined hereinafter, and BROAD wishes to have this PROGRAM utilized in the public interest, subject only to the royalty-free, nonexclusive, nontransferable license rights of the United States Government pursuant to 48 CFR 52.227-14; and +* WHEREAS, LICENSEE desires to license the PROGRAM and BROAD desires to grant a license on the following terms and conditions. +* NOW, THEREFORE, in consideration of the promises and covenants made herein, the parties hereto agree as follows: +* +* 1. DEFINITIONS +* 1.1 PROGRAM shall mean copyright in the object code and source code known as GATK2 and related documentation, if any, as they exist on the EFFECTIVE DATE and can be downloaded from http://www.broadinstitute/GATK on the EFFECTIVE DATE. +* +* 2. LICENSE +* 2.1 Grant. Subject to the terms of this Agreement, BROAD hereby grants to LICENSEE, solely for academic non-commercial research purposes, a non-exclusive, non-transferable license to: (a) download, execute and display the PROGRAM and (b) create bug fixes and modify the PROGRAM. +* The LICENSEE may apply the PROGRAM in a pipeline to data owned by users other than the LICENSEE and provide these users the results of the PROGRAM provided LICENSEE does so for academic non-commercial purposes only. For clarification purposes, academic sponsored research is not a commercial use under the terms of this Agreement. +* 2.2 No Sublicensing or Additional Rights. LICENSEE shall not sublicense or distribute the PROGRAM, in whole or in part, without prior written permission from BROAD. LICENSEE shall ensure that all of its users agree to the terms of this Agreement. LICENSEE further agrees that it shall not put the PROGRAM on a network, server, or other similar technology that may be accessed by anyone other than the LICENSEE and its employees and users who have agreed to the terms of this agreement. +* 2.3 License Limitations. Nothing in this Agreement shall be construed to confer any rights upon LICENSEE by implication, estoppel, or otherwise to any computer software, trademark, intellectual property, or patent rights of BROAD, or of any other entity, except as expressly granted herein. LICENSEE agrees that the PROGRAM, in whole or part, shall not be used for any commercial purpose, including without limitation, as the basis of a commercial software or hardware product or to provide services. LICENSEE further agrees that the PROGRAM shall not be copied or otherwise adapted in order to circumvent the need for obtaining a license for use of the PROGRAM. +* +* 3. OWNERSHIP OF INTELLECTUAL PROPERTY +* LICENSEE acknowledges that title to the PROGRAM shall remain with BROAD. The PROGRAM is marked with the following BROAD copyright notice and notice of attribution to contributors. LICENSEE shall retain such notice on all copies. LICENSEE agrees to include appropriate attribution if any results obtained from use of the PROGRAM are included in any publication. +* Copyright 2012 Broad Institute, Inc. +* Notice of attribution: The GATK2 program was made available through the generosity of Medical and Population Genetics program at the Broad Institute, Inc. +* LICENSEE shall not use any trademark or trade name of BROAD, or any variation, adaptation, or abbreviation, of such marks or trade names, or any names of officers, faculty, students, employees, or agents of BROAD except as states above for attribution purposes. +* +* 4. INDEMNIFICATION +* LICENSEE shall indemnify, defend, and hold harmless BROAD, and their respective officers, faculty, students, employees, associated investigators and agents, and their respective successors, heirs and assigns, (Indemnitees), against any liability, damage, loss, or expense (including reasonable attorneys fees and expenses) incurred by or imposed upon any of the Indemnitees in connection with any claims, suits, actions, demands or judgments arising out of any theory of liability (including, without limitation, actions in the form of tort, warranty, or strict liability and regardless of whether such action has any factual basis) pursuant to any right or license granted under this Agreement. +* +* 5. NO REPRESENTATIONS OR WARRANTIES +* THE PROGRAM IS DELIVERED AS IS. BROAD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE PROGRAM OR THE COPYRIGHT, EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, WHETHER OR NOT DISCOVERABLE. BROAD EXTENDS NO WARRANTIES OF ANY KIND AS TO PROGRAM CONFORMITY WITH WHATEVER USER MANUALS OR OTHER LITERATURE MAY BE ISSUED FROM TIME TO TIME. +* IN NO EVENT SHALL BROAD OR ITS RESPECTIVE DIRECTORS, OFFICERS, EMPLOYEES, AFFILIATED INVESTIGATORS AND AFFILIATES BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING, WITHOUT LIMITATION, ECONOMIC DAMAGES OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER BROAD SHALL BE ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT SHALL KNOW OF THE POSSIBILITY OF THE FOREGOING. +* +* 6. ASSIGNMENT +* This Agreement is personal to LICENSEE and any rights or obligations assigned by LICENSEE without the prior written consent of BROAD shall be null and void. +* +* 7. MISCELLANEOUS +* 7.1 Export Control. LICENSEE gives assurance that it will comply with all United States export control laws and regulations controlling the export of the PROGRAM, including, without limitation, all Export Administration Regulations of the United States Department of Commerce. Among other things, these laws and regulations prohibit, or require a license for, the export of certain types of software to specified countries. +* 7.2 Termination. LICENSEE shall have the right to terminate this Agreement for any reason upon prior written notice to BROAD. If LICENSEE breaches any provision hereunder, and fails to cure such breach within thirty (30) days, BROAD may terminate this Agreement immediately. Upon termination, LICENSEE shall provide BROAD with written assurance that the original and all copies of the PROGRAM have been destroyed, except that, upon prior written authorization from BROAD, LICENSEE may retain a copy for archive purposes. +* 7.3 Survival. The following provisions shall survive the expiration or termination of this Agreement: Articles 1, 3, 4, 5 and Sections 2.2, 2.3, 7.3, and 7.4. +* 7.4 Notice. Any notices under this Agreement shall be in writing, shall specifically refer to this Agreement, and shall be sent by hand, recognized national overnight courier, confirmed facsimile transmission, confirmed electronic mail, or registered or certified mail, postage prepaid, return receipt requested. All notices under this Agreement shall be deemed effective upon receipt. +* 7.5 Amendment and Waiver; Entire Agreement. This Agreement may be amended, supplemented, or otherwise modified only by means of a written instrument signed by all parties. Any waiver of any rights or failure to act in a specific instance shall relate only to such instance and shall not be construed as an agreement to waive any rights or fail to act in any other instance, whether or not similar. This Agreement constitutes the entire agreement among the parties with respect to its subject matter and supersedes prior agreements or understandings between the parties relating to its subject matter. +* 7.6 Binding Effect; Headings. This Agreement shall be binding upon and inure to the benefit of the parties and their respective permitted successors and assigns. All headings are for convenience only and shall not affect the meaning of any provision of this Agreement. +* 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. +*/ + +package org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics; + +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.CallableStatus; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.SampleStatistics; +import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.ThresHolder; + +/** + * User: carneiro + * Date: 4/20/13 + * Time: 11:44 PM + */ +public class SampleNoReads implements Sample { + private static final CallableStatus CALL = CallableStatus.NO_READS; + + private double votingThreshold; + + @Override + public void initialize(ThresHolder thresholds) { + votingThreshold = thresholds.votePercentageThreshold; + } + + @Override + public CallableStatus status(SampleStatistics sampleStatistics) { + return sampleStatistics.getnReads() == 0 ? CALL : null; + } + +} diff --git a/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargetsIntegrationTest.java b/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargetsIntegrationTest.java index ef14f8386..e5cea2c7b 100644 --- a/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargetsIntegrationTest.java +++ b/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargetsIntegrationTest.java @@ -66,11 +66,11 @@ public class DiagnoseTargetsIntegrationTest extends WalkerTest { @Test(enabled = true) public void testSingleSample() { - DTTest("testSingleSample ", "-I " + singleSample + " -max 75", "742c13fc092b42f9ff71fc3fff4a95cc"); + DTTest("testSingleSample ", "-I " + singleSample + " -max 75", "850304909477afa8c2a8f128d6eedde9"); } @Test(enabled = true) public void testMultiSample() { - DTTest("testMultiSample ", "-I " + multiSample, "7083cc720a2caa02fb0fa8f49f94a826"); + DTTest("testMultiSample ", "-I " + multiSample, "bedd19bcf21d1a779f6706c0351c9d26"); } } diff --git a/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/LocusStatisticsUnitTest.java b/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/LocusStatisticsUnitTest.java index c86acebb9..96747619f 100644 --- a/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/LocusStatisticsUnitTest.java +++ b/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/LocusStatisticsUnitTest.java @@ -47,37 +47,43 @@ package org.broadinstitute.sting.gatk.walkers.diagnostics.targets; import org.testng.Assert; +import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import java.util.Set; -public class LocusStatisticsUnitTest /*extends BaseTest*/ { +public class LocusStatisticsUnitTest { + + ThresHolder thresholds = new ThresHolder(); + + @BeforeClass + public void init() { + DiagnoseTargets.loadAllPlugins(thresholds); + } @Test(dataProvider = "StatusTestValues") public void testCallableStatuses(int coverage, int rawCoverage, CallableStatus status) { - // The min Coverage threshold is 10, the max is 100 - ThresHolder thresholds = new ThresHolder(20, 20, 10, 100, 50, 0.5, 0.5, 0.2, 0.2, 0.5); - Set statuses = new LocusStatistics(coverage, rawCoverage).callableStatuses(thresholds); - // Check to make sure the status provides matches the actual + Set statuses = new LocusStatistics(coverage, rawCoverage, thresholds).callableStatuses(); Assert.assertTrue((status == null) ? statuses.isEmpty() : (statuses.contains(status) && statuses.size() == 1)); - } @DataProvider(name = "StatusTestValues") public Object[][] getStatusTestValues() { + final int max = thresholds.maximumCoverage; + final int min = thresholds.minimumCoverage; return new Object[][]{ - new Object[]{100, 100, null}, - new Object[]{100, 101, null}, - new Object[]{101, 101, CallableStatus.EXCESSIVE_COVERAGE}, - new Object[]{10, 101, null}, - new Object[]{9, 101, CallableStatus.POOR_QUALITY}, - new Object[]{9, 10, CallableStatus.POOR_QUALITY}, - new Object[]{9, 9, CallableStatus.LOW_COVERAGE}, + new Object[]{max, max, null}, + new Object[]{max, max+1, null}, + new Object[]{max+1, max+1, CallableStatus.EXCESSIVE_COVERAGE}, + new Object[]{min, max+1, null}, + new Object[]{min-1, max+1, CallableStatus.POOR_QUALITY}, + new Object[]{min-1, min, CallableStatus.POOR_QUALITY}, + new Object[]{min-1, min-1, CallableStatus.LOW_COVERAGE}, new Object[]{0, 0, CallableStatus.COVERAGE_GAPS}, - new Object[]{0, 9, CallableStatus.LOW_COVERAGE}, - new Object[]{0, 101, CallableStatus.POOR_QUALITY}, - new Object[]{10, Integer.MAX_VALUE, null}, + new Object[]{0, min-1, CallableStatus.LOW_COVERAGE}, + new Object[]{0, max+1, CallableStatus.POOR_QUALITY}, + new Object[]{min, Integer.MAX_VALUE, null}, new Object[]{Integer.MAX_VALUE, Integer.MAX_VALUE, CallableStatus.EXCESSIVE_COVERAGE}, }; } From 38662f1d475e5bc63edbb88cb300fbb24dd62f90 Mon Sep 17 00:00:00 2001 From: Mauricio Carneiro Date: Tue, 23 Apr 2013 14:01:43 -0400 Subject: [PATCH 6/8] Limiting access to the DT classes * Make most classes final, others package local * Move to diagnostics.diagnosetargets package * Aggregate statistics and walker classes on the same package for simplified visibility. * Make status list a LinkedList instead of a HashSet --- .../BaseCoverageDistribution.java | 2 +- .../{targets => }/FindCoveredIntervals.java | 2 +- .../CallableStatus.java | 4 ++-- .../DiagnoseTargets.java | 13 +++++-------- .../Interval.java | 8 ++------ .../IntervalStatistics.java | 19 +++++++------------ .../statistics => diagnosetargets}/Locus.java | 9 ++------- .../LocusCoverageGap.java | 9 ++------- .../LocusExcessiveCoverage.java | 9 ++------- .../LocusLowCoverage.java | 9 ++------- .../LocusPoorQuality.java | 9 ++------- .../LocusStatistics.java | 13 +++++-------- .../PluginUtils.java | 7 ++----- .../Sample.java | 8 ++------ .../SampleBadMates.java | 8 ++------ .../SampleNoReads.java | 8 ++------ .../SampleStatistics.java | 10 ++++------ .../ThresHolder.java | 7 ++----- ...seCoverageDistributionIntegrationTest.java | 2 +- .../DiagnoseTargetsIntegrationTest.java | 12 ++++++------ .../LocusStatisticsUnitTest.java | 6 +++--- 21 files changed, 57 insertions(+), 117 deletions(-) rename protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/{targets => }/BaseCoverageDistribution.java (99%) rename protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/{targets => }/FindCoveredIntervals.java (99%) rename protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/{targets => diagnosetargets}/CallableStatus.java (98%) rename protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/{targets => diagnosetargets}/DiagnoseTargets.java (96%) rename protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/{targets/statistics => diagnosetargets}/Interval.java (96%) rename protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/{targets => diagnosetargets}/IntervalStatistics.java (95%) rename protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/{targets/statistics => diagnosetargets}/Locus.java (95%) rename protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/{targets/statistics => diagnosetargets}/LocusCoverageGap.java (95%) rename protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/{targets/statistics => diagnosetargets}/LocusExcessiveCoverage.java (95%) rename protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/{targets/statistics => diagnosetargets}/LocusLowCoverage.java (95%) rename protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/{targets/statistics => diagnosetargets}/LocusPoorQuality.java (95%) rename protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/{targets => diagnosetargets}/LocusStatistics.java (96%) rename protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/{targets/statistics => diagnosetargets}/PluginUtils.java (97%) rename protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/{targets/statistics => diagnosetargets}/Sample.java (96%) rename protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/{targets/statistics => diagnosetargets}/SampleBadMates.java (96%) rename protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/{targets/statistics => diagnosetargets}/SampleNoReads.java (95%) rename protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/{targets => diagnosetargets}/SampleStatistics.java (97%) rename protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/{targets => diagnosetargets}/ThresHolder.java (97%) rename protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/{targets => }/BaseCoverageDistributionIntegrationTest.java (99%) rename protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/{targets => diagnosetargets}/DiagnoseTargetsIntegrationTest.java (95%) rename protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/{targets => diagnosetargets}/LocusStatisticsUnitTest.java (97%) diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/BaseCoverageDistribution.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/BaseCoverageDistribution.java similarity index 99% rename from protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/BaseCoverageDistribution.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/BaseCoverageDistribution.java index 53b7cebaa..417da9d79 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/BaseCoverageDistribution.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/BaseCoverageDistribution.java @@ -44,7 +44,7 @@ * 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. */ -package org.broadinstitute.sting.gatk.walkers.diagnostics.targets; +package org.broadinstitute.sting.gatk.walkers.diagnostics; import org.broadinstitute.sting.commandline.Argument; import org.broadinstitute.sting.commandline.Output; diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/FindCoveredIntervals.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/FindCoveredIntervals.java similarity index 99% rename from protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/FindCoveredIntervals.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/FindCoveredIntervals.java index 1c9751c5b..ad6023579 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/FindCoveredIntervals.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/FindCoveredIntervals.java @@ -44,7 +44,7 @@ * 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. */ -package org.broadinstitute.sting.gatk.walkers.diagnostics.targets; +package org.broadinstitute.sting.gatk.walkers.diagnostics; import org.broadinstitute.sting.commandline.Argument; import org.broadinstitute.sting.commandline.Output; diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/CallableStatus.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/CallableStatus.java similarity index 98% rename from protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/CallableStatus.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/CallableStatus.java index 32c0c339d..d38736f4f 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/CallableStatus.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/CallableStatus.java @@ -44,7 +44,7 @@ * 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. */ -package org.broadinstitute.sting.gatk.walkers.diagnostics.targets; +package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; /** * Short one line description of the walker. @@ -52,7 +52,7 @@ package org.broadinstitute.sting.gatk.walkers.diagnostics.targets; * @author Mauricio Carneiro * @since 2/1/12 */ -public enum CallableStatus { +enum CallableStatus { PASS("the base satisfied the min. depth for calling but had less than maxDepth to avoid having EXCESSIVE_COVERAGE"), diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargets.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/DiagnoseTargets.java similarity index 96% rename from protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargets.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/DiagnoseTargets.java index d90f2d1fa..7ecbe2f21 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargets.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/DiagnoseTargets.java @@ -44,7 +44,7 @@ * 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. */ -package org.broadinstitute.sting.gatk.walkers.diagnostics.targets; +package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; import net.sf.picard.util.PeekableIterator; import org.broadinstitute.sting.commandline.ArgumentCollection; @@ -54,9 +54,6 @@ import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; import org.broadinstitute.sting.gatk.walkers.*; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics.Interval; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics.Locus; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics.Sample; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.SampleUtils; import org.broadinstitute.sting.utils.classloader.PluginManager; @@ -259,7 +256,7 @@ public class DiagnoseTargets extends LocusWalker { VariantContextBuilder vcb = new VariantContextBuilder("DiagnoseTargets", interval.getContig(), interval.getStart(), interval.getStop(), alleles); vcb = vcb.log10PError(VariantContext.NO_LOG10_PERROR); - vcb.filters(new HashSet(statusesToStrings(stats.callableStatuses(), true))); + vcb.filters(new LinkedHashSet(statusToStrings(stats.callableStatuses(), true))); attributes.put(VCFConstants.END_KEY, interval.getStop()); attributes.put(AVG_INTERVAL_DP_KEY, stats.averageCoverage()); @@ -268,10 +265,10 @@ public class DiagnoseTargets extends LocusWalker { for (String sample : samples) { final GenotypeBuilder gb = new GenotypeBuilder(sample); - SampleStatistics sampleStat = stats.getSampleStatics(sample); + SampleStatistics sampleStat = stats.getSampleStatistics(sample); gb.attribute(AVG_INTERVAL_DP_KEY, sampleStat.averageCoverage()); - gb.filters(statusesToStrings(stats.getSampleStatics(sample).getCallableStatuses(), false)); + gb.filters(statusToStrings(stats.getSampleStatistics(sample).callableStatuses(), false)); genotypes.add(gb.make()); } @@ -286,7 +283,7 @@ public class DiagnoseTargets extends LocusWalker { * @param statuses the set of statuses to be converted * @return a matching set of strings */ - private List statusesToStrings(Set statuses, final boolean isInfoField) { + private List statusToStrings(List statuses, final boolean isInfoField) { List output = new ArrayList(statuses.size()); for (CallableStatus status : statuses) diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/Interval.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Interval.java similarity index 96% rename from protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/Interval.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Interval.java index 3e8adc978..75f41edf9 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/Interval.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Interval.java @@ -44,11 +44,7 @@ * 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. */ -package org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics; - -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.CallableStatus; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.IntervalStatistics; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.ThresHolder; +package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; /** * Created with IntelliJ IDEA. @@ -57,7 +53,7 @@ import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.ThresHolder; * Time: 11:30 PM * To change this template use File | Settings | File Templates. */ -public interface Interval { +interface Interval { public void initialize(ThresHolder thresholds); public CallableStatus status (IntervalStatistics intervalStatistics); } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/IntervalStatistics.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/IntervalStatistics.java similarity index 95% rename from protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/IntervalStatistics.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/IntervalStatistics.java index 2e7333cc6..30cca8c5a 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/IntervalStatistics.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/IntervalStatistics.java @@ -44,21 +44,16 @@ * 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. */ -package org.broadinstitute.sting.gatk.walkers.diagnostics.targets; +package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics.Interval; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.exceptions.ReviewedStingException; import org.broadinstitute.sting.utils.pileup.ReadBackedPileup; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -public class IntervalStatistics { +import java.util.*; +final class IntervalStatistics { private final Map samples; private final GenomeLoc interval; private final ThresHolder thresholds; @@ -73,7 +68,7 @@ public class IntervalStatistics { this.samples.put(sample, new SampleStatistics(interval, thresholds)); } - public SampleStatistics getSampleStatics(String sample) { + public SampleStatistics getSampleStatistics(String sample) { return samples.get(sample); } @@ -126,13 +121,13 @@ public class IntervalStatistics { * * @return the callable status(es) for the whole interval */ - public Set callableStatuses() { - final Set output = new HashSet(); + public List callableStatuses() { + final List output = new LinkedList(); // sum up all the callable status for each sample final Map sampleStatusTally = new HashMap(CallableStatus.values().length); for (SampleStatistics sampleStatistics : samples.values()) { - for (CallableStatus status : sampleStatistics.getCallableStatuses()) { + for (CallableStatus status : sampleStatistics.callableStatuses()) { sampleStatusTally.put(status, !sampleStatusTally.containsKey(status) ? 1 : sampleStatusTally.get(status) + 1); } } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/Locus.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Locus.java similarity index 95% rename from protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/Locus.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Locus.java index aee41846b..5e6162fb6 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/Locus.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Locus.java @@ -44,12 +44,7 @@ * 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. */ -package org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics; - -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.CallableStatus; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.LocusStatistics; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.SampleStatistics; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.ThresHolder; +package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; /** * Created with IntelliJ IDEA. @@ -58,7 +53,7 @@ import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.ThresHolder; * Time: 11:29 PM * To change this template use File | Settings | File Templates. */ -public interface Locus { +interface Locus { public void initialize(ThresHolder thresholds); public CallableStatus status (LocusStatistics locusStatistics); public CallableStatus sampleStatus (SampleStatistics sampleStatistics); diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/LocusCoverageGap.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusCoverageGap.java similarity index 95% rename from protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/LocusCoverageGap.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusCoverageGap.java index effdd33b0..d78109a86 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/LocusCoverageGap.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusCoverageGap.java @@ -44,19 +44,14 @@ * 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. */ -package org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics; - -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.CallableStatus; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.LocusStatistics; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.SampleStatistics; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.ThresHolder; +package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; /** * User: carneiro * Date: 4/20/13 * Time: 11:44 PM */ -public class LocusCoverageGap implements Locus { +final class LocusCoverageGap implements Locus { private double threshold; private static final CallableStatus CALL = CallableStatus.COVERAGE_GAPS; diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/LocusExcessiveCoverage.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusExcessiveCoverage.java similarity index 95% rename from protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/LocusExcessiveCoverage.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusExcessiveCoverage.java index 72709a0f6..3bbb6b2d8 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/LocusExcessiveCoverage.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusExcessiveCoverage.java @@ -44,19 +44,14 @@ * 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. */ -package org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics; - -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.CallableStatus; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.LocusStatistics; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.SampleStatistics; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.ThresHolder; +package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; /** * User: carneiro * Date: 4/20/13 * Time: 11:44 PM */ -public class LocusExcessiveCoverage implements Locus { +final class LocusExcessiveCoverage implements Locus { private int excessiveCoverage; private double threshold; private static final CallableStatus CALL = CallableStatus.EXCESSIVE_COVERAGE ; diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/LocusLowCoverage.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusLowCoverage.java similarity index 95% rename from protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/LocusLowCoverage.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusLowCoverage.java index f3f181bd1..0f7d481c9 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/LocusLowCoverage.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusLowCoverage.java @@ -44,19 +44,14 @@ * 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. */ -package org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics; - -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.CallableStatus; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.LocusStatistics; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.SampleStatistics; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.ThresHolder; +package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; /** * User: carneiro * Date: 4/20/13 * Time: 11:44 PM */ -public class LocusLowCoverage implements Locus { +final class LocusLowCoverage implements Locus { private int minCoverage; private double threshold; private static final CallableStatus CALL = CallableStatus.LOW_COVERAGE ; diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/LocusPoorQuality.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusPoorQuality.java similarity index 95% rename from protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/LocusPoorQuality.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusPoorQuality.java index 91d5f8c04..3caf467ec 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/LocusPoorQuality.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusPoorQuality.java @@ -44,19 +44,14 @@ * 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. */ -package org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics; - -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.CallableStatus; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.LocusStatistics; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.SampleStatistics; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.ThresHolder; +package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; /** * User: carneiro * Date: 4/20/13 * Time: 11:44 PM */ -public class LocusPoorQuality implements Locus { +final class LocusPoorQuality implements Locus { private int minCoverage; private double threshold; private static final CallableStatus CALL = CallableStatus.POOR_QUALITY ; diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/LocusStatistics.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusStatistics.java similarity index 96% rename from protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/LocusStatistics.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusStatistics.java index e85f3d9c1..543b126b4 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/LocusStatistics.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusStatistics.java @@ -44,15 +44,12 @@ * 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. */ -package org.broadinstitute.sting.gatk.walkers.diagnostics.targets; +package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics.Locus; - -import java.util.HashSet; +import java.util.LinkedList; import java.util.List; -import java.util.Set; -public class LocusStatistics { +final class LocusStatistics { private int coverage; private int rawCoverage; private final List locusStatisticsList; @@ -80,8 +77,8 @@ public class LocusStatistics { * * @return a set of all statuses that apply */ - public Set callableStatuses() { - Set output = new HashSet(); + public List callableStatuses() { + List output = new LinkedList(); for (Locus stats : locusStatisticsList) { CallableStatus status = stats.status(this); if (status != null) { diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/PluginUtils.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/PluginUtils.java similarity index 97% rename from protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/PluginUtils.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/PluginUtils.java index 0a29aea4d..2343b637e 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/PluginUtils.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/PluginUtils.java @@ -44,10 +44,7 @@ * 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. */ -package org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics; - -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.CallableStatus; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.SampleStatistics; +package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; import java.util.Map; @@ -56,7 +53,7 @@ import java.util.Map; * Date: 4/21/13 * Time: 11:23 AM */ -public class PluginUtils { +final class PluginUtils { public static CallableStatus genericSampleStatus (final SampleStatistics sampleStatistics, final CallableStatus CALL, final double threshold) { final Map totals = sampleStatistics.getLocusStatusTally(); final int size = sampleStatistics.getIntervalSize(); diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/Sample.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Sample.java similarity index 96% rename from protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/Sample.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Sample.java index a33c33877..3b4e55347 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/Sample.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Sample.java @@ -44,11 +44,7 @@ * 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. */ -package org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics; - -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.CallableStatus; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.SampleStatistics; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.ThresHolder; +package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; /** * Created with IntelliJ IDEA. @@ -57,7 +53,7 @@ import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.ThresHolder; * Time: 11:30 PM * To change this template use File | Settings | File Templates. */ -public interface Sample { +interface Sample { public void initialize(ThresHolder thresholds); public CallableStatus status (SampleStatistics sampleStatistics); } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/SampleBadMates.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleBadMates.java similarity index 96% rename from protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/SampleBadMates.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleBadMates.java index 07e2cca5a..9c56858f6 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/SampleBadMates.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleBadMates.java @@ -44,18 +44,14 @@ * 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. */ -package org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics; - -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.CallableStatus; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.SampleStatistics; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.ThresHolder; +package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; /** * User: carneiro * Date: 4/20/13 * Time: 11:44 PM */ -public class SampleBadMates implements Sample { +final class SampleBadMates implements Sample { private static final CallableStatus CALL = CallableStatus.NO_READS ; private double threshold; diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/SampleNoReads.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleNoReads.java similarity index 95% rename from protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/SampleNoReads.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleNoReads.java index 30a6fbda3..95d66a555 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/statistics/SampleNoReads.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleNoReads.java @@ -44,18 +44,14 @@ * 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. */ -package org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics; - -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.CallableStatus; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.SampleStatistics; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.ThresHolder; +package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; /** * User: carneiro * Date: 4/20/13 * Time: 11:44 PM */ -public class SampleNoReads implements Sample { +final class SampleNoReads implements Sample { private static final CallableStatus CALL = CallableStatus.NO_READS; private double votingThreshold; diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/SampleStatistics.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleStatistics.java similarity index 97% rename from protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/SampleStatistics.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleStatistics.java index c05feebbd..6c8481b0e 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/SampleStatistics.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleStatistics.java @@ -44,10 +44,8 @@ * 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. */ -package org.broadinstitute.sting.gatk.walkers.diagnostics.targets; +package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics.Locus; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics.Sample; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.exceptions.ReviewedStingException; import org.broadinstitute.sting.utils.pileup.ReadBackedPileup; @@ -58,7 +56,7 @@ import java.util.*; /** * The statistics calculator for a specific sample given the interval */ -public class SampleStatistics { +final class SampleStatistics { private final GenomeLoc interval; private final ArrayList loci; private final ThresHolder thresholds; @@ -129,8 +127,8 @@ public class SampleStatistics { * * @return the callable statuses of the entire sample */ - public Set getCallableStatuses() { - final Set output = new HashSet(); + public List callableStatuses() { + final List output = new LinkedList(); // get the tally of all the locus callable statuses for (Locus locusStat : thresholds.locusStatisticList) { diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/ThresHolder.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/ThresHolder.java similarity index 97% rename from protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/ThresHolder.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/ThresHolder.java index 3b7626708..c45c2d9ff 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/ThresHolder.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/ThresHolder.java @@ -44,17 +44,14 @@ * 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. */ -package org.broadinstitute.sting.gatk.walkers.diagnostics.targets; +package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; import org.broadinstitute.sting.commandline.Argument; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics.Interval; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics.Locus; -import org.broadinstitute.sting.gatk.walkers.diagnostics.targets.statistics.Sample; import java.util.LinkedList; import java.util.List; -public class ThresHolder { +final class ThresHolder { /** * Only bases with quality greater than this will be considered in the coverage metrics. diff --git a/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/BaseCoverageDistributionIntegrationTest.java b/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/BaseCoverageDistributionIntegrationTest.java similarity index 99% rename from protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/BaseCoverageDistributionIntegrationTest.java rename to protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/BaseCoverageDistributionIntegrationTest.java index 53153c100..27f140337 100644 --- a/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/BaseCoverageDistributionIntegrationTest.java +++ b/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/BaseCoverageDistributionIntegrationTest.java @@ -44,7 +44,7 @@ * 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. */ -package org.broadinstitute.sting.gatk.walkers.diagnostics.targets; +package org.broadinstitute.sting.gatk.walkers.diagnostics; import org.broadinstitute.sting.WalkerTest; import org.testng.annotations.DataProvider; diff --git a/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargetsIntegrationTest.java b/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/DiagnoseTargetsIntegrationTest.java similarity index 95% rename from protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargetsIntegrationTest.java rename to protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/DiagnoseTargetsIntegrationTest.java index e5cea2c7b..bac09f30d 100644 --- a/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/DiagnoseTargetsIntegrationTest.java +++ b/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/DiagnoseTargetsIntegrationTest.java @@ -44,23 +44,23 @@ * 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. */ -package org.broadinstitute.sting.gatk.walkers.diagnostics.targets; +package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; +import org.broadinstitute.sting.BaseTest; import org.broadinstitute.sting.WalkerTest; import org.testng.annotations.Test; import java.util.Arrays; public class DiagnoseTargetsIntegrationTest extends WalkerTest { - final static String REF = b37KGReference; - final String singleSample = validationDataLocation + "NA12878.HiSeq.b37.chr20.10_11mb.bam"; - final String multiSample = validationDataLocation + "CEUTrio.HiSeq.b37.chr20.10_11mb.bam"; - final String L = validationDataLocation + "DT-itest.interval_list"; + final static String REF = BaseTest.b37KGReference; + final String singleSample = BaseTest.validationDataLocation + "NA12878.HiSeq.b37.chr20.10_11mb.bam"; + final String multiSample = BaseTest.validationDataLocation + "CEUTrio.HiSeq.b37.chr20.10_11mb.bam"; + final String L = BaseTest.validationDataLocation + "DT-itest.interval_list"; private void DTTest(String testName, String args, String md5) { String base = String.format("-T DiagnoseTargets --no_cmdline_in_header -R %s -L %s", REF, L) + " -o %s "; WalkerTestSpec spec = new WalkerTestSpec(base + args, Arrays.asList(md5)); - //spec.disableShadowBCF(); executeTest(testName, spec); } diff --git a/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/LocusStatisticsUnitTest.java b/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusStatisticsUnitTest.java similarity index 97% rename from protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/LocusStatisticsUnitTest.java rename to protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusStatisticsUnitTest.java index 96747619f..d784c2a9e 100644 --- a/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/targets/LocusStatisticsUnitTest.java +++ b/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusStatisticsUnitTest.java @@ -44,14 +44,14 @@ * 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. */ -package org.broadinstitute.sting.gatk.walkers.diagnostics.targets; +package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; -import java.util.Set; +import java.util.List; public class LocusStatisticsUnitTest { @@ -64,7 +64,7 @@ public class LocusStatisticsUnitTest { @Test(dataProvider = "StatusTestValues") public void testCallableStatuses(int coverage, int rawCoverage, CallableStatus status) { - Set statuses = new LocusStatistics(coverage, rawCoverage, thresholds).callableStatuses(); + List statuses = new LocusStatistics(coverage, rawCoverage, thresholds).callableStatuses(); Assert.assertTrue((status == null) ? statuses.isEmpty() : (statuses.contains(status) && statuses.size() == 1)); } From 8f8f339e4bd4106f95552d86c6b0368d228729b8 Mon Sep 17 00:00:00 2001 From: Mauricio Carneiro Date: Tue, 23 Apr 2013 18:02:27 -0400 Subject: [PATCH 7/8] Abstract class for the statistics Addressing the code duplication issue raised by Mark. --- .../diagnosetargets/AbstractStatistics.java | 150 ++++++++++++++++++ .../diagnosetargets/DiagnoseTargets.java | 8 +- .../diagnostics/diagnosetargets/Interval.java | 4 +- .../diagnosetargets/IntervalStatistics.java | 53 ++----- .../diagnostics/diagnosetargets/Locus.java | 4 +- .../diagnosetargets/LocusCoverageGap.java | 3 +- .../LocusExcessiveCoverage.java | 3 +- .../diagnosetargets/LocusLowCoverage.java | 5 +- .../diagnosetargets/LocusPoorQuality.java | 3 +- .../diagnosetargets/LocusStatistics.java | 28 ++-- .../diagnosetargets/PluginUtils.java | 2 +- .../diagnostics/diagnosetargets/Sample.java | 4 +- .../diagnosetargets/SampleBadMates.java | 3 +- .../diagnosetargets/SampleNoReads.java | 9 +- .../diagnosetargets/SampleStatistics.java | 132 +++++---------- .../diagnosetargets/Statistic.java | 57 +++++++ .../diagnosetargets/ThresHolder.java | 6 +- 17 files changed, 304 insertions(+), 170 deletions(-) create mode 100644 protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/AbstractStatistics.java create mode 100644 protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Statistic.java diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/AbstractStatistics.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/AbstractStatistics.java new file mode 100644 index 000000000..0ac083bb6 --- /dev/null +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/AbstractStatistics.java @@ -0,0 +1,150 @@ +/* +* By downloading the PROGRAM you agree to the following terms of use: +* +* BROAD INSTITUTE - SOFTWARE LICENSE AGREEMENT - FOR ACADEMIC NON-COMMERCIAL RESEARCH PURPOSES ONLY +* +* This Agreement is made between the Broad Institute, Inc. with a principal address at 7 Cambridge Center, Cambridge, MA 02142 (BROAD) and the LICENSEE and is effective at the date the downloading is completed (EFFECTIVE DATE). +* +* WHEREAS, LICENSEE desires to license the PROGRAM, as defined hereinafter, and BROAD wishes to have this PROGRAM utilized in the public interest, subject only to the royalty-free, nonexclusive, nontransferable license rights of the United States Government pursuant to 48 CFR 52.227-14; and +* WHEREAS, LICENSEE desires to license the PROGRAM and BROAD desires to grant a license on the following terms and conditions. +* NOW, THEREFORE, in consideration of the promises and covenants made herein, the parties hereto agree as follows: +* +* 1. DEFINITIONS +* 1.1 PROGRAM shall mean copyright in the object code and source code known as GATK2 and related documentation, if any, as they exist on the EFFECTIVE DATE and can be downloaded from http://www.broadinstitute/GATK on the EFFECTIVE DATE. +* +* 2. LICENSE +* 2.1 Grant. Subject to the terms of this Agreement, BROAD hereby grants to LICENSEE, solely for academic non-commercial research purposes, a non-exclusive, non-transferable license to: (a) download, execute and display the PROGRAM and (b) create bug fixes and modify the PROGRAM. +* The LICENSEE may apply the PROGRAM in a pipeline to data owned by users other than the LICENSEE and provide these users the results of the PROGRAM provided LICENSEE does so for academic non-commercial purposes only. For clarification purposes, academic sponsored research is not a commercial use under the terms of this Agreement. +* 2.2 No Sublicensing or Additional Rights. LICENSEE shall not sublicense or distribute the PROGRAM, in whole or in part, without prior written permission from BROAD. LICENSEE shall ensure that all of its users agree to the terms of this Agreement. LICENSEE further agrees that it shall not put the PROGRAM on a network, server, or other similar technology that may be accessed by anyone other than the LICENSEE and its employees and users who have agreed to the terms of this agreement. +* 2.3 License Limitations. Nothing in this Agreement shall be construed to confer any rights upon LICENSEE by implication, estoppel, or otherwise to any computer software, trademark, intellectual property, or patent rights of BROAD, or of any other entity, except as expressly granted herein. LICENSEE agrees that the PROGRAM, in whole or part, shall not be used for any commercial purpose, including without limitation, as the basis of a commercial software or hardware product or to provide services. LICENSEE further agrees that the PROGRAM shall not be copied or otherwise adapted in order to circumvent the need for obtaining a license for use of the PROGRAM. +* +* 3. OWNERSHIP OF INTELLECTUAL PROPERTY +* LICENSEE acknowledges that title to the PROGRAM shall remain with BROAD. The PROGRAM is marked with the following BROAD copyright notice and notice of attribution to contributors. LICENSEE shall retain such notice on all copies. LICENSEE agrees to include appropriate attribution if any results obtained from use of the PROGRAM are included in any publication. +* Copyright 2012 Broad Institute, Inc. +* Notice of attribution: The GATK2 program was made available through the generosity of Medical and Population Genetics program at the Broad Institute, Inc. +* LICENSEE shall not use any trademark or trade name of BROAD, or any variation, adaptation, or abbreviation, of such marks or trade names, or any names of officers, faculty, students, employees, or agents of BROAD except as states above for attribution purposes. +* +* 4. INDEMNIFICATION +* LICENSEE shall indemnify, defend, and hold harmless BROAD, and their respective officers, faculty, students, employees, associated investigators and agents, and their respective successors, heirs and assigns, (Indemnitees), against any liability, damage, loss, or expense (including reasonable attorneys fees and expenses) incurred by or imposed upon any of the Indemnitees in connection with any claims, suits, actions, demands or judgments arising out of any theory of liability (including, without limitation, actions in the form of tort, warranty, or strict liability and regardless of whether such action has any factual basis) pursuant to any right or license granted under this Agreement. +* +* 5. NO REPRESENTATIONS OR WARRANTIES +* THE PROGRAM IS DELIVERED AS IS. BROAD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE PROGRAM OR THE COPYRIGHT, EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, WHETHER OR NOT DISCOVERABLE. BROAD EXTENDS NO WARRANTIES OF ANY KIND AS TO PROGRAM CONFORMITY WITH WHATEVER USER MANUALS OR OTHER LITERATURE MAY BE ISSUED FROM TIME TO TIME. +* IN NO EVENT SHALL BROAD OR ITS RESPECTIVE DIRECTORS, OFFICERS, EMPLOYEES, AFFILIATED INVESTIGATORS AND AFFILIATES BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING, WITHOUT LIMITATION, ECONOMIC DAMAGES OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER BROAD SHALL BE ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT SHALL KNOW OF THE POSSIBILITY OF THE FOREGOING. +* +* 6. ASSIGNMENT +* This Agreement is personal to LICENSEE and any rights or obligations assigned by LICENSEE without the prior written consent of BROAD shall be null and void. +* +* 7. MISCELLANEOUS +* 7.1 Export Control. LICENSEE gives assurance that it will comply with all United States export control laws and regulations controlling the export of the PROGRAM, including, without limitation, all Export Administration Regulations of the United States Department of Commerce. Among other things, these laws and regulations prohibit, or require a license for, the export of certain types of software to specified countries. +* 7.2 Termination. LICENSEE shall have the right to terminate this Agreement for any reason upon prior written notice to BROAD. If LICENSEE breaches any provision hereunder, and fails to cure such breach within thirty (30) days, BROAD may terminate this Agreement immediately. Upon termination, LICENSEE shall provide BROAD with written assurance that the original and all copies of the PROGRAM have been destroyed, except that, upon prior written authorization from BROAD, LICENSEE may retain a copy for archive purposes. +* 7.3 Survival. The following provisions shall survive the expiration or termination of this Agreement: Articles 1, 3, 4, 5 and Sections 2.2, 2.3, 7.3, and 7.4. +* 7.4 Notice. Any notices under this Agreement shall be in writing, shall specifically refer to this Agreement, and shall be sent by hand, recognized national overnight courier, confirmed facsimile transmission, confirmed electronic mail, or registered or certified mail, postage prepaid, return receipt requested. All notices under this Agreement shall be deemed effective upon receipt. +* 7.5 Amendment and Waiver; Entire Agreement. This Agreement may be amended, supplemented, or otherwise modified only by means of a written instrument signed by all parties. Any waiver of any rights or failure to act in a specific instance shall relate only to such instance and shall not be construed as an agreement to waive any rights or fail to act in any other instance, whether or not similar. This Agreement constitutes the entire agreement among the parties with respect to its subject matter and supersedes prior agreements or understandings between the parties relating to its subject matter. +* 7.6 Binding Effect; Headings. This Agreement shall be binding upon and inure to the benefit of the parties and their respective permitted successors and assigns. All headings are for convenience only and shall not affect the meaning of any provision of this Agreement. +* 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. +*/ + +package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +/** + * Generic code for Diagnose Target Statistics + * + * @author Mauricio Carneiro + * @since 4/23/13 + */ +abstract class AbstractStatistics { + + private long preComputedTotalCoverage = -1; + private Map statusTally = null; + protected ThresHolder thresholds; + + /** + * Calculates the average "good" coverage of this sample. Good means "passes the base and + * mapping quality requirements. + * + * @return the average "good" coverage + */ + public double averageCoverage(final int size) { + if (preComputedTotalCoverage < 0) + preComputedTotalCoverage = calculateTotalCoverage(getElements()); + return (double) preComputedTotalCoverage / size; + } + + /** + * Calculates the total "good" coverage of this sample. Good means "passes the base and + * mapping quality requirements. + * + * @return the total "good" coverage across the interval for this sample + */ + public long getCoverage() { + if (preComputedTotalCoverage < 0) + preComputedTotalCoverage = calculateTotalCoverage(getElements()); + return preComputedTotalCoverage; + } + + + /** + * This is how the extending class will calculate it's own total coverage + * + * @return the total coverage + */ + private long calculateTotalCoverage(Iterable elements) { + long cov = 0; + for (AbstractStatistics element : elements) { + cov += element.getCoverage(); + } + return cov; + } + + /** + * What are the list of elements in your class? For example: + * + * IntervalStatistics => List + * SampleStatistics => List + * + * @return the corresponding list of elements of the extending class + */ + public abstract Iterable getElements(); + + /** + * Calculates the Callable statuses for the statistic as a whole (interval, sample or locus) + * + * @return the callable status(es) for the whole object + */ + public abstract Iterable callableStatuses(); + + + /** + * Tally up all the callable status of all the loci in this sample. + * + * @return a map of callable status and counts + */ + public Map getStatusTally() { + if (statusTally == null) { + statusTally = new HashMap(CallableStatus.values().length); + for (AbstractStatistics stats : getElements()) { + for (CallableStatus status : stats.callableStatuses()) { + statusTally.put(status, !statusTally.containsKey(status) ? 1 : statusTally.get(status) + 1); + } + } + } + return statusTally; + } + + public static List queryStatus(List statList, AbstractStatistics stratification) { + List output = new LinkedList(); + for (Statistic stat : statList) { + final CallableStatus status = stat.status(stratification); + if (status != null) { + output.add(status); + } + } + return output; + } + +} diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/DiagnoseTargets.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/DiagnoseTargets.java index 7ecbe2f21..78a30a7bd 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/DiagnoseTargets.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/DiagnoseTargets.java @@ -259,14 +259,14 @@ public class DiagnoseTargets extends LocusWalker { vcb.filters(new LinkedHashSet(statusToStrings(stats.callableStatuses(), true))); attributes.put(VCFConstants.END_KEY, interval.getStop()); - attributes.put(AVG_INTERVAL_DP_KEY, stats.averageCoverage()); + attributes.put(AVG_INTERVAL_DP_KEY, stats.averageCoverage(interval.size())); vcb = vcb.attributes(attributes); for (String sample : samples) { final GenotypeBuilder gb = new GenotypeBuilder(sample); SampleStatistics sampleStat = stats.getSampleStatistics(sample); - gb.attribute(AVG_INTERVAL_DP_KEY, sampleStat.averageCoverage()); + gb.attribute(AVG_INTERVAL_DP_KEY, sampleStat.averageCoverage(interval.size())); gb.filters(statusToStrings(stats.getSampleStatistics(sample).callableStatuses(), false)); @@ -283,8 +283,8 @@ public class DiagnoseTargets extends LocusWalker { * @param statuses the set of statuses to be converted * @return a matching set of strings */ - private List statusToStrings(List statuses, final boolean isInfoField) { - List output = new ArrayList(statuses.size()); + private List statusToStrings(Iterable statuses, final boolean isInfoField) { + List output = new LinkedList(); for (CallableStatus status : statuses) if ( isInfoField || status != CallableStatus.PASS ) diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Interval.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Interval.java index 75f41edf9..bd8307f89 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Interval.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Interval.java @@ -53,7 +53,5 @@ package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; * Time: 11:30 PM * To change this template use File | Settings | File Templates. */ -interface Interval { - public void initialize(ThresHolder thresholds); - public CallableStatus status (IntervalStatistics intervalStatistics); +interface Interval extends Statistic { } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/IntervalStatistics.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/IntervalStatistics.java index 30cca8c5a..1580ce9ac 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/IntervalStatistics.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/IntervalStatistics.java @@ -53,23 +53,21 @@ import org.broadinstitute.sting.utils.pileup.ReadBackedPileup; import java.util.*; -final class IntervalStatistics { - private final Map samples; +final class IntervalStatistics extends AbstractStatistics{ + private final Map samples; private final GenomeLoc interval; private final ThresHolder thresholds; - private int preComputedTotalCoverage = -1; - public IntervalStatistics(Set samples, GenomeLoc interval, ThresHolder thresholds) { this.interval = interval; this.thresholds = thresholds; - this.samples = new HashMap(samples.size()); + this.samples = new HashMap(samples.size()); for (String sample : samples) this.samples.put(sample, new SampleStatistics(interval, thresholds)); } public SampleStatistics getSampleStatistics(String sample) { - return samples.get(sample); + return (SampleStatistics) samples.get(sample); } public GenomeLoc getInterval() { @@ -94,7 +92,7 @@ final class IntervalStatistics { for (Map.Entry entry : samplePileups.entrySet()) { String sample = entry.getKey(); ReadBackedPileup samplePileup = entry.getValue(); - SampleStatistics sampleStatistics = samples.get(sample); + SampleStatistics sampleStatistics = (SampleStatistics) samples.get(sample); if (sampleStatistics == null) throw new ReviewedStingException(String.format("Trying to add locus statistics to a sample (%s) that doesn't exist in the Interval.", sample)); @@ -104,49 +102,30 @@ final class IntervalStatistics { } - public double averageCoverage() { - if (preComputedTotalCoverage < 0) - calculateTotalCoverage(); - return (double) preComputedTotalCoverage / interval.size(); - } - - private void calculateTotalCoverage() { - preComputedTotalCoverage = 0; - for (SampleStatistics sample : samples.values()) - preComputedTotalCoverage += sample.totalCoverage(); + /** + * {@inheritDoc} + */ + @Override + public Iterable getElements() { + return samples.values(); } /** - * Return the Callable statuses for the interval as a whole - * - * @return the callable status(es) for the whole interval + * {@inheritDoc} */ - public List callableStatuses() { + @Override + public Iterable callableStatuses() { final List output = new LinkedList(); - // sum up all the callable status for each sample - final Map sampleStatusTally = new HashMap(CallableStatus.values().length); - for (SampleStatistics sampleStatistics : samples.values()) { - for (CallableStatus status : sampleStatistics.callableStatuses()) { - sampleStatusTally.put(status, !sampleStatusTally.containsKey(status) ? 1 : sampleStatusTally.get(status) + 1); - } - } - // check if any of the votes pass the threshold final int nSamples = getNSamples(); - for (Map.Entry entry : sampleStatusTally.entrySet()) { + for (Map.Entry entry : getStatusTally().entrySet()) { if ((double) entry.getValue() / nSamples > thresholds.votePercentageThreshold) { output.add(entry.getKey()); } } - // add the interval specific statitics statuses - for (Interval intervalStat : thresholds.intervalStatisticList) { - final CallableStatus status = intervalStat.status(this); - if (status != null) { - output.add(status); - } - } + output.addAll(queryStatus(thresholds.intervalStatisticList, this)); return output; } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Locus.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Locus.java index 5e6162fb6..f04a093fd 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Locus.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Locus.java @@ -53,8 +53,6 @@ package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; * Time: 11:29 PM * To change this template use File | Settings | File Templates. */ -interface Locus { - public void initialize(ThresHolder thresholds); - public CallableStatus status (LocusStatistics locusStatistics); +interface Locus extends Statistic { public CallableStatus sampleStatus (SampleStatistics sampleStatistics); } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusCoverageGap.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusCoverageGap.java index d78109a86..d40816a34 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusCoverageGap.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusCoverageGap.java @@ -61,7 +61,8 @@ final class LocusCoverageGap implements Locus { } @Override - public CallableStatus status(LocusStatistics locusStatistics) { + public CallableStatus status(AbstractStatistics statistics) { + final LocusStatistics locusStatistics = (LocusStatistics) statistics; return locusStatistics.getRawCoverage() == 0 ? CALL : null; } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusExcessiveCoverage.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusExcessiveCoverage.java index 3bbb6b2d8..ef1d7ffde 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusExcessiveCoverage.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusExcessiveCoverage.java @@ -63,7 +63,8 @@ final class LocusExcessiveCoverage implements Locus { } @Override - public CallableStatus status(LocusStatistics locusStatistics) { + public CallableStatus status(AbstractStatistics statistics) { + final LocusStatistics locusStatistics = (LocusStatistics) statistics; return locusStatistics.getCoverage() > excessiveCoverage ? CALL : null; } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusLowCoverage.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusLowCoverage.java index 0f7d481c9..f421f5142 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusLowCoverage.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusLowCoverage.java @@ -63,8 +63,9 @@ final class LocusLowCoverage implements Locus { } @Override - public CallableStatus status(LocusStatistics locusStatistics) { - final int raw = locusStatistics.getRawCoverage(); + public CallableStatus status(AbstractStatistics statistics) { + final LocusStatistics locusStatistics = (LocusStatistics) statistics; + final long raw = locusStatistics.getRawCoverage(); return raw > 0 && raw < minCoverage ? CALL: null; } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusPoorQuality.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusPoorQuality.java index 3caf467ec..042ebcbf8 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusPoorQuality.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusPoorQuality.java @@ -63,7 +63,8 @@ final class LocusPoorQuality implements Locus { } @Override - public CallableStatus status(LocusStatistics locusStatistics) { + public CallableStatus status(AbstractStatistics statistics) { + final LocusStatistics locusStatistics = (LocusStatistics) statistics; return locusStatistics.getCoverage() < minCoverage && locusStatistics.getRawCoverage() >= minCoverage ? CALL: null; } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusStatistics.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusStatistics.java index 543b126b4..b5a9373d5 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusStatistics.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusStatistics.java @@ -49,10 +49,10 @@ package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; import java.util.LinkedList; import java.util.List; -final class LocusStatistics { - private int coverage; - private int rawCoverage; - private final List locusStatisticsList; +final class LocusStatistics extends AbstractStatistics{ + private long coverage; + private long rawCoverage; + private final List locusStatisticsList; public LocusStatistics(ThresHolder thresholds) { this(0,0,thresholds); @@ -64,12 +64,13 @@ final class LocusStatistics { this.locusStatisticsList = thresholds.locusStatisticList; } - public int getCoverage() { - return coverage; - } + @Override + public long getCoverage() {return coverage;} + public long getRawCoverage() {return rawCoverage;} - public int getRawCoverage() { - return rawCoverage; + public void addLocus(final int coverage, final int rawCoverage) { + this.coverage = coverage; + this.rawCoverage = rawCoverage; } /** @@ -79,7 +80,7 @@ final class LocusStatistics { */ public List callableStatuses() { List output = new LinkedList(); - for (Locus stats : locusStatisticsList) { + for (Statistic stats : locusStatisticsList) { CallableStatus status = stats.status(this); if (status != null) { output.add(status); @@ -88,8 +89,9 @@ final class LocusStatistics { return output; } - public void set(final int coverage, final int rawCoverage) { - this.coverage = coverage; - this.rawCoverage = rawCoverage; + @Override + public Iterable getElements() { + return null; } + } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/PluginUtils.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/PluginUtils.java index 2343b637e..cb28e0ac5 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/PluginUtils.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/PluginUtils.java @@ -55,7 +55,7 @@ import java.util.Map; */ final class PluginUtils { public static CallableStatus genericSampleStatus (final SampleStatistics sampleStatistics, final CallableStatus CALL, final double threshold) { - final Map totals = sampleStatistics.getLocusStatusTally(); + final Map totals = sampleStatistics.getStatusTally(); final int size = sampleStatistics.getIntervalSize(); final int statusCount = totals.containsKey(CALL) ? totals.get(CALL) : 0; return ( (double) statusCount / size) >= threshold ? CALL: null; diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Sample.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Sample.java index 3b4e55347..52b24520e 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Sample.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Sample.java @@ -53,7 +53,5 @@ package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; * Time: 11:30 PM * To change this template use File | Settings | File Templates. */ -interface Sample { - public void initialize(ThresHolder thresholds); - public CallableStatus status (SampleStatistics sampleStatistics); +interface Sample extends Statistic { } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleBadMates.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleBadMates.java index 9c56858f6..483f63c06 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleBadMates.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleBadMates.java @@ -64,7 +64,8 @@ final class SampleBadMates implements Sample { } @Override - public CallableStatus status(SampleStatistics sampleStatistics) { + public CallableStatus status(AbstractStatistics statistics) { + final SampleStatistics sampleStatistics = (SampleStatistics) statistics; final int nReads = sampleStatistics.getnReads(); return nReads > 0 && (double) sampleStatistics.getnBadMates() / nReads > threshold ? CALL : null; } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleNoReads.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleNoReads.java index 95d66a555..1c6d3deb7 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleNoReads.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleNoReads.java @@ -53,16 +53,13 @@ package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; */ final class SampleNoReads implements Sample { private static final CallableStatus CALL = CallableStatus.NO_READS; - - private double votingThreshold; - - @Override +@Override public void initialize(ThresHolder thresholds) { - votingThreshold = thresholds.votePercentageThreshold; } @Override - public CallableStatus status(SampleStatistics sampleStatistics) { + public CallableStatus status(AbstractStatistics statistics) { + final SampleStatistics sampleStatistics = (SampleStatistics) statistics; return sampleStatistics.getnReads() == 0 ? CALL : null; } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleStatistics.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleStatistics.java index 6c8481b0e..4d41fea16 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleStatistics.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleStatistics.java @@ -56,20 +56,18 @@ import java.util.*; /** * The statistics calculator for a specific sample given the interval */ -final class SampleStatistics { +final class SampleStatistics extends AbstractStatistics { private final GenomeLoc interval; - private final ArrayList loci; + private final ArrayList loci; private final ThresHolder thresholds; - // avoids re-calculating these sums over loci - private int preComputedTotalCoverage = -1; private Map locusStatusTally = null; private int nReads = -1; private int nBadMates = -1; public SampleStatistics(final GenomeLoc interval, final ThresHolder thresholds) { this.interval = interval; - this.loci = new ArrayList(interval.size()); + this.loci = new ArrayList(interval.size()); this.thresholds = thresholds; nReads = 0; nBadMates = 0; @@ -77,69 +75,61 @@ final class SampleStatistics { // Initialize every loci (this way we don't have to worry about non-existent loci in the object for (int i = 0; i < interval.size(); i++) this.loci.add(new LocusStatistics(thresholds)); - } /** - * Calculates the total "good" coverage of this sample. Good means "passes the base and - * mapping quality requirements. - * - * @return the total "good" coverage across the interval for this sample + * Simple Getters */ - public long totalCoverage() { - if (preComputedTotalCoverage < 0) - calculateTotalCoverage(); - return preComputedTotalCoverage; - } + public int getIntervalSize() {return interval.size();} + public int getnReads() {return nReads;} + public int getnBadMates() {return nBadMates;} /** - * Calculates the average "good" coverage of this sample. Good means "passes the base and - * mapping quality requirements. - * - * @return the average "good" coverage - */ - public double averageCoverage() { - return (double) totalCoverage() / loci.size(); - } - - /** - * Tally up all the callable status of all the loci in this sample. - * - * @return a map of callable status and counts - */ - public Map getLocusStatusTally() { - if (locusStatusTally == null) { - locusStatusTally = new HashMap(CallableStatus.values().length); - - // sum up all the callable statuses for each locus - for (int i = 0; i < interval.size(); i++) { - LocusStatistics locus = loci.get(i); - for (CallableStatus status : locus.callableStatuses()) { - locusStatusTally.put(status, !locusStatusTally.containsKey(status) ? 1 : locusStatusTally.get(status) + 1); - } - } - } - return locusStatusTally; - } - - /** - * Calculates the callable statuses of the entire sample + * Adds a locus to the interval wide stats * - * @return the callable statuses of the entire sample + * @param locus The locus given as a GenomeLoc + * @param pileup The pileup of that locus, this exclusively contains the sample */ - public List callableStatuses() { + public void addLocus(GenomeLoc locus, ReadBackedPileup pileup) { + if (!interval.containsP(locus)) + throw new ReviewedStingException(String.format("Locus %s is not part of the Interval %s", locus, interval)); + + // a null pileup means there nothing to add + if (pileup != null) { + final int locusIndex = locus.getStart() - interval.getStart(); + final int rawCoverage = pileup.depthOfCoverage(); + final int coverage = pileup.getBaseAndMappingFilteredPileup(thresholds.minimumBaseQuality, thresholds.minimumMappingQuality).depthOfCoverage(); + final LocusStatistics locusData = (LocusStatistics) loci.get(locusIndex); + locusData.addLocus(coverage, rawCoverage); + + // process all the reads in this pileup (tallying number of reads and bad mates) + for (GATKSAMRecord read : pileup.getReads()) + processRead(read); + } + } + + @Override + public Iterable getElements() { + return loci; + } + + /** + * {@inheritDoc} + */ + @Override + public Iterable callableStatuses() { final List output = new LinkedList(); // get the tally of all the locus callable statuses - for (Locus locusStat : thresholds.locusStatisticList) { - final CallableStatus status = locusStat.sampleStatus(this); + for (Statistic locusStat : thresholds.locusStatisticList) { + final CallableStatus status = ((Locus) locusStat).sampleStatus(this); if (status != null) { output.add(status); } } // get the sample specific statitics statuses - for (Sample sampleStat : thresholds.sampleStatisticList) { + for (Statistic sampleStat : thresholds.sampleStatisticList) { final CallableStatus status = sampleStat.status(this); if (status != null) { output.add(status); @@ -153,28 +143,6 @@ final class SampleStatistics { return output; } - /** - * Adds a locus to the interval wide stats - * - * @param locus The locus given as a GenomeLoc - * @param pileup The pileup of that locus, this exclusively contains the sample - */ - public void addLocus(GenomeLoc locus, ReadBackedPileup pileup) { - if (!interval.containsP(locus)) - throw new ReviewedStingException(String.format("Locus %s is not part of the Interval %s", locus, interval)); - - // a null pileup means there nothing ot add - if (pileup != null) { - final int locusIndex = locus.getStart() - interval.getStart(); - final int rawCoverage = pileup.depthOfCoverage(); - final int coverage = pileup.getBaseAndMappingFilteredPileup(thresholds.minimumBaseQuality, thresholds.minimumMappingQuality).depthOfCoverage(); - final LocusStatistics locusData = loci.get(locusIndex); - locusData.set(coverage, rawCoverage); - - for (GATKSAMRecord read : pileup.getReads()) - processRead(read); - } - } /** * Account for the read and check it for any statistics necessary. Reads are marked in the temporary @@ -190,22 +158,4 @@ final class SampleStatistics { read.setTemporaryAttribute("seen", true); } } - - private void calculateTotalCoverage() { - preComputedTotalCoverage = 0; - for (LocusStatistics locus : loci) - preComputedTotalCoverage += locus.getCoverage(); - } - - public int getIntervalSize() { - return interval.size(); - } - - public int getnReads() { - return nReads; - } - - public int getnBadMates() { - return nBadMates; - } } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Statistic.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Statistic.java new file mode 100644 index 000000000..c43b00a65 --- /dev/null +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Statistic.java @@ -0,0 +1,57 @@ +/* +* By downloading the PROGRAM you agree to the following terms of use: +* +* BROAD INSTITUTE - SOFTWARE LICENSE AGREEMENT - FOR ACADEMIC NON-COMMERCIAL RESEARCH PURPOSES ONLY +* +* This Agreement is made between the Broad Institute, Inc. with a principal address at 7 Cambridge Center, Cambridge, MA 02142 (BROAD) and the LICENSEE and is effective at the date the downloading is completed (EFFECTIVE DATE). +* +* WHEREAS, LICENSEE desires to license the PROGRAM, as defined hereinafter, and BROAD wishes to have this PROGRAM utilized in the public interest, subject only to the royalty-free, nonexclusive, nontransferable license rights of the United States Government pursuant to 48 CFR 52.227-14; and +* WHEREAS, LICENSEE desires to license the PROGRAM and BROAD desires to grant a license on the following terms and conditions. +* NOW, THEREFORE, in consideration of the promises and covenants made herein, the parties hereto agree as follows: +* +* 1. DEFINITIONS +* 1.1 PROGRAM shall mean copyright in the object code and source code known as GATK2 and related documentation, if any, as they exist on the EFFECTIVE DATE and can be downloaded from http://www.broadinstitute/GATK on the EFFECTIVE DATE. +* +* 2. LICENSE +* 2.1 Grant. Subject to the terms of this Agreement, BROAD hereby grants to LICENSEE, solely for academic non-commercial research purposes, a non-exclusive, non-transferable license to: (a) download, execute and display the PROGRAM and (b) create bug fixes and modify the PROGRAM. +* The LICENSEE may apply the PROGRAM in a pipeline to data owned by users other than the LICENSEE and provide these users the results of the PROGRAM provided LICENSEE does so for academic non-commercial purposes only. For clarification purposes, academic sponsored research is not a commercial use under the terms of this Agreement. +* 2.2 No Sublicensing or Additional Rights. LICENSEE shall not sublicense or distribute the PROGRAM, in whole or in part, without prior written permission from BROAD. LICENSEE shall ensure that all of its users agree to the terms of this Agreement. LICENSEE further agrees that it shall not put the PROGRAM on a network, server, or other similar technology that may be accessed by anyone other than the LICENSEE and its employees and users who have agreed to the terms of this agreement. +* 2.3 License Limitations. Nothing in this Agreement shall be construed to confer any rights upon LICENSEE by implication, estoppel, or otherwise to any computer software, trademark, intellectual property, or patent rights of BROAD, or of any other entity, except as expressly granted herein. LICENSEE agrees that the PROGRAM, in whole or part, shall not be used for any commercial purpose, including without limitation, as the basis of a commercial software or hardware product or to provide services. LICENSEE further agrees that the PROGRAM shall not be copied or otherwise adapted in order to circumvent the need for obtaining a license for use of the PROGRAM. +* +* 3. OWNERSHIP OF INTELLECTUAL PROPERTY +* LICENSEE acknowledges that title to the PROGRAM shall remain with BROAD. The PROGRAM is marked with the following BROAD copyright notice and notice of attribution to contributors. LICENSEE shall retain such notice on all copies. LICENSEE agrees to include appropriate attribution if any results obtained from use of the PROGRAM are included in any publication. +* Copyright 2012 Broad Institute, Inc. +* Notice of attribution: The GATK2 program was made available through the generosity of Medical and Population Genetics program at the Broad Institute, Inc. +* LICENSEE shall not use any trademark or trade name of BROAD, or any variation, adaptation, or abbreviation, of such marks or trade names, or any names of officers, faculty, students, employees, or agents of BROAD except as states above for attribution purposes. +* +* 4. INDEMNIFICATION +* LICENSEE shall indemnify, defend, and hold harmless BROAD, and their respective officers, faculty, students, employees, associated investigators and agents, and their respective successors, heirs and assigns, (Indemnitees), against any liability, damage, loss, or expense (including reasonable attorneys fees and expenses) incurred by or imposed upon any of the Indemnitees in connection with any claims, suits, actions, demands or judgments arising out of any theory of liability (including, without limitation, actions in the form of tort, warranty, or strict liability and regardless of whether such action has any factual basis) pursuant to any right or license granted under this Agreement. +* +* 5. NO REPRESENTATIONS OR WARRANTIES +* THE PROGRAM IS DELIVERED AS IS. BROAD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE PROGRAM OR THE COPYRIGHT, EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, WHETHER OR NOT DISCOVERABLE. BROAD EXTENDS NO WARRANTIES OF ANY KIND AS TO PROGRAM CONFORMITY WITH WHATEVER USER MANUALS OR OTHER LITERATURE MAY BE ISSUED FROM TIME TO TIME. +* IN NO EVENT SHALL BROAD OR ITS RESPECTIVE DIRECTORS, OFFICERS, EMPLOYEES, AFFILIATED INVESTIGATORS AND AFFILIATES BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING, WITHOUT LIMITATION, ECONOMIC DAMAGES OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER BROAD SHALL BE ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT SHALL KNOW OF THE POSSIBILITY OF THE FOREGOING. +* +* 6. ASSIGNMENT +* This Agreement is personal to LICENSEE and any rights or obligations assigned by LICENSEE without the prior written consent of BROAD shall be null and void. +* +* 7. MISCELLANEOUS +* 7.1 Export Control. LICENSEE gives assurance that it will comply with all United States export control laws and regulations controlling the export of the PROGRAM, including, without limitation, all Export Administration Regulations of the United States Department of Commerce. Among other things, these laws and regulations prohibit, or require a license for, the export of certain types of software to specified countries. +* 7.2 Termination. LICENSEE shall have the right to terminate this Agreement for any reason upon prior written notice to BROAD. If LICENSEE breaches any provision hereunder, and fails to cure such breach within thirty (30) days, BROAD may terminate this Agreement immediately. Upon termination, LICENSEE shall provide BROAD with written assurance that the original and all copies of the PROGRAM have been destroyed, except that, upon prior written authorization from BROAD, LICENSEE may retain a copy for archive purposes. +* 7.3 Survival. The following provisions shall survive the expiration or termination of this Agreement: Articles 1, 3, 4, 5 and Sections 2.2, 2.3, 7.3, and 7.4. +* 7.4 Notice. Any notices under this Agreement shall be in writing, shall specifically refer to this Agreement, and shall be sent by hand, recognized national overnight courier, confirmed facsimile transmission, confirmed electronic mail, or registered or certified mail, postage prepaid, return receipt requested. All notices under this Agreement shall be deemed effective upon receipt. +* 7.5 Amendment and Waiver; Entire Agreement. This Agreement may be amended, supplemented, or otherwise modified only by means of a written instrument signed by all parties. Any waiver of any rights or failure to act in a specific instance shall relate only to such instance and shall not be construed as an agreement to waive any rights or fail to act in any other instance, whether or not similar. This Agreement constitutes the entire agreement among the parties with respect to its subject matter and supersedes prior agreements or understandings between the parties relating to its subject matter. +* 7.6 Binding Effect; Headings. This Agreement shall be binding upon and inure to the benefit of the parties and their respective permitted successors and assigns. All headings are for convenience only and shall not affect the meaning of any provision of this Agreement. +* 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. +*/ + +package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; + +/** + * + * @author Mauricio Carneiro + * @since 4/23/13 + */ +interface Statistic { + public void initialize(ThresHolder thresholds); + public CallableStatus status (AbstractStatistics statistic); +} diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/ThresHolder.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/ThresHolder.java index c45c2d9ff..42c09dda1 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/ThresHolder.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/ThresHolder.java @@ -114,9 +114,9 @@ final class ThresHolder { @Argument(fullName = "quality_status_threshold", shortName = "stQ", doc = "The proportion of the loci needed for calling POOR_QUALITY", required = false) public double qualityStatusThreshold = 0.50; - public final List locusStatisticList = new LinkedList(); - public final List sampleStatisticList = new LinkedList(); - public final List intervalStatisticList = new LinkedList(); + public final List locusStatisticList = new LinkedList(); + public final List sampleStatisticList = new LinkedList(); + public final List intervalStatisticList = new LinkedList(); public ThresHolder() {} From 367f0c0ac1f7c94914dc3ab344dbbd1282ff6037 Mon Sep 17 00:00:00 2001 From: Mauricio Carneiro Date: Wed, 24 Apr 2013 14:15:49 -0400 Subject: [PATCH 8/8] Split class names into stratification and metrics Calling everything statistics was very confusing. Diagnose Targets stratifies the data three ways: Interval, Sample and Locus. Each stratification then has it's own set of metrics (plugin system) to calculate -- LocusMetric, SampleMetric, IntervalMetric. Metrics are generalized by the Metric interface. (for generic access) Stratifications are generalized by the AbstractStratification abstract class. (to aggressively limit code duplication) --- ...stics.java => AbstractStratification.java} | 14 ++++---- .../diagnosetargets/DiagnoseTargets.java | 36 +++++++++---------- .../{Sample.java => IntervalMetric.java} | 2 +- ...stics.java => IntervalStratification.java} | 24 ++++++------- .../{Locus.java => LocusMetric.java} | 4 +-- ...geGap.java => LocusMetricCoverageGap.java} | 12 +++---- ...java => LocusMetricExcessiveCoverage.java} | 12 +++---- ...erage.java => LocusMetricLowCoverage.java} | 12 +++---- ...ality.java => LocusMetricPoorQuality.java} | 12 +++---- ...atistics.java => LocusStratification.java} | 14 ++++---- .../{Statistic.java => Metric.java} | 4 +-- .../diagnosetargets/PluginUtils.java | 6 ++-- .../{Interval.java => SampleMetric.java} | 2 +- ...adMates.java => SampleMetricBadMates.java} | 10 +++--- ...eNoReads.java => SampleMetricNoReads.java} | 8 ++--- ...tistics.java => SampleStratification.java} | 25 ++++++------- .../diagnosetargets/ThresHolder.java | 6 ++-- .../LocusStatisticsUnitTest.java | 2 +- 18 files changed, 103 insertions(+), 102 deletions(-) rename protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/{AbstractStatistics.java => AbstractStratification.java} (95%) rename protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/{Sample.java => IntervalMetric.java} (99%) rename protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/{IntervalStatistics.java => IntervalStratification.java} (92%) rename protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/{Locus.java => LocusMetric.java} (98%) rename protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/{LocusCoverageGap.java => LocusMetricCoverageGap.java} (94%) rename protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/{LocusExcessiveCoverage.java => LocusMetricExcessiveCoverage.java} (94%) rename protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/{LocusLowCoverage.java => LocusMetricLowCoverage.java} (95%) rename protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/{LocusPoorQuality.java => LocusMetricPoorQuality.java} (94%) rename protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/{LocusStatistics.java => LocusStratification.java} (95%) rename protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/{Statistic.java => Metric.java} (98%) rename protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/{Interval.java => SampleMetric.java} (99%) rename protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/{SampleBadMates.java => SampleMetricBadMates.java} (95%) rename protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/{SampleNoReads.java => SampleMetricNoReads.java} (96%) rename protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/{SampleStatistics.java => SampleStratification.java} (93%) diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/AbstractStatistics.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/AbstractStratification.java similarity index 95% rename from protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/AbstractStatistics.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/AbstractStratification.java index 0ac083bb6..dca83af44 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/AbstractStatistics.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/AbstractStratification.java @@ -57,7 +57,7 @@ import java.util.Map; * @author Mauricio Carneiro * @since 4/23/13 */ -abstract class AbstractStatistics { +abstract class AbstractStratification { private long preComputedTotalCoverage = -1; private Map statusTally = null; @@ -93,9 +93,9 @@ abstract class AbstractStatistics { * * @return the total coverage */ - private long calculateTotalCoverage(Iterable elements) { + private long calculateTotalCoverage(Iterable elements) { long cov = 0; - for (AbstractStatistics element : elements) { + for (AbstractStratification element : elements) { cov += element.getCoverage(); } return cov; @@ -109,7 +109,7 @@ abstract class AbstractStatistics { * * @return the corresponding list of elements of the extending class */ - public abstract Iterable getElements(); + public abstract Iterable getElements(); /** * Calculates the Callable statuses for the statistic as a whole (interval, sample or locus) @@ -127,7 +127,7 @@ abstract class AbstractStatistics { public Map getStatusTally() { if (statusTally == null) { statusTally = new HashMap(CallableStatus.values().length); - for (AbstractStatistics stats : getElements()) { + for (AbstractStratification stats : getElements()) { for (CallableStatus status : stats.callableStatuses()) { statusTally.put(status, !statusTally.containsKey(status) ? 1 : statusTally.get(status) + 1); } @@ -136,9 +136,9 @@ abstract class AbstractStatistics { return statusTally; } - public static List queryStatus(List statList, AbstractStatistics stratification) { + public static List queryStatus(List statList, AbstractStratification stratification) { List output = new LinkedList(); - for (Statistic stat : statList) { + for (Metric stat : statList) { final CallableStatus status = stat.status(stratification); if (status != null) { output.add(status); diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/DiagnoseTargets.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/DiagnoseTargets.java index 78a30a7bd..32f87b973 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/DiagnoseTargets.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/DiagnoseTargets.java @@ -119,7 +119,7 @@ public class DiagnoseTargets extends LocusWalker { @ArgumentCollection private ThresHolder thresholds = new ThresHolder(); - private Map intervalMap = null; // maps each interval => statistics + private Map intervalMap = null; // maps each interval => statistics private PeekableIterator intervalListIterator; // an iterator to go over all the intervals provided as we traverse the genome private Set samples = null; // all the samples being processed private static final Allele SYMBOLIC_ALLELE = Allele.create("
", false); // avoid creating the symbolic allele multiple times @@ -134,7 +134,7 @@ public class DiagnoseTargets extends LocusWalker { if (getToolkit().getIntervals() == null || getToolkit().getIntervals().isEmpty()) throw new UserException("This tool only works if you provide one or more intervals (use the -L argument). If you want to run whole genome, use -T DepthOfCoverage instead."); - intervalMap = new HashMap(INITIAL_HASH_SIZE); + intervalMap = new HashMap(INITIAL_HASH_SIZE); intervalListIterator = new PeekableIterator(getToolkit().getIntervals().iterator()); // get all of the unique sample names for the VCF Header @@ -155,8 +155,8 @@ public class DiagnoseTargets extends LocusWalker { addNewOverlappingIntervals(refLocus); // at this point, all intervals in intervalMap overlap with this locus, so update all of them - for (IntervalStatistics intervalStatistics : intervalMap.values()) - intervalStatistics.addLocus(context); + for (IntervalStratification intervalStratification : intervalMap.values()) + intervalStratification.addLocus(context); return 1L; } @@ -207,7 +207,7 @@ public class DiagnoseTargets extends LocusWalker { // output empty statistics for uncovered intervals while (interval != null && interval.isBefore(refLocus)) { - final IntervalStatistics stats = intervalMap.get(interval); + final IntervalStratification stats = intervalMap.get(interval); outputStatsToVCF(stats != null ? stats : createIntervalStatistic(interval), UNCOVERED_ALLELE); if (stats != null) intervalMap.remove(interval); intervalListIterator.next(); @@ -243,7 +243,7 @@ public class DiagnoseTargets extends LocusWalker { * @param stats The statistics of the interval * @param refAllele the reference allele */ - private void outputStatsToVCF(IntervalStatistics stats, Allele refAllele) { + private void outputStatsToVCF(IntervalStratification stats, Allele refAllele) { GenomeLoc interval = stats.getInterval(); @@ -265,7 +265,7 @@ public class DiagnoseTargets extends LocusWalker { for (String sample : samples) { final GenotypeBuilder gb = new GenotypeBuilder(sample); - SampleStatistics sampleStat = stats.getSampleStatistics(sample); + SampleStratification sampleStat = stats.getSampleStatistics(sample); gb.attribute(AVG_INTERVAL_DP_KEY, sampleStat.averageCoverage(interval.size())); gb.filters(statusToStrings(stats.getSampleStatistics(sample).callableStatuses(), false)); @@ -293,36 +293,36 @@ public class DiagnoseTargets extends LocusWalker { return output; } - private IntervalStatistics createIntervalStatistic(GenomeLoc interval) { - return new IntervalStatistics(samples, interval, thresholds); + private IntervalStratification createIntervalStatistic(GenomeLoc interval) { + return new IntervalStratification(samples, interval, thresholds); } protected static void loadAllPlugins(final ThresHolder thresholds) { - for (Class stat : new PluginManager(Locus.class).getPlugins()) { + for (Class stat : new PluginManager(LocusMetric.class).getPlugins()) { try { - final Locus stats = (Locus) stat.newInstance(); + final LocusMetric stats = (LocusMetric) stat.newInstance(); stats.initialize(thresholds); - thresholds.locusStatisticList.add(stats); + thresholds.locusMetricList.add(stats); } catch (Exception e) { throw new DynamicClassResolutionException(stat, e); } } - for (Class stat : new PluginManager(Sample.class).getPlugins()) { + for (Class stat : new PluginManager(SampleMetric.class).getPlugins()) { try { - final Sample stats = (Sample) stat.newInstance(); + final SampleMetric stats = (SampleMetric) stat.newInstance(); stats.initialize(thresholds); - thresholds.sampleStatisticList.add(stats); + thresholds.sampleMetricList.add(stats); } catch (Exception e) { throw new DynamicClassResolutionException(stat, e); } } - for (Class stat : new PluginManager(Interval.class).getPlugins()) { + for (Class stat : new PluginManager(IntervalMetric.class).getPlugins()) { try { - final Interval stats = (Interval) stat.newInstance(); + final IntervalMetric stats = (IntervalMetric) stat.newInstance(); stats.initialize(thresholds); - thresholds.intervalStatisticList.add(stats); + thresholds.intervalMetricList.add(stats); } catch (Exception e) { throw new DynamicClassResolutionException(stat, e); } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Sample.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/IntervalMetric.java similarity index 99% rename from protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Sample.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/IntervalMetric.java index 52b24520e..50470a744 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Sample.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/IntervalMetric.java @@ -53,5 +53,5 @@ package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; * Time: 11:30 PM * To change this template use File | Settings | File Templates. */ -interface Sample extends Statistic { +interface IntervalMetric extends Metric { } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/IntervalStatistics.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/IntervalStratification.java similarity index 92% rename from protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/IntervalStatistics.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/IntervalStratification.java index 1580ce9ac..6c20403d1 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/IntervalStatistics.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/IntervalStratification.java @@ -53,21 +53,21 @@ import org.broadinstitute.sting.utils.pileup.ReadBackedPileup; import java.util.*; -final class IntervalStatistics extends AbstractStatistics{ - private final Map samples; +final class IntervalStratification extends AbstractStratification { + private final Map samples; private final GenomeLoc interval; private final ThresHolder thresholds; - public IntervalStatistics(Set samples, GenomeLoc interval, ThresHolder thresholds) { + public IntervalStratification(Set samples, GenomeLoc interval, ThresHolder thresholds) { this.interval = interval; this.thresholds = thresholds; - this.samples = new HashMap(samples.size()); + this.samples = new HashMap(samples.size()); for (String sample : samples) - this.samples.put(sample, new SampleStatistics(interval, thresholds)); + this.samples.put(sample, new SampleStratification(interval, thresholds)); } - public SampleStatistics getSampleStatistics(String sample) { - return (SampleStatistics) samples.get(sample); + public SampleStratification getSampleStatistics(String sample) { + return (SampleStratification) samples.get(sample); } public GenomeLoc getInterval() { @@ -92,12 +92,12 @@ final class IntervalStatistics extends AbstractStatistics{ for (Map.Entry entry : samplePileups.entrySet()) { String sample = entry.getKey(); ReadBackedPileup samplePileup = entry.getValue(); - SampleStatistics sampleStatistics = (SampleStatistics) samples.get(sample); + SampleStratification sampleStratification = (SampleStratification) samples.get(sample); - if (sampleStatistics == null) + if (sampleStratification == null) throw new ReviewedStingException(String.format("Trying to add locus statistics to a sample (%s) that doesn't exist in the Interval.", sample)); - sampleStatistics.addLocus(context.getLocation(), samplePileup); + sampleStratification.addLocus(context.getLocation(), samplePileup); } } @@ -106,7 +106,7 @@ final class IntervalStatistics extends AbstractStatistics{ * {@inheritDoc} */ @Override - public Iterable getElements() { + public Iterable getElements() { return samples.values(); } @@ -125,7 +125,7 @@ final class IntervalStatistics extends AbstractStatistics{ } } - output.addAll(queryStatus(thresholds.intervalStatisticList, this)); + output.addAll(queryStatus(thresholds.intervalMetricList, this)); return output; } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Locus.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusMetric.java similarity index 98% rename from protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Locus.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusMetric.java index f04a093fd..9950b4e2d 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Locus.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusMetric.java @@ -53,6 +53,6 @@ package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; * Time: 11:29 PM * To change this template use File | Settings | File Templates. */ -interface Locus extends Statistic { - public CallableStatus sampleStatus (SampleStatistics sampleStatistics); +interface LocusMetric extends Metric { + public CallableStatus sampleStatus (SampleStratification sampleStratification); } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusCoverageGap.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusMetricCoverageGap.java similarity index 94% rename from protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusCoverageGap.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusMetricCoverageGap.java index d40816a34..0973fef1e 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusCoverageGap.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusMetricCoverageGap.java @@ -51,7 +51,7 @@ package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; * Date: 4/20/13 * Time: 11:44 PM */ -final class LocusCoverageGap implements Locus { +final class LocusMetricCoverageGap implements LocusMetric { private double threshold; private static final CallableStatus CALL = CallableStatus.COVERAGE_GAPS; @@ -61,13 +61,13 @@ final class LocusCoverageGap implements Locus { } @Override - public CallableStatus status(AbstractStatistics statistics) { - final LocusStatistics locusStatistics = (LocusStatistics) statistics; - return locusStatistics.getRawCoverage() == 0 ? CALL : null; + public CallableStatus status(AbstractStratification statistics) { + final LocusStratification locusStratification = (LocusStratification) statistics; + return locusStratification.getRawCoverage() == 0 ? CALL : null; } @Override - public CallableStatus sampleStatus(SampleStatistics sampleStatistics) { - return PluginUtils.genericSampleStatus(sampleStatistics, CALL, threshold); + public CallableStatus sampleStatus(SampleStratification sampleStratification) { + return PluginUtils.genericSampleStatus(sampleStratification, CALL, threshold); } } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusExcessiveCoverage.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusMetricExcessiveCoverage.java similarity index 94% rename from protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusExcessiveCoverage.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusMetricExcessiveCoverage.java index ef1d7ffde..fbedc5404 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusExcessiveCoverage.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusMetricExcessiveCoverage.java @@ -51,7 +51,7 @@ package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; * Date: 4/20/13 * Time: 11:44 PM */ -final class LocusExcessiveCoverage implements Locus { +final class LocusMetricExcessiveCoverage implements LocusMetric { private int excessiveCoverage; private double threshold; private static final CallableStatus CALL = CallableStatus.EXCESSIVE_COVERAGE ; @@ -63,13 +63,13 @@ final class LocusExcessiveCoverage implements Locus { } @Override - public CallableStatus status(AbstractStatistics statistics) { - final LocusStatistics locusStatistics = (LocusStatistics) statistics; - return locusStatistics.getCoverage() > excessiveCoverage ? CALL : null; + public CallableStatus status(AbstractStratification statistics) { + final LocusStratification locusStratification = (LocusStratification) statistics; + return locusStratification.getCoverage() > excessiveCoverage ? CALL : null; } @Override - public CallableStatus sampleStatus(SampleStatistics sampleStatistics) { - return PluginUtils.genericSampleStatus(sampleStatistics, CALL, threshold); + public CallableStatus sampleStatus(SampleStratification sampleStratification) { + return PluginUtils.genericSampleStatus(sampleStratification, CALL, threshold); } } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusLowCoverage.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusMetricLowCoverage.java similarity index 95% rename from protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusLowCoverage.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusMetricLowCoverage.java index f421f5142..5b5015beb 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusLowCoverage.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusMetricLowCoverage.java @@ -51,7 +51,7 @@ package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; * Date: 4/20/13 * Time: 11:44 PM */ -final class LocusLowCoverage implements Locus { +final class LocusMetricLowCoverage implements LocusMetric { private int minCoverage; private double threshold; private static final CallableStatus CALL = CallableStatus.LOW_COVERAGE ; @@ -63,14 +63,14 @@ final class LocusLowCoverage implements Locus { } @Override - public CallableStatus status(AbstractStatistics statistics) { - final LocusStatistics locusStatistics = (LocusStatistics) statistics; - final long raw = locusStatistics.getRawCoverage(); + public CallableStatus status(AbstractStratification statistics) { + final LocusStratification locusStratification = (LocusStratification) statistics; + final long raw = locusStratification.getRawCoverage(); return raw > 0 && raw < minCoverage ? CALL: null; } @Override - public CallableStatus sampleStatus(SampleStatistics sampleStatistics) { - return PluginUtils.genericSampleStatus(sampleStatistics, CALL, threshold); + public CallableStatus sampleStatus(SampleStratification sampleStratification) { + return PluginUtils.genericSampleStatus(sampleStratification, CALL, threshold); } } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusPoorQuality.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusMetricPoorQuality.java similarity index 94% rename from protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusPoorQuality.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusMetricPoorQuality.java index 042ebcbf8..53c07d421 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusPoorQuality.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusMetricPoorQuality.java @@ -51,7 +51,7 @@ package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; * Date: 4/20/13 * Time: 11:44 PM */ -final class LocusPoorQuality implements Locus { +final class LocusMetricPoorQuality implements LocusMetric { private int minCoverage; private double threshold; private static final CallableStatus CALL = CallableStatus.POOR_QUALITY ; @@ -63,13 +63,13 @@ final class LocusPoorQuality implements Locus { } @Override - public CallableStatus status(AbstractStatistics statistics) { - final LocusStatistics locusStatistics = (LocusStatistics) statistics; - return locusStatistics.getCoverage() < minCoverage && locusStatistics.getRawCoverage() >= minCoverage ? CALL: null; + public CallableStatus status(AbstractStratification statistics) { + final LocusStratification locusStratification = (LocusStratification) statistics; + return locusStratification.getCoverage() < minCoverage && locusStratification.getRawCoverage() >= minCoverage ? CALL: null; } @Override - public CallableStatus sampleStatus(SampleStatistics sampleStatistics) { - return PluginUtils.genericSampleStatus(sampleStatistics, CALL, threshold); + public CallableStatus sampleStatus(SampleStratification sampleStratification) { + return PluginUtils.genericSampleStatus(sampleStratification, CALL, threshold); } } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusStatistics.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusStratification.java similarity index 95% rename from protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusStatistics.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusStratification.java index b5a9373d5..d6acaf850 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusStatistics.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusStratification.java @@ -49,19 +49,19 @@ package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; import java.util.LinkedList; import java.util.List; -final class LocusStatistics extends AbstractStatistics{ +final class LocusStratification extends AbstractStratification { private long coverage; private long rawCoverage; - private final List locusStatisticsList; + private final List locusStatisticsList; - public LocusStatistics(ThresHolder thresholds) { + public LocusStratification(ThresHolder thresholds) { this(0,0,thresholds); } - protected LocusStatistics(int coverage, int rawCoverage, ThresHolder thresholds) { + protected LocusStratification(int coverage, int rawCoverage, ThresHolder thresholds) { this.coverage = coverage; this.rawCoverage = rawCoverage; - this.locusStatisticsList = thresholds.locusStatisticList; + this.locusStatisticsList = thresholds.locusMetricList; } @Override @@ -80,7 +80,7 @@ final class LocusStatistics extends AbstractStatistics{ */ public List callableStatuses() { List output = new LinkedList(); - for (Statistic stats : locusStatisticsList) { + for (Metric stats : locusStatisticsList) { CallableStatus status = stats.status(this); if (status != null) { output.add(status); @@ -90,7 +90,7 @@ final class LocusStatistics extends AbstractStatistics{ } @Override - public Iterable getElements() { + public Iterable getElements() { return null; } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Statistic.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Metric.java similarity index 98% rename from protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Statistic.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Metric.java index c43b00a65..6f13b9cac 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Statistic.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Metric.java @@ -51,7 +51,7 @@ package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; * @author Mauricio Carneiro * @since 4/23/13 */ -interface Statistic { +interface Metric { public void initialize(ThresHolder thresholds); - public CallableStatus status (AbstractStatistics statistic); + public CallableStatus status (AbstractStratification statistic); } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/PluginUtils.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/PluginUtils.java index cb28e0ac5..1085e8cac 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/PluginUtils.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/PluginUtils.java @@ -54,9 +54,9 @@ import java.util.Map; * Time: 11:23 AM */ final class PluginUtils { - public static CallableStatus genericSampleStatus (final SampleStatistics sampleStatistics, final CallableStatus CALL, final double threshold) { - final Map totals = sampleStatistics.getStatusTally(); - final int size = sampleStatistics.getIntervalSize(); + public static CallableStatus genericSampleStatus (final SampleStratification sampleStratification, final CallableStatus CALL, final double threshold) { + final Map totals = sampleStratification.getStatusTally(); + final int size = sampleStratification.getIntervalSize(); final int statusCount = totals.containsKey(CALL) ? totals.get(CALL) : 0; return ( (double) statusCount / size) >= threshold ? CALL: null; } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Interval.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleMetric.java similarity index 99% rename from protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Interval.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleMetric.java index bd8307f89..8de33b269 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/Interval.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleMetric.java @@ -53,5 +53,5 @@ package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; * Time: 11:30 PM * To change this template use File | Settings | File Templates. */ -interface Interval extends Statistic { +interface SampleMetric extends Metric { } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleBadMates.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleMetricBadMates.java similarity index 95% rename from protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleBadMates.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleMetricBadMates.java index 483f63c06..cf5aac4a6 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleBadMates.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleMetricBadMates.java @@ -51,7 +51,7 @@ package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; * Date: 4/20/13 * Time: 11:44 PM */ -final class SampleBadMates implements Sample { +final class SampleMetricBadMates implements SampleMetric { private static final CallableStatus CALL = CallableStatus.NO_READS ; private double threshold; @@ -64,10 +64,10 @@ final class SampleBadMates implements Sample { } @Override - public CallableStatus status(AbstractStatistics statistics) { - final SampleStatistics sampleStatistics = (SampleStatistics) statistics; - final int nReads = sampleStatistics.getnReads(); - return nReads > 0 && (double) sampleStatistics.getnBadMates() / nReads > threshold ? CALL : null; + public CallableStatus status(AbstractStratification statistics) { + final SampleStratification sampleStratification = (SampleStratification) statistics; + final int nReads = sampleStratification.getnReads(); + return nReads > 0 && (double) sampleStratification.getnBadMates() / nReads > threshold ? CALL : null; } } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleNoReads.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleMetricNoReads.java similarity index 96% rename from protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleNoReads.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleMetricNoReads.java index 1c6d3deb7..bf9e7420d 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleNoReads.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleMetricNoReads.java @@ -51,16 +51,16 @@ package org.broadinstitute.sting.gatk.walkers.diagnostics.diagnosetargets; * Date: 4/20/13 * Time: 11:44 PM */ -final class SampleNoReads implements Sample { +final class SampleMetricNoReads implements SampleMetric { private static final CallableStatus CALL = CallableStatus.NO_READS; @Override public void initialize(ThresHolder thresholds) { } @Override - public CallableStatus status(AbstractStatistics statistics) { - final SampleStatistics sampleStatistics = (SampleStatistics) statistics; - return sampleStatistics.getnReads() == 0 ? CALL : null; + public CallableStatus status(AbstractStratification statistics) { + final SampleStratification sampleStratification = (SampleStratification) statistics; + return sampleStratification.getnReads() == 0 ? CALL : null; } } diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleStatistics.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleStratification.java similarity index 93% rename from protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleStatistics.java rename to protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleStratification.java index 4d41fea16..b9ae1f3cf 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleStatistics.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/SampleStratification.java @@ -51,30 +51,31 @@ import org.broadinstitute.sting.utils.exceptions.ReviewedStingException; import org.broadinstitute.sting.utils.pileup.ReadBackedPileup; import org.broadinstitute.sting.utils.sam.GATKSAMRecord; -import java.util.*; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; /** * The statistics calculator for a specific sample given the interval */ -final class SampleStatistics extends AbstractStatistics { +final class SampleStratification extends AbstractStratification { private final GenomeLoc interval; - private final ArrayList loci; + private final ArrayList loci; private final ThresHolder thresholds; - private Map locusStatusTally = null; private int nReads = -1; private int nBadMates = -1; - public SampleStatistics(final GenomeLoc interval, final ThresHolder thresholds) { + public SampleStratification(final GenomeLoc interval, final ThresHolder thresholds) { this.interval = interval; - this.loci = new ArrayList(interval.size()); + this.loci = new ArrayList(interval.size()); this.thresholds = thresholds; nReads = 0; nBadMates = 0; // Initialize every loci (this way we don't have to worry about non-existent loci in the object for (int i = 0; i < interval.size(); i++) - this.loci.add(new LocusStatistics(thresholds)); + this.loci.add(new LocusStratification(thresholds)); } /** @@ -99,7 +100,7 @@ final class SampleStatistics extends AbstractStatistics { final int locusIndex = locus.getStart() - interval.getStart(); final int rawCoverage = pileup.depthOfCoverage(); final int coverage = pileup.getBaseAndMappingFilteredPileup(thresholds.minimumBaseQuality, thresholds.minimumMappingQuality).depthOfCoverage(); - final LocusStatistics locusData = (LocusStatistics) loci.get(locusIndex); + final LocusStratification locusData = (LocusStratification) loci.get(locusIndex); locusData.addLocus(coverage, rawCoverage); // process all the reads in this pileup (tallying number of reads and bad mates) @@ -109,7 +110,7 @@ final class SampleStatistics extends AbstractStatistics { } @Override - public Iterable getElements() { + public Iterable getElements() { return loci; } @@ -121,15 +122,15 @@ final class SampleStatistics extends AbstractStatistics { final List output = new LinkedList(); // get the tally of all the locus callable statuses - for (Statistic locusStat : thresholds.locusStatisticList) { - final CallableStatus status = ((Locus) locusStat).sampleStatus(this); + for (Metric locusStat : thresholds.locusMetricList) { + final CallableStatus status = ((LocusMetric) locusStat).sampleStatus(this); if (status != null) { output.add(status); } } // get the sample specific statitics statuses - for (Statistic sampleStat : thresholds.sampleStatisticList) { + for (Metric sampleStat : thresholds.sampleMetricList) { final CallableStatus status = sampleStat.status(this); if (status != null) { output.add(status); diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/ThresHolder.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/ThresHolder.java index 42c09dda1..b0c999460 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/ThresHolder.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/ThresHolder.java @@ -114,9 +114,9 @@ final class ThresHolder { @Argument(fullName = "quality_status_threshold", shortName = "stQ", doc = "The proportion of the loci needed for calling POOR_QUALITY", required = false) public double qualityStatusThreshold = 0.50; - public final List locusStatisticList = new LinkedList(); - public final List sampleStatisticList = new LinkedList(); - public final List intervalStatisticList = new LinkedList(); + public final List locusMetricList = new LinkedList(); + public final List sampleMetricList = new LinkedList(); + public final List intervalMetricList = new LinkedList(); public ThresHolder() {} diff --git a/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusStatisticsUnitTest.java b/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusStatisticsUnitTest.java index d784c2a9e..fe3010e02 100644 --- a/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusStatisticsUnitTest.java +++ b/protected/java/test/org/broadinstitute/sting/gatk/walkers/diagnostics/diagnosetargets/LocusStatisticsUnitTest.java @@ -64,7 +64,7 @@ public class LocusStatisticsUnitTest { @Test(dataProvider = "StatusTestValues") public void testCallableStatuses(int coverage, int rawCoverage, CallableStatus status) { - List statuses = new LocusStatistics(coverage, rawCoverage, thresholds).callableStatuses(); + List statuses = new LocusStratification(coverage, rawCoverage, thresholds).callableStatuses(); Assert.assertTrue((status == null) ? statuses.isEmpty() : (statuses.contains(status) && statuses.size() == 1)); }