We've moved!
This site is now read-only. You can find our new documentation site and support forum for posting questions here.
Be sure to read our welcome blog!

Count Genotypes per position in a multi-sample VCF

Hello,

For a multi-sample VCF is there a module/walker availble in GATK to count the total number genotypes for every position? (i.e. give the counts each of het., alt.hom, reference or unknown)

Thanks,
Mika

Best Answer

Answers

  • mikawinmikawin Member

    Hi G,

    Thanks for your reply. Before I plunged and wrote a script, I wanted to make sure that I was not re-inventing the wheel!

    Cheers,
    M

  • estif74estif74 Saint Paul, MN, USAMember

    Hi, sorry if you may have figured this out already in a walker you wrote, but I was searching for the same thing today. It looks like if you use the walker VariantsToTable you can add -F HOM-REF -F HET -F HOM-VAR -F NO-CALL to your arguments, you can count the genotypes at every position. There's a little blurb right in the Overview section that explains this. Maybe this is a new function in 3.4, but it's quite handy so thanks GATK Development Team :-)

  • SheilaSheila Broad InstituteMember, Broadie admin

    @estif74
    Ah, thanks for catching that. Hopefully, Mika and others will find this helpful.

    -Sheila

  • tommycarstensentommycarstensen United KingdomMember ✭✭✭
    edited August 2015

    @mikawin @estif74 Unfortunately bcftools cannot do this to the best of my knowledge (not in one loop anyway). If I remember correctly GT has to be the first field according to the VCF file format description, so you can just do this awk one liner, if you care about memory and being able to pipe your output and don't care about speed/parallelisation:

    zcat mikawin.vcf.gz \
    | grep -v ^# \
    | awk '{
     unknown=0; homref=0; het=0; homalt=0; for(i=10;i<=NF;i++) {
      split($i,a,":"); split(a[1],GT,"[/|]");
      if(GT[1]=="."&&GT[2]==".") {unknown++}
      else if(GT[1]==0&&GT[2]==0) {homref++}
      else if(GT[1]==GT[2]) {homalt++}
      else {het++}};
     print $1,$2,$3,$4,$5,unknown,homref,homalt,het}'
    
Sign In or Register to comment.