Skip to content

Commit

Permalink
Adding pre- and post-processing hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
skchronicles committed Sep 19, 2023
1 parent 5ffd58c commit a5ae210
Show file tree
Hide file tree
Showing 2 changed files with 835 additions and 0 deletions.
99 changes: 99 additions & 0 deletions workflow/rules/hooks.smk
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Adding handlers for displaying status of the
# pipeline and for getting job information for
# previously submitted jobs using `jobby`:
# https://github.com/OpenOmics/scribble/blob/main/scripts/jobby/jobby
if config['options']['mode'] == 'slurm':
onstart:
shell(
"""
# Move any job information for a previous
# instance of the pipeline to logfiles
sleep 5; rm -f COMPLETED FAILED RUNNING;
touch RUNNING
for f in job_information_*.tsv; do
# Skip over non-existant files
[ -e "${{f}}" ] || continue
mv ${{f}} logfiles/;
done
for f in failed_jobs_*.tsv; do
# Skip over non-existant files
[ -e "${{f}}" ] || continue
mv ${{f}} logfiles/;
done
"""
)

onsuccess:
shell(
"""
# Get job information on all
# previously submitted jobs
sleep 15; rm -f COMPLETED FAILED RUNNING;
timestamp=$(date +"%Y-%m-%d_%H-%M-%S");
./workflow/scripts/jobby \\
$(grep --color=never "^Submitted .* external jobid" logfiles/snakemake.log \\
| awk '{{print $NF}}' \\
| sed "s/['.]//g" \\
| sort \\
| uniq \\
| tr "\\n" " "
) \\
> job_information_${{timestamp}}.tsv \\
|| {{
# Handles edge case were only "rule all"
# is run and no child jobs are submitted
touch job_information_${{timestamp}}.tsv
}}
# Get information on any child
# job(s) that may have failed
grep --color=never \\
'^jobid\\|FAILED' \\
job_information_${{timestamp}}.tsv \\
> failed_jobs_${{timestamp}}.tsv \\
|| {{
# Handles edge case were only "rule all"
# is run and no child jobs are submitted
touch failed_jobs_${{timestamp}}.tsv
}}
touch COMPLETED
"""
)

onerror:
shell(
"""
# Get job information on all
# previously submitted jobs
sleep 15; rm -f COMPLETED FAILED RUNNING;
timestamp=$(date +"%Y-%m-%d_%H-%M-%S");
./workflow/scripts/jobby \\
$(grep --color=never "^Submitted .* external jobid" logfiles/snakemake.log \\
| awk '{{print $NF}}' \\
| sed "s/['.]//g" \\
| sort \\
| uniq \\
| tr "\\n" " "
) \\
> job_information_${{timestamp}}.tsv \\
|| {{
# Handles edge case were only "rule all"
# is run and no child jobs are submitted
touch job_information_${{timestamp}}.tsv
}}
# Get information on any child
# job(s) that may have failed
grep --color=never \\
'^jobid\\|FAILED' \\
job_information_${{timestamp}}.tsv \\
> failed_jobs_${{timestamp}}.tsv \\
|| {{
# Handles edge case were only "rule all"
# is run and no child jobs are submitted
touch failed_jobs_${{timestamp}}.tsv
}}
touch FAILED
"""
)
Loading

0 comments on commit a5ae210

Please sign in to comment.