This is a test version of Biostars. For the public version, visit https://www.biostars.org.
compute count of position coverage with bedtools

I have a bed files with several regions :

exons.bed 
chr4   4    200
chr5   3    100 
chr5   90  110

I want to get the number of position covered by this bed file. For the exemple, I want : (200-4) + (100-3) + 10

bedtools

You could use R:

bed = read.delim(exons.bed,as.is=T)
bp_covered = sum(bed[,3]-bed[,2])

1 answer

For now, I success with this oneliner :

bedtools merge -i test.bed|awk '{print $3-$2}'|paste -sd+|bc

Log in to answer this question.