This is a test version of Biostars. For the public version, visit https://www.biostars.org.
compute genome coverage from specific bam contig

Hi there,

I have a BAM file containing mutliple contigs. I want to compute coverage only on a specific contig. I'm usualy using bedtools for computing coverage directly on my bam, like that:

bedtools genomecov -ibam simple.bam > simple.cov

The problem is that when i'm using this command on my "multiple.sam" the coverage of every contig is computed, including human chromosone, that I dont want in output.

I started to search a way to filtrate my bam,like this one (MN908947.3 is the only contig I want to keep) :

samtools view -b multiple.bam MN908947.3 > filtrate.bam
bedtools genomecov -ibam filtrate.bam -d > result.cov

But it's exactly the same result, bedtools compute every contig , ie 0 because for almost contig because bam is filtrated. This file is to huge to be handled easly.

I started to read more about this tool here : samjs but I dont realy know if this tool can solve my problem, and how to use it with java synthax.

Do you have any clues?

Thx and stay safe:)

samtools bedtools

1 answer

use mosdepth https://github.com/brentp/mosdepth/ with --chrom option.

Log in to answer this question.