{"action":"created","comment":{"url":"https://api.github.com/repos/samtools/htsjdk/pulls/comments/71811821","id":71811821,"diff_hunk":"@@ -0,0 +1,111 @@\n+/*\n+ * The MIT License\n+ *\n+ * Copyright (c) 2010 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+package htsjdk.samtools.filter;\n+\n+import htsjdk.samtools.SAMFileHeader;\n+import htsjdk.samtools.SAMRecord;\n+import htsjdk.samtools.SAMUtils;\n+import htsjdk.samtools.util.Interval;\n+import htsjdk.samtools.util.IntervalUtil;\n+import htsjdk.samtools.util.OverlapDetector;\n+\n+import java.util.Collection;\n+import java.util.List;\n+\n+/**\n+ * Filter SAMRecords so that only those that overlap the given list of intervals.\n+ * It is required that the SAMRecords are passed in coordinate order, and have non-null SAMFileHeaders.\n+ *\n+ *\n+ * @author kbergin@broadinstitute.org\n+ */\n+public class IntervalKeepPairFilter implements SamRecordFilter {\n+    private final SAMFileHeader samHeader;\n+    private OverlapDetector<Interval> intervalOverlapDetector;\n+\n+    /**\n+     * Prepare to filter out SAMRecords that do not overlap the given list of intervals\n+     * @param intervals -- must be locus-ordered & non-overlapping\n+     */\n+    public IntervalKeepPairFilter(final List<Interval> intervals, final SAMFileHeader samHeader) {\n+        this.samHeader = samHeader;\n+        IntervalUtil.assertOrderedNonOverlapping(intervals.iterator(), samHeader.getSequenceDictionary());\n+        this.intervalOverlapDetector = new OverlapDetector<>(0,0);\n+        this.intervalOverlapDetector.addAll(intervals, intervals);\n+    }\n+\n+    /**\n+     * Determines whether a SAMRecord matches this filter\n+     *\n+     * @param record the SAMRecord to evaluate\n+     * @return true if the SAMRecord matches the filter, otherwise false\n+     */\n+    public boolean filterOut(final SAMRecord record) {\n+        /*\n+        Take record, find its mate\n+        Check if either record overlaps the current interval using overlap detector\n+        If yes, return false, don't filter it out\n+         */\n+        boolean read1 = findOverlaps(record.getReferenceName(), record.getStart(), record.getEnd());","path":"src/main/java/htsjdk/samtools/filter/IntervalKeepPairFilter.java","position":70,"original_position":70,"commit_id":"db3b92183dd1628438a0bb1a5a804f8c75830ed8","original_commit_id":"db3b92183dd1628438a0bb1a5a804f8c75830ed8","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":"final","created_at":"2016-07-22T00:37:47Z","updated_at":"2016-07-22T00:37:47Z","html_url":"https://github.com/samtools/htsjdk/pull/667#discussion_r71811821","pull_request_url":"https://api.github.com/repos/samtools/htsjdk/pulls/667","_links":{"self":{"href":"https://api.github.com/repos/samtools/htsjdk/pulls/comments/71811821"},"html":{"href":"https://github.com/samtools/htsjdk/pull/667#discussion_r71811821"},"pull_request":{"href":"https://api.github.com/repos/samtools/htsjdk/pulls/667"}}},"pull_request":{"url":"https://api.github.com/repos/samtools/htsjdk/pulls/667","id":78391864,"html_url":"https://github.com/samtools/htsjdk/pull/667","diff_url":"https://github.com/samtools/htsjdk/pull/667.diff","patch_url":"https://github.com/samtools/htsjdk/pull/667.patch","issue_url":"https://api.github.com/repos/samtools/htsjdk/issues/667","number":667,"state":"open","locked":false,"title":"Interval Filter that Keeps Pairs","user":{"login":"kbergin","id":9449764,"avatar_url":"https://avatars.githubusercontent.com/u/9449764?v=3","gravatar_id":"","url":"https://api.github.com/users/kbergin","html_url":"https://github.com/kbergin","followers_url":"https://api.github.com/users/kbergin/followers","following_url":"https://api.github.com/users/kbergin/following{/other_user}","gists_url":"https://api.github.com/users/kbergin/gists{/gist_id}","starred_url":"https://api.github.com/users/kbergin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kbergin/subscriptions","organizations_url":"https://api.github.com/users/kbergin/orgs","repos_url":"https://api.github.com/users/kbergin/repos","events_url":"https://api.github.com/users/kbergin/events{/privacy}","received_events_url":"https://api.github.com/users/kbergin/received_events","type":"User","site_admin":false},"body":"### Description\r\n\r\nThe current Interval Filter did not work 'paired' filtering. Recently, we needed to use an interval list to filter a bam, but keep both the read and its mate if either of them overlapped with the interval. The IntervalKeepPairFilter does this using an overlap detector on a coordinate sorted bam and sorted interval list. \r\n\r\n### Checklist\r\n\r\n- [X] Code compiles correctly\r\n- [X] New tests covering changes and new functionality\r\n- [X] All tests passing\r\n- [X] Extended the README / documentation, if necessary\r\n- [X] Is not backward compatible (breaks binary or source compatibility)\r\n\r\n","created_at":"2016-07-21T21:36:48Z","updated_at":"2016-07-22T00:37:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"89199665658094c544a8057d39e23201ed3329f8","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/samtools/htsjdk/pulls/667/commits","review_comments_url":"https://api.github.com/repos/samtools/htsjdk/pulls/667/comments","review_comment_url":"https://api.github.com/repos/samtools/htsjdk/pulls/comments{/number}","comments_url":"https://api.github.com/repos/samtools/htsjdk/issues/667/comments","statuses_url":"https://api.github.com/repos/samtools/htsjdk/statuses/db3b92183dd1628438a0bb1a5a804f8c75830ed8","head":{"label":"samtools:kb_AddPairedIntervalFilter","ref":"kb_AddPairedIntervalFilter","sha":"db3b92183dd1628438a0bb1a5a804f8c75830ed8","user":{"login":"samtools","id":1518450,"avatar_url":"https://avatars.githubusercontent.com/u/1518450?v=3","gravatar_id":"","url":"https://api.github.com/users/samtools","html_url":"https://github.com/samtools","followers_url":"https://api.github.com/users/samtools/followers","following_url":"https://api.github.com/users/samtools/following{/other_user}","gists_url":"https://api.github.com/users/samtools/gists{/gist_id}","starred_url":"https://api.github.com/users/samtools/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samtools/subscriptions","organizations_url":"https://api.github.com/users/samtools/orgs","repos_url":"https://api.github.com/users/samtools/repos","events_url":"https://api.github.com/users/samtools/events{/privacy}","received_events_url":"https://api.github.com/users/samtools/received_events","type":"Organization","site_admin":false},"repo":{"id":19272315,"name":"htsjdk","full_name":"samtools/htsjdk","owner":{"login":"samtools","id":1518450,"avatar_url":"https://avatars.githubusercontent.com/u/1518450?v=3","gravatar_id":"","url":"https://api.github.com/users/samtools","html_url":"https://github.com/samtools","followers_url":"https://api.github.com/users/samtools/followers","following_url":"https://api.github.com/users/samtools/following{/other_user}","gists_url":"https://api.github.com/users/samtools/gists{/gist_id}","starred_url":"https://api.github.com/users/samtools/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samtools/subscriptions","organizations_url":"https://api.github.com/users/samtools/orgs","repos_url":"https://api.github.com/users/samtools/repos","events_url":"https://api.github.com/users/samtools/events{/privacy}","received_events_url":"https://api.github.com/users/samtools/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/samtools/htsjdk","description":"A Java API for high-throughput sequencing data (HTS) formats.","fork":false,"url":"https://api.github.com/repos/samtools/htsjdk","forks_url":"https://api.github.com/repos/samtools/htsjdk/forks","keys_url":"https://api.github.com/repos/samtools/htsjdk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/samtools/htsjdk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/samtools/htsjdk/teams","hooks_url":"https://api.github.com/repos/samtools/htsjdk/hooks","issue_events_url":"https://api.github.com/repos/samtools/htsjdk/issues/events{/number}","events_url":"https://api.github.com/repos/samtools/htsjdk/events","assignees_url":"https://api.github.com/repos/samtools/htsjdk/assignees{/user}","branches_url":"https://api.github.com/repos/samtools/htsjdk/branches{/branch}","tags_url":"https://api.github.com/repos/samtools/htsjdk/tags","blobs_url":"https://api.github.com/repos/samtools/htsjdk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/samtools/htsjdk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/samtools/htsjdk/git/refs{/sha}","trees_url":"https://api.github.com/repos/samtools/htsjdk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/samtools/htsjdk/statuses/{sha}","languages_url":"https://api.github.com/repos/samtools/htsjdk/languages","stargazers_url":"https://api.github.com/repos/samtools/htsjdk/stargazers","contributors_url":"https://api.github.com/repos/samtools/htsjdk/contributors","subscribers_url":"https://api.github.com/repos/samtools/htsjdk/subscribers","subscription_url":"https://api.github.com/repos/samtools/htsjdk/subscription","commits_url":"https://api.github.com/repos/samtools/htsjdk/commits{/sha}","git_commits_url":"https://api.github.com/repos/samtools/htsjdk/git/commits{/sha}","comments_url":"https://api.github.com/repos/samtools/htsjdk/comments{/number}","issue_comment_url":"https://api.github.com/repos/samtools/htsjdk/issues/comments{/number}","contents_url":"https://api.github.com/repos/samtools/htsjdk/contents/{+path}","compare_url":"https://api.github.com/repos/samtools/htsjdk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/samtools/htsjdk/merges","archive_url":"https://api.github.com/repos/samtools/htsjdk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/samtools/htsjdk/downloads","issues_url":"https://api.github.com/repos/samtools/htsjdk/issues{/number}","pulls_url":"https://api.github.com/repos/samtools/htsjdk/pulls{/number}","milestones_url":"https://api.github.com/repos/samtools/htsjdk/milestones{/number}","notifications_url":"https://api.github.com/repos/samtools/htsjdk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/samtools/htsjdk/labels{/name}","releases_url":"https://api.github.com/repos/samtools/htsjdk/releases{/id}","deployments_url":"https://api.github.com/repos/samtools/htsjdk/deployments","created_at":"2014-04-29T10:11:28Z","updated_at":"2016-07-16T15:46:35Z","pushed_at":"2016-07-21T21:36:48Z","git_url":"git://github.com/samtools/htsjdk.git","ssh_url":"git@github.com:samtools/htsjdk.git","clone_url":"https://github.com/samtools/htsjdk.git","svn_url":"https://github.com/samtools/htsjdk","homepage":"http://samtools.github.io/htsjdk/","size":69590,"stargazers_count":86,"watchers_count":86,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":122,"mirror_url":null,"open_issues_count":137,"forks":122,"open_issues":137,"watchers":86,"default_branch":"master"}},"base":{"label":"samtools:master","ref":"master","sha":"fcfad25be8728552707ce0201476258c9711d99f","user":{"login":"samtools","id":1518450,"avatar_url":"https://avatars.githubusercontent.com/u/1518450?v=3","gravatar_id":"","url":"https://api.github.com/users/samtools","html_url":"https://github.com/samtools","followers_url":"https://api.github.com/users/samtools/followers","following_url":"https://api.github.com/users/samtools/following{/other_user}","gists_url":"https://api.github.com/users/samtools/gists{/gist_id}","starred_url":"https://api.github.com/users/samtools/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samtools/subscriptions","organizations_url":"https://api.github.com/users/samtools/orgs","repos_url":"https://api.github.com/users/samtools/repos","events_url":"https://api.github.com/users/samtools/events{/privacy}","received_events_url":"https://api.github.com/users/samtools/received_events","type":"Organization","site_admin":false},"repo":{"id":19272315,"name":"htsjdk","full_name":"samtools/htsjdk","owner":{"login":"samtools","id":1518450,"avatar_url":"https://avatars.githubusercontent.com/u/1518450?v=3","gravatar_id":"","url":"https://api.github.com/users/samtools","html_url":"https://github.com/samtools","followers_url":"https://api.github.com/users/samtools/followers","following_url":"https://api.github.com/users/samtools/following{/other_user}","gists_url":"https://api.github.com/users/samtools/gists{/gist_id}","starred_url":"https://api.github.com/users/samtools/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samtools/subscriptions","organizations_url":"https://api.github.com/users/samtools/orgs","repos_url":"https://api.github.com/users/samtools/repos","events_url":"https://api.github.com/users/samtools/events{/privacy}","received_events_url":"https://api.github.com/users/samtools/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/samtools/htsjdk","description":"A Java API for high-throughput sequencing data (HTS) formats.","fork":false,"url":"https://api.github.com/repos/samtools/htsjdk","forks_url":"https://api.github.com/repos/samtools/htsjdk/forks","keys_url":"https://api.github.com/repos/samtools/htsjdk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/samtools/htsjdk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/samtools/htsjdk/teams","hooks_url":"https://api.github.com/repos/samtools/htsjdk/hooks","issue_events_url":"https://api.github.com/repos/samtools/htsjdk/issues/events{/number}","events_url":"https://api.github.com/repos/samtools/htsjdk/events","assignees_url":"https://api.github.com/repos/samtools/htsjdk/assignees{/user}","branches_url":"https://api.github.com/repos/samtools/htsjdk/branches{/branch}","tags_url":"https://api.github.com/repos/samtools/htsjdk/tags","blobs_url":"https://api.github.com/repos/samtools/htsjdk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/samtools/htsjdk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/samtools/htsjdk/git/refs{/sha}","trees_url":"https://api.github.com/repos/samtools/htsjdk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/samtools/htsjdk/statuses/{sha}","languages_url":"https://api.github.com/repos/samtools/htsjdk/languages","stargazers_url":"https://api.github.com/repos/samtools/htsjdk/stargazers","contributors_url":"https://api.github.com/repos/samtools/htsjdk/contributors","subscribers_url":"https://api.github.com/repos/samtools/htsjdk/subscribers","subscription_url":"https://api.github.com/repos/samtools/htsjdk/subscription","commits_url":"https://api.github.com/repos/samtools/htsjdk/commits{/sha}","git_commits_url":"https://api.github.com/repos/samtools/htsjdk/git/commits{/sha}","comments_url":"https://api.github.com/repos/samtools/htsjdk/comments{/number}","issue_comment_url":"https://api.github.com/repos/samtools/htsjdk/issues/comments{/number}","contents_url":"https://api.github.com/repos/samtools/htsjdk/contents/{+path}","compare_url":"https://api.github.com/repos/samtools/htsjdk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/samtools/htsjdk/merges","archive_url":"https://api.github.com/repos/samtools/htsjdk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/samtools/htsjdk/downloads","issues_url":"https://api.github.com/repos/samtools/htsjdk/issues{/number}","pulls_url":"https://api.github.com/repos/samtools/htsjdk/pulls{/number}","milestones_url":"https://api.github.com/repos/samtools/htsjdk/milestones{/number}","notifications_url":"https://api.github.com/repos/samtools/htsjdk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/samtools/htsjdk/labels{/name}","releases_url":"https://api.github.com/repos/samtools/htsjdk/releases{/id}","deployments_url":"https://api.github.com/repos/samtools/htsjdk/deployments","created_at":"2014-04-29T10:11:28Z","updated_at":"2016-07-16T15:46:35Z","pushed_at":"2016-07-21T21:36:48Z","git_url":"git://github.com/samtools/htsjdk.git","ssh_url":"git@github.com:samtools/htsjdk.git","clone_url":"https://github.com/samtools/htsjdk.git","svn_url":"https://github.com/samtools/htsjdk","homepage":"http://samtools.github.io/htsjdk/","size":69590,"stargazers_count":86,"watchers_count":86,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":122,"mirror_url":null,"open_issues_count":137,"forks":122,"open_issues":137,"watchers":86,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/samtools/htsjdk/pulls/667"},"html":{"href":"https://github.com/samtools/htsjdk/pull/667"},"issue":{"href":"https://api.github.com/repos/samtools/htsjdk/issues/667"},"comments":{"href":"https://api.github.com/repos/samtools/htsjdk/issues/667/comments"},"review_comments":{"href":"https://api.github.com/repos/samtools/htsjdk/pulls/667/comments"},"review_comment":{"href":"https://api.github.com/repos/samtools/htsjdk/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/samtools/htsjdk/pulls/667/commits"},"statuses":{"href":"https://api.github.com/repos/samtools/htsjdk/statuses/db3b92183dd1628438a0bb1a5a804f8c75830ed8"}}}}
{"actor":{"display_login":"yfarjoun"}}