Last active
May 24, 2023 18:50
-
-
Save arq5x/c057f896384b38d31b523223ef0225ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
chr1 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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