# Count all gene strings in an array field with a counter aggregator for a whole table

**URL:** <https://discuss.hail.is/t/count-all-gene-strings-in-an-array-field-with-a-counter-aggregator-for-a-whole-table/2345>\
**Category:** Hail Query & hailctl\
**Created:** [November 12, 2021, 1:01pm UTC](https://discuss.hail.is/t/count-all-gene-strings-in-an-array-field-with-a-counter-aggregator-for-a-whole-table/2345 "2021-11-12T13:01:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rjwswenson](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/rjwswenson/32/545_2.png) [@rjwswenson](https://discuss.hail.is/u/rjwswenson)\
**Post date:** [November 12, 2021, 1:01pm UTC](https://discuss.hail.is/t/count-all-gene-strings-in-an-array-field-with-a-counter-aggregator-for-a-whole-table/2345/1 "2021-11-12T13:01:27Z")

</div>

Hi,

I have an ANN entry field within info, that I want to display a count of the specific gene symbol or name, using the aggregator.

my code is as follows where anngen is the MT:

`anngen.aggregate_entries(hl.agg.explode(lambda element: hl.agg.counter(element), anngen.info.ANN))`

this returns:

`2021-11-12 12:53:32 Hail: INFO: Coerced prefix-sorted dataset`

**frozendict({’|3\_prime\_UTR\_variant|MODIFIER|LACE1|ENSG00000135537|transcript|ENST00000368977|protein\_coding|13/13|c.|||||1556|INFO\_REALIGN\_3\_PRIME’: 2504, ‘|3\_prime\_UTR\_variant|MODIFIER|MIER1|ENSG00000198160|transcript|ENST00000355356|protein\_coding|13/13|c.|||||904|INFO\_REALIGN\_3\_PRIME’: 2504,**

I believe the gene names are in the 4th position, array element 3. The above was great for exploding and aggregating counts of the entire ANN , but I am specifically wanting to enumerate the gene name list.

---

<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:** [November 12, 2021, 8:25pm UTC](https://discuss.hail.is/t/count-all-gene-strings-in-an-array-field-with-a-counter-aggregator-for-a-whole-table/2345/2 "2021-11-12T20:25:01Z")

</div>

I think you can do:

```auto
anngen.aggregate_entries(
  hl.agg.explode(lambda element: hl.agg.counter(element), 
                 anngen.info.ANN.split('|')[3]))

```

---

<div class="post-metadata">

**Author:** ![rjwswenson](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/rjwswenson/32/545_2.png) [@rjwswenson](https://discuss.hail.is/u/rjwswenson)\
**Post date:** [November 13, 2021, 3:06pm UTC](https://discuss.hail.is/t/count-all-gene-strings-in-an-array-field-with-a-counter-aggregator-for-a-whole-table/2345/3 "2021-11-13T15:06:20Z")

</div>

Hmm,

I got this, in response:

AttributeError: ‘ArrayExpression’ object has no attribute ‘split’

I am reviewing the ArrayExpression type now.

I am able to split with:

`smallgen.info.ANN[0].split('|')[3].show(4)`

but this oddly causes the entire ANN string array to be further rendered as comma separated individual characters as the return.

locus  
alleles  
locus array str  
chr1:16103 [“T”,“G”] “o”  
chr1:51479 [“T”,“A”] “n”  
chr1:51898 [“C”,“A”] “n”  
chr1:51928 [“G”,“A”] “n”  
chr1:51954 [“G”,“C”] “n”  
chr1:54490 [“G”,“A”] “n”  
chr1:54669 [“C”,“T”] “n”  
chr1:54708 [“G”,“C”] “n”  
chr1:54716 [“C”,“T”] “n”  
chr1:54725 [“T”,“G”] “n”
