Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 14, 2025

Implements a Snakemake script rule that generates comprehensive registration quality control visualizations using nilearn. The script produces an HTML report with embedded figures comparing template and transformed subject images with overlays, contours, atlas labels, and warp field analysis—suitable for both QC and presentation materials.

Implementation

  • Script (spimquant/workflow/scripts/reg_qc_report.py): Generates multi-modal QC visualizations and HTML report:

    • Affine and deformable registration comparisons (orthogonal views, overlays, contours)
    • Atlas segmentation overlays on template and warped subject
    • Warp field magnitude and directional components
    • All inputs accessed via snakemake object (no argparsing)
    • Generates self-contained HTML with embedded base64-encoded PNG figures
    • Professional CSS styling with tables, sections, and figure captions
    • Includes image information table and deformation field statistics
  • Rule (registration_qc_report in templatereg.smk):

    • Uses script: directive with subject-level wildcards
    • BIDS output: datatype=micr, suffix=regqc.html
    • Inputs: template, subject, affine/deform warped images, warp field, dseg
    • Added to all_segment target for automatic generation
  • Environment (spimquant/workflow/envs/nilearn.yaml): nilearn, nibabel, matplotlib, numpy

HTML Report Features

  • Self-contained HTML file with no external dependencies
  • All 10 QC visualizations embedded as base64-encoded images
  • Professional styling with CSS (blue headers, styled tables, figure boxes)
  • Comprehensive text descriptions for each section
  • Image information and deformation field statistics tables
  • Figure captions and summary checklist
  • Responsive design suitable for presentations

The script executes automatically during participant-level processing and outputs an HTML report with embedded visualizations and descriptive text.

Original prompt

add a new rule in the templatereg smk file that uses a ipynb notebook to produce a quality control output on the registration, using nilearn to make plots comparing the template and trnsformed subject, and transformed target and subject, those with and without outlines, labelmaps too, visualization of warp fields. this will be used for QC'ing the registration but also to produce figures for slides/presentations. the snakemake rule should use a notebook, e.g. as in:

rule hello:
output:
"test.txt"
log:
# optional path to the processed notebook
notebook="logs/notebooks/processed_notebook.ipynb"
notebook:
"notebooks/hello.py.ipynb"

inputs should be any subject-level images or template iamges needed for the notebook, these are accessed with snakemake.input.* so no argparsing is needed.. wildcards should just be subject level, and include this notebook in the default target rules so it is always generated. the noteobok itself can live in the micr datatype folder, and should have bids naming of: datatype=micr, desc=reg, suffix=report.py.ipynb, along iwth other subj wildcards..


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Add new Snakemake rule for quality control output Add registration QC notebook rule with nilearn visualizations Dec 14, 2025
Copilot AI requested a review from akhanf December 14, 2025 17:50
@akhanf
Copy link
Member

akhanf commented Dec 14, 2025

@copilot: I've made fixes to the python code, and moved it to a script instead. now, have this script also generate an html report with the matplotlib figures and text int he report

Copy link
Contributor Author

Copilot AI commented Dec 14, 2025

@copilot: I've made fixes to the python code, and moved it to a script instead. now, have this script also generate an html report with the matplotlib figures and text int he report

Done! The script now generates an HTML report with embedded matplotlib figures (base64-encoded) and comprehensive text including:

  • Styled HTML with sections and headers
  • Image information table
  • Deformation field statistics table
  • Figure captions for each visualization
  • Section descriptions explaining each QC visualization
  • Summary checklist of generated visualizations

The output is now regqc.html and includes all 10 QC visualizations with proper styling and explanatory text. See commit fa3e8b3.

Copilot AI changed the title Add registration QC notebook rule with nilearn visualizations Add registration QC report generation with HTML output and nilearn visualizations Dec 14, 2025
@akhanf akhanf marked this pull request as ready for review December 15, 2025 14:21
@akhanf akhanf merged commit f6b1c21 into main Dec 15, 2025
2 checks passed
@akhanf akhanf deleted the copilot/add-quality-control-notebook-rule branch December 15, 2025 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants