Skip to content

Instantly share code, notes, and snippets.

@vjcitn
Created March 25, 2024 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vjcitn/1993e35bbc18e991015e526a859dd048 to your computer and use it in GitHub Desktop.
Save vjcitn/1993e35bbc18e991015e526a859dd048 to your computer and use it in GitHub Desktop.
"instrumented" do_SingleR
do_SingleRi = function(sce=NULL, path="/home/vincent/tenx3k.h5ad",
ref=celldex::HumanPrimaryCellAtlasData(),
ref.type = "label.main",
min.common = 1000, assay.type.test=1L, instrument=TRUE,
clprocid=NULL, ...) {
if (instrument == TRUE && is.null(clprocid)) stop("clprocid not set")
cl_timestamp(clprocid, "init")
stopifnot(ref.type %in% c("label.main", "label.fine"))
if (is.null(sce)) {
is_h5ad = length(grep("h5ad$", path)==1)
is_rda = length(grep("rda$", path)==1)
is_rds = length(grep("rds$", path)==1)
chk = sum(c(is_h5ad, is_rda, is_rds))
if (chk != 1) stop("path must have suffix h5ad, rda or rds")
if (is_h5ad) sce = ingest_h5ad(path)
else if (is_rda) sce = get(load(path))
else if (is_rds) sce = get(readRDS(path))
stopifnot(inherits(sce, "SingleCellExperiment"))
}
cl_timestamp(clprocid, "pre-singler")
preds = SingleR(test=sce,
ref=ref, labels=ref[[ref.type]], assay.type.test=assay.type.test,...)
cl_timestamp(clprocid, "post-singler")
list(input=sce, preds=preds)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment