Skip to content

Commit

Permalink
Merge pull request #31 from childmindresearch/blink_removal_integration
Browse files Browse the repository at this point in the history
Blink removal integration
  • Loading branch information
Sam54000 authored Nov 4, 2024
2 parents 2491349 + 19d0c8a commit b42d9d9
Show file tree
Hide file tree
Showing 18 changed files with 3,681 additions and 527 deletions.
1 change: 1 addition & 0 deletions output_annotations_serie_cleaning_out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python: can't open file '/home/slouviot/01_projects/eeg_research/annotation_serie_pipeline.py': [Errno 2] No such file or directory
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 23 additions & 18 deletions src/eeg_research/cli/pipelines/eeg_fmri_cleaning.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
and adjust the cleaning parameters as necessary to achieve optimal results.
"""

from eeg_research.cli.tools.bids_parser import BIDSParser
from eeg_research.cli.tools.bids_parser import BIDSCreator, bids_args_parser
from eeg_research.cli.tools.interactive_menu import InteractiveMenu
from eeg_research.preprocessing.pipelines.bcg_cleaning_pipeline import clean_bcg
from eeg_research.preprocessing.pipelines.gradient_cleaning_pipeline import (
Expand All @@ -83,20 +83,23 @@

def main() -> None:
"""Main function."""
parser = BIDSParser()
parser = bids_args_parser()
bids_dataset = BIDSCreator(**parser)

scripts = {
"gradient": "Gradient Cleaning",
"bcg": "BCG Cleaning",
"qc": "Quality Control",
}

if parser.args.interactive:

# If the user wants to run the interactive menu
if parser['interactive']:
# If script flags are provided, preselect the scripts based on the flags
preselection = [
i
for i, arg in enumerate(
[parser.args.gradient, parser.args.bcg, parser.args.qc]
[parser['gradient'], parser['bcg'], parser['qc']]
)
if arg
]
Expand All @@ -109,49 +112,51 @@ def main() -> None:
)
selected_scripts = menu.get_selected_items()

layout = parser.update_layout(parser.entities)
# Create a BIDSLayout object for the data folder with given entities
layout = bids_dataset.update_layout(bids_dataset.entities)

available_entities = layout.get_entities()

# For each entity, get the available options and ask the user to select
for entity in parser.entities.keys():
# For each entity, get the available options and ask the user to select some
for entity in bids_dataset.entities.keys():
# Skip if the entity is not available or already selected
if (
entity not in available_entities.keys()
or parser.entities[entity] is not None
or bids_dataset.entities[entity] is not None
):
continue
# Get the available options for the entity
menu_entries = getattr(layout, f"get_{entity}s")()
# If there is only one option, select it automatically
if len(menu_entries) == 1:
parser.entities[entity] = menu_entries[0]
# If there are multiple options, ask the user to select
bids_dataset.entities[entity] = menu_entries[0]
# If there are multiple options, ask the user to select some
elif len(menu_entries) > 1:
menu = InteractiveMenu(
menu_entries=menu_entries,
entity=entity,
title=f"Select the {entity}s you want to include:",
)
parser.entities[entity] = menu.get_selected_items()
bids_dataset.entities[entity] = menu.get_selected_items()
# Update the BIDSLayout object to only include selected entities
layout = parser.update_layout(parser.entities)
layout = bids_dataset.update_layout( bids_dataset.entities)

# Remove None values from the selected entities
selected_entities = {k: v for k, v in parser.entities.items() if v is not None}
selected_entities = {k: v for k, v in bids_dataset.entities.items()
if v is not None}
# Get the files based on the selected entities
files = parser.layout.get(return_type="file", **selected_entities)
files = bids_dataset.layout.get(return_type="file", **selected_entities)

else:
# Select the scripts based on the flags
selected_scripts = [
scripts[script] for script in scripts if getattr(parser.args, script)
scripts[script] for script in scripts if parser.get(script, False)
]
# Remove None values from the entities dictionary
selected_entities = {k: v for k, v in parser.entities.items() if v is not None}
selected_entities = {k: v for k, v in bids_dataset.entities.items()
if v is not None}

# Get the files based on the flags
files = parser.layout.get(return_type="file", **selected_entities)
files = bids_dataset.layout.get(return_type="file", **selected_entities)

if not files:
raise FileNotFoundError("No valid files found with the given arguments.")
Expand Down
Loading

0 comments on commit b42d9d9

Please sign in to comment.