This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Edit vcf file 0|0 to 0

I have a vcf file with GT format as 0|0 0|1 1|1 etc. I would like to convert those to a single number to create a dosage file. Ex: Editing the vcf so that 0|0 become 0, 0|1 becomes 1 1|1 becomes 2 etc. I've tried using sed and gsub but can't seem to figure it out. Any advice would be greatly appreciated

linux vcf genomics edit

1 answer

bcftools annotate -x 'QUAL,INFO,^FORMAT/GT' in.vcf | sed 's/0[\/\|]0/0/g;s/0[\/\|]1/1/g;s/1[\/\|]1/2/g'

It worked, thanks so much!

Log in to answer this question.