diff --git a/singularity/Makefile b/singularity/Makefile index 33ec860442bfa3bcb62ee98df7e292546941c404..e8eb4bdbb773005e090ce6ea57f9c75aa9b66499 100644 --- a/singularity/Makefile +++ b/singularity/Makefile @@ -10,11 +10,13 @@ endif all: run_pipeline -install: run_pipeline run_pipeline.sh workflows_shell.sh +install: run_pipeline run_pipeline.sh workflows_shell.sh wrap_in_container.sh cluster_config.json sudo install -d $(PREFIX)_$(VERSION)/bin sudo install run_pipeline $(PREFIX)_$(VERSION)/bin/. sudo install run_pipeline.sh $(PREFIX)_$(VERSION)/bin/. sudo install workflows_shell.sh $(PREFIX)_$(VERSION)/bin/. + sudo install wrap_in_container.sh $(PREFIX)_$(VERSION)/bin/. + sudo install cluster_config.json $(PREFIX)_$(VERSION)/bin/. for datatype in sRNA-seq small_RNA-seq RNA-seq GRO-seq PRO-seq Degradome-seq Ribo-seq iCLIP-seq iCLIP; \ do \ sudo ln -sf $(PREFIX)_$(VERSION)/bin/run_pipeline.sh $(PREFIX)_$(VERSION)/bin/run_$${datatype}_pipeline; \ @@ -22,11 +24,13 @@ install: run_pipeline run_pipeline.sh workflows_shell.sh sudo ln -sfn $(PREFIX)_$(VERSION) $(PREFIX) # To test before replacing "prod" version in $(PREFIX) -install_test: run_pipeline run_pipeline.sh workflows_shell.sh +install_test: run_pipeline run_pipeline.sh workflows_shell.sh wrap_in_container.sh cluster_config.json sudo install -d $(TEST_PREFIX)_$(VERSION)/bin sudo install run_pipeline $(TEST_PREFIX)_$(VERSION)/bin/. sudo install run_pipeline.sh $(TEST_PREFIX)_$(VERSION)/bin/. sudo install workflows_shell.sh $(TEST_PREFIX)_$(VERSION)/bin/. + sudo install wrap_in_container.sh $(TEST_PREFIX)_$(VERSION)/bin/. + sudo install cluster_config.json $(TEST_PREFIX)_$(VERSION)/bin/. for datatype in sRNA-seq small_RNA-seq RNA-seq GRO-seq PRO-seq Degradome-seq Ribo-seq iCLIP-seq iCLIP; \ do \ sudo ln -sf $(TEST_PREFIX)_$(VERSION)/bin/run_pipeline.sh $(TEST_PREFIX)_$(VERSION)/bin/run_$${datatype}_pipeline; \ diff --git a/singularity/cluster_config.json b/singularity/cluster_config.json new file mode 100644 index 0000000000000000000000000000000000000000..b7014c4812e94b8a97d5896063534d13d6ff6e8b --- /dev/null +++ b/singularity/cluster_config.json @@ -0,0 +1,52 @@ +{ + "__default__" : + { + "ram" : "20G" + }, + "multiqc" : + { + "ram" : "20G" + }, + "star_mapping_pass1" : + { + "ram" : "32G" + }, + "star_mapping_pass2" : + { + "ram" : "50G" + }, + "star_index" : + { + "ram" : "60G" + }, + + "bowtie2" : + { + "ram" : "30G" + }, + + "bowtie2_index" : + { + "ram" : "60G" + }, + "kallisto_quant" : + { + "ram" : "30G" + }, + + "kallisto_index" : + { + "ram" : "60G" + }, + + "minimap2" : + { + "ram" : "30G" + }, + + "mark_duplicates": + { + "ram" : "30G" + } + +} diff --git a/singularity/run_pipeline.sh b/singularity/run_pipeline.sh index 653e90323c32ec45835346aa26fae58632fe79b5..ac4eb56f5f32c28ecd21394c1e23cd119edadd64 100755 --- a/singularity/run_pipeline.sh +++ b/singularity/run_pipeline.sh @@ -54,6 +54,8 @@ SCRIPT=$(readlink -f "${0}") # Absolute path this script is in BASEDIR=$(dirname "${SCRIPT}") container="${BASEDIR}/run_pipeline" +wrapper="${BASEDIR}/wrap_in_container.sh" +cluster_config="${BASEDIR}/cluster_config.json" # Do we have singularity? @@ -72,6 +74,16 @@ then fi fi +if [ ! -e ${wrapper} ] +then + error_exit "The wrapper script ${wrapper} was not found." +fi + +if [ ! -e ${cluster_config} ] +then + error_exit "The cluster configuration ${cluster_config} was not found." +fi + if [ ! -e ${container} ] then if [ -e ${BASEDIR}/run_pipeline.def ] @@ -79,7 +91,7 @@ then echo "The container was not found. Trying to build it. This may take quite some time and requires sudoer's rights." sudo singularity build ${BASEDIR}/run_pipeline ${BASEDIR}/run_pipeline.def || error_exit "The container could not be built." else - error_exit "The container was not found, nor a definition file to build it." + error_exit "The container ${container} was not found, nor a definition file to build it." fi fi @@ -98,9 +110,11 @@ fi [[ ${QOS} ]] || QOS="normal" [[ ${PART} ]] || PART="common" +cluster_opts="--cluster \\\'sbatch --mem={cluster.ram} --cpus-per-task={threads} --job-name={rule}-{wildcards} --qos=${QOS} --part=${PART} ${wrapper} ${container}\\\' --cluster-config ${cluster_config}" #cluster_opts="--cores 20 --cluster \'sbatch --mem={cluster.ram} --cpus-per-task={threads} --job-name={rule}-{wildcards} --qos=${QOS} --part=${PART} --mpi=none\' -j 300" #cmd="APPTAINERENV_USER=${USER} apptainer run --cleanenv -B /opt/hpc/slurm -B /var/run/munge -B /pasteur ${container} ${PROGNAME} ${pipeline_config} ${cluster_opts} --cluster-config ${cluster_config}" -cmd="APPTAINERENV_USER=${USER} apptainer run --cleanenv -B /opt/hpc/slurm -B /var/run/munge -B /pasteur ${container} ${PROGNAME} $@" +#cmd="APPTAINERENV_USER=${USER} apptainer run --cleanenv -B /opt/hpc/slurm -B /var/run/munge -B /pasteur ${container} ${PROGNAME} $@" +cmd="APPTAINERENV_USER=${USER} apptainer run -B /opt/hpc/slurm -B /var/run/munge -B /pasteur ${container} ${PROGNAME} $@ ${cluster_opts}" # This script can be called from various symbolic links. # The name of the link determines which snakefile to use. @@ -112,4 +126,7 @@ cmd="APPTAINERENV_USER=${USER} apptainer run --cleanenv -B /opt/hpc/slurm -B /va # so that it finds the Genome configuration and gene lists # that are expected to be in a specific location there. # singularity run -B /pasteur -B /run/shm:/run/shm ${container} ${PROGNAME} $@ -[[ $(hostname) = "pisa" ]] && SINGULARITYENV_USER=${USER} singularity run --cleanenv -B /pasteur -B /run/shm:/run/shm ${container} ${PROGNAME} $@ || sbatch --qos=${QOS} --part=${PART} --wrap="${cmd}" +#[[ $(hostname) = "pisa" ]] && SINGULARITYENV_USER=${USER} singularity run --cleanenv -B /pasteur -B /run/shm:/run/shm ${container} ${PROGNAME} $@ || sbatch --qos=${QOS} --part=${PART} --wrap="${cmd}" +[[ $(hostname) = "pisa" ]] && SINGULARITYENV_USER=${USER} singularity run -B /pasteur -B /run/shm:/run/shm ${container} ${PROGNAME} $@ || sbatch --qos=${QOS} --part=${PART} --wrap="${cmd}" + +exit 0 diff --git a/singularity/wrap_in_container.sh b/singularity/wrap_in_container.sh new file mode 100755 index 0000000000000000000000000000000000000000..a05a8ed0445ba0baa94a29dfdef3f76d91c42075 --- /dev/null +++ b/singularity/wrap_in_container.sh @@ -0,0 +1,76 @@ +#!/bin/bash -l +# Copyright (C) 2024 Blaise Li +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +# http://linuxcommand.org/wss0150.php +PROGNAME=$(basename "${0}") + +function error_exit +{ +# ---------------------------------------------------------------- +# Function for exit due to fatal program error +# Accepts 1 argument: +# string containing descriptive error message +# ---------------------------------------------------------------- + echo "${PROGNAME}: ${1:-"Unknown Error"}" 1>&2 + exit 1 +} + +# https://stackoverflow.com/a/1638397/1878788 +# Absolute path to this script +SCRIPT=$(readlink -f "${0}") +# Absolute path this script is in +BASEDIR=$(dirname "${SCRIPT}") +#container="${BASEDIR}/run_pipeline" +container=${1} +shift + +echo "(${PROGNAME}) BASEDIR: ${BASEDIR}" +echo "(${PROGNAME}) container: ${container}" + +# Do we have singularity? +apptainer --version 2> /dev/null && have_singularity=1 + +if [ ! ${have_singularity} ] +then + install_doc="https://sylabs.io/guides/3.4/user-guide/quick_start.html#quick-installation-steps" + # Do we have an environment modules system? + module --version 2> /dev/null && have_modules=1 + if [ ${have_modules} ] + then + module load apptainer || error_exit "singularity is needed to run the pipelines (see ${install_doc})" + else + error_exit "singularity is needed to run the pipelines (see ${install_doc})" + fi +fi + +echo "${PROGNAME} found apptainer" + +if [ ! -e ${container} ] +then + if [ -e ${BASEDIR}/run_pipeline.def ] + then + echo "The container was not found. Trying to build it. This may take quite some time and requires sudoer's rights." + apptainer build ${BASEDIR}/run_pipeline ${BASEDIR}/run_pipeline.def || error_exit "The container could not be built." + else + error_exit "The container was not found, nor a definition file to build it." + fi +fi + +echo "${PROGNAME} found ${container}" + +APPTAINERENV_USER=${USER} apptainer exec -B /pasteur ${container} $@ + +exit 0