This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Get both ends of fragment using pysam

Hi,

I am trying to analyse both ends of a fragment from a BAM file, that overlaps at a specific genomic position. I do this with the pysam library. But I haven't been able to find a way to get the other end belonging to a given read. My code essentially looks like this:

for pile in bam_file.pileup(contig=chromosome, start=start_position):
    for read in pile.pileups:
        if read.is_del or read.is_refskip:
            continue
        read_mate = bam_file.mate(read.alignment)

but the last statement gives the error *** ValueError: mate not found even though read.alignment.is_paired returns True. Perhaps an alternative strategy could be to use the id of the other end read.alignment.next_reference_id. But unfortunately, I can't find a pysam function that can fetch the read by id. I must be overlooking something obvious, because I can't imagine extracting both ends being that hard. Any ideas how to go on about doing this?

Thanks,

Hylke

alignment

0 answers

No answers yet.

Log in to answer this question.