MaciekAber / pysam

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

segfault due to unimplemented __getattr__ in csamtools.PileupProxy.pileups #55

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
A segfault may be induced by invoking dir() on 

samfile = pysam.Samfile( 'samfile.bam', 'rb' )
for pc in samfile.pileup( 'record', 100, 120 ) :
    print 'coverage @ base %s = %s' % (pc.pos, pc.n)

dir(pc.pileups)
<<Segmentation fault>>

Segfault can be avoided in interactive mode by adding 

    def __getattr__(self) :
        return []

at line 1896 of csamtools.pyx (with respect to pysam-0.3.1). 

Of course, it would be better to actually implement it...

Original issue reported on code.google.com by rynec...@gmail.com on 19 Jan 2011 at 2:39

GoogleCodeExporter commented 8 years ago
Actually, I suspect that this issue is behind some of the other segfault bugs. 
Gotta make sure your C objects implement the basic set of python builtins, or 
funny things happen.

Original comment by rynec...@gmail.com on 19 Jan 2011 at 2:43

GoogleCodeExporter commented 8 years ago
Thanks,

I can't reproduce it. Cython adds most of the object interface.

>>> samfile = pysam.Samfile( 'ex1.bam','rb')
>>> for pc in samfile.pileup( 'chr1', 100, 120 ) 
...     print 'coverage @ base %s = %s' % (pc.pos, pc.n) 
---
>>> dir(pc.pileups)
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', 
'__delslice__', '__doc__', '__eq__', '__format__', '__ge__', 
'__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', 
'__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', 
'__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', 
'__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', 
'__sizeof__', '__str__', '__subclasshook__', 'append', 'count', 'extend', 
'index', 'insert', 'pop', 'remove', 'reverse', 'sort']

Two issues might apply here:

1. pc.pileups is undefined out of the loop. For reasons of efficiency, the 
iterator
variable is only a proxy towards a C construct. This might become invalidated 
at the
end the iteration. I will keep an eye on this.

2. the filename bug.

Bw, 
Andreas

Original comment by andreas....@gmail.com on 10 Feb 2011 at 10:51