This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Retrieve coverage/depth of individual bed tracks from merged bed

I have been using bedtools for a long time but I can't seem to quite figure the following operation. Hope someone can help!

cat test.bed 
chr1    5   27
chr1    7   12
chr1    10  20
chr1    22  27
chr1    24  30

bedtools merge -i test.bed
chr1    5   30

Now I wish to conduct something that would like :

# first two lines
chr1    5    6   1  #only shown once
chr1    7    10  2  #shown twice

I can do it with coverage option by showing the base depth option, but surely there may be something that is even quicker!

bedtools

1 answer

You can try bedtools genomecov :

cat  test.bed
chr1    5   27
chr1    7   12
chr1    10  20
chr1    22  27
chr1    24  30

cat chr.txt
chr1    50

bedtools genomecov -i test.bed -g chr.txt -bg
chr1    5   7   1
chr1    7   10  2
chr1    10  12  3
chr1    12  20  2
chr1    20  22  1
chr1    22  24  2
chr1    24  27  3
chr1    27  30  1

Log in to answer this question.