Herper 1.6.0
The Herper package is a simple toolset to install and manage Conda packages and environments from within the R console.
Unfortunately many tools for data analysis are not available in R, but are present in public repositories like conda. With Herper users can install, manage, record and run conda tools from the comfort of their R session.
Furthermore, many R packages require the use of these external dependencies. Again these dependencies can be installed and managed with the Conda package repository. For example 169 Bioconductor packages have external dependencies listed in their System Requirements field (often with these packages having several requirements) [03 September, 2020].
## Warning in knitr::include_graphics(system.file("extdata/pkg_deps_bar_mask-1.png", : It is highly
## recommended to use relative paths for images. You had absolute paths: "F:/biocbuild/bbs-3.15-bioc/
## tmpdir/Rtmpu0eOof/Rinst27fc645e3c2f/Herper/extdata/pkg_deps_bar_mask-1.png"
Herper provides an ad-hoc approach to handling external system requirements for R packages. For people developing packages with python conda dependencies we recommend using basilisk to internally support these system requirements pre-hoc.
The Herper package was developed by Matt Paul, Doug Barrows and Thomas Carroll at the Rockefeller University Bioinformatics Resources Center with contributions from Kathryn Rozen-Gagnon.
Use the BiocManager
package to download and install the package from our Github repository:
if (!requireNamespace("BiocManager", quietly = TRUE)) {
install.packages("BiocManager")
}
BiocManager::install("Herper")
Once installed, load it into your R session:
library(Herper)
The install_CondaTools() function allows the user to specify required Conda software and the desired environment to install into.
Miniconda is installed as part of the process (by default into the r-reticulate’s default Conda location - C:/Users/biocbuild/AppData/Local/r-miniconda) and the user’s requested conda environment built within the same directory (by default C:/Users/biocbuild/AppData/Local/r-miniconda/envs/USERS_ENVIRONMENT_HERE).
If you already have Miniconda installed or you would like to install to a custom location, you can specify the path with the pathToMiniConda parameter. In this example we are installing in a temporary directory, but most likely you will want to install/use a stable version of Miniconda.
myMiniconda <- file.path(tempdir2(), "Test")
myMiniconda
## [1] "F:/biocbuild/bbs-3.15-bioc/tmpdir/RtmpUfqPeD/rr/Test"
install_CondaTools("samtools", "herper", pathToMiniConda = myMiniconda)
## Warning in system(paste(pathToConda, "search --quiet --json", package_input, : running command
## 'F:/biocbuild/bbs-3.15-bioc/tmpdir/RtmpUfqPeD/rr/Test/condabin/conda.bat search --quiet --json
## "samtools" -c bioconda -c defaults -c conda-forge' had status 1
## NULL
We can add additional tools to our Conda environment by specifying updateEnv = TRUE. A vector of tools can be used to install several at once.
pathToConda <- install_CondaTools(c("salmon", "kallisto"), "herper", updateEnv = TRUE, pathToMiniConda = myMiniconda)
## Warning in system(paste(pathToConda, "search --quiet --json", package_input, : running command 'F:/
## biocbuild/bbs-3.15-bioc/tmpdir/RtmpUfqPeD/rr/Test/condabin/conda.bat search --quiet --json "salmon"
## -c bioconda -c defaults -c conda-forge' had status 1
pathToConda
## NULL
Specific package versions can be installed using conda formatted inputs into the tools argument i.e. “salmon==1.3”, “salmon>=1.3” or “salmon<=1.3”. This can also be used to specifically upgrade or downgrade existing tools in the chosen environment.
pathToConda <- install_CondaTools("salmon<=1.3", "herper", updateEnv = TRUE, pathToMiniConda = myMiniconda)
## Warning in system(paste(pathToConda, "search --quiet --json", package_input, : running command 'F:/
## biocbuild/bbs-3.15-bioc/tmpdir/RtmpUfqPeD/rr/Test/condabin/conda.bat search --quiet --json "salmon"
## -c bioconda -c defaults -c conda-forge' had status 1
The install_CondaSysReqs checks the System Requirements for the specified R package, and uses Conda to install this software. Here we will use a test package contained within Herper. This test package has two System Requirements:
testPkg <- system.file("extdata/HerperTestPkg", package = "Herper")
install.packages(testPkg, type = "source", repos = NULL)
utils::packageDescription("HerperTestPkg", fields = "SystemRequirements")
## [1] "samtools==1.10, rmats>=v4.1.0"
The user can simply supply the name of an installed R package, and install_CondaSysReqs will install the System Requirements through conda.
install_CondaSysReqs("HerperTestPkg", pathToMiniConda = myMiniconda)
## Warning in system(paste(pathToConda, "search --quiet --json", package_input, : running command
## 'F:/biocbuild/bbs-3.15-bioc/tmpdir/RtmpUfqPeD/rr/Test/condabin/conda.bat search --quiet --json
## "samtools" -c bioconda -c defaults -c conda-forge' had status 1
## NULL
By default these packages are installed in a new environment, which has the name name of the R package and its version number. Users can control the environment name using the env parameter. As with install_CondaTools(), user can control which version of Miniconda with the parameter pathToMiniConda, and whether they want to amend an existing environment with the parameter updateEnv.
Note: install_CondaSysReqs can handle standard System Requirement formats, but will not work if the package has free form text. In this case just use install_CondaTools
Once installed within a conda environment, many external software can be executed directly from the conda environment’s bin directory without having to perform any additional actions.
pathToSamtools <- file.path(pathToConda$pathToEnvBin,"samtools")
Res <- system2(command=pathToSamtools, args = "help",stdout = TRUE)
Res
Some external software however require additional environmental variable to be set in order to execute correctly. An example of this would be Cytoscape which requires the java home directory and java library paths to be set prior to its execution.
The Herper package uses the withr family of functions (with_CondaEnv() and local_CondaEnv()) to provide methods to temporarily alter the system PATH and to add or update any required environmental variables. This is done without formally activating your environment or initializing your conda.
The with_CondaEnv allows users to run R code with the required PATH and environmental variables automatically set. The with_CondaEnv function simply requires the name of conda environment and the code to be executed within this environment. Additionally we can also the pathToMiniconda argument to specify any custom miniconda install location.
The with_CondaEnv function will update the PATH we can now run the above samtools command without specifying the full directory path to samtools.
res <- with_CondaEnv("herper",
system2(command="samtools",args = "help",stdout = TRUE),
pathToMiniConda=myMiniconda)
res
The local_CondaEnv function acts in a similar fashion to the with_CondaEnv function and allows the user to temporarily update the required PATH and environmental variable from within a function. The PATH and environmental variables will be modified only until the current function ends.
local_CondaEnv is best used within a user-created function, allowing access to the Conda environment’s PATH and variables from within the the function itself but resetting all environmental variables once complete.
samtoolsHelp <- function(){
local_CondaEnv("herper", pathToMiniConda=myMiniconda)
helpMessage <- system2(command="samtools",args = "help",stdout = TRUE)
helpMessage
}
samtoolsHelp()
To further demonstrate this we will use the first command from the seqCNA vignette. This step requires samtools. If this is not installed and available there is an error.
library(seqCNA)
data(seqsumm_HCC1143)
try(rco <- readSeqsumm(tumour.data = seqsumm_HCC1143), silent = FALSE)
Samtools is listed as a System Requirement for seqCNA, so we can first use install_CondaSysReqs() to install samtools. In this case we are installing samtools in the environment: seqCNA_env. We can then run the seqCNA command using with_CondaEnv specifying that we want to use our environment containing samtools. seqCNA can then find samtools and execute successfully.
install_CondaSysReqs(pkg="seqCNA",env="seqCNA_env",pathToMiniConda=myMiniconda)
rco <- with_CondaEnv(new="seqCNA_env",readSeqsumm(tumour.data=seqsumm_HCC1143)
,pathToMiniConda = myMiniconda)
summary(rco)
If the user is unsure of the exact name, or version of a tool available on conda, they can use the conda_search function.
conda_search("salmon", pathToMiniConda = myMiniconda)
## Warning in system(paste(pathToConda, "search --quiet --json", package_input, : running command 'F:/
## biocbuild/bbs-3.15-bioc/tmpdir/RtmpUfqPeD/rr/Test/condabin/conda.bat search --quiet --json "salmon"
## -c bioconda -c defaults -c conda-forge' had status 1
## Warning in conda_search("salmon", pathToMiniConda = myMiniconda): package salmon not found
## [1] FALSE
Specific package versions can be searched for using the conda format i.e. “salmon==1.3”, “salmon>=1.3” or “salmon<=1.3”. Searches will also find close matches for incorrect queries. Channels to search in can be controlled with channels parameter.
conda_search("salmon<=1.0", pathToMiniConda = myMiniconda)
## Warning in system(paste(pathToConda, "search --quiet --json", package_input, : running command 'F:/
## biocbuild/bbs-3.15-bioc/tmpdir/RtmpUfqPeD/rr/Test/condabin/conda.bat search --quiet --json "salmon"
## -c bioconda -c defaults -c conda-forge' had status 1
## Warning in conda_search("salmon<=1.0", pathToMiniConda = myMiniconda): package salmon<=1.0 not found
## [1] FALSE
conda_search("salmo", pathToMiniConda = myMiniconda)
## Warning in system(paste(pathToConda, "search --quiet --json", package_input, : running command 'F:/
## biocbuild/bbs-3.15-bioc/tmpdir/RtmpUfqPeD/rr/Test/condabin/conda.bat search --quiet --json "salmo"
## -c bioconda -c defaults -c conda-forge' had status 1
## Warning in conda_search("salmo", pathToMiniConda = myMiniconda): package salmo not found
## [1] FALSE
The export_CondaEnv function allows the user to export the environment information to a .yml file. These environment YAML files contain all essential information about the package, allowing for reproducibility and easy distribution of Conda system configuration for collaboration.
yml_name <- paste0("herper_", format(Sys.Date(), "%Y%m%d"), ".yml")
export_CondaEnv("herper", yml_name, pathToMiniConda = myMiniconda)
## Warning in system(paste(pathToConda, "env export -n", env_name, ">", export_path)): 'F:/biocbuild/
## bbs-3.15-bioc/tmpdir/RtmpUfqPeD/rr/Test/bin/conda' not found
## [1] "herper_20220426.yml"
The YAML export will contain all packages in the environment by default. If the user wants to only export the packages that were specifically installed and not their dependencies they can use the depends paramter.
yml_name <- paste0("herper_nodeps_", format(Sys.Date(), "%Y%m%d"), ".yml")
export_CondaEnv("herper", yml_name, depends = FALSE, pathToMiniConda = myMiniconda)
## Warning in system(paste(pathToConda, "env export --from-history -n", env_name, : 'F:/biocbuild/
## bbs-3.15-bioc/tmpdir/RtmpUfqPeD/rr/Test/bin/conda' not found
## [1] "herper_nodeps_20220426.yml"
The import_CondaEnv function allows the user to create a new conda environment from a .yml file. These can be previously exported from export_CondaEnv, conda, renv or manually created.
Users can simply provide a path to the YAML file for import. They can also specify the environment name, but by default the name will be taken from the YAML.
testYML <- system.file("extdata/test.yml",package="Herper")
import_CondaEnv(yml_import=testYML, pathToMiniConda = myMiniconda)
The list_CondaEnv function allows users to check what environments already exist within the given conda build.
If the User is using multiple builds of conda and wants to check environments across all them, they can include the parameter allCondas = TRUE.
list_CondaEnv(pathToMiniConda = myMiniconda)
## [1] conda path env
## <0 rows> (or 0-length row.names)
The list_CondaPkgs function allows users to check what packages are installed in a given environment.
list_CondaPkgs("my_test", pathToMiniConda = myMiniconda)
## name version channel platform
## 1 brotli 1.0.9 conda-forge win-64
## 2 brotli-bin 1.0.9 conda-forge win-64
## 3 brotlipy 0.7.0 conda-forge win-64
## 4 bzip2 1.0.8 conda-forge win-64
## 5 ca-certificates 2021.10.8 conda-forge win-64
## 6 certifi 2021.10.8 conda-forge win-64
## 7 cffi 1.15.0 conda-forge win-64
## 8 charset-normalizer 2.0.12 conda-forge noarch
## 9 click 8.1.2 conda-forge win-64
## 10 colorama 0.4.4 conda-forge noarch
## 11 coloredlogs 15.0.1 conda-forge noarch
## 12 colormath 3.0.0 conda-forge noarch
## 13 cryptography 36.0.2 conda-forge win-64
## 14 cycler 0.11.0 conda-forge noarch
## 15 fonttools 4.33.2 conda-forge win-64
## 16 freetype 2.10.4 conda-forge win-64
## 17 future 0.18.2 conda-forge win-64
## 18 humanfriendly 10.0 conda-forge win-64
## 19 idna 3.3 conda-forge noarch
## 20 importlib-metadata 4.11.3 conda-forge win-64
## 21 intel-openmp 2022.0.0 conda-forge win-64
## 22 jbig 2.1 conda-forge win-64
## 23 jinja2 3.1.1 conda-forge noarch
## 24 jpeg 9e conda-forge win-64
## 25 kiwisolver 1.4.2 conda-forge win-64
## 26 lcms2 2.12 conda-forge win-64
## 27 lerc 3.0 conda-forge win-64
## 28 libblas 3.9.0 conda-forge win-64
## 29 libbrotlicommon 1.0.9 conda-forge win-64
## 30 libbrotlidec 1.0.9 conda-forge win-64
## 31 libbrotlienc 1.0.9 conda-forge win-64
## 32 libcblas 3.9.0 conda-forge win-64
## 33 libdeflate 1.10 conda-forge win-64
## 34 libffi 3.4.2 conda-forge win-64
## 35 liblapack 3.9.0 conda-forge win-64
## 36 libpng 1.6.37 conda-forge win-64
## 37 libtiff 4.3.0 conda-forge win-64
## 38 libwebp 1.2.2 conda-forge win-64
## 39 libwebp-base 1.2.2 conda-forge win-64
## 40 libxcb 1.13 conda-forge win-64
## 41 libzlib 1.2.11 conda-forge win-64
## 42 lz4-c 1.9.3 conda-forge win-64
## 43 lzstring 1.0.4 conda-forge noarch
## 44 m2w64-gcc-libgfortran 5.3.0 conda-forge win-64
## 45 m2w64-gcc-libs 5.3.0 conda-forge win-64
## 46 m2w64-gcc-libs-core 5.3.0 conda-forge win-64
## 47 m2w64-gmp 6.1.0 conda-forge win-64
## 48 m2w64-libwinpthread-git 5.0.0.4634.697f757 conda-forge win-64
## 49 markdown 3.3.6 conda-forge noarch
## 50 markupsafe 2.1.1 conda-forge win-64
## 51 matplotlib-base 3.5.1 conda-forge win-64
## 52 mkl 2022.0.0 conda-forge win-64
## 53 msys2-conda-epoch 20160418 conda-forge win-64
## 54 multiqc 1.9 bioconda noarch
## 55 munkres 1.0.7 bioconda noarch
## 56 networkx 2.8 conda-forge noarch
## 57 numpy 1.22.3 conda-forge win-64
## 58 openjpeg 2.4.0 conda-forge win-64
## 59 openssl 1.1.1n conda-forge win-64
## 60 packaging 21.3 conda-forge noarch
## 61 pandas 1.4.2 conda-forge win-64
## 62 pillow 9.1.0 conda-forge win-64
## 63 pip 22.0.4 conda-forge noarch
## 64 pthread-stubs 0.4 conda-forge win-64
## 65 pycparser 2.21 conda-forge noarch
## 66 pyopenssl 22.0.0 conda-forge noarch
## 67 pyparsing 3.0.8 conda-forge noarch
## 68 pyreadline3 3.4.1 conda-forge win-64
## 69 pysocks 1.7.1 conda-forge win-64
## 70 python 3.10.4 conda-forge win-64
## 71 python-dateutil 2.8.2 conda-forge noarch
## 72 python_abi 3.10 conda-forge win-64
## 73 pytz 2022.1 conda-forge noarch
## 74 pyyaml 6.0 conda-forge win-64
## 75 requests 2.27.1 conda-forge noarch
## 76 scipy 1.8.0 conda-forge win-64
## 77 setuptools 62.1.0 conda-forge win-64
## 78 simplejson 3.17.6 conda-forge win-64
## 79 six 1.16.0 conda-forge noarch
## 80 spectra 0.0.11 conda-forge noarch
## 81 sqlite 3.38.2 conda-forge win-64
## 82 tbb 2021.5.0 conda-forge win-64
## 83 tk 8.6.12 conda-forge win-64
## 84 tzdata 2022a conda-forge noarch
## 85 ucrt 10.0.20348.0 conda-forge win-64
## 86 unicodedata2 14.0.0 conda-forge win-64
## 87 urllib3 1.26.9 conda-forge noarch
## 88 vc 14.2 conda-forge win-64
## 89 vs2015_runtime 14.29.30037 conda-forge win-64
## 90 wheel 0.37.1 conda-forge noarch
## 91 win_inet_pton 1.1.0 conda-forge win-64
## 92 xorg-libxau 1.0.9 conda-forge win-64
## 93 xorg-libxdmcp 1.1.3 conda-forge win-64
## 94 xz 5.2.5 conda-forge win-64
## 95 yaml 0.2.5 conda-forge win-64
## 96 zipp 3.8.0 conda-forge noarch
## 97 zlib 1.2.11 conda-forge win-64
## 98 zstd 1.5.2 conda-forge win-64
Thank you to Ji-Dung Luo and Wei Wang for testing/vignette review/critical feedback and Ziwei Liang for their support.
sessionInfo()
## R version 4.2.0 RC (2022-04-19 r82224 ucrt)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows Server x64 (build 20348)
##
## Matrix products: default
##
## locale:
## [1] LC_COLLATE=C LC_CTYPE=English_United States.utf8
## [3] LC_MONETARY=English_United States.utf8 LC_NUMERIC=C
## [5] LC_TIME=English_United States.utf8
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] seqCNA_1.42.0 seqCNA.annot_1.31.0 adehabitatLT_0.3.25 CircStats_0.2-6
## [5] boot_1.3-28 MASS_7.3-57 adehabitatMA_0.3.14 ade4_1.7-19
## [9] sp_1.4-7 doSNOW_1.0.20 snow_0.4-4 iterators_1.0.14
## [13] foreach_1.5.2 GLAD_2.60.0 Herper_1.6.0 reticulate_1.24
## [17] BiocStyle_2.24.0
##
## loaded via a namespace (and not attached):
## [1] Rcpp_1.0.8.3 bslib_0.3.1 compiler_4.2.0 BiocManager_1.30.17
## [5] jquerylib_0.1.4 highr_0.9 tools_4.2.0 digest_0.6.29
## [9] jsonlite_1.8.0 evaluate_0.15 lattice_0.20-45 png_0.1-7
## [13] rlang_1.0.2 Matrix_1.4-1 cli_3.3.0 parallel_4.2.0
## [17] yaml_2.3.5 xfun_0.30 fastmap_1.1.0 withr_2.5.0
## [21] stringr_1.4.0 knitr_1.38 sass_0.4.1 rappdirs_0.3.3
## [25] grid_4.2.0 R6_2.5.1 rmarkdown_2.14 bookdown_0.26
## [29] magrittr_2.0.3 codetools_0.2-18 htmltools_0.5.2 stringi_1.7.6
## [33] rjson_0.2.21