-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun
executable file
·93 lines (71 loc) · 2.5 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
#! /bin/bash
#
CONTAINER="[vistalab/acpc-anat]"
echo -e "$CONTAINER Initiated"
# Built to flywheel-v0 spec.
FLYWHEEL_BASE=/flywheel/v0
MCR_ROOT=/opt/mcr/v92/
INPUT_DIR=$FLYWHEEL_BASE/input
OUTPUT_DIR=$FLYWHEEL_BASE/output
# Set paths to input files
anatomical=$(find $FLYWHEEL_BASE/input/anatomical/ -type f -name "*.nii*")
CONFIG_FILE=${FLYWHEEL_BASE}/config.json
# Make sure that /output directory exists
if [[ ! -d "$OUTPUT_DIR" ]]
then
echo "$CONTAINER $OUTPUT_DIR not found!"
exit 1
fi
# Check for required inputs
if [[ -z "$anatomical" ]]; then
echo -e "$CONTAINER Anatomical input file not found! Exiting!"
exit 1
fi
# Parse Config File
if [[ -f $CONFIG_FILE ]]; then
# Parse config from config.json
echo -e "$CONTAINER Loading configuration from ${CONFIG_FILE}"
userProvidedAcpc=$(cat $CONFIG_FILE | jq -r '.config.userProvidedAcpc')
AC=$(cat $CONFIG_FILE | jq -r '.config.AC')
PC=$(cat $CONFIG_FILE | jq -r '.config.PC')
MS=$(cat $CONFIG_FILE | jq -r '.config.MS')
echo "$CONTAINER userProvidedAcpc has been set to $userProvidedAcpc"
echo "$CONTAINER AC has been set to $AC"
echo "$CONTAINER PC has been set to $PC"
echo "$CONTAINER MS has been set to $MS"
else
# Parse defaults from the manifest.json
CONFIG_FILE=$FLYWHEEL_BASE/manifest.json
echo -e "$CONTAINER Loading defaults from ${CONFIG_FILE}"
userProvidedAcpc=$(cat $CONFIG_FILE | jq -r '.config.userProvidedAcpc.default')
AC=$(cat $CONFIG_FILE | jq -r '.config.AC.default')
PC=$(cat $CONFIG_FILE | jq -r '.config.PC.default')
MS=$(cat $CONFIG_FILE | jq -r '.config.MS.default')
echo "$CONTAINER userProvidedAcpc has been set to $userProvidedAcpc"
echo "$CONTAINER AC has been set to $AC"
echo "$CONTAINER PC has been set to $PC"
echo "$CONTAINER MS has been set to $MS"
fi
# Run the Matlab executable
time /msa/run_acpcAnat.sh "${MCR_ROOT}" "${anatomical}" "${userProvidedAcpc}" "${AC}" "${PC}" "${MS}"
# Check exit status
exit_status=$?
if [[ $exit_status != 0 ]]; then
echo -e "$CONTAINER An error occurred during execution of the Matlab executable. Exiting!"
exit 1
fi
# Get a list of the files in the output directory
outputs=$(find $OUTPUT_DIR/* -maxdepth 0 -type f)
# If outputs exist, generate metadata, and exit
if [[ -z $outputs ]]; then
echo "$CONTAINER No results found in output directory... Exiting"
exit 1
else
cd $OUTPUT_DIR
echo -e "$CONTAINER Wrote: `ls`"
echo -e "$CONTAINER Done!"
fi
# Handle permissions of the outputs
chmod -R 777 $OUTPUT_DIR
# Exit
exit 0