Home Install User Guide Python Notebook API FAQ

Loom File (R studio)

ReadLoomR

Use R to import loom files

In [ ]:
# Install devtools from CRAN
#install.packages("devtools")
# Use devtools to install hdf5r and loomR from GitHub
#devtools::install_github(repo = "hhoeflin/hdf5r")
#devtools::install_github(repo = "mojaveazure/loomR", ref = "develop")
## Unload a completed analysis stored in loomR object
library(loomR)
## data used were from Cellular diversity in the Drosophila midbrain revealed by single-cell transcriptomics, Croset, Treiber and Waddell, 2018 (eLife)
lfile <- connect(filename = "Waddell_CentralBrain_10k.loom", mode = "r+")

Create gene expression matrix

In [ ]:
full.matrix <- lfile$matrix[, ]
mx <- t(full.matrix)
gene.names <- lfile[["row_attrs/Gene"]][];
cell.id <- lfile$col.attrs$CellID[]
rownames(mx) <- gene.names
colnames(mx) <- cell.id

Create embedding coordinate files

In [ ]:
embedding <- lfile$col.attrs$Embedding[]
clusterid <- lfile$col.attrs$Clusterings[]
coord2 <- cbind(embedding, clusterid)
rownames(coord2) <- cell.id
colnames(coord2) <- c("X","Y","cluster")

Create metainformation used for map

In [ ]:
mapType="tsne";
mapName='Waddell_CentralBrain_10k_tSNE';  
study="flyBrain";
subjectid="";
species="drosophila"
disease="Healthy";
source="Waddell2018";
sample="midbrain";
comment="from loom";
author="demo";
name <- c("study","species","subjectid","disease","source","sample","comment","author","mapType","mapname")
value <- c(study,species,subjectid,disease,source,sample,comment,author,mapType, mapName )
map.info <- data.frame(name, value, stringsAsFactors=FALSE)

Write csv files

In [ ]:
write.csv(mx,"counts.csv")
write.csv(coord2,"coords.csv")
write.csv(map.info, "mapinfo.csv")

Next step: use python scripts to load the above files into MongoDB