|
12 | 12 | from smriprep.workflows.surfaces import init_gifti_surface_wf
|
13 | 13 |
|
14 | 14 | from ...config import DEFAULT_MEMORY_MIN_GB
|
| 15 | +from ...data import load_resource |
15 | 16 |
|
16 | 17 | SURFACE_INPUTS = [
|
17 | 18 | "subjects_dir",
|
@@ -201,6 +202,81 @@ def init_mcribs_surface_recon_wf(
|
201 | 202 | return wf
|
202 | 203 |
|
203 | 204 |
|
| 205 | +def init_mcribs_sphere_reg_wf(*, name="mcribs_sphere_reg_wf"): |
| 206 | + """ |
| 207 | + Generate GIFTI registration sphere files from MCRIBS template to dHCP42 (32k). |
| 208 | +
|
| 209 | + TODO: Clarify any distinction with fsLR |
| 210 | + """ |
| 211 | + from smriprep.interfaces.surf import FixGiftiMetadata |
| 212 | + from smriprep.interfaces.workbench import SurfaceSphereProjectUnproject |
| 213 | + |
| 214 | + workflow = LiterateWorkflow(name=name) |
| 215 | + |
| 216 | + inputnode = pe.Node( |
| 217 | + niu.IdentityInterface(["subjects_dir", "subject_id"]), |
| 218 | + name="inputnode", |
| 219 | + ) |
| 220 | + outputnode = pe.Node( |
| 221 | + niu.IdentityInterface(["sphere_reg", "sphere_reg_fsLR"]), |
| 222 | + name="outputnode", |
| 223 | + ) |
| 224 | + |
| 225 | + get_spheres = pe.Node( |
| 226 | + niu.Function(function=_get_dhcp_spheres), |
| 227 | + name='get_spheres', |
| 228 | + run_without_submitting=True, |
| 229 | + ) |
| 230 | + |
| 231 | + # Via FreeSurfer2CaretConvertAndRegisterNonlinear.sh#L270-L273 |
| 232 | + # |
| 233 | + # See https://github.com/DCAN-Labs/DCAN-HCP/tree/9291324 |
| 234 | + sphere_gii = pe.MapNode( |
| 235 | + fs.MRIsConvert(out_datatype="gii"), iterfield="in_file", name="sphere_gii" |
| 236 | + ) |
| 237 | + |
| 238 | + fix_meta = pe.MapNode(FixGiftiMetadata(), iterfield="in_file", name="fix_meta") |
| 239 | + |
| 240 | + # load template files |
| 241 | + atlases = load_resource('atlases') |
| 242 | + |
| 243 | + # SurfaceSphereProjectUnProject |
| 244 | + # project to 41k dHCP atlas sphere |
| 245 | + # - sphere-in: Individual native sphere in surf directory registered to 41k atlas sphere |
| 246 | + # - sphere-to: the 41k atlas sphere, in the fsaverage directory |
| 247 | + # - sphere-unproject-from: 41k atlas sphere registered to dHCP 42wk sphere, in the fsaverage directory |
| 248 | + # - sphere-out: lh.sphere.reg2.dHCP42.native.surf.gii |
| 249 | + project_unproject = pe.MapNode( |
| 250 | + SurfaceSphereProjectUnproject(), |
| 251 | + iterfield=["sphere_in", "sphere_project_to", "sphere_unproject_from"], |
| 252 | + name="project_unproject", |
| 253 | + ) |
| 254 | + project_unproject.inputs.sphere_project_to = [ |
| 255 | + atlases / 'mcribs' / 'lh.sphere.reg2.surf.gii', |
| 256 | + atlases / 'mcribs' / 'rh.sphere.reg2.surf.gii', |
| 257 | + ] |
| 258 | + project_unproject.inputs.sphere_unproject_from = [ |
| 259 | + atlases / 'mcribs' / 'lh.sphere.reg.dHCP42.surf.gii', |
| 260 | + atlases / 'mcribs' / 'rh.sphere.reg.dHCP42.surf.gii', |
| 261 | + ] |
| 262 | + |
| 263 | + # fmt:off |
| 264 | + workflow.connect([ |
| 265 | + (inputnode, get_spheres, [ |
| 266 | + ('subjects_dir', 'subjects_dir'), |
| 267 | + ('subject_id', 'subject_id'), |
| 268 | + ]), |
| 269 | + (get_spheres, sphere_gii, [(('out', _sorted_by_basename), 'in_file')]), |
| 270 | + (sphere_gii, fix_meta, [('converted', 'in_file')]), |
| 271 | + (fix_meta, project_unproject, [('out_file', 'sphere_in')]), |
| 272 | + (sphere_gii, outputnode, [('converted', 'sphere_reg')]), |
| 273 | + (project_unproject, outputnode, [('sphere_out', 'sphere_reg_fsLR')]), |
| 274 | + ]) |
| 275 | + # fmt:on |
| 276 | + |
| 277 | + return workflow |
| 278 | + |
| 279 | + |
204 | 280 | def init_infantfs_surface_recon_wf(
|
205 | 281 | *, age_months, use_aseg=False, name="infantfs_surface_recon_wf"
|
206 | 282 | ):
|
@@ -483,3 +559,15 @@ def _sorted_by_basename(inlist):
|
483 | 559 | from os.path import basename
|
484 | 560 |
|
485 | 561 | return sorted(inlist, key=lambda x: str(basename(x)))
|
| 562 | + |
| 563 | + |
| 564 | +def _get_dhcp_spheres(subject_id: str, subjects_dir: str) -> list: |
| 565 | + from pathlib import Path |
| 566 | + |
| 567 | + out = [] |
| 568 | + for hemi in 'lr': |
| 569 | + sphere = Path(subjects_dir) / subject_id / 'surf' / f'{hemi}h.sphere.reg2' |
| 570 | + if not sphere.exists(): |
| 571 | + raise OSError("MCRIBS spherical registration not found.") |
| 572 | + out.append(str(sphere)) |
| 573 | + return out |
0 commit comments