Skip to content

Instantly share code, notes, and snippets.

@arq5x
Last active May 24, 2023 18:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arq5x/c057f896384b38d31b523223ef0225ed to your computer and use it in GitHub Desktop.
Save arq5x/c057f896384b38d31b523223ef0225ed to your computer and use it in GitHub Desktop.
# 1. convert dpeths file to bed (start is 0-based)
awk -v OFS="\t" '{print $1,$2-1,$2,$3}' toy.depths.txt > toy.depths.bed
# peek
head toy.depths.bed
chr1 0 1 5
chr1 1 2 4
chr1 2 3 3
chr1 3 4 2
chr1 4 5 1
chr1 5 6 10
chr1 6 7 20
chr1 7 8 30
chr1 8 9 40
chr1 9 10 50
# 2. make a BED files of 5bp (or 1000 in your case) intervals
# This requires a "genome" file which defines the length of each chromosome, so that it knows how many windows
# to make for each chromosome. See "genome.txt", each chrom is a line and second column is length of the chrom
bedtools makewindows -w 5 -g genome.txt > genome.5bp.bed
cat genome.5bp.bed
chr1 0 5
chr1 5 10
# 3. "map" (intersect, but with the ability to summarize data from the intersections)
# the window file with the depths file and compute the mean of the 4th column from
# the depths file
# https://bedtools.readthedocs.io/en/latest/content/tools/map.html
bedtools map -a genome.5bp.bed -b toy.depths.bed -c 4 -o mean
chr1 0 5 3
chr1 5 10 30
chr1 1 5
chr1 2 4
chr1 3 3
chr1 4 2
chr1 5 1
chr1 6 10
chr1 7 20
chr1 8 30
chr1 9 40
chr1 10 50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment