Select specific variants by locus


I have a very basic question - extracting specific variants from a matrix table.

If I wanted to extract a couple of variants, e.g.,

variant_list = ['chr1:xx', 'chr1:xx'] #locus
var_select = mt.filter_rows(hl.literal(set(variant_list).contains(

Then I got the error message about ‘TypeError’:

set element type: 'str'
type of arg 'item': locus<GRCh38>

I sort of understand the error, but how should exactly I generate the variant lists (as locus format) to extract variants?

Thank you very much!

You have to parse your loci into Hail’s format. You can use:

variant_list = [hl.parse_locus(x, reference_genome='GRCh38') for x in variant_list]

It worked - thanks much!

1 Like