aertslab / SCopeLoomR

R package (compatible with SCope) to create generic .loom files and extend them with other data e.g.: SCENIC regulons, Seurat clusters and markers, ...
MIT License
38 stars 15 forks source link

loom v3 #14

Closed cbravo93 closed 4 years ago

cbravo93 commented 4 years ago

Hi!

Some of the functions (specially regards to metadata) do not work with v3 loom files. I have also opened an issue in the loomR GitHub. Meanwhile, could some functions be added for dealing with these files?

For general metadata, something likes this works:

#Using hdf5r
library(hdf5r) 
library(data.table)
library(rjson)

# For general metadata, for example
meta <- data.frame(
        row.names = loom[["col_attrs"]][["CellID"]]$read()
        , nGenes = loom[["col_attrs"]][["n_genes"]]$read()
        , nUMIs = loom[["col_attrs"]][["n_counts"]]$read()
        , percent_mito = loom[["col_attrs"]][["percent_mito"]]$read()
        , scanpy_clusters = loom[["col_attrs"]][["louvain"]]$read())

# The get_embeddings function doesn't work
default_embedding <- loom[["col_attrs"]][["Embedding"]]$read()

# For other embeddings (didn't figure out how to get the embedding name)
X <- loom[["col_attrs"]][["Embedding_X"]]$read()
Y <-  loom[["col_attrs"]][["Embedding_y"]]$read()

# getRegulonThresholds doesn't work, instead
md <- rjson::fromJSON(loom[["attrs"]][["MetaData"]]$read())
thresholds <- rbindlist(sapply(md[["regulonThresholds"]], function(thr) {return(data.frame(thr))}), fill = TRUE)
dweemx commented 4 years ago

Hi @cbravo93, I added Loom v3 compatibility in version v0.6.0 These are the functions I tested:

cell_ids <- get_cell_ids(loom = loom)
default_embedding <- get_default_embedding(loom = loom)
embeddings <- get_embeddings(loom = loom)
regulon_thresholds <- get_regulonThresholds(loom = loom)
regulons_mask <- get_regulons(loom = loom)
regulons_auc <- get_regulonsAuc(loom = loom)
louvain <- get_col_attr_by_key(loom = loom, key = "louvain")
clusterings <- get_clusterings(loom = loom)

Let me know if this also works for you !