Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion petprep/reports/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
)
Expand Down
27 changes: 27 additions & 0 deletions petprep/reports/tests/test_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -146,3 +147,29 @@ def test_pet_report(tmp_path, monkeypatch):
assert html_file.is_file()
html_content = html_file.read_text()
assert '<div id="PET"' in html_content


def test_reportlets_dir_scoped_to_subject(tmp_path, monkeypatch):
work_dir = tmp_path / 'work'
target = work_dir / 'reportlets' / 'petprep' / 'sub-02'
target.mkdir(parents=True)
(work_dir / 'reportlets' / 'petprep' / 'sub-002').mkdir(parents=True)

recorded_reportlets = []

def _record_reportlets_dir(*args, reportlets_dir=None, **kwargs):
recorded_reportlets.append(reportlets_dir)
return None

monkeypatch.setattr(core, 'run_reports', _record_reportlets_dir)
monkeypatch.setattr(config.execution, 'aggr_ses_reports', 4)

class _Layout:
def get_sessions(self, subject=None):
return []

monkeypatch.setattr(config.execution, 'layout', _Layout())

generate_reports(['02'], tmp_path, 'fake', work_dir=work_dir)

assert recorded_reportlets == [target]