Bioconductor / LoomExperiment

A package to read, write, and manipulate loom files using LoomExperiments. Uses the loom file format from the Linnarson Lab. https://linnarssonlab.org/loompy/
https://www.bioconductor.org/packages/LoomExperiment
6 stars 5 forks source link

colData class and reducedDim dimnames don't survive roundtrip #10

Closed alexvpickering closed 4 years ago

alexvpickering commented 4 years ago

Example:

library(SingleCellExperiment)
library(LoomExperiment)
u <- matrix(rpois(20000, 5), ncol=100)
v <- log2(u + 1)
sce <- SingleCellExperiment(assays=list(counts=u, logcounts = v))
sce <- scater::runPCA(sce)
pcs <- reducedDim(sce, type = 'PCA')

g <- scran::buildSNNGraph(pcs, transpose = TRUE)
cluster <- igraph::cluster_walktrap(g)$membership
sce$cluster <- factor(cluster)

sce <- scater::runTSNE(sce, dimred = 'PCA')
colnames(reducedDim(sce, 'TSNE')) <- c('TSNE1', 'TSNE2')

scle <- as(sce, 'SingleCellLoomExperiment')

f <- tempfile(fileext = '.loom')
export(scle, f)
imported_scle <- import(f, type='SingleCellLoomExperiment')

# colnames are lost
# row.names are also changed from NULL to 1:nrow
head(reducedDim(scle, 'TSNE'), 1)
#          TSNE1      TSNE2
#[1,]  1.5825394 -0.8818167

head(reducedDim(imported_scle, 'TSNE'), 1)
#      [,1]       [,2]
#1 1.582539 -0.8818167

# class of colData elements also changes
class(scle$cluster)
# "factor"

class(imported_scle$cluster)
#  "character"

packageVersion('LoomExperiment')
#[1] ‘1.5.0’

Thank you!

LiNk-NY commented 4 years ago

Hi Alex, @alexvpickering I am still looking into the issue and see that we could organize the internal data model a bit better. I will get back to you soon with a fix. Thanks, Marcel

LiNk-NY commented 4 years ago

Hi Alex, @alexvpickering I have a PR pending with the changes that address these issues. Thanks for your patience. Best, Marcel