-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathalohaUploadAndTagOutputs
More file actions
executable file
·177 lines (153 loc) · 5.26 KB
/
alohaUploadAndTagOutputs
File metadata and controls
executable file
·177 lines (153 loc) · 5.26 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash
#
# Probably want the SubjectJsonFile path
#
CmdName=$(basename "$0")
Syntax="${CmdName} {-B BaselineDate} {-F FollowupDate} {-f FwFilePathJsonFile} {-i FollowupIndex} {-d FollowupDir}[-n][-v] SubjectAlohaJsonFile"
function sys {
[ -n "${opt_n}${opt_v}" ] && echo "$@" 1>&2
[ -n "$opt_n" ] || "$@"
}
while getopts B:d:F:f:i:nv arg
do
case "$arg" in
B|d|F|f|i|n|v)
eval "opt_${arg}='${OPTARG:=1}'"
;;
esac
done
shift $(("$OPTIND" - 1))
if [ -z "$opt_d" ]
then
echo "${CmdName} : missing -d FollowupDir" 1>&2
echo "$Syntax" 1>&2
exit 1
fi
FollowupDir="$opt_d"
FollowupUploadDir="${FollowupDir}/Uploads"
if [ -z "$opt_i" ]
then
echo "${CmdName} : missing -i FollowupIndex" 1>&2
echo "$Syntax" 1>&2
exit 2
fi
FollowupIndex="$opt_i"
if [ -z "$opt_B " ]
then
echo "${CmdName} : missing -B BaselineDate" 1>&2
echo "$Syntax" 1>&2
exit 2
fi
BaselineDate=$(date -d "$opt_B" '+%Y-%m-%d')
if [ -z "$opt_F " ]
then
echo "${CmdName} : missing -F FollowupDate" 1>&2
echo "$Syntax" 1>&2
exit 2
fi
FollowupDate=$(date -d "$opt_F" '+%Y-%m-%d')
SubjectAlohaJsonFile="$1"
SubjectId=$(jq -r '.SubjectId' "$SubjectAlohaJsonFile")
SubjectLabel=$(jq -r '.SubjectLabel' "$SubjectAlohaJsonFile")
FollowupJson=$(jq ".Followup[$FollowupIndex].FollowupT2" "$SubjectAlohaJsonFile")
FollowupSessionId=$(jq -r -n --argjson FollowupJson "$FollowupJson" "($FollowupJson).SessionId")
AlohaOutputJson='{
"FileNameTemplate": "aloha-%s-%s_%s-%s",
"FilenameSources": [ ".SubjectLabel", ".FromDate", ".ToDate", ".FileName" ],
"Metadata": "???",
"FollowupOutputFiles": [
{
"AlohaFileName": "deformable/bltrim_left_to_hw.nii.gz"
, "FwFileName": "BaselineT2LeftTrimmedHalfwaySpace"
, "Tags": [ "Aloha", "Output", "Left"]
}
, {
"AlohaFileName": "deformable/bltrim_right_to_hw.nii.gz"
, "FwFileName": "BaselineT2RightTrimmedHalfwaySpace"
, "Tags": [ "Aloha", "Output", "Right" ]
}
, {
"AlohaFileName": "deformable/futrim_om_left_to_hw.nii.gz"
, "FwFileName": "FollowupT2LeftTrimmedHalfwaySpace"
, "Tags": [ "Aloha", "Output", "Left" ]
}
, {
"AlohaFileName": "deformable/futrim_om_right_to_hw.nii.gz"
, "FwFileName": "FollowupT2RightTrimmedHalfwaySpace"
, "Tags": [ "Aloha", "Output", "Right" ]
}
, {
"AlohaFileName": "deformable/blmptrim_left_to_hw.nii.gz"
, "FwFileName": "BaselineT1LeftTrimmedHalfwaySpace"
, "Tags": [ "Aloha", "Output", "Left" ]
}
, {
"AlohaFileName": "deformable/blmptrim_right_to_hw.nii.gz"
, "FwFileName": "BaselineT1RightTrimmedHalfwaySpace"
, "Tags": [ "Aloha", "Output", "Right" ]
}
, {
"AlohaFileName": "deformable/fumptrim_om_left_to_hw.nii.gz"
, "FwFileName": "FollowupT1LeftTrimmedHalfwaySpace"
, "Tags": [ "Aloha", "Output", "Left" ]
}
, {
"AlohaFileName": "deformable/fumptrim_om_right_to_hw.nii.gz"
, "FwFileName": "FollowupT1RightTrimmedHalfwaySpace"
, "Tags": [ "Aloha", "Output", "Right" ]
}
, {
"AlohaFileName": "deformable/mp_antsreg3d_left1Warp.nii.gz"
, "FwFileName": "T1LeftWarpField"
, "Tags": [ "Aloha", "Output", "Left" ]
}
, {
"AlohaFileName": "deformable/mp_antsreg3d_right1Warp.nii.gz"
, "FwFileName": "T1RightWarpField"
, "Tags": [ "Aloha", "Output", "Right" ]
}
, {
"AlohaFileName": "deformable/tse_antsreg3d_left1Warp.nii.gz"
, "FwFileName": "T2LeftWarpField"
, "Tags": [ "Aloha", "Output", "Left" ]
}
, {
"AlohaFileName": "deformable/tse_antsreg3d_right1Warp.nii.gz"
, "FwFileName": "T2RightWarpField"
, "Tags": [ "Aloha", "Output", "Right" ]
}
, {
"AlohaFileName": "results/volumes_left.txt"
, "FwFileName": "LeftVolumes"
, "Tags": [ "Aloha", "Output", "Left" ]
}
, {
"AlohaFileName": "results/volumes_right.txt"
, "FwFileName": "RightVolumes"
, "Tags": [ "Aloha", "Output", "Right" ]
}
]
}'
FollowupUploadFilesRegEx=$(echo $(echo "$AlohaOutputJson" | jq -r '.FollowupOutputFiles[].AlohaFileName') | sed 's/ /)|(/g; s/^.*$/(&)/' )
echo "$AlohaOutputJson" > /tmp/json
[ -e "$FollowupUploadDir" ] || mkdir "$FollowupUploadDir"
FileNameTemplate=$(echo "$AlohaOutputJson" | jq -r '.FileNameTemplate')
FilenameSources=$(echo "$AlohaOutputJson" | jq -r '.FilenameSources[]')
while read f
do
Basename=$(basename "$f")
FwFileJson=$(echo "$AlohaOutputJson" | jq -r --argjson AlohaFileName "\"$Basename\"" '.. | select(.AlohaFileName | test($AlohaFileName)) ?')
FwFileName=$(echo "$FwFileJson" | jq -r '.FwFileName')
Tags=$(echo "$FwFileJson" | jq -r '.Tags|@csv' | sed 's/"//g')
FwTemplatedFileName=$(printf "$FileNameTemplate" "$SubjectLabel" "$BaselineDate" "$FollowupDate" "$FwFileName")
FwUploadFilename="${FollowupUploadDir}/${FwTemplatedFileName}"
sys cp "$f" "$FwUploadFilename"
sys fwuploadfile -t "$Tags" -p "$FollowupSessionId" "$FwUploadFilename"
done < <(find "$FollowupDir" -type f | grep -E "${FollowupUploadFilesRegEx}$" )
# naming: Want a name template: "
# and sources [ .followup.timestamp, .baseline.timestamp, subject, session, filename ]
#
# Copy file to new name
# upload renamed file to FollowupT2 and tag it
#
exit 0