-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpenn_pet_heuristic.py
321 lines (309 loc) · 12.3 KB
/
penn_pet_heuristic.py
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
'''
Heuristic file for BIDS classification of positron emission tomography (PET) data
collected at the University of Pennsylvania. The main function, infotodict, is defined
below and takes sequence information from dicom headers; you can see which information
is extracted by running fw-heudiconv-tabulate on the session directory, which writes
the sequence info to a tsv file that can subsequently be read in as a Pandas
dataframe. Each row of seqinfo corresponds to one series/acquisition in an imaging
session.
This heuristic is guided by the PET BIDS standard; however, it principally aims to
comply with file naming conventions and does not attempt to satisfy minimum require-
ments for BIDS-compliant pharmacokinetic analysis of dynamic scan data. Additionally,
it only provides BIDS naming for dynamic, attenuation-corrected images as well as
the rigid-body motion correction of the same; most series are left as non-BIDS.
'''
import datetime
import numpy as np
def create_key(template, outtype=('nii.gz',), annotation_classes=None):
if template is None or not template:
raise ValueError('Template must be a valid format string')
return template, outtype, annotation_classes
# PET acquisition types
# Tau
av1451 = create_key('sub-{subject}/{session}/pet/sub-{subject}_{session}_trc-AV1451_rec-acydyn_pet')
pi2620_suvr30_60 = create_key('sub-{subject}/{session}/pet/sub-{subject}_{session}_trc-PI2620_rec-acdyn3060_pet')
pi2620_suvr45_75 = create_key('sub-{subject}/{session}/pet/sub-{subject}_{session}_trc-PI2620_rec-acdyn4575_pet')
pi2620_suvr_other = create_key('sub-{subject}/{session}/pet/sub-{subject}_{session}_trc-PI2620_rec-othersum_pet')
pi2620_dyn0_61 = create_key('sub-{subject}/{session}/pet/sub-{subject}_{session}_trc-PI2620_rec-acdyn31frm_pet')
pi2620_dyn_other = create_key('sub-{subject}/{session}/pet/sub-{subject}_{session}_trc-PI2620_rec-otherdyn_pet')
# Amyloid
fbb = create_key('sub-{subject}/{session}/pet/sub-{subject}_{session}_trc-FLORBETABEN_rec-acdyn_pet')
fbp = create_key('sub-{subject}/{session}/pet/sub-{subject}_{session}_trc-FLORBETAPIR_rec-acdyn_pet')
from collections import defaultdict
def infotodict(seqinfo):
"""Heuristic evaluator for determining which runs belong where
allowed template fields - follow python string module:
index: index within category
subject: participant id
seqindex: run number during scanning
subindex: sub index within group
"""
info = {
av1451: [],
pi2620_suvr30_60: [],
pi2620_suvr45_75: [],
pi2620_suvr_other: [],
pi2620_dyn0_61: [],
pi2620_dyn_other: [],
fbb: [],
fbp: []
}
for s in seqinfo:
protocol = s.protocol_name.lower().replace("[","").replace("]","").replace("/","").replace("-","_").replace(" ","_").replace("__","_")
desc = s.series_description.lower().replace(" ","_").replace("__","_")
id = s.series_id
if all([st in desc for st in ["dy","ctac"]]):
if ("av_1451" in desc) or ("av1451" in desc):
info[av1451].append(id)
elif ("av45" in desc) or ("florbetapir" in desc):
info[fbp].append(id)
elif ("fbb" in desc) or ("florbetaben" in desc) or ("amyloid" in desc):
info[fbb].append(id)
elif ("pi_2620" in desc) or ("pi2620" in desc):
if ("30_60sum" in desc):
info[pi2620_suvr30_60].append(id)
elif ("sum" in desc):
info[pi2620_suvr_other].append(id)
elif ("31frm" in desc):
info[pi2620_dyn0_61].append(id)
elif "frm" in desc:
info[pi2620_dyn_other].append(id)
else:
info[pi2620_suvr45_75].append(id)
else:
print("Series not recognized!: ", protocol, s.dcm_dir_name)
return info
#def ReplaceSession(sesname):
# return sesname[:13].replace("-", "x").replace(".","x").replace("_","x")
#def ReplaceSubject(subjname):
# return subjname[:10].replace("-", "x").replace(".","x").replace("_","x")
MetadataExtras = {
av1451: {
"TracerName": "AV1451",
"TracerRadionuclide": "F18",
"InjectedRadioactivity": 0,
"InjectedRadioactivityUnits": "MBq",
"InjectedMass": "n/a",
"InjectedMassUnits": "ug",
"SpecificRadioactivity": "n/a",
"SpecificRadioactivityUnits": "Bq/g",
"ModeOfAdministration": "bolus",
"TimeZero": "00:00:00",
"ScanStart": 2700,
"InjectionStart": 0,
"FrameTimesStart": [2700, 3000, 3300, 3600, 3900, 4200],
"FrameDuration": [300, 300, 300, 300, 300, 300],
"AcquisitionMode": "list mode",
"ImageDecayCorrected": True,
"ImageDecayCorrectionTime": 2700,
"ReconMethodName": "blob-os-tf",
"ReconMethodParameterLabels": ["unknown"],
"ReconFilterType": ["unknown"],
"AttenuationCorrection": "CTAC-SG",
"Manufacturer": "Philips",
"ManufacturersModelName": "Ingenuity TF",
"Units": "Bq/mL",
"BodyPart": "HEAD_NECK"
},
fbb: {
"TracerName": "FLORBETABEN",
"TracerRadionuclide": "F18",
"InjectedRadioactivity": 0,
"InjectedRadioactivityUnits": "MBq",
"InjectedMass": "n/a",
"InjectedMassUnits": "ug",
"SpecificRadioactivity": "n/a",
"SpecificRadioactivityUnits": "Bq/g",
"ModeOfAdministration": "bolus",
"TimeZero": "00:00:00",
"ScanStart": 5400,
"InjectionStart": 0,
"FrameTimesStart": [5400, 5700, 6000, 6300],
"FrameDuration": [300, 300, 300, 300],
"AcquisitionMode": "list mode",
"ImageDecayCorrected": True,
"ImageDecayCorrectionTime": 5400,
"ReconMethodName": "blob-os-tf",
"ReconMethodParameterLabels": ["unknown"],
"ReconFilterType": ["unknown"],
"AttenuationCorrection": "CTAC-SG",
"Manufacturer": "Philips",
"ManufacturersModelName": "Ingenuity TF",
"Units": "Bq/mL",
"BodyPart": "HEAD_NECK"
},
fbp: {
"TracerName": "FLORBETAPIR",
"TracerRadionuclide": "F18",
"InjectedRadioactivity": 0,
"InjectedRadioactivityUnits": "MBq",
"InjectedMass": "n/a",
"InjectedMassUnits": "ug",
"SpecificRadioactivity": "n/a",
"SpecificRadioactivityUnits": "Bq/g",
"ModeOfAdministration": "bolus",
"TimeZero": "00:00:00",
"ScanStart": 3000,
"InjectionStart": 0,
"FrameTimesStart": [3000, 3300],
"FrameDuration": [300, 300],
"AcquisitionMode": "list mode",
"ImageDecayCorrected": True,
"ImageDecayCorrectionTime": 3000,
"ReconMethodName": "blob-os-tf",
"ReconMethodParameterLabels": ["unknown"],
"ReconFilterType": ["unknown"],
"AttenuationCorrection": "CTAC-SG",
"Manufacturer": "Philips",
"ManufacturersModelName": "Ingenuity TF",
"Units": "Bq/mL",
"BodyPart": "HEAD_NECK"
},
pi2620_suvr30_60: {
"TracerName": "PI2620",
"TracerRadionuclide": "F18",
"InjectedRadioactivity": 0,
"InjectedRadioactivityUnits": "MBq",
"InjectedMass": "n/a",
"InjectedMassUnits": "ug",
"SpecificRadioactivity": "n/a",
"SpecificRadioactivityUnits": "Bq/g",
"ModeOfAdministration": "bolus",
"TimeZero": "00:00:00",
"ScanStart": 1800,
"InjectionStart": 0,
"FrameTimesStart": [1800, 2100, 2400, 2700, 3000, 3300],
"FrameDuration": [300, 300, 300, 300, 300, 300],
"AcquisitionMode": "list mode",
"ImageDecayCorrected": True,
"ImageDecayCorrectionTime": 1800,
"ReconMethodName": "blob-os-tf",
"ReconMethodParameterLabels": ["unknown"],
"ReconFilterType": ["unknown"],
"AttenuationCorrection": "CTAC-SG",
"Manufacturer": "Philips",
"ManufacturersModelName": "Ingenuity TF",
"Units": "Bq/mL",
"BodyPart": "HEAD_NECK"
},
pi2620_suvr45_75: {
"TracerName": "PI2620",
"TracerRadionuclide": "F18",
"InjectedRadioactivity": 0,
"InjectedRadioactivityUnits": "MBq",
"InjectedMass": "n/a",
"InjectedMassUnits": "ug",
"SpecificRadioactivity": "n/a",
"SpecificRadioactivityUnits": "Bq/g",
"ModeOfAdministration": "bolus",
"TimeZero": "00:00:00",
"ScanStart": 1800,
"InjectionStart": 0,
"FrameTimesStart": [2700, 3000, 3300, 3600, 3900, 4200],
"FrameDuration": [300, 300, 300, 300, 300, 300],
"AcquisitionMode": "list mode",
"ImageDecayCorrected": True,
"ImageDecayCorrectionTime": 2700,
"ReconMethodName": "blob-os-tf",
"ReconMethodParameterLabels": ["unknown"],
"ReconFilterType": ["unknown"],
"AttenuationCorrection": "CTAC-SG",
"Manufacturer": "Philips",
"ManufacturersModelName": "Ingenuity TF",
"Units": "Bq/mL",
"BodyPart": "HEAD_NECK"
},
pi2620_suvr_other: {
"TracerName": "PI2620",
"TracerRadionuclide": "F18",
"InjectedRadioactivity": 0,
"InjectedRadioactivityUnits": "MBq",
"InjectedMass": "n/a",
"InjectedMassUnits": "ug",
"SpecificRadioactivity": "n/a",
"SpecificRadioactivityUnits": "Bq/g",
"ModeOfAdministration": "bolus",
"TimeZero": "00:00:00",
"ScanStart": 0,
"InjectionStart": 0,
"FrameTimesStart": [0],
"FrameDuration": [300],
"AcquisitionMode": "list mode",
"ImageDecayCorrected": True,
"ImageDecayCorrectionTime": 0,
"ReconMethodName": "blob-os-tf",
"ReconMethodParameterLabels": ["unknown"],
"ReconFilterType": ["unknown"],
"AttenuationCorrection": "CTAC-SG",
"Manufacturer": "Philips",
"ManufacturersModelName": "Ingenuity TF",
"Units": "Bq/mL",
"BodyPart": "HEAD_NECK"
},
pi2620_dyn0_61: {
"TracerName": "PI2620",
"TracerRadionuclide": "F18",
"InjectedRadioactivity": 0,
"InjectedRadioactivityUnits": "MBq",
"InjectedMass": "n/a",
"InjectedMassUnits": "ug",
"SpecificRadioactivity": "n/a",
"SpecificRadioactivityUnits": "Bq/g",
"ModeOfAdministration": "bolus",
"TimeZero": "00:00:00",
"ScanStart": 0,
"InjectionStart": 0,
"FrameTimesStart": [0, 15, 30, 45, 60, 90, 120,
180, 210, 240, 270, 300, 360, 420, 480, 540,
600, 660, 720, 780, 840, 1020, 1200, 1500,
1800, 2100, 2400, 2700, 3000, 3300, 3600],
"FrameDuration": [15, 15, 15, 15, 30, 30, 30, 30,
30, 30, 30, 30, 60, 60, 60, 60, 60, 60, 60,
60, 60, 180, 180, 300, 300, 300, 300, 300,
300, 300, 300],
"AcquisitionMode": "list mode",
"ImageDecayCorrected": True,
"ImageDecayCorrectionTime": 0,
"ReconMethodName": "blob-os-tf",
"ReconMethodParameterLabels": ["unknown"],
"ReconFilterType": ["unknown"],
"AttenuationCorrection": "CTAC-SG",
"Manufacturer": "Philips",
"ManufacturersModelName": "Ingenuity TF",
"Units": "Bq/mL",
"BodyPart": "HEAD_NECK"
},
pi2620_dyn_other: {
"TracerName": "PI2620",
"TracerRadionuclide": "F18",
"InjectedRadioactivity": 0,
"InjectedRadioactivityUnits": "MBq",
"InjectedMass": "n/a",
"InjectedMassUnits": "ug",
"SpecificRadioactivity": "n/a",
"SpecificRadioactivityUnits": "Bq/g",
"ModeOfAdministration": "bolus",
"TimeZero": "00:00:00",
"ScanStart": 0,
"InjectionStart": 0,
"FrameTimesStart": [0, 15, 30, 45, 60, 90, 120,
180, 210, 240, 270, 300, 360, 420, 480, 540,
600, 660, 720, 780, 840, 1020, 1200, 1500,
1800, 2100, 2400, 2700, 3000, 3300, 3600],
"FrameDuration": [15, 15, 15, 15, 30, 30, 30, 30,
30, 30, 30, 30, 60, 60, 60, 60, 60, 60, 60,
60, 60, 180, 180, 300, 300, 300, 300, 300,
300, 300, 300],
"AcquisitionMode": "list mode",
"ImageDecayCorrected": True,
"ImageDecayCorrectionTime": 0,
"ReconMethodName": "blob-os-tf",
"ReconMethodParameterLabels": ["unknown"],
"ReconFilterType": ["unknown"],
"AttenuationCorrection": "CTAC-SG",
"Manufacturer": "Philips",
"ManufacturersModelName": "Ingenuity TF",
"Units": "Bq/mL",
"BodyPart": "HEAD_NECK"
}
}