# How many reference genotypes is common for two samples?

**URL:** <https://discuss.hail.is/t/how-many-reference-genotypes-is-common-for-two-samples/1226>\
**Category:** Hail Query & hailctl\
**Created:** [December 21, 2019, 11:58am UTC](https://discuss.hail.is/t/how-many-reference-genotypes-is-common-for-two-samples/1226 "2019-12-21T11:58:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rost](https://avatars.discourse-cdn.com/v4/letter/r/6de8d8/32.png) [@Rost](https://discuss.hail.is/u/Rost)\
**Post date:** [December 21, 2019, 11:58am UTC](https://discuss.hail.is/t/how-many-reference-genotypes-is-common-for-two-samples/1226/1 "2019-12-21T11:58:32Z")

</div>

I got 2-sample matrix.

> samples = hl.literal(set([‘sample1’, ‘sample2’]))  
> mt\_test = mt.filter\_cols(samples.contains(mt.s), keep = True)

Now, I want to take all reference genotypes to calculate how similar are they. Finally, I hope to get one number (for example ratio of common reference genotypes to all). This is will do to check my PI\_HAT metrics. But I got some problems in next …

> mt\_test.aggregate\_rows(hl.agg.count\_where(mt\_test.GT == hl.literal(set([‘0/0’, ‘0/0’]))))  
> TypeError: Invalid ‘==’ comparison, cannot compare expressions of type ‘call’ and ‘set’

What am I wrong about?

---

<div class="post-metadata">

**Author:** ![danking](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/danking/32/43_2.png) [@danking](https://discuss.hail.is/u/danking)\
**Post date:** [December 23, 2019, 1:48pm UTC](https://discuss.hail.is/t/how-many-reference-genotypes-is-common-for-two-samples/1226/2 "2019-12-23T13:48:18Z")

</div>

[`aggregate_rows`](https://hail.is/docs/0.2/hail.MatrixTable.html?highlight=aggregate_rows#hail.MatrixTable.aggregate_rows) aggregates over the _row_ fields to produce a python value. `GT` is an _entry_ field, so you cannot use it here.

You’re thinking about the entire array of entries as if they were a _row_ field, which is actually reasonable! [`localize_entries`](https://hail.is/docs/0.2/hail.MatrixTable.html?highlight=aggregate_rows#hail.MatrixTable.localize_entries) is a method that converts a matrix table to a table with an array of entries.

Anyway, because the matrix table has exactly two samples, you could just use `hl.agg.all`:

```auto
mt = mt.annotate_rows(
    everyone_is_hom_ref = hl.agg.all(mt.GT.is_hom_ref()))
n_sites_where_everyone_is_hom_ref = mt.aggregate_rows(
    hl.agg.count_where(mt.everyone_is_hom_ref))

```

You have to do it in two steps because this really is a two step process: first collapse the entry fields into row field, then collapse the row fields into a single value.

---

<div class="post-metadata">

**Author:** ![Rost](https://avatars.discourse-cdn.com/v4/letter/r/6de8d8/32.png) [@Rost](https://discuss.hail.is/u/Rost)\
**Post date:** [December 23, 2019, 4:11pm UTC](https://discuss.hail.is/t/how-many-reference-genotypes-is-common-for-two-samples/1226/3 "2019-12-23T16:11:35Z")

</div>

Thank you! Now it works! I hope that a training course will appear soon to save you from such questions. 🙂
