This repository was archived by the owner on Sep 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun
More file actions
executable file
·127 lines (99 loc) · 3.68 KB
/
Copy pathrun
File metadata and controls
executable file
·127 lines (99 loc) · 3.68 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
#! /bin/bash
#
# Run script for flywheel/mri-deface Gear.
#
# Authorship: Jennifer Reiter, Michael Perry
#
##############################################################################
# Define directory names and containers
FLYWHEEL_BASE=/flywheel/v0
INPUT_DIR=$FLYWHEEL_BASE/input/anatomical
OUTPUT_DIR=$FLYWHEEL_BASE/output
CONFIG_FILE=$FLYWHEEL_BASE/config.json
CONTAINER='[flywheel/mri-deface]'
##############################################################################
# Parse configuration
function parse_config {
CONFIG_FILE=$FLYWHEEL_BASE/config.json
MANIFEST_FILE=$FLYWHEEL_BASE/manifest.json
if [[ -f $CONFIG_FILE ]]; then
echo "$(cat $CONFIG_FILE | jq -r '.config.'$1)"
else
CONFIG_FILE=$MANIFEST_FILE
echo "$(cat $MANIFEST_FILE | jq -r '.config.'$1'.default')"
fi
}
config_output_nifti="$(parse_config 'output_nifti')"
config_output_mgh="$(parse_config 'output_mgh')"
##############################################################################
# Define brain and face templates
brain_template=$FLYWHEEL_BASE/talairach_mixed_with_skull.gca
face_template=$FLYWHEEL_BASE/face.gca
##############################################################################
# Handle INPUT file
# Find input file In input directory with the extension
# .nii, .nii.gz, .mgz or .mgh.gz or a .zip DICOM file
input_file=`find $INPUT_DIR -iname '*.nii' -o -iname '*.nii.gz' -o -iname '*.mgz' -o -iname '*.mgh.gz' -o -iname '*.zip'`
# Check that input file exists
if [[ -e $input_file ]]; then
echo "${CONTAINER} Input file found: ${input_file}"
# Determine the type of the input file
if [[ "$input_file" == *.zip ]]; then
type=".zip"
elif [[ "$input_file" == *.nii ]]; then
type=".nii"
elif [[ "$input_file" == *.nii.gz ]]; then
type=".nii.gz"
elif [[ "$input_file" == *.mgz ]]; then
type=".mgz"
elif [[ "$input_file" == *.mgz.gz ]]; then
type=".mgz.gz"
fi
# Get the base filename
base_filename=`basename "$input_file" $type`
else
echo "${CONTAINER} No Nifti, DICOM or MGZ inputs were found within input directory $INPUT_DIR"
exit 1
fi
# If input extension is .zip, then unzip the files (assuming they are DICOM files)
if [[ "$type" == *.zip ]]; then
echo "${CONTAINER} Unzipping DICOM files..."
unzip_dir=/tmp/unzipped
unzip $input_file -d $unzip_dir
# Now that the DICOM files are unzipped, need to find the full path to the
# first file to pass mri_deface
input_file=`find $unzip_dir/* -type f | head -n 1`
if [[ -e $input_file ]]; then
echo "$CONTAINER Input file set to: $input_file"
base_filename=`basename "$base_filename" .dicom`
else
echo "${CONTAINER} No input file found in: ${input_file}"
exit 1
fi
fi
##############################################################################
# Run MRI_DEFACE algorithm
# Set initial exit status
mri_deface_exit_status_nifti=0
mri_deface_exit_status_mgz=0
# Set base output_file name
output_file=$OUTPUT_DIR/"$base_filename"'_deface'
# Check if user wanted NIfTI output
if [[ $config_output_nifti == 'true' ]]; then
/flywheel/v0/mri_deface "$input_file" "$brain_template" "$face_template" "$output_file"'.nii.gz'
mri_deface_exit_status_nifti=$?
fi
# Check if user wanted MGH output
if [[ $config_output_mgh == 'true' ]]; then
/flywheel/v0/mri_deface "$input_file" "$brain_template" "$face_template" "$output_file"'.mgz'
mri_deface_exit_status_mgz=$?
fi
##############################################################################
# Handle Exit status
if [[ $mri_deface_exit_status_nifti == 0 ]] && [[ $mri_deface_exit_status_mgz == 0 ]]; then
echo -e "${CONTAINER} Success!"
exit 0
else
echo "${CONTAINER} Something went wrong! mri_deface exited non-zero!"
exit 1
fi