Created
February 14, 2015 12:36
-
-
Save pontikos/9f438d59887a0f049527 to your computer and use it in GitHub Desktop.
Get sample names from 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
#! /bin/env bash | |
function error() { >&2 echo -e "\033[31m$*\033[0m"; } | |
function stop() { error "$*"; exit 1; } | |
try() { "$@" || stop "cannot $*"; } | |
file=$1 | |
#doesn't work for double extension .gvcf.gz | |
ext="${file##*.}" | |
search= | |
function usage { | |
echo "usage: $0 <file>" | |
} | |
if [[ "$ext" == "gvcf" || "$ext" == "vcf" ]] | |
then | |
search=grep | |
elif [[ "$ext" == "gz" ]] | |
then | |
search=zgrep | |
else | |
usage | |
stop "unrecognised extension $ext" | |
fi | |
$search -m1 '^#CHROM' $file | tr '\t' '\n' | grep -v -F -f <(echo '#CHROM,POS,ID,REF,ALT,QUAL,FILTER,INFO,FORMAT' | tr ',' '\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment