I am trying to convert a rather large (29k rows and 116k columns) SingleCellExperiment object to a AnnData object on disk using the writeH5AD function from the zellkonverter package. The matrix I want to use as the primary assay is a LowRankMatrix class and by default zellkonverter doesn't know how to convert this to a dgCMatrix so instead converts it to a base matrix class which is too large to fit in memory. The LowRankMatrix is actually the "reconstructed" assay generated by the correctExperiments function from the batchelor package. When I try to manually coerce the LowRankMatrix to a dgCMatrix I receive the following error:
library(Matrix) library(SingleCellExperiment) sce <- readRDS("SCE.rds") mat <- assay(sce, "reconstructed") mat <- as(mat, "dgCMatrix") Error in rbind(x, y, z) : negative extents to matrix
The operation is however successful if I perform it on a smaller subset of the matrix:
mat <- mat[1:100, 1:100] mat <- as(mat, "dgCMatrix")
I don't strictly need a H5AD file, I could get by with an MTX file, however the writeMM function from the Matrix package doesn't know how to handle a LowRankMatrix either.