Skip to content
Merged
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
4 changes: 2 additions & 2 deletions docker/ShinyCell2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ COPY install_packages.R /opt2/install_packages.R
RUN cd /opt2 && Rscript /opt2/install_packages.R
COPY git_installs.sh /opt2/work/git_installs.sh
RUN cd /opt2/work; ./git_installs.sh
RUN Rscript -e 'remotes::install_github("OpenOmics/ShinyCell2@deg_page")'
RUN Rscript -e 'remotes::install_github("OpenOmics/ShinyCell2")'
ADD build_shinycell.R /usr/bin/build_shinycell.R
RUN chmod +x /usr/bin/build_shinycell.R
RUN chmod +x /usr/bin/build_shinycell.R
43 changes: 31 additions & 12 deletions docker/ShinyCell2/build_shinycell.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ prompt_for_install <- function(pkg) {
response <- tolower(readLines("stdin", n = 1))
if (response == "y") {
if (pkg == "ShinyCell2") {
remotes::install_github("OpenOmics/ShinyCell2@deg_page", quiet = TRUE)
remotes::install_github("OpenOmics/ShinyCell2", quiet = TRUE)
} else {
install.packages(pkg, quiet = TRUE)
}
Expand Down Expand Up @@ -112,7 +112,7 @@ parser$add_argument(
args <- parser$parse_args()

if (args$silent) {
options(error = traceback(1))
options(error = function() traceback(1))
options(warn = -1)
}

Expand Down Expand Up @@ -214,13 +214,14 @@ if (class(seurat_obj) == "SeuratObject") {
# ShinyCell2 does NOT support:
# - celltype "assays" added by azimuth (prediction.score.celltype.l*)
# - HTO
# - sketch assays for large datasets
for (assay in Assays(seurat_obj)) {
if (startsWith(assay, "prediction.score.celltype.l")) {
seurat_obj[[assay]] <- NULL
}
}

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

shinycell_config <- do.call(
createConfig,
c(seurat_obj, config_params)
)

# Determine which metadata to include based on remove_metas list
remove_metas <- c()

if (!is.null(rmmeta)) {
remove_metas <- c(remove_metas, rmmeta)
}

for (config_label in shinycell_config$ID) {
# Add any metadata columns related to unsupported assays to remove_metas
all_meta_cols <- colnames(seurat_obj@meta.data)
for (meta_col in all_meta_cols) {
for (assay in unsupported_assays) {
if (grepl(assay, config_label, fixed = TRUE)) {
remove_metas <- c(remove_metas, config_label)
if (grepl(assay, meta_col, fixed = TRUE)) {
remove_metas <- c(remove_metas, meta_col)
}
}
}

shinycell_config <- delMeta(shinycell_config, remove_metas)
# Remove duplicates from remove_metas
remove_metas <- unique(remove_metas)

# Create meta.to.include: all metadata columns NOT in remove_metas
meta_to_include <- setdiff(all_meta_cols, remove_metas)

# Add meta.to.include to config parameters if there are columns to include
if (length(meta_to_include) > 0) {
# config_params$meta.to.del <- remove_metas
config_params$meta.to.include <- meta_to_include
}

shinycell_config <- do.call(
createConfig,
c(seurat_obj, config_params)
)

# if (!is.null(length(meta_to_include) > 0)) {
# shinycell_config$meta.to.del <- remove_metas
# shinycell_config <- delMeta(shinycell_config, remove_metas)
# }

# Build the Shiny Application,
# in the default location for
Expand Down
14 changes: 6 additions & 8 deletions workflow/rules/shinycell2.smk
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ from textwrap import dedent

seurat_object = config['seurat_object']
run_dir = config['run_dir']
project_title = config['project_title']
project_title = config['project_title'].replace("\"", "")
marker_file = config['marker_file'] if exists(config['marker_file']) else []
cluster_labels = config['cluster_labels']
rmmeta = config['rmmeta']
Expand All @@ -27,24 +27,23 @@ rule shinycodes:
container: "docker://rroutsong/shinycell2_builder:latest"
params:
rname = "shinycodes",
project_title = project_title,
rmmeta = rmmeta,
max_levels = max_levels,
assaytouse = assaytouse,
outdir = join(run_dir, "wd"),
title = f'"{project_title}"',
defred_flag = f"--defred {defaultreduction} " if defaultreduction else "",
cluster_flag = f"--cluster_labels {cluster_labels} " if cluster_labels else "",
marker_flag = lambda w, input: f"--markers {input.marker_list} " if input.marker_list and exists(input.marker_list) else "",
marker_flag = lambda w, input: f"--markers {input.marker_list} " if input.marker_list and exists(input.marker_list) else ""
shell:
dedent("""
build_shinycell.R \\
-j {input.seurat_object} {params.marker_flag} \\
--proj {params.project_title} {params.cluster_flag} \\
--proj {params.title} {params.cluster_flag} \\
--rmmeta {params.rmmeta} {params.defred_flag} \\
-l {params.max_levels} \\
-a {params.assaytouse} \\
-o {params.outdir} \\
--silent \\
--codesonly
""")

Expand All @@ -57,24 +56,23 @@ rule shinyfiles:
container: "docker://rroutsong/shinycell2_builder:latest"
params:
rname = "shinyfiles",
project_title = project_title,
rmmeta = rmmeta,
max_levels = max_levels,
assaytouse = assaytouse,
wd = join(run_dir, "wd"),
title = f'"{project_title}"',
defred_flag = f"--defred {defaultreduction} " if defaultreduction else "",
cluster_flag = f"--cluster_labels {cluster_labels} " if cluster_labels else "",
marker_flag = lambda w, input: f"--markers {input.marker_list} " if input.marker_list and exists(input.marker_list) else "",
shell:
dedent("""
build_shinycell.R \\
-j {input.seurat_object} {params.marker_flag} \\
--proj {params.project_title} {params.cluster_flag} \\
--proj {params.title} {params.cluster_flag} \\
--rmmeta {params.rmmeta} {params.defred_flag} \\
-l {params.max_levels} \\
-a {assaytouse} \\
-o {params.wd} \\
--silent \\
--filesonly
""")

Expand Down