How to convert heterozygous variants to ./. in a VCF file?
1
0
Entering edit mode
2.1 years ago
LDT ▴ 340

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 • 1.1k views
ADD COMMENT
1
Entering edit mode

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?

ADD REPLY
0
Entering edit mode

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

ADD REPLY
1
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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

ADD REPLY
2
Entering edit mode

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

sed 's/0\/1/.\/./g' input.vcf > output.vcf
ADD REPLY
1
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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

ADD REPLY
3
Entering edit mode
2.1 years ago
bcftools +setGT  in.vcf -- -t q -i 'GT="het"' -n '.' 
ADD COMMENT

Login before adding your answer.

Traffic: 1465 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6