HopTF / contracts /DATA_CONTRACT.md
pvd232's picture
Upload HopTF small artifact files 1
baac0a1 verified
|
Raw History Blame Contribute Delete
29.8 kB
# HOPTF Data Contract
This is the project-wide data contract for the HOPTF subtree. Source code, scripts, data indexes, generated artifacts, run records, and experiment notes are organized inside `hoptf/` with explicit provenance.
Experiment contracts inherit this root contract and add experiment-local paths, execution settings, and validation records under `hoptf/experiments/<experiment_id>/`.
## Directory Ownership
| Directory | Contract boundary |
| :--- | :--- |
| `components/` | Human component contracts and design notes |
| `data_contracts/` | Machine-facing artifact schemas, registries, and checksum slots |
| `configs/` | Execution and sweep configuration |
| `src/hoptf/` | Reusable library API |
| `scripts/` | Project-level CLI entry points |
| `data/` | Shallow index of canonical raw and processed external assets |
| `artifacts/` | Versioned HOPTF research objects suitable for reuse |
| `runs/` | Run-local outputs, validation artifacts, and smoke records |
| `experiments/` | Experiment-local plans, diagnostics, logs, checkpoints, and overlays |
| `tests/` | Project-level behavioral and contract tests |
| `latex/` | Manuscript or technical note source |
Generated experiment artifacts remain localized under `experiments/<experiment_id>/diagnostics/`, `logs/`, and `checkpoints/` unless they are promoted to a project-level reusable artifact. Promoted artifacts must be registered under `data_contracts/` and written under `artifacts/`.
Machine-facing producer and consumer registry:
```text
hoptf/data_contracts/artifacts/artifact_registry.yaml
```
## Terminology
An ORF means open reading frame. It is the nucleotide coding sequence intended to be translated into a protein. In this project, an ORF is the overexpression payload delivered by the library construct.
MORF means Multiplexed Overexpression of Regulatory Factors. In Joung et al. TF Atlas, MORF is the barcoded human TF ORF library. The library contains 3,548 TF splice isoform ORFs from 1,836 TF genes, plus two non-TF control vectors expressing GFP and mCherry.
For this experiment, a perturbation is one MORF construct assignment. A TF isoform perturbation is one non-control MORF row with a concrete ORF sequence and corresponding protein-embedding rows.
## Canonical Inputs
| Asset | Path | Contract |
| :--- | :--- | :--- |
| Paper | `hoptf/data/raw/joung_tfatlas/Joung_TFAtlas.pdf` | Local Joung TF Atlas paper |
| MORF source table | `hoptf/data/raw/joung_tfatlas/Sup_data_1.xlsx` | Data S1 workbook, sheet `Data S1` |
| Pseudotime source table | `hoptf/data/raw/joung_tfatlas/Sup_data_4.xlsx` | Data S4 workbook, sheets `Data S4A` and `Data S4B` |
| MORF manifest | `hoptf/data/processed/tf_atlas_morf_isoforms_esmc_600m/metadata/tf_atlas_morf_isoform_manifest.json` | 3,550 MORF rows including controls |
| TF isoform vocab | `hoptf/data/processed/tf_atlas_morf_isoforms_esmc_600m/metadata/tf_atlas_morf_isoform_vocab.json` | 3,548 non-control TF isoform row IDs |
| TF isoform sequences | `hoptf/data/processed/tf_atlas_morf_isoforms_esmc_600m/metadata/tf_atlas_morf_isoform_protein_sequences.json` | Protein sequence per embedded TF isoform |
| TF isoform ESM-C matrix | `hoptf/data/processed/tf_atlas_morf_isoforms_esmc_600m/tf_atlas_morf_isoforms_esmc_600m_mean_non_special.npy` | 3,548 x 1,152 float32 matrix |
| TF isoform ESM-3 matrix | `hoptf/data/processed/tf_atlas_morf_isoforms_esm3_sm_open_v1/tf_atlas_morf_isoforms_esm3_sm_open_v1_mean_non_special_max512.npy` | 3,548 x 1,536 float32 matrix |
| Raw GEO archive | `hoptf/data/raw/joung_tfatlas/GSE216481_RAW.tar` | Raw TF Atlas archive with TFmap assignments and expression matrices |
| Final TFAtlas S01-S04 expression | `hoptf/data/raw/joung_tfatlas/GSE217460_210322_TFAtlas_S01-S04.csv.gz` | Combined GSE217460 expression file completing `210322_TFAtlas_S01` through `S04` |
| GEO sync plan | `hoptf/data_contracts/tf_atlas/JOUNG_GEO_SYNC_PLAN.json` | Machine-readable upstream inventory, local coverage, and space-gated sync status |
## Raw H5AD Surface
Raw TFAtlas ingestion is a project-level data-surface construction step. It is separate from responder scoring and linear-probe diagnostics.
Authoritative contract:
| Artifact | Path |
| :--- | :--- |
| H5AD shard contract | `hoptf/data_contracts/tf_atlas/H5AD_SHARD_CONTRACT.md` |
| Preprocessing contract | `hoptf/data_contracts/tf_atlas/PREPROCESSING_CONTRACT.md` |
| Primary producer CLI | `hoptf/scripts/build_tf_atlas_h5ad_from_zarr_csr.py` |
| Direct TSV producer CLI | `hoptf/scripts/build_tf_atlas_h5ad_surface.py` |
| Producer module | `hoptf/src/hoptf/tf_atlas_h5ad_surface.py` |
| Binary CSR cache root | `hoptf/data/processed/tf_atlas_zarr_csr/` |
| Output root | `hoptf/data/processed/tf_atlas_h5ad/final_210322/` |
| Manifest | `hoptf/data/processed/tf_atlas_h5ad/final_210322/MANIFEST.json` |
| Selection cache | `hoptf/data/processed/tf_atlas_h5ad/final_210322/SELECTION_CACHE.json` |
| Contract validation | `hoptf/data_contracts/tf_atlas/H5AD_FROM_CSR_CONTRACT_VALIDATION_20260420.json` |
The final H5AD surface stores normalized expression in `X` and raw UMI counts in `layers["counts"]`. The `X` matrix is `log1p_cp10k` with cells by genes CSR layout. The raw-count layer has the same shape and sparsity structure as `X`, and is the only H5AD location consumers may treat as raw expression. QC annotations include count depth, detected genes, mitochondrial fraction, ribosomal fraction, hemoglobin fraction, top-gene concentration, and the core `IEG_score` defined in `hoptf/data_contracts/tf_atlas/PREPROCESSING_CONTRACT.md`. The H5AD shards must not contain HVG flags, PCA coordinates, responder scores, responder labels, protein embeddings, train/test splits, or probe metrics.
The realized final surface contains 24 H5AD shards, 11,859,849 selected assigned cells, 6,117,583,917 raw-count sparse nonzero entries, and shard-specific gene sets ranging from 32,895 to 36,655 genes. The gene count exceeds a simple protein-coding-gene expectation because the source matrix is a transcriptome annotation surface, not a curated protein-coding-only symbol list. Consumers must read each shard gene axis from H5AD `var` or CSR `gene_names.txt`.
The production H5AD path reads the pre-sorted CSR binary cache, writes raw counts to `layers["counts"]`, materializes `X` as `log1p(raw_count / cell_total * 10000.0)`, derives QC metrics from raw counts, and records provenance. The direct TSV producer is a source-ingestion reference path for parity checks and source debugging. Downstream consumers read the H5AD surface or the validated CSR cache.
## Gene-Expression PCA Surface
The responder metadata derives `cell_state` from a PCA surface built on assigned TF Atlas cells using the same `log1p_cp10k` preprocessing surface.
Expression preprocessing surface: `log1p_cp10k`.
HVG surface: `tf_atlas_global_hvg5k`.
Production PCA surface: `tf_atlas_perturbation_log1p_hvg5k_pca50`.
| Field | Value |
| :--- | :--- |
| Raw expression source | `layers["counts"]` in `hoptf/data/processed/tf_atlas_h5ad/final_210322/shards/*.h5ad` or the validated CSR cache when only raw expression is needed |
| Normalized expression source | `X` in `hoptf/data/processed/tf_atlas_h5ad/final_210322/shards/*.h5ad` |
| Assignment source | H5AD `obs` fields derived from TFmap CSV files in `GSE216481_RAW.tar` |
| Cell assignment key | Expression column key `R1,R2,R3,P1` is matched to TFmap key `R1,R2,R3` by dropping the plate suffix |
| Perturbation ID | MORF barcode from TFmap, canonicalized through the MORF manifest |
| Cell filtering | Assigned cells with a manifest-recognized MORF barcode |
| Gene filtering | Genes detected in at least 3 retained cells |
| Normalization | H5AD `X` is already `log1p_cp10k`: per-cell total-count normalization to 10,000 followed by `log1p` |
| HVG selection | Compute global gene variance on the `log1p_cp10k` surface and keep the top 5,000 detected genes |
| Scaling | Per-feature centering and unit-variance scaling before PCA |
| PCA dimensions | 50 principal components |
| Production output array | `cell_state`, shape `n_perturbations x 50`, where each row is a perturbation mean state |
| Production support array | `perturbation_n_cells`, shape `n_perturbations`, containing assigned-cell support |
| Production output IDs | `perturbation_id`, shape `n_perturbations` |
| Preview output array | `cell_state`, shape `n_assigned_cells x 50`, retained only for bounded parity and schema checks |
| Zero-total handling | Cells with zero total counts after the realized gene filter are dropped and counted in the surface manifest |
Consumers must not recompute normalization from H5AD `X`. Consumers that need normalized expression read `X`. Consumers that need raw UMI counts read `layers["counts"]` or the validated CSR cache.
The choice of 50 principal components follows the TF Atlas analysis contract: Joung et al. used highly variable genes as PCA input and fit the top 50 principal components for neighborhood construction, and their joint scRNA and scATAC workflow also used RNA PCA dimensions 1 through 50. This keeps the responder surface aligned to the source study rather than tuning K on the probe labels.
## Global HVG5K Gene-List Contract
The 5K HVG list is a materialized data-contract artifact. PCA must consume this fixed ordered list rather than recomputing HVGs implicitly.
Current v1 artifact path:
| Artifact | Path | Contract |
| :--- | :--- | :--- |
| Global TFAtlas HVG5K | `hoptf/experiments/v1_esm_linear_probe/diagnostics/TF_ATLAS_GLOBAL_HVG5K.json` | Ordered top-5,000 detected genes by global variance after `log1p_cp10k` |
The HVG artifact must include this provenance:
| Field | Required value or meaning |
| :--- | :--- |
| `surface_id` | `tf_atlas_global_hvg5k` |
| `preprocessing_surface` | `log1p_cp10k` |
| `normalization` | `counts_per_cell_scaled_to_10000_then_log1p` |
| `selection_metric` | `global_variance_after_log1p_cp10k` |
| `hvg_n_requested` | 5,000 |
| `hvg_n_realized` | Number of genes retained, expected 5,000 for the full surface |
| `min_gene_cells` | Detection support filter before HVG ranking |
| `n_cells_input` | Assigned cells considered before zero-total filtering |
| `n_cells` | Assigned cells retained for `log1p_cp10k` variance computation |
| `n_genes_input` | Raw gene rows considered |
| `n_genes_after_detection_filter` | Genes eligible for HVG ranking |
| `provenance.raw_tar` | Raw archive path |
| `provenance.shards` | Exact TFAtlas and TFmap members used |
| `provenance.assignment_rule` | Expression `R1,R2,R3,P1` matched to TFmap `R1,R2,R3` |
| `provenance.cell_filter` | Manifest-recognized assigned cells |
| `provenance.gene_filter` | Genes detected in at least the configured retained-cell count |
| `provenance.preprocessing_surface` | `log1p_cp10k` |
| `provenance.hvg_rank_metric` | `global_variance_after_log1p_cp10k` |
| `genes` | Ordered gene-symbol list consumed by PCA |
| `gene_stats` | Per-gene rank, variance, and mean on `log1p_cp10k` |
For sampled previews, the artifact must also record sampling caps such as `max_genes`, `max_total_cells`, and `max_cells_per_perturbation`. A sampled preview HVG list must not be treated as the full global TFAtlas HVG5K list.
Raw source coverage is recorded in `hoptf/data_contracts/tf_atlas/JOUNG_GEO_SYNC_PLAN.json`. The final 210322 source set includes `GSE216481_RAW.tar` and `GSE217460_210322_TFAtlas_S01-S04.csv.gz`. TFmap tokens are canonicalized through barcode, full embedding ID, ORF `Name`, and `Name-RefSeq Gene Name` aliases. The realized same-surface control support is 784,526 GFP assignments and 1,649,679 mCherry assignments. Audits are recorded in `hoptf/experiments/v1_esm_linear_probe/diagnostics/CONTROL_MAPPING_AUDIT.json`, `hoptf/experiments/v1_esm_linear_probe/diagnostics/CONTROL_SURFACE_PROVENANCE.md`, and `hoptf/data_contracts/tf_atlas/EXTRACTION_PIPELINE_AUDIT.md`.
## Responder Surface Contract
The production v1 H5AD responder builder is `hoptf/experiments/v1_esm_linear_probe/scripts/build_h5ad_perturbation_surface.py`. The direct raw-TSV builder is `hoptf/experiments/v1_esm_linear_probe/scripts/build_streaming_perturbation_surface.py` and is retained for parity checks.
The builder follows the MANTRA optimization workflow:
| Stage | Contract |
| :--- | :--- |
| Source read | Stream H5AD shards from the final 210322 surface, using `X` for normalized expression and `layers["counts"]` only for raw-count support checks |
| First pass | Compute per-gene support and global `log1p_cp10k` moments without materializing all cells by genes |
| Second pass | Aggregate `log1p_cp10k` expression directly to perturbation by HVG mean using vectorized reductions |
| HVG selection | Keep top 5,000 detected genes by global variance |
| Control pass | Build same-surface GFP and mCherry control PCA statistics for control standard deviation |
| Dense tail | Move the compact perturbation by HVG matrix to GPU when available for scaling, PCA, and responder scoring |
The `.npz` artifact must contain:
| Array | Shape | Meaning |
| :--- | :--- | :--- |
| `cell_state` | `n_perturbations x d` | PCA state per perturbation mean |
| `perturbation_id` | `n_perturbations` | Canonical MORF perturbation IDs |
| `perturbation_n_cells` | `n_perturbations` | Retained assigned-cell count per perturbation |
| `response_score` | `n_perturbations` | Control-standardized responder score |
| `control_mean` | `d` | Pooled GFP and mCherry control mean in PCA space |
| `control_sd` | `d` | Pooled GFP and mCherry control standard deviation in PCA space |
| `hvg_gene` | `hvg_n` | Ordered HVG gene list |
| `mean_log1p_hvg` | `n_perturbations x hvg_n` | Perturbation mean expression on the realized HVG surface |
| `gene_mean` | `hvg_n` | Feature mean used before PCA |
| `gene_sd` | `hvg_n` | Feature standard deviation used before PCA |
| `pca_components` | `hvg_n x d` | PCA loading matrix |
| `explained_variance_ratio` | `d` | PCA explained-variance ratio |
The paired JSON manifest must record raw source paths, shard membership, plate-to-shard mapping where used, MORF alias mapping rule, sampling caps, timing by pass, realized dimensions, and the exact `log1p_cp10k` and HVG provenance.
Executed full H5AD responder surface:
| Artifact | Path |
| :--- | :--- |
| Perturbation PCA surface | `hoptf/experiments/v1_esm_linear_probe/diagnostics/TF_ATLAS_H5AD_PERTURBATION_PCA_SURFACE.npz` |
| Perturbation PCA manifest | `hoptf/experiments/v1_esm_linear_probe/diagnostics/TF_ATLAS_H5AD_PERTURBATION_PCA_SURFACE.json` |
| Full responder metadata | `hoptf/experiments/v1_esm_linear_probe/diagnostics/h5ad_responder_full/PERTURBATION_METADATA.csv` |
| Full control null | `hoptf/experiments/v1_esm_linear_probe/diagnostics/h5ad_responder_full/CONTROL_NULL.json` |
| Full label summary | `hoptf/experiments/v1_esm_linear_probe/diagnostics/h5ad_responder_full/LABEL_SUMMARY.json` |
| Full run log | `hoptf/experiments/v1_esm_linear_probe/logs/h5ad_responder_full_20260420_block65536.log` |
The executed full surface used all 24 H5AD shards, 11,859,849 selected cells, 2,419,456 control cells, 37,528 union genes before detection filtering, HVG5K, PCA50, and 3,423 scored perturbation states. The label summary contains 856 responders, 856 nonresponders, 1,709 ambiguous TF rows, 2 control rows, and 127 insufficient-support manifest rows.
## Metadata Runner Input
The metadata runner consumes a cell-state `.npz` file with either one row per assigned cell or one row per perturbation aggregate.
| Array | Shape | Meaning |
| :--- | :--- | :--- |
| `cell_state` | `n_cells x d` | Fixed transcriptomic representation used for scoring |
| `perturbation_id` | `n_cells` | MORF perturbation assignment for each row |
| `perturbation_n_cells` | `n_perturbations`, optional | Support counts when the file is perturbation-level |
| `response_score` | `n_perturbations`, optional | Precomputed score when the file is perturbation-level |
| `control_mean` | `d`, optional | Pooled control mean for aggregate scoring |
| `control_sd` | `d`, optional | Pooled control standard deviation for aggregate scoring |
Perturbation IDs may be MORF IDs, MORF barcodes, full protein-embedding row IDs, ORF-label aliases, or control names for GFP and mCherry. They are canonicalized against the MORF manifest before scoring. Raw TFmap tokens must be resolved by accepting Data S1 `Barcode Sequence`, full `isoform_embedding_id`, `Name`, and `Name-RefSeq Gene Name` aliases.
## Linear Probe Contract
Machine-facing contract:
```text
hoptf/data_contracts/linear_probe/linear_probe_contract.yaml
```
Producer:
```text
hoptf/experiments/v1_esm_linear_probe/scripts/run_linear_probe.py
```
Primary consumer input:
```text
hoptf/experiments/v1_esm_linear_probe/diagnostics/h5ad_responder_full/PERTURBATION_METADATA.csv
```
Primary outputs:
```text
hoptf/experiments/v1_esm_linear_probe/diagnostics/LINEAR_PROBE_RESULTS.json
hoptf/experiments/v1_esm_linear_probe/diagnostics/LINEAR_PROBE_RESULTS_ESM3.json
```
The linear probe consumes only perturbation-level TF isoform rows with `label_status` equal to `responder` or `nonresponder`. It excludes `ambiguous`, `control_null`, and `insufficient_support` rows. GFP and mCherry define the responder-score control baseline but must not become classifier samples.
Evaluation groups by `gene_symbol` when feasible. The model is a frozen-feature logistic regression over fixed ESM-C or ESM-3 vectors with fold-local feature standardization, L2 regularization, and class weighting. The implementation supports inner-C selection by average precision. The realized full runs used the optimization workflow setting `--no-tune-c`, fixed `clf__C = 1.0`, `lbfgs`, `solver_tol = 0.01`, and `max_iter = 100`. Required comparison features are protein length, amino-acid composition, gene-symbol one-hot, and shuffled labels over the primary protein embedding.
Executed full linear probes:
| Feature set | Label source | AUROC | AUPRC | Balanced accuracy | Permutation p |
| :--- | :--- | ---: | ---: | ---: | ---: |
| `esmc` | metadata | 0.6185 | 0.6113 | 0.5940 | 0.0476 |
| `esm3` | metadata | 0.6068 | 0.5963 | 0.5894 | 0.0476 |
| `protein_length` | metadata | 0.6533 | 0.6250 | 0.6139 | not run |
| `aa_composition` | metadata | 0.6038 | 0.5915 | 0.5754 | not run |
| `gene_symbol_onehot` | metadata | 0.4862 | 0.4906 | 0.4907 | not run |
| `esmc` | shuffled metadata labels | 0.5117 | 0.5135 | 0.5035 | not run |
| `esm3` | shuffled metadata labels | 0.4908 | 0.4973 | 0.4924 | not run |
The realized runs used 1,712 labeled rows, 856 responders, 856 nonresponders, 5-fold `gene_symbol` grouped CV, and 20 label permutations on the primary embedding feature set. ESM-C results are in `hoptf/experiments/v1_esm_linear_probe/diagnostics/LINEAR_PROBE_RESULTS.json`. ESM-3 results are in `hoptf/experiments/v1_esm_linear_probe/diagnostics/LINEAR_PROBE_RESULTS_ESM3.json`.
## AlphaGenome K Matrix Contract
Machine-facing contract:
```text
hoptf/data_contracts/alphagenome/alphagenome_k_contract.yaml
```
Producer:
```text
hoptf/scripts/build_alphagenome_k_matrix.py
```
The AlphaGenome K matrix is a genome-locus memory bank:
$$
K \in \mathbb{R}^{N \times d}
$$
Rows are genomic loci identified by `chrom:start-end:strand`. Columns are deterministic AlphaGenome-derived functional sequence features declared in `FEATURE_SCHEMA.json`.
v2 variants:
| Variant | Output families | Role |
| :--- | :--- | :--- |
| `vanilla` | `ATAC`, `CHIP_HISTONE`, `CAGE`, `RNA_SEQ` | Base locus memory bank |
| `vanilla_mito_ieg_filtered` | `ATAC`, `CHIP_HISTONE`, `CAGE`, `RNA_SEQ` | Base locus memory bank after mitochondrial and core IEG row filtering |
| `tf_prior_enriched` | `ATAC`, `CHIP_HISTONE`, `CHIP_TF`, `CAGE`, `RNA_SEQ` | TF-facing ablation |
| `atac_tss_masked` | derived mask over K | Planned accessibility and TF-TSS mask |
Production storage is a directory containing `K.zarr/`, `LOCI.tsv`, `FEATURE_SCHEMA.json`, and `MANIFEST.json`. `vanilla` and `tf_prior_enriched` are cell-type agnostic. K562 ENCODE peak tracks are reserved for an explicitly named accessibility-prior ablation. Mitochondrial locus rows are excluded. The filtered ablation removes loci overlapping core IEG genes or mitochondrial gene symbols using `data/external/encode_k562/gencode.v44.annotation.gtf.gz`; GENCODE provenance is read from `data/external/encode_k562/encode_fetch_manifest.json`, and the core IEG list is sourced from `src/mantra/programs/docs/STATE.md`. Consumers must align by locus ID and feature schema, and filtered ablations must be compared by locus intersection.
## Hopfield Component Contract
Machine-facing contract:
```text
hoptf/data_contracts/hopfield/hopfield_component_contract.yaml
```
The Hopfield component maps TF protein embeddings to genome-context perturbation embeddings by retrieving over AlphaGenome K. It supports the plain retrieval path from `hoptf/latex/hoptf.tex` and a `self_similarity_gat` ablation from `hoptf/latex/NYGC_meeting_cleaned_transcript_v2.docx.md`.
## MORF Table Fields
The MORF source table fields are:
| Field | Meaning |
| :--- | :--- |
| `Source` | Construct source, such as `Genewiz`, `Broad GPP`, or `Neither` |
| `Name` | MORF ORF identifier such as `TFORF0001` |
| `RefSeq Gene Name` | Gene symbol or control name |
| `RefSeq and Gencode ID` | RefSeq and Gencode transcript IDs, where available |
| `Isoform ID` | Library isoform identifier |
| `Insert` | Full construct insert sequence |
| `ORF sequence` | Coding nucleotide sequence translated for protein embedding |
| `Barcode Sequence` | Unique 24-bp construct barcode |
| `Epitope Tag` | Tag annotation, where present |
## Control Constructs
The controls are non-human, non-TF fluorescent protein ORFs included in the MORF library.
| Control | MORF ID | Protein | Role | ORF nt length | Protein aa length | Barcode |
| :--- | :--- | :--- | :--- | ---: | ---: | :--- |
| GFP | `TFORF3549` | Green fluorescent protein | Negative control ORF | 720 | 240 | `GCTGACTCCTTCTTGGGAATCTGC` |
| mCherry | `TFORF3550` | Red fluorescent protein | Negative control ORF | 708 | 236 | `AGAGAATATCACGTCCGTGCAAAG` |
Control manifest IDs:
| Control | Manifest ID |
| :--- | :--- |
| GFP | `TFORF3549-GFP--` |
| mCherry | `TFORF3550-mCherry--` |
Controls are included in the MORF manifest with `is_control = true`. They are excluded from the TF isoform vocab, protein sequence JSON, and protein-embedding matrices used as linear probe input features.
The controls may be used to estimate a transcriptomic null response distribution. They must not be used as classifier samples in the protein-embedding TF isoform probe.
## Probe-Sample Inclusion Rules
A row is eligible for a protein-embedding linear probe if all conditions hold:
| Requirement | Rule |
| :--- | :--- |
| MORF control flag | `is_control = false` |
| Protein embedding | Row ID is present in `tf_atlas_morf_isoform_vocab.json` and the selected embedding matrix |
| Protein sequence | Row ID is present in `tf_atlas_morf_isoform_protein_sequences.json` |
| Cell support | Perturbation has at least 1 assigned cell; `n_cells` is recorded for support auditing |
| Response score | Perturbation has a finite responder score |
| Label | Perturbation passes responder or nonresponder thresholding |
Controls are eligible for null estimation only. They are not eligible for probe training, validation, or test rows.
## Perturbation-Level Table Schema
The metadata table for this experiment must contain one row per MORF construct considered for scoring.
| Column | Type | Required | Meaning |
| :--- | :--- | :--- | :--- |
| `morf_id` | string | yes | MORF ID such as `TFORF0001` |
| `isoform_embedding_id` | string | yes | Protein-embedding row ID for TF isoforms, control manifest ID for controls |
| `gene_symbol` | string | yes | TF gene symbol or control name |
| `isoform_id` | string | yes | MORF isoform ID, or `-` for controls |
| `is_control` | bool | yes | True for GFP and mCherry |
| `control_type` | string | yes | `negative_control` for GFP and mCherry, otherwise `none` |
| `barcode_sequence` | string | yes | 24-bp construct barcode |
| `orf_nt_length` | integer | yes | ORF nucleotide length |
| `protein_aa_length` | integer | yes | Translated protein length |
| `sequence` | string | TF rows only | Translated amino-acid sequence |
| `esm_embedding_index` | integer | TF rows only | Row index in the selected protein-embedding matrix |
| `n_cells` | integer | yes | Number of assigned cells used for scoring |
| `response_score` | float | yes | Perturbation-level transcriptomic shift score |
| `response_score_kind` | string | yes | Score method identifier |
| `null_source` | string | yes | `tf_quartile_control_standardized` |
| `responder_label` | integer or null | probe rows only | 1 for responder, 0 for nonresponder, null for ambiguous or controls |
| `label_status` | string | yes | `responder`, `nonresponder`, `ambiguous`, `control_null`, or `insufficient_support` |
## Response Score Definition
The v1 score is a perturbation-level transcriptomic shift, not a single-cell Mixscape label.
Let:
$$
\begin{aligned}
h_i &\in \mathbb{R}^d && \text{fixed cell-state vector for cell } i \\
p_i && \text{assigned MORF perturbation for cell } i \\
I_p &= \{i : p_i = p\} && \text{cells assigned to perturbation } p \\
G &= \{i : p_i = \mathrm{GFP}\} && \text{cells assigned to GFP control} \\
M &= \{i : p_i = \mathrm{mCherry}\} && \text{cells assigned to mCherry control} \\
C &= G \cup M && \text{negative-control cell pool} \\
\mu_p &= \frac{1}{|I_p|}\sum_{i \in I_p} h_i && \text{mean state for perturbation } p \\
\mu_{\mathrm{ctrl}} &= \frac{1}{|C|}\sum_{i \in C} h_i && \text{pooled GFP and mCherry control mean} \\
\sigma_{\mathrm{ctrl}} &= \operatorname{sd}\{h_i : i \in C\} && \text{pooled GFP and mCherry control standard deviation per dimension}
\end{aligned}
$$
The primary response score is:
$$
s_p =
\left\|
\frac{\mu_p - \mu_{\mathrm{ctrl}}}{\sigma_{\mathrm{ctrl}} + \epsilon}
\right\|_2
$$
For v1, $\mu_{\mathrm{ctrl}}$ and $\sigma_{\mathrm{ctrl}}$ are computed from GFP and mCherry cells pooled together on the same evaluation surface. If batch, sample, or context metadata are required by the realized data surface, compute the same pooled-control statistics within that surface.
The score must be computed in a fixed transcriptomic representation such as PCA or another fixed latent state. The same representation, control rule, and standardization rule must be used for TF isoforms and controls.
Raw gene-space scoring is allowed only as a documented fallback. If used, `response_score_kind` must record that choice.
## Negative-Control Scores
The negative controls are GFP and mCherry. Following the selected v1 contract, use them to define the control-standardized response score and record a small negative-control sanity check. GFP and mCherry do not define the responder labels directly.
Compute one score for each control construct. To avoid subtracting a control from itself, score each control against the other control construct:
$$
\begin{aligned}
\mu_{\mathrm{GFP}} &= \frac{1}{|G|}\sum_{i \in G} h_i \\
\mu_{\mathrm{mCherry}} &= \frac{1}{|M|}\sum_{i \in M} h_i \\
\sigma_{\mathrm{GFP}} &= \operatorname{sd}\{h_i : i \in G\} \\
\sigma_{\mathrm{mCherry}} &= \operatorname{sd}\{h_i : i \in M\} \\
s_{\mathrm{GFP}} &=
\left\|
\frac{\mu_{\mathrm{GFP}} - \mu_{\mathrm{mCherry}}}{\sigma_{\mathrm{mCherry}} + \epsilon}
\right\|_2 \\
s_{\mathrm{mCherry}} &=
\left\|
\frac{\mu_{\mathrm{mCherry}} - \mu_{\mathrm{GFP}}}{\sigma_{\mathrm{GFP}} + \epsilon}
\right\|_2
\end{aligned}
$$
The negative-control score set is:
$$
s_{\mathrm{neg}} =
\{s_{\mathrm{GFP}}, s_{\mathrm{mCherry}}\}
$$
The control artifact must record:
| Field | Meaning |
| :--- | :--- |
| `controls_used` | Must include GFP and mCherry unless one lacks support |
| `n_negative_control_scores` | Number of negative-control construct scores |
| `negative_control_scores` | GFP and mCherry control scores |
| `score_kind` | Must match TF perturbation score kind |
## Binary Label Contract
Primary thresholding follows the simple top and bottom TF quartile rule.
Let $S_{\mathrm{TF}}$ be the finite response scores of eligible non-control TF isoforms.
Let:
$$
\begin{aligned}
\tau_+ &= Q_{0.75}(S_{\mathrm{TF}}) \\
\tau_0 &= Q_{0.25}(S_{\mathrm{TF}})
\end{aligned}
$$
For each non-control TF isoform perturbation:
$$
y_p =
\begin{cases}
1, & s_p \ge \tau_+ \\
0, & s_p \le \tau_0 \\
\mathrm{ambiguous}, & \tau_0 < s_p < \tau_+
\end{cases}
$$
Rows with `ambiguous` label status are excluded from the linear probe training and evaluation table.
The controls set the score reference. The TF score distribution sets the responder and nonresponder buckets.
## Control Sanity Check
The `CONTROL_NULL.json` artifact records $s_{\mathrm{GFP}}$ and $s_{\mathrm{mCherry}}$ as a diagnostic sanity check. These scores should be interpreted as control similarity diagnostics, not as the primary threshold source.
## Required Metadata Artifacts
The metadata generation step must write these artifacts under the experiment diagnostics directory:
| Artifact | Contents |
| :--- | :--- |
| `PERTURBATION_METADATA.parquet` or `PERTURBATION_METADATA.csv` | One row per scored MORF construct |
| `CONTROL_NULL.json` | GFP and mCherry control scores, TF quartile thresholds, counts, and score summary |
| `LABEL_SUMMARY.json` | Counts of responder, nonresponder, ambiguous, control, and insufficient-support rows |
The metadata artifacts are producer inputs for `hoptf/experiments/v1_esm_linear_probe/diagnostics/LINEAR_PROBE_RESULTS.json` and `hoptf/experiments/v1_esm_linear_probe/diagnostics/LINEAR_PROBE_RESULTS_ESM3.json`.