# Aggregate GT over rows

**URL:** <https://discuss.hail.is/t/aggregate-gt-over-rows/3705>\
**Category:** Hail Query & hailctl\
**Created:** [January 4, 2024, 4:43pm UTC](https://discuss.hail.is/t/aggregate-gt-over-rows/3705 "2024-01-04T16:43:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![miye](https://avatars.discourse-cdn.com/v4/letter/m/90db22/32.png) [@miye](https://discuss.hail.is/u/miye)\
**Post date:** [January 4, 2024, 4:43pm UTC](https://discuss.hail.is/t/aggregate-gt-over-rows/3705/1 "2024-01-04T16:43:49Z")

</div>

Hi,

I am new to hail / genomics. I have a matrix table with locus and allele as row fields, s as a column field, and GT as an entry field. I want to find the counts of each genotype for each locus. So as example:

locus alleles s GT  
chr:pos [“T”,“C”] 1 0/1  
chr:pos [“T”,“C”] 2 0/0  
chr:pos2 [“A”,“G”] 1 0/1  
chr:pos2 [“A”,“G”] 2 1/1

Then I’d want to get

locus alleles count\_GT  
chr:pos [“T”,“C”] {0/0: 1, 0/1:1, 1/1:0}  
chr:pos2 [“A”, “G”]. {0/0:0, 0/1:1, 1/1:1}

Thank you 🙂

---

<div class="post-metadata">

**Author:** ![jsmadsen](https://avatars.discourse-cdn.com/v4/letter/j/46a35a/32.png) [@jsmadsen](https://discuss.hail.is/u/jsmadsen)\
**Post date:** [January 9, 2024, 11:40am UTC](https://discuss.hail.is/t/aggregate-gt-over-rows/3705/2 "2024-01-09T11:40:26Z")

</div>

Seems like [variant\_qc](https://hail.is/docs/0.2/methods/genetics.html#hail.methods.variant_qc) fits the bill, no?

---

<div class="post-metadata">

**Author:** ![miye](https://avatars.discourse-cdn.com/v4/letter/m/90db22/32.png) [@miye](https://discuss.hail.is/u/miye)\
**Post date:** [January 9, 2024, 5:37pm UTC](https://discuss.hail.is/t/aggregate-gt-over-rows/3705/3 "2024-01-09T17:37:25Z")

</div>

Yes, it seems like a very simple thing I missed:

result = hl.variant\_qc(mt)  
result.head(num\_variants, 1).entries().show()

I was able to do it in another roundabout way but could compare the correctness.

mt = mt.annotate\_entries(GT\_str = hl.str(mt.GT))  
row\_agg\_mt = mt.annotate\_rows(gt\_counter=hl.agg.counter(mt.GT\_str))  
row\_agg\_mt.rows().show()

Both results are giving me the same answer, so I think these are what I want, thank you @jsmadsen
