lixin6135 / pysam

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

Segmentation fault when accessing aligned read in pileup column #99

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I have a function:

def get_pileupcol(bam, chrom, start, end):
     for pileupcol in bam.pileup(chrom, start, end):
         if pileupcol.pos == start:
             return pileupcol

and code that accesses it:

counts = {'A': 0, 'C': 0, 'G': 0, 'T': 0}
pileupcol = get_pileupcol(bam, chrom, start, end)
for pileupread in pileupcol.pileups:
    base = pileupread.alignment.seq[pileupread.qpos]
    if base in counts:
        counts[base] += 1
    print counts

This will cause a segmentation fault. However if the code is modified so the 
function returns the pileups directly then there is no segmentation fault:

def get_pileups(bam, chrom, start, end):
     for pileupcol in bam.pileup(chrom, start, end):
         if pileupcol.pos == start:
             return pileupcol.pileups

counts = {'A': 0, 'C': 0, 'G': 0, 'T': 0}
pileups = get_pileupcol(bam, chrom, start, end)
for pileupread in pileups:
    base = pileupread.alignment.seq[pileupread.qpos]
    if base in counts:
        counts[base] += 1
    print counts

Original issue reported on code.google.com by tyler.fu...@gmail.com on 4 Oct 2012 at 7:57

GoogleCodeExporter commented 8 years ago
Hi,

this problem is known and can't be fixed easily. 

Basically, when iterating through a file the iterator variable is a proxy for 
the underlying iterator in c-samtools. If the iteration finishes, the proxy 
points
to no result.

I have changed the code to raise an exception.

Best wishes,
Andreas

Original comment by andreas....@gmail.com on 20 Nov 2012 at 11:31

GoogleCodeExporter commented 8 years ago

Original comment by andreas....@gmail.com on 20 Nov 2012 at 11:31