# Check if specific fields exists in matrix table in python script

**URL:** <https://discuss.hail.is/t/check-if-specific-fields-exists-in-matrix-table-in-python-script/1866>\
**Category:** Hail Query & hailctl\
**Created:** [December 23, 2020, 3:28pm UTC](https://discuss.hail.is/t/check-if-specific-fields-exists-in-matrix-table-in-python-script/1866 "2020-12-23T15:28:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![samn](https://avatars.discourse-cdn.com/v4/letter/s/90ced4/32.png) [@samn](https://discuss.hail.is/u/samn)\
**Post date:** [December 23, 2020, 3:28pm UTC](https://discuss.hail.is/t/check-if-specific-fields-exists-in-matrix-table-in-python-script/1866/1 "2020-12-23T15:28:47Z")

</div>

I am trying to run the below on a small Exome matrix table

> ```
> def filter_matrix_table(self):
> logging.info(f"Filtering matrix table")
> mt = hl.read_matrix_table(self.input_matrix_table)
> # memoize the loci we care about
> mt = mt.annotate_globals(fp_loci=self.get_loci_from_sites_path())
> # filter and grab what we need
> mt = mt.filter_rows(mt.fp_loci.contains(mt.locus))
> mt = mt.drop('info', 'fp_loci')
> return mt.select_entries('GT', 'PL')
> 
> ```

I am getting back

> ```
> Traceback (most recent call last):
> File "/tmp/1d77d8061d704092bf4a465ab1d44975/extract_fingerprint_sites.py", line 63, in <module>
> output_path=args.output_path
> File "/tmp/1d77d8061d704092bf4a465ab1d44975/extract_fingerprint_sites.py", line 44, in run
> mt = self.filter_matrix_table()
> File "/tmp/1d77d8061d704092bf4a465ab1d44975/extract_fingerprint_sites.py", line 36, in filter_matrix_table
> mt = mt.drop('info', 'fp_loci')
> File "<decorator-gen-1185>", line 2, in drop
> File "/opt/conda/default/lib/python3.6/site-packages/hail/typecheck/check.py", line 614, in wrapper
> return __original_func(*args_, **kwargs_)
> File "/opt/conda/default/lib/python3.6/site-packages/hail/matrixtable.py", line 1315, in drop
> raise IndexError("MatrixTable has no field '{}'".format(e))
> IndexError: MatrixTable has no field 'info'
> 
> ```

I think I should be able to run describe or summarize to see if ‘info’ or other fields needs to be removed (should I expect it to be there?), but I am having some trouble finding how I can run that in a python script and grab fields as a list.

_edit_  
Just for clarity, I have already confirmed there is no info field in this specific matrix table using describe and seeing the output, but I would like a way for the script to check on its own without manual intervention.

---

<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 23, 2020, 7:16pm UTC](https://discuss.hail.is/t/check-if-specific-fields-exists-in-matrix-table-in-python-script/1866/2 "2020-12-23T19:16:28Z")

</div>

You can get the fields of a MatrixTable component with:

```auto
list(mt.row)
list(mt.entry)
list(mt.col)

```

Or check for membership with:

```auto
field in mt.row

```

etc.

---

<div class="post-metadata">

**Author:** ![samn](https://avatars.discourse-cdn.com/v4/letter/s/90ced4/32.png) [@samn](https://discuss.hail.is/u/samn)\
**Post date:** [December 23, 2020, 8:57pm UTC](https://discuss.hail.is/t/check-if-specific-fields-exists-in-matrix-table-in-python-script/1866/3 "2020-12-23T20:57:51Z")

</div>

Thank you, that worked! Have a great break.

---

<div class="post-metadata">

**Author:** ![ruchim](https://avatars.discourse-cdn.com/v4/letter/r/a3d4f5/32.png) [@ruchim](https://discuss.hail.is/u/ruchim)\
**Post date:** [January 5, 2021, 2:08pm UTC](https://discuss.hail.is/t/check-if-specific-fields-exists-in-matrix-table-in-python-script/1866/4 "2021-01-05T14:08:41Z")

</div>

thanks!
