Hi there,
I have a list of ints that I’d like to convert to some hail object type and have this functionality:
aan[:5]
[155, 157, 165, 172, 189]
some_function(aan[:5]).take(1)
155
When I try array or many other things I get:
aan[:5]
[155, 157, 165, 172, 189]
hl.array(aan[:5]).take(1)
[[155, 157, 165, 172, 189]]
I’m very new to hail so any help with this would be great.
I’m assuming that aan
is a Hail expression of type array<int> that refers to some field on a Table or MatrixTable
. When you do expression.take
, that says, “take this expression, of which there are many values (one for each row of a table, for instance), and give me the first N”. so for example:
mt.alleles.take(3)
Will give you the alleles for the first three rows:
In [3]: mt.alleles.take(3)
Out[3]: [['A', 'C'], ['A', 'T'], ['A', 'G']]
Can you provide more information about what specifically you’re trying to do? Expression.take
generally isn’t a widely used feature for more than sanity checks – you probably want to be using vectorized operations like annotate_rows
and similar.
aan
is a regular list of ints. by regular I mean from the python base classes. I’d like to convert it to a hail object with the above functionally described to annotate some rows in a matrix.
Ideally it would be something like this, where mt
is a MatrixTable
len(aan)
899865
mt.count()
(899865, 34778)
take
mt.annotate_rows(test=aan).row.test.take(1)
155
but I get:
mt.annotate_rows(test=aan).row.test.take(1)
[[155,
157,
165,
172,
189,
214,
183,
instead so it annotates every row with the entire list best I can tell
instead so it annotates every row with the entire list best I can tell
That’s exactly what’s happening. If you want to annotate using row index to index into the array, you can do the following:
lit = hl.literal(aan) # convert aan to a hail literal expression
mt = mt.add_row_index() # add field row_idx
mt = mt.annotate_rows(test = lit[mt.row_idx])
Awesome. Thanks. Needed to know about row indexes. Really appreciate it