-
Notifications
You must be signed in to change notification settings - Fork 0
/
run
executable file
·83 lines (61 loc) · 2.08 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
#! /bin/bash
#
#
CONTAINER="[scitran/dwi-split-shells]"
echo -e "$CONTAINER Initiated"
# Built to flywheel-v0 spec.
FLYWHEEL_BASE=/flywheel/v0
MCR_ROOT=/opt/mcr/v93/
OUTPUT_DIR=$FLYWHEEL_BASE/output
# Make sure that /output directory exists
if [[ ! -d "$OUTPUT_DIR" ]]
then
echo "$CONTAINER $OUTPUT_DIR not found!"
exit 1
fi
# Set paths to input files
bvecFile=$(find $FLYWHEEL_BASE/input/bvec/ -type f -name "*.bvec*")
bvalFile=$(find $FLYWHEEL_BASE/input/bval/ -type f -name "*.bval*")
dwiFile=$(find $FLYWHEEL_BASE/input/dwi/ -type f -name "*.nii*")
CONFIG_FILE=${FLYWHEEL_BASE}/input/config.json
# Check for required inputs
if [[ -z "$bvecFile" ]] || [[ -z "$bvalFile" ]] || [[ -z "$dwiFile" ]]; then
echo -e "$CONTAINER One or more input files were 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}"
doNorm=$(cat $CONFIG_FILE | jq -r '.config.doNorm')
echo "$CONTAINER BVALUE normalization has been set to $doNorm"
else
# Parse defaults from the manifest.json
CONFIG_FILE=$FLYWHEEL_BASE/manifest.json
echo -e "$CONTAINER Loading defaults from ${CONFIG_FILE}"
doNorm=$(cat $CONFIG_FILE | jq -r '.config.doNorm.default')
echo "$CONTAINER BVALUE normalization has been set to $doNorm"
fi
# Run the Matlab executable
time /msa/run_dwisplitshells.sh "${MCR_ROOT}" "${bvecFile}" "${bvalFile}" "${dwiFile}" "${doNorm}" "${OUTPUT_DIR}"
# 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