# Counting the number of heterzygous SNPs per chromosome

**URL:** <https://discuss.hail.is/t/counting-the-number-of-heterzygous-snps-per-chromosome/2387>\
**Category:** Hail Query & hailctl\
**Created:** [December 1, 2021, 10:01pm UTC](https://discuss.hail.is/t/counting-the-number-of-heterzygous-snps-per-chromosome/2387 "2021-12-01T22:01:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![CuriousGeneticist](https://avatars.discourse-cdn.com/v4/letter/c/6f9a4e/32.png) [@CuriousGeneticist](https://discuss.hail.is/u/CuriousGeneticist)\
**Post date:** [December 1, 2021, 10:01pm UTC](https://discuss.hail.is/t/counting-the-number-of-heterzygous-snps-per-chromosome/2387/1 "2021-12-01T22:01:08Z")

</div>

Hello! I know that I can filter all the SNPs with heterozygous SNPs and count it with this:  
_mt\_het = mt.filter\_rows(hl.agg.all(mt.GT.is\_het()))_  
_mt\_het.rows().count()_  
However, instead of making a new mt for every single chromosome, is there a faster method to just count the number of heterozygous SNPs in each chromosome and then store it in a variable? Thank you very much!

---

<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:** [December 1, 2021, 10:07pm UTC](https://discuss.hail.is/t/counting-the-number-of-heterzygous-snps-per-chromosome/2387/2 "2021-12-01T22:07:09Z")

</div>

You could do:

```auto
mt_het = mt.filter_rows(hl.agg.all(mt.GT.is_het()))
counts_per_chrom = mt_het.aggregate_rows(hl.agg.group_by(mt_het.locus.contig, hl.agg.count()))

```
