Skip to content

Commit

Permalink
Merge pull request #7 from GalKepler/eddy_fsl
Browse files Browse the repository at this point in the history
found a way around dwifslpreproc
  • Loading branch information
GalKepler authored Jul 24, 2024
2 parents 41ab300 + 30d55af commit fa0213f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/keprep/interfaces/bids.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
from pathlib import Path
from typing import Union

from bids import BIDSLayout
from bids.layout import Query, parse_file_entities
Expand All @@ -19,7 +18,8 @@
LOGGER = logging.getLogger("nipype.interface")

CUSTOM_PATH_PATTERNS = [
"sub-{subject}[/ses-{session}]/{datatype<dwi>|dwi}/sub-{subject}[_ses-{session}][_acq-{acquisition}][_rec-{reconstruction}][_dir-{direction}][_run-{run}][_space-{space}][_cohort-{cohort}][_res-{resolution}][_desc-{desc}]_{suffix<dwi|dwiref|epiref|lowb|dseg|streamlines>}{extension<.json|.nii.gz|.nii|.tck|.trk>|.nii.gz}" # pylint: disable=line-too-long
"sub-{subject}[/ses-{session}]/{datatype<dwi>|dwi}/sub-{subject}[_ses-{session}][_acq-{acquisition}][_rec-{reconstruction}][_dir-{direction}][_run-{run}][_space-{space}][_cohort-{cohort}][_res-{resolution}][_desc-{desc}]_{suffix<dwi|dwiref|epiref|lowb|dseg|streamlines>}{extension<.json|.nii.gz|.nii|.tck|.trk>|.nii.gz}", # pylint: disable=line-too-long
"sub-{subject}[/ses-{session}]/{datatype<dwi>|dwi}/{desc}",
]


Expand Down
31 changes: 31 additions & 0 deletions src/keprep/workflows/dwi/stages/derivatives.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
DWI_PREPROC_BASE_ENTITIES = dict(desc="preproc", space="dwi", datatype="dwi")


def _eddy_qc_dds(eddy_qc, source_file):
import shutil
from pathlib import Path

destination = Path(source_file).parent / "eddy_qc"
if destination.exists():
shutil.rmtree(destination)
shutil.copytree(eddy_qc, destination)


def init_derivatives_wf(name: str = "derivatives_wf") -> pe.Workflow:
"""
Build the workflow that saves derivatives.
Expand Down Expand Up @@ -39,6 +49,7 @@ def init_derivatives_wf(name: str = "derivatives_wf") -> pe.Workflow:
"dwi2t1w_aff",
"t1w2dwi_aff",
"dwi_brain_mask",
"eddy_qc",
"sdc_report",
"coreg_report",
"unsifted_tck",
Expand All @@ -48,6 +59,16 @@ def init_derivatives_wf(name: str = "derivatives_wf") -> pe.Workflow:
name="inputnode",
)

ds_eddy_qc = pe.Node(
niu.Function(
input_names=["eddy_qc", "source_file"],
output_names=[],
function=_eddy_qc_dds,
),
name="ds_eddy_qc",
run_without_submitting=True,
)

ds_sdc_report = pe.Node(
DerivativesDataSink(
base_directory=output_dir,
Expand Down Expand Up @@ -194,6 +215,16 @@ def init_derivatives_wf(name: str = "derivatives_wf") -> pe.Workflow:

workflow.connect(
[
(
inputnode,
ds_eddy_qc,
[("eddy_qc", "eddy_qc")],
),
(
ds_dwi_preproc,
ds_eddy_qc,
[("out_file", "source_file")],
),
(
inputnode,
ds_sdc_report,
Expand Down
5 changes: 4 additions & 1 deletion src/keprep/workflows/dwi/stages/eddy.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ def init_eddy_wf(name: str = "eddy_wf") -> pe.Workflow:
)

outputnode = pe.Node(
niu.IdentityInterface(fields=["dwi_preproc", "dwi_reference_distorted"]),
niu.IdentityInterface(
fields=["dwi_preproc", "dwi_reference_distorted", "eddy_qc"]
),
name="outputnode",
)

Expand Down Expand Up @@ -156,6 +158,7 @@ def init_eddy_wf(name: str = "eddy_wf") -> pe.Workflow:
outputnode,
[
("out_file", "dwi_preproc"),
("eddyqc_all", "eddy_qc"),
],
),
]
Expand Down
10 changes: 8 additions & 2 deletions src/keprep/workflows/dwi/workflow.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from pathlib import Path
from typing import Union

from bids import BIDSLayout
from nipype.interfaces import utility as niu
Expand Down Expand Up @@ -71,7 +70,7 @@ def init_dwi_preproc_wf(dwi_file: str | Path, subject_data: dict):
inputnode.inputs.fmap_bval = Path(layout.get_bval(fieldmap))
inputnode.inputs.fmap_json = Path(layout.get_nearest(fieldmap, extension="json"))

outputnode = pe.Node(
outputnode = pe.Node( # noqa: F841
niu.IdentityInterface(
fields=["dwi_preproc", "dwi_reference", "dwi_mask"],
),
Expand Down Expand Up @@ -283,6 +282,13 @@ def init_dwi_preproc_wf(dwi_file: str | Path, subject_data: dict):
("dwi_file", "inputnode.source_file"),
],
),
(
eddy_wf,
ds_workflow,
[
("outputnode.eddy_qc", "inputnode.eddy_qc"),
],
),
(
post_eddy,
ds_workflow,
Expand Down

0 comments on commit fa0213f

Please sign in to comment.