# I tried to select some nested fields but I received a LookupError

**URL:** <https://discuss.hail.is/t/i-tried-to-select-some-nested-fields-but-i-received-a-lookuperror/1487>\
**Category:** Hail Query & hailctl\
**Created:** [June 24, 2020, 2:19pm UTC](https://discuss.hail.is/t/i-tried-to-select-some-nested-fields-but-i-received-a-lookuperror/1487 "2020-06-24T14:19:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Haseeb1](https://avatars.discourse-cdn.com/v4/letter/h/df705f/32.png) [@Haseeb1](https://discuss.hail.is/u/Haseeb1)\
**Post date:** [June 24, 2020, 2:19pm UTC](https://discuss.hail.is/t/i-tried-to-select-some-nested-fields-but-i-received-a-lookuperror/1487/1 "2020-06-24T14:19:08Z")

</div>

> [@Export Specific Column From MT](https://discuss.hail.is/t/export-specific-column-from-mt/1479/2):
>
> ```python
> t.key_by().select('gene_symbol', 'AF').export('/path/to/file.tsv')
> 
> ```

I can access vep.transcript.gene but i want to use it as;

t.key\_by().select(‘vep.transcript.gene’, ‘info.AF’).export(‘/path/to/file.tsv’)

which gives me error

---

<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:** [June 24, 2020, 2:38pm UTC](https://discuss.hail.is/t/i-tried-to-select-some-nested-fields-but-i-received-a-lookuperror/1487/2 "2020-06-24T14:38:21Z")

</div>

`select('abc')` only works if `'abc'` is the literal name of a field. Instead you can do this:

```auto
t = t.key_by()
t.select(gene=t.vep.transcript.gene, AF=t.info.AF).export(...)

```

–  
EDIT: Fixed mistake discussed below.

---

<div class="post-metadata">

**Author:** ![Haseeb1](https://avatars.discourse-cdn.com/v4/letter/h/df705f/32.png) [@Haseeb1](https://discuss.hail.is/u/Haseeb1)\
**Post date:** [June 24, 2020, 3:36pm UTC](https://discuss.hail.is/t/i-tried-to-select-some-nested-fields-but-i-received-a-lookuperror/1487/3 "2020-06-24T15:36:52Z")

</div>

t\_lc.key\_by().select(gene=t\_lc.vep.transcript\_consequences[0].gene\_symbol, lof=t\_lc.vep.transcript\_consequences[0].lof,hets=t\_lc.hets, n\_hets=t\_lc.n\_het, homs=t\_lc.homs, n\_homs=t\_lc.n\_hom).export(‘gs://cncd\_analysts/outputs/APOC3\_lc.tsv’)

I have used folowing command but its giving me this error;

ExpressionException: Cannot combine expressions from different source objects.  
Found fields from 1 objects:  
\<hail.table.Table object at 0x7f70b53fbb38\>: [‘vep’]

---

<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:** [June 24, 2020, 3:40pm UTC](https://discuss.hail.is/t/i-tried-to-select-some-nested-fields-but-i-received-a-lookuperror/1487/4 "2020-06-24T15:40:27Z")

</div>

Sorry, I mis-wrote the above. When you run `key_by()` you create a new table and you are not allowed to reference fields from the old table. In particular `t_lc.vep` refers to a field of `t_lc` not a field of `t_lc.key_by()`. Try this:

```auto
t_lc = t_lc.key_by()
t_lc.select(
    gene=t_lc.vep.transcript_consequences[0].gene_symbol,
    lof=t_lc.vep.transcript_consequences[0].lof,
    hets=t_lc.hets,
    n_hets=t_lc.n_het,
    homs=t_lc.homs,
    n_homs=t_lc.n_hom
).export(‘gs://cncd_analysts/outputs/APOC3_lc.tsv’)

```
