agentleFS
smith6jt-copsmith6jt-cop/KINTSUGI/notebooks/AGENTS.md

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.

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
  1. Distinctive:

    NEVER tell the user to restart the kernel: after editing Python modules

    line 15
  2. Very specific:

    After editing .py files (Kio.py, kintsugi/*.py, etc.), changes take effect automatically on next cell execution

    line 17
  3. Distinctive:

    Only suggest kernel restart for: new package installation, environment variable changes, or C extension recompilation.

    line 20
  4. Very specific:

    When users report NameError: name 'function_name' is not defined:

    line 24
  5. Distinctive:

    Solution: Run cells sequentially from the top, or at minimum run the definition cell before the calling cell.

    line 50

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

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 2

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 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:

  1. Check if function is defined in a notebook cell (not a module):
    • Some functions like run_deconvolution are defined inside the notebook, not imported from modules
    • These require running the definition cell before the cell that uses them
  2. 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")
  3. Common patterns in 2_Cycle_Processing.ipynb:
    FunctionDefined InCalled In
    run_deconvolutionCell 24Cell 25
    process_edf_tiffCell 31Cell 32
    visualize_deconvolutionCell 27(manual)
  4. 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.

HelperPurposeUsed by
load_channel_names()Parse CHANNELNAMES.txt (multiple formats)Notebooks 1, 2, 3
make_channel_names_unique()Disambiguate duplicate Blank/Empty namesNotebooks 1, 2
save_channel_names_template()Write a CHANNELNAMES.txt starterNotebook 1
extract_channels_from_ome()OME-TIFF → per-channel TIFFsNotebook 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 loadingNotebook 2
ProgressCounter, ProcessingConfig, zarr_write_lockShared dataclassesNotebook 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_statistics for:
    • 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 segmentation
  • pyFlowSOM - Self-organizing maps for clustering
  • napari-simpleitk-image-processing - Feature extraction
  • scanpy - Single-cell analysis framework
  • scimap - Spatial analysis toolkit
  • napari - 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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.