{"action":"created","comment":{"url":"https://api.github.com/repos/broadinstitute/picard/pulls/comments/70827793","id":70827793,"diff_hunk":"@@ -0,0 +1,225 @@\n+/*\n+ * The MIT License\n+ *\n+ * Copyright (c) 2016 The Broad Institute\n+ *\n+ * Permission is hereby granted, free of charge, to any person obtaining a copy\n+ * of this software and associated documentation files (the \"Software\"), to deal\n+ * in the Software without restriction, including without limitation the rights\n+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n+ * copies of the Software, and to permit persons to whom the Software is\n+ * furnished to do so, subject to the following conditions:\n+ *\n+ * The above copyright notice and this permission notice shall be included in\n+ * all copies or substantial portions of the Software.\n+ *\n+ * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n+ * THE SOFTWARE.\n+ */\n+\n+package picard.sam.markduplicates;\n+\n+import htsjdk.samtools.DuplicateSet;\n+import htsjdk.samtools.DuplicateSetIterator;\n+import htsjdk.samtools.SAMRecord;\n+import htsjdk.samtools.util.CloseableIterator;\n+import picard.PicardException;\n+\n+import java.util.ArrayList;\n+import java.util.Collections;\n+import java.util.Comparator;\n+import java.util.HashMap;\n+import java.util.Iterator;\n+import java.util.List;\n+import java.util.Map;\n+\n+/**\n+ * Created by fleharty on 5/23/16.\n+ */\n+public class UmiAwareDuplicateSetIterator implements CloseableIterator<DuplicateSet> {\n+    private DuplicateSetIterator wrappedIterator;\n+    private Iterator<DuplicateSet> nextSetsIterator;\n+    private List<List<Integer>> adjacencyList;\n+    private List<Integer> groups;\n+    int editDistanceToJoin;\n+    boolean addInferredUmi;\n+\n+    public UmiAwareDuplicateSetIterator(final DuplicateSetIterator wrappedIterator, final int editDistanceToJoin, boolean addInferredUmi) {\n+        this.wrappedIterator = wrappedIterator;\n+        this.editDistanceToJoin = editDistanceToJoin;\n+        this.addInferredUmi = addInferredUmi;\n+        nextSetsIterator = Collections.emptyIterator();\n+    }\n+\n+    @Override\n+    public void close() {\n+        wrappedIterator.close();\n+    }\n+\n+    @Override\n+    public boolean hasNext() {\n+        return nextSetsIterator.hasNext() || wrappedIterator.hasNext();\n+    }\n+\n+    @Override\n+    public DuplicateSet next() {\n+        if(!nextSetsIterator.hasNext())\n+            process(wrappedIterator.next());\n+\n+        return nextSetsIterator.next();\n+    }\n+\n+    // Takes a duplicate set and breaks it up into possible smaller sets according to the UMI,\n+    // and updates nextSetsIterator to be an iterator on that set of DuplicateSets.\n+    private void process(final DuplicateSet set) {\n+\n+        List<SAMRecord> records = set.getRecords();\n+\n+        groups = new ArrayList<>();\n+        adjacencyList = new ArrayList<>();\n+\n+        // If any records don't have the RX attribute... don't do anything special\n+        for(int i = 0;i < records.size();i++) {\n+            if(records.get(i).getAttribute(\"RX\") == null) {\n+                nextSetsIterator = Collections.singleton(set).iterator();\n+                return;\n+            } else {\n+            }\n+        }\n+\n+        // Sort records by RX tag\n+        Collections.sort(records, new Comparator<SAMRecord>() {\n+            @Override\n+            public int compare(final SAMRecord lhs, final SAMRecord rhs) {\n+                if(lhs == null || rhs == null) {\n+                    return 0;\n+                } else if(lhs.getAttribute(\"RX\") == null || rhs.getAttribute(\"RX\") == null) {\n+                    return 0;\n+                }\n+                else {\n+                    return ((String) lhs.getAttribute(\"RX\")).compareTo((String) rhs.getAttribute(\"RX\"));\n+                }\n+            }\n+        });\n+\n+        int n = records.size();\n+\n+        // Locate records that have identical UMI sequences\n+        List<String> uniqueObservedUMIs = new ArrayList<String>();\n+\n+        uniqueObservedUMIs.add((String) records.get(0).getAttribute(\"RX\"));","path":"src/main/java/picard/sam/markduplicates/UmiAwareDuplicateSetIterator.java","position":115,"original_position":115,"commit_id":"97bddf0593fa6b61bfd15a5af522f0e24d742c7d","original_commit_id":"97bddf0593fa6b61bfd15a5af522f0e24d742c7d","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":"the barcode tag should be an input parameter.","created_at":"2016-07-14T15:33:56Z","updated_at":"2016-07-14T15:33:57Z","html_url":"https://github.com/broadinstitute/picard/pull/599#discussion_r70827793","pull_request_url":"https://api.github.com/repos/broadinstitute/picard/pulls/599","_links":{"self":{"href":"https://api.github.com/repos/broadinstitute/picard/pulls/comments/70827793"},"html":{"href":"https://github.com/broadinstitute/picard/pull/599#discussion_r70827793"},"pull_request":{"href":"https://api.github.com/repos/broadinstitute/picard/pulls/599"}}},"pull_request":{"url":"https://api.github.com/repos/broadinstitute/picard/pulls/599","id":77465713,"html_url":"https://github.com/broadinstitute/picard/pull/599","diff_url":"https://github.com/broadinstitute/picard/pull/599.diff","patch_url":"https://github.com/broadinstitute/picard/pull/599.patch","issue_url":"https://api.github.com/repos/broadinstitute/picard/issues/599","number":599,"state":"open","locked":false,"title":"UMI Aware Mark Duplicates with rudimentary error correction","user":{"login":"fleharty","id":10714381,"avatar_url":"https://avatars.githubusercontent.com/u/10714381?v=3","gravatar_id":"","url":"https://api.github.com/users/fleharty","html_url":"https://github.com/fleharty","followers_url":"https://api.github.com/users/fleharty/followers","following_url":"https://api.github.com/users/fleharty/following{/other_user}","gists_url":"https://api.github.com/users/fleharty/gists{/gist_id}","starred_url":"https://api.github.com/users/fleharty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fleharty/subscriptions","organizations_url":"https://api.github.com/users/fleharty/orgs","repos_url":"https://api.github.com/users/fleharty/repos","events_url":"https://api.github.com/users/fleharty/events{/privacy}","received_events_url":"https://api.github.com/users/fleharty/received_events","type":"User","site_admin":false},"body":"This is a tool for performing MarkDuplicates in a UMI aware manner.  It uses a simple graph based algorithm to group UMIs into duplicate sets.  The error correction model is a bit naive, but this is intended to be a first iteration, and a more sophisticated algorithm will be submitted in the near future.","created_at":"2016-07-14T14:29:31Z","updated_at":"2016-07-14T15:33:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f4805ca6383c533ef92f1e430164284c783a005d","assignee":{"login":"nh13","id":846274,"avatar_url":"https://avatars.githubusercontent.com/u/846274?v=3","gravatar_id":"","url":"https://api.github.com/users/nh13","html_url":"https://github.com/nh13","followers_url":"https://api.github.com/users/nh13/followers","following_url":"https://api.github.com/users/nh13/following{/other_user}","gists_url":"https://api.github.com/users/nh13/gists{/gist_id}","starred_url":"https://api.github.com/users/nh13/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nh13/subscriptions","organizations_url":"https://api.github.com/users/nh13/orgs","repos_url":"https://api.github.com/users/nh13/repos","events_url":"https://api.github.com/users/nh13/events{/privacy}","received_events_url":"https://api.github.com/users/nh13/received_events","type":"User","site_admin":false},"assignees":[{"login":"nh13","id":846274,"avatar_url":"https://avatars.githubusercontent.com/u/846274?v=3","gravatar_id":"","url":"https://api.github.com/users/nh13","html_url":"https://github.com/nh13","followers_url":"https://api.github.com/users/nh13/followers","following_url":"https://api.github.com/users/nh13/following{/other_user}","gists_url":"https://api.github.com/users/nh13/gists{/gist_id}","starred_url":"https://api.github.com/users/nh13/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nh13/subscriptions","organizations_url":"https://api.github.com/users/nh13/orgs","repos_url":"https://api.github.com/users/nh13/repos","events_url":"https://api.github.com/users/nh13/events{/privacy}","received_events_url":"https://api.github.com/users/nh13/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/broadinstitute/picard/pulls/599/commits","review_comments_url":"https://api.github.com/repos/broadinstitute/picard/pulls/599/comments","review_comment_url":"https://api.github.com/repos/broadinstitute/picard/pulls/comments{/number}","comments_url":"https://api.github.com/repos/broadinstitute/picard/issues/599/comments","statuses_url":"https://api.github.com/repos/broadinstitute/picard/statuses/97bddf0593fa6b61bfd15a5af522f0e24d742c7d","head":{"label":"broadinstitute:mf_umiAwareMarkDuplicatesGradle","ref":"mf_umiAwareMarkDuplicatesGradle","sha":"97bddf0593fa6b61bfd15a5af522f0e24d742c7d","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-07-14T07:08:09Z","pushed_at":"2016-07-14T14:29:31Z","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":65114,"stargazers_count":187,"watchers_count":187,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":130,"mirror_url":null,"open_issues_count":95,"forks":130,"open_issues":95,"watchers":187,"default_branch":"master"}},"base":{"label":"broadinstitute:master","ref":"master","sha":"e37fd06bab1a2d7e7d8cebf6b00f0c5963b560af","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-07-14T07:08:09Z","pushed_at":"2016-07-14T14:29:31Z","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":65114,"stargazers_count":187,"watchers_count":187,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":130,"mirror_url":null,"open_issues_count":95,"forks":130,"open_issues":95,"watchers":187,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/broadinstitute/picard/pulls/599"},"html":{"href":"https://github.com/broadinstitute/picard/pull/599"},"issue":{"href":"https://api.github.com/repos/broadinstitute/picard/issues/599"},"comments":{"href":"https://api.github.com/repos/broadinstitute/picard/issues/599/comments"},"review_comments":{"href":"https://api.github.com/repos/broadinstitute/picard/pulls/599/comments"},"review_comment":{"href":"https://api.github.com/repos/broadinstitute/picard/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/broadinstitute/picard/pulls/599/commits"},"statuses":{"href":"https://api.github.com/repos/broadinstitute/picard/statuses/97bddf0593fa6b61bfd15a5af522f0e24d742c7d"}}}}
{"actor":{"display_login":"yfarjoun"}}