From ed69041b96b3976b5296ddc38ada3ff480b7a01e Mon Sep 17 00:00:00 2001 From: Vedran Kasalica Date: Mon, 10 Mar 2025 11:26:35 +0100 Subject: [PATCH 1/2] Add documentation for the R-based tools --- .../domain-expert-guide/adding-tools.rst | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/docs/source/domain-expert-guide/adding-tools.rst b/docs/source/domain-expert-guide/adding-tools.rst index 081e7ec..1635a23 100644 --- a/docs/source/domain-expert-guide/adding-tools.rst +++ b/docs/source/domain-expert-guide/adding-tools.rst @@ -99,8 +99,25 @@ The CWL file essentially describes one step from a workflow and we want to try w cwltool --validate path/to/cwlfile.cwl +Adding a library as a tool +========================== -1. Create a workflow --------------------- +Sometimes a tool is not a standalone executable, but a library for a programming language. In this case, the tool can be wrapped in a script that calls the library. These can be R, Python, Java, or any other language. The script should be able to run the library with the correct arguments and produce the expected output. The script can be run in a docker container that contains the required library, environment, and dependencies. The CWL file should then call the script in the same way as a standalone executable. + + +Creating an R-based tool +------------------------- + +1. Create the executable R script +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + +2. Pick a base image +~~~~~~~~~~~~~~~~~~~~ + +3. Test the tool +~~~~~~~~~~~~~~~~ + +4. Write the CWL file +~~~~~~~~~~~~~~~~~~~~~ -Create a workflow using the tool and test whether it runs. From faf1def2fdc05a68f956447bf67458e69fab19ca Mon Sep 17 00:00:00 2001 From: Zhao Date: Mon, 10 Mar 2025 12:26:57 +0100 Subject: [PATCH 2/2] Add r-based tool docs --- docs/source/domain-expert-guide/adding-tools.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/source/domain-expert-guide/adding-tools.rst b/docs/source/domain-expert-guide/adding-tools.rst index 1635a23..8e30c83 100644 --- a/docs/source/domain-expert-guide/adding-tools.rst +++ b/docs/source/domain-expert-guide/adding-tools.rst @@ -111,13 +111,29 @@ Creating an R-based tool 1. Create the executable R script ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Since many R packages only provide function calls, write a simple R script(e.g., run_mytool.R) +that accepts command-line arguments(via commandArgs(trailingOnly = TRUE)) and then calls the package's functions. +Set this script as an executable in the Dockerfile and optionally specify it under ENTRYPOINT. 2. Pick a base image ~~~~~~~~~~~~~~~~~~~~ +A common choice is the rocker family(e.g., rocker/r-base:4.2.0), which ensures a functional +R environment. + +First, we suggest finding containers in biocontainers or docker hub. If there is no container for +your tool, creating a dockerfile is needed. In your Dockerfile, use ``apt-get install`` for +system libraries(e.g., libxml2-dev) and ``R -e"install.packages(...)"`` or ``BiocManager::install(...)`` +for R packages. + 3. Test the tool ~~~~~~~~~~~~~~~~ +Launch the container in interactive mode by ``docker run -it ...`` to ensure the R script +runs correctly and that all libraries are installed. + 4. Write the CWL file ~~~~~~~~~~~~~~~~~~~~~ +In the `` baseCommand``, refer to ["Rscript", "/path/to/run_script.R"]. Define your inputs +and outputs according to the script's parameters. \ No newline at end of file