-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_nextflow_wes.sh
executable file
·107 lines (89 loc) · 2.79 KB
/
run_nextflow_wes.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
#!/bin/bash
set -euo pipefail
workflow_path='/hpc/diaggen/software/production/DxNextflowWES'
# Set input and output dirs
input=`realpath -e $1`
output=`realpath $2`
email=$3
optional_params=( "${@:4}" )
mkdir -p $output && cd $output
mkdir -p log
if ! { [ -f 'workflow.running' ] || [ -f 'workflow.done' ] || [ -f 'workflow.failed' ]; }; then
touch workflow.running
output_log="${output}/log"
file="${output_log}/nextflow_trace.txt"
# Check if nextflow_trace.txt exists
if [ -e "${file}" ]; then
current_suffix=0
# Get a list of all trace files WITH a suffix
trace_file_list=$(ls "${output_log}"/nextflow_trace*.txt 2> /dev/null)
# Check if any trace files with a suffix exist
if [ "$?" -eq 0 ]; then
# Check for each trace file with a suffix if the suffix is the highest and save that one as the current suffix
for trace_file in ${trace_file_list}; do
basename_trace_file=$(basename "${trace_file}")
if echo "${basename_trace_file}" | grep -qE '[0-9]+'; then
suffix=$(echo "${basename_trace_file}" | grep -oE '[0-9]+')
else
suffix=0
fi
if [ "${suffix}" -gt "${current_suffix}" ]; then
current_suffix=${suffix}
fi
done
fi
# Increment the suffix
new_suffix=$((current_suffix + 1))
# Create the new file name with the incremented suffix
new_file="${file%.*}_$new_suffix.${file##*.}"
# Rename the file
mv "${file}" "${new_file}"
fi
sbatch <<EOT
#!/bin/bash
#SBATCH --time=36:00:00
#SBATCH --nodes=1
#SBATCH --mem 5G
#SBATCH --gres=tmpspace:10G
#SBATCH --job-name Nextflow_WES
#SBATCH -o log/slurm_nextflow_wes.%j.out
#SBATCH -e log/slurm_nextflow_wes.%j.err
#SBATCH --mail-user $email
#SBATCH --mail-type FAIL
#SBATCH --export=NONE
#SBATCH --account=diaggen
export NXF_JAVA_HOME='$workflow_path/tools/java/jdk'
$workflow_path/tools/nextflow/nextflow run $workflow_path/WES.nf \
-c $workflow_path/WES.config \
--fastq_path $input \
--outdir $output \
--email $email \
-profile slurm \
-resume -ansi-log false \
${optional_params[@]:-""}
if [ \$? -eq 0 ]; then
echo "Nextflow done."
echo "Zip work directory"
find work -type f | egrep "\.(command|exitcode)" | zip -@ -q work.zip
echo "Remove work directory"
rm -r work
echo "Creating md5sum"
find -type f -not -iname 'md5sum.txt' -exec md5sum {} \; > md5sum.txt
echo "WES workflow completed successfully."
rm workflow.running
touch workflow.done
echo "Change permissions"
chmod 775 -R $output
exit 0
else
echo "Nextflow failed"
rm workflow.running
touch workflow.failed
echo "Change permissions"
chmod 775 -R $output
exit 1
fi
EOT
else
echo "Workflow job not submitted, please check $output for 'workflow.status' files."
fi