# Creating a Variant representation on a V0.2 Table

**URL:** <https://discuss.hail.is/t/creating-a-variant-representation-on-a-v0-2-table/856>\
**Category:** Hail Query & hailctl\
**Created:** [February 12, 2019, 2:58pm UTC](https://discuss.hail.is/t/creating-a-variant-representation-on-a-v0-2-table/856 "2019-02-12T14:58:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![knguyen142](https://avatars.discourse-cdn.com/v4/letter/k/74df32/32.png) [@knguyen142](https://discuss.hail.is/u/knguyen142)\
**Post date:** [February 12, 2019, 2:58pm UTC](https://discuss.hail.is/t/creating-a-variant-representation-on-a-v0-2-table/856/1 "2019-02-12T14:58:58Z")

</div>

I’m trying to create a Hail Table keyed on a variant so I can convert it to a matrix table. I have the chr, pos, alt, and ref fields, and must create a variant from this.

The equivalent v01 code is the following

`.annotate("variant=Variant(chr, pos, ref, alt)").key_by('variant')`

I believe v02 does not have the Variant class available anymore, and see that I can create a locus and an allele array and key by those two.

I tried

```auto
.annotate(locus=hl.Locus(ht.chr, ht.pos))
        .annotate(alleles=[ht.ref, ht.alt])
        .key_by('locus', 'alleles')

```

But have trouble creating the locus with this error:  
`TypeError: __init__ : parameter 'contig': expected (str or int), found hail.expr.expressions.typed_expressions.StringExpression: <StringExpression of type str>`

It looks like I have to pass in a literal value, but I only have access to the expression values and can’t find a way to convert it. What would you recommend?

Also, is the rest of the logic (creating an array of ref and alt alleles and keying on the locus-allele array pair the right idea to then import into a Matrix Table?

Thanks!

---

<div class="post-metadata">

**Author:** ![knguyen142](https://avatars.discourse-cdn.com/v4/letter/k/74df32/32.png) [@knguyen142](https://discuss.hail.is/u/knguyen142)\
**Post date:** [February 12, 2019, 4:41pm UTC](https://discuss.hail.is/t/creating-a-variant-representation-on-a-v0-2-table/856/2 "2019-02-12T16:41:39Z")

</div>

I unblocked myself with the following hack:

```auto
ht = ht.key_by(**hl.parse_variant(ht.chr + hl.literal(':') + hl.str(ht.pos) + hl.literal(':') + ht.ref + hl.literal(':') + ht.alt))

```

I think this works? But would love to find out the right way to do it.

---

<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:** [February 12, 2019, 5:37pm UTC](https://discuss.hail.is/t/creating-a-variant-representation-on-a-v0-2-table/856/3 "2019-02-12T17:37:10Z")

</div>

That totally works. This would too:

```auto
key_by(locus = hl.locus(ht.chr, ht.pos), [ht.ref, ht.alt])

```

---

<div class="post-metadata">

**Author:** ![knguyen142](https://avatars.discourse-cdn.com/v4/letter/k/74df32/32.png) [@knguyen142](https://discuss.hail.is/u/knguyen142)\
**Post date:** [February 12, 2019, 6:32pm UTC](https://discuss.hail.is/t/creating-a-variant-representation-on-a-v0-2-table/856/4 "2019-02-12T18:32:42Z")

</div>

Sweet! And there’s an `alleles=` in there too, right? That looks to work.

---

<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:** [February 12, 2019, 7:10pm UTC](https://discuss.hail.is/t/creating-a-variant-representation-on-a-v0-2-table/856/5 "2019-02-12T19:10:56Z")

</div>

oh, yeah, oops.
