Skip to content

Commit 0ee5a21

Browse files
rroutsongRyan Routsong
andauthored
Quality of usage shinycell updates (#23)
* fix: rework project title in snk rule, remove sketch assay from assays for shinycell * fix: remove sketch assays if exists * fix: install sc2 from main not deg branch * fix: build_shinycell.R fix meta removal function * fix: comment out meta removal for now * fix: install shinycell main not DEG_page * fix: remove silent arg --------- Co-authored-by: Ryan Routsong <ryan.routsong@nih.gov>
1 parent 1992639 commit 0ee5a21

File tree

3 files changed

+39
-22
lines changed

3 files changed

+39
-22
lines changed

docker/ShinyCell2/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ COPY install_packages.R /opt2/install_packages.R
5151
RUN cd /opt2 && Rscript /opt2/install_packages.R
5252
COPY git_installs.sh /opt2/work/git_installs.sh
5353
RUN cd /opt2/work; ./git_installs.sh
54-
RUN Rscript -e 'remotes::install_github("OpenOmics/ShinyCell2@deg_page")'
54+
RUN Rscript -e 'remotes::install_github("OpenOmics/ShinyCell2")'
5555
ADD build_shinycell.R /usr/bin/build_shinycell.R
56-
RUN chmod +x /usr/bin/build_shinycell.R
56+
RUN chmod +x /usr/bin/build_shinycell.R

docker/ShinyCell2/build_shinycell.R

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ prompt_for_install <- function(pkg) {
44
response <- tolower(readLines("stdin", n = 1))
55
if (response == "y") {
66
if (pkg == "ShinyCell2") {
7-
remotes::install_github("OpenOmics/ShinyCell2@deg_page", quiet = TRUE)
7+
remotes::install_github("OpenOmics/ShinyCell2", quiet = TRUE)
88
} else {
99
install.packages(pkg, quiet = TRUE)
1010
}
@@ -112,7 +112,7 @@ parser$add_argument(
112112
args <- parser$parse_args()
113113

114114
if (args$silent) {
115-
options(error = traceback(1))
115+
options(error = function() traceback(1))
116116
options(warn = -1)
117117
}
118118

@@ -214,13 +214,14 @@ if (class(seurat_obj) == "SeuratObject") {
214214
# ShinyCell2 does NOT support:
215215
# - celltype "assays" added by azimuth (prediction.score.celltype.l*)
216216
# - HTO
217+
# - sketch assays for large datasets
217218
for (assay in Assays(seurat_obj)) {
218219
if (startsWith(assay, "prediction.score.celltype.l")) {
219220
seurat_obj[[assay]] <- NULL
220221
}
221222
}
222223

223-
unsupported_assays <- c("HTO")
224+
unsupported_assays <- c("HTO", "sketch")
224225
for (assay in unsupported_assays) {
225226
if (assay %in% names(seurat_obj@assays)) {
226227
cat(paste0(assay, "unsupported assay removed!", sep = " "))
@@ -235,26 +236,44 @@ if (!is.null(max.levels)) {
235236
config_params$maxLevels <- max.levels
236237
}
237238

238-
shinycell_config <- do.call(
239-
createConfig,
240-
c(seurat_obj, config_params)
241-
)
242-
239+
# Determine which metadata to include based on remove_metas list
243240
remove_metas <- c()
244241

245242
if (!is.null(rmmeta)) {
246243
remove_metas <- c(remove_metas, rmmeta)
247244
}
248245

249-
for (config_label in shinycell_config$ID) {
246+
# Add any metadata columns related to unsupported assays to remove_metas
247+
all_meta_cols <- colnames(seurat_obj@meta.data)
248+
for (meta_col in all_meta_cols) {
250249
for (assay in unsupported_assays) {
251-
if (grepl(assay, config_label, fixed = TRUE)) {
252-
remove_metas <- c(remove_metas, config_label)
250+
if (grepl(assay, meta_col, fixed = TRUE)) {
251+
remove_metas <- c(remove_metas, meta_col)
253252
}
254253
}
255254
}
256255

257-
shinycell_config <- delMeta(shinycell_config, remove_metas)
256+
# Remove duplicates from remove_metas
257+
remove_metas <- unique(remove_metas)
258+
259+
# Create meta.to.include: all metadata columns NOT in remove_metas
260+
meta_to_include <- setdiff(all_meta_cols, remove_metas)
261+
262+
# Add meta.to.include to config parameters if there are columns to include
263+
if (length(meta_to_include) > 0) {
264+
# config_params$meta.to.del <- remove_metas
265+
config_params$meta.to.include <- meta_to_include
266+
}
267+
268+
shinycell_config <- do.call(
269+
createConfig,
270+
c(seurat_obj, config_params)
271+
)
272+
273+
# if (!is.null(length(meta_to_include) > 0)) {
274+
# shinycell_config$meta.to.del <- remove_metas
275+
# shinycell_config <- delMeta(shinycell_config, remove_metas)
276+
# }
258277

259278
# Build the Shiny Application,
260279
# in the default location for

workflow/rules/shinycell2.smk

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ from textwrap import dedent
33

44
seurat_object = config['seurat_object']
55
run_dir = config['run_dir']
6-
project_title = config['project_title']
6+
project_title = config['project_title'].replace("\"", "")
77
marker_file = config['marker_file'] if exists(config['marker_file']) else []
88
cluster_labels = config['cluster_labels']
99
rmmeta = config['rmmeta']
@@ -27,24 +27,23 @@ rule shinycodes:
2727
container: "docker://rroutsong/shinycell2_builder:latest"
2828
params:
2929
rname = "shinycodes",
30-
project_title = project_title,
3130
rmmeta = rmmeta,
3231
max_levels = max_levels,
3332
assaytouse = assaytouse,
3433
outdir = join(run_dir, "wd"),
34+
title = f'"{project_title}"',
3535
defred_flag = f"--defred {defaultreduction} " if defaultreduction else "",
3636
cluster_flag = f"--cluster_labels {cluster_labels} " if cluster_labels else "",
37-
marker_flag = lambda w, input: f"--markers {input.marker_list} " if input.marker_list and exists(input.marker_list) else "",
37+
marker_flag = lambda w, input: f"--markers {input.marker_list} " if input.marker_list and exists(input.marker_list) else ""
3838
shell:
3939
dedent("""
4040
build_shinycell.R \\
4141
-j {input.seurat_object} {params.marker_flag} \\
42-
--proj {params.project_title} {params.cluster_flag} \\
42+
--proj {params.title} {params.cluster_flag} \\
4343
--rmmeta {params.rmmeta} {params.defred_flag} \\
4444
-l {params.max_levels} \\
4545
-a {params.assaytouse} \\
4646
-o {params.outdir} \\
47-
--silent \\
4847
--codesonly
4948
""")
5049

@@ -57,24 +56,23 @@ rule shinyfiles:
5756
container: "docker://rroutsong/shinycell2_builder:latest"
5857
params:
5958
rname = "shinyfiles",
60-
project_title = project_title,
6159
rmmeta = rmmeta,
6260
max_levels = max_levels,
6361
assaytouse = assaytouse,
6462
wd = join(run_dir, "wd"),
63+
title = f'"{project_title}"',
6564
defred_flag = f"--defred {defaultreduction} " if defaultreduction else "",
6665
cluster_flag = f"--cluster_labels {cluster_labels} " if cluster_labels else "",
6766
marker_flag = lambda w, input: f"--markers {input.marker_list} " if input.marker_list and exists(input.marker_list) else "",
6867
shell:
6968
dedent("""
7069
build_shinycell.R \\
7170
-j {input.seurat_object} {params.marker_flag} \\
72-
--proj {params.project_title} {params.cluster_flag} \\
71+
--proj {params.title} {params.cluster_flag} \\
7372
--rmmeta {params.rmmeta} {params.defred_flag} \\
7473
-l {params.max_levels} \\
7574
-a {assaytouse} \\
7675
-o {params.wd} \\
77-
--silent \\
7876
--filesonly
7977
""")
8078

0 commit comments

Comments
 (0)