# MAC for sites with more than 1 ALT allele

**URL:** <https://discuss.hail.is/t/mac-for-sites-with-more-than-1-alt-allele/2814>\
**Category:** Hail Query & hailctl\
**Created:** [September 1, 2022, 7:54am UTC](https://discuss.hail.is/t/mac-for-sites-with-more-than-1-alt-allele/2814 "2022-09-01T07:54:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DBScan](https://avatars.discourse-cdn.com/v4/letter/d/bc79bd/32.png) [@DBScan](https://discuss.hail.is/u/DBScan)\
**Post date:** [September 1, 2022, 7:54am UTC](https://discuss.hail.is/t/mac-for-sites-with-more-than-1-alt-allele/2814/1 "2022-09-01T07:54:41Z")

</div>

Hi, I started to look into HAIL this week and I am really amazed how fast it is.  
I want to calculate the MAC for all of my sites (\> 100 million), but I am struggling with this.  
I have an INFO/AC entry with is an array with as many entries as there are ALT alleles.  
I tried to get the max value like this, but no success:

```python
mt = mt.annotate_rows(MAC = hl.agg.max(mt.info.AC))

```

---

<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 1, 2022, 11:11pm UTC](https://discuss.hail.is/t/mac-for-sites-with-more-than-1-alt-allele/2814/2 "2022-09-01T23:11:05Z")

</div>

What failed about this? I’d expect this to work fine.

Separately, what is the definition of “MAC” at a multiallelic site? Is it the allele count of the alt allele with the most observations? the fewest? The sum of all alts?

---

<div class="post-metadata">

**Author:** ![DBScan](https://avatars.discourse-cdn.com/v4/letter/d/bc79bd/32.png) [@DBScan](https://discuss.hail.is/u/DBScan)\
**Post date:** [September 2, 2022, 6:14am UTC](https://discuss.hail.is/t/mac-for-sites-with-more-than-1-alt-allele/2814/3 "2022-09-02T06:14:53Z")

</div>

The error code I get is the following:

```python
TypeError: max: parameter 'expr': expected expression of type int32 or int64 or float32 or float64, found <ArrayNumericExpression of type array<int32>>

```

Somehow the function doesn’t expect an array.

My understanding of MAC at multiallelic sites is that it is defined as the count of the alt allele withe the most observations (similar to bcftools ([bcftools +fill-tags calculates unexpected MAF for multiallelic variants · Issue #1313 · samtools/bcftools · GitHub](https://github.com/samtools/bcftools/issues/1313)).

---

<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 2, 2022, 12:35pm UTC](https://discuss.hail.is/t/mac-for-sites-with-more-than-1-alt-allele/2814/4 "2022-09-02T12:35:16Z")

</div>

> [@DBScan](#):
>
> Somehow the function doesn’t expect an array.

Ahhh… This is the wrong `max` function.

There are two max functions in Hail – `hl.max` and `hl.agg.max`. `hl.max` takes the maximum value of an array, while `hl.agg.max` is an aggregator that takes the max value along some aggregated axis. If you wanted to take the max value of some entry field (like `GQ`) per row, using `hl.agg.max` is correct, but here we want `hl.max`.

---

<div class="post-metadata">

**Author:** ![DBScan](https://avatars.discourse-cdn.com/v4/letter/d/bc79bd/32.png) [@DBScan](https://discuss.hail.is/u/DBScan)\
**Post date:** [September 2, 2022, 12:44pm UTC](https://discuss.hail.is/t/mac-for-sites-with-more-than-1-alt-allele/2814/5 "2022-09-02T12:44:39Z")

</div>

Indeed, it’s working now, thanks!
