This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Convert missing genotype ./. to homozygous 0/0 in vcf

Dear all,

Is there a way to change missing genotype ./. to homozygous 0/0 in a vcf file? Fo example:

Input:

chr1    69849   .   G   A   100.59  PASS    AC=1;AF=0.500;AN=2;ClippingRankSum=0;DP=16;VQSLOD=1.66;culprit=NULL;set=variant-variant2    GT:AD:DP:GQ:PL  ./.:13,3:16:41:41,0,402

Output:

chr1    69849   .   G   A   100.59  PASS    AC=1;AF=0.500;AN=2;ClippingRankSum=0;DP=16;VQSLOD=1.66;culprit=NULL;set=variant-variant2    GT:AD:DP:GQ:PL  0/0:13,3:16:41:41,0,402
vcf

2 answers

bcftools plugin setGT : https://samtools.github.io/bcftools/howtos/plugins.html

Probably easier to use bcftools +missing2ref

Thanks a lot to both, missing2ref is deprecated as far as I understood

Your question inspired me to add the pyvcf.VcfFrame.miss2ref method in my fuc package. Here's an example usage of the method in Python API:

>>> from fuc import pyvcf
>>> data = {
...     'CHROM': ['chr1', 'chr2'],
...     'POS': [100, 101],
...     'ID': ['.', '.'],
...     'REF': ['G', 'T'],
...     'ALT': ['A', 'C'],
...     'QUAL': ['.', '.'],
...     'FILTER': ['.', '.'],
...     'INFO': ['.', '.'],
...     'FORMAT': ['GT', 'GT'],
...     'A': ['./.', '1/1'],
...     'B': ['./.', './.']
... }
>>> vf = pyvcf.VcfFrame.from_dict([], data)
>>> # vf = pyvcf.VcfFrame.from_file('input.vcf')
>>> vf.df
  CHROM  POS ID REF ALT QUAL FILTER INFO FORMAT    A    B
0  chr1  100  .   G   A    .      .    .     GT  ./.  ./.
1  chr2  101  .   T   C    .      .    .     GT  1/1  ./.
>>> new_vf = vf.miss2ref()
>>> new_vf.df
  CHROM  POS ID REF ALT QUAL FILTER INFO FORMAT    A    B
0  chr1  100  .   G   A    .      .    .     GT  0/0  0/0
1  chr2  101  .   T   C    .      .    .     GT  1/1  0/0
>>> # new_vf.to_file('output.vcf')

Log in to answer this question.