This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to convert heterozygous variants to ./. in a VCF file?

Dear all,

I have a large VCF file from which I want to convert the heterozygous alleles to ./..

Do you have any idea how I can do that?

heterozygosity vcf bcftools

Hi! What are you trying to achieve? What do you mean by "converting heterozygous alleles to NA"? Could you simply discard them from your VCF? Could you describe your desired output?

I want to mask heterozygous sites and work only with the homozygotes. Thank you for the comment :)

I think if you just need to work with homozygous variant calls, you could simply generate a new VCF with the homozygous calls:

grep '^#' input.vcf > homozygous_variants.vcf
grep '1/1' input.vcf >> homozygous_variants.vcf

N.B: These commands only work for a single alternative allele at the variant position.

thats very handy, thank you so so much, but I really want to convert heterozygotes to ./. and keep them in the file. Maybe I could try a grep command? Also thank you so much for your time, means a lot learning from others

Sure, no worries, happy to help. So, an easy way could be with sed:

sed 's/0\/1/.\/./g' input.vcf > output.vcf

I have a large VCF file from which I want to convert the heterozygous alleles to NA.

NA ? that doesnt fit in the VCF specification. Could be ./. but not NA.

Yes you are right to ./. I wanted to write. I am changing the question asap

1 answer

bcftools +setGT  in.vcf -- -t q -i 'GT="het"' -n '.' 

Log in to answer this question.