Skip to content

Commit 957080a

Browse files
committed
fix cubids validate --participant-label
1 parent 6c97441 commit 957080a

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

cubids/workflows.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,9 @@ def validate(
178178
validation_scope : :obj:`str`
179179
Scope of validation: 'dataset' validates the entire dataset,
180180
'subject' validates each subject separately.
181-
participant_label : :obj:`list` of :obj:`str`
181+
participant_label : :obj:`list` of :obj:`str` or None
182182
Filter the validation to only include the listed subjects.
183+
Only applies when validation_scope='subject'. Ignored for dataset-level validation.
183184
local_validator : :obj:`bool`
184185
Use the local bids validator.
185186
ignore_nifti_headers : :obj:`bool`
@@ -207,6 +208,12 @@ def validate(
207208
# Run directly from python using subprocess
208209
if validation_scope == "dataset":
209210
# run on full dataset
211+
# Note: participant_label is ignored for dataset-level validation
212+
if participant_label:
213+
logger.warning(
214+
"participant_label is ignored when validation_scope='dataset'. "
215+
"Use validation_scope='subject' to filter by participant."
216+
)
210217
call = build_validator_call(
211218
str(bids_dir),
212219
local_validator,
@@ -249,19 +256,25 @@ def validate(
249256
# user may be in python session, return dataframe
250257
return parsed
251258
else:
252-
# logger.info("Prepping sequential validator run...")
253-
254259
# build a dictionary with {SubjectLabel: [List of files]}
255-
subjects_dict = build_subject_paths(bids_dir)
256-
257-
# logger.info("Running validator sequentially...")
258-
# iterate over the dictionary
260+
# if participant_label is provided, only build paths for those subjects
261+
if participant_label:
262+
# Build paths only for requested subjects to avoid scanning entire dataset
263+
subjects_dict = {}
264+
for subject_label in participant_label:
265+
subject_path = os.path.join(bids_dir, subject_label)
266+
if os.path.isdir(subject_path):
267+
subject_dict = build_first_subject_path(bids_dir, subject_path)
268+
subjects_dict.update(subject_dict)
269+
else:
270+
logger.warning(f"Subject directory not found: {subject_path}")
271+
else:
272+
# Build paths for all subjects
273+
subjects_dict = build_subject_paths(bids_dir)
259274

260275
parsed = []
261276

262-
if participant_label:
263-
subjects_dict = {k: v for k, v in subjects_dict.items() if k in participant_label}
264-
assert len(list(subjects_dict.keys())) > 1, "No subjects found in filter"
277+
assert len(list(subjects_dict.keys())) >= 1, "No subjects found"
265278

266279
# Convert schema Path to string if it exists (for multiprocessing pickling)
267280
schema_str = str(schema) if schema is not None else None

0 commit comments

Comments
 (0)