forked from FAANG/analysis-TAGADA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun
executable file
·118 lines (111 loc) · 3.19 KB
/
run
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
#!/bin/bash
# Parse arguments
command=("$0")
escape="'\''"
command+=("'${1//\'/$escape}'")
[ -f "$1" ] && pipeline=$(readlink -m "$1") || pipeline="$1"
shift
while (( "$#" )); do
# Split --option=parameter into two variables
[[ "$1" == --*=* ]] && set -- "${1%%=*}" "${1#*=}" "${@:2}"
case "$1" in
# Parse output directory
--output)
command+=("$1")
if [[ -n "$2" && "$2" != -* ]]; then
command+=("'${2//\'/$escape}'")
output="$2"
shift
fi
shift
;;
# Parse nextflow options passed as pipeline options
--ansi-log|--bucket-dir|--cache|--dump-channels|--dump-hashes|--e.?*|--entry|--help|--hub|--latest|--lib|--name|--offline|--params-file|--process.?*|--profile|--qs|--queue-size|--resume|--revision|--test|--user|--with-conda|--with-dag|--with-docker|--with-notification|--with-podman|--with-report|--with-singularity|--with-timeline|--with-tower|--with-trace|--with-weblog|--without-docker|--without-podman|--work-dir)
command+=("$1")
args+=("${1#-}")
shift
;;
# Parse options
-?*)
command+=("$1")
args+=("$1")
shift
;;
# Parse other arguments
*)
command+=("'${1//\'/$escape}'")
args+=("$1")
shift
;;
esac
done
# Check required arguments
if [[ -z "$pipeline" || -z "$output" ]]; then
echo "Usage: $0 <pipeline.nf> --output <directory> [arguments]"
exit 1
fi
# Prepare nextflow temp folder
mkdir -p "$output"/temp
ln -sf "$output"/temp "$output"/.nextflow
rm -rf "$output"/temp/input
rm -rf "$output"/logs/nextflow.log
rm -rf "$output"/logs/report.html
rm -rf "$output"/logs/timeline.html
# Write command to history
mkdir -p "$output"/logs
[ -f "$output"/logs/command.log ] && echo "" >> "$output"/logs/command.log
echo $(date '+%Y/%m/%d %H:%M:%S')$'\t'"${command[@]}" >> "$output"/logs/command.log
# Parse arguments
set -- "${args[@]}"
args=()
while (( "$#" )); do
case "$1" in
# Parse options and parameters
-?*)
args+=("$1")
[[ "$1" == --* ]] && glob=true || glob=false
option="${1#--}"
paths=""
values=""
params=""
while [[ -n "$2" && "$2" != -* ]]; do
if [[ $glob == true && (-d "$2" || -f "$2") ]]; then
# Create symlink to original path
symlink=$(basename "$2")
symlink="$output"/temp/input/"$option"/"$symlink"
mkdir -p "$output"/temp/input/"$option"
ln -sf "$2" "$symlink"
# Replace path with glob to symlink
paths="$output"/temp/input/"$option"/*
else
# Join values with commas
values+="$2",
fi
shift
done
params+="$values"
params+="$paths"
params="${params%,}"
args+=("$params")
shift
;;
# Parse other arguments
*)
args+=("$1")
shift
;;
esac
done
# Go to output directory
cd "$output"
# Run nextflow pipeline and remove temp folder
# after pipeline successfully completes
nextflow \
-log "$output"/logs/nextflow.log \
run "$pipeline" \
-with-report "$output"/logs/report.html \
-with-timeline "$output"/logs/timeline.html \
-work-dir "$output"/temp/work \
--output "$output" \
"${args[@]}" \
&& rm -rf "$output"/temp "$output"/.nextflow