{"action":"created","comment":{"url":"https://api.github.com/repos/samtools/htsjdk/pulls/comments/47855611","id":47855611,"diff_hunk":"@@ -75,11 +83,34 @@ public static boolean isSupported() {\n      * @return true if a string is a valid SRA accession\n      */\n     public static boolean isValid(String acc) {\n-        if (!isSupported()) {\n-            return false;\n+        boolean looksLikeSRA = false;\n+        File f = new File(acc);\n+        if (f.isFile()) {\n+            try {\n+                byte[] buffer = new byte[8];\n+                byte[] signature1 = \"NCBI.sra\".getBytes();\n+                byte[] signature2 = \"NCBInenc\".getBytes();\n+\n+                InputStream is = new FileInputStream(f);\n+                int numRead = is.read(buffer);\n+                is.close();\n+\n+                looksLikeSRA = numRead == buffer.length &&\n+                        (Arrays.equals(buffer, signature1) || Arrays.equals(buffer, signature2));\n+            } catch (IOException e) {\n+                looksLikeSRA = false;\n+            }\n+        } else if (f.exists()) {\n+            // anything else local other than a file is not an SRA archive\n+            looksLikeSRA = false;\n+        } else {\n+            looksLikeSRA = acc.toUpperCase().matches ( \"^[SED]RR[0-9]{6,9}$\" );\n         }\n \n-        return NGS.isValid(acc);\n+        if (!looksLikeSRA)","path":"src/java/htsjdk/samtools/sra/SRAAccession.java","position":null,"original_position":52,"commit_id":"42558f76d9ffc87ec32ed682b67f424555929beb","original_commit_id":"30b72cb39d4dbb7245400fab3078ceab7a00a9b0","user":{"login":"a-nikitiuk","id":12701013,"avatar_url":"https://avatars.githubusercontent.com/u/12701013?v=3","gravatar_id":"","url":"https://api.github.com/users/a-nikitiuk","html_url":"https://github.com/a-nikitiuk","followers_url":"https://api.github.com/users/a-nikitiuk/followers","following_url":"https://api.github.com/users/a-nikitiuk/following{/other_user}","gists_url":"https://api.github.com/users/a-nikitiuk/gists{/gist_id}","starred_url":"https://api.github.com/users/a-nikitiuk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/a-nikitiuk/subscriptions","organizations_url":"https://api.github.com/users/a-nikitiuk/orgs","repos_url":"https://api.github.com/users/a-nikitiuk/repos","events_url":"https://api.github.com/users/a-nikitiuk/events{/privacy}","received_events_url":"https://api.github.com/users/a-nikitiuk/received_events","type":"User","site_admin":false},"body":"Changed to `if (!looksLikeSRA) return false;`","created_at":"2015-12-17T00:37:32Z","updated_at":"2015-12-17T00:37:32Z","html_url":"https://github.com/samtools/htsjdk/pull/407#discussion_r47855611","pull_request_url":"https://api.github.com/repos/samtools/htsjdk/pulls/407","_links":{"self":{"href":"https://api.github.com/repos/samtools/htsjdk/pulls/comments/47855611"},"html":{"href":"https://github.com/samtools/htsjdk/pull/407#discussion_r47855611"},"pull_request":{"href":"https://api.github.com/repos/samtools/htsjdk/pulls/407"}}},"pull_request":{"url":"https://api.github.com/repos/samtools/htsjdk/pulls/407","id":53449640,"html_url":"https://github.com/samtools/htsjdk/pull/407","diff_url":"https://github.com/samtools/htsjdk/pull/407.diff","patch_url":"https://github.com/samtools/htsjdk/pull/407.patch","issue_url":"https://api.github.com/repos/samtools/htsjdk/issues/407","number":407,"state":"open","locked":false,"title":"Added checks that can very early report that path is not an SRA archive and not load SRA engine and its libraries","user":{"login":"a-nikitiuk","id":12701013,"avatar_url":"https://avatars.githubusercontent.com/u/12701013?v=3","gravatar_id":"","url":"https://api.github.com/users/a-nikitiuk","html_url":"https://github.com/a-nikitiuk","followers_url":"https://api.github.com/users/a-nikitiuk/followers","following_url":"https://api.github.com/users/a-nikitiuk/following{/other_user}","gists_url":"https://api.github.com/users/a-nikitiuk/gists{/gist_id}","starred_url":"https://api.github.com/users/a-nikitiuk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/a-nikitiuk/subscriptions","organizations_url":"https://api.github.com/users/a-nikitiuk/orgs","repos_url":"https://api.github.com/users/a-nikitiuk/repos","events_url":"https://api.github.com/users/a-nikitiuk/events{/privacy}","received_events_url":"https://api.github.com/users/a-nikitiuk/received_events","type":"User","site_admin":false},"body":"We implemented several checks to see if the path looks like an SRA archive and if not fail immediately and try other readers.\r\n\r\nThis PR should address issues for users working with non-SRA data sources and limited internet connections. (for instance, that one: https://github.com/broadinstitute/picard/issues/354)\r\n\r\nThe file recognition in `SamReaderFactory` will work as follows:\r\n\r\n1. Checks if the file is a BAM file and then loads it;\r\n2. Checks if the file is a CRAM file and then loads it;\r\n3. Checks if the file is:\r\n  * An existing file, then checks its header to match SRA signature. If matched - load SRA engine and pass the file to it\r\n  * Non-existing file path, then checks if it matches to SRA accession pattern (`^[SED]RR[0-9]{6,9}$`). If matched - load SRA engine and make it check if that was a real SRA accession\r\n4. Tries to read the file as a text SAM file\r\n\r\nYou can also pass `InputResource` of type `InputResource.Type.SRA_ACCESSION`\r\n to `SamReaderFactory`, then we will load SRA engine and try to read that `InputResource` as SRA (because you specified SRA type explicitly).","created_at":"2015-12-11T22:00:39Z","updated_at":"2015-12-17T00:37:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"45f15c678305e6dd59675037ac9409d83cd9d122","assignee":{"login":"lbergelson","id":4700332,"avatar_url":"https://avatars.githubusercontent.com/u/4700332?v=3","gravatar_id":"","url":"https://api.github.com/users/lbergelson","html_url":"https://github.com/lbergelson","followers_url":"https://api.github.com/users/lbergelson/followers","following_url":"https://api.github.com/users/lbergelson/following{/other_user}","gists_url":"https://api.github.com/users/lbergelson/gists{/gist_id}","starred_url":"https://api.github.com/users/lbergelson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lbergelson/subscriptions","organizations_url":"https://api.github.com/users/lbergelson/orgs","repos_url":"https://api.github.com/users/lbergelson/repos","events_url":"https://api.github.com/users/lbergelson/events{/privacy}","received_events_url":"https://api.github.com/users/lbergelson/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/samtools/htsjdk/pulls/407/commits","review_comments_url":"https://api.github.com/repos/samtools/htsjdk/pulls/407/comments","review_comment_url":"https://api.github.com/repos/samtools/htsjdk/pulls/comments{/number}","comments_url":"https://api.github.com/repos/samtools/htsjdk/issues/407/comments","statuses_url":"https://api.github.com/repos/samtools/htsjdk/statuses/42558f76d9ffc87ec32ed682b67f424555929beb","head":{"label":"a-nikitiuk:sra-accession-check","ref":"sra-accession-check","sha":"42558f76d9ffc87ec32ed682b67f424555929beb","user":{"login":"a-nikitiuk","id":12701013,"avatar_url":"https://avatars.githubusercontent.com/u/12701013?v=3","gravatar_id":"","url":"https://api.github.com/users/a-nikitiuk","html_url":"https://github.com/a-nikitiuk","followers_url":"https://api.github.com/users/a-nikitiuk/followers","following_url":"https://api.github.com/users/a-nikitiuk/following{/other_user}","gists_url":"https://api.github.com/users/a-nikitiuk/gists{/gist_id}","starred_url":"https://api.github.com/users/a-nikitiuk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/a-nikitiuk/subscriptions","organizations_url":"https://api.github.com/users/a-nikitiuk/orgs","repos_url":"https://api.github.com/users/a-nikitiuk/repos","events_url":"https://api.github.com/users/a-nikitiuk/events{/privacy}","received_events_url":"https://api.github.com/users/a-nikitiuk/received_events","type":"User","site_admin":false},"repo":{"id":40136007,"name":"htsjdk","full_name":"a-nikitiuk/htsjdk","owner":{"login":"a-nikitiuk","id":12701013,"avatar_url":"https://avatars.githubusercontent.com/u/12701013?v=3","gravatar_id":"","url":"https://api.github.com/users/a-nikitiuk","html_url":"https://github.com/a-nikitiuk","followers_url":"https://api.github.com/users/a-nikitiuk/followers","following_url":"https://api.github.com/users/a-nikitiuk/following{/other_user}","gists_url":"https://api.github.com/users/a-nikitiuk/gists{/gist_id}","starred_url":"https://api.github.com/users/a-nikitiuk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/a-nikitiuk/subscriptions","organizations_url":"https://api.github.com/users/a-nikitiuk/orgs","repos_url":"https://api.github.com/users/a-nikitiuk/repos","events_url":"https://api.github.com/users/a-nikitiuk/events{/privacy}","received_events_url":"https://api.github.com/users/a-nikitiuk/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/a-nikitiuk/htsjdk","description":"A Java API for high-throughput sequencing data (HTS) formats.","fork":true,"url":"https://api.github.com/repos/a-nikitiuk/htsjdk","forks_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/forks","keys_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/teams","hooks_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/hooks","issue_events_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/issues/events{/number}","events_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/events","assignees_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/assignees{/user}","branches_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/branches{/branch}","tags_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/tags","blobs_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/git/refs{/sha}","trees_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/statuses/{sha}","languages_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/languages","stargazers_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/stargazers","contributors_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/contributors","subscribers_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/subscribers","subscription_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/subscription","commits_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/commits{/sha}","git_commits_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/git/commits{/sha}","comments_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/comments{/number}","issue_comment_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/issues/comments{/number}","contents_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/contents/{+path}","compare_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/merges","archive_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/downloads","issues_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/issues{/number}","pulls_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/pulls{/number}","milestones_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/milestones{/number}","notifications_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/labels{/name}","releases_url":"https://api.github.com/repos/a-nikitiuk/htsjdk/releases{/id}","created_at":"2015-08-03T16:39:32Z","updated_at":"2015-08-03T16:39:36Z","pushed_at":"2015-12-17T00:36:10Z","git_url":"git://github.com/a-nikitiuk/htsjdk.git","ssh_url":"git@github.com:a-nikitiuk/htsjdk.git","clone_url":"https://github.com/a-nikitiuk/htsjdk.git","svn_url":"https://github.com/a-nikitiuk/htsjdk","homepage":"http://samtools.github.io/htsjdk/","size":55127,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"samtools:master","ref":"master","sha":"2fa3f624e1d5841f57c3090a00e4684b9776ac24","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}","created_at":"2014-04-29T10:11:28Z","updated_at":"2015-12-12T19:06:19Z","pushed_at":"2015-12-17T00:36:10Z","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":63445,"stargazers_count":67,"watchers_count":67,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":91,"mirror_url":null,"open_issues_count":74,"forks":91,"open_issues":74,"watchers":67,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/samtools/htsjdk/pulls/407"},"html":{"href":"https://github.com/samtools/htsjdk/pull/407"},"issue":{"href":"https://api.github.com/repos/samtools/htsjdk/issues/407"},"comments":{"href":"https://api.github.com/repos/samtools/htsjdk/issues/407/comments"},"review_comments":{"href":"https://api.github.com/repos/samtools/htsjdk/pulls/407/comments"},"review_comment":{"href":"https://api.github.com/repos/samtools/htsjdk/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/samtools/htsjdk/pulls/407/commits"},"statuses":{"href":"https://api.github.com/repos/samtools/htsjdk/statuses/42558f76d9ffc87ec32ed682b67f424555929beb"}}}}