Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpaTalk #15

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/methods/spatalk/config.vsh.yaml
Original file line number Diff line number Diff line change
@@ -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
44 changes: 44 additions & 0 deletions src/methods/spatalk/script.R
Original file line number Diff line number Diff line change
@@ -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")