Skip to content

Commit

Permalink
Merge pull request #130 from effigies/fix/higher_level_reports
Browse files Browse the repository at this point in the history
FIX: Restore level 2+ reports
  • Loading branch information
effigies authored Apr 18, 2019
2 parents c6ffb70 + 14b2579 commit 30dec1d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 20 deletions.
2 changes: 1 addition & 1 deletion fitlins/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def run_fitlins(argv=None):
for model in models:
analysis = Analysis(layout, model=model)
report_dicts = parse_directory(deriv_dir, work_dir, analysis)
write_report('unknown', report_dicts, run_context, deriv_dir)
write_report(report_dicts, run_context, deriv_dir)

return retcode

Expand Down
10 changes: 7 additions & 3 deletions fitlins/data/report.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,24 @@
<li>Model: {{ model_name }}</li>
</ul>
</div>
{% if warning or design_matrix_svg or contrasts_svg or correlation_matrix_svg %}
<div id="model">
<h1 class="sub-report-title">Model</h1>
{{ warning }}
{% if design_matrix_svg %}
<h2>Design matrix</h3>
<h2>Design matrix</h2>
<img src="{{ design_matrix_svg }}" />
{% endif %}
<h2>Contrasts</h3>
{% if contrasts_svg %}
<h2>Contrasts</h2>
<img src="{{ contrasts_svg }}" />
{% endif %}
{% if correlation_matrix_svg %}
<h2>Correlation matrix</h3>
<h2>Correlation matrix</h2>
<img src="{{ correlation_matrix_svg }}" />
{% endif %}
</div>
{% endif %}
{% if contrasts %}
<div id="contrasts">
<h1 class="sub-report-title">Contrasts</h1>
Expand Down
33 changes: 24 additions & 9 deletions fitlins/viz/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from ..utils import snake_to_camel

PATH_PATTERNS = [
'[sub-{subject}/][ses-{session}/][sub-{subject}_][ses-{session}_]'
'model-{model}[_run-{run}].html'
'reports/[sub-{subject}/][ses-{session}/][sub-{subject}_][ses-{session}_]'
'[run-{run}_]model-{model}.html'
]

add_config_paths(fitlins=pkgr.resource_filename('fitlins', 'data/fitlins.json'))
Expand Down Expand Up @@ -37,28 +37,43 @@ def parse_directory(deriv_dir, work_dir, analysis):
wd_layout = BIDSLayout(
str(Path(work_dir) / 'reportlets' / 'fitlins'),
validate=False)
contrast_svgs = fl_layout.get(extensions='.svg', suffix='contrasts')
all_pngs = fl_layout.get(extensions='.png')
fig_dirs = set(
(png.dirname, tuple(ent for ent in png.entities.items()
if ent[0] not in ('suffix', 'contrast')))
for png in fl_layout.get(extensions='.png'))

analyses = []
for contrast_svg in contrast_svgs:
ents = contrast_svg.entities
ents.pop('suffix')
for figdir, ent_tuple in fig_dirs:
ents = dict(ent_tuple)
ents.setdefault('subject', None)
ents.setdefault('session', None)
ents.setdefault('run', None)
contrast_matrix = fl_layout.get(extensions='.svg', suffix='contrasts', **ents)
correlation_matrix = fl_layout.get(extensions='.svg', suffix='corr',
**ents)
design_matrix = fl_layout.get(extensions='.svg', suffix='design', **ents)
job_desc = {
'ents': {k: v for k, v in ents.items() if v is not None},
'dataset': analysis.layout.root,
'model_name': analysis.model['name'],
'contrasts_svg': contrast_svg.path,
}
if ents.get('subject'):
job_desc['subject_id'] = ents.get('subject')
if contrast_matrix:
job_desc['contrasts_svg']: contrast_matrix[0].path
if correlation_matrix:
job_desc['correlation_matrix_svg'] = correlation_matrix[0].path
if design_matrix:
job_desc['design_matrix_svg'] = design_matrix[0].path
if ents['run'] is not None:
job_desc['level'] = 'run'
elif ents['session'] is not None:
job_desc['level'] = 'session'
elif ents['subject'] is not None:
job_desc['level'] = 'subject'
else:
job_desc['level'] = 'dataset'

snippet = wd_layout.get(extensions='.html', suffix='snippet', **ents)
if snippet:
Expand All @@ -77,7 +92,7 @@ def parse_directory(deriv_dir, work_dir, analysis):
return analyses


def write_report(level, report_dicts, run_context, deriv_dir):
def write_report(report_dicts, run_context, deriv_dir):
fl_layout = BIDSLayout(
deriv_dir, config=['bids', 'derivatives', 'fitlins'])

Expand All @@ -91,7 +106,7 @@ def write_report(level, report_dicts, run_context, deriv_dir):
ents = context['ents'].copy()
ents['model'] = snake_to_camel(context['model_name'])
target_file = op.join(deriv_dir, fl_layout.build_path(ents, PATH_PATTERNS))
html = tpl.render(deroot({'level': level, **context, **run_context},
html = tpl.render(deroot({**context, **run_context},
op.dirname(target_file)))
with open(target_file, 'w') as fobj:
fobj.write(html)
14 changes: 7 additions & 7 deletions fitlins/workflows/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,18 @@ def init_fitlins_wf(bids_dir, derivatives, out_dir, analysis_level, space,
l1_model.inputs.smoothing_fwhm = smoothing_fwhm

# Set up common patterns
image_pattern = '[sub-{subject}/][ses-{session}/]' \
image_pattern = 'reports/[sub-{subject}/][ses-{session}/]figures/[run-{run}/]' \
'[sub-{subject}_][ses-{session}_]task-{task}[_acq-{acquisition}]' \
'[_rec-{reconstruction}][_run-{run}][_echo-{echo}]_bold_' \
'[_rec-{reconstruction}][_run-{run}][_echo-{echo}]_' \
'{suffix<design|corr|contrasts>}.svg'
contrast_plot_pattern = '[sub-{subject}/][ses-{session}/]' \
contrast_plot_pattern = 'reports/[sub-{subject}/][ses-{session}/]figures/[run-{run}/]' \
'[sub-{subject}_][ses-{session}_]task-{task}[_acq-{acquisition}]' \
'[_rec-{reconstruction}][_run-{run}][_echo-{echo}]_bold' \
'[_space-{space}]_contrast-{contrast}_ortho.png'
'[_rec-{reconstruction}][_run-{run}][_echo-{echo}][_space-{space}]_' \
'contrast-{contrast}_ortho.png'
contrast_pattern = '[sub-{subject}/][ses-{session}/]' \
'[sub-{subject}_][ses-{session}_]task-{task}[_acq-{acquisition}]' \
'[_rec-{reconstruction}][_run-{run}][_echo-{echo}]_bold' \
'[_space-{space}]_contrast-{contrast}_{suffix<effect|stat>}.nii.gz'
'[_rec-{reconstruction}][_run-{run}][_echo-{echo}][_space-{space}]_' \
'contrast-{contrast}_{suffix<effect|stat>}.nii.gz'

# Set up general interfaces
#
Expand Down

0 comments on commit 30dec1d

Please sign in to comment.