From 0f4ef95080697cb7fc1c4e30f4e5e3fb40ff5ab4 Mon Sep 17 00:00:00 2001 From: Thomas Weber Date: Fri, 22 Sep 2023 14:12:17 +0000 Subject: [PATCH] 2.2.2: install R package fix --- workflow/rules/setup.smk | 8 ++++---- workflow/scripts/utils/install_R_package.R | 21 ++++++++++++++++----- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/workflow/rules/setup.smk b/workflow/rules/setup.smk index 5b381733..de8f3430 100644 --- a/workflow/rules/setup.smk +++ b/workflow/rules/setup.smk @@ -27,8 +27,8 @@ rule install_BSgenome_package: "../envs/rtools.yaml" resources: mem_mb=get_mem_mb_heavy, - script: - "../scripts/utils/install_R_package.R" + shell: + "Rscript workflow/scripts/utils/install_R_package.R {params.selected_package}" rule install_sctrip_multiplot_package: @@ -44,8 +44,8 @@ rule install_sctrip_multiplot_package: "../envs/rtools.yaml" resources: mem_mb=get_mem_mb_heavy, - script: - "../scripts/utils/install_R_package.R" + shell: + "Rscript workflow/scripts/utils/install_R_package.R {params.selected_package}" rule config_run_summary: diff --git a/workflow/scripts/utils/install_R_package.R b/workflow/scripts/utils/install_R_package.R index eef070d3..ebf2e346 100644 --- a/workflow/scripts/utils/install_R_package.R +++ b/workflow/scripts/utils/install_R_package.R @@ -1,23 +1,34 @@ -package <- snakemake@params[["selected_package"]] +# package <- snakemake@params[["selected_package"]] +args <- commandArgs(TRUE) +package <- args[1] +# Check if the package is already available is_package_available <- require(package, character.only = TRUE) if (!isTRUE(is_package_available)) { + # Ensure BiocManager is available since it will be needed regardless of the condition if (!require("BiocManager", quietly = TRUE)) { install.packages("BiocManager", repos = "http://cran.us.r-project.org") } + # Condition 1: Install custom tar.gz Bsgenome package named BSgenome.T2T.CHM13.V2_1.0.0.tar.gz if (grepl("BSgenome.T2T.CHM13.V2_1.0.0.tar.gz", package, fixed = TRUE, perl = FALSE)) { - print("T2T") BiocManager::install("GenomeInfoDbData", update = FALSE) install.packages(package, repos = NULL, type = "source") + + # Condition 2: Install standard Bsgenome packages (hg38/hg19/mm10) + } else if (package %in% c("BSgenome.Hsapiens.UCSC.hg38", "BSgenome.Hsapiens.UCSC.hg19", "BSgenome.Mmusculus.UCSC.mm10")) { + BiocManager::install(package, update = FALSE) + + # Condition 3: Install a custom package using devtools } else { - # Check if devtools is installed, if not install it + # Ensure devtools is installed if (!require("devtools", quietly = TRUE)) { install.packages("devtools", repos = "http://cran.us.r-project.org") } - # Use devtools::install to install the package devtools::install(package, dependencies = TRUE, update = FALSE) } - quit(save = "no") + + # Exit after installation, if desired + # quit(save = "no") }