-
-
Save edawson/3ceb7c0fae0fae8ed070dfec6a1e667e to your computer and use it in GitHub Desktop.
Natural sort a VCF
This file contains hidden or 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 hidden or 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 | |
# Natural sorts a VCF using linux sort's | |
# built-in parallelization | |
[ $# -eq 0 ] && { echo "Sorts a VCF file in natural chromosome order";\ | |
echo "Usage: $0 [my.vcf | my.vcf.gz]"; exit 1; | |
} | |
if (zless $1 | grep ^#; zless $1 | grep -v ^# | LC_ALL=C sort -S 80% --parallel=4 -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 hidden or 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 hidden or 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