bryan7264 commited on
Commit
0a1c815
Β·
verified Β·
1 Parent(s): e96148f

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +593 -0
README.md ADDED
@@ -0,0 +1,593 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # PANDA β€” reproducibility recipe
2
+
3
+ **PANDA** (Pan-tissue Adversarial Normalized Domain-invariant Anchored MLP) is a
4
+ compact prototype-anchored MLP classifier for scRNA-seq cell identity across skin,
5
+ hematopoietic, and pancreatic tissues, trained under a composite loss (supervised-
6
+ contrastive + VICReg + sub-center angular prototype-InfoNCE + gradient-reversal
7
+ dataset/depth adversary + HSIC depth-decorrelation + prototype-repulsion). Two
8
+ input variants ship out of the box: **PANDA-PCA** (`PCA(50) -> trunk`) and
9
+ **PANDA-Marker** (`[PCA(50) || marker_expr] -> trunk`); Marker beats PCA on 33/35
10
+ fold-comparisons across the three systems.
11
+
12
+ This README is a complete recipe to reproduce every result in `PAPER.tex` from a
13
+ clean clone. All commands are copy-pasteable and use absolute paths.
14
+
15
+ Repository layout:
16
+
17
+ ```
18
+ panda/ model + losses + panda/markers.yaml
19
+ scripts/pan_skin/ skin pipeline: download -> corpus -> train -> CV -> zero-shot
20
+ scripts/pancreas/ pancreas pipeline (same shape)
21
+ scripts/hematopoiesis/ HSC pipeline (same shape)
22
+ scripts/common/ system-agnostic train / CV / zero-shot drivers
23
+ scripts/analysis/ downstream discovery + interpretability
24
+ scripts/figures/ paper + supplement figure builders
25
+ data/corpus/{sys}/ downloaded + harmonized data
26
+ data/raw/ per-dataset raw counts (not in git)
27
+ checkpoints/{sys}/{variant}/panda_final.pt
28
+ discovery/{sys}/{variant}/*.json,*.csv all quantitative artefacts
29
+ figures/ fig1_..fig6, PANDA_supplement.pdf, biology/*.pdf
30
+ ```
31
+
32
+ ---
33
+
34
+ ## 1. Requirements
35
+
36
+ - **Python**: 3.9+ (project is tested on 3.10).
37
+ - **CUDA**: PyTorch 2.6.0 wheels β€” CUDA 12.1/12.4 runtime works.
38
+ - **GPU**: 4x A100 40GB used for the paper; **1 GPU works** if you drop the
39
+ training batch size to `bs=64` (default is 256 for 4-GPU DataParallel).
40
+ - **Disk**: ~400 GB (raw GEO tars + harmonized corpora + checkpoints).
41
+ - **RAM**: ~64 GB (the pancreas HVG builder peaks near ~40 GB).
42
+
43
+ Pinned runtime dependencies (from `pyproject.toml` / `requirements.txt`):
44
+
45
+ ```
46
+ torch==2.6.0 transformers==5.6.2 peft==0.18.1
47
+ scanpy==1.11.5 anndata==0.11.4 scvi-tools==1.3.3
48
+ harmonypy==0.2.0 numpy>=1.24,<3.0 scipy>=1.10
49
+ scikit-learn>=1.2 pandas>=1.5 matplotlib>=3.7
50
+ seaborn>=0.12 umap-learn>=0.5 pyyaml>=6.0
51
+ tqdm>=4.65 einops>=0.6 gdown>=5.0
52
+ GEOparse>=2.0 leidenalg>=0.10 pynndescent>=0.5
53
+ scikit-misc>=0.5
54
+ ```
55
+
56
+ Optional extras: `bayes` (numpyro/jax for horseshoe), `gpu` (flash-attn 2.8.2),
57
+ `viz` (plotly), `dev` (pytest, ruff, mypy).
58
+
59
+ Install:
60
+
61
+ ```bash
62
+ git clone <this-repo> /home/bcheng/PRISM
63
+ cd /home/bcheng/PRISM
64
+ pip install -e .
65
+ # or, editable dev install:
66
+ pip install -e ".[dev]"
67
+ ```
68
+
69
+ ### 1.1 LD_LIBRARY_PATH prefix (required for every PyTorch invocation)
70
+
71
+ PyTorch 2.6 sparse ops load `libcusparseLt.so.0` which sits under the pip-installed
72
+ `nvidia-cusparselt-cu12` package, and `scanpy` needs a modern `libstdc++`. Both
73
+ paths must be exported **at the shell level, before Python starts**:
74
+
75
+ ```bash
76
+ export LD_LIBRARY_PATH="$(python -c "import site,os; print(os.path.join(site.getsitepackages()[0],'nvidia','cusparselt','lib'))"):$LD_LIBRARY_PATH"
77
+ ```
78
+
79
+ If you also have a conda env that ships a newer `libstdc++`, prepend it:
80
+
81
+ ```bash
82
+ # example β€” path is machine-specific; drop it if your system libstdc++ is >= 3.4.30
83
+ export LD_LIBRARY_PATH="/home/bcheng/.conda/pkgs/libstdcxx-15.2.0-h39759b7_7/lib:$LD_LIBRARY_PATH"
84
+ ```
85
+
86
+ Every `bash scripts/*/run_all.sh` driver applies the same export automatically.
87
+
88
+ ---
89
+
90
+ ## 2. Data acquisition
91
+
92
+ Every URL below is a public GEO/ArrayExpress FTP link. Raw data is **not**
93
+ committed β€” it must be re-downloaded before anything else runs. Corpus builders
94
+ expect files at `data/corpus/{system}/tier_{a,b,c,v2}/`.
95
+
96
+ ### Pan-skin (6 studies, 45,387 cells)
97
+
98
+ | Study | GEO | Role |
99
+ |---|---|---|
100
+ | Sulic 2023 (E14.5 dorsal) | GSE212673 | anchor + held-out zero-shot |
101
+ | Dingwall 2024 (En1-cKO) | GSE220977 | discovery target (paired with Aldrich GSE214695) |
102
+ | Belote 2021 (human melanocyte) | GSE151091 | melanocyte anchor + held-out zero-shot |
103
+ | Haensel/Annusver 2020 | GSE142471 | adult homeostasis + wound |
104
+ | Joost 2016 | GSE67602 | Smart-seq2 platform anchor |
105
+ | Sennett 2015 (bulk RNA) | GSE70288 | placode/dermal-condensate marker reference |
106
+ | Han MCA 2018 (neonatal skin) | GSE108097 | Microwell-seq low-depth anchor |
107
+ | Merkel 2022 | GSE201447 | touch dome / volar biology |
108
+ | Aldrich 2023 (paired with Dingwall) | GSE214695 | En1-cKO snRNA-seq |
109
+
110
+ ```bash
111
+ bash scripts/pan_skin/01_download_tier_a.sh # Aldrich, Ge/Gupta, Joost, Haensel
112
+ bash scripts/pan_skin/02_download_tier_b.sh # MCA, WIHN, Ge/Fuchs, Merkel
113
+ bash scripts/pan_skin/03_download_tier_c.sh # Sennett, Tie, Wiedemann (bulk + human)
114
+ # Dingwall / Sulic / Belote must be placed in data/raw/ manually β€” see repo notes
115
+ ```
116
+
117
+ ### Pan-hematopoietic (3 studies used in the paper, 192,833 cells)
118
+
119
+ | Study | GEO | Role |
120
+ |---|---|---|
121
+ | Weinreb LARRY 2020 | GSE140802 | corpus anchor |
122
+ | Baccin whole-BM 2020 | GSE122465 | corpus (stromal + hematopoietic) |
123
+ | Tabula Muris Senis BM 2020 | GSE132042 | corpus (paper-labeled) |
124
+ | Nestorowa 2016 | GSE81682 | held-out zero-shot (Smart-seq2) |
125
+ | Dahlin 2018 | GSE107727 | discovery target (Kit-W41 mutant) |
126
+ | Paul 2015 (auxiliary) | GSE72857 | myeloid branch reference |
127
+ | Tusi 2018 (auxiliary) | GSE89754 | erythroid trajectory |
128
+
129
+ ```bash
130
+ bash scripts/hematopoiesis/01_download.sh # Paul, Nestorowa, Tusi, Dahlin
131
+ bash scripts/hematopoiesis/02_download.sh # Baccin whole-BM, TMS bone marrow
132
+ ```
133
+
134
+ ### Pan-pancreatic (6 studies, 120,611 cells)
135
+
136
+ | Study | GEO | Role |
137
+ |---|---|---|
138
+ | Baron 2016 | GSE84133 | corpus mouse-train half + held-out mouse-test half |
139
+ | Bastidas-Ponce 2019 (E15.5) | GSE132188 | corpus (endocrine progenitor time course) |
140
+ | Byrnes 2018 | GSE101099 | corpus (paper-labeled subset) |
141
+ | Yu 2021 | GSE139627 | corpus (paper-labeled Ngn3 lineage) |
142
+ | Hrovatin MIA 2023 | GSE211796 | corpus (adult islet, paper-labeled) |
143
+ | Veres 2019 | GSE114412 | 57,297 corpus + 12,297 held-out slice |
144
+
145
+ ```bash
146
+ bash scripts/pancreas/01_download.sh # Baron, Muraro, Grun, Byrnes, Veres
147
+ bash scripts/pancreas/09_download.sh # Yu Ngn3 seq-EP, MIA 4-month adult islet
148
+ ```
149
+
150
+ Wall-clock: 2-6 h depending on bandwidth (GSE108097 MCA tar is ~9 GB, GSE140802
151
+ Weinreb is ~14 GB, GSE114412 Veres is ~4 GB).
152
+
153
+ ---
154
+
155
+ ## 3. Corpus build (per system)
156
+
157
+ Each system builds a `data/corpus/{system}/harmonized/corpus.h5ad` plus a shared
158
+ HVG list, per-HVG mean/std, and a fitted PCA basis. Corpus is 100% paper-labeled;
159
+ every cell carries a label from its source paper's supplementary table.
160
+
161
+ ### Pan-skin
162
+
163
+ ```bash
164
+ python scripts/pan_skin/06_build_per_dataset_h5ads.py
165
+ python scripts/pan_skin/07_build_shared_hvgs_and_pca.py
166
+ python scripts/pan_skin/08_assign_labels.py
167
+ python scripts/pan_skin/08b_curated_label_override.py
168
+ python scripts/pan_skin/10_build_corpus.py # canonical corpus.h5ad
169
+ python scripts/pan_skin/93_add_belote_anchor.py # +Belote melanocyte anchor
170
+ ```
171
+
172
+ Wall-clock ~10-20 min (HVG + PCA is the expensive step).
173
+
174
+ ### Pan-hematopoietic
175
+
176
+ ```bash
177
+ python scripts/hematopoiesis/02_build_per_dataset.py
178
+ python scripts/hematopoiesis/03_shared_hvgs_and_pca.py
179
+ python scripts/hematopoiesis/10_build_corpus.py # canonical corpus.h5ad
180
+ python scripts/hematopoiesis/11_filter_paper_only.py # enforce paper-labeled subset
181
+ python scripts/hematopoiesis/09_retrain_with_nestorowa_anchor.py # optional anchor
182
+ ```
183
+
184
+ Wall-clock ~15-30 min.
185
+
186
+ ### Pan-pancreatic
187
+
188
+ ```bash
189
+ python scripts/pancreas/02_build_per_dataset.py
190
+ python scripts/pancreas/03_shared_hvgs_and_pca.py
191
+ python scripts/pancreas/04_assign_labels.py
192
+ python scripts/pancreas/11_build_corpus.py # canonical corpus.h5ad
193
+ python scripts/pancreas/08_add_baron_split.py # 943-cell Baron test-half
194
+ ```
195
+
196
+ Wall-clock ~30-60 min (peak ~40 GB RAM on the union HVG step).
197
+
198
+ Also generate the held-out labeled slices used for zero-shot:
199
+
200
+ ```bash
201
+ python scripts/common/generate_missing_holdouts.py
202
+ ```
203
+
204
+ writes `data/corpus/hematopoiesis/held_out_labeled/nestorowa_GSE81682_test.h5ad`
205
+ and `data/corpus/pan_skin/held_out_labeled/sulic_GSE212673_test.h5ad`.
206
+
207
+ ---
208
+
209
+ ## 4. Training
210
+
211
+ The **canonical trainer** is system-agnostic. It reads
212
+ `data/corpus/{system}/harmonized/corpus.h5ad` and writes
213
+ `checkpoints/{system}/{variant}/panda_final.pt`.
214
+
215
+ ```bash
216
+ # 6 checkpoints total (3 systems x 2 variants). ~30-60 min each on 1x A100.
217
+ python -m scripts.common.train_panda pan_skin --variant pca --epochs 8
218
+ python -m scripts.common.train_panda pan_skin --variant marker --epochs 8
219
+ python -m scripts.common.train_panda hematopoiesis --variant pca --epochs 8
220
+ python -m scripts.common.train_panda hematopoiesis --variant marker --epochs 8
221
+ python -m scripts.common.train_panda pancreas --variant pca --epochs 8
222
+ python -m scripts.common.train_panda pancreas --variant marker --epochs 8
223
+ ```
224
+
225
+ Legacy per-system entry points also exist and are functionally equivalent for
226
+ skin/HSC/pancreas single-variant training:
227
+ `scripts/pan_skin/20_train_panda.py`, `scripts/hematopoiesis/05_train_panda.py`,
228
+ `scripts/pancreas/05_train_panda.py`. Prefer `scripts.common.train_panda`.
229
+
230
+ ---
231
+
232
+ ## 5. Held-out 5-fold cross-validation (Table 1)
233
+
234
+ The paper's Table 1 CV block reads
235
+ `discovery/{system}/{variant}/cv_5fold.json`. Two drivers exist:
236
+
237
+ - **`scripts/common/run_cv.py`** β€” canonical, 5 epochs per fold, matches
238
+ paper numbers (mean acc / F1 / AUROC + per-class report).
239
+ - `scripts/common/cv_holdout.py` β€” same architecture but supports GroupKFold
240
+ by dataset and a fuller 6-8 epoch curriculum; slower.
241
+
242
+ Both accept `--systems` and `--variants`:
243
+
244
+ ```bash
245
+ # canonical 5-fold CV for all 3 systems x 2 variants
246
+ python -m scripts.common.run_cv --folds 5 --epochs 5
247
+ ```
248
+
249
+ Per-system CV drivers also exist (`scripts/pan_skin/40_heldout_5fold_cv.py`,
250
+ `scripts/hematopoiesis/07_heldout_5fold_cv.py`,
251
+ `scripts/pancreas/07_heldout_5fold_cv.py`); they are single-variant, single-
252
+ system alternatives.
253
+
254
+ ### Multi-seed rigor (35 fold-comparisons)
255
+
256
+ The paper reports Marker beating PCA on 33/35 folds across seeded runs
257
+ (2 seeds for skin+pancreas, 3 for HSC). Re-run with different `random_state`s;
258
+ outputs write to `cv_5fold_seed{1,2}.json`:
259
+
260
+ ```bash
261
+ python -m scripts.common.run_cv --folds 5 --epochs 5 # seed 0
262
+ # The script's seed hook is the random_state passed to StratifiedKFold + model
263
+ # init; re-run with edits to `run_cv.py` main() (add `--seed N` arg) or wrap
264
+ # a small loop. See scripts/common/cv_holdout.py for the current seed plumbing.
265
+ ```
266
+
267
+ ---
268
+
269
+ ## 6. Held-out labeled zero-shot targets (Section 5)
270
+
271
+ One driver runs every zero-shot target for both variants:
272
+
273
+ ```bash
274
+ python -m scripts.common.run_all_zero_shot \
275
+ --systems pan_skin hematopoiesis pancreas \
276
+ --variants pca marker
277
+ ```
278
+
279
+ writes `discovery/{system}/{variant}/{target}_predictions.csv` and
280
+ `{target}_summary.json`. Individual per-target scripts exist for finer-grained
281
+ control:
282
+
283
+ | Target | Script | Populates |
284
+ |---|---|---|
285
+ | Baron test-half (pancreas, 943 cells) | `scripts/analysis/93_true_zero_shot_baron.py` | Table 1 Baron row + Sec 5.1 |
286
+ | Nestorowa Smart-seq2 (HSC, 66 LT-HSC gated) | `scripts/analysis/94_true_zero_shot_nestorowa.py` | Sec 5.3 |
287
+ | Sulic E14.5 dorsal skin (4,183 cells) | `scripts/common/run_all_zero_shot.py` (target `sulic`) | Sec 5.5 |
288
+ | Belote melanocyte (6,088 cells) | `scripts/common/run_all_zero_shot.py` (target `belote`) | Sec 5.4 |
289
+ | Veres held-out slice (12,297 pancreas) | `scripts/common/run_all_zero_shot.py` (target `veres`) | Sec 5.2 |
290
+ | Dingwall (25,344 skin, discovery) | `scripts/pan_skin/30_zero_shot_aldrich.py` | Sec 6 |
291
+ | Dahlin (61,122 HSC, discovery) | `scripts/common/run_all_zero_shot.py` (target `dahlin`) | Sec 7 |
292
+
293
+ Adult-beta canonical panel validation on Veres:
294
+
295
+ ```bash
296
+ python scripts/analysis/95_adult_beta_validation.py
297
+ # -> discovery/pancreas/marker/95_adult_beta_validation.json
298
+ ```
299
+
300
+ ---
301
+
302
+ ## 7. Discovery analyses
303
+
304
+ Grouped by paper section. All write to `discovery/{system}/{variant}/`.
305
+
306
+ ### 7.1 Section 5 (held-out labeled) marker deep-dives
307
+
308
+ ```bash
309
+ python scripts/analysis/90_dingwall_marker_deep_dive.py # skin -> 90_..._marker_deep_dive.csv
310
+ python scripts/analysis/91_veres_marker_deep_dive.py # pancreas
311
+ python scripts/analysis/92_dahlin_marker_deep_dive.py # HSC
312
+ ```
313
+
314
+ ### 7.2 Section 6 β€” Dingwall En1-cKO (skin)
315
+
316
+ ```bash
317
+ python scripts/analysis/44_en1_cko_contrast.py # class-level cKO vs WT contrast
318
+ python scripts/analysis/45_marker_refinement.py # per-class marker refinement
319
+ python scripts/analysis/49_melanocyte_deep_dive.py # melanocyte 2x expansion
320
+ python scripts/analysis/57_multiclass_pathway_analysis.py # Dingwall pathway table
321
+ python scripts/analysis/57_pathway_analysis.py # symmetric 25+ module scoring, all systems
322
+ python scripts/analysis/99_en1_dual_role_analysis.py # spatial repressor / local activator
323
+ python scripts/analysis/106_melanoblast_neural_crest.py # Sec 6.5 MITF-axis vs NC reversion
324
+ python scripts/analysis/107_dingwall_class_deg_count.py # Sec 6.7 HF-placode DEG rank
325
+
326
+ # EDEN validation β€” three complementary lines of evidence (Sec 6.4)
327
+ python scripts/analysis/98_eden_posthoc_detection.py # Line A (null)
328
+ python scripts/analysis/103_replicate_dingwall_seurat_pipeline.py # Line B (Derm10 4.32x)
329
+ python scripts/analysis/104_train_on_dingwall_derm_labels.py # Line C (Derm10 5.20x)
330
+
331
+ # Primary EDEN (Derm2) discovery β€” Sec 6.4.1
332
+ python scripts/analysis/100_primary_eden_discovery.py # sub-cluster fibro predictions
333
+ python scripts/analysis/101_primary_eden_derm_scoring.py # score vs Data S1C panels
334
+ python scripts/analysis/105_primary_eden_full_dermal.py # on full dermal denominator
335
+
336
+ # Auxiliary: variant-A Dingwall training used for scope comparison
337
+ python scripts/analysis/102_train_on_dingwall_variantA.py
338
+ ```
339
+
340
+ ### 7.3 Section 7 β€” Dahlin Kit-mutant (hematopoiesis)
341
+
342
+ ```bash
343
+ python scripts/analysis/66_dahlin_kit_mutant.py # class enrichment WT vs Kit-W41
344
+ python scripts/analysis/67_dahlin_within_class.py # within-class Wilcoxon DE
345
+ python scripts/analysis/73_novel_populations_dahlin.py # abstain-gated novel pops
346
+ python scripts/analysis/108_dahlin_lineage_metabolism.py # per-lineage OXPHOS/glycolysis
347
+ ```
348
+
349
+ ### 7.4 Section 7.4 β€” Veres held-out (pancreas)
350
+
351
+ ```bash
352
+ python scripts/analysis/62_time_course_analysis.py # class fractions across LARRY days (HSC time-course template)
353
+ python scripts/analysis/109_veres_mature_beta.py # Sec 5.2 adult MAFA/UCN3 quadrant
354
+ python scripts/analysis/110_veres_polyhormonal_alpha.py # Sec 5.2 polyhormonal alpha cluster
355
+ ```
356
+
357
+ ### 7.5 Section 8 β€” cross-system prototype geometry + interpretability
358
+
359
+ ```bash
360
+ python scripts/analysis/70_prototype_geometry.py # intra + cross-system cosine + eff-dim
361
+ python scripts/analysis/72_emergent_axes.py # within-class PCA of 128-d z
362
+ python scripts/analysis/80_prototype_gene_attribution.py # integrated gradients per prototype
363
+ python scripts/analysis/81_counterfactual_knockouts.py # per-gene KO delta on cosine
364
+ python scripts/analysis/82_gene_coattribution_modules.py # gene co-attribution modules
365
+ python scripts/analysis/83_prototype_training_trajectory.py # prototype drift across curriculum
366
+ python scripts/analysis/84_adversary_purification.py # test GRL adversary is at chance
367
+ python scripts/analysis/85_hessian_gene_interactions.py # second-order gene pair Hessian
368
+ python scripts/analysis/63_nestorowa_zero_shot.py # Nestorowa unlabeled discovery
369
+ ```
370
+
371
+ ---
372
+
373
+ ## 8. Figures + supplement
374
+
375
+ ### Main-text figures (`figures/fig{1,2,3,4}_*.pdf`)
376
+
377
+ ```bash
378
+ python scripts/figures/generate_paper_figures.py
379
+ # fig1_confusion_matrices.pdf 3-panel per-class F1 confusion matrices
380
+ # fig2_aldrich_volcano.pdf melanocyte cKO vs WT volcano
381
+ # fig3_dahlin_heatmap.pdf within-class module-score heatmap
382
+ # fig4_sharon_stage_stack.pdf Veres per-stage class fractions
383
+ ```
384
+
385
+ Figures 5/6 (En1-cKO + Kit-W41 recap) are built by the biology page pipeline
386
+ below β€” the standalone `regen_fig5_fig6.py` referenced in older notes is not in
387
+ the current tree; use the biology pipeline instead.
388
+
389
+ ### Supplement (`figures/PANDA_supplement.pdf`)
390
+
391
+ ```bash
392
+ python scripts/figures/build_pca_vs_marker_umaps.py # PCA vs Marker UMAPs per target
393
+ python scripts/figures/build_figure_supplement.py # combined supplement PDF
394
+ ```
395
+
396
+ ### Biology deep-dive supplement pages
397
+
398
+ Cache UMAPs once, then build per-topic pages, then merge into the supplement:
399
+
400
+ ```bash
401
+ python scripts/figures/biology_00_umap_cache.py
402
+ python scripts/figures/biology_01_dingwall_umap.py
403
+ python scripts/figures/biology_02_primary_eden.py
404
+ python scripts/figures/biology_03_melanoblast_mitf.py
405
+ python scripts/figures/biology_04_dahlin_metabolism.py
406
+ python scripts/figures/biology_05_dahlin_composition.py
407
+ python scripts/figures/biology_06_veres_beta_quadrant.py
408
+ python scripts/figures/biology_07_veres_polyhormonal.py
409
+ python scripts/figures/biology_08_prototype_geometry.py
410
+ python scripts/figures/biology_99_merge_supplement.py # appends into PANDA_supplement.pdf
411
+ ```
412
+
413
+ Wall-clock: 20-40 min end-to-end (UMAPs dominate).
414
+
415
+ ---
416
+
417
+ ## 9. PDF build
418
+
419
+ The paper is a self-contained LaTeX document referencing PDFs in `figures/`:
420
+
421
+ ```bash
422
+ cd /home/bcheng/PRISM
423
+ pdflatex -interaction=nonstopmode PAPER.tex # first pass (writes .aux)
424
+ pdflatex -interaction=nonstopmode PAPER.tex # second pass (resolves refs)
425
+ ```
426
+
427
+ `bibtex` is not required β€” the paper uses an embedded `thebibliography`.
428
+
429
+ ---
430
+
431
+ ## 10. End-to-end make target
432
+
433
+ The provided `Makefile` covers the canonical skin pipeline end-to-end:
434
+
435
+ ```bash
436
+ make install # pip install -e .
437
+ make run # bash scripts/pan_skin/run_all.sh β€” full skin pipeline
438
+ make test-heldout # scripts/pan_skin/40_heldout_5fold_cv.py
439
+ make clean # remove __pycache__ + *.pyc
440
+ ```
441
+
442
+ For a full three-system reproduction, chain the per-section commands above.
443
+ A minimal "everything" recipe:
444
+
445
+ ```bash
446
+ # 1) data
447
+ bash scripts/pan_skin/01_download_tier_a.sh
448
+ bash scripts/pan_skin/02_download_tier_b.sh
449
+ bash scripts/pan_skin/03_download_tier_c.sh
450
+ bash scripts/hematopoiesis/01_download.sh
451
+ bash scripts/hematopoiesis/02_download.sh
452
+ bash scripts/pancreas/01_download.sh
453
+ bash scripts/pancreas/09_download.sh
454
+
455
+ # 2) corpora
456
+ bash scripts/pan_skin/run_all.sh # includes build + train + skin CV
457
+ python scripts/hematopoiesis/02_build_per_dataset.py
458
+ python scripts/hematopoiesis/03_shared_hvgs_and_pca.py
459
+ python scripts/hematopoiesis/10_build_corpus.py
460
+ python scripts/hematopoiesis/11_filter_paper_only.py
461
+ python scripts/pancreas/02_build_per_dataset.py
462
+ python scripts/pancreas/03_shared_hvgs_and_pca.py
463
+ python scripts/pancreas/04_assign_labels.py
464
+ python scripts/pancreas/11_build_corpus.py
465
+ python scripts/pancreas/08_add_baron_split.py
466
+ python scripts/common/generate_missing_holdouts.py
467
+ python scripts/pan_skin/93_add_belote_anchor.py
468
+
469
+ # 3) all 6 training runs
470
+ for sys in pan_skin hematopoiesis pancreas; do
471
+ for v in pca marker; do
472
+ python -m scripts.common.train_panda $sys --variant $v --epochs 8
473
+ done
474
+ done
475
+
476
+ # 4) CV + zero-shot
477
+ python -m scripts.common.run_cv --folds 5 --epochs 5
478
+ python -m scripts.common.run_all_zero_shot
479
+
480
+ # 5) discovery
481
+ bash scripts/common/rerun_all_discovery.sh # drives scripts/analysis/* end-to-end
482
+ python scripts/analysis/95_adult_beta_validation.py
483
+
484
+ # 6) figures + PDF
485
+ python scripts/figures/generate_paper_figures.py
486
+ python scripts/figures/build_pca_vs_marker_umaps.py
487
+ python scripts/figures/build_figure_supplement.py
488
+ python scripts/figures/biology_00_umap_cache.py
489
+ for i in 01 02 03 04 05 06 07 08; do
490
+ python scripts/figures/biology_${i}_*.py
491
+ done
492
+ python scripts/figures/biology_99_merge_supplement.py
493
+ pdflatex -interaction=nonstopmode PAPER.tex && pdflatex -interaction=nonstopmode PAPER.tex
494
+ ```
495
+
496
+ ---
497
+
498
+ ## 11. Trouble-shooting
499
+
500
+ - **`libcusparseLt.so.0: cannot open shared object file`** β€” you forgot to
501
+ export `LD_LIBRARY_PATH` **before** Python started. The pip-installed
502
+ `nvidia-cusparselt-cu12` provides the library; PyTorch does not add its
503
+ path to the loader search. See section 1.1.
504
+ - **`GLIBCXX_3.4.30 not found`** β€” your system `libstdc++` is too old; prepend
505
+ a newer `libstdc++.so.6`'s directory to `LD_LIBRARY_PATH`.
506
+ - **Dingwall GSM -> genotype mapping** (frequent bug source): the correct map is
507
+ `WT = {GSM6833478, GSM6833479, GSM6833480, GSM6833481}`,
508
+ `cKO = {GSM6833482, GSM6833483}`.
509
+ GSM6833480/481 are `rttaControl` (Cre-negative WT), **not** cKO. Getting this
510
+ wrong flips every En1-cKO enrichment sign.
511
+ - **Pancreas HVG builder OOM** β€” `scripts/pancreas/03_shared_hvgs_and_pca.py`
512
+ peaks near 40 GB RAM on the 6-study union. Run on a node with >= 64 GB.
513
+ - **`data/raw` not in git** β€” it is git-ignored (14+ GB of GEO tars). Rerun
514
+ section 2 to repopulate.
515
+ - **`stratified split failure` on rare classes** β€” small-support classes
516
+ (< 2 members per fold) are merged into the parent `canonical_label`. If a
517
+ fold still errors, check that `corpus.h5ad`'s `canonical_label` column has
518
+ the expected vocabulary; the paper vocab is the union enumerated in
519
+ `PAPER.tex` Sec 3.
520
+ - **`n_conditions` mismatch** β€” `PANDAEncoder` reads it from
521
+ `len(datasets)` in the checkpoint; regenerate the checkpoint if you have
522
+ added/removed a dataset.
523
+ - **`ContrastiveSampler` in 1-condition data** β€” auto-disabled when there is
524
+ only one condition; no config change needed.
525
+ - **DataParallel batch-size** β€” default `bs=256` is calibrated for 4x A100
526
+ 40 GB. Drop to `bs=64` for a single GPU or you will OOM inside the
527
+ sub-center prototype attention.
528
+ - **`X_prism` not persisted** β€” after `20_train_panda.py` / `05_train_panda.py`
529
+ writes the checkpoint, the embedding is re-projected on demand in every
530
+ downstream analysis; if you want it cached, re-save the AnnData explicitly
531
+ via `adata.write_h5ad()`.
532
+
533
+ ---
534
+
535
+ ## 12. Artefact index (from PAPER.tex Section 11)
536
+
537
+ Every quantitative claim traces to one of:
538
+
539
+ - **Model checkpoints**: `checkpoints/{system}/{variant}/panda_final.pt`
540
+ - **Marker gene lists**: `panda/markers.yaml`
541
+ - **Corpus builders**: `scripts/{pan_skin,hematopoiesis,pancreas}/`
542
+ - **Unified trainer**: `scripts/common/train_panda.py`
543
+ - **Unified 5-fold CV**: `scripts/common/run_cv.py` (or `cv_holdout.py`)
544
+ - **Zero-shot driver**: `scripts/common/run_all_zero_shot.py`
545
+ - **External label supplements**:
546
+ `data/external_labels/{dingwall_supp,haensel,joost2016,mca,mia,byrnes,yu,baccin,melanocyte_anchor}/`
547
+ - **CV outputs**: `discovery/{system}/{variant}/cv_5fold{,_seed1,_seed2}.json`
548
+ - **Zero-shot summaries**:
549
+ - `discovery/pancreas/{pca,marker}/baron_summary.json`
550
+ - `discovery/pancreas/{pca,marker}/veres_summary.json`
551
+ - `discovery/hematopoiesis/{pca,marker}/nestorowa_summary.json`
552
+ - `discovery/pan_skin/{pca,marker}/sulic_summary.json`
553
+ - `discovery/pan_skin/{pca,marker}/belote_summary.json`
554
+ - **Adult-beta panel**: `discovery/pancreas/marker/95_adult_beta_validation.json`
555
+ - **Pathway modules**: `discovery/{system}/marker/57_pathway_class_by_module_{padj,delta}.tsv`
556
+ - **Dingwall EDEN validation**:
557
+ Line A `discovery/pan_skin/marker/98_eden_summary.json`;
558
+ Line B `data/processed/dingwall_replica/dingwall_replica.h5ad`,
559
+ `replica_cluster_20_qc.json`, `replica_marker_matches.csv`;
560
+ Line C `discovery/pan_skin/marker/104_dingwall_derm_summary.json` + prediction CSVs.
561
+ - **Primary EDEN (Derm2)**:
562
+ `discovery/pan_skin/marker/100_primary_eden_discovery.csv`,
563
+ `100_primary_eden_summary.json`,
564
+ `101_derm_identity_summary.json`,
565
+ `101_derm_subcluster_scores.csv`.
566
+ - **Dingwall other**:
567
+ `discovery/pan_skin/marker/57_pathway_analysis.csv`,
568
+ `90_dingwall_marker_deep_dive.csv`.
569
+ - **Dahlin Kit-mutant**:
570
+ `discovery/hematopoiesis/marker/92_dahlin_marker_deep_dive.csv`, `dahlin_summary.json`.
571
+ - **Veres deep-dive**: `discovery/pancreas/marker/91_veres_marker_deep_dive.csv`.
572
+
573
+ Central architecture: `panda/model.py`. Composite loss lives in the same file
574
+ (`supcon_loss`, `vicreg_loss`, `hsic_biased`, `subcenter_angular_infonce`,
575
+ `prototype_repulsion`) and is imported as `from panda import PANDAEncoder, ...`.
576
+
577
+ ## Data mirror
578
+
579
+ Full data (~195 GB corpus + raw + processed + external labels) is mirrored to Hugging Face at [bryan7264/PANDA](https://huggingface.co/bryan7264/PANDA). Fetch with:
580
+
581
+ ```bash
582
+ huggingface-cli download bryan7264/PANDA --local-dir . --include "data/corpus/pan_skin/**"
583
+ ```
584
+
585
+ Priority folders (fetch these first for the minimum-reproducible pipeline):
586
+ - `data/corpus/{pan_skin,hematopoiesis,pancreas}/harmonized/` β€” training corpora
587
+ - `data/external_labels/` β€” paper-supplement label files
588
+ - `checkpoints/{pan_skin,hematopoiesis,pancreas}/marker/` β€” trained weights
589
+
590
+ Bulk (only needed to reproduce corpus builds from scratch):
591
+ - `data/raw/` β€” GEO downloads (regenerable from `scripts/*/03_download*.sh`)
592
+ - `data/corpus/tier{1,2,3}/` β€” pretraining tier data
593
+ - `data/processed/` β€” intermediate build artefacts