Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pysam Samfile gives error reading bamfile #51

Closed
shashidhar22 opened this issue Nov 7, 2014 · 9 comments
Closed

pysam Samfile gives error reading bamfile #51

shashidhar22 opened this issue Nov 7, 2014 · 9 comments
Assignees

Comments

@shashidhar22
Copy link

pysam Samfile give the following error when trying to read bamfile

Traceback (most recent call last):
File "sam_flanker.py", line 10, in
bam_file = pysam.Samfile(input_file, "rb")
File "csamfile.pyx", line 314, in pysam.csamfile.Samfile.cinit (pysam/csamfile.c:4820)
File "csamfile.pyx", line 491, in pysam.csamfile.Samfile._open (pysam/csamfile.c:6730)
ValueError: file header is empty (mode='rb') - is it SAM/BAM format?

@AndreasHeger
Copy link
Contributor

Is your file SAM/BAM format?

@shashidhar22
Copy link
Author

Its a BAM file. I am able to use it with samtools without any issue.

@AndreasHeger
Copy link
Contributor

Thanks, I should have been more explicit. Do you have any other information that might be helpful?

Best wishes,
Andreas

@AndreasHeger AndreasHeger self-assigned this Nov 12, 2014
@blaiseli
Copy link

I have the same problem with a bam file for which samtools view -H returns the following:

@HD VN:1.3  SO:coordinate

Strictly speaking, the header is not empty. I just have no reads in it, which may happen when the sam file resulted from a mapping of an empty file, and is a arguably legitimate situation in an analysis pipeline.

@AndreasHeger
Copy link
Contributor

Thanks, I will check this.

@lynxoid
Copy link

lynxoid commented Feb 1, 2016

Any updates on the issue? I am running into the same error w/ pysam 0.8.4.

@lynxoid
Copy link

lynxoid commented Feb 1, 2016

Some hints as to the cause of this here: https://code.google.com/archive/p/pysam/issues/104

Workaround: set check_header=False and check_sq=False when calling fetch().

@AndreasHeger
Copy link
Contributor

Not yet, will add a test case.

@AndreasHeger
Copy link
Contributor

Thanks. I had a look and it seems to me that this is indeed a feature rather than a bug.
Setting check_sq=False when opening the file is sufficient. Opened, it will return 0 for
mapped and unmapped reads and fetch() will return an empty iterator.

I 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.

Please reopen if you feel strongly about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants