@@ -21,13 +21,36 @@ class TemplateInputs(NamedTuple):
2121 sub: Subject label.
2222 sessions: Per-input session labels (parallel to ``files``).
2323 files: Per-session preprocessed T1w brain volumes.
24- bold_ref : Per-session preprocessed BOLD volumes (all tasks).
24+ bold_files : Per-session, unique preprocessed BOLD volumes (all tasks).
2525 """
2626
2727 sub : str
2828 sessions : list [str ]
2929 files : list [Path ]
30- bold_files : dict [str , Path ]
30+ bold_files : dict [BoldKey , Path ]
31+
32+
33+ # Use typing library instead of collections for static type hints
34+ class BoldKey (NamedTuple ):
35+ """Key with associated entities to use as dict key to represent bold filepath found.
36+
37+ Attributes:
38+ task: Task associated with file.
39+ run: Run associated with file.
40+ acq: Acquisition associated with file.
41+ dir: Direction associated with file.
42+ echo: Echo associated with file.
43+ part: Part associated with file.
44+ rec: Recording associated with file.
45+ """
46+
47+ task : str
48+ run : str | None = None
49+ acq : str | None = None
50+ dir : str | None = None
51+ echo : str | None = None
52+ part : str | None = None
53+ rec : str | None = None
3154
3255
3356def discover_template_inputs (
@@ -80,19 +103,9 @@ def discover_template_inputs(
80103 sub_bold = bold_rows .filter (
81104 (pl .col ("sub" ) == sub ) & (pl .col ("ses" ) == sessions [0 ])
82105 ).unique (subset = (* FUNC_GROUP_ENTITIES , "root" , "path" ))
83- # Check each task is unique, otherwise raise assertion error with details
84- if sub_bold .height != sub_bold .unique ().height :
85- conflicts = (
86- sub_bold .filter (pl .struct (FUNC_GROUP_ENTITIES ).is_duplicated ())
87- .group_by (FUNC_GROUP_ENTITIES )
88- .agg (pl .format ("{}/{}" , "root" , "path" ).alias ("paths" ))
89- )
90- raise AssertionError (
91- f"Found multiple non-matching grids for subject { sub } :\n "
92- + "\n " .join (str (dict (row )) for row in conflicts .iter_rows (named = True ))
93- )
94- bold_files = {
95- row ["task" ]: Path (row ["root" ]) / row ["path" ]
106+ bold_files : dict [BoldKey , Path ] = {
107+ BoldKey (** {ent : row [ent ] for ent in FUNC_GROUP_ENTITIES }): Path (row ["root" ])
108+ / row ["path" ]
96109 for row in sub_bold .iter_rows (named = True )
97110 }
98111 inputs .append (
@@ -112,8 +125,8 @@ def export_template(tpl: Bids, outputs: LongitudinalTemplateOutputs) -> None:
112125 outputs: Results from the longitudinal template workflow.
113126 """
114127 tpl .save (outputs .template , suffix = Suffix .T1W )
115- for btask , bold_template in outputs .bold_templates .items ():
116- tpl .save (bold_template , res = btask , suffix = Suffix .T1W )
128+ for bold_key , bold_template in outputs .bold_templates .items ():
129+ tpl .save (bold_template , res = bids_safe_label ( bold_key . task ) , suffix = Suffix .T1W )
117130 for ses , xfm in zip (outputs .sessions , outputs .transforms , strict = True ):
118131 ses_label = bids_safe_label (ses )
119132 tpl .save (
0 commit comments