Dear Team,
I am wondering is there an option/function to perform "moving average" to coverage signal with bedtools or other related tools?
Something like: bedtools movingAverage -i a.bed --start --end --bin 200bp --out
Thanks.
Shicheng
Dear Team,
I am wondering is there an option/function to perform "moving average" to coverage signal with bedtools or other related tools?
Something like: bedtools movingAverage -i a.bed --start --end --bin 200bp --out
Thanks.
Shicheng
Hi there
What I do for this is use a combination of three bedtools functions, genomecov,
makewindows
and map
.
In addition to the coverage bed file, I also require a bed file of the genome assembly (chromosome name in first column, and size in second, I usually just take the first two columns from the .fai file after samtools faidx, 'genome.bed' below)
First, my coverage input:
bedtools genomecov -d -ibam sample.bam > sample.cov.tsv
Next is to split up the assembly bed file into the windows with makewindows by giving it the window size and how far to slide each time
bedtools makewindows -w sizeofwindow -s sizeofslide -g genome.bed > genome.windows.bed
Then next thing is bedtools map which essentially takes all the windows created before and calculates what ever average asked for (-o)
First though I just have to modify the raw output from genomecov, to repeat the second column twice (the basepair position) essentially saying that the 'window' in which the coverage comes from is actually single basepair position
cat sample.cov.tsv | awk '{print $1"\t"$2"\t"$2"\t"$3}' | bedtools map -b - -a genome.windows.bed -c 4 -o median > sample.cov.movingaverage.tsv
Hope that helps
This is one of the BEDOPS recipes, with one small change:
https://bedops.readthedocs.io/en/latest/content/usage-examples/smoothing-tags.html
Just replace --count
with --mean
to do a moving average over the sliding window. Other parameters let you change the size of the window and the sliding step.
Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Hi, I was looking into this a while ago and didn't find nothing comparable, either. I ended up loading it into a R dataframe/tibble and apply a rolling average, something along this (from here):