Skip to content

Commit

Permalink
[FIX] Write updated doughnut file to disk at the end of `DicomReorgWo…
Browse files Browse the repository at this point in the history
…rkflow` and `BidsConversionWorkflow` (nipoppy#260)

* write doughnut in DicomReorgWorkflow's cleanup step

* write doughnut in BidsConversionWorkflow's cleanup step

* address code review comment about docstrings
  • Loading branch information
michellewang authored Jun 13, 2024
1 parent 3f02887 commit 5f107e0
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
10 changes: 10 additions & 0 deletions nipoppy_cli/nipoppy/workflows/bids_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,13 @@ def run_single(self, participant_id: str, session_id: str):
)

return invocation_and_descriptor

def run_cleanup(self, **kwargs):
"""
Clean up after main BIDS conversion part is run.
Specifically:
- Write updated doughnut file
"""
self.save_tabular_file(self.doughnut, self.layout.fpath_doughnut)
return super().run_cleanup(**kwargs)
10 changes: 10 additions & 0 deletions nipoppy_cli/nipoppy/workflows/dicom_reorg.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,13 @@ def run_main(self):
"Error reorganizing DICOM files for participant "
f"{participant_id} session {session_id}: {exception}"
)

def run_cleanup(self):
"""
Clean up after main DICOM reorg part is run.
Specifically:
- Write updated doughnut file
"""
self.save_tabular_file(self.doughnut, self.layout.fpath_doughnut)
return super().run_cleanup()
33 changes: 33 additions & 0 deletions nipoppy_cli/tests/test_workflow_bids_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,39 @@ def test_setup(config: Config, tmp_path: Path):
assert not workflow.dpath_pipeline.exists()


@pytest.mark.parametrize(
"doughnut",
[
Doughnut(),
Doughnut(
data={
Doughnut.col_participant_id: ["01"],
Doughnut.col_visit_id: ["1"],
Doughnut.col_session_id: ["1"],
Doughnut.col_datatype: "['anat']",
Doughnut.col_participant_dicom_dir: ["01"],
Doughnut.col_in_raw_imaging: [True],
Doughnut.col_in_sourcedata: [True],
Doughnut.col_in_bids: [True],
}
).validate(),
],
)
def test_cleanup(doughnut: Doughnut, tmp_path: Path):
workflow = BidsConversionRunner(
dpath_root=tmp_path / "my_dataset",
pipeline_name="",
pipeline_version="",
pipeline_step="",
)
workflow.doughnut = doughnut

workflow.run_cleanup()

assert workflow.layout.fpath_doughnut.exists()
assert Doughnut.load(workflow.layout.fpath_doughnut).equals(doughnut)


@pytest.mark.parametrize(
"doughnut_data,participant_id,session_id,expected",
[
Expand Down
29 changes: 29 additions & 0 deletions nipoppy_cli/tests/test_workflow_dicom_reorg.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pytest

from nipoppy.tabular.dicom_dir_map import DicomDirMap
from nipoppy.tabular.doughnut import Doughnut
from nipoppy.tabular.manifest import Manifest
from nipoppy.utils import participant_id_to_bids_participant, session_id_to_bids_session
from nipoppy.workflows.dicom_reorg import DicomReorgWorkflow, is_derived_dicom
Expand Down Expand Up @@ -430,3 +431,31 @@ def test_run_main(

else:
assert not dpath_to_check.exists()


@pytest.mark.parametrize(
"doughnut",
[
Doughnut(),
Doughnut(
data={
Doughnut.col_participant_id: ["01"],
Doughnut.col_visit_id: ["1"],
Doughnut.col_session_id: ["1"],
Doughnut.col_datatype: "['anat']",
Doughnut.col_participant_dicom_dir: ["01"],
Doughnut.col_in_raw_imaging: [True],
Doughnut.col_in_sourcedata: [True],
Doughnut.col_in_bids: [True],
}
).validate(),
],
)
def test_cleanup(doughnut: Doughnut, tmp_path: Path):
workflow = DicomReorgWorkflow(dpath_root=tmp_path / "my_dataset")
workflow.doughnut = doughnut

workflow.run_cleanup()

assert workflow.layout.fpath_doughnut.exists()
assert Doughnut.load(workflow.layout.fpath_doughnut).equals(doughnut)

0 comments on commit 5f107e0

Please sign in to comment.