# ABHet ratio for variant level QC

**URL:** <https://discuss.hail.is/t/abhet-ratio-for-variant-level-qc/2258>\
**Category:** Feature Requests\
**Created:** [September 21, 2021, 1:53pm UTC](https://discuss.hail.is/t/abhet-ratio-for-variant-level-qc/2258 "2021-09-21T13:53:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jjfarrell](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/jjfarrell/32/108_2.png) [@jjfarrell](https://discuss.hail.is/u/jjfarrell)\
**Post date:** [September 21, 2021, 1:53pm UTC](https://discuss.hail.is/t/abhet-ratio-for-variant-level-qc/2258/1 "2021-09-21T13:53:25Z")

</div>

A very useful metric for variant QC is the ABHet ratio. Variants with ABHet \< 0.2 and \> 0.8 are used to filter out false positives. More conservative cutoffs (0.25 and 0.75) are also used.

ABHet is a variant-level annotation that aims to estimate if biallelic variants match expected allelic ratios. An ideal heterozygous variant will have a value of close to 0.5 and an ideal homozygous variant will have a value of close to 1.0. ABHet is calculated for a variant based on all samples in the VCF which are not homozygous at this site.

ABHet=# REF reads from heterozygous samples/# REF + ALT reads from heterozygous samples

What would be the best approach for calculating this with Hail? Could this be added to the variantQC method?

---

<div class="post-metadata">

**Author:** ![kumarveerapen](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/kumarveerapen/32/355_2.png) [@kumarveerapen](https://discuss.hail.is/u/kumarveerapen)\
**Post date:** [September 21, 2021, 4:13pm UTC](https://discuss.hail.is/t/abhet-ratio-for-variant-level-qc/2258/2 "2021-09-21T16:13:21Z")

</div>

Thank you for your question, @jjfarrell ! II do also use allele balances as a QC metric for my datasets.

I do have a snippet that I use when analysing sequencing data which can be found [here](https://github.com/covid19-hg/covid19_sequencing/blob/master/Hail_COVID19weswgs.ipynb).

```auto
#create an allele balance annotation
mt= mt.annotate_entries(AB = (mt.AD[1] / hl.sum(mt.AD) ))

#set filter condition for AB. So if you want to be less or more stringent you can pick your balances accordingly. I've included both hom-ref and hom-alt in my filtering step here
filter_condition_ab = ((mt.GT.is_hom_ref() & (mt.AB <= 0.1)) |
                        (mt.GT.is_het() & (mt.AB >= 0.25) & (mt.AB <= 0.75)) |
                        (mt.GT.is_hom_var() & (mt.AB >= 0.9)))
fraction_filtered = mt.aggregate_entries(hl.agg.fraction(~filter_condition_ab))
print(f'Filtering {fraction_filtered * 100:.2f}% entries out of downstream analysis.')

mt = mt.filter_entries( (mt.GQ>=20) &
                 (mt.GQ >= 10) &
                 ((mt.GT.is_hom_ref() & (mt.AB <= 0.1)) |
                        (mt.GT.is_het() & (mt.AB >= 0.25) & (mt.AB <= 0.75)) |
                        (mt.GT.is_hom_var() & (mt.AB >= 0.9))))

```

I hope that this is helpful 🙂

---

<div class="post-metadata">

**Author:** ![kumarveerapen](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/kumarveerapen/32/355_2.png) [@kumarveerapen](https://discuss.hail.is/u/kumarveerapen)\
**Post date:** [September 21, 2021, 4:21pm UTC](https://discuss.hail.is/t/abhet-ratio-for-variant-level-qc/2258/3 "2021-09-21T16:21:28Z")

</div>

And to note, our developers have been flagged to see if we can include this into a future iteration of Hail.

---

<div class="post-metadata">

**Author:** ![tpoterba](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/tpoterba/32/61_2.png) [@tpoterba](https://discuss.hail.is/u/tpoterba)\
**Post date:** [September 21, 2021, 6:43pm UTC](https://discuss.hail.is/t/abhet-ratio-for-variant-level-qc/2258/4 "2021-09-21T18:43:21Z")

</div>

> [@jjfarrell](#):
>
> ABHet=# REF reads from heterozygous samples# REF + ALT reads from heterozygous samples

@kumarveerapen I think the solution we want here is a variant-level metric which is the sum of ref reads in het samples divided by the sum of alt reads in het samples.

We probably want this to compute a ratio per alternate allele, actually.

---

<div class="post-metadata">

**Author:** ![jjfarrell](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/jjfarrell/32/108_2.png) [@jjfarrell](https://discuss.hail.is/u/jjfarrell)\
**Post date:** [September 22, 2021, 3:35pm UTC](https://discuss.hail.is/t/abhet-ratio-for-variant-level-qc/2258/5 "2021-09-22T15:35:21Z")

</div>

@tpoterba @kumarveerapen

yes, we typically use this at the variant level rather than the GT level as Tim suggests. Two variant level metrics could be defined: An AS\_ABHet (Allele Specific ABHet) and an ABHet (defined as ratio of all #Alt\_reads to #homozygous reference reads). We run variantQC after splitting the multiallelic so either would work.
