Aggregate GT over rows


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 :slight_smile:

1 Like

Seems like variant_qc fits the bill, no?

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))

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