From bdf835f024d0f8fe450cd280b983b6c23de5a180 Mon Sep 17 00:00:00 2001 From: Chananchida Sang-aram VSCODE Date: Wed, 12 Jun 2024 15:53:48 +0200 Subject: [PATCH] spatalk --- src/methods/spatalk/config.vsh.yaml | 26 +++++++++++++++++ src/methods/spatalk/script.R | 44 +++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 src/methods/spatalk/config.vsh.yaml create mode 100644 src/methods/spatalk/script.R diff --git a/src/methods/spatalk/config.vsh.yaml b/src/methods/spatalk/config.vsh.yaml new file mode 100644 index 0000000..83f2eb4 --- /dev/null +++ b/src/methods/spatalk/config.vsh.yaml @@ -0,0 +1,26 @@ +functionality: + name: spatalk + arguments: + - name: --input + type: file + description: Path to the input file + example: resources/datasets/Zhuang_2023_merfish_brain/dataset.h5ad + - name: --output + type: file + description: Path to the output directory + direction: output + example: resources/results/spatalk/prediction.h5ad + resources: + - type: r_script + path: script.R +platforms: + - type: docker + image: satijalab/seurat:4.1.0 + setup: + - type: r + packages: + - anndata + - tidyverse + github: + - linxihui/NNLM + - ZJUFanLab/SpaTalk \ No newline at end of file diff --git a/src/methods/spatalk/script.R b/src/methods/spatalk/script.R new file mode 100644 index 0000000..d327fd3 --- /dev/null +++ b/src/methods/spatalk/script.R @@ -0,0 +1,44 @@ +## VIASH START +par <- list( + input = "resources/datasets/Zhuang_2023_merfish_brain/dataset.h5ad", + output = "resources/results/spatalk/prediction.h5ad" +) +## VIASH END +library(tidyverse) +library(SpaTalk) +library(anndata) + +adata <- read_h5ad(par$input) +count_matrix <- adata$layers[["counts"]] %>% t %>% + `rownames<-`(adata$var$gene_symbol) +coords <- adata$obsm %>% data.frame %>% + mutate(cell = colnames(count_matrix), .before=1) %>% + rename(x = spatial.1, y = spatial.2) + +pyad <- adata$.__enclos_env__$private$.anndata +pyad$obs <- reticulate::py_get_item(pyad$obs, c("celltype", "fov")) + +# create SpaTalk data +obj <- createSpaTalk(st_data = count_matrix, + st_meta = coords, + species = "Mouse", + if_st_is_sc = T, + spot_max_cell = 1, + celltype = as.character(adata$obs[["celltype"]])) + +obj <- find_lr_path(object = obj, lrpairs = lrpairs, pathways = pathways) +obj <- dec_cci_all(object = obj) + +# generate prediction +ccc_pred <- data.frame( + obj@lrpair +) %>% arrange(desc(score)) + +# create output +output <- anndata::AnnData( + shape = c(0L, 0L), + uns = list( + ccc_pred = ccc_pred + ) +) +output$write_h5ad(par$output, compression = "gzip")