-
Notifications
You must be signed in to change notification settings - Fork 0
/
run
executable file
·67 lines (55 loc) · 1.77 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
#! /bin/bash
#
#
FLYWHEEL_BASE=/flywheel/v0
CONTAINER='[scitran/dcm2nii]'
# Make sure that /output directory is empty (all content will be removed later).
OUTPUT_DIR=$FLYWHEEL_BASE/output
INPUT_DIR=$FLYWHEEL_BASE/input/dicom
# Make sure the input directory is not empty
if [[ "$(ls -A $INPUT_DIR)" ]] ; then
echo "$CONTAINER Starting..."
else
echo "$CONTAINER Input directory is empty:"
exit 1
fi
# Make sure that /output directory is empty before we begin
if [ "$(ls -A $OUTPUT_DIR)" ]; then
echo -e "$CONTAINER $OUTPUT_DIR is not Empty! Please provide an empty directory and mount at '$OUTPUT_DIR'."
exit 1
fi
# The directory that will be sent to dcm2nii
dicom_dir=''
# Unzip the input file (or gunzip it)
input_file=`find $INPUT_DIR -not -path '*/\.*' -type f`
if [[ "$input_file" == *.zip ]] ; then
cd $INPUT_DIR
echo "$CONTAINER Unzipping $input_file"
unzip -q "`basename "$input_file"`"
dicom_dir=$(find $INPUT_DIR/* -maxdepth 0 -not -path '*/\.*' -type d)
if [ -z "$dicom_dir" ] ; then
dicom_dir=$INPUT_DIR
fi
elif [[ "$input_file" == *.gz ]] ; then
cd $INPUT_DIR
echo "$CONTAINER Gunzipping $input_file"
gunzip -q "$input_file"
dicom_dir=$INPUT_DIR
else
dicom_dir=$INPUT_DIR
fi
# Run the algorithm
echo -e "$CONTAINER running dcm2nii..."
dcm2nii $@ -o "$OUTPUT_DIR" "$dicom_dir" &> /dev/null
# Get a list of the files in the output directory
outputs=`find $OUTPUT_DIR -not -path '*/\.*' -type f -name "*"`
# If outputs exist, then go on...
if [ -z "$outputs" ] ; then
echo "$CONTAINER No results found in output directory... Exiting(1)!"
exit 1
else
chmod -R 777 $OUTPUT_DIR
$FLYWHEEL_BASE/metadata_create.py $OUTPUT_DIR $CONTAINER
echo -e "$CONTAINER Success! Wrote:\n`ls $OUTPUT_DIR`"
fi
exit 0