# Added ability to compute HWE on subsets of samples

**URL:** https://discuss.hail.is/t/added-ability-to-compute-hwe-on-subsets-of-samples/76
**Category:** Updates
**Created:** [November 7, 2016, 6:57pm UTC](https://discuss.hail.is/t/added-ability-to-compute-hwe-on-subsets-of-samples/76 "2016-11-07T18:57:04Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![jigold](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/jigold/32/143_2.png) [@jigold](https://discuss.hail.is/u/jigold)
#### Post date: [November 7, 2016, 6:57pm UTC](https://discuss.hail.is/t/added-ability-to-compute-hwe-on-subsets-of-samples/76/1 "2016-11-07T18:57:04Z")

</div>

Hardy Weinberg Equilibrium (HWE) p-values are computed automatically when using the `variantqc` command. However, the `variantqc` command computes p-values from the genotypes of all samples present in the dataset.

We have added a HWE aggregator **`hardyWeinberg()`** to the Hail Expression Language that allows you to compute HWE p-values on a subset of samples. For example, to compute the HWE p-value in cases and controls separately, we can use the following command:

```nohighlight
vds.annotate_variants_expr('va.hweCase = gs.filter(g => sa.pheno == "Case").hardyWeinberg(), va.hweControl = gs.filter(g => sa.pheno == "Control").hardyWeinberg()')

```

The output schema will have the following format:

```nohighlight
va: Struct {
    hweCase: Struct {
        rExpectedHetFrequency: Double,
        pHWE: Double
    },
    hweControl: Struct {
        rExpectedHetFrequency: Double,
        pHWE: Double
    }
}

```

For more information, see the [documentation](https://hail.is/hail/functions.html) of `pHWE` on the Hail website.
