fasta_lake.multi_omics.evidence_gate#
fasta_lake.multi_omics.evidence_gate
#
FL_MO multi-omics evidence gate (Methods §M5.5).
This is the committed, runnable implementation of the FastaLake multi-omics (FL_MO) arm reported in the manuscript. It restores, as a first-class library function, the per-sample OR-gate / AND-gate logic that produced the verified FL_MO numbers (defect-ledger D3: razor per-sample median 13,776 protein groups, +11-13% across inference strategies, OR-gate median 13,170, AND-gate 3,544).
The original verified code lived in project-specific scripts: - projects/groundup_2026-05-12/MP/scripts/17_FL_MO_persample_augment.py (OR-gate: builds the per-sample evidence_lookup.tsv from raw inputs) - manuscript/v2.2_analyses/scripts/A2_AND_gate_build_sample_fasta.py (AND-gate: subsets an existing evidence_lookup.tsv) - manuscript/v2.2_analyses/scripts/c86_sweep_build_fasta.py (threshold sweep; generalises both gates)
This module re-expresses that logic against the frozen FastaLake hashing
contract (fasta_lake.hashing) with no new dependencies, so the FL_MO numbers
can be regenerated from committed code.
The gate logic (Methods §M5.5)
A FL_MO run augments per-sample extraction (Stage 3). For each cluster representative r, include r if ANY of:
(a) a sample de novo peptide matches r exactly (the normal de-novo evidence that the Stage-3 extractor already produces); OR (b) the sample's MEGAHIT-assembled protein hashing (SHA-256, frozen normalize contract) to r's cluster has metaG_tpm >= the per-sample top-1% threshold (computed on non-zero metaG_tpm; ties -> smallest tied value so all ties are included); OR © the same hash-matched assembly protein has metaT_tpm > 1.0.
OR-gate = (a) OR (b) OR © -- default for FL_MO AND-gate = (a) AND ((b) OR ©) -- the low-FDR option
Cross-sample identity is by SHA-256 protein hash via the FL_MO hash_to_rep table (assembly protein sequence hash -> cluster representative id).
FASTA headers are NEVER edited: rescued representative sequences are copied verbatim from the cluster97 representative FASTA (CLAUDE.md contract).
Gate
#
EvidenceRow
dataclass
#
One cluster representative's per-sample evidence attribution.
Source code in fasta_lake/multi_omics/evidence_gate.py
in_gate
#
Whether this representative is admitted under the given gate.
Source code in fasta_lake/multi_omics/evidence_gate.py
to_tsv
#
Serialize this legacy gate row, formatting TPM to four decimal places.
Source code in fasta_lake/multi_omics/evidence_gate.py
top1_threshold
#
Per-sample metaG cutoff: smallest value v* such that values >= v* are the
top top_pct percent of the NON-ZERO distribution.
Ties resolve to the smallest tied value, so every protein tied at the boundary is admitted (Methods §M5.5). Returns 0.0 if nothing is non-zero (i.e. no metaG rescue possible for the sample).
Matches the verified contract in 17_FL_MO_persample_augment.py: nonzero = sorted(values_desc); top1 = nonzero[ceil(n*pct/100) - 1] re-expressed in ascending order with explicit tie-to-smallest handling.
Source code in fasta_lake/multi_omics/evidence_gate.py
passes_tpm
#
passes_tpm(metag_tpm: float, metat_tpm: float, metag_cutoff: float, metat_abs: float = DEFAULT_METAT_ABS) -> tuple[bool, bool]
Return (passes_metaG_top1, passes_metaT_1) for a single assembly protein.
Source code in fasta_lake/multi_omics/evidence_gate.py
build_evidence_lookup
#
build_evidence_lookup(denovo_rep_ids, tpm_rows, assembly_seqs, hash_to_rep, metag_top_pct: float = DEFAULT_METAG_TOP_PCT, metat_abs: float = DEFAULT_METAT_ABS)
Build the per-sample evidence attribution table (the FL_MO core).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
denovo_rep_ids
|
iterable of str
|
Cluster representative ids the Stage-3 de-novo extractor selected for this sample (evidence (a)). |
required |
tpm_rows
|
iterable of (assembly_protein_id, metaG_tpm, metaT_tpm)
|
The sample's per-assembly TPM table (e.g. |
required |
assembly_seqs
|
mapping assembly_protein_id -> amino-acid sequence (str)
|
The sample's MEGAHIT predicted-genes FASTA, indexed by id. |
required |
hash_to_rep
|
mapping sha256_hex -> cluster_rep_id
|
FL_MO hash_to_rep table (cross-sample identity bridge). |
required |
metag_top_pct
|
float
|
Gate thresholds (defaults are the published §M5.5 values). |
DEFAULT_METAG_TOP_PCT
|
metat_abs
|
float
|
Gate thresholds (defaults are the published §M5.5 values). |
DEFAULT_METAG_TOP_PCT
|
Returns:
| Type | Description |
|---|---|
(rows, stats) where rows is a list[EvidenceRow] and stats is a dict.
|
|
A representative may be admitted by both de novo and TPM evidence; in that
|
|
case it appears once with source=DENOVO and the TPM flags set.
|
|
Source code in fasta_lake/multi_omics/evidence_gate.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |