This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Merge regions in bedgraph file

I have a bedgraph file with the chromosome, start and end point, and the coverage:

CM000994.3      10167710        10167711        95

CM000994.3      10167718        10167720        95

I want to merge regions that are close together.

With a bed file I could use something like this:

bedtools merge -d 1000 -i file.bed >file.merged.bed

Is there a similar thing for bedgraph files? I could convert to bed and then merge, but then I loose the information about coverage.

bedgraph

bedGraphs are BED files, and bedtools merge has options -c and -o which determine how it should summarize additional columns of overlapping regions, e.g. summing, averaging. Check the help section of bedtools merge.

1 answer

Thanks. I was able to do this with:

bedtools merge -d 1000 -c 4 -o sum -i Coverage.bedgraph > Coverage.merged.bedgraph

Log in to answer this question.