How to export ld_matrix() to pandas?

Hi,

I’ve performed ld calculation on a small set of variants using the following formula:

ld_mat = vds.filter_intervals(Interval.parse('1:START-3M')).ld_matrix()

I’m looking for a way to export this matrix to pandas, using va.rsid to name rows and columns.
I’ve tried .to_local_matrix() but I’m unfamiliar with the resulting format and how to convert it to pandas.

ld_mat.to_local_matrix()
DenseMatrix(8, 8, [1.0, 0.1518, -0.0191, -0.0103, -0.0271, 0.0284, 0.0603, -0.103, ..., -0.103, -0.0231, 0.0143, 0.0399, 0.0502, 0.0208, -0.1352, 1.0], False)

Any tip?

Thanks,

Steph

to_local_matrix() produces a Spark Matrix which you can convert to a numpy matrix using .toArray():

ld_mat = vds.filter_intervals(Interval.parse('1:START-3M')).ld_matrix()
my_ndarray = ld_mat.to_local_matrix().toArray()
## pandas stuff here
1 Like