{"action":"created","comment":{"url":"https://api.github.com/repos/googlegenomics/htsget/pulls/comments/209256643","pull_request_review_id":145236752,"id":209256643,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwOTI1NjY0Mw==","diff_hunk":"@@ -0,0 +1,110 @@\n+// Copyright 2018 Google Inc.\n+//\n+// Licensed under the Apache License, Version 2.0 (the \"License\");\n+// you may not use this file except in compliance with the License.\n+// You may obtain a copy of the License at\n+//\n+// https://www.apache.org/licenses/LICENSE-2.0\n+//\n+// Unless required by applicable law or agreed to in writing, software\n+// distributed under the License is distributed on an \"AS IS\" BASIS,\n+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+// See the License for the specific language governing permissions and\n+// limitations under the License.\n+\n+// Package bcf contains support for parsing BCF files.\n+package bcf\n+\n+import (\n+\t\"bufio\"\n+\t\"compress/gzip\"\n+\t\"errors\"\n+\t\"fmt\"\n+\t\"io\"\n+\t\"strconv\"\n+\t\"strings\"\n+\n+\t\"github.com/googlegenomics/htsget/internal/binary\"\n+)\n+\n+const (\n+\tbcfMagic = \"BCF\\x02\\x02\"\n+)\n+\n+// GetReferenceID retrieves the reference id of the given referenceName\n+// from the provided bcf file.\n+func GetReferenceID(bcf io.Reader, referenceName string) (int, error) {\n+\tgzr, err := gzip.NewReader(bcf)\n+\tif err != nil {\n+\t\treturn 0, fmt.Errorf(\"initializing gzip reader: %v\", err)\n+\t}\n+\tdefer gzr.Close()\n+\n+\tif err := binary.ExpectBytes(gzr, []byte(bcfMagic)); err != nil {\n+\t\treturn 0, fmt.Errorf(\"checking magic: %v\", err)\n+\t}\n+\n+\tvar length uint32\n+\tif err := binary.Read(gzr, &length); err != nil {\n+\t\treturn 0, fmt.Errorf(\"reading header length: %v\", err)\n+\t}\n+\n+\theaderReader := io.LimitReader(gzr, int64(length))\n+\tscanner := bufio.NewScanner(headerReader)\n+\tvar id int\n+\tfor scanner.Scan() {\n+\t\tif line := scanner.Text(); strings.HasPrefix(line, \"##contig\") {\n+\t\t\tif contigField(line, \"ID\") == referenceName {\n+\t\t\t\tidx, err := getIdx(line)\n+\t\t\t\tif err != nil {\n+\t\t\t\t\treturn 0, fmt.Errorf(\"getting idx: %v\", err)\n+\t\t\t\t}\n+\t\t\t\tif idx > -1 {\n+\t\t\t\t\treturn idx, nil\n+\t\t\t\t}\n+\t\t\t\treturn id, nil\n+\t\t\t}\n+\t\t\tid++\n+\t\t} else {\n+\t\t\tif id > 0 {\n+\t\t\t\tbreak\n+\t\t\t}\n+\t\t}\n+\t}\n+\tif err := scanner.Err(); err != nil {\n+\t\treturn 0, fmt.Errorf(\"scanning header: %v\", err)\n+\t}\n+\treturn 0, errors.New(\"reference name not found\")\n+}\n+\n+func contigField(input, name string) string {\n+\tfield := fmt.Sprintf(\"%s=\", name)\n+\tfor {\n+\t\tstart := strings.Index(input, field)\n+\t\tif start == -1 {\n+\t\t\treturn \"\"\n+\t\t}\n+\t\tif start > 0 && !isDelimiter(input[start-1]) {\n+\t\t\tinput = input[start+len(field):]\n+\t\t\tcontinue\n+\t\t}\n+\t\tinput = input[start+len(field):]\n+\t\tif end := strings.IndexAny(input, \",>\"); end > 0 {\n+\t\t\treturn input[:end]\n+\t\t} else {\n+\t\t\treturn input\n+\t\t}\n+\t}\n+}\n+\n+func isDelimiter(chr byte) bool {\n+\treturn chr == ',' || chr == '<'\n+}\n+\n+func getIdx(contig string) (int, error) {\n+\tidx := contigField(contig, \"IDX\")\n+\tif idx == \"\" {\n+\t\treturn -1, nil\n+\t}\n+\treturn strconv.Atoi(string(idx))","path":"internal/bcf/bcf.go","position":109,"original_position":109,"commit_id":"662c776e33631a49f14fe0c7b7d6f2e0963dbc7d","original_commit_id":"662c776e33631a49f14fe0c7b7d6f2e0963dbc7d","user":{"login":"kemp-google","id":28713279,"node_id":"MDQ6VXNlcjI4NzEzMjc5","avatar_url":"https://avatars3.githubusercontent.com/u/28713279?v=4","gravatar_id":"","url":"https://api.github.com/users/kemp-google","html_url":"https://github.com/kemp-google","followers_url":"https://api.github.com/users/kemp-google/followers","following_url":"https://api.github.com/users/kemp-google/following{/other_user}","gists_url":"https://api.github.com/users/kemp-google/gists{/gist_id}","starred_url":"https://api.github.com/users/kemp-google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kemp-google/subscriptions","organizations_url":"https://api.github.com/users/kemp-google/orgs","repos_url":"https://api.github.com/users/kemp-google/repos","events_url":"https://api.github.com/users/kemp-google/events{/privacy}","received_events_url":"https://api.github.com/users/kemp-google/received_events","type":"User","site_admin":false},"body":"Why string(idx) ? It's already a string","created_at":"2018-08-10T13:23:04Z","updated_at":"2018-08-10T13:25:58Z","html_url":"https://github.com/googlegenomics/htsget/pull/40#discussion_r209256643","pull_request_url":"https://api.github.com/repos/googlegenomics/htsget/pulls/40","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/googlegenomics/htsget/pulls/comments/209256643"},"html":{"href":"https://github.com/googlegenomics/htsget/pull/40#discussion_r209256643"},"pull_request":{"href":"https://api.github.com/repos/googlegenomics/htsget/pulls/40"}}},"pull_request":{"url":"https://api.github.com/repos/googlegenomics/htsget/pulls/40","id":206067722,"node_id":"MDExOlB1bGxSZXF1ZXN0MjA2MDY3NzIy","html_url":"https://github.com/googlegenomics/htsget/pull/40","diff_url":"https://github.com/googlegenomics/htsget/pull/40.diff","patch_url":"https://github.com/googlegenomics/htsget/pull/40.patch","issue_url":"https://api.github.com/repos/googlegenomics/htsget/issues/40","number":40,"state":"open","locked":false,"title":"Get Reference ID from BCF file","user":{"login":"anamanolache","id":23612578,"node_id":"MDQ6VXNlcjIzNjEyNTc4","avatar_url":"https://avatars1.githubusercontent.com/u/23612578?v=4","gravatar_id":"","url":"https://api.github.com/users/anamanolache","html_url":"https://github.com/anamanolache","followers_url":"https://api.github.com/users/anamanolache/followers","following_url":"https://api.github.com/users/anamanolache/following{/other_user}","gists_url":"https://api.github.com/users/anamanolache/gists{/gist_id}","starred_url":"https://api.github.com/users/anamanolache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anamanolache/subscriptions","organizations_url":"https://api.github.com/users/anamanolache/orgs","repos_url":"https://api.github.com/users/anamanolache/repos","events_url":"https://api.github.com/users/anamanolache/events{/privacy}","received_events_url":"https://api.github.com/users/anamanolache/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-08-03T15:39:22Z","updated_at":"2018-08-10T13:25:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c23df17f3a026bcd3b1a2d1e8815a15ffa9689a0","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/googlegenomics/htsget/pulls/40/commits","review_comments_url":"https://api.github.com/repos/googlegenomics/htsget/pulls/40/comments","review_comment_url":"https://api.github.com/repos/googlegenomics/htsget/pulls/comments{/number}","comments_url":"https://api.github.com/repos/googlegenomics/htsget/issues/40/comments","statuses_url":"https://api.github.com/repos/googlegenomics/htsget/statuses/662c776e33631a49f14fe0c7b7d6f2e0963dbc7d","head":{"label":"anamanolache:gerRefIDFromBCF","ref":"gerRefIDFromBCF","sha":"662c776e33631a49f14fe0c7b7d6f2e0963dbc7d","user":{"login":"anamanolache","id":23612578,"node_id":"MDQ6VXNlcjIzNjEyNTc4","avatar_url":"https://avatars1.githubusercontent.com/u/23612578?v=4","gravatar_id":"","url":"https://api.github.com/users/anamanolache","html_url":"https://github.com/anamanolache","followers_url":"https://api.github.com/users/anamanolache/followers","following_url":"https://api.github.com/users/anamanolache/following{/other_user}","gists_url":"https://api.github.com/users/anamanolache/gists{/gist_id}","starred_url":"https://api.github.com/users/anamanolache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anamanolache/subscriptions","organizations_url":"https://api.github.com/users/anamanolache/orgs","repos_url":"https://api.github.com/users/anamanolache/repos","events_url":"https://api.github.com/users/anamanolache/events{/privacy}","received_events_url":"https://api.github.com/users/anamanolache/received_events","type":"User","site_admin":false},"repo":{"id":143027990,"node_id":"MDEwOlJlcG9zaXRvcnkxNDMwMjc5OTA=","name":"htsget","full_name":"anamanolache/htsget","owner":{"login":"anamanolache","id":23612578,"node_id":"MDQ6VXNlcjIzNjEyNTc4","avatar_url":"https://avatars1.githubusercontent.com/u/23612578?v=4","gravatar_id":"","url":"https://api.github.com/users/anamanolache","html_url":"https://github.com/anamanolache","followers_url":"https://api.github.com/users/anamanolache/followers","following_url":"https://api.github.com/users/anamanolache/following{/other_user}","gists_url":"https://api.github.com/users/anamanolache/gists{/gist_id}","starred_url":"https://api.github.com/users/anamanolache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anamanolache/subscriptions","organizations_url":"https://api.github.com/users/anamanolache/orgs","repos_url":"https://api.github.com/users/anamanolache/repos","events_url":"https://api.github.com/users/anamanolache/events{/privacy}","received_events_url":"https://api.github.com/users/anamanolache/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/anamanolache/htsget","description":"Open Source implementation of the GA4GH htsget protocol for objects stored in Google Cloud Storage","fork":true,"url":"https://api.github.com/repos/anamanolache/htsget","forks_url":"https://api.github.com/repos/anamanolache/htsget/forks","keys_url":"https://api.github.com/repos/anamanolache/htsget/keys{/key_id}","collaborators_url":"https://api.github.com/repos/anamanolache/htsget/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/anamanolache/htsget/teams","hooks_url":"https://api.github.com/repos/anamanolache/htsget/hooks","issue_events_url":"https://api.github.com/repos/anamanolache/htsget/issues/events{/number}","events_url":"https://api.github.com/repos/anamanolache/htsget/events","assignees_url":"https://api.github.com/repos/anamanolache/htsget/assignees{/user}","branches_url":"https://api.github.com/repos/anamanolache/htsget/branches{/branch}","tags_url":"https://api.github.com/repos/anamanolache/htsget/tags","blobs_url":"https://api.github.com/repos/anamanolache/htsget/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/anamanolache/htsget/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/anamanolache/htsget/git/refs{/sha}","trees_url":"https://api.github.com/repos/anamanolache/htsget/git/trees{/sha}","statuses_url":"https://api.github.com/repos/anamanolache/htsget/statuses/{sha}","languages_url":"https://api.github.com/repos/anamanolache/htsget/languages","stargazers_url":"https://api.github.com/repos/anamanolache/htsget/stargazers","contributors_url":"https://api.github.com/repos/anamanolache/htsget/contributors","subscribers_url":"https://api.github.com/repos/anamanolache/htsget/subscribers","subscription_url":"https://api.github.com/repos/anamanolache/htsget/subscription","commits_url":"https://api.github.com/repos/anamanolache/htsget/commits{/sha}","git_commits_url":"https://api.github.com/repos/anamanolache/htsget/git/commits{/sha}","comments_url":"https://api.github.com/repos/anamanolache/htsget/comments{/number}","issue_comment_url":"https://api.github.com/repos/anamanolache/htsget/issues/comments{/number}","contents_url":"https://api.github.com/repos/anamanolache/htsget/contents/{+path}","compare_url":"https://api.github.com/repos/anamanolache/htsget/compare/{base}...{head}","merges_url":"https://api.github.com/repos/anamanolache/htsget/merges","archive_url":"https://api.github.com/repos/anamanolache/htsget/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/anamanolache/htsget/downloads","issues_url":"https://api.github.com/repos/anamanolache/htsget/issues{/number}","pulls_url":"https://api.github.com/repos/anamanolache/htsget/pulls{/number}","milestones_url":"https://api.github.com/repos/anamanolache/htsget/milestones{/number}","notifications_url":"https://api.github.com/repos/anamanolache/htsget/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/anamanolache/htsget/labels{/name}","releases_url":"https://api.github.com/repos/anamanolache/htsget/releases{/id}","deployments_url":"https://api.github.com/repos/anamanolache/htsget/deployments","created_at":"2018-07-31T14:46:20Z","updated_at":"2018-08-08T19:37:21Z","pushed_at":"2018-08-09T20:24:23Z","git_url":"git://github.com/anamanolache/htsget.git","ssh_url":"git@github.com:anamanolache/htsget.git","clone_url":"https://github.com/anamanolache/htsget.git","svn_url":"https://github.com/anamanolache/htsget","homepage":"","size":214,"stargazers_count":0,"watchers_count":0,"language":"Go","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":1,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"googlegenomics:master","ref":"master","sha":"a5a9fa0e4b3111b5c925b505ee3421875023f9ab","user":{"login":"googlegenomics","id":7434120,"node_id":"MDEyOk9yZ2FuaXphdGlvbjc0MzQxMjA=","avatar_url":"https://avatars2.githubusercontent.com/u/7434120?v=4","gravatar_id":"","url":"https://api.github.com/users/googlegenomics","html_url":"https://github.com/googlegenomics","followers_url":"https://api.github.com/users/googlegenomics/followers","following_url":"https://api.github.com/users/googlegenomics/following{/other_user}","gists_url":"https://api.github.com/users/googlegenomics/gists{/gist_id}","starred_url":"https://api.github.com/users/googlegenomics/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/googlegenomics/subscriptions","organizations_url":"https://api.github.com/users/googlegenomics/orgs","repos_url":"https://api.github.com/users/googlegenomics/repos","events_url":"https://api.github.com/users/googlegenomics/events{/privacy}","received_events_url":"https://api.github.com/users/googlegenomics/received_events","type":"Organization","site_admin":false},"repo":{"id":106715755,"node_id":"MDEwOlJlcG9zaXRvcnkxMDY3MTU3NTU=","name":"htsget","full_name":"googlegenomics/htsget","owner":{"login":"googlegenomics","id":7434120,"node_id":"MDEyOk9yZ2FuaXphdGlvbjc0MzQxMjA=","avatar_url":"https://avatars2.githubusercontent.com/u/7434120?v=4","gravatar_id":"","url":"https://api.github.com/users/googlegenomics","html_url":"https://github.com/googlegenomics","followers_url":"https://api.github.com/users/googlegenomics/followers","following_url":"https://api.github.com/users/googlegenomics/following{/other_user}","gists_url":"https://api.github.com/users/googlegenomics/gists{/gist_id}","starred_url":"https://api.github.com/users/googlegenomics/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/googlegenomics/subscriptions","organizations_url":"https://api.github.com/users/googlegenomics/orgs","repos_url":"https://api.github.com/users/googlegenomics/repos","events_url":"https://api.github.com/users/googlegenomics/events{/privacy}","received_events_url":"https://api.github.com/users/googlegenomics/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/googlegenomics/htsget","description":"Open Source implementation of the GA4GH htsget protocol for objects stored in Google Cloud Storage","fork":false,"url":"https://api.github.com/repos/googlegenomics/htsget","forks_url":"https://api.github.com/repos/googlegenomics/htsget/forks","keys_url":"https://api.github.com/repos/googlegenomics/htsget/keys{/key_id}","collaborators_url":"https://api.github.com/repos/googlegenomics/htsget/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/googlegenomics/htsget/teams","hooks_url":"https://api.github.com/repos/googlegenomics/htsget/hooks","issue_events_url":"https://api.github.com/repos/googlegenomics/htsget/issues/events{/number}","events_url":"https://api.github.com/repos/googlegenomics/htsget/events","assignees_url":"https://api.github.com/repos/googlegenomics/htsget/assignees{/user}","branches_url":"https://api.github.com/repos/googlegenomics/htsget/branches{/branch}","tags_url":"https://api.github.com/repos/googlegenomics/htsget/tags","blobs_url":"https://api.github.com/repos/googlegenomics/htsget/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/googlegenomics/htsget/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/googlegenomics/htsget/git/refs{/sha}","trees_url":"https://api.github.com/repos/googlegenomics/htsget/git/trees{/sha}","statuses_url":"https://api.github.com/repos/googlegenomics/htsget/statuses/{sha}","languages_url":"https://api.github.com/repos/googlegenomics/htsget/languages","stargazers_url":"https://api.github.com/repos/googlegenomics/htsget/stargazers","contributors_url":"https://api.github.com/repos/googlegenomics/htsget/contributors","subscribers_url":"https://api.github.com/repos/googlegenomics/htsget/subscribers","subscription_url":"https://api.github.com/repos/googlegenomics/htsget/subscription","commits_url":"https://api.github.com/repos/googlegenomics/htsget/commits{/sha}","git_commits_url":"https://api.github.com/repos/googlegenomics/htsget/git/commits{/sha}","comments_url":"https://api.github.com/repos/googlegenomics/htsget/comments{/number}","issue_comment_url":"https://api.github.com/repos/googlegenomics/htsget/issues/comments{/number}","contents_url":"https://api.github.com/repos/googlegenomics/htsget/contents/{+path}","compare_url":"https://api.github.com/repos/googlegenomics/htsget/compare/{base}...{head}","merges_url":"https://api.github.com/repos/googlegenomics/htsget/merges","archive_url":"https://api.github.com/repos/googlegenomics/htsget/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/googlegenomics/htsget/downloads","issues_url":"https://api.github.com/repos/googlegenomics/htsget/issues{/number}","pulls_url":"https://api.github.com/repos/googlegenomics/htsget/pulls{/number}","milestones_url":"https://api.github.com/repos/googlegenomics/htsget/milestones{/number}","notifications_url":"https://api.github.com/repos/googlegenomics/htsget/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/googlegenomics/htsget/labels{/name}","releases_url":"https://api.github.com/repos/googlegenomics/htsget/releases{/id}","deployments_url":"https://api.github.com/repos/googlegenomics/htsget/deployments","created_at":"2017-10-12T16:07:32Z","updated_at":"2018-08-08T19:32:51Z","pushed_at":"2018-08-09T17:50:01Z","git_url":"git://github.com/googlegenomics/htsget.git","ssh_url":"git@github.com:googlegenomics/htsget.git","clone_url":"https://github.com/googlegenomics/htsget.git","svn_url":"https://github.com/googlegenomics/htsget","homepage":"","size":171,"stargazers_count":11,"watchers_count":11,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"archived":false,"open_issues_count":7,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":6,"open_issues":7,"watchers":11,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/googlegenomics/htsget/pulls/40"},"html":{"href":"https://github.com/googlegenomics/htsget/pull/40"},"issue":{"href":"https://api.github.com/repos/googlegenomics/htsget/issues/40"},"comments":{"href":"https://api.github.com/repos/googlegenomics/htsget/issues/40/comments"},"review_comments":{"href":"https://api.github.com/repos/googlegenomics/htsget/pulls/40/comments"},"review_comment":{"href":"https://api.github.com/repos/googlegenomics/htsget/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/googlegenomics/htsget/pulls/40/commits"},"statuses":{"href":"https://api.github.com/repos/googlegenomics/htsget/statuses/662c776e33631a49f14fe0c7b7d6f2e0963dbc7d"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"kemp-google"}}