-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_bind_paths.sh
More file actions
executable file
·148 lines (131 loc) · 4.07 KB
/
update_bind_paths.sh
File metadata and controls
executable file
·148 lines (131 loc) · 4.07 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
#!/bin/bash
set -euo pipefail
annovar_dir=""
phenosv_dir=""
config_file="nextflow.config"
usage() {
cat <<'USAGE'
Usage:
./update_bind_paths.sh --annovar-dir=<path> --phenosv-dir=<path>
./update_bind_paths.sh <annovar_dir> <phenosv_dir>
Updates PipeVar local bind-path settings used by Singularity/Docker in
nextflow.config without running the full setup.
Options:
--annovar-dir=<path> Existing ANNOVAR directory (contains annotate_variation.pl)
--phenosv-dir=<path> Existing PhenoSV resource directory
-h, --help Show this help message
USAGE
}
resolve_path() {
local path_in="$1"
if [[ -d "$path_in" ]]; then
(cd "$path_in" && pwd -P)
else
return 1
fi
}
escape_groovy_single_quote() {
printf "%s" "$1" | sed "s/'/\\\\'/g"
}
make_tmpfile() {
local config_dir tmp_base
config_dir="$(cd "$(dirname "$config_file")" && pwd -P)"
tmp_base="${TMPDIR:-$config_dir}"
mkdir -p "$tmp_base"
mktemp "$tmp_base/pipevar-bind-config.XXXXXX"
}
update_nextflow_bind_paths() {
local annovar_path="$1"
local phenosv_path="$2"
local annovar_escaped phenosv_escaped tmp_file
if [[ ! -f "$config_file" ]]; then
echo "Error: nextflow.config not found in current directory: $(pwd)" >&2
exit 1
fi
annovar_escaped="$(escape_groovy_single_quote "$annovar_path")"
phenosv_escaped="$(escape_groovy_single_quote "$phenosv_path")"
tmp_file="$(make_tmpfile)"
if ! awk -v annovar="$annovar_escaped" -v phenosv="$phenosv_escaped" '
BEGIN { annovar_done=0; phenosv_done=0 }
{
if ($0 ~ /^[[:space:]]*annovar_host_path[[:space:]]*=/) {
match($0, /^[[:space:]]*/)
indent = substr($0, RSTART, RLENGTH)
print indent "annovar_host_path = \047" annovar "\047"
annovar_done=1
next
}
if ($0 ~ /^[[:space:]]*phenosv_host_path[[:space:]]*=/) {
match($0, /^[[:space:]]*/)
indent = substr($0, RSTART, RLENGTH)
print indent "phenosv_host_path = \047" phenosv "\047"
phenosv_done=1
next
}
print
}
END {
if (!annovar_done || !phenosv_done) exit 2
}
' "$config_file" > "$tmp_file"; then
rm -f "$tmp_file"
echo "Error: failed to update annovar_host_path/phenosv_host_path in ${config_file}" >&2
exit 1
fi
mv "$tmp_file" "$config_file"
}
for arg in "$@"; do
case "$arg" in
--annovar-dir=*)
annovar_dir="${arg#*=}"
;;
--phenosv-dir=*)
phenosv_dir="${arg#*=}"
;;
-h|--help)
usage
exit 0
;;
--*)
echo "Unknown option: $arg" >&2
usage >&2
exit 1
;;
*)
if [[ -z "$annovar_dir" ]]; then
annovar_dir="$arg"
elif [[ -z "$phenosv_dir" ]]; then
phenosv_dir="$arg"
else
echo "Unexpected extra argument: $arg" >&2
usage >&2
exit 1
fi
;;
esac
done
if [[ -z "$annovar_dir" || -z "$phenosv_dir" ]]; then
echo "Error: both ANNOVAR and PhenoSV directories are required." >&2
usage >&2
exit 1
fi
if [[ ! -d "$annovar_dir" ]]; then
echo "Error: ANNOVAR directory not found: $annovar_dir" >&2
exit 1
fi
if [[ ! -f "$annovar_dir/annotate_variation.pl" ]]; then
echo "Error: annotate_variation.pl not found in: $annovar_dir" >&2
exit 1
fi
if [[ ! -d "$phenosv_dir" ]]; then
echo "Error: PhenoSV directory not found: $phenosv_dir" >&2
exit 1
fi
annovar_dir="$(resolve_path "$annovar_dir")"
phenosv_dir="$(resolve_path "$phenosv_dir")"
update_nextflow_bind_paths "$annovar_dir" "$phenosv_dir"
echo "Updated ${config_file}"
echo " annovar_host_path = ${annovar_dir}"
echo " phenosv_host_path = ${phenosv_dir}"
echo
echo "These paths will be used by Singularity/Docker bind options in PipeVar profiles."