This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Bedtools merge messing chromosome start - end points

Hello everyone,

I am trying to merge my bedtools genomecov output using the bedtools merge option. I am using this data :

Chromosome_1    0   54  0
Chromosome_1    54  204 3
Chromosome_1    204 410 0
Chromosome_1    410 476 2
Chromosome_1    476 502 4 ....

I used the following command to run:

' bedtools merge' -i input.sorted.bam -c 4 -o mean > output. coverage

Here is the output:

Chromosome_1 0 7841240 48.9278333
Chromosome_10 0 9941773 17.7389834

I am expecting to get:

Chromosome_1 0 7841240 48.9278333
Chromosome_2 7841240 x  23.9494951

Can anyone please suggest a way to do it?

TIA!

genome merge bedtools merge bedtools

2 answers

Can anyone please suggest a way to do it?

use sort -t $'\t' -k1,1V -k2,2n or bedtools sort with option -g

bedtools merge does not mess around with your chromosomes. In fact if you use it with bedfiles it expects them to be previously sorted with sort -k1,1 -k2,2n, therefore chromosomes end up being sorted as 1 10..19 2 20..22 MT X Y.

If you need some other sorting, just provide it yourself at the end of your command as Pierre suggested:

bedtools merge -i input.sorted.bam -c 4 -o mean | sort -k1,1V -k2,2n > output. coverage

Log in to answer this question.