Annotating gene names from file (gtf)

I want to add gene names (stored in mt from an imported GTF file as locus interval) to an imported mt from VCF. I annotate by the conditional that the locus is contained in the locus interval:

mt_vcf= mt_vcf.annotate_rows(gencode= hl.cond(gencode_genes_mt.interval.contains(mt_vcf.locus), gencode_genes_mt.gene_name))

And get the following error. What is the best way to do so?

ExpressionException: Cannot combine expressions from different source objects.
    Found fields from 2 objects:
        <hail.matrixtable.MatrixTable object at 0x7fa1c03254a8>: ['interval']
        <hail.matrixtable.MatrixTable object at 0x7fa1c00a3160>: ['locus']

Thanks.

The method you should be using is Table.index:

mt_vcf = mt_vcf.annotate_rows(gencode = gencode_genes[mt.locus].gene_name)

I thought we had a how-to on doing this, I’l make a note to add one.

Worked. thanks Tom