{"action":"created","comment":{"url":"https://api.github.com/repos/samtools/htsjdk/pulls/comments/225373511","pull_request_review_id":164959184,"id":225373511,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIyNTM3MzUxMQ==","diff_hunk":"@@ -0,0 +1,338 @@\n+/*\n+ * The MIT License\n+ *\n+ * Copyright (c) 2018 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;\n+\n+import htsjdk.samtools.util.BinaryCodec;\n+import htsjdk.samtools.util.BlockCompressedFilePointerUtil;\n+\n+import java.io.BufferedInputStream;\n+import java.io.IOException;\n+import java.io.InputStream;\n+import java.io.Serializable;\n+import java.nio.file.Files;\n+import java.nio.file.Path;\n+import java.util.ArrayList;\n+import java.util.Arrays;\n+import java.util.List;\n+import java.util.NavigableSet;\n+import java.util.Objects;\n+import java.util.TreeSet;\n+import java.util.stream.Collectors;\n+\n+/**\n+ * SBI is an index into BGZF-compressed data files, which has an entry for the file position of the start of every\n+ * <i>n</i>th record. Reads files that were created by {@link BAMSBIIndexer}.\n+ */\n+public final class SBIIndex implements Serializable {\n+\n+    public static class Header implements Serializable {\n+        private final long fileLength;\n+        private final byte[] md5;\n+        private final byte[] uuid;\n+        private final long totalNumberOfRecords;\n+        private final long granularity;\n+\n+        public Header(long fileLength, byte[] md5, byte[] uuid, long totalNumberOfRecords, long granularity) {\n+            this.fileLength = fileLength;\n+            this.md5 = md5;\n+            this.uuid = uuid;\n+            this.totalNumberOfRecords = totalNumberOfRecords;\n+            this.granularity = granularity;\n+        }\n+\n+        public long getFileLength() {\n+            return fileLength;\n+        }\n+\n+        public byte[] getMd5() {\n+            return md5;\n+        }\n+\n+        public byte[] getUuid() {\n+            return uuid;\n+        }\n+\n+        public long getTotalNumberOfRecords() {\n+            return totalNumberOfRecords;\n+        }\n+\n+        public long getGranularity() {\n+            return granularity;\n+        }\n+\n+        @Override\n+        public boolean equals(Object o) {\n+            if (this == o) return true;\n+            if (o == null || getClass() != o.getClass()) return false;\n+            Header header = (Header) o;\n+            return fileLength == header.fileLength &&\n+                    totalNumberOfRecords == header.totalNumberOfRecords &&\n+                    granularity == header.granularity &&\n+                    Arrays.equals(md5, header.md5) &&\n+                    Arrays.equals(uuid, header.uuid);\n+        }\n+\n+        @Override\n+        public int hashCode() {\n+            int result = Objects.hash(fileLength, totalNumberOfRecords, granularity);\n+            result = 31 * result + Arrays.hashCode(md5);\n+            result = 31 * result + Arrays.hashCode(uuid);\n+            return result;\n+        }\n+\n+        @Override\n+        public String toString() {\n+            return \"Header{\" +\n+                    \"fileLength=\" + fileLength +\n+                    \", md5=\" + Arrays.toString(md5) +\n+                    \", uuid=\" + Arrays.toString(uuid) +\n+                    \", totalNumberOfRecords=\" + totalNumberOfRecords +\n+                    \", granularity=\" + granularity +\n+                    '}';\n+        }\n+    }\n+\n+    public static final String FILE_EXTENSION = \".sbi\";\n+\n+    /**\n+     * SBI magic number.\n+     */\n+    static final byte[] SBI_MAGIC = \"SBI\\1\".getBytes();\n+\n+    private final Header header;\n+    private final long[] virtualOffsets;\n+\n+    /**\n+     * Create an in-memory SBI with the given virtual offsets.\n+     * @param virtualOffsets the offsets in the index\n+     */\n+    public SBIIndex(final Header header, final long[] virtualOffsets) {\n+        this.header = header;\n+        this.virtualOffsets = virtualOffsets;\n+        if (this.virtualOffsets.length == 0) {\n+            throw new RuntimeException(\"Invalid SBI format: should contain at least one offset\");\n+        }\n+    }\n+\n+    /**\n+     * Load an SBI into memory from a path.\n+     * @param path the path to the SBI file\n+     * @throws IOException as per java IO contract\n+     */\n+    public static SBIIndex load(final Path path) throws IOException {\n+        try (InputStream in = new BufferedInputStream(Files.newInputStream(path))) {","path":"src/main/java/htsjdk/samtools/SBIIndex.java","position":144,"original_position":144,"commit_id":"bc817169012be0d2f33e4c76c589e40f9e4406b7","original_commit_id":"bc817169012be0d2f33e4c76c589e40f9e4406b7","user":{"login":"yfarjoun","id":2745554,"node_id":"MDQ6VXNlcjI3NDU1NTQ=","avatar_url":"https://avatars3.githubusercontent.com/u/2745554?v=4","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 `in`","created_at":"2018-10-16T02:00:47Z","updated_at":"2018-10-16T02:06:55Z","html_url":"https://github.com/samtools/htsjdk/pull/1138#discussion_r225373511","pull_request_url":"https://api.github.com/repos/samtools/htsjdk/pulls/1138","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/samtools/htsjdk/pulls/comments/225373511"},"html":{"href":"https://github.com/samtools/htsjdk/pull/1138#discussion_r225373511"},"pull_request":{"href":"https://api.github.com/repos/samtools/htsjdk/pulls/1138"}}},"pull_request":{"url":"https://api.github.com/repos/samtools/htsjdk/pulls/1138","id":192371011,"node_id":"MDExOlB1bGxSZXF1ZXN0MTkyMzcxMDEx","html_url":"https://github.com/samtools/htsjdk/pull/1138","diff_url":"https://github.com/samtools/htsjdk/pull/1138.diff","patch_url":"https://github.com/samtools/htsjdk/pull/1138.patch","issue_url":"https://api.github.com/repos/samtools/htsjdk/issues/1138","number":1138,"state":"open","locked":false,"title":"Add support for reading and writing splitting BAM index files.","user":{"login":"tomwhite","id":85085,"node_id":"MDQ6VXNlcjg1MDg1","avatar_url":"https://avatars3.githubusercontent.com/u/85085?v=4","gravatar_id":"","url":"https://api.github.com/users/tomwhite","html_url":"https://github.com/tomwhite","followers_url":"https://api.github.com/users/tomwhite/followers","following_url":"https://api.github.com/users/tomwhite/following{/other_user}","gists_url":"https://api.github.com/users/tomwhite/gists{/gist_id}","starred_url":"https://api.github.com/users/tomwhite/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomwhite/subscriptions","organizations_url":"https://api.github.com/users/tomwhite/orgs","repos_url":"https://api.github.com/users/tomwhite/repos","events_url":"https://api.github.com/users/tomwhite/events{/privacy}","received_events_url":"https://api.github.com/users/tomwhite/received_events","type":"User","site_admin":false},"body":"Move logic to read and write splitting-bai files to htsjdk from Hadoop-BAM, since they are useful for distributed processing in general (and perhaps other tools). The format here is different to (and incompatible with) the one in Hadoop-BAM: it adds a header with a magic number (for file discovery and versioning), as well as a field for granularity. Also, the offsets are written in little-endian format for consistency with the rest of the BAM spec.\r\n\r\n### Checklist\r\n\r\n- [ ] Code compiles correctly\r\n- [ ] New tests covering changes and new functionality\r\n- [ ] All tests passing\r\n- [ ] Extended the README / documentation, if necessary\r\n- [ ] Is not backward compatible (breaks binary or source compatibility)\r\n\r\n","created_at":"2018-06-04T10:58:43Z","updated_at":"2018-10-16T02:06:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"edc23b3252ccc7b15c0818692ef3908b44dc7ae6","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/samtools/htsjdk/pulls/1138/commits","review_comments_url":"https://api.github.com/repos/samtools/htsjdk/pulls/1138/comments","review_comment_url":"https://api.github.com/repos/samtools/htsjdk/pulls/comments{/number}","comments_url":"https://api.github.com/repos/samtools/htsjdk/issues/1138/comments","statuses_url":"https://api.github.com/repos/samtools/htsjdk/statuses/bc817169012be0d2f33e4c76c589e40f9e4406b7","head":{"label":"tomwhite:splitting_bai","ref":"splitting_bai","sha":"bc817169012be0d2f33e4c76c589e40f9e4406b7","user":{"login":"tomwhite","id":85085,"node_id":"MDQ6VXNlcjg1MDg1","avatar_url":"https://avatars3.githubusercontent.com/u/85085?v=4","gravatar_id":"","url":"https://api.github.com/users/tomwhite","html_url":"https://github.com/tomwhite","followers_url":"https://api.github.com/users/tomwhite/followers","following_url":"https://api.github.com/users/tomwhite/following{/other_user}","gists_url":"https://api.github.com/users/tomwhite/gists{/gist_id}","starred_url":"https://api.github.com/users/tomwhite/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomwhite/subscriptions","organizations_url":"https://api.github.com/users/tomwhite/orgs","repos_url":"https://api.github.com/users/tomwhite/repos","events_url":"https://api.github.com/users/tomwhite/events{/privacy}","received_events_url":"https://api.github.com/users/tomwhite/received_events","type":"User","site_admin":false},"repo":{"id":41047611,"node_id":"MDEwOlJlcG9zaXRvcnk0MTA0NzYxMQ==","name":"htsjdk","full_name":"tomwhite/htsjdk","private":false,"owner":{"login":"tomwhite","id":85085,"node_id":"MDQ6VXNlcjg1MDg1","avatar_url":"https://avatars3.githubusercontent.com/u/85085?v=4","gravatar_id":"","url":"https://api.github.com/users/tomwhite","html_url":"https://github.com/tomwhite","followers_url":"https://api.github.com/users/tomwhite/followers","following_url":"https://api.github.com/users/tomwhite/following{/other_user}","gists_url":"https://api.github.com/users/tomwhite/gists{/gist_id}","starred_url":"https://api.github.com/users/tomwhite/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomwhite/subscriptions","organizations_url":"https://api.github.com/users/tomwhite/orgs","repos_url":"https://api.github.com/users/tomwhite/repos","events_url":"https://api.github.com/users/tomwhite/events{/privacy}","received_events_url":"https://api.github.com/users/tomwhite/received_events","type":"User","site_admin":false},"html_url":"https://github.com/tomwhite/htsjdk","description":"A Java API for high-throughput sequencing data (HTS) formats.","fork":true,"url":"https://api.github.com/repos/tomwhite/htsjdk","forks_url":"https://api.github.com/repos/tomwhite/htsjdk/forks","keys_url":"https://api.github.com/repos/tomwhite/htsjdk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tomwhite/htsjdk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tomwhite/htsjdk/teams","hooks_url":"https://api.github.com/repos/tomwhite/htsjdk/hooks","issue_events_url":"https://api.github.com/repos/tomwhite/htsjdk/issues/events{/number}","events_url":"https://api.github.com/repos/tomwhite/htsjdk/events","assignees_url":"https://api.github.com/repos/tomwhite/htsjdk/assignees{/user}","branches_url":"https://api.github.com/repos/tomwhite/htsjdk/branches{/branch}","tags_url":"https://api.github.com/repos/tomwhite/htsjdk/tags","blobs_url":"https://api.github.com/repos/tomwhite/htsjdk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tomwhite/htsjdk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tomwhite/htsjdk/git/refs{/sha}","trees_url":"https://api.github.com/repos/tomwhite/htsjdk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tomwhite/htsjdk/statuses/{sha}","languages_url":"https://api.github.com/repos/tomwhite/htsjdk/languages","stargazers_url":"https://api.github.com/repos/tomwhite/htsjdk/stargazers","contributors_url":"https://api.github.com/repos/tomwhite/htsjdk/contributors","subscribers_url":"https://api.github.com/repos/tomwhite/htsjdk/subscribers","subscription_url":"https://api.github.com/repos/tomwhite/htsjdk/subscription","commits_url":"https://api.github.com/repos/tomwhite/htsjdk/commits{/sha}","git_commits_url":"https://api.github.com/repos/tomwhite/htsjdk/git/commits{/sha}","comments_url":"https://api.github.com/repos/tomwhite/htsjdk/comments{/number}","issue_comment_url":"https://api.github.com/repos/tomwhite/htsjdk/issues/comments{/number}","contents_url":"https://api.github.com/repos/tomwhite/htsjdk/contents/{+path}","compare_url":"https://api.github.com/repos/tomwhite/htsjdk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tomwhite/htsjdk/merges","archive_url":"https://api.github.com/repos/tomwhite/htsjdk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tomwhite/htsjdk/downloads","issues_url":"https://api.github.com/repos/tomwhite/htsjdk/issues{/number}","pulls_url":"https://api.github.com/repos/tomwhite/htsjdk/pulls{/number}","milestones_url":"https://api.github.com/repos/tomwhite/htsjdk/milestones{/number}","notifications_url":"https://api.github.com/repos/tomwhite/htsjdk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tomwhite/htsjdk/labels{/name}","releases_url":"https://api.github.com/repos/tomwhite/htsjdk/releases{/id}","deployments_url":"https://api.github.com/repos/tomwhite/htsjdk/deployments","created_at":"2015-08-19T16:58:31Z","updated_at":"2016-03-11T14:29:16Z","pushed_at":"2018-10-02T14:38:30Z","git_url":"git://github.com/tomwhite/htsjdk.git","ssh_url":"git@github.com:tomwhite/htsjdk.git","clone_url":"https://github.com/tomwhite/htsjdk.git","svn_url":"https://github.com/tomwhite/htsjdk","homepage":"http://samtools.github.io/htsjdk/","size":63469,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"samtools:master","ref":"master","sha":"fb36a36fb6c362bc273c30948ec5d21a9b4ef90b","user":{"login":"samtools","id":1518450,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE1MTg0NTA=","avatar_url":"https://avatars1.githubusercontent.com/u/1518450?v=4","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,"node_id":"MDEwOlJlcG9zaXRvcnkxOTI3MjMxNQ==","name":"htsjdk","full_name":"samtools/htsjdk","private":false,"owner":{"login":"samtools","id":1518450,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE1MTg0NTA=","avatar_url":"https://avatars1.githubusercontent.com/u/1518450?v=4","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},"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":"2018-10-15T17:50:17Z","pushed_at":"2018-10-15T21:29:56Z","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":68816,"stargazers_count":171,"watchers_count":171,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":190,"mirror_url":null,"archived":false,"open_issues_count":243,"license":null,"forks":190,"open_issues":243,"watchers":171,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/samtools/htsjdk/pulls/1138"},"html":{"href":"https://github.com/samtools/htsjdk/pull/1138"},"issue":{"href":"https://api.github.com/repos/samtools/htsjdk/issues/1138"},"comments":{"href":"https://api.github.com/repos/samtools/htsjdk/issues/1138/comments"},"review_comments":{"href":"https://api.github.com/repos/samtools/htsjdk/pulls/1138/comments"},"review_comment":{"href":"https://api.github.com/repos/samtools/htsjdk/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/samtools/htsjdk/pulls/1138/commits"},"statuses":{"href":"https://api.github.com/repos/samtools/htsjdk/statuses/bc817169012be0d2f33e4c76c589e40f9e4406b7"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"yfarjoun"}}