{"action":"created","comment":{"url":"https://api.github.com/repos/broadinstitute/picard/pulls/comments/80308475","id":80308475,"diff_hunk":"@@ -583,69 +606,78 @@ protected WgsMetricsCollector getCollector(final int coverageCap, final Interval\n         protected final int coverageCap;\n \n         public WgsMetricsCollector(final int coverageCap, final IntervalList intervals) {\n-            depthHistogramArray = new long[coverageCap + 1];\n-            baseQHistogramArray = new long[Byte.MAX_VALUE];\n+            unfilteredDepthHistogramArray = new long[coverageCap + 1];\n+            highQualityDepthHistogramArray = new long[coverageCap + 1];\n+            unfilteredBaseQHistogramArray = new long[Byte.MAX_VALUE];\n             this.coverageCap    = coverageCap;\n             this.intervals      = intervals;\n         }\n \n-        public void addInfo(final SamLocusIterator.LocusInfo info, final ReferenceSequence ref) {\n+        public void addInfo(final SamLocusIterator.LocusInfo info) {\n \n             // Figure out the coverage while not counting overlapping reads twice, and excluding various things\n             final HashSet<String> readNames = new HashSet<>(info.getRecordAndPositions().size());\n             int pileupSize = 0;\n+            int unfilteredDepth = 0;\n+\n             for (final SamLocusIterator.RecordAndOffset recs : info.getRecordAndPositions()) {\n+                if (recs.getBaseQuality() <= 2) { ++basesExcludedByBaseq;   continue; }\n+\n+                // we add to the base quality histogram any bases that have quality > 2\n+                // the raw depth may exceed the coverageCap before the high-quality depth does. So stop counting once we reach the coverage cap.\n+                if (unfilteredDepth < coverageCap) {\n+                    unfilteredBaseQHistogramArray[recs.getRecord().getBaseQualities()[recs.getOffset()]]++;\n+                    unfilteredDepth++;\n+                }\n \n                 if (recs.getBaseQuality() < MINIMUM_BASE_QUALITY ||\n                         SequenceUtil.isNoCall(recs.getReadBase()))                  { ++basesExcludedByBaseq;   continue; }\n                 if (!readNames.add(recs.getRecord().getReadName()))                 { ++basesExcludedByOverlap; continue; }\n \n                 pileupSize++;\n-                if (pileupSize <= coverageCap) {\n-                    baseQHistogramArray[recs.getRecord().getBaseQualities()[recs.getOffset()]]++;\n-                }\n             }\n \n-            final int depth = Math.min(pileupSize, coverageCap);\n-            if (depth < pileupSize) basesExcludedByCapping += pileupSize - coverageCap;\n-            depthHistogramArray[depth]++;\n+            final int highQualityDepth = Math.min(pileupSize, coverageCap);\n+            if (highQualityDepth < pileupSize) basesExcludedByCapping += pileupSize - coverageCap;\n+            highQualityDepthHistogramArray[highQualityDepth]++;\n+            unfilteredDepthHistogramArray[unfilteredDepth]++;\n+\n+            // check that we added the same number of bases to the raw coverage histogram and the base quality histograms\n+            if (Arrays.stream(unfilteredBaseQHistogramArray).sum() !=  LongStream.rangeClosed(0,coverageCap).map(i -> (i * unfilteredDepthHistogramArray[(int)i])).sum()) {\n+                throw new PicardException(\"updated coverage and baseQ distributions unequally\");\n+            }\n         }\n \n         public void addToMetricsFile(final MetricsFile<WgsMetrics, Integer> file,\n                                      final boolean includeBQHistogram,\n                                      final CountingFilter dupeFilter,\n                                      final CountingFilter mapqFilter,\n                                      final CountingPairedFilter pairFilter) {\n-            addMetricsToFile(file, dupeFilter, mapqFilter, pairFilter);\n+            final WgsMetrics metrics = getMetrics(dupeFilter, mapqFilter, pairFilter);\n+\n+            // add them to the file\n+            file.addMetric(metrics);\n+            file.addHistogram(getHighQualityDepthHistogram());\n \n             if (includeBQHistogram) {\n                 addBaseQHistogram(file);\n             }\n         }\n \n         protected void addBaseQHistogram(final MetricsFile<WgsMetrics, Integer> file) {\n-            file.addHistogram(getBaseQHistogram());\n+            file.addHistogram(getUnfilteredBaseQHistogram());\n         }\n \n-        protected void addMetricsToFile(final MetricsFile<WgsMetrics, Integer> file,\n-                                        final CountingFilter dupeFilter,\n-                                        final CountingFilter mapqFilter,\n-                                        final CountingPairedFilter pairFilter) {\n-            // get the depth histogram and metrics\n-            final Histogram<Integer> depthHistogram = getDepthHistogram();\n-            final WgsMetrics metrics = getMetrics(depthHistogram, dupeFilter, mapqFilter, pairFilter);\n-\n-            // add them to the file\n-            file.addMetric(metrics);\n-            file.addHistogram(depthHistogram);\n+        protected Histogram<Integer> getHighQualityDepthHistogram() {\n+            return getHistogram(highQualityDepthHistogramArray,\"coverage\", \"count\");\n         }\n \n-        protected Histogram<Integer> getDepthHistogram() {\n-            return getHistogram(depthHistogramArray,\"coverage\", \"count\");\n+        protected Histogram<Integer> getUnfilteredDepthHistogram(){\n+            return getHistogram(unfilteredDepthHistogramArray, \"coverage\", \"count\");","path":"src/main/java/picard/analysis/CollectWgsMetrics.java","position":393,"original_position":393,"commit_id":"8a6264b2ad468be694ae9cbffd76929c05f129ed","original_commit_id":"8a6264b2ad468be694ae9cbffd76929c05f129ed","user":{"login":"yfarjoun","id":2745554,"avatar_url":"https://avatars.githubusercontent.com/u/2745554?v=3","gravatar_id":"","url":"https://api.github.com/users/yfarjoun","html_url":"https://github.com/yfarjoun","followers_url":"https://api.github.com/users/yfarjoun/followers","following_url":"https://api.github.com/users/yfarjoun/following{/other_user}","gists_url":"https://api.github.com/users/yfarjoun/gists{/gist_id}","starred_url":"https://api.github.com/users/yfarjoun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yfarjoun/subscriptions","organizations_url":"https://api.github.com/users/yfarjoun/orgs","repos_url":"https://api.github.com/users/yfarjoun/repos","events_url":"https://api.github.com/users/yfarjoun/events{/privacy}","received_events_url":"https://api.github.com/users/yfarjoun/received_events","type":"User","site_admin":false},"body":"...UnfilteredDepthCount","created_at":"2016-09-23T19:11:18Z","updated_at":"2016-09-23T19:11:18Z","html_url":"https://github.com/broadinstitute/picard/pull/658#discussion_r80308475","pull_request_url":"https://api.github.com/repos/broadinstitute/picard/pulls/658","_links":{"self":{"href":"https://api.github.com/repos/broadinstitute/picard/pulls/comments/80308475"},"html":{"href":"https://github.com/broadinstitute/picard/pull/658#discussion_r80308475"},"pull_request":{"href":"https://api.github.com/repos/broadinstitute/picard/pulls/658"}}},"pull_request":{"url":"https://api.github.com/repos/broadinstitute/picard/pulls/658","id":85872071,"html_url":"https://github.com/broadinstitute/picard/pull/658","diff_url":"https://github.com/broadinstitute/picard/pull/658.diff","patch_url":"https://github.com/broadinstitute/picard/pull/658.patch","issue_url":"https://api.github.com/repos/broadinstitute/picard/issues/658","number":658,"state":"open","locked":false,"title":"Include low quality bases in depth and base quality histograms for theoretical het sensitivity","user":{"login":"takutosato","id":5185538,"avatar_url":"https://avatars.githubusercontent.com/u/5185538?v=3","gravatar_id":"","url":"https://api.github.com/users/takutosato","html_url":"https://github.com/takutosato","followers_url":"https://api.github.com/users/takutosato/followers","following_url":"https://api.github.com/users/takutosato/following{/other_user}","gists_url":"https://api.github.com/users/takutosato/gists{/gist_id}","starred_url":"https://api.github.com/users/takutosato/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/takutosato/subscriptions","organizations_url":"https://api.github.com/users/takutosato/orgs","repos_url":"https://api.github.com/users/takutosato/repos","events_url":"https://api.github.com/users/takutosato/events{/privacy}","received_events_url":"https://api.github.com/users/takutosato/received_events","type":"User","site_admin":false},"body":"We now store two depth histograms: `unfilteredDepthHistogram` and `highQualityDepthHistogram`. The former includes all but quality 2 bases, and the latter includes bases with quality greater than or equal to `MINIMUM_BASE_QUALITY` (default 20). Base quality histogram adopts the 'unfiltered' rule. With this change we hope to improve theoretical het sensitivity estimates.\r\n\r\nAlso included in this PR: in `TargetMetricsCollector.java`, we used to double-count the zero-bin of coverageDistribution when the target had no coverage (once in line 624 and again in 630). This did not affect the metrics (as far as I can tell) but over-counted the zero-depth bin in the depth histogram. I fixed the bug and added a test: `testCoverageHistogram` in `CollectHsMetricsTest`.\r\n\r\nIt also fixes a couple bugs in `CollectWgsMetricsWithNonZeroCoverage`. I commented out the code that called out to R code to plot the depth histograms as I couldn't get it to work.\r\n\r\nNote: three tests are failing. One is a deprecated test, and the change in het sensitivity is expected. The other two (\"Contig too big [0 < 0\") I cannot reproduce locally.","created_at":"2016-09-19T21:22:07Z","updated_at":"2016-09-23T19:11:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8b31492dace242fbff59f106651cb3e01d5ddafe","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/broadinstitute/picard/pulls/658/commits","review_comments_url":"https://api.github.com/repos/broadinstitute/picard/pulls/658/comments","review_comment_url":"https://api.github.com/repos/broadinstitute/picard/pulls/comments{/number}","comments_url":"https://api.github.com/repos/broadinstitute/picard/issues/658/comments","statuses_url":"https://api.github.com/repos/broadinstitute/picard/statuses/8a6264b2ad468be694ae9cbffd76929c05f129ed","head":{"label":"broadinstitute:ts_het_sensitivity2","ref":"ts_het_sensitivity2","sha":"8a6264b2ad468be694ae9cbffd76929c05f129ed","user":{"login":"broadinstitute","id":393552,"avatar_url":"https://avatars.githubusercontent.com/u/393552?v=3","gravatar_id":"","url":"https://api.github.com/users/broadinstitute","html_url":"https://github.com/broadinstitute","followers_url":"https://api.github.com/users/broadinstitute/followers","following_url":"https://api.github.com/users/broadinstitute/following{/other_user}","gists_url":"https://api.github.com/users/broadinstitute/gists{/gist_id}","starred_url":"https://api.github.com/users/broadinstitute/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/broadinstitute/subscriptions","organizations_url":"https://api.github.com/users/broadinstitute/orgs","repos_url":"https://api.github.com/users/broadinstitute/repos","events_url":"https://api.github.com/users/broadinstitute/events{/privacy}","received_events_url":"https://api.github.com/users/broadinstitute/received_events","type":"Organization","site_admin":false},"repo":{"id":18225913,"name":"picard","full_name":"broadinstitute/picard","owner":{"login":"broadinstitute","id":393552,"avatar_url":"https://avatars.githubusercontent.com/u/393552?v=3","gravatar_id":"","url":"https://api.github.com/users/broadinstitute","html_url":"https://github.com/broadinstitute","followers_url":"https://api.github.com/users/broadinstitute/followers","following_url":"https://api.github.com/users/broadinstitute/following{/other_user}","gists_url":"https://api.github.com/users/broadinstitute/gists{/gist_id}","starred_url":"https://api.github.com/users/broadinstitute/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/broadinstitute/subscriptions","organizations_url":"https://api.github.com/users/broadinstitute/orgs","repos_url":"https://api.github.com/users/broadinstitute/repos","events_url":"https://api.github.com/users/broadinstitute/events{/privacy}","received_events_url":"https://api.github.com/users/broadinstitute/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/broadinstitute/picard","description":"A set of command line tools (in Java) for manipulating high-throughput sequencing (HTS) data and formats such as SAM/BAM/CRAM and VCF.","fork":false,"url":"https://api.github.com/repos/broadinstitute/picard","forks_url":"https://api.github.com/repos/broadinstitute/picard/forks","keys_url":"https://api.github.com/repos/broadinstitute/picard/keys{/key_id}","collaborators_url":"https://api.github.com/repos/broadinstitute/picard/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/broadinstitute/picard/teams","hooks_url":"https://api.github.com/repos/broadinstitute/picard/hooks","issue_events_url":"https://api.github.com/repos/broadinstitute/picard/issues/events{/number}","events_url":"https://api.github.com/repos/broadinstitute/picard/events","assignees_url":"https://api.github.com/repos/broadinstitute/picard/assignees{/user}","branches_url":"https://api.github.com/repos/broadinstitute/picard/branches{/branch}","tags_url":"https://api.github.com/repos/broadinstitute/picard/tags","blobs_url":"https://api.github.com/repos/broadinstitute/picard/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/broadinstitute/picard/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/broadinstitute/picard/git/refs{/sha}","trees_url":"https://api.github.com/repos/broadinstitute/picard/git/trees{/sha}","statuses_url":"https://api.github.com/repos/broadinstitute/picard/statuses/{sha}","languages_url":"https://api.github.com/repos/broadinstitute/picard/languages","stargazers_url":"https://api.github.com/repos/broadinstitute/picard/stargazers","contributors_url":"https://api.github.com/repos/broadinstitute/picard/contributors","subscribers_url":"https://api.github.com/repos/broadinstitute/picard/subscribers","subscription_url":"https://api.github.com/repos/broadinstitute/picard/subscription","commits_url":"https://api.github.com/repos/broadinstitute/picard/commits{/sha}","git_commits_url":"https://api.github.com/repos/broadinstitute/picard/git/commits{/sha}","comments_url":"https://api.github.com/repos/broadinstitute/picard/comments{/number}","issue_comment_url":"https://api.github.com/repos/broadinstitute/picard/issues/comments{/number}","contents_url":"https://api.github.com/repos/broadinstitute/picard/contents/{+path}","compare_url":"https://api.github.com/repos/broadinstitute/picard/compare/{base}...{head}","merges_url":"https://api.github.com/repos/broadinstitute/picard/merges","archive_url":"https://api.github.com/repos/broadinstitute/picard/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/broadinstitute/picard/downloads","issues_url":"https://api.github.com/repos/broadinstitute/picard/issues{/number}","pulls_url":"https://api.github.com/repos/broadinstitute/picard/pulls{/number}","milestones_url":"https://api.github.com/repos/broadinstitute/picard/milestones{/number}","notifications_url":"https://api.github.com/repos/broadinstitute/picard/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/broadinstitute/picard/labels{/name}","releases_url":"https://api.github.com/repos/broadinstitute/picard/releases{/id}","deployments_url":"https://api.github.com/repos/broadinstitute/picard/deployments","created_at":"2014-03-28T20:43:35Z","updated_at":"2016-09-21T08:26:48Z","pushed_at":"2016-09-23T18:30:57Z","git_url":"git://github.com/broadinstitute/picard.git","ssh_url":"git@github.com:broadinstitute/picard.git","clone_url":"https://github.com/broadinstitute/picard.git","svn_url":"https://github.com/broadinstitute/picard","homepage":"http://broadinstitute.github.io/picard/","size":67504,"stargazers_count":212,"watchers_count":212,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":144,"mirror_url":null,"open_issues_count":107,"forks":144,"open_issues":107,"watchers":212,"default_branch":"master"}},"base":{"label":"broadinstitute:master","ref":"master","sha":"915ffa737d9b147b6aa7c7336e2bb5447a2c31df","user":{"login":"broadinstitute","id":393552,"avatar_url":"https://avatars.githubusercontent.com/u/393552?v=3","gravatar_id":"","url":"https://api.github.com/users/broadinstitute","html_url":"https://github.com/broadinstitute","followers_url":"https://api.github.com/users/broadinstitute/followers","following_url":"https://api.github.com/users/broadinstitute/following{/other_user}","gists_url":"https://api.github.com/users/broadinstitute/gists{/gist_id}","starred_url":"https://api.github.com/users/broadinstitute/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/broadinstitute/subscriptions","organizations_url":"https://api.github.com/users/broadinstitute/orgs","repos_url":"https://api.github.com/users/broadinstitute/repos","events_url":"https://api.github.com/users/broadinstitute/events{/privacy}","received_events_url":"https://api.github.com/users/broadinstitute/received_events","type":"Organization","site_admin":false},"repo":{"id":18225913,"name":"picard","full_name":"broadinstitute/picard","owner":{"login":"broadinstitute","id":393552,"avatar_url":"https://avatars.githubusercontent.com/u/393552?v=3","gravatar_id":"","url":"https://api.github.com/users/broadinstitute","html_url":"https://github.com/broadinstitute","followers_url":"https://api.github.com/users/broadinstitute/followers","following_url":"https://api.github.com/users/broadinstitute/following{/other_user}","gists_url":"https://api.github.com/users/broadinstitute/gists{/gist_id}","starred_url":"https://api.github.com/users/broadinstitute/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/broadinstitute/subscriptions","organizations_url":"https://api.github.com/users/broadinstitute/orgs","repos_url":"https://api.github.com/users/broadinstitute/repos","events_url":"https://api.github.com/users/broadinstitute/events{/privacy}","received_events_url":"https://api.github.com/users/broadinstitute/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/broadinstitute/picard","description":"A set of command line tools (in Java) for manipulating high-throughput sequencing (HTS) data and formats such as SAM/BAM/CRAM and VCF.","fork":false,"url":"https://api.github.com/repos/broadinstitute/picard","forks_url":"https://api.github.com/repos/broadinstitute/picard/forks","keys_url":"https://api.github.com/repos/broadinstitute/picard/keys{/key_id}","collaborators_url":"https://api.github.com/repos/broadinstitute/picard/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/broadinstitute/picard/teams","hooks_url":"https://api.github.com/repos/broadinstitute/picard/hooks","issue_events_url":"https://api.github.com/repos/broadinstitute/picard/issues/events{/number}","events_url":"https://api.github.com/repos/broadinstitute/picard/events","assignees_url":"https://api.github.com/repos/broadinstitute/picard/assignees{/user}","branches_url":"https://api.github.com/repos/broadinstitute/picard/branches{/branch}","tags_url":"https://api.github.com/repos/broadinstitute/picard/tags","blobs_url":"https://api.github.com/repos/broadinstitute/picard/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/broadinstitute/picard/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/broadinstitute/picard/git/refs{/sha}","trees_url":"https://api.github.com/repos/broadinstitute/picard/git/trees{/sha}","statuses_url":"https://api.github.com/repos/broadinstitute/picard/statuses/{sha}","languages_url":"https://api.github.com/repos/broadinstitute/picard/languages","stargazers_url":"https://api.github.com/repos/broadinstitute/picard/stargazers","contributors_url":"https://api.github.com/repos/broadinstitute/picard/contributors","subscribers_url":"https://api.github.com/repos/broadinstitute/picard/subscribers","subscription_url":"https://api.github.com/repos/broadinstitute/picard/subscription","commits_url":"https://api.github.com/repos/broadinstitute/picard/commits{/sha}","git_commits_url":"https://api.github.com/repos/broadinstitute/picard/git/commits{/sha}","comments_url":"https://api.github.com/repos/broadinstitute/picard/comments{/number}","issue_comment_url":"https://api.github.com/repos/broadinstitute/picard/issues/comments{/number}","contents_url":"https://api.github.com/repos/broadinstitute/picard/contents/{+path}","compare_url":"https://api.github.com/repos/broadinstitute/picard/compare/{base}...{head}","merges_url":"https://api.github.com/repos/broadinstitute/picard/merges","archive_url":"https://api.github.com/repos/broadinstitute/picard/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/broadinstitute/picard/downloads","issues_url":"https://api.github.com/repos/broadinstitute/picard/issues{/number}","pulls_url":"https://api.github.com/repos/broadinstitute/picard/pulls{/number}","milestones_url":"https://api.github.com/repos/broadinstitute/picard/milestones{/number}","notifications_url":"https://api.github.com/repos/broadinstitute/picard/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/broadinstitute/picard/labels{/name}","releases_url":"https://api.github.com/repos/broadinstitute/picard/releases{/id}","deployments_url":"https://api.github.com/repos/broadinstitute/picard/deployments","created_at":"2014-03-28T20:43:35Z","updated_at":"2016-09-21T08:26:48Z","pushed_at":"2016-09-23T18:30:57Z","git_url":"git://github.com/broadinstitute/picard.git","ssh_url":"git@github.com:broadinstitute/picard.git","clone_url":"https://github.com/broadinstitute/picard.git","svn_url":"https://github.com/broadinstitute/picard","homepage":"http://broadinstitute.github.io/picard/","size":67504,"stargazers_count":212,"watchers_count":212,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":144,"mirror_url":null,"open_issues_count":107,"forks":144,"open_issues":107,"watchers":212,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/broadinstitute/picard/pulls/658"},"html":{"href":"https://github.com/broadinstitute/picard/pull/658"},"issue":{"href":"https://api.github.com/repos/broadinstitute/picard/issues/658"},"comments":{"href":"https://api.github.com/repos/broadinstitute/picard/issues/658/comments"},"review_comments":{"href":"https://api.github.com/repos/broadinstitute/picard/pulls/658/comments"},"review_comment":{"href":"https://api.github.com/repos/broadinstitute/picard/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/broadinstitute/picard/pulls/658/commits"},"statuses":{"href":"https://api.github.com/repos/broadinstitute/picard/statuses/8a6264b2ad468be694ae9cbffd76929c05f129ed"}}}}
{"actor":{"display_login":"yfarjoun"}}