-
Notifications
You must be signed in to change notification settings - Fork 4
/
entrypoint
executable file
·129 lines (118 loc) · 5.82 KB
/
entrypoint
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
#!/usr/bin/env bash
#
# Copyright © 2022 Ye Chang yech1990@gmail.com
# Distributed under terms of the GNU license.
#
# Created: 2022-04-04 18:49
logo="
\033[1;32m ██╗ ██╗ ██╗\033[0m ██████╗ ██╗██████╗ ███████╗███████╗ ██████╗ \033[0m
\033[1;32m ██║ ██║ ██║\033[0m ██╔══██╗██║██╔══██╗██╔════╝██╔════╝██╔═══██╗ \033[0m
\033[1;32m ██║ ██║ ██║\033[0m█████╗██████╔╝██║██║ ██║███████╗█████╗ ██║ ██║ \033[0m
\033[1;32m ╚████████╔╝\033[0m╚════╝██╔══██╗██║██║ ██║╚════██║██╔══╝ ██║▄▄ ██║ \033[0m
\033[1;32m ╚══██║══╝ \033[0m ██████╔╝██║██████╔╝███████║███████╗╚██████╔╝ \033[0m
\033[1;32m ╚═╝ \033[0m ╚═════╝ ╚═╝╚═════╝ ╚══════╝╚══════╝ ╚══▀▀═╝ \033[0m
\033[0m \033[0m
\033[0m ██████╗ ██╗██████╗ ███████╗██╗ ██╗███╗ ██╗███████╗ \033[0m
\033[0m ██╔══██╗██║██╔══██╗██╔════╝██║ ██║████╗ ██║██╔════╝ \033[0m
\033[0m ██████╔╝██║██████╔╝█████╗ ██║ ██║██╔██╗ ██║█████╗ \033[0m
\033[0m ██╔═══╝ ██║██╔═══╝ ██╔══╝ ██║ ██║██║╚██╗██║██╔══╝ \033[0m
\033[0m ██║ ██║██║ ███████╗███████╗██║██║ ╚████║███████╗ \033[0m
\033[0m ╚═╝ ╚═╝╚═╝ ╚══════╝╚══════╝╚═╝╚═╝ ╚═══╝╚══════╝ \033[0m
"
printf "$logo\n"
# Set default values
snake="/pipeline/Snakefile"
conf="data.yaml"
# PORT=$(shuf -i 60000-65000 -n 1)
PORT=""
POSITIONAL_ARGS=()
while [[ $# -gt 0 ]]; do
case $1 in
-j | --jobs | --cores)
cores_cmd="$2"
shift
shift
;;
-c | --conf)
conf="$2"
shift
shift
;;
--mysnake)
snake="$2"
shift
shift
;;
--myport)
PORT="$2"
shift
shift
;;
*)
POSITIONAL_ARGS+=("$1")
shift
;;
esac
done
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
if [ ! -f "${conf}" ]; then
echo "${conf} can not be found!"
exit 1
else
python /pipeline/validator ${conf}
fi
bind_string=$(python -c 'import yaml, sys, os;print(",".join(set(os.path.dirname(v2) for v in yaml.safe_load(open(sys.argv[1],"r"))["reference"].values() for v2 in v.values() if os.path.isabs(v2)) | set(os.path.dirname(v3) for v in yaml.safe_load(open(sys.argv[1],"r"))["samples"].values() for v2 in v.get("data", {}) for v3 in v2.values() if os.path.isabs(v3)) | set(os.path.dirname(v2) for v in yaml.safe_load(open(sys.argv[1],"r"))["samples"].values() for v2 in v.get("bam", {}).values() if os.path.isabs(v2))))' ${conf})
if [ -n "${bind_string}" ]; then
echo -e "Please add \033[0;31m--bind ${bind_string}\033[0m right after 'apptainer run'"
fi
if [ -z "${cores_cmd}" ]; then
cores_conf=$(python -c 'import yaml, sys;print(yaml.safe_load(open(sys.argv[1],"r")).get("cores",""))' ${conf})
if [ -z "${cores_conf}" ]; then
cores=48
else
cores=${cores_conf}
fi
else
cores=${cores_cmd}
fi
if [ -z "${PORT}" ]; then
LOGFILE="BIDSEQ_LOG_$(date +"%F-%H%M%S").txt"
echo -e "\033[0;32mREAD DEBUG LOG AT\033[0m ${LOGFILE}"
printf "\033[0;33m Analyzing...\033[0m"
snakemake --rerun-incomplete --jobs ${cores} --snakefile ${snake} --configfiles /pipeline/config.yaml ${conf} $@ 1>${LOGFILE} 2>${LOGFILE}
if [ $? -eq 0 ]; then
printf "\033[0;33m\b\b\b\b\b\b\b\b\b\b\b\b\b\033[0m"
printf "\033[0;32m\xE2\x9C\x94\033[0m Successfully finished all jobs.\n"
else
printf "\033[0;33m\b\b\b\b\b\b\b\b\b\b\b\b\b\b\033[0m"
printf "\033[0;31m\xE2\x9D\x8C\033[0m Jobs exit with error!\n"
fi
else
panoptes --ip 0.0.0.0 --port ${PORT} 1>/dev/null 2>/dev/null &
export PANOPTES_PID=$!
# echo "PANOPTES_PID=$PANOPTES_PID"
trap 'kill -s SIGKILL $PANOPTES_PID' EXIT
while true; do
if curl -s http://127.0.0.1:${PORT}/api/service-info | grep -q running; then
echo -e "\033[0;32mPLEASE MONITOR THE PIPELINE AT\033[0m http://127.0.0.1:${PORT}"
echo -e "\033[0;32mIf you are running this pipeline on a remote server,\033[0m"
echo -e "\033[0;32mreplace the IP adress with server IP, or set ssh proxy on you local machine.\033[0m"
LOGFILE="BIDSEQ_LOG_$(date +"%F-%H%M%S").txt"
echo -e "\033[0;32mREAD DEBUG LOG AT\033[0m ${LOGFILE}"
printf "\033[0;33m Analyzing...\033[0m"
snakemake --wms-monitor http://127.0.0.1:${PORT} --rerun-incomplete --jobs ${cores} --snakefile ${snake} --configfiles /pipeline/config.yaml ${conf} $@ 1>${LOGFILE} 2>${LOGFILE}
if [ $? -eq 0 ]; then
printf "\033[0;33m\b\b\b\b\b\b\b\b\b\b\b\b\b\033[0m"
printf "\033[0;32m\xE2\x9C\x94\033[0m Successfully finished all jobs.\n"
else
printf "\033[0;33m\b\b\b\b\b\b\b\b\b\b\b\b\b\b\033[0m"
printf "\033[0;31m\xE2\x9D\x8C\033[0m Jobs exit with error!\n"
fi
# rm .panoptes.db
kill -s SIGKILL $PANOPTES_PID
break
fi
echo "$(date) waiting for service to start..."
sleep 2
done
fi