From 7e04313b4ed8f0029efa3ab7cd2ee31a3183787b Mon Sep 17 00:00:00 2001 From: depristo Date: Tue, 21 Jul 2009 11:55:05 +0000 Subject: [PATCH] Bug fixes and improvements to CoverageHistogram. Now displays the frequency of the bin. Also correctly prints out the last element in the coverage histogram (<= vs. <) git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1284 348d0f76-0448-11de-a6fe-93d51630548a --- .../gatk/walkers/CoverageHistogram.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/CoverageHistogram.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/CoverageHistogram.java index f2cb27401..c375d4112 100644 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/CoverageHistogram.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/CoverageHistogram.java @@ -29,7 +29,7 @@ public class CoverageHistogram extends LocusWalker //@Argument(fullName="start", shortName="start", required=false, doc="start") public Integer START = 0; // Private state. - int[] coverage_hist; + long[] coverage_hist; int max_depth; long sum_coverage; @@ -39,7 +39,8 @@ public class CoverageHistogram extends LocusWalker // Walker Interface Functions public void initialize() { - coverage_hist = new int[1000000]; + coverage_hist = new long[1000000]; + Arrays.fill(coverage_hist, 0); max_depth = 0; sum_coverage = 0; @@ -62,13 +63,13 @@ public class CoverageHistogram extends LocusWalker public void onTraversalDone(Integer sum) { double mean_coverage = (double)sum_coverage / (double)num_sites; - out.printf("# all_sites : mean:%f num_sites:%d\n\n", mean_coverage, num_sites); - out.printf("# sites with at least 1 read : mean:%f num_sites:%d\n\n", sum_coverage / ((double)(num_sites - coverage_hist[0])), num_sites - coverage_hist[0]); + out.printf("# all_sites : mean:%f num_sites:%d%n", mean_coverage, num_sites); + out.printf("# sites with at least 1 read : mean:%f num_sites:%d%n%n", sum_coverage / ((double)(num_sites - coverage_hist[0])), num_sites - coverage_hist[0]); - out.println("depth count"); - for (int i = 0; i < max_depth; i++) + out.println("depth count freq"); + for (int i = 0; i <= max_depth; i++) { - out.printf("%d %d\n", i, coverage_hist[i]); + out.printf("%d %d %f\n", i, coverage_hist[i], (100.0*coverage_hist[i]) / num_sites); } return; }