diff --git a/heudiconv/main.py b/heudiconv/main.py index 5036e2de..a98eee9c 100644 --- a/heudiconv/main.py +++ b/heudiconv/main.py @@ -57,7 +57,6 @@ def process_extra_commands( outdir: str, command: str, files: list[str], - dicom_dir_template: Optional[str], heuristic: Optional[str], session: Optional[str], subjs: Optional[list[str]], @@ -75,13 +74,6 @@ def process_extra_commands( Heudiconv command to run files : list of str List of files - dicom_dir_template : str - Location of dicomdir that can be indexed with subject id - {subject} and session {session}. Tarballs (can be compressed) - are supported in addition to directory. All matching tarballs - for a subject are extracted and their content processed in a - single pass. If multiple tarballs are found, each is assumed to - be a separate session and the 'session' argument is ignored. heuristic : str Path to heuristic file or name of builtin heuristic. session : str @@ -101,7 +93,7 @@ def process_extra_commands( heuristic_ls = getattr(heuristic_mod, "ls", None) for fname in files: study_sessions = get_study_sessions( - dicom_dir_template, + None, [fname], heuristic_mod, outdir, @@ -111,9 +103,10 @@ def process_extra_commands( ) print(fname) for study_session, sequences in study_sessions.items(): + assert isinstance(sequences, dict) suf = "" if heuristic_ls: - suf += heuristic_ls(study_session, sequences) + suf += heuristic_ls(study_session, list(sequences.keys())) print("\t%s %d sequences%s" % (str(study_session), len(sequences), suf)) elif command == "populate-templates": ensure_heuristic_arg(heuristic) @@ -366,11 +359,11 @@ def workflow( if command: if files is None: raise ValueError("'command' given but 'files' is None") + assert dicom_dir_template is None process_extra_commands( outdir, command, files, - dicom_dir_template, heuristic, session, subjs, diff --git a/heudiconv/parser.py b/heudiconv/parser.py index 750cc762..354b1601 100644 --- a/heudiconv/parser.py +++ b/heudiconv/parser.py @@ -10,7 +10,7 @@ import re import shutil from types import ModuleType -from typing import Any, Optional +from typing import Optional from .dicoms import group_dicoms_into_seqinfos from .utils import SeqInfo, StudySessionInfo, TempDirs, docstring_parameter @@ -156,7 +156,7 @@ def get_study_sessions( session: Optional[str], sids: Optional[list[str]], grouping: str = "studyUID", -) -> dict[StudySessionInfo, Any]: +) -> dict[StudySessionInfo, list[str] | dict[SeqInfo, list[str]]]: """Sort files or dicom seqinfos into study_sessions. study_sessions put together files for a single session of a subject @@ -168,7 +168,7 @@ def get_study_sessions( - if files_opt is provided, sorts all DICOMs it can find under those paths """ - study_sessions: dict[StudySessionInfo, Any] = {} + study_sessions: dict[StudySessionInfo, list[str] | dict[SeqInfo, list[str]]] = {} if dicom_dir_template: dicom_dir_template = op.abspath(dicom_dir_template) diff --git a/heudiconv/tests/test_main.py b/heudiconv/tests/test_main.py index bbb869a1..c31c0405 100644 --- a/heudiconv/tests/test_main.py +++ b/heudiconv/tests/test_main.py @@ -347,7 +347,6 @@ def test_populate_intended_for( bids_folder, "populate-intended-for", [], - "", "example", session, subjects, @@ -374,7 +373,7 @@ def test_populate_intended_for( if session: os.makedirs(opj(subj_dir, "ses-" + session)) process_extra_commands( - outdir, "populate-intended-for", [], "", "example", None, [], "all" + outdir, "populate-intended-for", [], "example", None, [], "all" ) for s in subjects: expected_info = 'Adding "IntendedFor" to the fieldmaps in ' + opj(