# Hail 0.2 - Questions on MatrixTable joins for columns

**URL:** <https://discuss.hail.is/t/hail-0-2-questions-on-matrixtable-joins-for-columns/466>\
**Category:** Hail Query & hailctl\
**Created:** [April 14, 2018, 11:40pm UTC](https://discuss.hail.is/t/hail-0-2-questions-on-matrixtable-joins-for-columns/466 "2018-04-14T23:40:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bjo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/bjo/32/149_2.png) [@bjo](https://discuss.hail.is/u/bjo)\
**Post date:** [April 14, 2018, 11:40pm UTC](https://discuss.hail.is/t/hail-0-2-questions-on-matrixtable-joins-for-columns/466/1 "2018-04-14T23:40:48Z")

</div>

Hi,

I have a couple of questions about annotating my MatrixTable.

I have an imported vcf (ds), and I want to annotate it based on a file that has samples as columns:

ID SAMP-A SAMP-B SAMP-C SAMP-D …  
PC1 0.0154 0.0139 0.0145 -0.0728 …  
PC2 -0.0093 -0.0097 -0.0093 -0.0077 …  
PC3 0.0107 0.0067 0.0327 -0.0044 …  
PC4 -0.0038 -0.0144 0.0056 -0.0146 …  
PC5 -0.0083 0.0296 0.0510 0.0063 …

using the command:

covs\_kt = hl.import\_matrix\_table(anno\_path, entry\_type=hl.tfloat64, row\_fields={‘ID’: hl.tstr}, row\_key = ‘ID’)

Now, SAMP-A, SAMP-B, are entries of ds.s and covs\_kt.col\_id

I have a couple of questions at this stage:  
In hail 0.1, I had to export covs\_kt to pandas, transpose it, re-convert to a KeyTable, and then run annotate\_samples\_table(covs\_kt, root=‘sa.covs’)

1. I now understand join based on index are possible for rows, but it seems like they’re not possible for columns - so covs\_kt[ds.s] will not work unless I transpose covs\_kt - am I correct?
2. What would be a good way to run annotate\_cols with this MatrixTable? Eventually I want to be able to annotate the columns with all ~20,000 expression values - how can I do this based on all rows (or columns) of covs\_kt? (This bit wasn’t clear from the documentation on annotate\_cols() function)

Thank you for your help!

---

<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:** [April 15, 2018, 3:25pm UTC](https://discuss.hail.is/t/hail-0-2-questions-on-matrixtable-joins-for-columns/466/2 "2018-04-15T15:25:02Z")

</div>

For 1, yes, you’ll need to transpose TSV to read it in as a `Table` whose rows are keyed by `ID`. Given that your table isn’t all that big, even with 20K fields, I’d recommend just saving a transposed copy. You might also want to rename `covs_kt` since `KeyTable` is gone. Internally we’ve settled on `ht` for Hail Table and `mt` for MatrixTable.

Were your table huge, you could read it in as a `MatrixTable`, create a [BlockMatrix](https://hail.is/docs/devel/linalg/hail.linalg.BlockMatrix.html) using `BlockMatrix.from_entry_expr`, transpose the BlockMatrix, and convert that back to a `Table` or `MatrixTable` (coming soon!), which could be used directly and/or exported row-wise.

For 2, see the `**` trick for adding all fields in [Adding column fields](https://hail.is/docs/devel/tutorials/01-genome-wide-association-study.html#Adding-column-fields) section of the Overview Tutorial.

---

<div class="post-metadata">

**Author:** ![bjo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/bjo/32/149_2.png) [@bjo](https://discuss.hail.is/u/bjo)\
**Post date:** [April 15, 2018, 5:34pm UTC](https://discuss.hail.is/t/hail-0-2-questions-on-matrixtable-joins-for-columns/466/3 "2018-04-15T17:34:29Z")

</div>

Thank you, that is helpful!
