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

Collect aslref-space CBF derivatives as part of precomputed cache #370

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 102 additions & 2 deletions aslprep/data/io_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"queries": {
"baseline": {
"hmc": {
"datatype": "func",
"datatype": "perf",
"space": null,
"desc": "hmc",
"suffix": "aslref",
Expand All @@ -12,14 +12,114 @@
]
},
"coreg": {
"datatype": "func",
"datatype": "perf",
"space": null,
"desc": "coreg",
"suffix": "aslref",
"extension": [
".nii.gz",
".nii"
]
},
"mean_cbf": {
"datatype": "perf",
"space": null,
"desc": null,
"suffix": "cbf",
"extension": [
".nii.gz",
".nii"
]
},
"cbf_ts": {
"datatype": "perf",
"space": null,
"desc": "timeseries",
"suffix": "cbf",
"extension": [
".nii.gz",
".nii"
]
},
"att": {
"datatype": "perf",
"space": null,
"desc": null,
"suffix": "att",
"extension": [
".nii.gz",
".nii"
]
},
"cbf_ts_score": {
"datatype": "perf",
"space": null,
"desc": "scoreTimeseries",
"suffix": "cbf",
"extension": [
".nii.gz",
".nii"
]
},
"mean_cbf_score": {
"datatype": "perf",
"space": null,
"desc": "score",
"suffix": "cbf",
"extension": [
".nii.gz",
".nii"
]
},
"mean_cbf_scrub": {
"datatype": "perf",
"space": null,
"desc": "scrub",
"suffix": "cbf",
"extension": [
".nii.gz",
".nii"
]
},
"mean_cbf_basil": {
"datatype": "perf",
"space": null,
"desc": "basil",
"suffix": "cbf",
"extension": [
".nii.gz",
".nii"
]
},
"mean_cbf_gm_basil": {
"datatype": "perf",
"space": null,
"desc": "basilGM",
"suffix": "cbf",
"extension": [
".nii.gz",
".nii"
]
},
"mean_cbf_wm_basil": {
"datatype": "perf",
"space": null,
"desc": "basilWM",
"suffix": "cbf",
"extension": [
".nii.gz",
".nii"
]
},
"att_basil": {
"datatype": "perf",
"space": null,
"desc": "basil",
"suffix": "att",
"extension": [
".nii.gz",
".nii"
]
}
},
"transforms": {
Expand Down
4 changes: 4 additions & 0 deletions aslprep/tests/data/expected_outputs_test_003_minimal.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ sub-01
sub-01.html
sub-01/ses-1
sub-01/ses-1/perf
sub-01/ses-1/perf/sub-01_ses-1_cbf.json
sub-01/ses-1/perf/sub-01_ses-1_cbf.nii.gz
sub-01/ses-1/perf/sub-01_ses-1_desc-coreg_aslref.json
sub-01/ses-1/perf/sub-01_ses-1_desc-coreg_aslref.nii.gz
sub-01/ses-1/perf/sub-01_ses-1_desc-hmc_aslref.json
sub-01/ses-1/perf/sub-01_ses-1_desc-hmc_aslref.nii.gz
sub-01/ses-1/perf/sub-01_ses-1_desc-timeseries_cbf.json
sub-01/ses-1/perf/sub-01_ses-1_desc-timeseries_cbf.nii.gz
sub-01/ses-1/perf/sub-01_ses-1_from-aslref_to-T1w_mode-image_xfm.json
sub-01/ses-1/perf/sub-01_ses-1_from-aslref_to-T1w_mode-image_xfm.txt
sub-01/ses-1/perf/sub-01_ses-1_from-orig_to-aslref_mode-image_xfm.json
Expand Down
4 changes: 4 additions & 0 deletions aslprep/tests/data/expected_outputs_test_003_resampling.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ sub-01
sub-01.html
sub-01/ses-1
sub-01/ses-1/perf
sub-01/ses-1/perf/sub-01_ses-1_cbf.json
sub-01/ses-1/perf/sub-01_ses-1_cbf.nii.gz
sub-01/ses-1/perf/sub-01_ses-1_desc-confounds_timeseries.tsv
sub-01/ses-1/perf/sub-01_ses-1_desc-coreg_aslref.json
sub-01/ses-1/perf/sub-01_ses-1_desc-coreg_aslref.nii.gz
sub-01/ses-1/perf/sub-01_ses-1_desc-hmc_aslref.json
sub-01/ses-1/perf/sub-01_ses-1_desc-hmc_aslref.nii.gz
sub-01/ses-1/perf/sub-01_ses-1_desc-qualitycontrol_cbf.tsv
sub-01/ses-1/perf/sub-01_ses-1_desc-timeseries_cbf.json
sub-01/ses-1/perf/sub-01_ses-1_desc-timeseries_cbf.nii.gz
sub-01/ses-1/perf/sub-01_ses-1_from-aslref_to-T1w_mode-image_xfm.json
sub-01/ses-1/perf/sub-01_ses-1_from-aslref_to-T1w_mode-image_xfm.txt
sub-01/ses-1/perf/sub-01_ses-1_from-orig_to-aslref_mode-image_xfm.json
Expand Down
18 changes: 16 additions & 2 deletions aslprep/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,15 @@ def test_test_003_minimal(data_dir, output_dir, working_dir):
extra_params=["--fs-no-reconall"],
)

base_test_003(
data_dir,
output_dir,
working_dir,
level="full",
level_name="minimal",
extra_params=["--fs-no-reconall"],
)


@pytest.mark.test_003_resampling
def test_test_003_resampling(data_dir, output_dir, working_dir):
Expand All @@ -359,7 +368,7 @@ def test_test_003_full(data_dir, output_dir, working_dir):
)


def base_test_003(data_dir, output_dir, working_dir, level, extra_params):
def base_test_003(data_dir, output_dir, working_dir, level, level_name=None, extra_params=None):
"""Run aslprep on sub-01.

This dataset is Siemens.
Expand All @@ -369,7 +378,11 @@ def base_test_003(data_dir, output_dir, working_dir, level, extra_params):

dataset_dir = download_test_data(TEST_NAME, data_dir)
download_test_data("anatomical", data_dir)
level_test_name = f"{TEST_NAME}_{level}"
if level_name:
level_test_name = f"{TEST_NAME}_{level_name}"
else:
level_test_name = f"{TEST_NAME}_{level}"

out_dir = os.path.join(output_dir, level_test_name, "aslprep")
work_dir = os.path.join(working_dir, level_test_name)

Expand All @@ -383,6 +396,7 @@ def base_test_003(data_dir, output_dir, working_dir, level, extra_params):
"--omp-nthreads=1",
"--output-spaces",
"asl",
"MNI152NLin2009cAsym",
"--use-syn-sdc",
"--m0_scale=10",
f"--fs-subjects-dir={os.path.join(data_dir, 'anatomical/freesurfer')}",
Expand Down
45 changes: 29 additions & 16 deletions aslprep/workflows/asl/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from aslprep.workflows.asl.fit import init_asl_fit_wf, init_asl_native_wf
from aslprep.workflows.asl.outputs import (
init_ds_asl_native_wf,
init_ds_cbf_native_wf,
init_ds_ciftis_wf,
init_ds_volumes_wf,
)
Expand Down Expand Up @@ -380,6 +381,7 @@ def init_asl_wf(
processing_target=processing_target,
dummy_scans=dummy_scans,
m0_scale=m0_scale,
precomputed=precomputed,
scorescrub=scorescrub,
basil=basil,
smooth_kernel=smooth_kernel,
Expand All @@ -404,6 +406,30 @@ def init_asl_wf(
]),
]) # fmt:skip

# If we want aslref-space outputs, then call the appropriate workflow
aslref_out = bool(nonstd_spaces.intersection(("func", "run", "asl", "aslref", "sbref")))
aslref_out &= config.workflow.level == "full"

# Write out aslref-space CBF derivatives for the minimal and resampling workflows,
# or if we want them anyway.
if (config.workflow.level != "full") or aslref_out:
ds_cbf_native_wf = init_ds_cbf_native_wf(
bids_root=str(config.execution.bids_dir),
output_dir=config.execution.aslprep_dir,
metadata=metadata,
cbf_3d=cbf_3d_derivs,
cbf_4d=cbf_4d_derivs,
att=att_derivs,
)
ds_cbf_native_wf.inputs.inputnode.source_files = [asl_file]

for cbf_deriv in cbf_derivs:
workflow.connect([
(cbf_wf, ds_cbf_native_wf, [
(f"outputnode.{cbf_deriv}", f"inputnode.{cbf_deriv}"),
]),
]) # fmt:skip

if config.workflow.level == "minimal":
return workflow

Expand All @@ -412,7 +438,7 @@ def init_asl_wf(
# - Calculate ASL confounds and CBF QC metrics.
# - Generate plots for CBF.
# - Resample to anatomical space.
# - Save aslref-space outputs only if requested.
# - Save aslref-space ASL outputs only if requested.
#

asl_confounds_wf = init_asl_confounds_wf(
Expand Down Expand Up @@ -482,7 +508,8 @@ def init_asl_wf(
]) # fmt:skip

# Plot CBF outputs.
# NOTE: CIFTI input won't be provided unless level is set to 'full'.
# NOTE: CIFTI input won't be provided unless level is set to 'full' and CIFTI outputs are
# requested.
cbf_reporting_wf = init_cbf_reporting_wf(
metadata=metadata,
plot_timeseries=not (is_multi_pld or use_ge or (config.workflow.level == "resampling")),
Expand Down Expand Up @@ -519,19 +546,12 @@ def init_asl_wf(
(cbf_wf, cbf_reporting_wf, [(f"outputnode.{cbf_deriv}", f"inputnode.{cbf_deriv}")]),
]) # fmt:skip

# If we want aslref-space outputs, then call the appropriate workflow
aslref_out = bool(nonstd_spaces.intersection(("func", "run", "asl", "aslref", "sbref")))
aslref_out &= config.workflow.level == "full"

if aslref_out:
ds_asl_native_wf = init_ds_asl_native_wf(
bids_root=str(config.execution.bids_dir),
output_dir=config.execution.aslprep_dir,
asl_output=aslref_out,
metadata=metadata,
cbf_3d=cbf_3d_derivs,
cbf_4d=cbf_4d_derivs,
att=att_derivs,
)
ds_asl_native_wf.inputs.inputnode.source_files = [asl_file]

Expand All @@ -540,13 +560,6 @@ def init_asl_wf(
(asl_native_wf, ds_asl_native_wf, [("outputnode.asl_native", "inputnode.asl")]),
]) # fmt:skip

for cbf_deriv in cbf_derivs:
workflow.connect([
(cbf_wf, ds_asl_native_wf, [
(f"outputnode.{cbf_deriv}", f"inputnode.{cbf_deriv}"),
]),
]) # fmt:skip

if config.workflow.level == "resampling":
# Fill in datasinks of reportlets seen so far
for node in workflow.list_node_names():
Expand Down
Loading