KINTSUGI / notebooks
AGENTS.md9 starsChanged 30 days agoMITView on GitHub
Context for AI coding assistants working in the notebooks/ directory. See root AGENTS.md for project overview, CLI usage, and architecture. CRITICAL: Autoreload is enabled in all KINTSUGI notebooks: This means: - NEVER tell the user to restart the kernel after editing Python modules - NEVER tell the user to reload/reopen the notebook - After editing .py files (Kio.py, kintsugi/*.py, etc.), changes take effect automatically on next cell execution - Just re-run the relevant cell - no restart needed Only suggest…
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 31,439 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository5 other files it gives its agents.
- AGENTS.mdAGENTS.md
- workflow/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- notebooks/CLAUDE.mdCLAUDE.md
- workflow/CLAUDE.mdCLAUDE.md
The file
We split this AGENTS.md into the rules it gives an agent
5 rules. About 0 are common, 3 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 15
NEVER tell the user to restart the kernel: after editing Python modules
- Very specific: line 17
After editing .py files (Kio.py, kintsugi/*.py, etc.), changes take effect automatically on next cell execution
- Distinctive: line 20
Only suggest kernel restart for: new package installation, environment variable changes, or C extension recompilation.
- Very specific: line 24
When users report NameError: name 'function_name' is not defined:
- Distinctive: line 50
Solution: Run cells sequentially from the top, or at minimum run the definition cell before the calling cell.
≈ “Common” is an estimate: at least 1 in 5 of the 40,246 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Notebooks AGENTS.md
Context for AI coding assistants working in the notebooks/ directory. See root AGENTS.md for project overview, CLI usage, and architecture.
Jupyter Notebook Workflow
CRITICAL: Autoreload is enabled in all KINTSUGI notebooks:
%load_ext autoreload
%autoreload 2This means:
- NEVER tell the user to restart the kernel after editing Python modules
- NEVER tell the user to reload/reopen the notebook
- After editing
.pyfiles (Kio.py, kintsugi/*.py, etc.), changes take effect automatically on next cell execution - Just re-run the relevant cell - no restart needed
Only suggest kernel restart for: new package installation, environment variable changes, or C extension recompilation.
Troubleshooting "Function Not Found" Errors
When users report NameError: name 'function_name' is not defined:
- Check if function is defined in a notebook cell (not a module):
- Some functions like
run_deconvolutionare defined inside the notebook, not imported from modules - These require running the definition cell before the cell that uses them
- Some functions like
- Verify cell execution order:
# Use this to analyze notebook cell order import json with open('notebook.ipynb') as f: nb = json.load(f) for i, cell in enumerate(nb['cells']): source = ''.join(cell.get('source', [])) if 'function_name' in source: is_def = 'def function_name' in source print(f"Cell {i}: {'DEFINES' if is_def else 'CALLS'} function_name") - Common patterns in 2_Cycle_Processing.ipynb:
Function Defined In Called In run_deconvolutionCell 24 Cell 25 process_edf_tiffCell 31 Cell 32 visualize_deconvolutionCell 27 (manual) - Solution: Run cells sequentially from the top, or at minimum run the definition cell before the calling cell.
Shared Notebook Utilities (Kio.py)
Canonical home for helpers used by more than one notebook. Add functions here instead of duplicating in notebook cells.
| Helper | Purpose | Used by |
load_channel_names() | Parse CHANNELNAMES.txt (multiple formats) | Notebooks 1, 2, 3 |
make_channel_names_unique() | Disambiguate duplicate Blank/Empty names | Notebooks 1, 2 |
save_channel_names_template() | Write a CHANNELNAMES.txt starter | Notebook 1 |
extract_channels_from_ome() | OME-TIFF → per-channel TIFFs | Notebook 4 |
normalize_cycle_dirs() | Rename long-form CODEX cycle folders (e.g. cyc004_reg001_211206_201615 → cyc004) | Notebooks 1 cell 5, 2 cell 6 |
load_tiles_parallel() / load_stack_parallel() | Threaded tile/z-stack loading | Notebook 2 |
ProgressCounter, ProcessingConfig, zarr_write_lock | Shared dataclasses | Notebook 2 |
Cycle Directory Normalization
Raw CODEX folders can arrive as cyc004_reg001_211206_201615, but Notebook 1 cell 14 and Notebook 2 cells 13/16/42 all hard-code short-form paths like f"cyc{cycle:03d}". The normalize_cycle_dirs(raw_dir, width=3, dry_run=False) helper renames in place, is idempotent, and raises RuntimeError on collisions (never overwrites).
This was previously a cell in Notebook 2 that got dropped. Both notebooks now call it automatically before find_raw_cycles(). The SLURM/Snakemake path uses a different mechanism (workflow/scripts/stitch.py:find_cycle_dir() resolves long-form at glob time) and is unaffected.
Notebook 4: Segmentation & Spatial Analysis
Notebook 4 provides a comprehensive workflow for cell segmentation, feature extraction, and spatial analysis:
Current Capabilities
Segmentation (InstanSeg):
- Nuclear segmentation from DAPI
- Combined cell + nucleus segmentation
- ECM (extracellular matrix) region segmentation via watershed from cell boundaries
- Matched compartment masks (cytoplasm, nuclear, ECM) with shared labels
Feature Extraction:
- Uses
napari-simpleitk-image-processing.label_statisticsfor:- Morphological features (size, perimeter, shape descriptors)
- Position features (centroids)
- Intensity statistics (mean, median, min, max, sigma, variance, sum)
- Moments for texture analysis
- Separate feature DataFrames for cell, nuclear, and ECM compartments
SOM Clustering (pyFlowSOM):
- Self-organizing map clustering with configurable grid size
- Learning rate scheduling (start -> end)
- Iterative refinement with visualization
- Separate clustering for: cells, nuclei, ECM, combined features
Spatial Analysis (scanpy + scimap):
- AnnData integration for single-cell analysis framework
- PCA, UMAP dimensionality reduction
- PAGA graph-based analysis
- Leiden community detection clustering
- Combined SOM + Leiden consensus phenotyping
- Spatial scatter plots with cluster overlays
- Hierarchical clustering for merged phenotypes
- Differential marker analysis (Wilcoxon rank-sum)
Key Dependencies
instanseg- Deep learning instance segmentationpyFlowSOM- Self-organizing maps for clusteringnapari-simpleitk-image-processing- Feature extractionscanpy- Single-cell analysis frameworkscimap- Spatial analysis toolkitnapari- Interactive visualization
Migration Notes
The old Notebooks 3 (Signal Isolation) and 5 (DL Channel Refinement) have been replaced with a unified 3_Signal_Isolation_QC.ipynb that supports interactive work and, through the optional MCP server, AI-assisted work. See notebooks/MIGRATION_GUIDE.md for detailed transition guidance.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

