annotate spatialGE_clust.R @ 0:c84663d92248 draft default tip

planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
author goeckslab
date Wed, 13 Aug 2025 19:32:05 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
1 # ------------------------------
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
2 # Spatially-Informed Clustering
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
3 # ------------------------------
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
4
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
5 # Purpose:
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
6 # Group cells into tissue domains using hierarchical clustering on a weighted similarity matrix
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
7
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
8 library(spatialGE)
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
9 library(optparse)
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
10 library(ggplot2)
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
11 library(tools)
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
12 library(dplyr)
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
13
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
14 ### Command Line Options
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
15
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
16
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
17 option_list <- list(
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
18 make_option(c("-f", "--file"), action = "store", default = NA, type = "character",
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
19 help = "STlist .rds file path from preprocessing"),
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
20 make_option(c("--visium"), action = "store_true", type = "logical", default = FALSE,
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
21 help = "Flag for Visium data"),
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
22 make_option(c("--raw"), action = "store_true", type = "logical", default = FALSE,
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
23 help = "Flag for raw data"),
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
24 make_option(c("--cosmx"), action = "store_true", type = "logical", default = FALSE,
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
25 help = "Flag for CosMX data"),
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
26 make_option(c("-s", "--samples"), action = "store", default = NULL, type = "character",
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
27 help = "Sample subset to perform clustering on"),
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
28 make_option(c("-w", "--weight"), action = "store", default = 0.025, type = "numeric",
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
29 help = "Weight to be applied to spatial distances between 0-1"),
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
30 make_option(c("-d", "--dist"), action = "store", default = "euclidean", type = "character",
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
31 help = "Distance metric to be used, all methods found in wordspace::dist.matrix"),
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
32 make_option(c("--dslogical"), action = "store_true", type = "logical", default = FALSE,
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
33 help = "Deepsplit logical flag"),
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
34 make_option(c("--logical"), action = "store", default = TRUE, type = "logical",
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
35 help = "Control cluster resolution, true will produce more clusters"),
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
36 make_option(c("--dsnumeric"), action = "store_true", type = "logical", default = FALSE,
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
37 help = "Deepsplit numeric flag"),
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
38 make_option(c("--numeric"), action = "store", default = 0, type = "numeric",
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
39 help = "control cluster resolution between 0-4, higher number will produce more clusters"),
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
40 make_option(c("-p", "--ptsize"), action = "store", default = 2.75, type = "numeric",
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
41 help = "Size of points on cluster plot")
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
42 )
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
43
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
44 ### Main
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
45
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
46 # parse args
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
47 opt <- parse_args(OptionParser(option_list = option_list))
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
48
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
49 # read in ST data from spatialGE preprocessing
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
50 STdata <- readRDS(opt$file)
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
51
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
52 message("Rds object successfully loaded")
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
53
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
54 # if deepSplit flag is included, choose between logical or numeric
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
55 if (opt$logical) {
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
56 deepsplit <- opt$dslogical
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
57 } else if (opt$numeric) {
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
58 deepsplit <- opt$dsnumeric
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
59 }
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
60
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
61 if (!is.null(opt$samples)) {
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
62 opt$samples <- strsplit(opt$samples, ",")[[1]]
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
63 } else if (is.null(opt$samples)) {
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
64 opt$samples <- NULL
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
65 }
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
66
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
67 # perform data clustering on transformed data
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
68 clusters <- STclust(x = STdata, samples = opt$samples, ws = opt$weight, dist_metric = opt$dist, deepSplit = deepsplit)
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
69
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
70 message("Unsupervised spatially-informed clustering has been performed")
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
71
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
72 # transform S4 to list for easier slot access
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
73 S4toList <- function(obj) {
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
74 slot_names <- slotNames(obj)
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
75 structure(lapply(slot_names, slot, object = obj), names = slot_names)
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
76 }
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
77
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
78 STdata <- S4toList(STdata)
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
79
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
80 message("Transformed to S4 for slot name access")
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
81
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
82 # depending on data input type, pull correct sample column
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
83 if (opt$visium) {
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
84 sample_col <- "sample_id"
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
85 } else if (opt$raw) {
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
86 sample_col <- "sampleID"
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
87 } else if (opt$cosmx) {
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
88 sample_col <- "sample_name"
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
89 }
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
90
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
91
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
92 if (!is.null(opt$samples)) {
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
93 samples <- STdata$sample_meta %>% pull(.data[[sample_col]]) %>% intersect(opt$samples)
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
94 } else {
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
95 samples <- STdata$sample_meta %>% pull(.data[[sample_col]])
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
96 }
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
97
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
98
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
99 message("Sample names identified")
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
100
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
101 # create cluster plot directory
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
102 if (!dir.exists("cluster_plots")) dir.create("cluster_plots")
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
103
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
104 # iterate through each sample, generate a plot, and save
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
105 for (s in samples) {
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
106
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
107 plot <- STplot(x = clusters, ws = opt$weight, ptsize = opt$ptsize, deepSplit = deepsplit, samples = s)
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
108
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
109 message("Cluster plots generated")
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
110
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
111
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
112 #create unique plot file names based on sample name
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
113
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
114 filename <- paste0("clustered_", s, ".png")
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
115
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
116 #save plot to subdir
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
117 ggsave(
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
118 path = "./cluster_plots",
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
119 filename = filename,
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
120 bg = "white",
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
121 width = 12
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
122 )
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
123 }
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
124
c84663d92248 planemo upload for repository https://github.com/goeckslab/tools-st/tree/main/tools/spatialge commit 482b2e0e6ca7aaa789ba07b8cd689da9a01532ef
goeckslab
parents:
diff changeset
125 message("Cluster plots saved")