yeatmanlab / pyAFQ

Automated Fiber Quantification ... in Python
http://yeatmanlab.github.io/pyAFQ/
BSD 2-Clause "Simplified" License
56 stars 34 forks source link

Using preexisting ITK maps #959

Closed TeddyTuresky closed 5 months ago

TeddyTuresky commented 1 year ago

Hello,

Many thanks for putting out this wonderful toolkit. I was hoping to modify the default GroupAFQ object to incorporate transforms from ANTs. My understanding (which may be wrong) from looking through the mapping.py code is that pyAFQ will look for a composite transform *.h5 file, so I used an antsRegistration call to generate an inverse composite transform for mapping an individual participant b0 to the UNC neonate template (infant study).

[ Side note, I'm not sure if it's a problem with the h5py library or something else, but the h5 file keys ended up with misspellings; e.g., please see "Transform" versus "Tranform" below:

np.asarray(warp2["TransformGroup"]['1']) array(['TranformFixedParameters', 'TranformParameters', 'TransformType'], dtype='<U23')

The most expedient solution seemed to be to change the mapping.py code, but maybe I should reach out to the h5py folks at some point...? ]

I then tried to incorporate the transform into the GroupAFQ object...

itk_map = ItkMap( warp_suffix="xfm", warp_filters={"scope": "ants"}) # derivatives folder name containing transform

my_afq = GroupAFQ( mapping_definition=itk_map,

) ...and run export_all. I checked pyAFQ's template mapping to native space (sub-01_ses-01_dwi_space-subject_desc-template_dwi.nii.gz) and it was not aligned to the b0. In contrast, the warped individual b0 from the antsRegistration call looked well aligned to the template, so I'm guessing pyAFQ is looking for me to generate the composite transform differently. I also tried these steps for an older child using the MNI152NLin2009cAsym, but had similar mapping difficulties. Any guidance would be greatly appreciated! Many thanks, Teddy
36000 commented 1 year ago

Hello Teddy! I think you are doing everything correctly. I have noticed that the ItkMap does not work for all ANTs transforms, and I have been meaning to fix it. My guess is this code (lines 263 and on) needs to be changed for your specific h5 file: https://github.com/yeatmanlab/pyAFQ/blob/7bf8b2527441262aee4b26a7eeac6798a021c9b2/AFQ/definitions/mapping.py#L263

I am going to try switching over to using read_transform and transform_to_displacement_field from ANTsPy ( https://github.com/ANTsX/ANTsPy ). I will bump this to the top of my TODO list and let you know when this is done, so you can try it out for your case. Thank you for your patience!

TeddyTuresky commented 1 year ago

Thank you, John! Much appreciated. And please let me know if you need/want me to test anything on my end in the interim. t

36000 commented 5 months ago

Sorry for the late update, I couldnt figure out how to get this to work so I ended up removing support for ITK files. It seems to work with old qsiprep versions (when I first wrote the code) but not the new ones.

The default pyAFQ behavior is to just find a new mapping using SyN. This can take like 20 minutes to run per subject, which can be a pain. However, it should work, we use it all the time for neonatal template! Let me know if you have any further questions.

TeddyTuresky commented 5 months ago

Good to know! Thank you, John.