Convert missing genotype ./. to homozygous 0/0 in vcf
2
0
Entering edit mode
3 months ago
User000 ▴ 490

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

Probably easier to use bcftools +missing2ref

ADD REPLY
0
Entering edit mode

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

ADD REPLY
1
Entering edit mode
3 months ago
sbstevenlee ▴ 230

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')
ADD COMMENT

Login before adding your answer.

Traffic: 2934 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