Skip to content

Commit 201662a

Browse files
effigiesmgxd
andauthored
ENH: Resample morphometrics to fsLR dscalar CIFTI-2 files if --cifti-output is used (#279)
* MNT: Pin smriprep 0.11.x * ENH: Resample morphometrics to fsLR dscalar CIFTI-2 files if --cifti-output is used * FIX: Import workflow * FIX: Workflow variable name --------- Co-authored-by: Mathias Goncalves <[email protected]>
1 parent deb3f76 commit 201662a

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

nibabies/workflows/anatomical/base.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def init_infant_anat_wf(
2424
skull_strip_template,
2525
sloppy,
2626
spaces,
27+
cifti_output=False,
2728
name="infant_anat_wf",
2829
):
2930
"""
@@ -193,6 +194,7 @@ def init_infant_anat_wf(
193194
num_t1w=num_t1w,
194195
output_dir=output_dir,
195196
spaces=spaces,
197+
cifti_output=cifti_output,
196198
)
197199

198200
# Multiple T1w files -> generate average reference
@@ -444,4 +446,23 @@ def init_infant_anat_wf(
444446
]),
445447
])
446448
# fmt: on
449+
450+
if cifti_output:
451+
from smriprep.workflows.surfaces import init_morph_grayords_wf
452+
453+
morph_grayords_wf = init_morph_grayords_wf(grayord_density=cifti_output)
454+
anat_derivatives_wf.get_node('inputnode').inputs.cifti_density = cifti_output
455+
# fmt:off
456+
wf.connect([
457+
(surface_recon_wf, morph_grayords_wf, [
458+
('outputnode.subject_id', 'inputnode.subject_id'),
459+
('outputnode.subjects_dir', 'inputnode.subjects_dir'),
460+
]),
461+
(morph_grayords_wf, anat_derivatives_wf, [
462+
("outputnode.cifti_morph", "inputnode.cifti_morph"),
463+
("outputnode.cifti_metadata", "inputnode.cifti_metadata"),
464+
]),
465+
])
466+
# fmt:on
467+
447468
return wf

nibabies/workflows/anatomical/outputs.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ def init_anat_derivatives_wf(
249249
num_t1w,
250250
output_dir,
251251
spaces,
252+
cifti_output,
252253
name="anat_derivatives_wf",
253254
tpm_labels=BIDS_TISSUE_ORDER,
254255
):
@@ -314,6 +315,12 @@ def init_anat_derivatives_wf(
314315
List of input T2w images
315316
t2w_preproc
316317
The T2w image in T1w space.
318+
cifti_morph
319+
Morphometric CIFTI-2 dscalar files
320+
cifti_density
321+
Grayordinate density
322+
cifti_metadata
323+
JSON files containing metadata dictionaries
317324
"""
318325
from niworkflows.interfaces.nibabel import ApplyMask
319326
from niworkflows.interfaces.utility import KeySelect
@@ -347,6 +354,9 @@ def init_anat_derivatives_wf(
347354
"t1w_fs_aparc",
348355
"t2w_source_files",
349356
"t2w_preproc",
357+
"cifti_metadata",
358+
"cifti_density",
359+
"cifti_morph",
350360
]
351361
),
352362
name="inputnode",
@@ -706,6 +716,26 @@ def init_anat_derivatives_wf(
706716
('source_files', 'source_file')]),
707717
])
708718
# fmt: on
719+
if cifti_output:
720+
ds_cifti_morph = pe.MapNode(
721+
DerivativesDataSink(
722+
base_directory=output_dir,
723+
suffix=['curv', 'sulc', 'thickness'],
724+
compress=False,
725+
space='fsLR',
726+
),
727+
name='ds_cifti_morph',
728+
run_without_submitting=True,
729+
iterfield=["in_file", "meta_dict", "suffix"],
730+
)
731+
# fmt:off
732+
workflow.connect([
733+
(inputnode, ds_cifti_morph, [('cifti_morph', 'in_file'),
734+
('source_files', 'source_file'),
735+
('cifti_density', 'density'),
736+
(('cifti_metadata', _read_jsons), 'meta_dict')])
737+
])
738+
# fmt:on
709739
return workflow
710740

711741

@@ -718,3 +748,10 @@ def _set_tpl_res(space, resolution):
718748
return int(resolution)
719749
except ValueError:
720750
return 1
751+
752+
753+
def _read_jsons(in_file):
754+
from json import loads
755+
from pathlib import Path
756+
757+
return [loads(Path(f).read_text()) for f in in_file]

nibabies/workflows/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ def init_single_subject_wf(subject_id, session_id=None):
331331
skull_strip_template=Reference.from_string(config.workflow.skull_strip_template)[0],
332332
sloppy=config.execution.sloppy,
333333
spaces=spaces,
334+
cifti_output=config.workflow.cifti_output,
334335
)
335336

336337
# fmt: off

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ dependencies = [
3232
"pybids >= 0.15.0",
3333
"requests",
3434
"sdcflows ~= 2.2.2",
35-
"smriprep ~= 0.10.0",
35+
"smriprep ~= 0.11.0",
3636
"tedana ~= 0.0.12",
3737
"templateflow >= 0.6",
3838
"toml",

0 commit comments

Comments
 (0)