This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Getting read counts per loci

How can I get the number of mapped reads for a particular region?

samtools view -c -F 4 my.bam gives me count in the entire bam file but I can't just add -r Chr1:0:1000 to get reads in that region only.

bam rna-seq samtools

1 answer

samtools view in.bam chr1:0-1000 | wc -l

but better way is to do it with bedtools if you have many regions, for e.g like exon coordinates or peak coordinates, which is more efficient way for counting purpose.

bedtools multicov -bams aln1.bam [ aln2.bam aln3.bam . . ] -bed ivls-of-interest.bed

Just to confirm, the number of lines in a BAM file give the info on the number of reads it has? Apologies, I am completely new to this area.

Pls check the link in updated answer.

Just confirming that for any given region, they both should give the same number?

Log in to answer this question.