Closed nh3 closed 5 years ago
Thank you for the issue. We are looking into a way to efficiently write Matrix::SparseMatrix
objects as dense matrices in the loomfile.
I've pushed a change that I hope addresses your issue. I've added functionality for dgCMatrix
in export as well as a few other changes to facilitate its usage.
I couldn't use your example since I don't know where test_data
comes from, so I've used an examples from DropletUtils
.
library(LoomExperiment)
library(DropletUtils)
example(read10xCounts)
scle <- SingleCellLoomExperiment(sce10x2)
temp <- tempfile(fileext = ".loom")
export(scle, temp)
res <- import(temp)
The assay will be given as a HDF5Array::DelayedMatrix
in the res
object. In export, writeHDF5Array()
is used on the dgCMatrix
. writeHDF5Array()
uses block processing i.e. it expands the sparse matrix block by block before writing each block to the HDF5 file, so this solution should write the dgCMatrix
efficiently. Message me back is this solution works.
The example in the vignette seems to be based on dense matrix only.
This is what I did:
export()
works on the same data if converted to dense matrix:As loom uses a dense representation on disk, perhaps it's not too unreasonable to ask for dense matrices. But
loompy
does support taking sparse matrices and writing dense to disk. Having to do sparse -> dense conversion in memory is quite limiting.