-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_victree_analysis.sh
executable file
·95 lines (76 loc) · 2.07 KB
/
run_victree_analysis.sh
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
#!/bin/bash
create_output_dir() {
local yaml_file="$1"
local yaml_dir="$(dirname "$yaml_file")"
local output_dir="$yaml_dir/$(basename "${yaml_file%.*}")"
if [ ! -d "$output_dir" ]; then
mkdir "$output_dir"
else
echo "ERROR: Output dir was already present. Exit." >&2
exit 1
fi
echo "${output_dir}"
}
parse_yaml_args() {
local yaml_file="$1"
local output_dir="$2"
local yaml_dir="$(dirname "$yaml_file")"
local args=("--output" "${output_dir}")
while IFS="=" read -r key value; do
# replace underscores with dashes
key=${key//_/-}
# flag param
if [[ "${value}" == "true" ]]; then
args+=("--${key}")
# elif [[ "${key}" == "input" ]]; then
# args+=("--${key} ${yaml_dir}/${value}")
else
args+=("--${key} ${value}")
fi
done < <(
yq 'to_entries | map([.key, .value] | join("=")) | .[]' "${yaml_file}"
)
echo "${args[@]}"
}
copytree_dir="/home/x_harme/victree"
# validate input
if [ $# -ne 1 ]; then
if [ $# -eq 2 ]; then
copytree_dir="$2"
else
echo "Usage: $0 <config.yml> [ <copytree_dir> ]"
exit 1
fi
fi
victree="${copytree_dir}/src/main.py"
# analysis="./r_analysis.R"
yaml_file="$1"
yaml_dir="$(dirname "$yaml_file")"
start_dir="$(pwd)"
echo "setting up output directory"
output_dir=$(create_output_dir "${yaml_file}")
echo "Parsing config"
args=($(parse_yaml_args "${yaml_file}" "${output_dir}"))
echo "Running VI"
"${victree}" "${args[@]}" || {
echo "Something went wrong. Cleaning up output dir"
rm -r "${output_dir}"
exit 1
}
checkpoint="$(realpath "$(find "${output_dir}" -maxdepth 1 -type f -name "checkpoint*.h5")")"
if [ -f "$checkpoint" ]; then
echo "checkpoint found! $checkpoint"
else
echo "checkpoint not found. skipping analysis"
exit
fi
input_file="$(yq eval '.input' ${yaml_file})"
# go in copytree_dir so to use catch scripts dependencies
echo "moving into ${copytree_dir}"
cd "${copytree_dir}" || exit 1
echo "running R analysis"
./r_analysis.R -gt "$input_file" -m -p 2 "$checkpoint"
echo "Finish."
# go back
echo "moving back to ${start_dir}"
cd "${start_dir}"