{"action":"created","comment":{"url":"https://api.github.com/repos/broadinstitute/gatk-protected/pulls/comments/50407524","id":50407524,"diff_hunk":"@@ -0,0 +1,484 @@\n+package org.broadinstitute.hellbender.tools.exome;\n+\n+import com.google.common.collect.Iterators;\n+import org.broadinstitute.hellbender.cmdline.*;\n+import org.broadinstitute.hellbender.cmdline.programgroups.CopyNumberProgramGroup;\n+import org.broadinstitute.hellbender.exceptions.GATKException;\n+import org.broadinstitute.hellbender.exceptions.UserException;\n+import org.broadinstitute.hellbender.tools.exome.hmm.CopyNumberTriStateHiddenMarkovModel;\n+import org.broadinstitute.hellbender.tools.exome.hmm.CopyNumberTriStateHiddenMarkovModelArgumentCollection;\n+import org.broadinstitute.hellbender.utils.IndexRange;\n+import org.broadinstitute.hellbender.utils.MathUtils;\n+import org.broadinstitute.hellbender.utils.QualityUtils;\n+import org.broadinstitute.hellbender.utils.hmm.CopyNumberTriState;\n+import org.broadinstitute.hellbender.utils.hmm.ForwardBackwardAlgorithm;\n+import org.broadinstitute.hellbender.utils.hmm.ViterbiAlgorithm;\n+\n+import java.io.File;\n+import java.io.IOException;\n+import java.util.*;\n+import java.util.stream.Collectors;\n+import java.util.stream.DoubleStream;\n+\n+/**\n+ * Discover potential copy-number segments in input read-counts as the most likely segment sequences\n+ * based on {@link CopyNumberTriStateHiddenMarkovModel} HMM model.\n+ *\n+ * @author Valentin Ruano-Rubio &lt;valentin@broadinstitute.org&gt;\n+ */\n+@CommandLineProgramProperties(\n+        programGroup = CopyNumberProgramGroup.class,\n+        summary = \"Finds possible locations for rare copy number variation events in germline samples using a HMM\",\n+        oneLineSummary = \"Discovers possible location of copy number variation\"\n+)\n+public final class DiscoverCopyNumberTriStateSegments extends CommandLineProgram {\n+\n+    public static final String INPUT_ARE_ZSCORES_FULL_NAME = \"inputAreZscores\";\n+\n+    public static final String INPUT_ARE_ZSCORES_SHORT_NAME = \"zscores\";\n+\n+    /**\n+     * Maximum reportable output quality score; higher quality scores will\n+     * capped to this value.\n+     */\n+    public static final double MAX_QUAL_SCORE = 199.9999;\n+\n+    @ArgumentCollection\n+    protected CopyNumberTriStateHiddenMarkovModelArgumentCollection modelArguments =\n+            new CopyNumberTriStateHiddenMarkovModelArgumentCollection();\n+\n+    @Argument(\n+            doc = \"Indicate whether the input is expressed in z-scores\",\n+            fullName = INPUT_ARE_ZSCORES_FULL_NAME,\n+            shortName = INPUT_ARE_ZSCORES_SHORT_NAME,\n+            optional = false\n+    )\n+    protected boolean inputAreZscores;\n+\n+    @Argument(\n+            doc = \"Input counts\",\n+            fullName = StandardArgumentDefinitions.INPUT_LONG_NAME,\n+            shortName = StandardArgumentDefinitions.INPUT_SHORT_NAME,\n+            optional = false\n+    )\n+    protected File inputFile;\n+\n+    @Argument(\n+            doc = \"Output counts\",\n+            fullName = StandardArgumentDefinitions.OUTPUT_LONG_NAME,\n+            shortName = StandardArgumentDefinitions.OUTPUT_SHORT_NAME,\n+            optional = false\n+    )\n+    protected File outputFile;\n+\n+    @ArgumentCollection\n+    protected TargetArgumentCollection targetArguments = new TargetArgumentCollection(() -> inputFile);\n+\n+    @Override\n+    protected Object doWork() {\n+        final CopyNumberTriStateHiddenMarkovModel model = modelArguments.createModel();\n+        final TargetCollection<Target> targets = targetArguments.readTargetCollection(false);\n+        final ReadCountCollection inputCounts = readAndSortCountsByTargetCoordinates(targets);\n+        checkForMissingTargetsInInputCounts(targets, inputCounts);\n+\n+        final Map<String, List<CopyNumberTriStateSegment>> allSegments =\n+                calculateBestPathSegments(model, inputCounts);\n+\n+        final Iterator<CopyNumberTriStateSegmentRecord> allSegmentsSorted =\n+                composeATargetSortedSegmentRecordIterator(targets, allSegments);\n+\n+        writeSegmentsInOutputFile(allSegmentsSorted);\n+\n+        return \"SUCCESS\";\n+    }\n+\n+    /**\n+     * Writes sorted segments into the output file provided by the user.\n+     * @param allSegmentsSorted iterator that must produce segment records in order.\n+     * @throws org.broadinstitute.hellbender.exceptions.UserException.CouldNotCreateOutputFile if there is any\n+     * issue creating or writing into the output file provided by the user.\n+     */\n+    private void writeSegmentsInOutputFile(final Iterator<CopyNumberTriStateSegmentRecord> allSegmentsSorted) {\n+        try (final CopyNumberTriStateSegmentRecordWriter writer = new CopyNumberTriStateSegmentRecordWriter(outputFile)) {\n+            while (allSegmentsSorted.hasNext()) {\n+                writer.writeRecord(allSegmentsSorted.next());\n+            }\n+        } catch (final IOException ex) {\n+            throw new UserException.CouldNotCreateOutputFile(outputFile, \"problems writing into the output\", ex);\n+        }\n+    }\n+\n+    /**\n+     * Create a merging iterator that sort all the segments across samples based","path":"src/main/java/org/broadinstitute/hellbender/tools/exome/DiscoverCopyNumberTriStateSegments.java","position":112,"original_position":112,"commit_id":"ed694fa96c4e199e590f0bf0d520295d751ee585","original_commit_id":"ed694fa96c4e199e590f0bf0d520295d751ee585","user":{"login":"davidbenjamin","id":8438890,"avatar_url":"https://avatars.githubusercontent.com/u/8438890?v=3","gravatar_id":"","url":"https://api.github.com/users/davidbenjamin","html_url":"https://github.com/davidbenjamin","followers_url":"https://api.github.com/users/davidbenjamin/followers","following_url":"https://api.github.com/users/davidbenjamin/following{/other_user}","gists_url":"https://api.github.com/users/davidbenjamin/gists{/gist_id}","starred_url":"https://api.github.com/users/davidbenjamin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidbenjamin/subscriptions","organizations_url":"https://api.github.com/users/davidbenjamin/orgs","repos_url":"https://api.github.com/users/davidbenjamin/repos","events_url":"https://api.github.com/users/davidbenjamin/events{/privacy}","received_events_url":"https://api.github.com/users/davidbenjamin/received_events","type":"User","site_admin":false},"body":"sorts","created_at":"2016-01-21T14:38:48Z","updated_at":"2016-01-21T14:38:48Z","html_url":"https://github.com/broadinstitute/gatk-protected/pull/313#discussion_r50407524","pull_request_url":"https://api.github.com/repos/broadinstitute/gatk-protected/pulls/313","_links":{"self":{"href":"https://api.github.com/repos/broadinstitute/gatk-protected/pulls/comments/50407524"},"html":{"href":"https://github.com/broadinstitute/gatk-protected/pull/313#discussion_r50407524"},"pull_request":{"href":"https://api.github.com/repos/broadinstitute/gatk-protected/pulls/313"}}},"pull_request":{"url":"https://api.github.com/repos/broadinstitute/gatk-protected/pulls/313","id":56571362,"html_url":"https://github.com/broadinstitute/gatk-protected/pull/313","diff_url":"https://github.com/broadinstitute/gatk-protected/pull/313.diff","patch_url":"https://github.com/broadinstitute/gatk-protected/pull/313.patch","issue_url":"https://api.github.com/repos/broadinstitute/gatk-protected/issues/313","number":313,"state":"open","locked":false,"title":"Germline HMM based CNV segment discovery","user":{"login":"vruano","id":791104,"avatar_url":"https://avatars.githubusercontent.com/u/791104?v=3","gravatar_id":"","url":"https://api.github.com/users/vruano","html_url":"https://github.com/vruano","followers_url":"https://api.github.com/users/vruano/followers","following_url":"https://api.github.com/users/vruano/following{/other_user}","gists_url":"https://api.github.com/users/vruano/gists{/gist_id}","starred_url":"https://api.github.com/users/vruano/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vruano/subscriptions","organizations_url":"https://api.github.com/users/vruano/orgs","repos_url":"https://api.github.com/users/vruano/repos","events_url":"https://api.github.com/users/vruano/events{/privacy}","received_events_url":"https://api.github.com/users/vruano/received_events","type":"User","site_admin":false},"body":"Addresses issue #146.","created_at":"2016-01-20T07:05:40Z","updated_at":"2016-01-21T14:38:48Z","closed_at":null,"merged_at":null,"merge_commit_sha":"774242421001b563f44a1e0b380163cb3c62ba03","assignee":{"login":"davidbenjamin","id":8438890,"avatar_url":"https://avatars.githubusercontent.com/u/8438890?v=3","gravatar_id":"","url":"https://api.github.com/users/davidbenjamin","html_url":"https://github.com/davidbenjamin","followers_url":"https://api.github.com/users/davidbenjamin/followers","following_url":"https://api.github.com/users/davidbenjamin/following{/other_user}","gists_url":"https://api.github.com/users/davidbenjamin/gists{/gist_id}","starred_url":"https://api.github.com/users/davidbenjamin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidbenjamin/subscriptions","organizations_url":"https://api.github.com/users/davidbenjamin/orgs","repos_url":"https://api.github.com/users/davidbenjamin/repos","events_url":"https://api.github.com/users/davidbenjamin/events{/privacy}","received_events_url":"https://api.github.com/users/davidbenjamin/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/broadinstitute/gatk-protected/pulls/313/commits","review_comments_url":"https://api.github.com/repos/broadinstitute/gatk-protected/pulls/313/comments","review_comment_url":"https://api.github.com/repos/broadinstitute/gatk-protected/pulls/comments{/number}","comments_url":"https://api.github.com/repos/broadinstitute/gatk-protected/issues/313/comments","statuses_url":"https://api.github.com/repos/broadinstitute/gatk-protected/statuses/ed694fa96c4e199e590f0bf0d520295d751ee585","head":{"label":"broadinstitute:vrr_hmm_based_caller","ref":"vrr_hmm_based_caller","sha":"ed694fa96c4e199e590f0bf0d520295d751ee585","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":34413897,"name":"gatk-protected","full_name":"broadinstitute/gatk-protected","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/gatk-protected","description":"GATK4 development of the license-protected part of the toolkit","fork":false,"url":"https://api.github.com/repos/broadinstitute/gatk-protected","forks_url":"https://api.github.com/repos/broadinstitute/gatk-protected/forks","keys_url":"https://api.github.com/repos/broadinstitute/gatk-protected/keys{/key_id}","collaborators_url":"https://api.github.com/repos/broadinstitute/gatk-protected/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/broadinstitute/gatk-protected/teams","hooks_url":"https://api.github.com/repos/broadinstitute/gatk-protected/hooks","issue_events_url":"https://api.github.com/repos/broadinstitute/gatk-protected/issues/events{/number}","events_url":"https://api.github.com/repos/broadinstitute/gatk-protected/events","assignees_url":"https://api.github.com/repos/broadinstitute/gatk-protected/assignees{/user}","branches_url":"https://api.github.com/repos/broadinstitute/gatk-protected/branches{/branch}","tags_url":"https://api.github.com/repos/broadinstitute/gatk-protected/tags","blobs_url":"https://api.github.com/repos/broadinstitute/gatk-protected/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/broadinstitute/gatk-protected/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/broadinstitute/gatk-protected/git/refs{/sha}","trees_url":"https://api.github.com/repos/broadinstitute/gatk-protected/git/trees{/sha}","statuses_url":"https://api.github.com/repos/broadinstitute/gatk-protected/statuses/{sha}","languages_url":"https://api.github.com/repos/broadinstitute/gatk-protected/languages","stargazers_url":"https://api.github.com/repos/broadinstitute/gatk-protected/stargazers","contributors_url":"https://api.github.com/repos/broadinstitute/gatk-protected/contributors","subscribers_url":"https://api.github.com/repos/broadinstitute/gatk-protected/subscribers","subscription_url":"https://api.github.com/repos/broadinstitute/gatk-protected/subscription","commits_url":"https://api.github.com/repos/broadinstitute/gatk-protected/commits{/sha}","git_commits_url":"https://api.github.com/repos/broadinstitute/gatk-protected/git/commits{/sha}","comments_url":"https://api.github.com/repos/broadinstitute/gatk-protected/comments{/number}","issue_comment_url":"https://api.github.com/repos/broadinstitute/gatk-protected/issues/comments{/number}","contents_url":"https://api.github.com/repos/broadinstitute/gatk-protected/contents/{+path}","compare_url":"https://api.github.com/repos/broadinstitute/gatk-protected/compare/{base}...{head}","merges_url":"https://api.github.com/repos/broadinstitute/gatk-protected/merges","archive_url":"https://api.github.com/repos/broadinstitute/gatk-protected/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/broadinstitute/gatk-protected/downloads","issues_url":"https://api.github.com/repos/broadinstitute/gatk-protected/issues{/number}","pulls_url":"https://api.github.com/repos/broadinstitute/gatk-protected/pulls{/number}","milestones_url":"https://api.github.com/repos/broadinstitute/gatk-protected/milestones{/number}","notifications_url":"https://api.github.com/repos/broadinstitute/gatk-protected/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/broadinstitute/gatk-protected/labels{/name}","releases_url":"https://api.github.com/repos/broadinstitute/gatk-protected/releases{/id}","created_at":"2015-04-22T20:24:45Z","updated_at":"2016-01-11T17:09:39Z","pushed_at":"2016-01-21T14:32:52Z","git_url":"git://github.com/broadinstitute/gatk-protected.git","ssh_url":"git@github.com:broadinstitute/gatk-protected.git","clone_url":"https://github.com/broadinstitute/gatk-protected.git","svn_url":"https://github.com/broadinstitute/gatk-protected","homepage":null,"size":61529,"stargazers_count":4,"watchers_count":4,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":101,"forks":1,"open_issues":101,"watchers":4,"default_branch":"master"}},"base":{"label":"broadinstitute:master","ref":"master","sha":"f66d461339bb2b5fcce678a6a09a1e7dc0911e36","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":34413897,"name":"gatk-protected","full_name":"broadinstitute/gatk-protected","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/gatk-protected","description":"GATK4 development of the license-protected part of the toolkit","fork":false,"url":"https://api.github.com/repos/broadinstitute/gatk-protected","forks_url":"https://api.github.com/repos/broadinstitute/gatk-protected/forks","keys_url":"https://api.github.com/repos/broadinstitute/gatk-protected/keys{/key_id}","collaborators_url":"https://api.github.com/repos/broadinstitute/gatk-protected/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/broadinstitute/gatk-protected/teams","hooks_url":"https://api.github.com/repos/broadinstitute/gatk-protected/hooks","issue_events_url":"https://api.github.com/repos/broadinstitute/gatk-protected/issues/events{/number}","events_url":"https://api.github.com/repos/broadinstitute/gatk-protected/events","assignees_url":"https://api.github.com/repos/broadinstitute/gatk-protected/assignees{/user}","branches_url":"https://api.github.com/repos/broadinstitute/gatk-protected/branches{/branch}","tags_url":"https://api.github.com/repos/broadinstitute/gatk-protected/tags","blobs_url":"https://api.github.com/repos/broadinstitute/gatk-protected/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/broadinstitute/gatk-protected/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/broadinstitute/gatk-protected/git/refs{/sha}","trees_url":"https://api.github.com/repos/broadinstitute/gatk-protected/git/trees{/sha}","statuses_url":"https://api.github.com/repos/broadinstitute/gatk-protected/statuses/{sha}","languages_url":"https://api.github.com/repos/broadinstitute/gatk-protected/languages","stargazers_url":"https://api.github.com/repos/broadinstitute/gatk-protected/stargazers","contributors_url":"https://api.github.com/repos/broadinstitute/gatk-protected/contributors","subscribers_url":"https://api.github.com/repos/broadinstitute/gatk-protected/subscribers","subscription_url":"https://api.github.com/repos/broadinstitute/gatk-protected/subscription","commits_url":"https://api.github.com/repos/broadinstitute/gatk-protected/commits{/sha}","git_commits_url":"https://api.github.com/repos/broadinstitute/gatk-protected/git/commits{/sha}","comments_url":"https://api.github.com/repos/broadinstitute/gatk-protected/comments{/number}","issue_comment_url":"https://api.github.com/repos/broadinstitute/gatk-protected/issues/comments{/number}","contents_url":"https://api.github.com/repos/broadinstitute/gatk-protected/contents/{+path}","compare_url":"https://api.github.com/repos/broadinstitute/gatk-protected/compare/{base}...{head}","merges_url":"https://api.github.com/repos/broadinstitute/gatk-protected/merges","archive_url":"https://api.github.com/repos/broadinstitute/gatk-protected/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/broadinstitute/gatk-protected/downloads","issues_url":"https://api.github.com/repos/broadinstitute/gatk-protected/issues{/number}","pulls_url":"https://api.github.com/repos/broadinstitute/gatk-protected/pulls{/number}","milestones_url":"https://api.github.com/repos/broadinstitute/gatk-protected/milestones{/number}","notifications_url":"https://api.github.com/repos/broadinstitute/gatk-protected/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/broadinstitute/gatk-protected/labels{/name}","releases_url":"https://api.github.com/repos/broadinstitute/gatk-protected/releases{/id}","created_at":"2015-04-22T20:24:45Z","updated_at":"2016-01-11T17:09:39Z","pushed_at":"2016-01-21T14:32:52Z","git_url":"git://github.com/broadinstitute/gatk-protected.git","ssh_url":"git@github.com:broadinstitute/gatk-protected.git","clone_url":"https://github.com/broadinstitute/gatk-protected.git","svn_url":"https://github.com/broadinstitute/gatk-protected","homepage":null,"size":61529,"stargazers_count":4,"watchers_count":4,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":101,"forks":1,"open_issues":101,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/broadinstitute/gatk-protected/pulls/313"},"html":{"href":"https://github.com/broadinstitute/gatk-protected/pull/313"},"issue":{"href":"https://api.github.com/repos/broadinstitute/gatk-protected/issues/313"},"comments":{"href":"https://api.github.com/repos/broadinstitute/gatk-protected/issues/313/comments"},"review_comments":{"href":"https://api.github.com/repos/broadinstitute/gatk-protected/pulls/313/comments"},"review_comment":{"href":"https://api.github.com/repos/broadinstitute/gatk-protected/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/broadinstitute/gatk-protected/pulls/313/commits"},"statuses":{"href":"https://api.github.com/repos/broadinstitute/gatk-protected/statuses/ed694fa96c4e199e590f0bf0d520295d751ee585"}}}}