user2725109
user2725109

Reputation: 2386

Samtools pysam mate

I am using pysam to dome data mining on .bam files. I want to check if a read has a mapped mate. The command

mate = samfile.mate(read1)

throws an error if the mate is not mapped, so if I do

if samfile.mate(read1): ...

that throws an error, too. Any other way to check if the read has a mapped mate?

Thanks.

Upvotes: 0

Views: 701

Answers (1)

Shawn Sullivan
Shawn Sullivan

Reputation: 156

AlignedSegment.mate_is_unmapped should work for you. See docs for pysam

if not read1.mate_is_unmapped:
    mate = samfile.mate(read1)
    ...

Alternatively, you could just catch the exception and move on, but relying on exception handling for normal program flow is not ideal.

Upvotes: 0

Related Questions