# Hail 0.2 export gwas results to tsv

**URL:** <https://discuss.hail.is/t/hail-0-2-export-gwas-results-to-tsv/696>\
**Category:** Help \[0.1\]\
**Created:** [October 16, 2018, 4:06pm UTC](https://discuss.hail.is/t/hail-0-2-export-gwas-results-to-tsv/696 "2018-10-16T16:06:56Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![hhx037](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/hhx037/32/160_2.png) [@hhx037](https://discuss.hail.is/u/hhx037)\
**Post date:** [October 16, 2018, 4:06pm UTC](https://discuss.hail.is/t/hail-0-2-export-gwas-results-to-tsv/696/1 "2018-10-16T16:06:56Z")

</div>

I’m trying to export the gwas results to a tsv, via a table, but I’m not able to shake the structure format. This is how I do it:

```
results = gwas.rows()
results.export('file:////root/logreg_wald.tsv.bgz')

```

This works, but the resulting file requires a lot of parsing:

> locus alleles rsid cm\_position logreg  
> 1:768448 [“G”,“A”] rs12562034 0.0000e+00 {“beta”:0.24564585404573575,“standard\_error”:0.09766742410866683,“z\_stat”:2.515125757513836,“p\_value”:0.011898993159370147,“fit”:{“n\_iterations”:4,“converged”:true,“exploded”:false}}

The explode() method does not apply here (and does not apply to structures). Is there a quick way to save the results as different columns? (logreg.beta etc would be just fine)

---

<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:** [October 16, 2018, 5:15pm UTC](https://discuss.hail.is/t/hail-0-2-export-gwas-results-to-tsv/696/2 "2018-10-16T17:15:09Z")

</div>

Table.flatten is what you’re looking for here!

---

<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:** [October 16, 2018, 5:15pm UTC](https://discuss.hail.is/t/hail-0-2-export-gwas-results-to-tsv/696/3 "2018-10-16T17:15:36Z")

</div>

you can also do something like

```auto
results = results.select(**results.logreg)

```

in between the two lines you have there

---

<div class="post-metadata">

**Author:** ![hhx037](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/hhx037/32/160_2.png) [@hhx037](https://discuss.hail.is/u/hhx037)\
**Post date:** [October 16, 2018, 7:28pm UTC](https://discuss.hail.is/t/hail-0-2-export-gwas-results-to-tsv/696/4 "2018-10-16T19:28:17Z")

</div>

That makes perfect sense, thank you. I was looking for a flatten option in rows and export, but didn’t think to look if a table.flatten existed.

---

<div class="post-metadata">

**Author:** ![hhx037](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/hhx037/32/160_2.png) [@hhx037](https://discuss.hail.is/u/hhx037)\
**Post date:** [October 16, 2018, 7:30pm UTC](https://discuss.hail.is/t/hail-0-2-export-gwas-results-to-tsv/696/5 "2018-10-16T19:30:27Z")

</div>

One more thing though, I don’t understand the two stars in results.select(\*\*results.logreg), what do they stand for? I saw this for ds.annotate() also.

---

<div class="post-metadata">

**Author:** ![jbloom](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/jbloom/32/109_2.png) [@jbloom](https://discuss.hail.is/u/jbloom)\
**Post date:** [October 16, 2018, 7:34pm UTC](https://discuss.hail.is/t/hail-0-2-export-gwas-results-to-tsv/696/6 "2018-10-16T19:34:12Z")

</div>

It’s unpacking the struct `results.logreg` into a top-level list of keyword pairs (field name and expression):  
[http://treyhunner.com/2018/10/asterisks-in-python-what-they-are-and-how-to-use-them/](http://treyhunner.com/2018/10/asterisks-in-python-what-they-are-and-how-to-use-them/)

---

<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:** [October 16, 2018, 7:59pm UTC](https://discuss.hail.is/t/hail-0-2-export-gwas-results-to-tsv/696/7 "2018-10-16T19:59:17Z")

</div>

it’s usually a good idea to avoid the \*\* in `annotate` unless you’re sure you want to be doing that, as it can do things like overwrite existing fields. Generally `annotate_cols(phenos = pheno_table[mt.s])` is safer than `annotate_cols(**pheno_table[mt.s])`, but will require you to access fields with `mt.phenos.pheno1` rather than `me.pheno1`

---

<div class="post-metadata">

**Author:** ![hhx037](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/hhx037/32/160_2.png) [@hhx037](https://discuss.hail.is/u/hhx037)\
**Post date:** [October 18, 2018, 9:43am UTC](https://discuss.hail.is/t/hail-0-2-export-gwas-results-to-tsv/696/8 "2018-10-18T09:43:37Z")

</div>

Great, thank you both, very helpful 🙂
