Skip to content

Instantly share code, notes, and snippets.

@danielecook
Created August 11, 2020 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielecook/887c116e08fc9b6368557ea6c1d7462d to your computer and use it in GitHub Desktop.
Save danielecook/887c116e08fc9b6368557ea6c1d7462d to your computer and use it in GitHub Desktop.
Split bedfile by chromosome and chunk size #bed
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