# Correct method to annotate\_rows of matrix table with a table of VQSR scores

**URL:** <https://discuss.hail.is/t/correct-method-to-annotate-rows-of-matrix-table-with-a-table-of-vqsr-scores/962>\
**Category:** Hail Query & hailctl\
**Created:** [May 22, 2019, 7:29pm UTC](https://discuss.hail.is/t/correct-method-to-annotate-rows-of-matrix-table-with-a-table-of-vqsr-scores/962 "2019-05-22T19:29:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vivek](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/vivek/32/249_2.png) [@Vivek](https://discuss.hail.is/u/Vivek)\
**Post date:** [May 22, 2019, 7:29pm UTC](https://discuss.hail.is/t/correct-method-to-annotate-rows-of-matrix-table-with-a-table-of-vqsr-scores/962/1 "2019-05-22T19:29:35Z")

</div>

I have a matrix table of variants (behaving fine) and I have imported a table of VQSR scores. I cannot get around what must be a stupid problem: the table (row\_qc) is keyed by a string (which looks like a locus). The matrix table (mt\_split\_annotated) has rows keyed by [locus, alleles]. When I attempt a simple join to bolt on the vqsr scores like so:

mt\_split\_annotated = mt\_split\_annotated.annotate\_rows(vqsr = row\_qc[mt\_split\_annotated.locus])

I get this error:  
ExpressionException: Key type mismatch: cannot index table with given expressions:  
Table key: str  
Index Expressions: locus

I can see there’s a clear type-mismatch, but my attempts to cast the string to a locus or convert the locus to a string are not working so far ☹  
Any help appreciated!  
Vivek

---

<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:** [May 22, 2019, 9:17pm UTC](https://discuss.hail.is/t/correct-method-to-annotate-rows-of-matrix-table-with-a-table-of-vqsr-scores/962/2 "2019-05-22T21:17:50Z")

</div>

the method you need is [`parse_locus`](https://hail.is/docs/0.2/functions/genetics.html?highlight=parse_locus#hail.expr.functions.parse_locus):

```auto
row_qc = row_qc.key_by(locus = hl.parse_locus(row_qc.locus, 
    reference_genome=...)) 

```

---

<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:** [May 22, 2019, 9:24pm UTC](https://discuss.hail.is/t/correct-method-to-annotate-rows-of-matrix-table-with-a-table-of-vqsr-scores/962/3 "2019-05-22T21:24:11Z")

</div>

you can also specify the type on import:

```auto
row_qc = hl.import_table('file', types={'locus': 'locus<GRCh37>'})

```

---

<div class="post-metadata">

**Author:** ![Vivek](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/vivek/32/249_2.png) [@Vivek](https://discuss.hail.is/u/Vivek)\
**Post date:** [May 23, 2019, 7:55pm UTC](https://discuss.hail.is/t/correct-method-to-annotate-rows-of-matrix-table-with-a-table-of-vqsr-scores/962/4 "2019-05-23T19:55:26Z")

</div>

Thank you! I imported with the correct type for the locus field, and that worked fine.
