# 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+")
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
embedding <- lfile$col.attrs$Embedding[]
clusterid <- lfile$col.attrs$Clusterings[]
coord2 <- cbind(embedding, clusterid)
rownames(coord2) <- cell.id
colnames(coord2) <- c("X","Y","cluster")
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(mx,"counts.csv")
write.csv(coord2,"coords.csv")
write.csv(map.info, "mapinfo.csv")