brittneybrinsfield / pysam

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

Segmentation fault on pysam.Samfile().pileup().next() #131

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.
Python 2.6.6 (r266:84292, Feb 22 2013, 00:00:18)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pysam
>>> pysam.__version__
'0.7.5'
>>> pcolumn = pysam.Samfile("ex1.bam", "rb" ).pileup( 'seq1', 10, 20).next()
>>> for pread in pcolumn.pileups:
...   print "read: {0}, base: {1}".format(pread.alignment.qname, 
pread.alignment.seq[pread.qpos])
...
Segmentation fault (core dumped)

2.
Using example dataset from:
https://bamseek.googlecode.com/files/ex1.bam

What is the expected output? What do you see instead?
I expect to be able to iterate over the pileup reads. Instead I get a 
"Segmentation fault".

What version of the product are you using? On what operating system?
I'm using pysam 0.7.5, python 2.6.6 in a CentOS 6.4.

Please provide any additional information below.
A small modification of the above code does work. I can't say why.
>>> p = pysam.Samfile("ex1.bam", "rb" ).pileup( 'seq1', 10, 20)
>>> pcolumn = p.next()
>>> for pread in pcolumn.pileups:
...   print "read: {0}, base: {1}".format(pread.alignment.qname, 
pread.alignment.seq[pread.qpos])
...
read: B7_591:4:96:693:509, base: C

Original issue reported on code.google.com by carlos.b...@gmail.com on 1 Jul 2013 at 3:01

GoogleCodeExporter commented 9 years ago
Thanks. The issue is that the iterator object closes after .next(). 

The solution is to keep an object alive. The following works:

piter = pysam.Samfile("ex1.bam", "rb" ).pileup( 'seq1', 10, 20)
pcolumn = piter.next()
for pread in pcolumn.pileups:
    print "read: {0}, base: {1}".format(pread.alignment.qname, pread.alignment.seq[pread.qpos])

I have now created an error that should prevent the segfault and
added some documentation

Best wishes,
Andreas

Original comment by andreas....@gmail.com on 17 Sep 2013 at 8:09