Error coercing LowRankMatrix to dgCMatrix
1
0
Entering edit mode
jma1991 ▴ 70
@jma1991-11856
Last seen 13 months ago
Cumbernauld

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.

BiocSingular zellkonverter batchelor • 1.4k views
ADD COMMENT
0
Entering edit mode
Aaron Lun ★ 28k
@alun
Last seen 20 hours ago
The city by the bay

I had a much longer answer, but I accidentally pressed ESC and deleted it. So I'll just mention the tl;dr.

Immediate fix: just wipe the "reconstructed" assay from the SCE before passing it to zellkonverter. In the resulting H5AD file, you may be able to do:

library(HDF5Array)
writeHDF5Array(mat, filepath="my.h5ad", name="layers/reconstructed")

luke.zappia we should probably do this automatically if we see a DelayedArray in writeH5AD.

ADD COMMENT
0
Entering edit mode

I've opened a GitHub issue here as a reminder to fix this https://github.com/theislab/zellkonverter/issues/32.

ADD REPLY

Login before adding your answer.

Traffic: 679 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6