-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_GenPipes.sh
More file actions
executable file
·237 lines (221 loc) · 9.53 KB
/
check_GenPipes.sh
File metadata and controls
executable file
·237 lines (221 loc) · 9.53 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#!/usr/bin/env bash
THIS_SCRIPT=$(basename "$0")
usage() {
echo "script usage: $THIS_SCRIPT -h [-c cluster] [-j genpipes_json] [-r readset_file] [-l job_list]"
echo "Usage:"
echo " -h Display this help message."
echo " -c <cluster> Cluster name on which the check is expected /!\ MANDATORY /!\."
echo " -j <genpipes_json> json file generated by GenPipes /!\ MANDATORY /!\."
echo " -r <readset_file> Readset File used to submit GenPipes /!\ MANDATORY /!\."
echo " -l <job_list> job_list file generated by GenPipes /!\ MANDATORY /!\."
exit 1
}
genpipes_tagging() {
echo "-> Tagging GenPipes json..."
module load mugqic/python/3.11.1
# shellcheck disable=SC2086
$MOH_path/moh_automation/moh_automation_main/genpipes_deliverables_metrics_tagging.py -i $1 -o ${1/.json/_tagged.json}
module unload mugqic/python/3.11.1
}
genpipes_ingesting() {
echo "-> Ingesting GenPipes json..."
# shellcheck disable=SC1091,SC2086
source $MOH_path/project_tracking_cli/venv/bin/activate
# shellcheck disable=SC2086
pt-cli ingest genpipes --input-json $1
deactivate
}
genpipes_transfer() {
genpipes_run=$(basename $(dirname "$readset_file"))
transfer_log=$(dirname "$readset_file")/transfer.log
echo "-> Transferring GenPipes run $genpipes_run..."
{
if [ -z "$3" ]; then
# If $3 (protocol) is empty, omit the -t option
nohup "$MOH_path/moh_automation/moh_automation_main/transfer_GenPipes.sh" -r "$1" -p "$2" 2>&1 &
else
# If $3 (protocol) is not empty, include the -t option
nohup "$MOH_path/moh_automation/moh_automation_main/transfer_GenPipes.sh" -r "$1" -p "$2" -t "$3" 2>&1 &
fi
echo -n "PID: "
echo $!
echo "LOG: "
} >> "$transfer_log"
echo "-> To follow transfer status see $transfer_log"
}
while getopts 'hc:j:r:l:' OPTION; do
case "$OPTION" in
c)
cluster="$OPTARG"
if [[ $cluster == abacus ]]; then
MOH_path="/lb/project/mugqic/projects/MOH"
if [ -z "${MUGQIC_INSTALL_HOME_DEV:-}" ]; then
export MUGQIC_INSTALL_HOME_DEV=/lb/project/mugqic/analyste_dev
fi
if [ -z "${MUGQIC_INSTALL_HOME_PRIVATE:-}" ]; then
export MUGQIC_INSTALL_HOME_PRIVATE=/lb/project/mugqic/analyste_private
fi
elif [[ $cluster == rorqual ]]; then
MOH_path="/project/6007512/C3G/projects/MOH_PROCESSING"
if [ -z "${MUGQIC_INSTALL_HOME_DEV:-}" ]; then
export MUGQIC_INSTALL_HOME_DEV=/project/6007512/C3G/analyste_dev
fi
elif [[ $cluster == cardinal ]]; then
MOH_path="/project/60007/MOH"
if [ -z "${MUGQIC_INSTALL_HOME_DEV:-}" ]; then
export MUGQIC_INSTALL_HOME_DEV=/project/60007/analyste_dev
fi
elif [[ $cluster == narval ]]; then
MOH_path="/lustre06/project/6084703/C3G/projects/MOH"
if [ -z "${MUGQIC_INSTALL_HOME_DEV:-}" ]; then
export MUGQIC_INSTALL_HOME_DEV=/lustre06/project/6007512/C3G/analyste_dev
fi
elif [[ $cluster == fir ]]; then
MOH_path="/project/6007512/C3G/projects/MOH"
if [ -z "${MUGQIC_INSTALL_HOME_DEV:-}" ]; then
export MUGQIC_INSTALL_HOME_DEV=/project/6007512/C3G/analyste_dev
fi
else
echo -e "ERROR: Invalid cluster: '$cluster'. It has to be either 'abacus', 'rorqual', 'narval', 'fir', or 'cardinal'\n"
usage
fi
;;
j)
genpipes_json=$(readlink -f "$OPTARG")
;;
r)
readset_file="$OPTARG"
;;
l)
job_list="$OPTARG"
;;
h)
usage
;;
?)
usage
;;
esac
done
# mandatory arguments
if [ ! "$cluster" ] || [ ! "$readset_file" ] || [ ! "$genpipes_json" ] || [ ! "$job_list" ]; then
echo -e "ERROR: Missing mandatory arguments -c and/or -r and/or -j and/or -l.\n"
usage
fi
if [ -z "${MUGQIC_INSTALL_HOME:-}" ]; then
export MUGQIC_INSTALL_HOME=/cvmfs/soft.mugqic/CentOS6
fi
if [ -z "${PORTAL_OUTPUT_DIR:-}" ]; then
export PORTAL_OUTPUT_DIR=$MUGQIC_INSTALL_HOME_DEV/portal_out_dir
fi
module avail 2>&1 | grep -m 1 -q "mugqic"; greprc=$?
if ! [[ $greprc -eq 0 ]]; then
module use "$MUGQIC_INSTALL_HOME/modulefiles" "$MUGQIC_INSTALL_HOME_DEV/modulefiles"
fi
if [ -z "${JOB_MAIL:-}" ]; then
export JOB_MAIL=c3g-processing@fakeemail.ca
fi
# Check if json file is empty
if [ ! -s "$genpipes_json" ]; then
echo "ERROR: GenPipes json file is empty Cf. $genpipes_json"
exit 1
fi
operation_cmd_line=$(jq '.operation_cmd_line' "$genpipes_json")
pipeline=$(echo "$operation_cmd_line" | cut -d' ' -f1 | rev | cut -d'/' -f2 | rev)
# if pipeline is rnaseq_light, protocol is empty
if [[ $pipeline == "rnaseq_light" ]]; then
protocol=""
else
protocol=$(echo "$genpipes_json" | cut -d'.' -f2 | cut -d'_' -f1)
fi
# MAIN folder location
MOH_MAIN="$MOH_path/MAIN"
genpipes_submission_folder=$(dirname "$readset_file")
echo "-> Checking $genpipes_submission_folder..."
if [[ $cluster == rorqual ]] || [[ $cluster == narval ]] || [[ $cluster == fir ]] || [[ $cluster == cardinal ]] ; then
log_report_file="${job_list}.tsv"
# shellcheck disable=SC2046,SC2086
$MOH_MAIN/genpipes_moh/genpipes/utils/log_report.py $(readlink -f $job_list) --tsv $log_report_file 2>&1
status=$(awk -F'\t' 'NR>1 {print $5"\n"$6"\n"$7}' "$log_report_file" | sort | uniq)
chmod 660 "$log_report_file"
# FIRST check if still running and skipping
if [[ $status =~ (^|[[:space:]])"RUNNING"([[:space:]]|$) ]] || [[ $status =~ (^|[[:space:]])"PENDING"([[:space:]]|$) ]]; then
# Let's skip and wait
echo "INFO: Job(s) still running Cf. $log_report_file"
# SECOND check if failed or timeout
elif [[ $status =~ (^|[[:space:]])"FAILED"([[:space:]]|$) ]] || [[ $status =~ (^|[[:space:]])"TIMEOUT"([[:space:]]|$) ]] || [[ $status =~ (^|[[:space:]])"OUT_OF_MEMORY"([[:space:]]|$) ]]; then
echo "WARNING: FAILED and/or TIMEOUT found in $job_list Cf. $log_report_file"
# Let's tag GenPipes + Ingest GenPipes
genpipes_tagging "$genpipes_json"
genpipes_ingesting "${genpipes_json/.json/_tagged.json}"
touch "${genpipes_submission_folder}.checked"
chmod 660 "${genpipes_submission_folder}.checked"
# THIRD check if completed and cancelled for instance when cancelled by a user
elif [[ $status =~ (^|[[:space:]])"COMPLETED"([[:space:]]|$) ]] && [[ $status =~ (^|[[:space:]])"CANCELLED"([[:space:]]|$) ]]; then
echo "WARNING: It seems to have been cancelled by a user"
# Let's tag GenPipes + Ingest GenPipes
genpipes_tagging "$genpipes_json"
genpipes_ingesting "${genpipes_json/.json/_tagged.json}"
touch "${genpipes_submission_folder}.checked"
chmod 660 "${genpipes_submission_folder}.checked"
# FOURTH check if success or completed
elif [[ $status =~ (^|[[:space:]])"COMPLETED"([[:space:]]|$) ]]; then
echo "SUCCESS: All jobs completed"
# Let's tag GenPipes + Ingest GenPipes
genpipes_tagging "$genpipes_json"
genpipes_ingesting "${genpipes_json/.json/_tagged.json}"
touch "${genpipes_submission_folder}.checked"
chmod 660 "${genpipes_submission_folder}.checked"
# FIFTH check if cancelled
elif [[ $status =~ (^|[[:space:]])"CANCELLED"([[:space:]]|$) ]]; then
echo "INFO: All jobs cancelled Cf. $log_report_file"
touch "${genpipes_submission_folder}.checked"
chmod 660 "${genpipes_submission_folder}.checked"
# FIFTH check if unknown status
else
echo "ERROR: Unknown status Cf. $log_report_file"
fi
elif [[ $cluster == abacus ]]; then
log_report_file="${job_list}.txt"
# shellcheck disable=SC2086
$MOH_MAIN/genpipes_moh/genpipes/utils/log_report.pl $job_list > $log_report_file
status=$(grep -v "^#" "$log_report_file" | awk -F'\t' '{print $5}' | sort | uniq)
chmod 660 "${job_list}.txt"
# FIRST check if still running and skipping
if [[ $status =~ (^|[[:space:]])"ACTIVE"([[:space:]]|$) ]] || [[ $status =~ (^|[[:space:]])"QUEUED"([[:space:]]|$) ]]; then
# Let's skip and wait
echo "INFO: Job(s) still running Cf. $log_report_file"
# SECOND check if failed or timeout
elif [[ $status =~ (^|[[:space:]])"FAILED"([[:space:]]|$) ]]; then
echo "WARNING: FAILED and/or TIMEOUT found in $job_list Cf. $log_report_file"
# Let's tag GenPipes + Ingest GenPipes
genpipes_tagging "$genpipes_json"
genpipes_ingesting "${genpipes_json/.json/_tagged.json}"
touch "${genpipes_submission_folder}.checked"
chmod 660 "${genpipes_submission_folder}.checked"
# THIRD check if completed and cancelled for instance when cancelled by a user
elif [[ $status =~ (^|[[:space:]])"SUCCESS"([[:space:]]|$) ]] && [[ $status =~ (^|[[:space:]])"CANCELLED"([[:space:]]|$) ]]; then
echo "WARNING: It seems to have been cancelled by a user"
# Let's tag GenPipes + Ingest GenPipes
genpipes_tagging "$genpipes_json"
genpipes_ingesting "${genpipes_json/.json/_tagged.json}"
touch "${genpipes_submission_folder}.checked"
chmod 660 "${genpipes_submission_folder}.checked"
# FOURTH check if success or completed
elif [[ $status =~ (^|[[:space:]])"SUCCESS"([[:space:]]|$) ]]; then
echo "SUCCESS: All jobs completed"
# Let's tag GenPipes + Ingest GenPipes
genpipes_tagging "$genpipes_json"
genpipes_ingesting "${genpipes_json/.json/_tagged.json}"
touch "${genpipes_submission_folder}.checked"
chmod 660 "${genpipes_submission_folder}.checked"
# FIFTH check if cancelled
elif [[ $status =~ (^|[[:space:]])"CANCELLED"([[:space:]]|$) ]]; then
echo "INFO: All jobs cancelled Cf. $log_report_file"
touch "${genpipes_submission_folder}.checked"
chmod 660 "${genpipes_submission_folder}.checked"
# FIFTH check if unknown status
else
echo "ERROR: Unknown status Cf. $log_report_file"
fi
fi