Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support MCRIBS derivatives #1029

Merged
merged 17 commits into from
Jan 29, 2024
Merged

Support MCRIBS derivatives #1029

merged 17 commits into from
Jan 29, 2024

Conversation

tsalo
Copy link
Member

@tsalo tsalo commented Jan 4, 2024

Closes #840 and relates to #976.

Changes proposed in this pull request

  • Create interface, xcp_d.interfaces.bids.CollectRegistrationFiles, to collect FreeSurfer or MCRIBs sphere and transform files for anatomical workflow.
  • Remove xcp_d.utils.bids.get_freesurfer_sphere, as the functionality is now in CollectRegistrationFiles.
  • Heavily refactor xcp_d.utils.bids.get_freesurfer_dir to support MCRIBS on top of FreeSurfer.

@tsalo tsalo added enhancement New feature or request dcan DCAN-related issues and PRs labels Jan 4, 2024
Copy link

codecov bot commented Jan 8, 2024

Codecov Report

Attention: Patch coverage is 85.45455% with 8 lines in your changes missing coverage. Please review.

Project coverage is 82.45%. Comparing base (673efa3) to head (9752361).
Report is 138 commits behind head on main.

Files with missing lines Patch % Lines
xcp_d/interfaces/bids.py 79.41% 5 Missing and 2 partials ⚠️
xcp_d/workflows/anatomical.py 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1029      +/-   ##
==========================================
- Coverage   82.51%   82.45%   -0.07%     
==========================================
  Files          48       48              
  Lines        5846     5871      +25     
  Branches      786      787       +1     
==========================================
+ Hits         4824     4841      +17     
- Misses        826      832       +6     
- Partials      196      198       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tsalo
Copy link
Member Author

tsalo commented Jan 8, 2024

@madisoth I think this should work. Would you be willing to try it out on some Nibabies+MCRIBS data?

@tsalo tsalo requested a review from madisoth January 9, 2024 19:00
Copy link
Collaborator

@madisoth madisoth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got an error in CollectingRegistrationFiles ingressing NiBabies 24.0.0a1 MCRIBS derivatives; changing it to this fixed it for me:

class CollectRegistrationFiles(SimpleInterface):
    """Collect registration files for fsnative-to-fsLR transformation."""

    input_spec = _CollectRegistrationFilesInputSpec
    output_spec = _CollectRegistrationFilesOutputSpec

    def _run_interface(self, runtime):
        import os

        from pkg_resources import resource_filename as pkgrf
        from templateflow.api import get as get_template

        hemisphere = self.inputs.hemisphere
        hstr = f"{hemisphere.lower()}h"
        participant_id = self.inputs.participant_id
        if not participant_id.startswith("sub-"):
            participant_id = f"sub-{participant_id}"

        # Find the subject's sphere in the segmentation derivatives.
        # TODO: Collect from the preprocessing derivatives if they're a compliant version.
        # Namely, fMRIPrep >= 23.1.2, Nibabies >= 24.0.0a1.
        self._results["subject_sphere"] = os.path.join(
            self.inputs.segmentation_dir,
            participant_id,
            "surf",
            f"{hstr}.sphere.reg",
        )

        # NOTE: Why do we need the fsaverage mesh?
        # TODO: Replace with appropriate files.
        if self.inputs.software == "FreeSurfer":
            # Find the subject's sphere in the FreeSurfer derivatives.
            # TODO: Collect from the preprocessing derivatives if they're a compliant version.
            # Namely, fMRIPrep >= 23.1.2, Nibabies >= 24.0.0a1.
            self._results["subject_sphere"] = os.path.join(
                self.inputs.segmentation_dir,
                participant_id,
                "surf",
                f"{hstr}.sphere.reg",
            )
            # Load the fsaverage-164k sphere
            # FreeSurfer: tpl-fsaverage_hemi-?_den-164k_sphere.surf.gii
            self._results["source_sphere"] = str(
                get_template(
                    template="fsaverage",
                    space=None,
                    hemi=hemisphere,
                    density="164k",
                    desc=None,
                    suffix="sphere",
                )
            )
            # NOTE: Can we upload these to templateflow?
            # FreeSurfer: fs_?/fs_?-to-fs_LR_fsaverage.?_LR.spherical_std.164k_fs_?.surf.gii
            self._results["sphere_to_sphere"] = pkgrf(
                "xcp_d",
                (
                    f"data/standard_mesh_atlases/fs_{hemisphere}/"
                    f"fs_{hemisphere}-to-fs_LR_fsaverage.{hemisphere}_LR.spherical_std."
                    f"164k_fs_{hemisphere}.surf.gii"
                ),
            )
            # FreeSurfer: tpl-fsLR_hemi-?_den-32k_sphere.surf.gii
            self._results["target_sphere"] = str(
                get_template(
                    template="fsLR",
                    space=None,
                    hemi=hemisphere,
                    density="32k",
                    desc=None,
                    suffix="sphere",
                )
            )

        elif self.inputs.software == "MCRIBS":
            # Find the subject's sphere in the MCRIBS derivatives.
            # TODO: Collect from the preprocessing derivatives if they're a compliant version.
            # Namely, fMRIPrep >= 23.1.2, Nibabies >= 24.0.0a1.
            self._results["subject_sphere"] = os.path.join(
                self.inputs.segmentation_dir,
                participant_id,
                "freesurfer",
                participant_id,
                "surf",
                f"{hstr}.sphere.reg2",
            )
            # MCRIBS: tpl-fsaverage_hemi-?_den-41k_desc-reg_sphere.surf.gii
            self._results["source_sphere"] = os.path.join(
                self.inputs.segmentation_dir,
                "templates_fsLR",
                f"tpl-fsaverage_hemi-{hemisphere}_den-41k_desc-reg_sphere.surf.gii",
            )
            # MCRIBS: tpl-dHCP_space-fsaverage_hemi-?_den-41k_desc-reg_sphere.surf.gii
            self._results["sphere_to_sphere"] = os.path.join(
                self.inputs.segmentation_dir,
                "templates_fsLR",
                f"tpl-dHCP_space-fsaverage_hemi-{hemisphere}_den-41k_desc-reg_sphere.surf.gii",
            )
            # MCRIBS: tpl-dHCP_space-fsLR_hemi-?_den-32k_desc-week42_sphere.surf.gii
            self._results["target_sphere"] = os.path.join(
                self.inputs.segmentation_dir,
                "templates_fsLR",
                f"tpl-dHCP_space-fsLR_hemi-{hemisphere}_den-32k_desc-week42_sphere.surf.gii",
            )

        return runtime

@tsalo tsalo merged commit d03d282 into PennLINC:main Jan 29, 2024
19 of 20 checks passed
@tsalo tsalo deleted the nibabies-24 branch January 29, 2024 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dcan DCAN-related issues and PRs enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DCAN] Support MIRTK anatomical derivative structure
2 participants