"', def: '",
defs[[i]] ,
"'}) ",
"with o ",
"MATCH (p:OntoTerm { id: '",
multi_parents[j],
"'}) ",
"CREATE (p)<-[:parent]-(o) ",
"CREATE (p)-[:child]->(o) "
)
q_cypher <- gsub("\"", "", query_parents)
call_neo4j(q_cypher, con)
# quotes <- c(quotes, query_parents)
# call_neo4j(query_parents, con)
}
}
}
}
importOntology("~/Projects/work/scSearch/scripts/ontologies/v1/efo_v3.32.0.obo", "3.32", "EFO")
importOntology <-
function(onto_path,
version,
source,
neo4j_user = "neo4j",
neo4j_pass = "test") {
con <- neo4j_api$new(url = "http://localhost:7474",
user = neo4j_user,
password = neo4j_pass)
query_node <-
paste0(
"MERGE (o:OntoSource { source:'", source , "', version: '",
version,
"'})"
)
q_cypher <- gsub("\"", "", query_node)
# quotes <- c(quotes, query_node)
call_neo4j(q_cypher, con)
out <-
ontologyIndex::get_ontology(onto_path, extract_tags = "everything")
ids <- out$id
names <- out$name
parents <- out$parents
ancestors <- out$ancestors
is_as <- out$is_a
defs <- out$def
nss <- out$namespace
quotes <- c()
for (i in 1:length(ids)) {
query_node <-
paste0(
"MERGE (os:OntoSource { source:'", source , "', version: '",
version,
"'}) ",
"MERGE (o:OntoTerm { source:'", source , "', id: '",
ids[[i]] ,
"', name: '",
names[[i]],
"', def: '",
defs[[i]] ,
"'})",
"with os, o ",
"CREATE (o)-[:source]->(os) "
)
q_cypher <- gsub("\"", "", query_node)
# quotes <- c(quotes, query_node)
call_neo4j(q_cypher, con)
if (length(unname(unlist(nss[i]))) > 0) {
query_namespace <-
paste0(
"MERGE (o:OntoTerm { id: '",
ids[[i]] ,
"', name: '",
names[[i]],
"', def: '",
defs[[i]] ,
"'}) ",
"MERGE (n:OntoNamespace { id: '",
unlist(unname(nss[i])),
"'}) ",
"with o, n ",
"CREATE (o)-[:namespace]->(n) "
)
q_cypher <- gsub("\"", "", query_namespace)
call_neo4j(q_cypher, con)
# quotes <- c(quotes, query_namespace)
# call_neo4j(query_namespace, con)
}
}
for (i in 1:length(ids)) {
if (length(unname(unlist(parents[i]))) > 0) {
multi_parents <- strsplit(unname(unlist(parents[i])), ";")
for (j in 1:length(multi_parents)) {
query_parents = paste0(
"MERGE (o:OntoTerm { id: '",
ids[[i]] ,
"', name: '",
names[[i]],
"', def: '",
defs[[i]] ,
"'}) ",
"with o ",
"MATCH (p:OntoTerm { id: '",
multi_parents[j],
"'}) ",
"CREATE (p)<-[:parent]-(o) ",
"CREATE (p)-[:child]->(o) "
)
q_cypher <- gsub("\"", "", query_parents)
call_neo4j(q_cypher, con)
# quotes <- c(quotes, query_parents)
# call_neo4j(query_parents, con)
}
}
}
}
importOntology("~/Projects/work/scSearch/scripts/ontologies/v1/efo_v3.32.0.obo", "3.32", "EFO")
out <-
ontologyIndex::get_ontology("~/Projects/work/scSearch/scripts/ontologies/v1/uberon_7_27_2021.obo", extract_tags = "everything")
ids <- out$id
names <- out$name
parents <- out$parents
ancestors <- out$ancestors
is_as <- out$is_a
defs <- out$def
nss <- out$namespace
i < 1
i <- 1
query_node <-
paste0(
"MATCH (os:OntoSource { source:'", source , "', version: '",
version,
"'}) ",
"MERGE (o:OntoTerm { source:'", source , "', id: '",
ids[[i]] ,
"', name: '",
names[[i]],
"', def: '",
defs[[i]] ,
"'})",
"with os, o ",
"CREATE (o)-[:source]->(os) "
)
q_cypher <- gsub("\"", "", query_node)
source <- "UBERON"
version <- "TEST"
query_node <-
paste0(
"MATCH (os:OntoSource { source:'", source , "', version: '",
version,
"'}) ",
"MERGE (o:OntoTerm { source:'", source , "', id: '",
ids[[i]] ,
"', name: '",
names[[i]],
"', def: '",
defs[[i]] ,
"'})",
"with os, o ",
"CREATE (o)-[:source]->(os) "
)
q_cypher <- gsub("\"", "", query_node)
print(q_cypher)
library(neo4r)
library(ontologyIndex)
importOntology <-
function(onto_path,
version,
source,
neo4j_user = "neo4j",
neo4j_pass = "test") {
con <- neo4j_api$new(url = "http://localhost:7474",
user = neo4j_user,
password = neo4j_pass)
query_node <-
paste0(
"MERGE (o:OntoSource { source:'", source , "', version: '",
version,
"'})"
)
q_cypher <- gsub("\"", "", query_node)
# print(q_cypher)
call_neo4j(q_cypher, con)
out <-
ontologyIndex::get_ontology(onto_path, extract_tags = "everything")
ids <- out$id
names <- out$name
parents <- out$parents
ancestors <- out$ancestors
is_as <- out$is_a
defs <- out$def
nss <- out$namespace
for (i in 1:length(ids)) {
query_node <-
paste0(
"MATCH (os:OntoSource { source:'", source , "', version: '",
version,
"'}) ",
"MERGE (o:OntoTerm { source:'", source , "', id: '",
ids[[i]] ,
"', name: '",
names[[i]],
"', def: '",
defs[[i]] ,
"'})",
"with os, o ",
"CREATE (o)-[:source]->(os) "
)
q_cypher <- gsub("\"", "", query_node)
# print(q_cypher)
call_neo4j(q_cypher, con)
if (length(unname(unlist(nss[i]))) > 0) {
query_namespace <-
paste0(
"MERGE (o:OntoTerm { id: '",
ids[[i]] ,
"', name: '",
names[[i]],
"', def: '",
defs[[i]] ,
"'}) ",
"MERGE (n:OntoNamespace { id: '",
unlist(unname(nss[i])),
"'}) ",
"with o, n ",
"CREATE (o)-[:namespace]->(n) "
)
q_cypher <- gsub("\"", "", query_namespace)
# print(q_cypher)
call_neo4j(q_cypher, con)
}
}
for (i in 1:length(ids)) {
if (length(unname(unlist(parents[i]))) > 0) {
multi_parents <- strsplit(unname(unlist(parents[i])), ";")
for (j in 1:length(multi_parents)) {
query_parents = paste0(
"MERGE (o:OntoTerm { id: '",
ids[[i]] ,
"', name: '",
names[[i]],
"', def: '",
defs[[i]] ,
"'}) ",
"with o ",
"MATCH (p:OntoTerm { id: '",
multi_parents[j],
"'}) ",
"CREATE (p)<-[:parent]-(o) ",
"CREATE (p)-[:child]->(o) "
)
q_cypher <- gsub("\"", "", query_parents)
# print(q_cypher)
call_neo4j(q_cypher, con)
}
}
}
}
# UBERON
importOntology("~/Projects/work/scSearch/scripts/ontologies/v1/uberon_7_27_2021.obo", "7_27_2021", "UBERON")
importOntology("~/Projects/work/scSearch/scripts/ontologies/v1/uberon_7_27_2021.obo", "7_27_2021", "UBERON")
m <- sparseMatrix(
i = sample(x = 1e4, size = 1e4),
j = sample(x = 1e4, size = 1e4),
x = rnorm(n = 1e4)
)
mm
??sample
library(Matrix)
m <- sparseMatrix(
i = sample(x = 1e4, size = 1e4),
j = sample(x = 1e4, size = 1e4),
x = rnorm(n = 1e4)
)
m
??sparseMatrix
?sparseMatrix
install.packages("viewpoly")
viewpoly::run_app()
viewpoly::run_app()
viewpoly::run_app()
viewpoly::run_app()
suppressPackageStartupMessages(library(scater))
suppressPackageStartupMessages(library(zellkonverter))
set.seed(1000)
sce <- mockSCE()
dim(sce)
#> [1] 2000  200
# Will use `Treatment` as a fake batch variable.
table(sce$Treatment)
writeH5AD(sce, file = "mockSCE.h5ad")
BiocManager::install("HCAData")
library("HCAData")
HCAData()
HCAData()
library("HCAData")
HCAData()
HCAData("ica_bone_marrow")
library(dsassembly)
restUrl("https://dev.cerberus.genomics.roche.com/v2")
ds <- getDataset("DS000020088")
dsassembly::activeUserCache(())
dsassembly::activeUserCache()
dsassembly::userCache()
library(dsassembly)
library(dsassembly)
restUrl("https://dev.cerberus.genomics.roche.com/v2")
ds <- getDataset("DS000020088")
library(dsassembly)
library(zellkonverter)
library(jsonvalidate)
sce <- zellkonverter::readH5AD("~/Projects/GSM3138367.h5ad")
sce <- annotateExperiment(sce,
title="test_sce",
description="tst_sce_description",
annotation=NULL,
sources=list(
list(name="GEO", id="asbc7")
),
organism="Mus musculus",
namespace=list(
list(type="genome", id="GRCm38")
),
technology=list(name="scRNA-seq",details="10X Genomics")
)
row.names(sce) <- make.unique(row.names(sce))
library(MultiAssayExperiment)
mae <- MultiAssayExperiment(experiments=list("experiment-1" = sce))
mae <- annotateDataset(mae,
title="test",
description="test_desc",
authors=c("kancherj"))
library(dsdb.plus)
dsassembly::saveDataset(mae, dir="./Projects/work/test-datasets-upload/", stage.only=TRUE)
ds <- getDataset("DS000020088")
traceback()
library(dsassembly)
restUrl("https://dev.cerberus.genomics.roche.com/v2")
ds <- getDataset("DS000020102")
ds <- getDataset("DS000000267")
ds
rowRanges((ds))
rowRanges(ds)
rowRanges(rowdata(ds)()
rowRanges(rowdata(ds))
rowRanges(rowdata(ds))
rowRanges(rowData(ds))
experiments(ds)
experiments(ds)[["RNA-Seq_hsa_gene"]]
rowRanges(experiments(ds)[["RNA-Seq_hsa_gene"]])
as(rowRanges(experiments(ds)[["RNA-Seq_hsa_gene"]]), "data.frame")
View(as(rowRanges(experiments(ds)[["RNA-Seq_hsa_gene"]]), "data.frame"))
View(as(rowRanges(experiments(getDataset("DS000000267"))[["RNA-Seq_hsa_gene"]]), "data.frame"))
library(dsassembly)
restUrl("https://dev.cerberus.genomics.roche.com/v2")
ds <- getDataset("DS000020088")
ds <- getDataset("DS000000264")
library(dsassembly)
restUrl("https://dev.cerberus.genomics.roche.com/v2")
ds <- getDataset("DS000020104")
library(genomitory)
hits <- searchFiles(type="collection", n=Inf)
# Ignore the FeatureDB legacy feature sets.
hits <- hits[hits$project != "GMTY28",]
descriptions <- list()
collections <- list()
all.genes <- all.ids <- integer(0)
counter <- 0L
for (h in seq_len(nrow(hits))) {
cursets <-  getFeatureSetCollection(hits$id[h])
descriptions[[h]] <- mcols(cursets)
descriptions[[h]]$size <- lengths(cursets)
collections[[h]] <- data.frame(id = hits$id[h], number = length(cursets), title=hits$title[h], description=hits$description[h], species=hits$organism[h])
all.genes <- c(all.genes, unlist(cursets, use.names=FALSE))
all.ids <- c(all.ids, rep(seq_along(cursets) + counter, lengths(cursets)))
counter <- counter + length(cursets)
}
descriptions <- do.call(rbind, descriptions)
collections <- do.call(rbind, collections)
u.genes <- unique(all.genes)
all.genes <- match(all.genes, u.genes)
by.gene <- split(all.ids, factor(all.genes, seq_along(u.genes)))
by.set <- split(all.genes, factor(all.ids, seq_len(nrow(descriptions))))
gathered <- list(
list(
id = "GMTY17:GRCm38/GRCm38.IGIS4.0.genes.rds@REVISION-3",
field = "symbol"
),
list(
id = "GMTY17:GRCh38/GRCh38.IGIS4.0.genes.rds@REVISION-3",
field = "symbol"
)
)
found.genes <- found.symbols <- character(0)
for (x in gathered) {
current <- getFeatures(x$id)
found.genes <- c(found.genes, names(current))
found.symbols <- c(found.symbols, mcols(current)[[x$field]])
}
keep <- found.genes %in% u.genes & !is.na(found.symbols)
found.symbols <- c(u.genes, found.symbols[keep]) # get the Ensembl ID at the front.
found.genes <- c(u.genes, found.genes[keep])
symbol.mapping <- split(found.symbols, factor(found.genes, levels=u.genes))
dir <- "assets"
dir.create(dir)
saveTabbedIndices <- function(y, path) {
x <- vapply(y, function(z) {
z <- sort(z) # convert to diffs to reduce integer size
z <- c(z[1] - 1L, diff(z)) # get to 0-based indexing.
paste(z, collapse="\t")
}, "")
write(x, file=file.path(dir, path))
handle <- gzfile(file.path(dir, paste0(path, ".ranges.gz")))
write(nchar(x), file=handle, ncolumns=1)
close(handle)
}
saveTabbedIndices(by.gene, path="gene2set.tsv")
saveTabbedIndices(by.set, path="set2gene.tsv")
collected <- sprintf("%s\t%s\t%s\t%s\t%s", collections$id, collections$number, tolower(collections$title), gsub("\t|\n", " ", tolower(collections$description)), collections$species)
handle <- gzfile(file.path(dir, "collections.tsv.gz"))
write(collected, file=handle)
close(handle)
collected <- sprintf("%s\t%s\t%s", gsub("\t|\n", " ", tolower(descriptions$name)), gsub("\t|\n", " ", tolower(descriptions$description)), descriptions$size)
handle <- gzfile(file.path(dir, "sets.tsv.gz"))
write(collected, file=handle)
close(handle)
collected <- vapply(symbol.mapping, function(x) paste(gsub("\t|\n", " ", tolower(x)), collapse="\t"), "")
handle <- gzfile(file.path(dir, "genes.tsv.gz"))
write(collected, file=handle)
close(handle)
library(dsassembly)
dataset <- "DS000012156"
ds <- getDataset(dataset)
ds <- getDataset(dataset)
library(GenomeInfoDbData)
install.packages("BiocManager")
BiocManager::install("GenomeInfoDbData")
BiocManager::install("GenomeInfoDbData", version = 1.2.7)
BiocManager::install("GenomeInfoDbData", version = "1.2.7")
setwd("~/Projects/public/BiocPy/rds2py/tests/data")
setClass("FOO", slots=c(bar="integer"))
# pairlist
y <- pairlist(runif(10), runif(20), runif(30))
saveRDS(y, file="pairlist.rds")
y <- pairlist(sample(letters), pairlist(sample(11), runif(12)))
saveRDS(y, file="pairlist_nested.rds")
y <- pairlist(foo=sample(letters), bar=pairlist(whee=sample(11), bum=runif(12))) # with names
saveRDS(y, file="pairlist_names.rds")
y <- pairlist(aaron=sample(letters), bar=list(sample(11), runif(12)))
attr(y, "foo") <- "bar"
saveRDS(y, file="pairlist_attr.rds")
# altrep
scenarios <- 1:15
saveRDS(y, file="altrep_series.rds")
x <- 1:100
names(x) <- sprintf("GENE_%s", seq_along(x))
saveRDS(x, file="altrep_attr.rds")
x <- as.character(1:100)
saveRDS(x, file="altrep_strings_deferred.rds")
x <- c(NA_integer_, 1:10, NA_integer_)
x <- as.character(x)
saveRDS(x, file="altrep_strings_wNA.rds")
x <- as.character(1:100 * 2)
saveRDS(x, file="altrep_double_deferred.rds")
x <- c(NaN, 1:10, Inf, -Inf, NA)
x <- as.character(x)
saveRDS(x, file="altrep_double_wNA.rds")
# atomic
y <- rpois(112, lambda=8)
saveRDS(y, file="atomic_ints.rds")
y <- rbinom(55, 1, 0.5) == 0
saveRDS(y, file="atomic_logical.rds")
y <- rbinom(999, 1, 0.5) == 0
y[sample(length(y), 10)] <- NA
saveRDS(y, file="atomic_logical_wNA.rds")
y <- rnorm(99)
saveRDS(y, file="atomic_double.rds")
y <- as.raw(sample(256, 99, replace=TRUE) - 1)
saveRDS(y, file="atomic_raw.rds")
y <- rnorm(99) + rnorm(99) * 1i
saveRDS(y, file="atomic_complex.rds")
y <- sample(LETTERS)
saveRDS(y, file="atomic_chars.rds")
y <- c("α-globin", "😀😀😀", "fußball", "Hervé Pagès")
saveRDS(y, file="atomic_chars_unicode.rds")
vals <- sample(.Machine$integer.max, 1000)
names(vals) <- sprintf("GENE_%i", seq_along(vals))
attr(vals, "foo") <- c("BAR", "bar", "Bar")
class(vals) <- "frog"
saveRDS(vals, file="atomic_attr.rds")
# lists
y <- list(runif(10), runif(20), runif(30))
saveRDS(y, file="lists.rds")
y <- list(sample(letters), list(sample(11), runif(12)))
saveRDS(y, file="lists_nested.rds")
y <- list(list(2, 6), list(5, c("cat", "dog", "bouse"), list(sample(99), runif(20))))
saveRDS(y, file="lists_nested_deep.rds")
df <- data.frame(xxx=runif(19), YYY=sample(letters, 19), ZZZ=rbinom(19, 1, 0.4) == 0)
saveRDS(df, file="lists_df.rds")
rownames(df) <- paste0("FOO-", LETTERS[1:19])
saveRDS(df, file="lists_df_rownames.rds")
# S4
y <- Matrix::rsparsematrix(100, 10, 0.05)
saveRDS(y, file="s4_matrix.rds")
setClass("FOO", slots=c(bar="integer"))
y <- new("FOO", bar=2L)
saveRDS(y, file="s4_class.rds")
?.row_data_path
??.row_data_path
showMethods(.row_data_path)
methods(".row_data_path")
methods(print)
methods(.row_data_path)
