If I understood your question correctly, you want to select only those variants where a specific sample has ALT AD of 3 or higher. If that's the case, here's a Python solution using the pyvcf submodule I wrote:

>>> from fuc import pyvcf
>>> data = {
...     'CHROM': ['chr1', 'chr1', 'chr1'],
...     'POS': [100, 101, 102],
...     'ID': ['.', '.', '.'],
...     'REF': ['G', 'T', 'A'],
...     'ALT': ['A', 'C', 'C'],
...     'QUAL': ['.', '.', '.'],
...     'FILTER': ['.', '.', '.'],
...     'INFO': ['.', '.', '.'],
...     'FORMAT': ['GT:AD', 'GT:AD', 'GT:AD'],
...     'A': ['0/1:15,8', '1/1:0,17', '0/0:15,0'],
...     'B': ['0/1:12,2', '0/1:23,3', '0/1:10,9']
... }
>>> 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:AD  0/1:15,8  0/1:12,2
1  chr1  101  .   T   C    .      .    .  GT:AD  1/1:0,17  0/1:23,3
2  chr1  102  .   A   C    .      .    .  GT:AD  0/0:15,0  0/1:10,9
>>> i = vf.extract('AD', func=lambda x: float(x.split(',')[1]))['B'] >= 3
>>> vf.df = vf.df[i]
>>> vf.df
  CHROM  POS ID REF ALT QUAL FILTER INFO FORMAT         A         B
0  chr1  101  .   T   C    .      .    .  GT:AD  1/1:0,17  0/1:23,3
1  chr1  102  .   A   C    .      .    .  GT:AD  0/0:15,0  0/1:10,9
>>> # vf.to_file('output.vcf')



Source link