Subset HailTable and MatrixTable from i to n

Is there a way to subset a MatrixTable by rows from row i up to n? What about HailTable?

Sure:

In [5]: import hail as hl
   ...: ht = hl.utils.range_table(50000, n_partitions=50000)
   ...: n_rows = 50000
   ...: i = 50
   ...: n = 30
   ...: ht.tail(n_rows - i).head(n).show()
+-------+
|   idx |
+-------+
| int32 |
+-------+
|    50 |
|    51 |
|    52 |
|    53 |
|    54 |
|    55 |
|    56 |
|    57 |
|    58 |
|    59 |
|    60 |
|    61 |
|    62 |
|    63 |
|    64 |
|    65 |
|    66 |
|    67 |
|    68 |
|    69 |
|    70 |
|    71 |
|    72 |
|    73 |
|    74 |
|    75 |
|    76 |
|    77 |
|    78 |
|    79 |
+-------+

EDIT: Forgot MTs. It’s the same for MTs:

In [7]: import hail as hl
   ...: mt = hl.utils.range_matrix_table(n_rows=50000, n_cols=10, n_partitions=50000)
   ...: mt = mt.annotate_entries(x = mt.row_idx * mt.col_idx)
   ...: n_rows = 50000
   ...: i = 50
   ...: n = 30
   ...: mt.tail(n_rows - i).head(n).show()
+---------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+
| row_idx |   0.x |   1.x |   2.x |   3.x |   4.x |   5.x |   6.x |   7.x |   8.x |   9.x |
+---------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+
|   int32 | int32 | int32 | int32 | int32 | int32 | int32 | int32 | int32 | int32 | int32 |
+---------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+
|      50 |     0 |    50 |   100 |   150 |   200 |   250 |   300 |   350 |   400 |   450 |
|      51 |     0 |    51 |   102 |   153 |   204 |   255 |   306 |   357 |   408 |   459 |
|      52 |     0 |    52 |   104 |   156 |   208 |   260 |   312 |   364 |   416 |   468 |
|      53 |     0 |    53 |   106 |   159 |   212 |   265 |   318 |   371 |   424 |   477 |
|      54 |     0 |    54 |   108 |   162 |   216 |   270 |   324 |   378 |   432 |   486 |
|      55 |     0 |    55 |   110 |   165 |   220 |   275 |   330 |   385 |   440 |   495 |
|      56 |     0 |    56 |   112 |   168 |   224 |   280 |   336 |   392 |   448 |   504 |
|      57 |     0 |    57 |   114 |   171 |   228 |   285 |   342 |   399 |   456 |   513 |
|      58 |     0 |    58 |   116 |   174 |   232 |   290 |   348 |   406 |   464 |   522 |
|      59 |     0 |    59 |   118 |   177 |   236 |   295 |   354 |   413 |   472 |   531 |
|      60 |     0 |    60 |   120 |   180 |   240 |   300 |   360 |   420 |   480 |   540 |
|      61 |     0 |    61 |   122 |   183 |   244 |   305 |   366 |   427 |   488 |   549 |
|      62 |     0 |    62 |   124 |   186 |   248 |   310 |   372 |   434 |   496 |   558 |
|      63 |     0 |    63 |   126 |   189 |   252 |   315 |   378 |   441 |   504 |   567 |
|      64 |     0 |    64 |   128 |   192 |   256 |   320 |   384 |   448 |   512 |   576 |
|      65 |     0 |    65 |   130 |   195 |   260 |   325 |   390 |   455 |   520 |   585 |
|      66 |     0 |    66 |   132 |   198 |   264 |   330 |   396 |   462 |   528 |   594 |
|      67 |     0 |    67 |   134 |   201 |   268 |   335 |   402 |   469 |   536 |   603 |
|      68 |     0 |    68 |   136 |   204 |   272 |   340 |   408 |   476 |   544 |   612 |
|      69 |     0 |    69 |   138 |   207 |   276 |   345 |   414 |   483 |   552 |   621 |
|      70 |     0 |    70 |   140 |   210 |   280 |   350 |   420 |   490 |   560 |   630 |
|      71 |     0 |    71 |   142 |   213 |   284 |   355 |   426 |   497 |   568 |   639 |
|      72 |     0 |    72 |   144 |   216 |   288 |   360 |   432 |   504 |   576 |   648 |
|      73 |     0 |    73 |   146 |   219 |   292 |   365 |   438 |   511 |   584 |   657 |
|      74 |     0 |    74 |   148 |   222 |   296 |   370 |   444 |   518 |   592 |   666 |
|      75 |     0 |    75 |   150 |   225 |   300 |   375 |   450 |   525 |   600 |   675 |
|      76 |     0 |    76 |   152 |   228 |   304 |   380 |   456 |   532 |   608 |   684 |
|      77 |     0 |    77 |   154 |   231 |   308 |   385 |   462 |   539 |   616 |   693 |
|      78 |     0 |    78 |   156 |   234 |   312 |   390 |   468 |   546 |   624 |   702 |
|      79 |     0 |    79 |   158 |   237 |   316 |   395 |   474 |   553 |   632 |   711 |
+---------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+

tail and head for MatrixTables also support an n_cols argument.

1 Like