-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_snakemake.sh
146 lines (124 loc) · 4.16 KB
/
run_snakemake.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
set -eo pipefail
module purge
# Check if the required arguments are provided
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <RUNMODE> <WORKDIR>"
exit 1
fi
# Set input arguments
RUNMODE=$1
WORKDIR=$2
ENTRY=$3
# Ensure RUNMODE is provided
if [ -z "$RUNMODE" ]; then
echo "RUNMODE argument is missing"
exit 1
fi
# Ensure WORKDIR is provided and exists
if [ -z "$WORKDIR" ]; then
echo "WORKDIR argument is missing"
exit 1
elif [ ! -d "$WORKDIR" ]; then
echo "WORKDIR does not exist: $WORKDIR"
exit 1
fi
echo "RUNMODE: $RUNMODE"
echo "WORKDIR: $WORKDIR"
# Set variables
PIPELINE_HOME=$(readlink -f "$(dirname "$0")")
SNAKEFILE="${PIPELINE_HOME}/workflow/Snakefile"
PARTITIONS="norm,ccr"
PYTHON_VERSION="python/3.9"
SNAKEMAKE_VERSION="snakemake/7.32.3"
SINGULARITY_VERSION="singularity/3.10.5"
# Load necessary modules
module load "$SNAKEMAKE_VERSION"
# Define essential files and folders
ESSENTIAL_CONFIGS="config/config.yaml config/fqscreen_config.conf config/multiqc_config.yaml config/cluster.yaml config/tools.yaml"
ESSENTIAL_MANIFESTS="manifest/sample_manifest.csv"
ESSENTIAL_FOLDERS="workflow/scripts"
# Initialize workdir if RUNMODE is "init"
##if [ "$RUNMODE" == "init" ]; then
## init
## elif
if [ "$RUNMODE" == "local" ]; then
# Run Snakemake locally
echo "local mode"
echo "test mode"
snakemake -s "$SNAKEFILE" \
--directory "$WORKDIR" \
--printshellcmds \
--use-singularity \
--use-envmodules \
--jobs 1 \
--latency-wait 90000 -j 1 \
--configfile "${WORKDIR}/config/config.yaml" \
--cores all \
--stats "${WORKDIR}/logs/snakemake.stats" \
2>&1 | tee "${WORKDIR}/logs/snakemake.log"
echo "call mode"
# Generate report if successful
if [ "$?" -eq "0" ]; then
snakemake -s "$SNAKEFILE" \
--report "${WORKDIR}/logs/runlocal_snakemake_report.html" \
--directory "$WORKDIR" \
--configfile "${WORKDIR}/config/config.yaml"
fi
elif [ "$RUNMODE" == "slurm" ]; then
cat > "${WORKDIR}/submit_script.sbatch" << EOF
#!/bin/bash
#SBATCH --job-name="SNAKEMAKETEST"
#SBATCH --mem=40g
#SBATCH --partition="$PARTITIONS"
#SBATCH --time=05-00:00:00
#SBATCH --cpus-per-task=2
#SBATCH --ntasks=1
module load $PYTHON_VERSION
module load $SNAKEMAKE_VERSION
module load $SINGULARITY_VERSION
cd \$SLURM_SUBMIT_DIR
snakemake -s "$SNAKEFILE" \
--directory "$WORKDIR" \
--use-singularity \
--use-envmodules \
--printshellcmds \
--latency-wait 90000 \
--jobs 1 \
--configfile "${PIPELINE_HOME}/config/config.yaml" \
--cluster-config "${PIPELINE_HOME}/config/cluster.yaml" \
--cluster "sbatch --gres {cluster.gres} --cpus-per-task {cluster.threads} -p {cluster.partition} -t {cluster.time} --mem {cluster.mem} --job-name {cluster.name} --output {cluster.output} --error {cluster.error}" \
-j 1 \
--rerun-incomplete \
--keep-going \
--restart-times 1 \
--stats "${WORKDIR}/logs/snakemake.stats" \
2>&1 | tee "${WORKDIR}/logs/snakemake.log"
if [ "\$?" -eq "0" ]; then
snakemake -s "$SNAKEFILE" \
--directory "$WORKDIR" \
--report "${WORKDIR}/logs/runslurm_snakemake_report.html" \
--configfile "${PIPELINE_HOME}/config/config.yaml"
fi
bash <(curl https://raw.githubusercontent.com/CCBR/Tools/master/Biowulf/gather_cluster_stats.sh 2>/dev/null) "${WORKDIR}/logs/snakemake.log" > "${WORKDIR}/logs/snakemake.log.HPC_summary.txt"
EOF
sbatch "${WORKDIR}/submit_script.sbatch"
else
# Run Snakemake for unlock and dryrun modes
echo "--$RUNMODE"
snakemake -s "$SNAKEFILE" \
"--$RUNMODE" \
--directory "$WORKDIR" \
--use-envmodules \
--printshellcmds \
--latency-wait 120 \
--jobs 1 \
--configfile "${PIPELINE_HOME}/config/config.yaml" \
--cluster-config "${PIPELINE_HOME}/config/cluster.yaml" \
--cluster "sbatch --gres {cluster.gres} --cpus-per-task {cluster.threads} -p {cluster.partition} -t {cluster.time} --mem {cluster.mem} --job-name {cluster.name} --output {cluster.output} --error {cluster.error}" \
-j 1 \
--rerun-incomplete \
--keep-going \
--touch \
--stats "${WORKDIR}/logs/snakemake.stats"
fi