Pysam--how to check for empty results in fetch(region) of bam file
0
0
Entering edit mode
4.7 years ago
swidler • 0

I'm reading a bam file using Pysam, but I couldn't find one file for the whole genome, so I'm iterating over the chromosomes. When I fetch a region by chromosome, only the file-specific chromosome will get results (ie if I fetch "21" in the chrom 1 file, I shouldn't get any results). Is there a way to determine at the fetch that there's no data so I can move on? Thanks.

genome alignment • 1.6k views
ADD COMMENT
0
Entering edit mode

I found count(region), which does more or less what I want (ie it tells me if the region returns nothing), but running it on a non-empty region takes a while and I'm hoping there's a better way.

ADD REPLY
0
Entering edit mode

The most simply way would be to name the files that way, that you know which chromosome is in.

Another way would be to use pysam's get_index_statistics() which will give you the number of mapped, unmapped and total reads per contig.

ADD REPLY

Login before adding your answer.

Traffic: 2015 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