Last active
January 24, 2019 13:02
-
-
Save arq5x/ab78b7be4d4f2a989a31 to your computer and use it in GitHub Desktop.
Natural sort a VCF
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
chmod a+x vcfsort.sh | |
vcfsort.sh trio.trim.vep.vcf.gz |
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
#!/bin/bash | |
# Faster, but can't handle streams | |
[ $# -eq 0 ] && { echo "Sorts a VCF file in natural chromosome order";\ | |
echo "Usage: $0 [my.vcf | my.vcf.gz]"; exit 1; | |
} | |
# cheers, @michaelhoffman | |
if (zless $1 | grep ^#; zless $1 | grep -v ^# | LC_ALL=C sort -k1,1V -k2,2n); | |
then | |
exit 0 | |
else | |
printf 'sort failed. Does your version of sort support the -V option?\n' | |
printf 'If not, you should update sort with the latest from GNU coreutils:\n' | |
printf 'git clone git://git.sv.gnu.org/coreutils' | |
fi |
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
#!/bin/bash | |
# Slower, but handles streams. | |
[ $# -eq 0 ] && { echo "Sorts a VCF file in natural chromosome order";\ | |
echo "Usage: $0 [my.vcf | my.vcf.gz]"; \ | |
echo "Usage: cat [my.vcf | my.vcf.gz] | $0"; \ | |
exit 1; | |
} | |
# cheers, @colbychiang | |
if zless $1 | awk '$0~"^#" { print $0; next } { print $0 | "LC_ALL=C sort -k1,1V -k2,2n" }'; | |
then | |
exit 0 | |
else | |
printf 'sort failed. Does your version of sort support the -V option?\n' | |
printf 'If not, you should update sort with the latest from GNU coreutils:\n' | |
printf 'git clone git://git.sv.gnu.org/coreutils' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment