This is a test version of Biostars. For the public version, visit https://www.biostars.org.
VCF: removing all FORMAT but FORMAT/GT

how do i grep the vcf, so that i only need the GT information

Input:

chr1    67947   rs1202587463    A       AT      .       PASS    -       GT:GQ:DP:AD:MIN_DP:PGT:PID:PL:SB        0/0:22:21:.:11:.:.:.:.  0/0:24:21:.:9:.:.:.:.   0/0:2
chr1    69928   .       T       TAC     .       PASS    -       GT:GQ:DP:AD:MIN_DP:PGT:PID:PL:SB        0/0:21:22:.:8:.:.:.:.   0/0:35:34:.:21:.:.:.:.  0/0:30:18:.:1

I want the output as

chr1    67947   rs1202587463    A       AT      .       PASS    -       GT        0/0  0/0   0/0
chr1    69928   .       T       TAC     .       PASS    -       GT       0/0  0/0

I tried using sed -e 's/:.:.:.:.:.:.:.:.//g' ani.vcf but everything after GT gets eliminated

chr1    67947   rs1202587463    A       AT      .       PASS    -       GT
chr1    69928   .       T       TAC     .       PASS    -       GT
vcf grep

usually I don't grep VCF if avoidable by using bcftools bcftools query my.vcf -f '[\t%GT]\n

2 answers

bcftools annotate -x '^FORMAT/GT' in.vcf

A small educational note: if an answer was helpful, you should upvote it; if the answer resolved your question, you should mark it as accepted. You can accept more than one answer if they work. This will help future users that might find this post find the right answer.

upvote_bookmark_accept

Instead of regular expressions I would recommend you to use one of the many tools that allow you to filter VCF files and format the output to your needs

for example, to remove INFO tags use

bcftools annotate -x INFO/VDB,INFO/FS,INFO/SGB 

oh Pierre Lindenbaum solution is even better,

I forgot the exact format to use it and tested it out, hence the later answer that was not even as good as the original

Log in to answer this question.