Skip to content

Commit

Permalink
2.2.2: install R package fix
Browse files Browse the repository at this point in the history
  • Loading branch information
weber8thomas committed Sep 22, 2023
1 parent c4a0671 commit 0f4ef95
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
8 changes: 4 additions & 4 deletions workflow/rules/setup.smk
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
21 changes: 16 additions & 5 deletions workflow/scripts/utils/install_R_package.R
Original file line number Diff line number Diff line change
@@ -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")
}

0 comments on commit 0f4ef95

Please sign in to comment.