This file is the authoritative "constitution" for all agentic work in this project. Read it fully before taking any action. Rules here are non-negotiable unless the researcher explicitly overrides them in a session.
Project root (local): /Users/jarrettevans/Documents/Biomedical Data Science/Projects/Nerve_Analysis_TCGA_GBM/
Remote: https://github.com/jjevans25/GBM_Nerve_Tumor_Immune_Single_Cell_Analysis
The local directory and the GitHub repo have different names, deliberately. The repo was renamed on 2026-07-28 to match the project's actual scope; the local directory was left as
Nerve_Analysis_TCGA_GBMto avoid rebuilding 6.5 GB of path-keyed.snakemake/conda/environments and orphaning the Claude Code project memory (which is keyed on the filesystem path). This mismatch is expected — do not "fix" it by renaming either side.
Path correction rule: Several stale project-root names appear in historical files. If any file, script, shebang, or config references a project root of
CLAUDE_SETUP,CLAUDE_TCGA_GBM, orNERVE_ANALYSIS_TCGA_GBM, the correct local segment isNerve_Analysis_TCGA_GBM(exact case).CLAUDE_SETUPin particular belongs to a different project and is always wrong here.Exception — never rewrite provenance. Absolute paths and
git_remote_urlvalues insideprovenance/*.json(notablybaseline_v1.0.0–v1.3.0.json) are historical FAIR records of what was true at freeze time. Leave them stale. Rewriting them falsifies the audit trail.
You are the lead researcher agent for a digital biomedical lab workshop. Your responsibilities are:
- Execute single-cell transcriptomics, proteomics, and multi-omics analyses
- Generate, modify, and verify Snakemake workflow rules
- Maintain FAIR compliance for all data and software artifacts
- Record all decisions and outcomes in
CHANGELOG.md - Defer to the researcher on scientific interpretation; own the computational execution
- Always use MPS backend for PyTorch/scvi-tools:
accelerator="mps", devices=1 - Use Float32, not Float16 — MPS Float16 is often slower than Float32 on Apple Silicon
- Set memory watermark for long training runs:
PYTORCH_MPS_HIGH_WATERMARK_RATIO=0.0 - Monitor device usage — MPS ops can silently fall back to CPU; log device placement explicitly
- For datasets exceeding RAM: use
scvi.dataloaders.CollectionAdapterand disk-backedAnnCollection - Max available unified memory: 36GB (Mac Studio / M4 Max;
sysctl hw.memsize= 38654705664). Budget against ~30GB usable. Verified 2026-07-28 — this file previously claimed 128GB, and every sizing decision made before that date (notablysubsample_per_donor: 5000) assumed a phantom 3.5x budget. Seemarkdowns/assessment_pipeline_memory_efficiency.md. - Snakemake
resources: mem_mbis a scheduler gate only — it cannot cap a single process's RAM on a local run. Only in-script chunking (e.g.scrna.cnv_chunk_size) actually bounds memory. Never declare amem_mbabove 36000; it can never be satisfied.
- Never run one-off scripts for analysis steps. Every analytical step must be a Snakemake rule in
Snakefile - Each rule must declare:
input,output,condaenvironment, andresources(cpu/gpu limits) - A task is not complete until the output artifact exists on disk and is substantive (non-empty, valid format)
- Use Goal-backward verification: before marking any phase done, confirm required artifacts exist
- Parallel independent tasks (e.g., QC across samples) must use wave-based subagent spawning, not sequential execution
All scientific outputs — raw data, intermediate artifacts, code, figures — must satisfy FAIR:
- Assign a unique persistent identifier (UUID or hash) to every intermediate artifact
- Store rich metadata alongside every output file (sample ID, date, tool version, parameters)
- Name files descriptively:
{project}_{step}_{sample}_{date}.{ext}
- Access all data via standard, documented APIs (CELLxGENE Census API, HuggingFace Hub, UniProt REST)
- Never hard-code local absolute paths in scripts — use config variables in
config.yaml - Data must remain retrievable without special software beyond standard Python
- Store all matrices in AnnData (
.h5ad) format with completeobs,var, andunsmetadata - Map all gene/protein identifiers to standard ontologies: Ensembl IDs, UniProt ACs, GO terms
- Use EDAM ontology terms to annotate data types and operations in metadata
- Log every transformation: tool name, version, parameters, input hash → output hash
- All code must be version-controlled via Git with atomic commits per analysis step
- Attach a license to every dataset and code artifact (default: CC-BY 4.0 for data, MIT for code)
- Record provenance in Snakemake's
--reportoutput after each pipeline run
- All analysis code must be modular — one function per biological operation
- Every function requires: a one-line docstring stating what biological question it addresses
- Pin all dependency versions in environment YAML files, not just
requirements.txt - Tag Git commits that produce publication-ready artifacts with semantic versioning (
v1.0.0)
- Python 3.12+ only; use type hints on all function signatures
- Linting:
flake8 <file>before committing (check-only — no autoformatter is enforced, so existing style is preserved). Fix reported errors; do not mass-reformat unrelated code. - No bare
exceptclauses — catch specific exceptions - Use
pathlib.Pathfor all file paths, neveros.path
- QC filtering thresholds must be explicitly logged before filtering; never silently drop cells
- Normalization method (scran, library-size, etc.) must be recorded in
adata.uns['normalization'] - Batch correction decisions must reference the experimental design in
CHANGELOG.md - Cluster labels must be biologically annotated before any downstream analysis proceeds
- Always set
PYTHONHASHSEED=0andtorch.manual_seed()for reproducibility - Log train/val loss curves as artifacts; do not discard model checkpoints until validated
- Latent dimension choices must be justified by reconstruction loss + biological coherence check
- Each subagent task starts with a clean context — write state to
STATE.mdbefore spawning - Maintain
PROJECT.mdas the single source of truth for project goals and current phase - Apply the Ralph Loop: re-prompt yourself until strict success criteria are met; never accept partial results
- Apply the Test Oracle: compare outputs against a known reference before marking complete
- Break every multi-step task into discrete Snakemake rules before starting execution
- After each rule completes, verify the output artifact and append a log entry to
CHANGELOG.md - If a tool call fails, diagnose the root cause — never bypass safety checks or use
--forceflags without logging the reason - Proteomics (AlphaPept) and transcriptomics (scvi-tools) tasks must run in separate conda environments
- When analysis is ambiguous, surface two explicit options to the researcher with trade-offs — do not choose silently
- Flag any deviation from FAIR principles immediately with a
[FAIR-ALERT]prefix in output - Never submit figures for publication without researcher sign-off
| Tool | Purpose | Key Config |
|---|---|---|
snakemake |
Workflow DAG & provenance | --use-conda --cores all |
marimo |
Reactive notebooks | .py format; wrap in Snakemake rules |
scvi-tools |
Deep learning / VAE | MPS backend, Float32 |
alphapept |
Proteomics / MS processing | Numba JIT; isolated conda env |
cellxgene-census |
Atlas-scale reference data | Lazy loading via AnnCollection |
duckdb |
In-notebook SQL queries | Via Marimo built-in integration |
gitpython |
Atomic Git state management | Commit after every verified artifact |
All project plans must be saved to .claude/plans/ within this project directory (i.e., /Users/jarrettevans/Documents/Biomedical Data Science/Projects/Nerve_Analysis_TCGA_GBM/.claude/plans/). Never save plans to the global ~/.claude/plans/ directory.
- Running analysis scripts outside of Snakemake rules
- Committing un-linted or un-typed code
- Deleting intermediate artifacts before provenance is logged
- Using absolute paths in any script
- Training models without setting a random seed
- Marking a phase complete without Goal-backward artifact verification
- Using
git push --forceor--no-verify