brittneybrinsfield / pysam

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

Negative size passed to PyString_FromStringAndSize from IndelCall.second_allele #68

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago

In [4]: for n,ref in enumerate(samfile.references) :
   ...:     pileup_iter = samfile.pileup( stepper = "samtools", fastafile = fastafile, reference=ref )
   ...:     indelcall_iter = pysam.IteratorIndelCalls( pileup_iter )
   ...:     indels = filter( lambda x:x, indelcall_iter )
   ...:     for i in indels :
   ...:         print i.second_allele
   ...:         
*
*
*
*
---------------------------------------------------------------------------
SystemError                               Traceback (most recent call last)
/home/russell/pkg/pysam-0.5-test/build/lib.linux-x86_64-2.7/<ipython-input-4-d93
5ae0a6829> in <module>()
      4     indels = filter( lambda x:x, indelcall_iter )
      5     for i in indels :
----> 6         print i.second_allele
      7 

/home/russell/pkg/pysam-0.5-test/build/lib.linux-x86_64-2.7/csamtools.so in 
csamtools.IndelCall.second_allele.__get__ (pysam/csamtools.c:28934)()

SystemError: Negative size passed to PyString_FromStringAndSize

I added the following properties to class IndelCall in csamtools.pyx :

    property debug_s0:
       def __get__(self): return self._r.s[0]
    property debug_s1:
       def __get__(self): return self._r.s[1]
    property debug_indel1:
       def __get__(self): return self._r.indel1
    property debug_indel2:
       def __get__(self): return self._r.indel2

I then recompiled, reloaded the data, and reproduced the error. I found the 
following values :

   In [6]: i.debug_indel1
   Out[6]: 0

   In [7]: i.debug_indel2
   Out[7]: -2

   In [8]: i.debug_s0
   Out[8]: '*'

   In [9]: i.debug_s1
   Out[9]: '-CT'

So, PyString_FromStringAndSize is being invoked with the arguments

   PyString_FromStringAndSize( '-CT', -2 + 1 )

So, we are indeed getting a negative size.

From looking at the docstrings for the indel calling functions (e.g., 
IteratorIndelCalls), it looks like the functions might have been cut-and-pasted 
from their sister functions for calling SNPs. SNPs will always have a length of 
1, so adding 1 to a negative size should prevent this error. 

Though, I'm rather confused as to why the length should be negative in the fist 
place....

Original issue reported on code.google.com by rynec...@gmail.com on 1 Sep 2011 at 3:28

GoogleCodeExporter commented 9 years ago
Thank you! 

I had to take out IteratorIndelCalls as it is based on the deprecated samtools 
pileup code. The code likely needs to be completely rewritten for mpileup.

Best wishes,
Andreas

Original comment by andreas....@gmail.com on 6 Dec 2011 at 7:51