There may already be a recipe for this, so asking first before reinventing the wheel:
I would like to create a bed file where the score is the average mapQ from the reads of the
input.bam
file. I think bedtools
or bedops
are the way to go:http://bedtools.readthedocs.org/en/latest/content/tools/bamtobed.htmlhttp://bedops.readthedocs.org/en/latest/content/reference/file-management/conversion/bam2bed.html
Other than simply running bamtobed
/bam2bed
, I would like to be able to define a sliding window size and step for the windows, of say, size=1000 and step=200.
I also would like to generate the bam2bed information only from a list of regions in regions.bed
. E.g., something like:mapq_sliding_windows --bam input.bam --wsize 1000 -wstep 200 --regions regions.bed > mapq_sliding_windows.bed
EDITED:
Thank you Aaron for you answer. I got it working but it's slow for my 30x WGS bams:
mysql --user=genome --host=genome-mysql.cse.ucsc.edu -A -e "select chrom, size from hg19.chromInfo" > hg19.genome
bedtools makewindows -g hg19.genome -w 1000 -s 200 > hg19.windows.bed
bedtools map -a hg19.windows.bed -b <(bedtools bamtobed -i input.bam | grep -v chrM) -c 5 -o mean > ...