Get both ends of fragment using pysam
0
1
Entering edit mode
3.6 years ago
h.c.donker ▴ 10

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 • 725 views
ADD COMMENT

Login before adding your answer.

Traffic: 2598 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6