{"action":"created","issue":{"url":"https://api.github.com/repos/pysam-developers/pysam/issues/51","repository_url":"https://api.github.com/repos/pysam-developers/pysam","labels_url":"https://api.github.com/repos/pysam-developers/pysam/issues/51/labels{/name}","comments_url":"https://api.github.com/repos/pysam-developers/pysam/issues/51/comments","events_url":"https://api.github.com/repos/pysam-developers/pysam/issues/51/events","html_url":"https://github.com/pysam-developers/pysam/issues/51","id":48051177,"number":51,"title":"pysam Samfile gives error reading bamfile","user":{"login":"shashidhar22","id":6678885,"avatar_url":"https://avatars.githubusercontent.com/u/6678885?v=3","gravatar_id":"","url":"https://api.github.com/users/shashidhar22","html_url":"https://github.com/shashidhar22","followers_url":"https://api.github.com/users/shashidhar22/followers","following_url":"https://api.github.com/users/shashidhar22/following{/other_user}","gists_url":"https://api.github.com/users/shashidhar22/gists{/gist_id}","starred_url":"https://api.github.com/users/shashidhar22/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shashidhar22/subscriptions","organizations_url":"https://api.github.com/users/shashidhar22/orgs","repos_url":"https://api.github.com/users/shashidhar22/repos","events_url":"https://api.github.com/users/shashidhar22/events{/privacy}","received_events_url":"https://api.github.com/users/shashidhar22/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":{"login":"AndreasHeger","id":4426336,"avatar_url":"https://avatars.githubusercontent.com/u/4426336?v=3","gravatar_id":"","url":"https://api.github.com/users/AndreasHeger","html_url":"https://github.com/AndreasHeger","followers_url":"https://api.github.com/users/AndreasHeger/followers","following_url":"https://api.github.com/users/AndreasHeger/following{/other_user}","gists_url":"https://api.github.com/users/AndreasHeger/gists{/gist_id}","starred_url":"https://api.github.com/users/AndreasHeger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndreasHeger/subscriptions","organizations_url":"https://api.github.com/users/AndreasHeger/orgs","repos_url":"https://api.github.com/users/AndreasHeger/repos","events_url":"https://api.github.com/users/AndreasHeger/events{/privacy}","received_events_url":"https://api.github.com/users/AndreasHeger/received_events","type":"User","site_admin":false},"milestone":null,"comments":9,"created_at":"2014-11-07T06:00:35Z","updated_at":"2016-02-09T21:06:44Z","closed_at":"2016-02-09T21:06:42Z","body":"pysam Samfile give the following error when trying to read bamfile\r\n\r\nTraceback (most recent call last):\r\n  File \"sam_flanker.py\", line 10, in <module>\r\n    bam_file = pysam.Samfile(input_file, \"rb\")\r\n  File \"csamfile.pyx\", line 314, in pysam.csamfile.Samfile.__cinit__ (pysam/csamfile.c:4820)\r\n  File \"csamfile.pyx\", line 491, in pysam.csamfile.Samfile._open (pysam/csamfile.c:6730)\r\nValueError: file header is empty (mode='rb') - is it SAM/BAM format?\r\n"},"comment":{"url":"https://api.github.com/repos/pysam-developers/pysam/issues/comments/182067885","html_url":"https://github.com/pysam-developers/pysam/issues/51#issuecomment-182067885","issue_url":"https://api.github.com/repos/pysam-developers/pysam/issues/51","id":182067885,"user":{"login":"AndreasHeger","id":4426336,"avatar_url":"https://avatars.githubusercontent.com/u/4426336?v=3","gravatar_id":"","url":"https://api.github.com/users/AndreasHeger","html_url":"https://github.com/AndreasHeger","followers_url":"https://api.github.com/users/AndreasHeger/followers","following_url":"https://api.github.com/users/AndreasHeger/following{/other_user}","gists_url":"https://api.github.com/users/AndreasHeger/gists{/gist_id}","starred_url":"https://api.github.com/users/AndreasHeger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndreasHeger/subscriptions","organizations_url":"https://api.github.com/users/AndreasHeger/orgs","repos_url":"https://api.github.com/users/AndreasHeger/repos","events_url":"https://api.github.com/users/AndreasHeger/events{/privacy}","received_events_url":"https://api.github.com/users/AndreasHeger/received_events","type":"User","site_admin":false},"created_at":"2016-02-09T21:06:44Z","updated_at":"2016-02-09T21:06:44Z","body":"Thanks. I had a look and it seems to me that this is indeed a feature rather than a bug. \r\nSetting check_sq=False when opening the file is sufficient. Opened, it will return 0 for \r\nmapped and unmapped reads and fetch() will return an empty iterator.\r\n\r\nI have added a test case covering this and modified the error message. On balance I would hesitate to disable the check at this stage - it is currently the primary way of detecting if the format is valid when opening a file.\r\n\r\nPlease reopen if you feel strongly about this."}}