-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreamflow-run-wrapper.sh
More file actions
executable file
·132 lines (114 loc) · 2.87 KB
/
Copy pathstreamflow-run-wrapper.sh
File metadata and controls
executable file
·132 lines (114 loc) · 2.87 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
#!/usr/bin/env bash
# SPDX-License-Identifier: CC-BY-4.0
#
# This file is licensed under CC BY 4.0
# https://creativecommons.org/licenses/by/4.0/
#
# Copyright (c) 2026 Bruno de Paula Kinoshita
# A StreamFlow wrapper to match the cwltool and toil-cwl-runner command-line API.
set -euo pipefail
if [[ $# -lt 1 ]]; then
echo "Usage: $0 [--debug] [--container=docker|singularity|none] [--outdir DIR] WORKFLOW.cwl [SETTINGS.yml]"
exit 1
fi
cwl_file=""
settings=""
container="none"
debug=false
outdir=""
# Loop through all arguments dynamically
for arg in "$@"; do
case "$arg" in
--debug)
debug=true
;;
--container=*)
container="${arg#*=}"
;;
--outdir=*)
outdir="${arg#*=}"
;;
*.cwl)
cwl_file="$(realpath "$arg")"
;;
*.yml | *.yaml)
settings="$(realpath "$arg")"
;;
*)
# Strict fallback: Only assign the CWL file if we don't have one yet.
# Everything else (like --np, or standalone numbers like 2) is ignored.
if [[ -z "$cwl_file" ]]; then
cwl_file="$(realpath "$arg")"
fi
;;
esac
done
# Safety check to ensure a CWL file was actually provided
if [[ -z "$cwl_file" ]]; then
echo "Error: No CWL workflow file provided."
exit 1
fi
# And a container...
if [[ "$container" != "docker" && "$container" != "singularity" && "$container" != "none" ]]; then
echo "Error: Invalid --container value: $container"
echo "Valid options: docker | singularity | none"
exit 1
fi
wrapper=$(mktemp)
trap 'rm -f "$wrapper"' EXIT
# The database connection using memory is to avoid errors that happened while running
# the workflows, e.g., sqlite3.OperationalError: database is locked
cat >"$wrapper" <<EOF
version: v1.0
database:
type: default
config:
connection: ":memory:"
workflows:
workflow_name:
type: cwl
config:
file: "$cwl_file"
EOF
# This will now remain empty and clean unless a true .yml/.yaml file was passed
if [[ -n "$settings" ]]; then
cat >>"$wrapper" <<EOF
settings: "$settings"
EOF
fi
# ----------------------------
# Container configuration
# ----------------------------
if [[ "$container" == "singularity" ]]; then
cat >>"$wrapper" <<'EOF'
docker:
- step: /
deployment:
type: singularity
config: {}
EOF
elif [[ "$container" == "docker" ]]; then
cat >>"$wrapper" <<'EOF'
docker:
- step: /
deployment:
type: docker
config: {}
EOF
fi
printf "StreamFlow file:\n\n"
cat "$wrapper"
printf "\n\n"
# Construct the streamflow command dynamically
cmd=(streamflow run)
if [[ "$debug" == true ]]; then
cmd+=(--debug)
fi
if [[ -n "$outdir" ]]; then
cmd+=(--outdir "$outdir")
fi
# Add only the wrapper generated file
cmd+=("$wrapper")
# Execute the clean command
echo "Executing: ${cmd[*]}"
"${cmd[@]}"