Skip to content

Commit

Permalink
Update aroma.py
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalo committed May 5, 2024
1 parent 69c0b54 commit 3e9c3a2
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/fmripost_aroma/workflows/aroma.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,24 @@ def init_ica_aroma_wf(
(smooth, melodic, [("smoothed_file", "in_files")]),
]) # fmt:skip

select_melodic_files = pe.Node(
niu.Function(
function=_select_melodic_files,
input_names=["melodic_dir"],
output_names=["mixing", "component_maps"],
),
name="select_melodic_files",
)
workflow.connect([(melodic, select_melodic_files, [("out_dir", "melodic_dir")])])

# Run the ICA-AROMA classifier
ica_aroma = pe.Node(AROMAClassifier(TR=metadata["RepetitionTime"]))
workflow.connect([
(inputnode, ica_aroma, [("movpar_file", "motion_parameters")]),
# TODO: Add node to select the MELODIC files AROMA uses
(melodic, ica_aroma, [("out_dir", "melodic_dir")]),
(select_melodic_files, ica_aroma, [
("mixing", "mixing"),
("component_maps", "component_maps"),
]),
]) # fmt:skip

# Generate the ICA-AROMA report
Expand Down Expand Up @@ -448,3 +460,14 @@ def _get_wf_name(bold_fname, prefix):
fname = split_filename(bold_fname)[1]
fname_nosub = "_".join(fname.split("_")[1:-1])
return f"{prefix}_{fname_nosub.replace('-', '_')}_wf"


def _select_melodic_files(melodic_dir):
"""Select the mixing and component maps from the Melodic output."""
import os

mixing = os.path.join(melodic_dir, "melodic_mix")
assert os.path.isfile(mixing), f"Missing MELODIC mixing matrix: {mixing}"
component_maps = os.path.join(melodic_dir, "melodic_IC.nii.gz")
assert os.path.isfile(component_maps), f"Missing MELODIC ICs: {component_maps}"
return mixing, component_maps

0 comments on commit 3e9c3a2

Please sign in to comment.