# Converting array\<array\<str\>\> expression to array\<str\>

**URL:** <https://discuss.hail.is/t/converting-array-array-str-expression-to-array-str/2300>\
**Category:** Hail Query & hailctl\
**Created:** [October 19, 2021, 12:15pm UTC](https://discuss.hail.is/t/converting-array-array-str-expression-to-array-str/2300 "2021-10-19T12:15:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeji29](https://avatars.discourse-cdn.com/v4/letter/j/b5ac83/32.png) [@jeji29](https://discuss.hail.is/u/jeji29)\
**Post date:** [October 19, 2021, 12:15pm UTC](https://discuss.hail.is/t/converting-array-array-str-expression-to-array-str/2300/1 "2021-10-19T12:15:47Z")

</div>

Hello, beginner in hail here!  
From the ‘transcript\_consequences’ row of vep row:

```auto
 transcript_consequences: array<struct {
            allele_num: int32, 
            amino_acids: str, 
            appris: str, 
            biotype: str, 
            cadd_phred: float64, 
            cadd_raw: float64, 
            canonical: int32, 
            ccds: str, 
            cdna_start: int32, 
            cdna_end: int32, 
            cds_end: int32, 
            cds_start: int32, 
            codons: str, 
            consequence_terms: array<str>, 
            distance: int32, 
            domains: array<struct {
                db: str, 
                name: str
            }>

```

I just wanted to see the consequence\_terms, so I annotated it to a new row:

```auto
d = d.annotate_rows(consequence_terms= d.vep.transcript_consequences['consequence_terms'])

```

Now all the value in my new ‘consequence\_terms’ row are an array\<array\> expression, such as [[‘missense\_variant’]].  
This is causing me a problem, because I want to know whether these samples have a ‘loss of function’ variant.

I have tried:

```auto
LoF_mutation = hl.array(['stop_gained', 'frameshift_variant', 'splice_region_variant', 'splice_acceptor_variant','splice_donor_variant', 'missense_variant'])
d = d.annotate_rows(is_LoF = hl.if_else(LoF_mutation.contains(d.consequent_terms), 'Y', 'N'))

```

But it shows the error  
`HailException: no conversion found for contains(, array<str>, array<array<str>>) => bool`.  
Is there any way to convert my array\<array\> values into a more simple expression, such as just array or a list?  
It also seems unnecessary, because all my consequent\_terms just have two brackets in a row around them.

Thanks in advance 🙂

---

<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:** [October 19, 2021, 1:58pm UTC](https://discuss.hail.is/t/converting-array-array-str-expression-to-array-str/2300/2 "2021-10-19T13:58:56Z")

</div>

Hey @jeji29 ,

I’m sorry to hear you’re having trouble with Hail! The direct answer to the question in your post title is `flatten`:

```auto
d.vep.transcript_consequences['consequence_terms']).flatten()

```

However, I think you actually need to use set intersection here. You have a list of loss of function consequences (`LoF_mutation`) and you have a list of all the consequences across all the transcripts of this variant (`d.vep.transcript_consequences['consequence_terms']`). If you want to know if there is _at least one_ loss of function consequence you can use this:

```python
all_consequences = d.vep.transcript_consequences['consequence_terms'].flatten()

d = d.annotate_rows(
    is_LoF = hl.len(LoF_mutation.intersect(hl.set(all_consequences))) != 0
)

```

I also want to point you at one more resource, the gnomAD Python library. It contains a function called [`process_consequences`](https://broadinstitute.github.io/gnomad_methods/api_reference/utils/vep.html#gnomad.utils.vep.process_consequences) which finds the most severe consequence for you:

```python
from gnomad.utils.vep import process_consequences
d = process_consequences(d)
d.vep.worst_consequence_term.describe()

```

```auto
--------------------------------------------------------
Type:
        str
--------------------------------------------------------
Source:
    <hail.table.MatrixTable object at 0x7fc41357c050>
Index:
    ['row']
--------------------------------------------------------

```

---

<div class="post-metadata">

**Author:** ![jeji29](https://avatars.discourse-cdn.com/v4/letter/j/b5ac83/32.png) [@jeji29](https://discuss.hail.is/u/jeji29)\
**Post date:** [October 20, 2021, 1:06pm UTC](https://discuss.hail.is/t/converting-array-array-str-expression-to-array-str/2300/3 "2021-10-20T13:06:10Z")

</div>

Thanks! The flatten() and intersection() functions solved my problem 🙂
