# RERUN_NOTES -- TP53 C-terminal mCherry knock-in

Engineering/biology notes for the next agent. Audience: a re-run, not the PDF reader.

## 1. What this project did
Designed an endogenous **C-terminal mCherry knock-in at human TP53** (NM_000546.6, GRCh38)
for HEK293T, SpCas9 + HDR. Deliverables: **1 primary + 1 backup guide** at the stop codon
(cross-validated Cas-OFFinder + CRISPOR), a **2,353 bp HDR donor** (800/800 bp arms, (GGGGS)x3
linker, human codon-optimized BsaI/BsmBI-free mCherry, built-in re-cut protection), and **3
genotyping primer pairs** (5' + 3' junction, internal/zygosity). Fusion: p53(1-393)-(GGGGS)x3-
mCherry, reusing the native TGA stop + 3'UTR.

## 2. Key biology decisions (the why)
- **Insert before the native stop, reuse it.** The 3'UTR is intronless and contiguous with the
  stop (verified: genomic 3'UTR = mRNA 3'UTR = 1188 nt), so arms come straight from genomic
  sequence and native post-transcriptional regulation is preserved. Insertion point = first base
  of the native stop (chr17:7,669,609, minus strand).
- **C-terminal, not N-terminal:** N-term would block the MDM2-binding site (~17-29) and
  artificially stabilize p53. C-term abuts the regulatory CTD (363-393) -> flag + validate.
- **Primary guide g3** (GGAGAATGTCAGTCTGAGTC, AGG, - strand): cut -6 bp from insertion, 50% GC,
  5' G, highest MIT/CFD of any stop-codon guide, and its protospacer STRADDLES the insertion ->
  insert splits the target -> **no PAM-block needed** (proven in 05).
- **Backup g2** (+ strand, opposite strand for failure-mode diversity); target lies wholly in
  the 5' arm -> silent PAM-block (codon389 GGG->GGT, Gly) built into the donor.
- **Off-target = the client's pain point** (prior pseudogene miss). Used TWO genome-wide tools;
  both report 0 hits <=1 mm and 0 in any TP53 pseudogene / p53-family gene. GC-rich g5-g7
  rejected (622-908 off-targets).

## 3. Where the knobs live (code-knob map)
- Target accession / locus window: `01_fetch_locus.py:30-33` (CHROM, WIN_START/END 0-based, ACC).
  Stop codon found by exact-match anchor (build-independent) -- no hard-coded coordinate.
- Guide search distance from insertion: `02_design_guides.py:31` (MAX_CUT_DIST=35); scan window L240.
- Off-target PAM/mismatch passes: `03_offtarget_casoffinder.py:83` (NGG<=4 + NAG<=3); RefGene
  annotation table cached at `03...py:19` (~/genomes/hg38_refGene.txt.gz).
- CRISPOR (2nd tool) is a MANUAL Playwright step (web). Result frozen in
  `crispor_summary.json` (batchId aRbLJgEIKxU6WaeejUMP). To redo: submit the 300 bp window from
  `crispor_submit_window.txt` at crispor.gi.ucsc.edu, genome hg38, 20bp-NGG; pull download=guides/offtargets TSV.
- mCherry source + codon-opt: `04_codon_optimize_mcherry.py:35` (GenBank AY678264), `:77`
  (CodonOptimize species h_sapiens), `:71-72` (forbid BsaI/BsmBI). Linker hardcoded `:96-98`.
- Donor arm length + flank + PAM-block: `05_design_donor.py:33-34` (ARM=800, FLANK=500), `:99`
  (apply_pam_block; PAM-disrupt-first, seed-mismatch fallback).
- Primer3 params + region constraints: `06_design_primers.py:31` (Tm) and `:52-56` (the 3
  SEQUENCE_PRIMER_PAIR_OK_REGION_LIST quadruples that force F/R into the right zones).

## 4. What was tried and didn't work
- `MAX_CUT_DIST=25` first (02): only 4 guides, 2 near-duplicate. Widened to 35 to expose the
  full neighborhood; the extra g5-g7 are GC-rich/promiscuous and were rejected, not used.
- DNAChisel `use_best_codon` on the linker made a perfect 45-bp tandem repeat (synthesis/
  recombination risk) -> replaced with a hand codon-diversified (GGGGS)x3 (`04...py:96`).
- FlashFry added as a THIRD independent (local) off-target tool (`10_offtarget_flashfry.py`).
  One-time index build (~30-60 min, cached in ~/genomes for reuse across tasks):
    `~/genomes/twoBitToFa ~/genomes/hg38.2bit ~/genomes/hg38.fa`
    `java -Xmx10g -jar ~/genomes/FlashFry.jar index --tmpLocation ~/genomes/flashfry_idx_tmp \`
      `--database ~/genomes/flashfry_hg38_cas9ngg --reference ~/genomes/hg38.fa --enzyme SPCAS9NGG`
  Then `discover` + `score` (hsu2013,doench2014ontarget,doench2016cfd,moreno2015,dangerous) on the
  300 bp window. FlashFry reports CFD/Hsu specificity + Doench on-target -- same community metrics
  as CRISPOR/Cas-OFFinder, so it cross-validates them on a third independent algorithm.

## 5. Gotchas
- TP53 is **minus strand**: script 01 works in gene-sense (revcomp of the plus-strand 2bit slice);
  watch the gene-sense-index <-> chr17 coordinate mapping (`gs_to_chr1`, off-by-one on the +1).
- Cas-OFFinder needs an OpenCL device; CPU mode (`C`) works here (~25 s/run, ~17 CPU-min wall).
- Cas-OFFinder pattern is 21 N + PAM suffix (e.g. N21GG); the query line is the 20-nt spacer +
  "NNN" + max_mm. The on-target 0-mm NGG self-hit must be excluded from off-target tallies (done).
- Internal/zygosity primers also amplify the DONOR plasmid (arms are on the donor) -> only the
  JUNCTION PCRs (one primer outside the arm) prove genuine integration. Stated in the report.
- twoBitToFa coordinates are 0-based half-open; locus window length asserted (`01...py:72`).
- **Bio.Restriction `.search()` on a LINEAR seq silently drops a recognition site whose cut falls
  past the sequence end** -- it missed the BsaI site in the last 8 bp of the donor (`05...py` now
  uses a both-strand regex `_find()` for recognition sites; donor has 2 BsaI + 1 BsmBI in the arms,
  insert 0/0). Always count recognition sites by sequence search, not cut-site enumeration, for
  "is this site present" questions.
- Variant screen (`11_variant_screen.py`) hits Ensembl Variation; fetch MAF via ONE bulk POST to
  `/variation/homo_sapiens` (69 variants in the 56 bp window -- per-variant GETs time out). The
  stop-codon/3'UTR region is densely catalogued with rare variants; none are common (MAF>=1%).

## 6. Re-running for common modifications
- **Different tag (e.g. EGFP/HaloTag):** swap the protein in `04` (fetch its CDS or paste aa),
  keep the codon-opt + BsaI/BsmBI constraints; everything downstream (donor, primers) regenerates.
- **N-terminal tag instead:** change the insertion point in 01 to the start codon and re-derive
  guides; note the MDM2-site caveat flips (N-term tag perturbs MDM2 binding).
- **Different cell line:** only the report caveat text (07/09 Section 7) changes; the design is
  HEK293T-independent (human reference). If the line is p53-mutant, re-check the locus is WT.
- **Tighter off-target:** raise NGG to <=3 mm and re-rank by CFD; re-pull CRISPOR.
