// gene_regulation.sy -- Gene expression control from promoters to
// RNA interference as native Scyla.
//
// Marjorie McCubbins + Aether, April 2026
// Patent pending: 64/034,536
//
// From operon to enhancer, from chromatin remodeling to miRNA,
// every layer of gene regulation encoded with UniProt accessions,
// structural motifs, and mechanistic detail. This is how a cell
// decides which genes to read and when.
//
// Sources:
//   Alberts B et al. Molecular Biology of the Cell, 7th ed, 2022.
//   Nelson DL, Cox MM. Lehninger Principles of Biochemistry, 8th ed, 2021.
//   Lodish H et al. Molecular Cell Biology, 9th ed, 2021.
//   Jacob F, Monod J. J Mol Biol 3:318-356, 1961 (operon model, Nobel 1965).
//   Yanofsky C. Nature 289:751-758, 1981 (trp attenuation).
//   Fire A et al. Nature 391:806-811, 1998 (RNAi, Nobel 2006).
//   Bartel DP. Cell 136:215-233, 2009 (miRNA review).
//   Kornberg RD. Science 320:1286-1290, 2008 (eukaryotic transcription, Nobel 2006).
//   Doudna JA, Charpentier E. Science 346:1258096, 2014 (CRISPR, Nobel 2020).

// ═══════════════════════════════════════════════════════
// STRUCTS
// ═══════════════════════════════════════════════════════

struct OperonComponent {
    name: String,
    gene: String,
    accession: String,
    role: String,
    description: String,
    citation: String,
}

struct TranscriptionFactor {
    name: String,
    gene: String,
    accession: String,
    tf_class: String,
    dna_motif: String,
    role: String,
    description: String,
    citation: String,
}

struct RegulatoryElement {
    name: String,
    element_type: String,
    typical_distance: String,
    mechanism: String,
    key_protein: String,
    key_accession: String,
    description: String,
    citation: String,
}

struct ChromatinRemodeler {
    name: String,
    complex_family: String,
    accession: String,
    gene: String,
    mechanism: String,
    atp_dependent: Bool,
    description: String,
    citation: String,
}

struct RNAProcessingEvent {
    name: String,
    event_type: String,
    key_enzyme: String,
    accession: String,
    mechanism: String,
    description: String,
    citation: String,
}

struct RNAiComponent {
    name: String,
    pathway: String,
    accession: String,
    gene: String,
    role: String,
    description: String,
    citation: String,
}

struct TranslationalControl {
    name: String,
    pathway: String,
    key_protein: String,
    accession: String,
    mechanism: String,
    description: String,
    citation: String,
}

struct SignalRegulation {
    name: String,
    pathway: String,
    key_protein: String,
    accession: String,
    trigger: String,
    mechanism: String,
    target_genes: String,
    description: String,
    citation: String,
}

struct CRISPRComponent {
    name: String,
    component_type: String,
    accession: String,
    organism: String,
    role: String,
    description: String,
    citation: String,
}

struct SplicingVariant {
    name: String,
    variant_type: String,
    mechanism: String,
    example_gene: String,
    description: String,
    citation: String,
}

struct GeneralTF {
    name: String,
    accession: String,
    gene: String,
    assembly_order: Int,
    role: String,
    description: String,
    citation: String,
}

// ═══════════════════════════════════════════════════════
// HELPER CONSTRUCTORS
// ═══════════════════════════════════════════════════════

fn opcomp(n: String, g: String, a: String, r: String, d: String, ci: String) -> OperonComponent {
    return OperonComponent { name: n, gene: g, accession: a, role: r, description: d, citation: ci }
}

fn txfactor(n: String, g: String, a: String, tc: String, dm: String, r: String, d: String, ci: String) -> TranscriptionFactor {
    return TranscriptionFactor { name: n, gene: g, accession: a, tf_class: tc, dna_motif: dm, role: r, description: d, citation: ci }
}

fn regelem(n: String, et: String, td: String, me: String, kp: String, ka: String, d: String, ci: String) -> RegulatoryElement {
    return RegulatoryElement { name: n, element_type: et, typical_distance: td, mechanism: me, key_protein: kp, key_accession: ka, description: d, citation: ci }
}

fn remodeler(n: String, cf: String, a: String, g: String, me: String, ad: Bool, d: String, ci: String) -> ChromatinRemodeler {
    return ChromatinRemodeler { name: n, complex_family: cf, accession: a, gene: g, mechanism: me, atp_dependent: ad, description: d, citation: ci }
}

fn rnaproc(n: String, et: String, ke: String, a: String, me: String, d: String, ci: String) -> RNAProcessingEvent {
    return RNAProcessingEvent { name: n, event_type: et, key_enzyme: ke, accession: a, mechanism: me, description: d, citation: ci }
}

fn rnai(n: String, p: String, a: String, g: String, r: String, d: String, ci: String) -> RNAiComponent {
    return RNAiComponent { name: n, pathway: p, accession: a, gene: g, role: r, description: d, citation: ci }
}

fn transctrl(n: String, p: String, kp: String, a: String, me: String, d: String, ci: String) -> TranslationalControl {
    return TranslationalControl { name: n, pathway: p, key_protein: kp, accession: a, mechanism: me, description: d, citation: ci }
}

fn sigreg(n: String, p: String, kp: String, a: String, tr: String, me: String, tg: String, d: String, ci: String) -> SignalRegulation {
    return SignalRegulation { name: n, pathway: p, key_protein: kp, accession: a, trigger: tr, mechanism: me, target_genes: tg, description: d, citation: ci }
}

fn crispr(n: String, ct: String, a: String, o: String, r: String, d: String, ci: String) -> CRISPRComponent {
    return CRISPRComponent { name: n, component_type: ct, accession: a, organism: o, role: r, description: d, citation: ci }
}

fn splvar(n: String, vt: String, me: String, eg: String, d: String, ci: String) -> SplicingVariant {
    return SplicingVariant { name: n, variant_type: vt, mechanism: me, example_gene: eg, description: d, citation: ci }
}

fn gtf(n: String, a: String, g: String, ao: Int, r: String, d: String, ci: String) -> GeneralTF {
    return GeneralTF { name: n, accession: a, gene: g, assembly_order: ao, role: r, description: d, citation: ci }
}

// ═══════════════════════════════════════════════════════
// SECTION A: PROKARYOTIC GENE REGULATION
// ═══════════════════════════════════════════════════════
//
// Jacob and Monod, Nobel Prize 1965. The operon model:
// a single regulatory unit controlling a set of structural
// genes from one promoter. The blueprint for understanding
// how environment controls gene expression.
//
// Alberts 7th ed Ch 7; Lehninger 8th ed Ch 28; Lodish 9th ed Ch 9.

fn lac_operon_component(name: String) -> OperonComponent {
    // The lac operon: inducible system for lactose catabolism in E. coli.
    // Negative control (lacI repressor) + positive control (CAP/cAMP).
    // Jacob F, Monod J. J Mol Biol 3:318-356, 1961.

    // Structural genes
    if name == "lacZ" { return opcomp("beta-galactosidase", "lacZ", "P00722", "structural_gene", "Cleaves lactose into glucose and galactose. Also cleaves the artificial substrate X-gal to produce blue color (blue-white screening). Tetramer, 1023 residues per monomer. The workhorse enzyme of the operon.", "Jacob F, Monod J. J Mol Biol 3:318-356, 1961") }
    if name == "lacY" { return opcomp("lactose permease", "lacY", "P02920", "structural_gene", "Symporter: imports lactose (and analogues) with H+ across the inner membrane. 12 transmembrane helices. Without LacY, lactose cannot enter the cell and the operon is useless.", "Kaback HR. Proc Natl Acad Sci 102:13399-13404, 2005") }
    if name == "lacA" { return opcomp("thiogalactoside transacetylase", "lacA", "P07464", "structural_gene", "Acetylates thiogalactosides and other non-metabolizable sugars. Likely a detoxification function, transferring acetyl-CoA to galactosides to mark them for export.", "Lehninger 8th ed Ch 28") }

    // Regulatory gene
    if name == "lacI" { return opcomp("lac repressor", "lacI", "P03023", "repressor", "Constitutively expressed from its own promoter (lacIp). Tetramer binds the operator (lacO) and blocks RNA polymerase. Allolactose (the true inducer, not lactose itself) binds lacI, causing conformational change that releases it from the operator. The archetype of allosteric regulation in gene control.", "Lewis M et al. Science 271:1247-1254, 1996") }

    // Regulatory regions
    if name == "lacO" { return opcomp("lac operator", "lacO", "", "operator", "21 bp palindromic sequence overlapping the promoter. LacI repressor binds here. Actually three operators exist: O1 (primary, overlaps promoter), O2 (within lacZ, +412), O3 (upstream, -82). Repressor tetramer bridges O1 with O2 or O3, forming a DNA loop. Looping increases repression 50-fold.", "Oehler S et al. EMBO J 9:973-979, 1990") }
    if name == "lacP" { return opcomp("lac promoter", "lacP", "", "promoter", "Contains the -10 (TATGTT vs consensus TATAAT) and -35 (TTTACA vs consensus TTGACA) elements recognized by sigma-70. Weak promoter by itself: poor match to consensus explains why CAP activation is needed for high-level expression.", "Lehninger 8th ed Ch 28") }

    // Positive regulators
    if name == "CAP" { return opcomp("catabolite activator protein (CAP/CRP)", "crp", "P0ACJ8", "activator", "cAMP receptor protein. When glucose is LOW, adenylate cyclase produces cAMP. cAMP binds CAP, inducing DNA-binding conformation. CAP-cAMP binds upstream of lacP (-61 to -72) and bends DNA ~90 degrees, making direct contact with RNA polymerase alpha-CTD. Increases transcription 50-fold. This is catabolite repression: glucose present = low cAMP = no CAP activation = lac operon silent even if lactose is present.", "Busby S, Ebright RH. J Mol Biol 293:199-213, 1999") }
    if name == "allolactose" { return opcomp("allolactose (inducer)", "", "", "inducer", "1,6-allolactose, a rearrangement product of lactose made by beta-galactosidase itself. The TRUE inducer of the lac operon (not lactose). Binds the lacI repressor and triggers conformational change. This creates a positive feedback loop: a tiny amount of constitutive lacZ expression produces trace allolactose, which derepresses the operon to make more beta-galactosidase. IPTG (isopropyl-beta-D-thiogalactopyranoside) is a synthetic inducer that cannot be cleaved.", "Jobe A, Bourgeois S. J Mol Biol 69:397-408, 1972") }

    return opcomp("", "", "", "", "", "")
}

fn trp_operon_component(name: String) -> OperonComponent {
    // The trp operon: repressible system for tryptophan biosynthesis.
    // Negative control (TrpR corepressor) + attenuation (leader peptide).
    // Yanofsky C. Nature 289:751-758, 1981.

    if name == "trpR" { return opcomp("trp repressor", "trpR", "P0A881", "corepressor", "Aporepressor: inactive alone. When tryptophan (the corepressor) is abundant, Trp binds TrpR, activating its DNA-binding form. Active TrpR binds the trp operator and blocks transcription. The opposite logic of lac: the product of the pathway shuts off its own synthesis.", "Schevitz RW et al. Nature 317:782-786, 1985") }
    if name == "trpE" { return opcomp("anthranilate synthase component I", "trpE", "P00895", "structural_gene", "First enzyme in tryptophan biosynthesis. Converts chorismate to anthranilate. Feedback-inhibited by tryptophan (double regulation: transcription and enzyme activity).", "Lehninger 8th ed Ch 22") }
    if name == "trpD" { return opcomp("anthranilate phosphoribosyltransferase", "trpD", "P00896", "structural_gene", "Second enzyme. Converts anthranilate to N-(5-phosphoribosyl)-anthranilate.", "Lehninger 8th ed Ch 22") }
    if name == "trpC" { return opcomp("indole-3-glycerol-phosphate synthase / phosphoribosylanthranilate isomerase", "trpC", "P00909", "structural_gene", "Bifunctional enzyme catalyzing steps 3 and 4 of tryptophan biosynthesis.", "Lehninger 8th ed Ch 22") }
    if name == "trpB" { return opcomp("tryptophan synthase beta chain", "trpB", "P0A879", "structural_gene", "Beta subunit of tryptophan synthase. Forms alpha-beta-beta-alpha complex with TrpA. Catalyzes final step: indole + serine -> tryptophan (PLP-dependent).", "Hyde CC et al. J Biol Chem 263:17857-17871, 1988") }
    if name == "trpA" { return opcomp("tryptophan synthase alpha chain", "trpA", "P0A877", "structural_gene", "Alpha subunit of tryptophan synthase. Cleaves indole-3-glycerol-phosphate to indole + glyceraldehyde-3-phosphate. Indole channeled through tunnel to beta subunit.", "Lehninger 8th ed Ch 22") }
    if name == "trpL" { return opcomp("trp leader peptide (attenuator)", "trpL", "", "attenuator", "14-amino-acid leader peptide with two consecutive Trp codons (Trp-Trp at positions 10-11). Attenuation mechanism: if Trp is scarce, ribosome stalls at Trp codons, allowing an antiterminator hairpin (2-3) to form in the mRNA leader, preventing the terminator hairpin (3-4). Transcription continues into structural genes. If Trp is abundant, ribosome translates through quickly, terminator forms, transcription aborts. This is a second layer of regulation on top of repressor control.", "Yanofsky C. Nature 289:751-758, 1981") }

    return opcomp("", "", "", "", "", "")
}

fn operon_logic(operon: String, glucose: Bool, inducer: Bool) -> String {
    // Returns transcription status based on environmental conditions.
    // For lac operon: glucose and lactose (allolactose) levels matter.
    if operon == "lac" {
        if glucose == true {
            if inducer == true { return "LOW: repressor released by allolactose BUT CAP inactive (glucose present, low cAMP). Basal transcription only." }
            if inducer == false { return "OFF: repressor bound to operator AND CAP inactive. Double lock." }
        }
        if glucose == false {
            if inducer == true { return "FULL ON: repressor released by allolactose AND CAP-cAMP active. Maximum transcription. This is the only condition where the lac operon is fully induced." }
            if inducer == false { return "OFF: CAP-cAMP active but repressor still bound. No inducer to release it." }
        }
    }
    // For trp operon: tryptophan levels matter.
    if operon == "trp" {
        if inducer == true { return "OFF: tryptophan (corepressor) abundant. TrpR-Trp complex binds operator. Attenuation also terminates any read-through transcription." }
        if inducer == false { return "ON: tryptophan scarce. TrpR aporepressor cannot bind operator. Ribosome stalls at Trp codons in leader, antiterminator forms, full transcription proceeds." }
    }
    return ""
}

// ═══════════════════════════════════════════════════════
// SECTION B: EUKARYOTIC TRANSCRIPTION MACHINERY
// ═══════════════════════════════════════════════════════
//
// RNA Polymerase II and the general transcription factors.
// Kornberg RD, Nobel 2006. The preinitiation complex (PIC)
// assembles at the core promoter in a defined order.
//
// Alberts 7th ed Ch 6; Lehninger 8th ed Ch 26; Lodish 9th ed Ch 9.

fn rna_pol_ii(subunit: String) -> OperonComponent {
    // RNA Polymerase II: the 12-subunit enzyme that transcribes all
    // protein-coding genes (mRNA) plus most snRNAs and miRNAs.
    if subunit == "RPB1" { return opcomp("RPB1 (largest subunit)", "POLR2A", "P24928", "catalytic_subunit", "Largest subunit (220 kDa). Contains the C-terminal domain (CTD): 52 heptad repeats (YSPTSPS) in humans. CTD phosphorylation orchestrates the transcription cycle: unphosphorylated CTD binds Mediator and recruits PIC, Ser5-P (by TFIIH/CDK7) marks initiation and recruits capping enzymes, Ser2-P (by P-TEFb/CDK9) marks elongation and recruits splicing/polyadenylation factors.", "Kornberg RD. Science 320:1286-1290, 2008") }
    if subunit == "RPB2" { return opcomp("RPB2 (second largest)", "POLR2B", "P30876", "catalytic_subunit", "Second largest subunit. Forms the active site cleft with RPB1. Contains part of the NTP entry pore. Contacts the DNA-RNA hybrid in the active center.", "Cramer P et al. Science 292:1863-1876, 2001") }
    if subunit == "RPB3" { return opcomp("RPB3", "POLR2C", "P19387", "assembly_platform", "Core subunit forming the RPB3/RPB11 heterodimer, analogous to bacterial alpha subunit dimer. Platform for Pol II assembly.", "Lodish 9th ed Ch 9") }
    return opcomp("", "", "", "", "", "")
}

fn general_tf(name: String) -> GeneralTF {
    // General transcription factors assemble on the core promoter
    // in a specific order to form the preinitiation complex (PIC).
    // TFIID -> TFIIA -> TFIIB -> Pol II/TFIIF -> TFIIE -> TFIIH.

    if name == "TFIID" { return gtf("TFIID (TBP + TAFs)", "P20226", "TBP", 1, "Promoter recognition. TBP (TATA-binding protein) binds TATA box (consensus TATAAA, located ~25-30 bp upstream of TSS). TBP inserts phenylalanines into the minor groove, bending DNA ~80 degrees. TBP-associated factors (TAFs) recognize other promoter elements (Inr, DPE, MTE). TFIID nucleates PIC assembly.", "TFIID is the first factor to bind the promoter. TBP bends DNA sharply to create a platform for other GTFs. TAF1 (P21675) has HAT activity. TAF4 (O00268) is a coactivator interface.", "Alberts 7th ed Ch 6; Nikolov DB et al. Nature 360:40-46, 1992") }

    if name == "TFIIA" { return gtf("TFIIA", "P23193", "GTF2A1", 2, "Stabilizes TBP-DNA interaction. Antirepression: blocks negative regulators from displacing TBP. Contains alpha/beta and gamma subunits.", "Stabilizes the TFIID-promoter complex and counteracts transcriptional repressors that compete with TBP for TATA box binding.", "Lehninger 8th ed Ch 26") }

    if name == "TFIIB" { return gtf("TFIIB", "Q00403", "GTF2B", 3, "Start site selection. Bridges TBP and RNA Pol II. The B-reader and B-linker elements position Pol II precisely at the transcription start site (+1). Recruits Pol II-TFIIF complex.", "TFIIB makes direct contacts with both TBP (upstream face) and Pol II (dock domain). Mutations in TFIIB shift the start site, proving it sets +1 position.", "Alberts 7th ed Ch 6; Lodish 9th ed Ch 9") }

    if name == "TFIIF" { return gtf("TFIIF (RAP30/RAP74)", "P13984", "GTF2F1", 4, "Escorts Pol II to the promoter. Reduces nonspecific DNA binding by Pol II. RAP74 (large subunit, P35269) has phosphatase activity on CTD. RAP30 (small subunit) binds Pol II directly.", "Enters as Pol II-TFIIF complex. Stabilizes the growing PIC and helps Pol II engage the template strand.", "Lehninger 8th ed Ch 26") }

    if name == "TFIIE" { return gtf("TFIIE", "P29083", "GTF2E1", 5, "Recruits TFIIH. Two subunits: alpha (56 kDa) and beta (34 kDa, P29084). Modulates TFIIH helicase and kinase activities. Required for promoter melting.", "TFIIE bridges between Pol II and TFIIH. Without TFIIE, TFIIH cannot be recruited and the promoter cannot be opened.", "Alberts 7th ed Ch 6") }

    if name == "TFIIH" { return gtf("TFIIH", "P19447", "ERCC3", 6, "The engine of initiation. 10-subunit complex with two enzymatic activities: (a) XPB helicase (P19447, 3-to-5) melts ~11 bp around the start site to form the transcription bubble, (b) CDK7 kinase (P43461) phosphorylates CTD Ser5 to trigger promoter escape. TFIIH also functions in nucleotide excision repair (NER). Mutations cause xeroderma pigmentosum (XPB, XPD) and trichothiodystrophy.", "TFIIH is the last GTF to join the PIC. Its helicase opens the DNA, its kinase phosphorylates CTD to release Pol II from the promoter. This is the committed step of initiation.", "Alberts 7th ed Ch 6; Lehninger 8th ed Ch 26; Compe E, Egly JM. Nat Rev Mol Cell Biol 13:343-354, 2012") }

    return gtf("", "", "", 0, "", "", "")
}

fn mediator_complex() -> OperonComponent {
    // Mediator: the bridge between gene-specific TFs and Pol II.
    return opcomp("Mediator complex", "MED1", "Q15648", "coactivator", "30-subunit complex (in humans) that bridges gene-specific transcription factors bound at enhancers/proximal elements to the Pol II PIC at the core promoter. Mediator integrates activating and repressive signals. Head module contacts Pol II, middle module contacts TFIIB, tail module contacts activators. MED1 (TRAP220) is the nuclear receptor-binding subunit. MED12 (Q93074) and MED13 (Q9UHV7) form the CDK8 kinase module which can repress transcription. Without Mediator, gene-specific regulation cannot reach the basal machinery.", "Kornberg RD. Trends Biochem Sci 30:235-239, 2005; Alberts 7th ed Ch 6")
}

fn promoter_element(name: String) -> RegulatoryElement {
    // Core promoter elements recognized by the PIC.
    if name == "TATA_box" { return regelem("TATA box", "core_promoter", "-25 to -30 bp from TSS", "TBP subunit of TFIID binds the minor groove. TATAAA consensus. Present in ~24% of human promoters. Strongly positioned TSS.", "TBP", "P20226", "The classic core promoter element. Goldberg-Hogness box. Identified in 1979. Not universal: most human promoters lack a TATA box and use Inr, DPE, or CpG islands instead.", "Alberts 7th ed Ch 6; Lodish 9th ed Ch 9") }
    if name == "Inr" { return regelem("Initiator (Inr)", "core_promoter", "spans TSS (-2 to +5)", "Recognized by TAF1/TAF2 subunits of TFIID. Consensus: YYANWYY (Y=pyrimidine, N=any, W=A/T). Can function alone or synergize with TATA box or DPE.", "TAF1", "P21675", "The Inr element directly encompasses the +1 transcription start site. More common than TATA box. Found in both TATA-containing and TATA-less promoters.", "Smale ST, Baltimore D. Cell 57:103-113, 1989") }
    if name == "DPE" { return regelem("Downstream promoter element (DPE)", "core_promoter", "+28 to +34 from TSS", "Recognized by TAF6/TAF9 subunits of TFIID. Consensus: RGWYV. Functions in TATA-less promoters in cooperation with Inr.", "TAF6", "P49848", "DPE is downstream of the TSS, unlike TATA which is upstream. Prevalent in Drosophila. Functions as an alternative to TATA box, always requiring a functional Inr.", "Burke TW, Kadonaga JT. Genes Dev 10:711-724, 1996") }
    if name == "CpG_island" { return regelem("CpG island", "core_promoter", "spans TSS (typically -500 to +500)", "GC-rich regions (observed/expected CpG ratio >0.6) that resist DNA methylation. Associated with ~70% of human gene promoters. Housekeeping genes almost always have CpG island promoters. Often lack TATA box; dispersed initiation from multiple TSSs.", "CFP1/CXXC1", "Q9P0U4", "CpG islands are unmethylated in normal somatic cells. Methylation of CpG island promoters = stable gene silencing (seen in X-inactivation, imprinting, cancer). H3K4me3 marks active CpG island promoters.", "Deaton AM, Bird A. Genes Dev 25:1010-1022, 2011") }
    return regelem("", "", "", "", "", "", "", "")
}

// ═══════════════════════════════════════════════════════
// SECTION C: REGULATORY ELEMENTS
// ═══════════════════════════════════════════════════════
//
// Enhancers, silencers, insulators, and locus control
// regions. These elements can act over enormous genomic
// distances through DNA looping.
//
// Alberts 7th ed Ch 7; Lodish 9th ed Ch 9.

fn regulatory_element(name: String) -> RegulatoryElement {
    if name == "enhancer" { return regelem("Enhancer", "distal_activating", "Can be 1 Mb or more from target promoter, upstream, downstream, or in introns", "Enhancers contain clusters of TF binding sites. When bound by activators, they loop to contact the promoter via Mediator and cohesin. Marked by H3K4me1 (poised) or H3K4me1 + H3K27ac (active). eRNAs (enhancer RNAs) transcribed bidirectionally from active enhancers. Orientation-independent and position-independent. Can skip over intervening genes.", "Mediator/Cohesin", "Q15648", "Enhancers are the primary mechanism for cell-type-specific gene expression. The same gene can have different enhancers active in different cell types. Super-enhancers: large clusters of enhancers driving cell identity genes, occupied by high levels of Mediator, BRD4, and master TFs.", "Alberts 7th ed Ch 7; Lodish 9th ed Ch 9; Hnisz D et al. Cell 155:934-947, 2013") }

    if name == "silencer" { return regelem("Silencer", "distal_repressing", "Variable, can be far from promoter", "Opposite of enhancer. Binds repressive TFs that recruit corepressors (NCoR, SMRT) and HDACs. Results in local histone deacetylation and compaction. Can also recruit Polycomb (PRC2) for H3K27me3 silencing. Some silencers are constitutive, others are tissue-specific.", "REST/NRSF", "Q13127", "REST (RE1-silencing transcription factor) binds the RE1/NRSE element to silence neuronal genes in non-neuronal tissues. Recruits CoREST, LSD1, and HDAC1/2. Loss of REST silencing is implicated in neurodegeneration.", "Lodish 9th ed Ch 9; Ballas N et al. Cell 121:645-657, 2005") }

    if name == "insulator" { return regelem("Insulator (boundary element)", "boundary", "Between enhancer and non-target promoter", "Blocks enhancer-promoter communication when positioned between them (enhancer-blocking activity). Some also act as barriers against heterochromatin spreading. CTCF (CCCTC-binding factor) is the primary insulator protein in vertebrates. CTCF works with cohesin to form topologically associating domain (TAD) boundaries. Convergent CTCF sites create loop anchors.", "CTCF", "P49711", "CTCF is the master insulator protein with 11 zinc fingers. Binds ~55,000 sites in the human genome. CTCF orientation matters: convergent CTCF motifs form stable loops via cohesin (loop extrusion model). Loss of CTCF boundaries causes enhancer hijacking in cancer (e.g., IDH mutant gliomas, CTCF site methylation).", "Alberts 7th ed Ch 7; Rao SS et al. Cell 159:1665-1680, 2014") }

    if name == "LCR" { return regelem("Locus control region (LCR)", "distal_master_activating", "Can be 5-50 kb from target genes", "Master regulatory element. Required for high-level, tissue-specific, position-independent expression of an entire gene cluster. The beta-globin LCR (5 DNase I hypersensitive sites, HS1-5) controls sequential expression of epsilon, gamma, delta, and beta globin during development (hemoglobin switching). LCR makes direct contact with the active promoter via looping (active chromatin hub model). Deletion of the LCR silences the entire 60 kb beta-globin locus.", "GATA1/NF-E2", "P15976", "The beta-globin LCR was the first LCR discovered (Grosveld et al. Cell 51:975-985, 1987). It explained why transgenes inserted at random positions expressed poorly unless the LCR was included. The LCR overcomes position effects by creating an open chromatin domain.", "Alberts 7th ed Ch 7; Lodish 9th ed Ch 9; Grosveld F et al. Cell 51:975-985, 1987") }

    return regelem("", "", "", "", "", "", "", "")
}

// ═══════════════════════════════════════════════════════
// SECTION D: TRANSCRIPTION FACTOR STRUCTURAL MOTIFS
// ═══════════════════════════════════════════════════════
//
// DNA-binding domains fall into a small number of
// structural families. Each motif recognizes DNA
// differently and has distinct biology.
//
// Alberts 7th ed Ch 7; Lodish 9th ed Ch 9.

fn tf_structural_motif(motif: String) -> TranscriptionFactor {
    if motif == "zinc_finger" { return txfactor("Cys2His2 zinc finger", "SP1", "P08047", "zinc_finger", "GC box (GGGCGG)", "activator", "Most common DNA-binding motif in the human genome (~700 C2H2 ZF proteins). Each finger is ~30 aa stabilized by a Zn2+ ion coordinated by 2 Cys and 2 His residues. Each finger recognizes ~3 bp in the major groove. Tandem arrays of fingers read extended sequences. SP1 has 3 zinc fingers, recognizes GC-rich elements in housekeeping gene promoters. Kruppel-like factors (KLFs) use the same motif.", "Alberts 7th ed Ch 7; Lodish 9th ed Ch 9; Pavletich NP, Pabo CO. Science 252:809-817, 1991") }

    if motif == "helix_turn_helix" { return txfactor("Helix-turn-helix (HTH)", "lacI (prokaryotic archetype)", "P03023", "helix_turn_helix", "lac operator (palindromic)", "repressor", "The oldest known DNA-binding motif. Two alpha helices connected by a short turn. The recognition helix inserts into the major groove. Prokaryotic examples: lac repressor, lambda cI/Cro, trp repressor. Eukaryotic variants: homeodomain, winged HTH (forkhead), POU domain. The HTH alone is not sufficient for stable binding; dimerization or additional contacts are required.", "Alberts 7th ed Ch 7; Lehninger 8th ed Ch 28; Brennan RG, Matthews BW. J Biol Chem 264:1903-1906, 1989") }

    if motif == "leucine_zipper" { return txfactor("Leucine zipper (bZIP)", "JUN (c-Jun)", "P05412", "leucine_zipper", "AP-1 site (TGACTCA)", "activator", "Alpha-helical coiled coil held together by leucine residues at every 7th position (heptad repeat). Two helices wrap around each other (zipper). Basic region N-terminal to the zipper contacts DNA. Always dimerize: homodimers (Jun-Jun) or heterodimers (Jun-Fos = AP-1). FOS (P01100) cannot homodimerize. AP-1 complex controls proliferation, differentiation, apoptosis. bZIP TFs include CREB (P16220), ATF family, C/EBP family.", "Alberts 7th ed Ch 7; Lodish 9th ed Ch 9; Landschulz WH et al. Science 240:1759-1764, 1988") }

    if motif == "helix_loop_helix" { return txfactor("Helix-loop-helix (bHLH)", "MYC (c-Myc)", "P01106", "helix_loop_helix", "E-box (CACGTG)", "activator", "Two amphipathic helices connected by a loop. HLH domain mediates dimerization, basic region contacts DNA. Class I (E proteins: E12/E47, ubiquitous) heterodimerize with Class II (tissue-specific: MyoD, NeuroD, Myc). Class V (Id proteins) lack basic region and act as dominant-negative inhibitors. MYC-MAX heterodimers activate proliferative genes; MAD-MAX heterodimers repress them. MYC is an oncogene amplified in many cancers.", "Alberts 7th ed Ch 7; Lodish 9th ed Ch 9; Murre C et al. Cell 56:777-783, 1989") }

    if motif == "homeodomain" { return txfactor("Homeodomain", "PAX6", "P26367", "homeodomain", "TAAT core motif", "master_regulator", "60-amino-acid domain with three helices. Helix 3 (recognition helix) contacts the major groove. Found in Hox proteins that specify body plan along the anterior-posterior axis (colinearity: gene order on chromosome = expression order in body). PAX6 is the master control gene for eye development across all phyla (Drosophila eyeless, mouse Small eye). Aniridia in humans from PAX6 haploinsufficiency. Homeodomain proteins were discovered through homeotic mutations in Drosophila (Lewis EB, Nobel 1995).", "Alberts 7th ed Ch 7; Lodish 9th ed Ch 9; Gehring WJ et al. Annu Rev Biochem 63:487-526, 1994") }

    if motif == "nuclear_hormone_receptor" { return txfactor("Nuclear hormone receptor (zinc finger + LBD)", "ESR1 (estrogen receptor alpha)", "P03372", "nuclear_receptor", "ERE (estrogen response element): AGGTCAnnnTGACCT", "ligand_dependent_activator", "Modular domain structure: A/B (AF-1 activation), C (DNA-binding, 2 zinc fingers of C4 type), D (hinge), E (ligand-binding domain, LBD, AF-2 activation), F (variable). Type I (steroid): cytoplasmic, ligand binding causes nuclear translocation, bind as homodimers to palindromic HREs. Type II (RXR heterodimers): already in nucleus, bound to DNA, ligand switches from repression to activation. Includes ER, AR, GR, PR (Type I) and RAR, TR, VDR, PPAR (Type II). The largest single TF family: 48 members in humans.", "Alberts 7th ed Ch 7; Lodish 9th ed Ch 9; Mangelsdorf DJ et al. Cell 83:835-839, 1995") }

    return txfactor("", "", "", "", "", "", "", "")
}

// ═══════════════════════════════════════════════════════
// SECTION E: CHROMATIN REMODELING COMPLEXES
// ═══════════════════════════════════════════════════════
//
// ATP-dependent machines that slide, eject, or restructure
// nucleosomes to control DNA accessibility.
//
// Alberts 7th ed Ch 6; Lodish 9th ed Ch 9.

fn chromatin_remodeler_lookup(name: String) -> ChromatinRemodeler {
    if name == "SWI_SNF" { return remodeler("SWI/SNF (BAF complex in mammals)", "SWI/SNF", "P51532", "SMARCA4 (BRG1)", "Nucleosome sliding and ejection. ATPase translocates DNA around the histone octamer, breaking histone-DNA contacts. Can completely eject nucleosomes to expose regulatory DNA. Bromodomain in BRG1 reads acetylated histones. BAF complex: 12-15 subunits. SMARCB1/SNF5/INI1 (Q12824) is a tumor suppressor lost in malignant rhabdoid tumors. ARID1A (O14497) is the most frequently mutated chromatin regulator in cancer (~6% of all cancers).", true, "The yeast SWI/SNF complex was discovered through mating-type switching (SWI) and sucrose non-fermenting (SNF) screens. Mammalian BAF complex is essential for stem cell pluripotency and neural development. PBAF is the related complex with ARID2 and PBRM1.", "Alberts 7th ed Ch 6; Kadoch C, Crabtree GR. Nat Rev Cancer 15:397-406, 2015") }

    if name == "ISWI" { return remodeler("ISWI (ACF, CHRAC, NURF, RSF)", "ISWI", "O60264", "SMARCA5 (SNF2H)", "Nucleosome sliding (NOT ejection). ISWI complexes space nucleosomes at regular intervals, creating ordered chromatin structure. ACF (Acf1+SNF2H) and CHRAC add regular spacing. NURF (nucleosome remodeling factor) can randomize spacing to activate genes. Context-dependent: can activate or repress depending on the complex composition.", true, "ISWI complexes are the assembly-line workers of chromatin organization. Where SWI/SNF opens chromatin, ISWI creates order. SNF2H ATPase senses linker DNA length and slides nucleosomes until optimal spacing is achieved.", "Alberts 7th ed Ch 6; Lodish 9th ed Ch 9; Tsukiyama T, Wu C. Cell 83:1011-1020, 1995") }

    if name == "CHD" { return remodeler("CHD (NuRD complex)", "CHD", "Q12873", "CHD4 (Mi-2beta)", "Nucleosome sliding coupled with histone deacetylation. The NuRD (nucleosome remodeling and deacetylase) complex uniquely combines remodeling (CHD3/4 ATPase) with HDAC activity (HDAC1/2). Chromodomain in CHD4 reads methylated histones. NuRD also contains MBD2/3 (reads methylated DNA) and GATAD2A/B. Primarily repressive.", true, "CHD family has 9 members in mammals. CHD1 has a different role: binds H3K4me3 at active promoters and is required for transcription elongation through chromatin. CHD7 mutations cause CHARGE syndrome (Coloboma, Heart defects, Atresia choanae, Retarded growth, Genital hypoplasia, Ear anomalies).", "Alberts 7th ed Ch 6; Lodish 9th ed Ch 9; Tong JK et al. Nature 395:917-921, 1998") }

    if name == "INO80" { return remodeler("INO80 / SWR1 (SRCAP in mammals)", "INO80", "Q9ULG1", "INO80", "Histone variant exchange. INO80 removes H2A.Z from nucleosomes and replaces with canonical H2A. SWR1/SRCAP does the reverse: incorporates H2A.Z. H2A.Z marks promoters and enhancers, creating unstable nucleosomes that facilitate TF access. INO80 also has roles in replication fork stability and DNA repair.", true, "INO80 is unique among remodelers in its ability to edit nucleosome composition rather than just sliding them. H2A.Z-containing nucleosomes are thermodynamically less stable, creating a 'fragile' nucleosome that can be easily displaced. This poises promoters for rapid activation.", "Alberts 7th ed Ch 6; Papamichos-Chronakis M et al. Cell 144:200-213, 2011") }

    return remodeler("", "", "", "", "", false, "", "")
}

// ═══════════════════════════════════════════════════════
// SECTION F: POST-TRANSCRIPTIONAL REGULATION
// ═══════════════════════════════════════════════════════
//
// mRNA processing, alternative splicing, and mRNA stability.
// After transcription, the mRNA faces multiple layers of
// regulation before it can be translated.
//
// Alberts 7th ed Ch 6-7; Lehninger 8th ed Ch 26; Lodish 9th ed Ch 10.

fn mrna_processing(event: String) -> RNAProcessingEvent {
    // Co-transcriptional mRNA processing events.
    if event == "five_prime_cap" { return rnaproc("5' capping", "capping", "RNA guanylyltransferase (capping enzyme)", "O60942", "Three enzymatic steps: (a) RNA triphosphatase removes gamma-phosphate from 5' end, (b) guanylyltransferase adds GMP via 5'-5' triphosphate bond (unique linkage), (c) methyltransferase adds methyl to N7 of guanine (m7G cap). Cap added co-transcriptionally when nascent RNA is ~20-30 nt. Capping enzyme recruited by Ser5-phosphorylated CTD of Pol II.", "The m7G cap protects mRNA from 5'-to-3' exonucleases (XRN1), recruits the nuclear cap-binding complex (CBC: CBP80+CBP20) for splicing and export, and recruits eIF4E for translation initiation. Cap is essential: uncapped mRNAs are rapidly degraded.", "Alberts 7th ed Ch 6; Lehninger 8th ed Ch 26") }

    if event == "three_prime_poly_A" { return rnaproc("3' polyadenylation", "polyadenylation", "Poly(A) polymerase (PAP)", "P51003", "Cleavage and polyadenylation signal: AAUAAA hexamer (Proudfoot sequence) recognized by CPSF (cleavage and polyadenylation specificity factor). GU/U-rich DSE (downstream element) recognized by CstF. CPSF/CstF recruit cleavage factors that cut the pre-mRNA 10-30 nt downstream of AAUAAA. PAP then adds ~200-250 adenines without a template. PABP (poly-A binding protein, P11940) coats the tail and determines its length. Polyadenylation is coupled to transcription termination.", "Poly(A) tail promotes nuclear export, enhances translation (PABP-eIF4G interaction creates a closed loop with 5' cap), and controls mRNA stability. Tail shortening (deadenylation) by CCR4-NOT is the rate-limiting step of mRNA decay. Histone mRNAs are the notable exception: they end with a stem-loop instead of poly(A).", "Alberts 7th ed Ch 6; Lehninger 8th ed Ch 26; Lodish 9th ed Ch 10") }

    if event == "splicing" { return rnaproc("Pre-mRNA splicing", "splicing", "U2 snRNP / spliceosome", "P09661", "Intron removal by the spliceosome, a dynamic ribonucleoprotein machine of 5 snRNPs (U1, U2, U4, U5, U6) and ~200 proteins. Splice site recognition: 5' splice site (GU), branch point (A, 18-40 nt upstream of 3' ss), polypyrimidine tract, 3' splice site (AG). Two transesterification reactions: (a) 2'-OH of branch-point A attacks 5' splice site, forming a lariat, (b) free 3'-OH of exon 1 attacks 3' splice site, ligating exons and releasing the lariat. U2-U6 catalytic core: the spliceosome is a ribozyme.", "Splicing is required because human genes average 8-9 exons (median coding exon ~120 bp) with introns averaging ~3,400 bp. Some genes are enormous: dystrophin (DMD) has 79 exons spanning 2.4 Mb, taking ~16 hours to transcribe. Splicing errors cause ~15% of genetic diseases.", "Alberts 7th ed Ch 6; Lehninger 8th ed Ch 26; Lodish 9th ed Ch 10; Wahl MC et al. Cell 136:701-718, 2009") }

    return rnaproc("", "", "", "", "", "", "")
}

fn alternative_splicing(variant_type: String) -> SplicingVariant {
    // Alternative splicing generates multiple mRNAs from one gene.
    // >95% of human multi-exon genes undergo alternative splicing.
    if variant_type == "exon_skipping" { return splvar("Exon skipping (cassette exon)", "exon_skipping", "An internal exon is either included or excluded from the mature mRNA. The most common form of alternative splicing in mammals (~40% of all AS events). Regulated by ESE/ESS (exonic splicing enhancers/silencers) and ISE/ISS (intronic) bound by SR proteins (promote inclusion) and hnRNPs (promote skipping).", "FGFR2: exon IIIb (epithelial) vs exon IIIc (mesenchymal) = different ligand specificity. Drosophila DSCAM: 38,016 possible isoforms by combinatorial exon skipping.", "Single most important mechanism for proteome expansion from ~20,000 genes. SR proteins (SRSF1/ASF, Q07955) bind ESEs with RRM domains and recruit U1/U2 snRNPs. hnRNP A1 (P09651) antagonizes SR proteins.", "Lodish 9th ed Ch 10; Alberts 7th ed Ch 6; Wang ET et al. Nature 456:470-476, 2008") }

    if variant_type == "intron_retention" { return splvar("Intron retention", "intron_retention", "An intron is retained in the mature mRNA instead of being spliced out. Most common form of AS in plants and fungi. In mammals, often triggers nonsense-mediated decay (NMD) because retained introns usually contain premature stop codons. Can be a regulatory mechanism: detained introns in the nucleus as a post-transcriptional gene silencing strategy.", "Granulocyte differentiation: intron retention in mRNAs encoding splicing factors triggers NMD, reducing splicing factor levels and reshaping the transcriptome during maturation.", "Intron retention was once considered a splicing error but is now recognized as a regulated event. Particularly important in hematopoietic differentiation and neuronal development.", "Lodish 9th ed Ch 10; Braunschweig U et al. Cell 152:1252-1269, 2013") }

    if variant_type == "alt_five_prime" { return splvar("Alternative 5' splice site", "alt_five_prime_ss", "Two or more 5' splice sites (donor sites) compete for pairing with the same 3' splice site. Results in exons with different 3' boundaries. The upstream 5'ss produces a longer exon, the downstream 5'ss a shorter one.", "Bcl-x: alternative 5' splice site produces Bcl-xL (long, anti-apoptotic) vs Bcl-xS (short, pro-apoptotic). The splice choice is literally a life-or-death decision for the cell.", "Regulated by the relative strength of competing 5' splice sites and by SR/hnRNP proteins that enhance or suppress recognition of each site.", "Lodish 9th ed Ch 10; Alberts 7th ed Ch 6") }

    if variant_type == "alt_three_prime" { return splvar("Alternative 3' splice site", "alt_three_prime_ss", "Two or more 3' splice sites (acceptor sites) compete for pairing with the same 5' splice site. Results in exons with different 5' boundaries. Often involves competition between polypyrimidine tracts.", "Calcitonin/CGRP: in thyroid C-cells, exons 1-4 are used (calcitonin hormone). In neurons, exon 4 is skipped and exons 5-6 are used (CGRP neuropeptide). Same gene, different tissues, different hormones.", "Regulated by tissue-specific splicing factors like NOVA (neurons, P51513), PTB/PTBP1 (P26599, represses neural exons in non-neuronal tissues), and MBNL1 (Q9NR56, muscle).", "Lodish 9th ed Ch 10; Lehninger 8th ed Ch 26") }

    return splvar("", "", "", "", "", "")
}

fn mrna_stability(element: String) -> RNAProcessingEvent {
    // Elements and mechanisms controlling mRNA half-life.
    if element == "ARE" { return rnaproc("AU-rich element (ARE)", "stability_element", "Tristetraprolin (TTP/ZFP36)", "P26651", "AREs (AUUUA pentamers, often in UUAUUUAUU nonamer context) in the 3' UTR target mRNAs for rapid degradation. TTP binds AREs and recruits the CCR4-NOT deadenylase complex, triggering deadenylation, decapping (DCP1/2), and 5'-to-3' degradation by XRN1. ARE-containing mRNAs encode cytokines (TNF-alpha, IL-6), proto-oncogenes (c-Myc, c-Fos), and growth factors. Half-lives as short as 15-30 minutes vs hours for stable mRNAs.", "ARE-mediated decay is a critical inflammation control mechanism. HuR/ELAVL1 (Q15717) is a stabilizing ARE-binding protein that competes with TTP. In cancer, HuR overexpression stabilizes oncogene mRNAs.", "Alberts 7th ed Ch 7; Lodish 9th ed Ch 10; Chen CY, Shyu AB. Trends Biochem Sci 20:465-470, 1995") }

    if element == "NMD" { return rnaproc("Nonsense-mediated mRNA decay (NMD)", "quality_control", "UPF1 (RNA helicase)", "Q92900", "NMD degrades mRNAs with premature termination codons (PTCs). Rule of thumb: a stop codon >50-55 nt upstream of an exon junction complex (EJC) triggers NMD. UPF1 is recruited by eRF1/eRF3 at the terminating ribosome. If UPF1 encounters a downstream EJC (deposited by splicing), it is phosphorylated by SMG1 kinase, triggering mRNA degradation via SMG5/6/7. NMD eliminates ~5-25% of alternatively spliced mRNAs (unproductive splicing, RUST).", "NMD is both quality control (eliminates nonsense mutations that would produce truncated toxic proteins) and a gene regulation mechanism (regulated unproductive splicing and translation). ~one-third of inherited disease alleles generate PTCs, and NMD determines whether the phenotype is recessive (PTC mRNA destroyed, no dominant-negative) or dominant (PTC protein produced).", "Alberts 7th ed Ch 7; Lodish 9th ed Ch 10; Kurosaki T et al. Nat Rev Mol Cell Biol 20:382-398, 2019") }

    return rnaproc("", "", "", "", "", "", "")
}

// ═══════════════════════════════════════════════════════
// SECTION G: RNA INTERFERENCE
// ═══════════════════════════════════════════════════════
//
// Small RNA pathways that silence gene expression
// post-transcriptionally. Fire and Mello, Nobel 2006.
//
// Alberts 7th ed Ch 7; Lodish 9th ed Ch 10;
// Fire A et al. Nature 391:806-811, 1998.

fn rnai_component(name: String) -> RNAiComponent {
    // miRNA pathway: pri-miRNA -> pre-miRNA (Drosha) -> miRNA duplex (Dicer) -> RISC
    if name == "DROSHA" { return rnai("Drosha (RNase III)", "miRNA", "Q9NRR4", "DROSHA", "nuclear_processing", "Class III RNase that cleaves pri-miRNA (primary miRNA transcript, Pol II product with hairpin) into ~60-70 nt pre-miRNA hairpin. Works as the Microprocessor complex with DGCR8/Pasha (Q8WYQ5), which recognizes the ssRNA-dsRNA junction at the hairpin base. Cuts ~11 bp from the basal junction and ~22 bp from the apical loop. DiGeorge syndrome (22q11 deletion) loses one DGCR8 copy.", "Alberts 7th ed Ch 7; Lee Y et al. Nature 425:415-419, 2003") }

    if name == "EXPORTIN5" { return rnai("Exportin-5", "miRNA", "Q9HAV4", "XPO5", "nuclear_export", "Ran-GTP-dependent nuclear export receptor that transports pre-miRNA hairpins from nucleus to cytoplasm. Recognizes the 2-nt 3' overhang left by Drosha cleavage and the double-stranded stem. Also exports some tRNAs.", "Lodish 9th ed Ch 10; Yi R et al. Genes Dev 17:3011-3016, 2003") }

    if name == "DICER" { return rnai("Dicer (RNase III)", "miRNA_and_siRNA", "Q9UPY3", "DICER1", "cytoplasmic_processing", "Class III RNase with PAZ domain (binds 3' overhang) and two RNase III domains that form an intramolecular dimer. Measures ~22 nt from the 3' overhang and cleaves the pre-miRNA loop to produce a ~22 nt miRNA duplex with 2-nt 3' overhangs on each strand. Also processes long dsRNA into siRNAs. Dicer partners with TRBP (P29558) which assists in loading the duplex into RISC.", "Alberts 7th ed Ch 7; Lodish 9th ed Ch 10; Bernstein E et al. Nature 409:363-366, 2001") }

    if name == "AGO2" { return rnai("Argonaute-2 (AGO2)", "miRNA_and_siRNA", "Q9UKV8", "AGO2", "effector_RISC", "The catalytic core of RISC (RNA-induced silencing complex). PAZ domain binds the 3' end of the guide strand. MID domain binds the 5' phosphate. PIWI domain has RNase H-like (Slicer) activity that cleaves target mRNA between positions 10-11 of the guide. AGO2 is the only human Argonaute with Slicer activity (AGO1/3/4 repress without cleavage). Guide strand selection: the strand with the less stable 5' end (lower thermodynamic stability) is retained as the guide; the passenger strand (miRNA*) is discarded.", "The heart of RNAi. miRNAs typically bind with imperfect complementarity to 3' UTR of target mRNAs (seed region: nt 2-8 of the guide), causing translational repression and mRNA destabilization via GW182/TNRC6 recruitment of CCR4-NOT deadenylase. siRNAs bind with perfect complementarity and trigger endonucleolytic cleavage (slicing). One miRNA can regulate hundreds of targets; one mRNA can be regulated by multiple miRNAs.", "Alberts 7th ed Ch 7; Lodish 9th ed Ch 10; Liu J et al. Science 305:1437-1441, 2004") }

    // siRNA
    if name == "siRNA" { return rnai("Small interfering RNA (siRNA)", "siRNA", "", "", "exogenous_silencing", "Exogenous dsRNA (viral, transgene, or synthetic) processed by Dicer into 21-23 nt duplexes with 2-nt 3' overhangs. Loaded into RISC. Perfect complementarity to target causes AGO2-mediated cleavage. Used therapeutically: patisiran (first FDA-approved siRNA drug, 2018) treats hereditary transthyretin amyloidosis by silencing TTR mRNA in hepatocytes. Delivered via lipid nanoparticles.", "Alberts 7th ed Ch 7; Fire A et al. Nature 391:806-811, 1998 (Nobel 2006); Adams D et al. N Engl J Med 379:11-21, 2018") }

    // piRNA
    if name == "piRNA" { return rnai("PIWI-interacting RNA (piRNA)", "piRNA", "Q96J94", "PIWIL1 (HIWI)", "transposon_silencing", "24-31 nt small RNAs (longer than miRNAs). Dicer-independent: processed from single-stranded precursors transcribed from piRNA clusters (often in heterochromatic regions rich in transposon fragments). Bind PIWI-clade Argonautes (PIWIL1-4 in humans). Silence transposons in germline cells by: (a) post-transcriptional slicing of transposon mRNA in cytoplasm (ping-pong amplification cycle), (b) transcriptional silencing by directing DNA methylation at transposon loci. Essential for fertility: PIWI mutants in Drosophila and mice are sterile due to transposon derepression.", "piRNAs are the guardians of germline genome integrity. Without them, transposons (which comprise ~45% of the human genome) would mobilize and cause insertional mutagenesis. The ping-pong cycle (sense piRNA cleaves antisense transcript, antisense piRNA cleaves sense transcript) amplifies the silencing response specifically against active transposons.", "Alberts 7th ed Ch 7; Lodish 9th ed Ch 10; Ozata DM et al. Nat Rev Genet 20:89-108, 2019") }

    return rnai("", "", "", "", "", "", "")
}

fn mirna_pathway_step(step: Int) -> String {
    // The canonical miRNA biogenesis pathway, step by step.
    if step == 1 { return "Transcription: RNA Pol II transcribes miRNA gene into pri-miRNA (primary transcript, can be several kb). Often from introns of host genes or from intergenic regions. Has 5' cap and poly(A) tail." }
    if step == 2 { return "Microprocessor cleavage: Drosha (RNase III) + DGCR8 recognize the pri-miRNA hairpin in the nucleus. Cut ~11 bp from the basal junction, releasing ~60-70 nt pre-miRNA hairpin with a 2-nt 3' overhang." }
    if step == 3 { return "Nuclear export: Exportin-5 recognizes the 2-nt 3' overhang and dsRNA stem of pre-miRNA. Ran-GTP-dependent transport through the nuclear pore to cytoplasm." }
    if step == 4 { return "Dicer processing: Dicer (with TRBP cofactor) cleaves the pre-miRNA loop, producing a ~22 nt miRNA duplex with 2-nt 3' overhangs on both ends." }
    if step == 5 { return "RISC loading: miRNA duplex loaded into AGO2. Guide strand selected (thermodynamic asymmetry rule: strand with less stable 5' end is retained). Passenger strand (star strand) ejected and degraded." }
    if step == 6 { return "Target recognition: Guide miRNA in RISC base-pairs with target mRNA 3' UTR. Seed region (nt 2-8) is critical for target recognition. Imperfect complementarity is typical for animal miRNAs." }
    if step == 7 { return "Silencing: GW182/TNRC6 bridges RISC to CCR4-NOT deadenylase complex. Target mRNA is deadenylated, decapped, and degraded. Translational repression also occurs (blocked at initiation step). Result: reduced protein output from target gene." }
    return ""
}

// ═══════════════════════════════════════════════════════
// SECTION H: TRANSLATIONAL CONTROL
// ═══════════════════════════════════════════════════════
//
// Regulation at the level of mRNA translation.
// Controls protein output without changing mRNA levels.
//
// Alberts 7th ed Ch 7; Lehninger 8th ed Ch 27; Lodish 9th ed Ch 10.

fn translational_control(name: String) -> TranslationalControl {
    if name == "mTOR_4EBP" { return transctrl("mTOR-4E-BP-eIF4E axis", "mTOR_signaling", "mTOR (mechanistic target of rapamycin)", "P42345", "mTORC1 phosphorylates 4E-BP1 (Q13541), releasing it from eIF4E (P06730). Free eIF4E binds the 5' m7G cap and recruits eIF4G scaffold, forming eIF4F complex. eIF4F recruits 43S preinitiation complex (40S + eIF2-GTP-Met-tRNAi) for cap-dependent translation initiation. When mTORC1 is inhibited (nutrient deprivation, rapamycin), 4E-BP1 is dephosphorylated, sequesters eIF4E, globally represses cap-dependent translation. Selectively spares IRES-dependent mRNAs.", "The master growth switch. mTORC1 integrates amino acids (Rag GTPases), growth factors (PI3K-Akt), energy (AMPK), and oxygen. Dysregulated in most cancers. Rapamycin (sirolimus, from Streptomyces hygroscopicus on Easter Island/Rapa Nui) is an immunosuppressant and anticancer drug that inhibits mTORC1 via FKBP12.", "Lodish 9th ed Ch 10; Lehninger 8th ed Ch 27; Ma XM, Bhatt DK. Nat Rev Mol Cell Biol 10:307-318, 2009") }

    if name == "IRE_IRP" { return transctrl("Iron response element / Iron regulatory protein", "iron_homeostasis", "IRP1 (aconitase/IRE-BP)", "P21399", "Iron response elements (IREs) are stem-loop structures in UTRs of iron-metabolism mRNAs. When iron is LOW, IRP1/IRP2 bind IREs: in the 5' UTR of ferritin mRNA, IRP binding blocks scanning 43S complex, repressing translation (less iron storage). In the 3' UTR of transferrin receptor (TfR1) mRNA, IRP binding stabilizes the mRNA (more iron import). When iron is HIGH, IRP1 assembles a [4Fe-4S] cluster and becomes cytoplasmic aconitase (loses RNA-binding), IRP2 is ubiquitinated by FBXL5 and degraded. Elegant reciprocal regulation: one signal, two opposite outcomes depending on IRE position.", "A textbook example of translational control. The same RNA-binding protein simultaneously increases iron uptake (stabilizing TfR1 mRNA) and decreases iron storage (blocking ferritin translation) when iron is scarce. Hereditary hyperferritinemia-cataract syndrome results from mutations in the ferritin L-chain IRE that prevent IRP binding.", "Alberts 7th ed Ch 7; Lehninger 8th ed Ch 27; Lodish 9th ed Ch 10; Hentze MW et al. Cell 117:285-297, 2004") }

    if name == "uORF" { return transctrl("Upstream open reading frames (uORFs)", "scanning_regulation", "eIF2alpha", "P05198", "uORFs are short ORFs in the 5' UTR, upstream of the main coding ORF. After translating a uORF, the ribosome may dissociate (repressing downstream ORF) or reinitiate (allowing downstream translation). Reinitiation requires re-acquisition of eIF2-GTP-Met-tRNAi ternary complex. When eIF2alpha is phosphorylated (stress: GCN2/HRI/PERK/PKR kinases), ternary complex is scarce. Ribosomes scan past inhibitory uORFs and reinitiate at the downstream main ORF. ATF4 mRNA has 2 uORFs: under stress, uORF2 is bypassed and ATF4 is translated (integrated stress response). GCN4 in yeast (4 uORFs) is the classic model.", "uORFs are present in ~50% of human mRNAs. They are a widespread but underappreciated layer of translational regulation. The integrated stress response (ISR) uses eIF2alpha phosphorylation to globally repress translation while selectively upregulating stress-response genes (ATF4, CHOP, GADD34) via their uORF architecture.", "Lehninger 8th ed Ch 27; Lodish 9th ed Ch 10; Hinnebusch AG. Annu Rev Microbiol 59:407-450, 2005") }

    if name == "IRES" { return transctrl("Internal ribosome entry site (IRES)", "cap_independent", "eIF4G (direct recruitment, no eIF4E needed)", "Q04637", "Structured RNA elements in 5' UTRs that recruit ribosomes directly without cap-dependent scanning. Discovered in picornavirus mRNAs (poliovirus, HCV) that cleave eIF4G to shut down host cap-dependent translation while their own IRES-driven translation continues. Cellular IRES elements exist in mRNAs for survival factors (XIAP, Bcl-2, c-Myc, VEGF, p53) that must be translated during stress/apoptosis when cap-dependent translation is shut down. Some IRES recruit 40S subunit directly; others use IRES trans-acting factors (ITAFs).", "IRES-mediated translation is controversial for cellular mRNAs: some reported cellular IRES elements may be artifacts of cryptic promoters in bicistronic reporter assays. However, HCV IRES (directly binds 40S, confirmed by cryo-EM) and cricket paralysis virus IRES (no initiation factors needed at all) are well-established. HCV IRES is a drug target (sofosbuvir era).", "Lodish 9th ed Ch 10; Alberts 7th ed Ch 7; Pelletier J, Sonenberg N. Nature 334:320-325, 1988") }

    return transctrl("", "", "", "", "", "", "")
}

// ═══════════════════════════════════════════════════════
// SECTION I: SIGNAL-DEPENDENT REGULATION
// ═══════════════════════════════════════════════════════
//
// Extracellular signals control gene expression through
// signaling cascades that activate transcription factors.
//
// Alberts 7th ed Ch 15; Lodish 9th ed Ch 16.

fn signal_dependent_regulation(pathway: String) -> SignalRegulation {
    if pathway == "NF_kB" { return sigreg("NF-kB pathway", "NF_kB", "NF-kB p65 (RelA)", "Q04206", "TNF-alpha, IL-1, LPS (TLR4), antigen receptors, DNA damage", "At rest, NF-kB (p65/p50 heterodimer) is sequestered in the cytoplasm by IkB-alpha (P25963). Signal activates IKK complex (IKK-alpha/beta/gamma). IKK-beta phosphorylates IkB-alpha on Ser32/36, triggering K48-ubiquitination by SCF-beta-TrCP and proteasomal degradation. Free NF-kB translocates to nucleus and activates target genes. IkB-alpha is itself a target gene, creating a negative feedback oscillation.", "TNF-alpha, IL-6, IL-8, COX2, iNOS, MHC-I, Bcl-xL, c-IAP, ICAM1, VCAM1, MMP9", "Master regulator of inflammation and innate immunity. Constitutive NF-kB activation drives chronic inflammation and cancer. All five NF-kB family members (RelA/p65, RelB, c-Rel, p50/NF-kB1, p52/NF-kB2) share the Rel homology domain. Canonical pathway (p65/p50) vs non-canonical (RelB/p52, activated by BAFF/CD40L via NIK).", "Alberts 7th ed Ch 15; Lodish 9th ed Ch 16; Hayden MS, Ghosh S. Cell 132:344-362, 2008") }

    if pathway == "JAK_STAT" { return sigreg("JAK-STAT pathway", "JAK_STAT", "STAT3", "P40763", "Interferons (IFN-alpha/beta/gamma), interleukins (IL-6, IL-10), growth hormone, erythropoietin, leptin", "Cytokine binds receptor, causing receptor dimerization. Receptor-associated JAK kinases (JAK1/2/3, TYK2) transphosphorylate each other, then phosphorylate receptor tyrosines. STATs dock on phospho-tyrosines via SH2 domain, are phosphorylated by JAKs on a single conserved tyrosine. Phospho-STATs dimerize (reciprocal SH2-pY interaction), translocate to nucleus, bind GAS (gamma-activated sequence, TTCNNNGAA) elements. Negative regulators: SOCS proteins (induced by STATs, feedback inhibition), protein tyrosine phosphatases, PIAS (SUMO E3 ligases).", "ISGs (interferon-stimulated genes), IRF1, c-Myc, Bcl-xL, SOCS1/3, cyclin D1", "The fastest signal-to-transcription pathway: no second messengers, no kinase cascade. Seven STATs in mammals (STAT1-4, 5a, 5b, 6). STAT3 is an oncogene (constitutively active in many cancers). STAT1 is a tumor suppressor (IFN-gamma signaling). JAK2 V617F mutation causes polycythemia vera (myeloproliferative neoplasm). Ruxolitinib (JAK1/2 inhibitor) treats myelofibrosis.", "Alberts 7th ed Ch 15; Lodish 9th ed Ch 16; Darnell JE Jr. Science 277:1630-1635, 1997") }

    if pathway == "nuclear_hormone" { return sigreg("Nuclear hormone receptor signaling", "nuclear_receptor", "Glucocorticoid receptor (GR)", "P04150", "Lipophilic hormones: cortisol, estradiol, testosterone, T3, retinoic acid, vitamin D, aldosterone", "Lipophilic ligands cross the plasma membrane directly. Type I receptors (GR, ER, AR, PR): reside in cytoplasm bound to Hsp90/Hsp70 chaperones. Ligand binding releases chaperones, exposes NLS, receptor dimerizes and translocates to nucleus. Binds palindromic HREs (hormone response elements) as homodimers. Type II receptors (TR, RAR, VDR, PPAR): already in nucleus bound to DNA as heterodimers with RXR. Without ligand, recruit NCoR/SMRT corepressor complexes (HDACs). Ligand binding triggers corepressor release and coactivator recruitment (SRC/p160 family, p300/CBP HATs).", "Gluconeogenic genes (PEPCK, G6Pase), anti-inflammatory genes (IkB-alpha, ANXA1), metabolic genes (FABP, CYP), differentiation genes", "Type I mechanism explains why steroids have systemic effects: the hormone reaches every cell, but the receptor's expression pattern and chromatin context determine which genes respond. Dexamethasone (synthetic glucocorticoid) activates GR. Tamoxifen (selective estrogen receptor modulator, SERM) is an ER antagonist in breast but agonist in bone.", "Alberts 7th ed Ch 15; Lodish 9th ed Ch 16; Mangelsdorf DJ et al. Cell 83:835-839, 1995") }

    if pathway == "p53" { return sigreg("p53 tumor suppressor pathway", "p53", "p53 (TP53)", "P04637", "DNA damage (DSBs: ATM kinase, UV/stalled forks: ATR kinase), oncogene activation (ARF), hypoxia, nucleotide depletion", "Normal state: MDM2 (Q00987) ubiquitinates p53, targeting it for proteasomal degradation. p53 half-life ~20 minutes. DNA damage activates ATM/ATR kinases, which phosphorylate p53 (Ser15) and MDM2, disrupting their interaction. p53 stabilizes, accumulates, and activates as a homotetramer. Binds p53 response elements (two copies of RRRCWWGYYY separated by 0-13 bp). Activates target genes for cell cycle arrest (p21/CDKN1A), DNA repair (GADD45), or apoptosis (BAX, PUMA, NOXA). Also induces MDM2 (negative feedback loop). Outcome depends on damage severity: mild = arrest + repair, severe = apoptosis.", "p21 (cell cycle arrest at G1/S), GADD45 (DNA repair), BAX (mitochondrial apoptosis), PUMA/BBC3 (BH3-only apoptosis), NOXA/PMAIP1 (BH3-only), MDM2 (feedback), TIGAR (metabolism), DRAM (autophagy)", "TP53 is the most frequently mutated gene in human cancer (~50% of all cancers). Called 'guardian of the genome' (Lane, 1992). Most mutations are missense in the DNA-binding domain (hotspots: R175H, G245S, R248W, R249S, R273H, R282W), producing dominant-negative or gain-of-function proteins. Li-Fraumeni syndrome: germline TP53 mutations, cancer predisposition.", "Alberts 7th ed Ch 17; Lodish 9th ed Ch 25; Vogelstein B et al. Nature 408:307-310, 2000") }

    return sigreg("", "", "", "", "", "", "", "", "")
}

// ═══════════════════════════════════════════════════════
// SECTION J: CRISPR GENE EDITING
// ═══════════════════════════════════════════════════════
//
// Doudna and Charpentier, Nobel Prize 2020.
// The tool that made programmable genome editing accessible.
//
// Doudna JA, Charpentier E. Science 346:1258096, 2014.
// Jinek M et al. Science 337:816-821, 2012.

fn crispr_component(name: String) -> CRISPRComponent {
    if name == "Cas9" { return crispr("Cas9 (CRISPR-associated protein 9)", "endonuclease", "Q99ZW2", "Streptococcus pyogenes", "RNA-guided DNA endonuclease. 1368 aa. Two nuclease domains: RuvC (cuts non-target strand) and HNH (cuts target strand complementary to guide RNA). Creates blunt-ended DSB 3 bp upstream of the PAM. Requires both crRNA (20 nt guide) and tracrRNA (scaffold), or a single guide RNA (sgRNA) fusion of both. R-loop formation: Cas9-sgRNA scans DNA for PAM, melts adjacent DNA, guide RNA hybridizes to target strand. Full R-loop triggers HNH conformational change and cleavage.", "The workhorse of CRISPR gene editing. SpCas9 recognizes NGG PAM. Catalytically dead dCas9 (D10A + H840A) fused to transcriptional activators (CRISPRa: VP64, p65, Rta) or repressors (CRISPRi: KRAB) enables programmable gene regulation without cutting. Cas9 nickase (D10A, only HNH active) used in paired-nickase strategies for higher specificity.", "Jinek M et al. Science 337:816-821, 2012; Doudna JA, Charpentier E. Science 346:1258096, 2014 (Nobel 2020)") }

    if name == "sgRNA" { return crispr("Single guide RNA (sgRNA)", "guide_rna", "", "Engineered", "Synthetic fusion of crRNA (spacer, 20 nt complementary to target) and tracrRNA (scaffold that binds Cas9). The 20 nt spacer determines target specificity. Seed region (8-12 nt PAM-proximal) is most critical for binding. Mismatches in seed region abolish cleavage; distal mismatches are more tolerated (off-target concern). Chemical modifications (2'-O-methyl, phosphorothioate) at the 5' and 3' ends improve stability and reduce off-targets in vivo.", "The programmable component. Change the 20 nt spacer sequence to target any genomic locus adjacent to a PAM. Design considerations: GC content 40-60%, avoid homopolymers, check for off-targets using Cas-OFFinder or CRISPOR. Truncated sgRNAs (17 nt spacer) can reduce off-targets.", "Jinek M et al. Science 337:816-821, 2012") }

    if name == "PAM" { return crispr("PAM (protospacer adjacent motif)", "recognition_element", "", "Target DNA", "Short DNA sequence (2-6 bp) adjacent to the target site that Cas9 must recognize BEFORE unwinding DNA. SpCas9 PAM: 5'-NGG-3' (on the non-target strand, immediately downstream of the protospacer). PAM recognition is the first step: Cas9 interrogates DNA at PAM sites, only melting adjacent sequence if PAM is present. PAM prevents Cas9 from cutting its own CRISPR array (the spacers in the array lack a PAM). Different Cas proteins recognize different PAMs: SaCas9 (NNGRRT), Cas12a/Cpf1 (TTTV), xCas9/SpCas9-NG (relaxed PAM).", "PAM requirement limits targetable sites. For SpCas9 (NGG), ~1 PAM per 8 bp in random sequence. PAM-less Cas variants (SpRY, near-PAMless) expand targeting but may increase off-targets. In bacterial immunity, PAM distinguishes self (CRISPR array, no PAM) from non-self (phage DNA, has PAM).", "Mojica FJ et al. J Mol Evol 60:174-182, 2005; Sternberg SH et al. Nature 507:62-67, 2014") }

    if name == "HDR" { return crispr("Homology-directed repair (HDR)", "repair_pathway", "", "Host cell", "Precise repair pathway that uses a homologous template (donor DNA) to repair the Cas9-induced DSB. Requires a donor template with homology arms flanking the desired edit. Can insert point mutations, tags, reporter genes, or entire cassettes. HDR is restricted to S/G2 phases (requires sister chromatid or exogenous template). Efficiency is low (typically 5-50%) because NHEJ competes. Strategies to enhance HDR: small molecule NHEJ inhibitors (SCR7, NU7441), cell cycle synchronization, Cas9-CtIP fusions, ssDNA oligonucleotide donors (ssODN).", "HDR is the precision editing pathway. Used for: gene correction (sickle cell: E6V reversion in HBB), reporter knock-in, conditional alleles (loxP insertion), epitope tagging of endogenous proteins. Base editors (BE) and prime editors (PE) achieve precise edits without DSBs.", "Doudna JA, Charpentier E. Science 346:1258096, 2014") }

    if name == "NHEJ" { return crispr("Non-homologous end joining (NHEJ)", "repair_pathway", "DNA-PKcs", "P78527", "Error-prone repair of Cas9-induced DSB. Ku70/Ku80 heterodimer binds broken ends, recruits DNA-PKcs. Ends are processed (nucleases, polymerases) and ligated by XRCC4-Ligase IV. Produces insertions and deletions (indels) at the cut site. Frameshift indels in coding sequence = gene knockout. NHEJ is active throughout the cell cycle (dominant pathway). Most CRISPR knockouts rely on NHEJ-mediated indels.", "NHEJ is the default repair pathway and the basis of CRISPR gene knockout. Indel spectrum is not random: microhomology-mediated end joining (MMEJ/alt-EJ) produces predictable deletions. inDelphi and other tools predict indel outcomes. For therapeutic gene knockout (e.g., BCL11A enhancer disruption for sickle cell/thalassemia), NHEJ is sufficient and preferred over HDR.", "Alberts 7th ed Ch 5; Lodish 9th ed Ch 6") }

    if name == "Cas12a" { return crispr("Cas12a (Cpf1)", "endonuclease", "U2UMQ6", "Lachnospiraceae bacterium", "Class 2 Type V CRISPR effector. Single RuvC nuclease domain (no HNH). Creates staggered cuts (5-nt 5' overhang) distal to the PAM. Uses only crRNA (no tracrRNA needed). Processes its own crRNA array (multiplexing). PAM: 5'-TTTV-3' (T-rich, complements SpCas9 G-rich PAM). Smaller than SpCas9 (~1300 aa vs 1368 aa). Collateral cleavage of ssDNA after target activation (basis of DETECTR diagnostic platform).", "Cas12a advantages: staggered cuts favor HDR, self-processing crRNA enables multiplexing from a single transcript, T-rich PAM expands AT-rich genome targeting. DETECTR (DNA Endonuclease Targeted CRISPR Trans Reporter): Cas12a + fluorescent ssDNA reporter for rapid molecular diagnostics (COVID-19 testing).", "Zetsche B et al. Cell 163:759-771, 2015; Chen JS et al. Science 360:436-439, 2018") }

    return crispr("", "", "", "", "", "", "")
}

fn crispr_application(application: String) -> String {
    if application == "gene_knockout" { return "Cas9 + sgRNA targeting coding exon -> DSB -> NHEJ indels -> frameshift -> premature stop codon -> NMD or truncated nonfunctional protein. Target early constitutive exons for complete knockout. Can generate biallelic knockouts in a single step." }
    if application == "gene_correction" { return "Cas9 + sgRNA near mutation + HDR donor template with corrected sequence. Corrects point mutations (sickle cell HBB E6V), small insertions/deletions. Limited by low HDR efficiency and restriction to dividing cells. Base editors (CBE, ABE) and prime editors offer DSB-free alternatives." }
    if application == "CRISPRa" { return "dCas9 (catalytically dead) fused to transcriptional activators (VP64-p65-Rta, SunTag-VP64, or SAM system). Targeted to promoter region. Upregulates endogenous gene expression without altering DNA sequence. Useful for gain-of-function screens, gene therapy (activate silenced allele), and studying gene dosage." }
    if application == "CRISPRi" { return "dCas9 fused to KRAB repressor domain. Targeted to promoter or TSS. Blocks transcription initiation or elongation. Recruits KAP1 and NuRD complex for local heterochromatin formation. Reversible gene silencing without DNA cleavage. Alternative to RNAi with fewer off-targets." }
    if application == "base_editing" { return "No DSB. Cas9 nickase fused to deaminase. CBE (cytosine base editor, Komor et al. 2016): C-to-T conversion via cytidine deaminase (APOBEC1). ABE (adenine base editor, Gaudelli et al. 2017): A-to-G conversion via evolved tRNA adenosine deaminase (TadA). Editing window: ~4-8 nt from PAM-distal end of protospacer. Corrects ~60% of known pathogenic point mutations (transition mutations)." }
    if application == "prime_editing" { return "No DSB, no donor DNA. Cas9 nickase (H840A) fused to engineered reverse transcriptase (M-MLV RT). pegRNA (prime editing guide RNA) contains spacer + PBS (primer binding site) + RT template encoding the edit. Cas9 nicks target strand, PBS hybridizes to the nicked end, RT copies the template into the genome. Can install all 12 types of point mutations, small insertions (up to ~44 bp), and small deletions. Anzalone AV et al. Nature 576:149-157, 2019." }
    return ""
}

// ═══════════════════════════════════════════════════════
// SECTION K: PIC ASSEMBLY ORDER
// ═══════════════════════════════════════════════════════

fn pic_assembly_step(step: Int) -> String {
    if step == 1 { return "TFIID binds: TBP subunit recognizes TATA box (or TAFs recognize Inr/DPE in TATA-less promoters). DNA bent ~80 degrees. Nucleates all subsequent assembly." }
    if step == 2 { return "TFIIA joins: Stabilizes TBP-DNA complex. Blocks antirepressors. Not always required but enhances stability." }
    if step == 3 { return "TFIIB joins: Bridges TBP and incoming Pol II. B-reader/B-linker set the transcription start site. Asymmetric binding defines direction of transcription." }
    if step == 4 { return "Pol II-TFIIF complex joins: TFIIF escorts Pol II to the promoter. Reduces nonspecific DNA binding. Closed complex formed (DNA still double-stranded)." }
    if step == 5 { return "TFIIE joins: Recruits TFIIH. Modulates its helicase and kinase activities. Required for promoter opening." }
    if step == 6 { return "TFIIH joins: XPB helicase melts ~11 bp around TSS (closed to open complex transition, ATP-dependent). CDK7 phosphorylates CTD Ser5. Promoter escape: Pol II clears the promoter, TFIID/TFIIA/TFIIB remain as scaffold for reinitiation." }
    if step == 7 { return "Mediator: Bridges gene-specific activators at enhancers to the PIC. Integrates activating and repressive signals. Stimulates TFIIH kinase activity. Required for regulated (activated) transcription in vivo." }
    return ""
}

// ═══════════════════════════════════════════════════════
// SECTION L: HELPER LOOKUPS AND CROSS-REFERENCES
// ═══════════════════════════════════════════════════════

fn is_activator(tf_name: String) -> Bool {
    if tf_name == "SP1" { return true }
    if tf_name == "JUN" { return true }
    if tf_name == "MYC" { return true }
    if tf_name == "PAX6" { return true }
    if tf_name == "ESR1" { return true }
    if tf_name == "CAP" { return true }
    return false
}

fn is_repressor(tf_name: String) -> Bool {
    if tf_name == "lacI" { return true }
    if tf_name == "trpR" { return true }
    if tf_name == "REST" { return true }
    if tf_name == "MDM2" { return true }
    return false
}

fn requires_ligand(tf_name: String) -> Bool {
    if tf_name == "ESR1" { return true }
    if tf_name == "GR" { return true }
    if tf_name == "lacI" { return true }
    if tf_name == "trpR" { return true }
    return false
}

fn regulation_level(level: String) -> String {
    if level == "chromatin" { return "Chromatin remodeling and histone modification. Controls DNA accessibility. SWI/SNF, ISWI, CHD, INO80. Operates before transcription can begin." }
    if level == "transcriptional" { return "Transcription factor binding, PIC assembly, promoter-enhancer looping, Mediator. The primary regulatory step for most genes. Determines whether mRNA is made." }
    if level == "post_transcriptional" { return "mRNA processing (capping, splicing, polyadenylation), alternative splicing, mRNA stability (AREs, NMD), mRNA localization. Determines which mRNA isoforms exist and how long they last." }
    if level == "translational" { return "Control of ribosome recruitment and scanning. mTOR-4EBP-eIF4E, IRE-IRP, uORFs, IRES. Determines how much protein is made from existing mRNA." }
    if level == "post_translational" { return "Protein modification (phosphorylation, ubiquitination, SUMOylation), protein stability (proteasomal degradation), protein localization. Determines protein activity and lifetime." }
    if level == "rna_interference" { return "miRNA, siRNA, piRNA pathways. Small RNA-guided silencing of target mRNAs via RISC. Tunes protein output, silences transposons, defends against viruses." }
    return ""
}

fn noble_laureate_gene_regulation(topic: String) -> String {
    if topic == "operon" { return "Jacob F, Monod J. Nobel Prize 1965 (Physiology or Medicine). The operon model of gene regulation. Shared with Lwoff A. J Mol Biol 3:318-356, 1961." }
    if topic == "rnai" { return "Fire A, Mello CC. Nobel Prize 2006 (Physiology or Medicine). RNA interference: gene silencing by double-stranded RNA. Nature 391:806-811, 1998." }
    if topic == "transcription" { return "Kornberg RD. Nobel Prize 2006 (Chemistry). Molecular basis of eukaryotic transcription. Studies of yeast RNA Pol II. Science 320:1286-1290, 2008." }
    if topic == "crispr" { return "Doudna JA, Charpentier E. Nobel Prize 2020 (Chemistry). Development of CRISPR-Cas9 as a genome editing tool. Science 346:1258096, 2014." }
    if topic == "hox" { return "Lewis EB, Nusslein-Volhard C, Wieschaus E. Nobel Prize 1995 (Physiology or Medicine). Genetic control of early embryonic development (homeotic genes). Lewis: bithorax complex." }
    if topic == "split_genes" { return "Sharp PA, Roberts RJ. Nobel Prize 1993 (Physiology or Medicine). Discovery of split genes (introns and RNA splicing). Independently discovered that eukaryotic genes contain non-coding interruptions." }
    return ""
}

// ═══════════════════════════════════════════════════════
// COUNT FUNCTIONS
// ═══════════════════════════════════════════════════════

fn lac_operon_component_count() -> Int {
    return 7
}

fn trp_operon_component_count() -> Int {
    return 7
}

fn general_tf_count() -> Int {
    return 6
}

fn promoter_element_count() -> Int {
    return 4
}

fn regulatory_element_count() -> Int {
    return 4
}

fn tf_structural_motif_count() -> Int {
    return 6
}

fn chromatin_remodeler_count() -> Int {
    return 4
}

fn mrna_processing_event_count() -> Int {
    return 3
}

fn alternative_splicing_type_count() -> Int {
    return 4
}

fn mrna_stability_element_count() -> Int {
    return 2
}

fn rnai_component_count() -> Int {
    return 6
}

fn mirna_pathway_step_count() -> Int {
    return 7
}

fn translational_control_count() -> Int {
    return 4
}

fn signal_dependent_pathway_count() -> Int {
    return 4
}

fn crispr_component_count() -> Int {
    return 6
}

fn crispr_application_count() -> Int {
    return 6
}

fn pic_assembly_step_count() -> Int {
    return 7
}

fn regulation_level_count() -> Int {
    return 6
}

fn noble_prize_gene_regulation_count() -> Int {
    return 6
}
