diff --git a/petprep/reports/core.py b/petprep/reports/core.py index a4b83f8c..0199ed01 100644 --- a/petprep/reports/core.py +++ b/petprep/reports/core.py @@ -82,6 +82,21 @@ def generate_reports( errors = [] for subject_label in subject_list: subject_label = subject_label.removeprefix('sub-') + + subject_reportlets_dir = reportlets_dir + if reportlets_dir is not None: + subject_reportlets_dir = next( + ( + candidate + for candidate in ( + reportlets_dir / 'petprep' / f'sub-{subject_label}', + reportlets_dir / f'sub-{subject_label}', + reportlets_dir, + ) + if candidate.exists() + ), + reportlets_dir, + ) # The number of sessions is intentionally not based on session_list but # on the total number of sessions, because I want the final derivatives # folder to be the same whether sessions were run one at a time or all-together. @@ -106,7 +121,7 @@ def generate_reports( run_uuid, bootstrap_file=bootstrap_file, out_filename=html_report, - reportlets_dir=reportlets_dir, + reportlets_dir=subject_reportlets_dir, errorname=f'report-{run_uuid}-{subject_label}.err', subject=subject_label, ) diff --git a/petprep/reports/tests/test_reports.py b/petprep/reports/tests/test_reports.py index 75c122fd..b7457ff4 100644 --- a/petprep/reports/tests/test_reports.py +++ b/petprep/reports/tests/test_reports.py @@ -4,6 +4,7 @@ import pytest from bids.layout import BIDSLayout +import petprep.reports.core as core from petprep.reports.core import generate_reports from ... import config, data @@ -146,3 +147,29 @@ def test_pet_report(tmp_path, monkeypatch): assert html_file.is_file() html_content = html_file.read_text() assert '