-
Notifications
You must be signed in to change notification settings - Fork 0
/
copy_subject.sh
executable file
·97 lines (82 loc) · 2.3 KB
/
copy_subject.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
95
96
97
#!/bin/bash
#
# Copy certain DICOMs of a subject from one project to another on XNAT
#
# A DAX installation is required, and its python venv must be active.
# Default options
skipvars="no"
# Parse options
while [[ $# -gt 0 ]]
do
key="${1}"
case "${key}" in
--source_project)
source_project="${2}"; shift; shift ;;
--dest_project)
dest_project="${2}"; shift; shift ;;
--subjects)
subjects="${2}"; shift; shift ;;
--scan_types)
scan_types="${2}"; shift; shift ;;
--skipvars)
skipvars="yes"; shift ;;
*)
echo Unknown input "${1}"; shift ;;
esac
done
# Check for params
if [ -z "${source_project}" ] \
|| [ -z "${dest_project}" ] \
|| [ -z "${subjects}" ] \
|| [ -z "${scan_types}" ] ; then
cat << HERE
Usage example:
${0} \\
--source_project SOURCE_PROJ \\
--dest_project DESTINATION_PROJ \\
--subjects 123456,234567,345678 \\
--scan_types "T1,Rest"
HERE
exit 0
fi
# Where are our scripts? We need to find the python code
function realpath() {
if ! pushd $1 &> /dev/null; then
pushd ${1##*/} &> /dev/null
echo $( pwd -P )/${1%/*}
else
pwd -P
fi
popd > /dev/null
}
script_dir=$(realpath $(dirname "${0}"))
# Check for subjects already present in dest project
echo "Checking subject list ${subjects}"
subjlist=$(echo ${subjects} | tr ',' ' ')
for subj in ${subjlist} ; do
python "${script_dir}"/check_for_subject.py "${dest_project}" "${subj}" \
|| exit 1
done
# Make temporary directory
tmp_dir=$(mktemp -d copy_subject.XXXXXX) || exit 1
# Download
Xnatdownload -p "${source_project}" -d "${tmp_dir}" --subj "${subjects}" -s "${scan_types}" --rs DICOM
# Replace project name in download report CSV
cat "${tmp_dir}"/download_report.csv | \
sed s/^scan,${source_project}/scan,${dest_project}/ > \
"${tmp_dir}"/upload.csv
# Upload. Note, if target resource already exists, Xnatupload prints a warning and does
# not do the upload.
Xnatupload --csv "${tmp_dir}"/upload.csv
# Clean up
if [ -d "${tmp_dir}" ] ; then
rm -fr "${tmp_dir}"
fi
# Set subject and session variables
if [[ "${skipvars}" == "no" ]]; then
subjlist=$(echo ${subjects} | tr ',' ' ')
for subj in ${subjlist} ; do
echo "Copying subject and session vars for ${subj}"
python "${script_dir}"/set_vars.py "${source_project}" "${dest_project}" "${subj}"
done
fi