Skip to content

Commit 2c8b010

Browse files
committed
Changed YAEL pipeline allowed images from DWI and BOLD to preopCT, T1wContrast, and fGATIR
1 parent cac3dc7 commit 2c8b010

File tree

3 files changed

+43
-21
lines changed

3 files changed

+43
-21
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: rpyANTs
22
Title: An Alternative Advanced Normalization Tools ('ANTs')
3-
Version: 0.0.3.9001
3+
Version: 0.0.3.9002
44
Authors@R:
55
person("Zhengjia", "Wang", email = "[email protected]",
66
role = c("aut", "cre"))

NAMESPACE

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ export(antspynet_desikan_killiany_tourville_labeling)
5555
export(antspynet_preprocess_brain_image)
5656
export(as_ANTsImage)
5757
export(as_ANTsTransform)
58+
export(correct_intensity)
59+
export(ensure_template)
5860
export(halpern_apply_transform_template_mri)
5961
export(halpern_register_ct_mri)
6062
export(halpern_register_template_mri)

inst/rpyants/rpyants/registration/yael.py

+40-20
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,17 @@ def __init__(self, subject_code : str, work_path : str):
3535
@type work_path: str
3636
3737
'''
38-
self.allowed_image_types = ["CT", "T1w", "T2w", "FLAIR", "DWI", "BOLD"]
38+
39+
# List of allowed image types
40+
# CT: postop CT
41+
# T1w: preop T1w MRI without contrast
42+
# T2w: preop T2w MRI
43+
# FLAIR: preop FLAIR MRI
44+
# preopCT: preop CT (for showing blood vessels)
45+
# T1wContrast: preop T1w MRI with contrast (for showing blood vessels)
46+
# fGATIR: preop fast Gray Matter Acquisition T1 Inversion Recovery
47+
self.allowed_image_types = ["CT", "T1w", "T2w", "FLAIR", "preopCT", "T1wContrast", "fGATIR"]
3948
# Each item is a dictionary returned by `parse_bids_filename`
40-
# Keys are image types (e.g., `CT`, `T1w`, `T2w`, `FLAIR`, `DWI`, `BOLD`)
4149
self._images = {}
4250

4351
self._subject_code = subject_code
@@ -89,7 +97,7 @@ def input_image_path(self, type : str, relative : bool = False):
8997
'''
9098
Get the path to the image.
9199
92-
@param type: The type of the image (e.g., `CT`, `T1w`, "T2w", "FLAIR", "DWI", "BOLD")
100+
@param type: The type of the image (e.g., `CT`, `T1w`, "T2w", "FLAIR", "preopCT", "T1wContrast", "fGATIR")
93101
@type type: str
94102
95103
@param relative: If True, return the relative path (to the working directory).
@@ -141,7 +149,7 @@ def expected_image_path(self, type : str, folder : str = None, name = None, **kw
141149
'''
142150
Get the expected path to the image.
143151
144-
@param type: The type of the image (e.g., `CT`, `T1w`, "T2w", "FLAIR", "DWI", "BOLD")
152+
@param type: The type of the image (e.g., `CT`, `T1w`, "T2w", "FLAIR", "preopCT", "T1wContrast", "fGATIR")
145153
@type type: str
146154
147155
@param folder: The folder where the image is expected to be found.
@@ -171,7 +179,7 @@ def set_image(self, type : str, path : str, **kwargs):
171179
'''
172180
Set the path to the image.
173181
174-
@param type: The type of the image (e.g., `CT`, `T1w`, "T2w", "FLAIR", "DWI", "BOLD")
182+
@param type: The type of the image (e.g., `CT`, `T1w`, "T2w", "FLAIR", "preopCT", "T1wContrast", "fGATIR")
175183
@type type: str
176184
177185
@param path: The path to the image.
@@ -192,10 +200,12 @@ def set_image(self, type : str, path : str, **kwargs):
192200
raise FileExistsError(f"Image type {type} already exists. If you want to overwrite it, set `overwrite=True`.")
193201
try:
194202
parsed = parse_bids_filename(os.path.basename(path))
195-
parsed['folder'] = "inputs/anat"
196-
parsed = self._fix_image_path(parsed)
197203
if parsed is None:
198204
raise ValueError("Invalid BIDS filename")
205+
parsed['folder'] = "inputs/anat"
206+
parsed['type'] = type
207+
parsed['ext'] = "nii.gz"
208+
parsed = self._fix_image_path(parsed)
199209
except:
200210
parsed = self._fix_image_path({
201211
'folder': "inputs/anat",
@@ -228,18 +238,22 @@ def input_flair_path(self):
228238
return self.input_image_path("FLAIR")
229239

230240
@property
231-
def input_dwi_path(self):
232-
return self.input_image_path("DWI")
241+
def input_preopCT_path(self):
242+
return self.input_image_path("preopCT")
243+
244+
@property
245+
def input_fGATIR_path(self):
246+
return self.input_image_path("fGATIR")
233247

234248
@property
235-
def input_bold_path(self):
236-
return self.input_image_path("BOLD")
249+
def input_t1wcontrast_path(self):
250+
return self.input_image_path("T1wContrast")
237251

238252
def register_to_T1w(self, type : str, reverse : bool= False, verbose : bool=True):
239253
'''
240254
Register an image to the T1w image.
241255
242-
@param type: The type of the image (e.g., `CT`, `T2w`, "FLAIR", "DWI", "BOLD")
256+
@param type: The type of the image (e.g., `CT`, `T2w`, "FLAIR", "preopCT", "T1wContrast", "fGATIR")
243257
@type type: str
244258
245259
@param reverse: If True, register the T1w image to the image (switch the fixed and moving images).
@@ -307,17 +321,17 @@ def register_to_T1w(self, type : str, reverse : bool= False, verbose : bool=True
307321
ct_img.set_qform(new_sform)
308322
ct_img.to_filename( ensure_basename( self.expected_image_path( type, "coregistration/anat", space = "scanner" ) ) )
309323
# save the mapping configurations
310-
mappings = self.get_native_mappings(type, relative = True)
324+
mappings = self.get_native_mapping(type, relative = True)
311325
log_file = ensure_basename( self.format_path(folder="coregistration/log", name = "mapping", ext="json", space = "scanner", orig = type) )
312326
with open(log_file, "w") as f:
313327
json.dump(mappings, f)
314328
return mappings
315329

316-
def get_native_mappings(self, type : str = "CT", relative : bool = False):
330+
def get_native_mapping(self, type : str = "CT", relative : bool = False):
317331
'''
318332
Get the mappings for the native image.
319333
320-
@param type: The type of the image modality (e.g., "CT", "T2w", "FLAIR", "DWI", "BOLD")
334+
@param type: The type of the image modality (e.g., "CT", "T2w", "FLAIR", "preopCT", "T1wContrast", "fGATIR")
321335
@type type: str
322336
323337
@param relative: If True, return the relative path (to the working directory).
@@ -344,6 +358,8 @@ def get_native_mappings(self, type : str = "CT", relative : bool = False):
344358
'mappings': {},
345359
}
346360
mappings = result['mappings']
361+
if not os.path.exists(tranform_rootdir):
362+
ensure_dir(tranform_rootdir)
347363
for filename in os.listdir( tranform_rootdir ):
348364
if os.path.isfile( file_path(tranform_rootdir, filename) ):
349365
try:
@@ -353,6 +369,8 @@ def get_native_mappings(self, type : str = "CT", relative : bool = False):
353369
mappings[parsed['type']] = file_path(transform_prefix, filename)
354370
except:
355371
continue
372+
if not os.path.exists(aligned_rootdir):
373+
ensure_dir(aligned_rootdir)
356374
for filename in os.listdir( aligned_rootdir ):
357375
if os.path.isfile( file_path(aligned_rootdir, filename) ):
358376
try:
@@ -378,7 +396,7 @@ def map_to_template(self,
378396
@param template_name: The name of the template image (e.g., `MNI152NLin2009bAsym`)
379397
@type template_name: str
380398
381-
@param native_type: The type of the image (e.g., `CT`, `T1w`, `T2w`, "FLAIR", "DWI", "BOLD")
399+
@param native_type: The type of the image (e.g., `CT`, `T1w`, `T2w`, "FLAIR", "preopCT", "T1wContrast", "fGATIR")
382400
@type native_type: str
383401
384402
@param reverse: If True, register the template image to the image (switch the fixed and moving images).
@@ -503,7 +521,7 @@ def get_template_mapping(self, template_name : str, native_type : str = "T1w", r
503521
@param template_name: The name of the template image (e.g., `MNI152NLin2009bAsym`)
504522
@type template_name: str
505523
506-
@param native_type: The type of the image (e.g., `CT`, `T1w`, `T2w`, "FLAIR", "DWI", "BOLD"), default is `T1w`.
524+
@param native_type: The type of the image (e.g., `CT`, `T1w`, `T2w`, "FLAIR", "preopCT", "T1wContrast", "fGATIR"), default is `T1w`.
507525
@type native_type: str
508526
509527
@param relative: If True, return the relative path (to the working directory).
@@ -515,6 +533,8 @@ def get_template_mapping(self, template_name : str, native_type : str = "T1w", r
515533
if native_type not in self.allowed_image_types:
516534
raise ValueError(f"Invalid image type: {native_type}. Must be one of {self.allowed_image_types}")
517535
tranform_rootdir = file_path(self._work_path, "normalization/transformations")
536+
if not os.path.exists(tranform_rootdir):
537+
return None
518538
forward_list = []
519539
inverse_list = []
520540
for filename in os.listdir( tranform_rootdir ):
@@ -564,7 +584,7 @@ def transform_image_from_template(self, path : str, template_name : str, native_
564584
@param template_name: The name of the template image (e.g., `MNI152NLin2009bAsym`)
565585
@type template_name: str
566586
567-
@param native_type: The type of the image (e.g., `CT`, `T1w`, `T2w`, "FLAIR", "DWI", "BOLD"), default is `T1w`.
587+
@param native_type: The type of the image (e.g., `CT`, `T1w`, `T2w`, "FLAIR", "preopCT", "T1wContrast", "fGATIR"), default is `T1w`.
568588
@type native_type: str
569589
570590
@return: The mapped image.
@@ -595,7 +615,7 @@ def transform_points_to_template(self, points : np.ndarray, template_name : str,
595615
@param template_name: The name of the template image (e.g., `MNI152NLin2009bAsym`)
596616
@type template_name: str
597617
598-
@param native_type: The type of the image (e.g., `CT`, `T1w`, `T2w`, "FLAIR", "DWI", "BOLD"), default is `T1w`.
618+
@param native_type: The type of the image (e.g., `CT`, `T1w`, `T2w`, "FLAIR", "preopCT", "T1wContrast", "fGATIR"), default is `T1w`.
599619
@type native_type: str
600620
601621
@return: The mapped points.
@@ -643,7 +663,7 @@ def transform_points_from_template(self, points : np.ndarray, template_name : st
643663
@param template_name: The name of the template image (e.g., `MNI152NLin2009bAsym`)
644664
@type template_name: str
645665
646-
@param native_type: The type of the image (e.g., `CT`, `T1w`, `T2w`, "FLAIR", "DWI", "BOLD"), default is `T1w`.
666+
@param native_type: The type of the image (e.g., `CT`, `T1w`, `T2w`, "FLAIR", "preopCT", "T1wContrast", "fGATIR"), default is `T1w`.
647667
@type native_type: str
648668
649669
@return: The mapped points.

0 commit comments

Comments
 (0)