Dear Biostars, 

I have a multisample vcf. I would like a to turn this into a per sample "alts"  file as below. 

The desired outcome would be :

    chr10:12342:A:T  SAMPLEID1:0/1 SAMPLEID2:1/1 ...
    chr10:432234:G:C SAMPLEID4:0/1 SAMPLEID7:1/1 ...

I have tried :

    bcftools query -f "%CHROM:%POS:%REF:%ALT\n[%SAMPLE:%GT\t]'  i- 'GT="alt"' input.vcf 

which gives me:

    chr10:12342:A:T  SAMPLEID1:0/1 SAMPLEID2:1/1 chr10:432234:G:C 
    SAMPLEID4:0/1 SAMPLEID7:1/1 ...

or 

     bcftools query -f "%CHROM:%POS:%REF:%ALT\t[%SAMPLE:%GT\n']  i- 'GT="alt"' input.vcf 


    chr10:12342:A:T  SAMPLEID1:0/1 
    SAMPLEID2:1/1 
    chr10:432234:G:C SAMPLEID4:0/1 
    SAMPLEID7:1/1 

or

  

      bcftools query -f "%CHROM:%POS:%REF:%ALT\t[%SAMPLE:%GT\t']  i- 'GT="alt"' input.vcf 

      chr10:12342:A:T  SAMPLEID1:0/1 SAMPLEID2:1/1 chr10:432234:G:C SAMPLEID4:0/1 SAMPLEID7:1/1 

I can't quite get my head around the correct syntax and sure there is an easy fix! Your help would be much appreciated. 

All the best






Figured it out! 

    bcftools query -f "%CHROM:%POS:%REF:%ALT[\t%SAMPLE:%GT]\n'  i- 'GT="alt"' input.vcf 

Just needed to move the \n out of the square brackets! 