Skip to content

Instantly share code, notes, and snippets.

@janxkoci
Last active November 17, 2018 22:22
Show Gist options
  • Save janxkoci/a21298b9b21f185901ce22d7c63e986b to your computer and use it in GitHub Desktop.
Save janxkoci/a21298b9b21f185901ce22d7c63e986b to your computer and use it in GitHub Desktop.
AWK script to parse info on a single sample and position from a VCF file
#!/bin/bash
# bash awk_vcf_anim_chrom_pos.sh in.vcf sample chrom pos
echo vcf: "$1"
echo sample: "$2"
echo chrom: "$3"
echo pos: "$4"
awk -v sample=$2 -v chrom="$3" -v pos=$4 \
'/#CHROM/ {for(i=1;i<=NF;i++) if ($i~sample) f=i;next} ($1==chrom && $2==pos) {print $1 "_" $2 ": " $f " (" $9 ")"}' $1
@janxkoci
Copy link
Author

janxkoci commented Nov 17, 2018

FORMAT field could be added to the output by adding $9 to the print statement, for easier interpretation of the output

Edit: DONE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment