brittneybrinsfield / pysam

Automatically exported from code.google.com/p/pysam
0 stars 0 forks source link

Using pysam with an unaligned bam file #117

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
import pysam
bam = pysam.Samfile("test_unaligned.bam", "rb")

What is the expected output? What do you see instead?

I expect (or would like) pysam to simply open the file and read the data that 
is available.

Instead, I get:

 In [4]: bam = pysam.Samfile("test_unaligned.bam", "rb")
 ---------------------------------------------------------------------------
 ValueError                                Traceback (most recent call last)
 <ipython-input-4-d5030d65448f> in <module>()
 ----> 1 bam = pysam.Samfile("test_unaligned.bam", "rb")

 /share/apps/python/2.7.3-shared/lib/python2.7/site-packages/pysam/csamtools.so in csamtools.Samfile.__cinit__ (pysam/csamtools.c:5982)()

 /share/apps/python/2.7.3-shared/lib/python2.7/site-packages/pysam/csamtools.so in csamtools.Samfile._open (pysam/csamtools.c:7675)()

 ValueError: file header is empty (mode='rb') - is it SAM/BAM format?

This is entirely true, but I still should be able to do useful things with the 
file in python.

What version of the product are you using? On what operating system?

0.7.4, Linux (CentOS6.0, python 2.7.3)

Please provide any additional information below.

Original issue reported on code.google.com by kevin.sq...@gmail.com on 20 Mar 2013 at 5:09

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks. It is possible to do this with a workaround:

input_filename = "test_unaligned.bam"
# do not check for sequence names when opening
samfile = pysam.Samfile( input_filename, "rb", check_sq = False )
# do not require index when collecting
samfile.fetch( until_eof = True )

Would this suffice?

Best wishes,
Andreas

Original comment by andreas....@gmail.com on 26 Jun 2013 at 8:05

GoogleCodeExporter commented 9 years ago
This is a great solution. Thanks so much! I'm glad this thread will come up 
next time people search this issue. Thanks!

Original comment by psudm...@gmail.com on 26 Jun 2013 at 8:11