Created
August 11, 2020 14:09
-
-
Save danielecook/887c116e08fc9b6368557ea6c1d7462d to your computer and use it in GitHub Desktop.
Split bedfile by chromosome and chunk size #bed
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
function split_bed() { | |
# This function will split a bed file by chromosome and chunk_size=1000 | |
# In other words, split files will only possess one chromosome max. | |
# File sizes may be variable. | |
awk -v chunk_size=1000 'NR == 1 { chrom=$1; iter=0; fname_iter=0; print chrom } | |
{ | |
if(chrom == $1 && iter <= chunk_size) { | |
print > sprintf("x%04d_%s.segment.txt", fname_iter, $1); | |
iter++; | |
} else { | |
chrom=$1; | |
iter=0; | |
fname_iter++; | |
} | |
}' $1 | |
} | |
split_bed SureSelectV5_TRACERx_Edition.bed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment