File size: 34,301 Bytes
e2409ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
const pptxgen = require("pptxgenjs");

const pres = new pptxgen();
pres.layout = "LAYOUT_16x9";
pres.author = "Qian";
pres.title = "GRN-Guided Perturbation Prediction";

// ── Design Tokens ──────────────────────────────────────────────────
const C = {
  primary:    "990011",   // cherry red
  primaryLt:  "B8001A",   // lighter red
  accent:     "2F3C7E",   // navy accent
  dark:       "1A1A2E",   // near-black for title slides
  white:      "FFFFFF",
  offWhite:   "FCF6F5",
  lightGray:  "F5F0EE",
  midGray:    "AAAAAA",
  darkText:   "2D2D2D",
  bodyText:   "3A3A3A",
  tableHead:  "990011",
  tableAlt:   "FDF2F2",
  green:      "2E7D32",
  red:        "C62828",
};
const FONT_H = "Georgia";
const FONT_B = "Calibri";

// ── Helper: section divider bar (top) ──────────────────────────────
function addTopBar(slide) {
  slide.addShape(pres.shapes.RECTANGLE, {
    x: 0, y: 0, w: 10, h: 0.06,
    fill: { color: C.primary },
  });
}

// ── Helper: slide number ───────────────────────────────────────────
function addSlideNum(slide, num) {
  slide.addText(String(num), {
    x: 9.2, y: 5.15, w: 0.6, h: 0.35,
    fontSize: 10, fontFace: FONT_B, color: C.midGray, align: "right",
  });
}

// ── Helper: content slide title ────────────────────────────────────
function addTitle(slide, title, num) {
  addTopBar(slide);
  slide.addText(title, {
    x: 0.6, y: 0.25, w: 8.8, h: 0.55,
    fontSize: 28, fontFace: FONT_H, color: C.primary, bold: true, margin: 0,
  });
  // thin separator
  slide.addShape(pres.shapes.LINE, {
    x: 0.6, y: 0.85, w: 8.8, h: 0,
    line: { color: C.primary, width: 1.2 },
  });
  addSlideNum(slide, num);
}

// ── Helper: bullet list ────────────────────────────────────────────
function bullets(items, opts = {}) {
  return items.map((t, i) => ({
    text: typeof t === "string" ? t : t.text,
    options: {
      bullet: { code: "2022" },
      breakLine: i < items.length - 1,
      fontSize: opts.fontSize || 14,
      fontFace: FONT_B,
      color: opts.color || C.bodyText,
      bold: (typeof t === "object" && t.bold) || false,
      indentLevel: (typeof t === "object" && t.indent) || 0,
      paraSpaceAfter: 6,
    },
  }));
}

// ── Helper: table with standard styling ────────────────────────────
function styledTable(headerRow, dataRows, opts = {}) {
  const hdrCells = headerRow.map((h) => ({
    text: h, options: {
      bold: true, color: C.white, fill: { color: C.tableHead },
      fontSize: 11, fontFace: FONT_B, align: "center", valign: "middle",
    },
  }));
  const bodyRows = dataRows.map((row, ri) =>
    row.map((cell) => {
      const isObj = typeof cell === "object" && cell !== null;
      return {
        text: isObj ? cell.text : String(cell),
        options: {
          fontSize: 11, fontFace: FONT_B, color: C.darkText,
          fill: { color: ri % 2 === 0 ? C.white : C.tableAlt },
          align: isObj && cell.align ? cell.align : "center",
          valign: "middle",
          bold: isObj && cell.bold ? true : false,
        },
      };
    })
  );
  return { rows: [hdrCells, ...bodyRows], opts };
}

// ====================================================================
// SLIDE 1 β€” Title
// ====================================================================
{
  const s = pres.addSlide();
  s.background = { color: C.dark };
  // accent bar left
  s.addShape(pres.shapes.RECTANGLE, {
    x: 0, y: 0, w: 0.12, h: 5.625, fill: { color: C.primary },
  });
  s.addText("GRN-Guided Perturbation Prediction", {
    x: 0.7, y: 1.2, w: 8.6, h: 1.2,
    fontSize: 36, fontFace: FONT_H, color: C.white, bold: true, margin: 0,
  });
  s.addText("From Cascaded Flow Matching to RegFM", {
    x: 0.7, y: 2.4, w: 8.6, h: 0.6,
    fontSize: 20, fontFace: FONT_B, color: C.primaryLt, margin: 0,
  });
  s.addShape(pres.shapes.LINE, {
    x: 0.7, y: 3.2, w: 3, h: 0,
    line: { color: C.primary, width: 2 },
  });
  s.addText("Weekly Research Progress Report  |  2026-03-29", {
    x: 0.7, y: 3.5, w: 8.6, h: 0.4,
    fontSize: 14, fontFace: FONT_B, color: "CCCCCC", margin: 0,
  });
}

// ====================================================================
// SLIDE 2 β€” Task Overview
// ====================================================================
{
  const s = pres.addSlide();
  s.background = { color: C.white };
  addTitle(s, "Task: Single-Cell Perturbation Prediction", 2);

  // Left column β€” description
  s.addText(bullets([
    "Input: control expression + perturbed gene(s)",
    "Output: post-perturbation expression",
    "No cell-level pairing (destructive assay)",
    "Eval: DE overlap, Pearson, MSE, etc.",
  ]), { x: 0.6, y: 1.15, w: 4.5, h: 2.2 });

  // Right column β€” dataset card
  s.addShape(pres.shapes.RECTANGLE, {
    x: 5.5, y: 1.15, w: 4.0, h: 2.3,
    fill: { color: C.lightGray },
  });
  s.addShape(pres.shapes.RECTANGLE, {
    x: 5.5, y: 1.15, w: 4.0, h: 0.4,
    fill: { color: C.primary },
  });
  s.addText("Norman Dataset", {
    x: 5.5, y: 1.15, w: 4.0, h: 0.4,
    fontSize: 13, fontFace: FONT_B, color: C.white, bold: true, align: "center", valign: "middle",
  });
  s.addText(bullets([
    "~9,000 cells x 5,000 HVG",
    "105 CRISPR perturbations (KO + OE)",
    "39 held-out test perturbations",
    "Fold-1 split (additive)",
  ], { fontSize: 12 }), { x: 5.7, y: 1.65, w: 3.6, h: 1.7 });

  // Formalization box
  s.addShape(pres.shapes.RECTANGLE, {
    x: 0.6, y: 3.7, w: 8.8, h: 1.4,
    fill: { color: C.offWhite },
  });
  s.addShape(pres.shapes.RECTANGLE, {
    x: 0.6, y: 3.7, w: 0.08, h: 1.4,
    fill: { color: C.primary },
  });
  s.addText([
    { text: "Formal Definition", options: { bold: true, fontSize: 14, fontFace: FONT_H, color: C.primary, breakLine: true, paraSpaceAfter: 4 } },
    { text: "Given:  x_ctrl in R^G  (control expression),  p in {gene_1, gene_2}  (perturbation)", options: { fontSize: 12, fontFace: FONT_B, color: C.bodyText, breakLine: true, paraSpaceAfter: 2 } },
    { text: "Predict:  x_pert in R^G  (post-perturbation expression)", options: { fontSize: 12, fontFace: FONT_B, color: C.bodyText } },
  ], { x: 0.9, y: 3.8, w: 8.3, h: 1.2 });
}

// ====================================================================
// SLIDE 3 β€” Baseline: scDFM
// ====================================================================
{
  const s = pres.addSlide();
  s.background = { color: C.white };
  addTitle(s, "Baseline: scDFM (Flow Matching)", 3);

  s.addText(bullets([
    "Learns velocity field v(x, t) via flow matching",
    "Transports control distribution to perturbed",
    "DiffPerceiverBlock backbone (d=128, 4 layers)",
    "ODE solver: RK4, 20 steps",
  ]), { x: 0.6, y: 1.15, w: 5.0, h: 2.0 });

  // Metrics callout cards
  const metrics = [
    { label: "Pearson Delta", value: "0.866" },
    { label: "MSE", value: "0.0032" },
    { label: "DE Direction", value: "93.7%" },
    { label: "Discrimination", value: "0.980" },
  ];
  metrics.forEach((m, i) => {
    const mx = 0.6 + i * 2.3;
    s.addShape(pres.shapes.RECTANGLE, {
      x: mx, y: 2.9, w: 2.1, h: 1.5,
      fill: { color: C.offWhite },
    });
    s.addShape(pres.shapes.RECTANGLE, {
      x: mx, y: 2.9, w: 2.1, h: 0.06,
      fill: { color: C.primary },
    });
    s.addText(m.value, {
      x: mx, y: 3.1, w: 2.1, h: 0.6,
      fontSize: 26, fontFace: FONT_H, color: C.primary, bold: true, align: "center", margin: 0,
    });
    s.addText(m.label, {
      x: mx, y: 3.7, w: 2.1, h: 0.4,
      fontSize: 12, fontFace: FONT_B, color: "777777", align: "center", margin: 0,
    });
  });

  // Limitation note
  s.addText([
    { text: "Limitation: ", options: { bold: true, fontSize: 13, color: C.red } },
    { text: "Genes treated as unstructured vector; no GRN modeling", options: { fontSize: 13, color: C.bodyText } },
  ], { x: 0.6, y: 4.7, w: 8.8, h: 0.3, fontFace: FONT_B });
}

// ====================================================================
// SLIDE 4 β€” GRN-CCFM: Cascaded Approach
// ====================================================================
{
  const s = pres.addSlide();
  s.background = { color: C.white };
  addTitle(s, "GRN-CCFM: Cascaded Approach", 4);

  // Core idea
  s.addText([
    { text: "Core Idea", options: { bold: true, fontSize: 16, fontFace: FONT_H, color: C.primary, breakLine: true, paraSpaceAfter: 6 } },
    { text: "Extract Attention-Delta from scGPT to capture GRN change, then use LatentForcing cascade to jointly generate GRN features and gene expression.", options: { fontSize: 13, fontFace: FONT_B, color: C.bodyText } },
  ], { x: 0.6, y: 1.15, w: 8.8, h: 1.0 });

  // Three pillars
  const pillars = [
    { title: "Attention-Delta", items: ["delta_attn = attn_tgt - attn_ctrl", "Captures regulatory change", "Sparse G x G matrix (~0.6%)"] },
    { title: "Cascaded Training", items: ["40% steps: latent flow only", "60% steps: expression flow only", "Two-stage ODE at inference"] },
    { title: "Architecture Fix", items: ["d_model: 128 -> 512", "Missing gene mask (7 sites)", "scGPT vocab alignment"] },
  ];
  pillars.forEach((p, i) => {
    const px = 0.6 + i * 3.1;
    s.addShape(pres.shapes.RECTANGLE, {
      x: px, y: 2.4, w: 2.8, h: 2.8,
      fill: { color: C.offWhite },
    });
    s.addShape(pres.shapes.RECTANGLE, {
      x: px, y: 2.4, w: 2.8, h: 0.45,
      fill: { color: C.primary },
    });
    s.addText(p.title, {
      x: px, y: 2.4, w: 2.8, h: 0.45,
      fontSize: 13, fontFace: FONT_B, color: C.white, bold: true, align: "center", valign: "middle",
    });
    s.addText(bullets(p.items, { fontSize: 11 }), {
      x: px + 0.15, y: 3.0, w: 2.5, h: 2.0,
    });
  });
}

// ====================================================================
// SLIDE 5 β€” Cascaded Variants Overview
// ====================================================================
{
  const s = pres.addSlide();
  s.background = { color: C.white };
  addTitle(s, "Cascaded Variants: Design Space", 5);

  const tbl = styledTable(
    ["Variant", "Latent Dim", "Agg. Method", "delta_topk", "Key Idea"],
    [
      ["grn_att_only", "128 (bilinear)", "Bilinear head", "30", "Attention only, no SVD"],
      ["grn_svd", "128", "SVD dictionary", "30", "Fixed SVD basis"],
      ["grn_svd_cross", "128", "SVD + cross-attn", "30", "Learnable SVD queries"],
      ["grn_dense4", "4", "Multi-stats", "30", "Low-dim dense features"],
      ["grn_scalar", "1", "signed_L2 + norm", "100", "Scalar latent per gene"],
      ["dim1_ablation", "1", "Slice scGPT[0]", "30", "Ablation: 512d -> 1d"],
    ]
  );
  s.addTable(tbl.rows, {
    x: 0.5, y: 1.15, w: 9.0,
    border: { pt: 0.5, color: "DDDDDD" },
    colW: [1.5, 1.3, 1.5, 1.0, 3.7],
    rowH: [0.38, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35],
    autoPage: false,
  });

  // Shared config note
  s.addShape(pres.shapes.RECTANGLE, {
    x: 0.5, y: 3.85, w: 9.0, h: 1.3,
    fill: { color: C.offWhite },
  });
  s.addShape(pres.shapes.RECTANGLE, {
    x: 0.5, y: 3.85, w: 0.08, h: 1.3,
    fill: { color: C.accent },
  });
  s.addText([
    { text: "Shared Config", options: { bold: true, fontSize: 13, fontFace: FONT_H, color: C.accent, breakLine: true, paraSpaceAfter: 4 } },
  ], { x: 0.8, y: 3.95, w: 8.5, h: 0.3 });
  s.addText(bullets([
    "d_model=128, nlayers=4, nhead=8, lr=5e-5, EMA=0.9999",
    "Cascaded: choose_latent_p=0.4, latent_weight=1.0",
    "Inference: RK4 ODE, 20 steps each stage",
  ], { fontSize: 11 }), { x: 0.8, y: 4.25, w: 8.5, h: 0.8 });
}

// ====================================================================
// SLIDE 6 β€” Cascaded Results
// ====================================================================
{
  const s = pres.addSlide();
  s.background = { color: C.white };
  addTitle(s, "Cascaded Results: Evaluation Metrics", 6);

  const tbl = styledTable(
    ["Model", "Pearson Delta", "MSE", "DE Direction", "Discrim."],
    [
      [{ text: "scDFM Baseline", bold: true }, { text: "0.866", bold: true }, { text: "0.0032", bold: true }, { text: "0.937", bold: true }, { text: "0.980", bold: true }],
      [{ text: "dim1_ablation", bold: true }, { text: "0.752", bold: true }, "0.0059", "0.878", "0.914"],
      ["grn_dense4", "0.122", "0.020", "0.780", "0.521"],
      ["grn_scalar (dtk100)", "0.087", "0.021", "0.793", "0.534"],
      ["grn_scalar (bs48)", "0.068", "0.026", "0.771", "0.533"],
      ["grn_att_only", "-0.097", "0.602", "0.747", "0.552"],
      ["grn_svd / svd_cross", "-0.096", "0.575", "0.746", "0.492"],
    ]
  );
  s.addTable(tbl.rows, {
    x: 0.5, y: 1.15, w: 9.0,
    border: { pt: 0.5, color: "DDDDDD" },
    colW: [2.2, 1.7, 1.3, 1.6, 1.4],
    rowH: [0.4, 0.36, 0.36, 0.36, 0.36, 0.36, 0.36, 0.36],
    autoPage: false,
  });

  // Insight box
  s.addShape(pres.shapes.RECTANGLE, {
    x: 0.5, y: 4.2, w: 9.0, h: 1.05,
    fill: { color: "FFF5F5" },
  });
  s.addShape(pres.shapes.RECTANGLE, {
    x: 0.5, y: 4.2, w: 0.08, h: 1.05,
    fill: { color: C.red },
  });
  s.addText(bullets([
    { text: "Only dim1 (d=1) approaches baseline; all high-dim cascaded variants fail", bold: true },
    "High-dim latent generation is the fundamental bottleneck",
    "grn_att_only / grn_svd: negative Pearson, MSE > 0.5",
  ], { fontSize: 12 }), { x: 0.8, y: 4.25, w: 8.5, h: 0.95 });
}

// ====================================================================
// SLIDE 7 β€” Failure Analysis
// ====================================================================
{
  const s = pres.addSlide();
  s.background = { color: C.white };
  addTitle(s, "Failure Analysis: Why Cascaded Fails", 7);

  // Left: problem
  s.addShape(pres.shapes.RECTANGLE, {
    x: 0.5, y: 1.15, w: 4.3, h: 3.5,
    fill: { color: "FFF5F5" },
  });
  s.addShape(pres.shapes.RECTANGLE, {
    x: 0.5, y: 1.15, w: 4.3, h: 0.45,
    fill: { color: C.red },
  });
  s.addText("Root Cause", {
    x: 0.5, y: 1.15, w: 4.3, h: 0.45,
    fontSize: 14, fontFace: FONT_B, color: C.white, bold: true, align: "center", valign: "middle",
  });
  s.addText(bullets([
    "Latent loss stuck at ~1.0-2.0",
    "Target: sparse G x G matrix (~0.6% non-zero)",
    "Generating GRN is itself a hard problem",
    "Decoupled training prevents joint optimization",
    "Expression flow never benefits from GRN",
  ], { fontSize: 12 }), { x: 0.7, y: 1.8, w: 3.9, h: 2.5 });

  // Right: evidence
  s.addShape(pres.shapes.RECTANGLE, {
    x: 5.2, y: 1.15, w: 4.3, h: 3.5,
    fill: { color: C.offWhite },
  });
  s.addShape(pres.shapes.RECTANGLE, {
    x: 5.2, y: 1.15, w: 4.3, h: 0.45,
    fill: { color: C.green },
  });
  s.addText("Evidence from dim1 Ablation", {
    x: 5.2, y: 1.15, w: 4.3, h: 0.45,
    fontSize: 14, fontFace: FONT_B, color: C.white, bold: true, align: "center", valign: "middle",
  });
  s.addText(bullets([
    "scgpt_dim: 512 -> 1",
    "Latent loss converges normally",
    "Pearson delta: 0.752 (vs baseline 0.866)",
    "Confirms: high-dim target is the bottleneck",
    "But dim=1 loses most GRN information",
  ], { fontSize: 12 }), { x: 5.4, y: 1.8, w: 3.9, h: 2.5 });

  // Bottom conclusion
  s.addShape(pres.shapes.RECTANGLE, {
    x: 0.5, y: 4.85, w: 9.0, h: 0.5,
    fill: { color: C.dark },
  });
  s.addText("Conclusion: Cascaded generation of GRN features is a dead end. Need a new paradigm.", {
    x: 0.5, y: 4.85, w: 9.0, h: 0.5,
    fontSize: 13, fontFace: FONT_B, color: C.white, bold: true, align: "center", valign: "middle",
  });
}

// ====================================================================
// SLIDE 8 β€” Paradigm Shift
// ====================================================================
{
  const s = pres.addSlide();
  s.background = { color: C.dark };
  s.addShape(pres.shapes.RECTANGLE, {
    x: 0, y: 0, w: 0.12, h: 5.625, fill: { color: C.primary },
  });

  s.addText("Paradigm Shift", {
    x: 0.7, y: 0.8, w: 8.6, h: 0.6,
    fontSize: 32, fontFace: FONT_H, color: C.white, bold: true, margin: 0,
  });
  s.addText("From GRN Generation to Structural Supervision", {
    x: 0.7, y: 1.4, w: 8.6, h: 0.5,
    fontSize: 18, fontFace: FONT_B, color: C.primaryLt, margin: 0,
  });

  // Key insight box
  s.addShape(pres.shapes.RECTANGLE, {
    x: 0.7, y: 2.3, w: 8.6, h: 1.2,
    fill: { color: C.primary },
  });
  s.addText([
    { text: "Key Insight: ", options: { bold: true, fontSize: 15, color: C.white } },
    { text: "Delta-attention is ", options: { fontSize: 15, color: C.white } },
    { text: "privileged information", options: { bold: true, italic: true, fontSize: 15, color: C.white } },
    { text: " -- available at training (from source + target), absent at inference (only source).", options: { fontSize: 15, color: C.white } },
  ], { x: 1.0, y: 2.5, w: 8.0, h: 0.8, fontFace: FONT_B });

  // Old vs New
  s.addShape(pres.shapes.RECTANGLE, {
    x: 0.7, y: 3.8, w: 4.0, h: 1.2,
    fill: { color: "2A2A42" },
  });
  s.addText([
    { text: "OLD: Cascaded", options: { bold: true, fontSize: 14, color: C.red, breakLine: true, paraSpaceAfter: 4 } },
    { text: "Generate GRN features (latent flow)", options: { fontSize: 13, color: "E8E8E8", breakLine: true, paraSpaceAfter: 2 } },
    { text: "-> Use for expression (expr flow)", options: { fontSize: 13, color: "E8E8E8" } },
  ], { x: 0.9, y: 3.9, w: 3.6, h: 1.0, fontFace: FONT_B });

  s.addShape(pres.shapes.RECTANGLE, {
    x: 5.3, y: 3.8, w: 4.0, h: 1.2,
    fill: { color: "2A2A42" },
  });
  s.addText([
    { text: "NEW: RegFM", options: { bold: true, fontSize: 14, color: "66BB6A", breakLine: true, paraSpaceAfter: 4 } },
    { text: "Embed GRN as structural bias", options: { fontSize: 13, color: "E8E8E8", breakLine: true, paraSpaceAfter: 2 } },
    { text: "-> Soft-supervise with delta_attn at train", options: { fontSize: 13, color: "E8E8E8" } },
  ], { x: 5.5, y: 3.9, w: 3.6, h: 1.0, fontFace: FONT_B });

  addSlideNum(s, 8);
}

// ====================================================================
// SLIDE 9 β€” RegFM Architecture
// ====================================================================
{
  const s = pres.addSlide();
  s.background = { color: C.white };
  addTitle(s, "RegFM: Architecture", 9);

  // Equation box
  s.addShape(pres.shapes.RECTANGLE, {
    x: 0.6, y: 1.15, w: 8.8, h: 0.7,
    fill: { color: C.offWhite },
  });
  s.addText([
    { text: "v(x, t)  =  \u03B1 \u00B7 v", options: { fontFace: "Calibri", fontSize: 22, color: C.primary, bold: true } },
    { text: "reg", options: { fontFace: "Calibri", fontSize: 15, color: C.primary, bold: true } },
    { text: "  +  (1 \u2013 \u03B1) \u00B7 v", options: { fontFace: "Calibri", fontSize: 22, color: C.primary, bold: true } },
    { text: "int", options: { fontFace: "Calibri", fontSize: 15, color: C.primary, bold: true } },
  ], {
    x: 0.6, y: 1.15, w: 8.8, h: 0.7,
    align: "center", valign: "middle",
  });

  // Three component cards
  const comps = [
    {
      title: "v_reg (Regulatory)",
      color: C.primary,
      items: [
        "RegulatoryHead module",
        "Q, K, V from backbone h",
        "R = tanh(QK^T / sqrt(d_r))",
        "v_reg = Linear(R @ V)",
        "d_r = 32, params = 12K",
      ],
    },
    {
      title: "v_int (Intrinsic)",
      color: C.accent,
      items: [
        "Original ExprDecoder",
        "3-layer MLP",
        "Per-gene autonomous dynamics",
        "No inter-gene interaction",
        "Reused from scDFM baseline",
      ],
    },
    {
      title: "Gate (alpha)",
      color: C.green,
      items: [
        "VelocityGate module",
        "Input: h + pert_emb + t_emb",
        "MLP(384 -> 128 -> 1)",
        "Init: bias=-3, alpha~0.05",
        "Safe fallback to v_int",
      ],
    },
  ];
  comps.forEach((c, i) => {
    const cx = 0.5 + i * 3.15;
    s.addShape(pres.shapes.RECTANGLE, {
      x: cx, y: 2.15, w: 2.95, h: 3.0,
      fill: { color: C.offWhite },
    });
    s.addShape(pres.shapes.RECTANGLE, {
      x: cx, y: 2.15, w: 2.95, h: 0.42,
      fill: { color: c.color },
    });
    s.addText(c.title, {
      x: cx, y: 2.15, w: 2.95, h: 0.42,
      fontSize: 12, fontFace: FONT_B, color: C.white, bold: true, align: "center", valign: "middle",
    });
    s.addText(bullets(c.items, { fontSize: 10.5 }), {
      x: cx + 0.1, y: 2.7, w: 2.75, h: 2.3,
    });
  });
}

// ====================================================================
// SLIDE 10 β€” RegFM Training & Loss
// ====================================================================
{
  const s = pres.addSlide();
  s.background = { color: C.white };
  addTitle(s, "RegFM: Training & Loss Design", 10);

  // Loss equation
  s.addShape(pres.shapes.RECTANGLE, {
    x: 0.6, y: 1.15, w: 8.8, h: 0.6,
    fill: { color: C.offWhite },
  });
  s.addText([
    { text: "L  =  L", options: { fontFace: "Calibri", fontSize: 20, color: C.primary, bold: true } },
    { text: "vel", options: { fontFace: "Calibri", fontSize: 14, color: C.primary, bold: true } },
    { text: "  +  \u03BB \u00B7 L", options: { fontFace: "Calibri", fontSize: 20, color: C.primary, bold: true } },
    { text: "reg", options: { fontFace: "Calibri", fontSize: 14, color: C.primary, bold: true } },
    { text: "  +  \u03B3 \u00B7 L", options: { fontFace: "Calibri", fontSize: 20, color: C.primary, bold: true } },
    { text: "mmd", options: { fontFace: "Calibri", fontSize: 14, color: C.primary, bold: true } },
  ], {
    x: 0.6, y: 1.15, w: 8.8, h: 0.6,
    align: "center", valign: "middle",
  });

  // Loss details table
  const tbl = styledTable(
    ["Loss Term", "Target", "Weight", "Description"],
    [
      ["L_vel", "v_target = x1 - eps", "1.0", "Standard flow matching MSE"],
      ["L_reg", "delta_attention", "0.1", "R_theta aligned with GRN ground truth"],
      ["L_mmd", "Distribution matching", "0.5", "Sliced Wasserstein / MMD"],
    ]
  );
  s.addTable(tbl.rows, {
    x: 0.6, y: 2.0, w: 8.8,
    border: { pt: 0.5, color: "DDDDDD" },
    colW: [1.2, 2.5, 1.0, 4.1],
    rowH: [0.38, 0.35, 0.35, 0.35],
    autoPage: false,
  });

  // Training status
  s.addText([
    { text: "Training Status (RegFM + MMD)", options: { bold: true, fontSize: 14, fontFace: FONT_H, color: C.primary, breakLine: true, paraSpaceAfter: 6 } },
  ], { x: 0.6, y: 3.4, w: 4.5, h: 0.35 });

  const statusTbl = styledTable(
    ["Step", "L_vel", "L_reg", "L_mmd", "Total"],
    [
      ["5k", "0.169", "0.318", "0.025", "0.226"],
      ["20k", "0.126", "0.254", "0.017", "0.168"],
      ["32k", "0.112", "0.236", "0.016", "0.152"],
    ]
  );
  s.addTable(statusTbl.rows, {
    x: 0.6, y: 3.8, w: 5.5,
    border: { pt: 0.5, color: "DDDDDD" },
    colW: [0.8, 1.0, 1.0, 1.0, 1.0],
    rowH: [0.35, 0.3, 0.3, 0.3],
    autoPage: false,
  });

  // Key design notes
  s.addShape(pres.shapes.RECTANGLE, {
    x: 6.5, y: 3.4, w: 3.0, h: 1.8,
    fill: { color: C.offWhite },
  });
  s.addShape(pres.shapes.RECTANGLE, {
    x: 6.5, y: 3.4, w: 0.07, h: 1.8,
    fill: { color: C.accent },
  });
  s.addText([
    { text: "Design Notes", options: { bold: true, fontSize: 12, fontFace: FONT_H, color: C.accent, breakLine: true, paraSpaceAfter: 4 } },
  ], { x: 6.75, y: 3.5, w: 2.6, h: 0.3 });
  s.addText(bullets([
    "Gate init: alpha ~ 0.05",
    "Diagonal removed from R",
    "Tanh bounds R to [-1, 1]",
    "Backbone: d_model=128",
  ], { fontSize: 10.5 }), { x: 6.75, y: 3.85, w: 2.6, h: 1.2 });
}

// ====================================================================
// SLIDE 11 β€” Schrodinger Bridge: Approach
// ====================================================================
{
  const s = pres.addSlide();
  s.background = { color: C.white };
  addTitle(s, "Schrodinger Bridge: Approach", 11);

  // Motivation
  s.addText(bullets([
    "FM: noise -> target (unpaired, indirect)",
    "SB: source -> target (optimal transport coupling)",
    "Natural fit for perturbation prediction",
  ], { fontSize: 13 }), { x: 0.6, y: 1.15, w: 9.0, h: 1.2 });

  // Variants table
  const tbl = styledTable(
    ["Variant", "Transport", "Score Head", "Anchoring", "Key Feature"],
    [
      ["A1 (baseline)", "SB-ODE", "None", "None", "Basic SB formulation"],
      ["A5 (full SDE)", "SB-SDE", "Full ASB", "None", "Score + velocity joint"],
      ["A6 (DSM aniso)", "SB-SDE", "Anisotropic", "None", "Per-gene noise scale"],
      ["SA1 (src-ODE)", "SB-ODE", "None", "Source cell", "Anchor at x_ctrl"],
      ["SA6 (src-SDE)", "SB-SDE", "Anisotropic", "Source cell", "Anchor + aniso score"],
    ]
  );
  s.addTable(tbl.rows, {
    x: 0.4, y: 2.55, w: 9.2,
    border: { pt: 0.5, color: "DDDDDD" },
    colW: [1.7, 1.2, 1.4, 1.3, 3.6],
    rowH: [0.38, 0.32, 0.32, 0.32, 0.32, 0.32],
    autoPage: false,
  });

  // Source-anchored note
  s.addShape(pres.shapes.RECTANGLE, {
    x: 0.5, y: 4.35, w: 9.0, h: 0.75,
    fill: { color: C.offWhite },
  });
  s.addShape(pres.shapes.RECTANGLE, {
    x: 0.5, y: 4.35, w: 0.08, h: 0.75,
    fill: { color: C.accent },
  });
  s.addText([
    { text: "Source-Anchored: ", options: { bold: true, fontSize: 12, color: C.accent } },
    { text: "ODE starts from x_ctrl (not noise). Loss_v drops to ~0.0004 (vs ~0.3 for standard SB).", options: { fontSize: 12, color: C.bodyText } },
  ], { x: 0.8, y: 4.4, w: 8.5, h: 0.6, fontFace: FONT_B });
}

// ====================================================================
// SLIDE 12 β€” Schrodinger Bridge: Results
// ====================================================================
{
  const s = pres.addSlide();
  s.background = { color: C.white };
  addTitle(s, "Schrodinger Bridge: Results", 12);

  // Top table β€” use explicit large font cells
  const hdr12 = ["Model", "Pearson", "MSE", "DE Dir.", "Discrim."].map(h => ({
    text: h, options: { bold: true, color: C.white, fill: { color: C.tableHead }, fontSize: 13, fontFace: FONT_B, align: "center", valign: "middle" },
  }));
  const data12 = [
    [{ text: "scDFM Baseline", bold: true }, { text: "0.866", bold: true }, "0.0032", "0.937", "0.980"],
    [{ text: "SB A1 (baseline)", bold: true }, { text: "0.858", bold: true }, "0.0072", "0.902", "0.957"],
    ["SB A6 (aniso DSM)", "0.849", "0.0074", "0.901", "0.956"],
    ["SA1 / SA6", "Training...", "@ 195k", "-", "-"],
  ].map((row, ri) => row.map(cell => {
    const isObj = typeof cell === "object" && cell !== null;
    return { text: isObj ? cell.text : String(cell), options: { fontSize: 13, fontFace: FONT_B, color: C.darkText, fill: { color: ri % 2 === 0 ? C.white : C.tableAlt }, align: "center", valign: "middle", bold: isObj && cell.bold ? true : false } };
  }));
  s.addTable([hdr12, ...data12], {
    x: 0.5, y: 1.15, w: 9.0,
    border: { pt: 0.5, color: "DDDDDD" },
    colW: [2.4, 1.6, 1.4, 1.6, 1.6],
    rowH: [0.42, 0.4, 0.4, 0.4, 0.4],
    autoPage: false,
  });

  // Training loss comparison
  s.addText([
    { text: "Training Loss Comparison", options: { bold: true, fontSize: 14, fontFace: FONT_H, color: C.primary, breakLine: true, paraSpaceAfter: 6 } },
  ], { x: 0.6, y: 3.25, w: 8.8, h: 0.35 });

  const hdrL = ["Variant", "Loss_v", "Loss_s", "Notes"].map(h => ({
    text: h, options: { bold: true, color: C.white, fill: { color: C.tableHead }, fontSize: 12, fontFace: FONT_B, align: "center", valign: "middle" },
  }));
  const dataL = [
    ["A1 Baseline", "0.26 - 0.40", "N/A", "Stable"],
    ["A6 DSM Aniso", "0.30 - 0.37", "0.76 - 0.80", "Better score"],
    ["SA1 Src-ODE", "~0.0005", "N/A", "Very low (anchored)"],
    ["SA6 Src-SDE", "~0.001", "~0.057", "Anchored + aniso"],
  ].map((row, ri) => row.map(cell => ({
    text: cell, options: { fontSize: 12, fontFace: FONT_B, color: C.darkText, fill: { color: ri % 2 === 0 ? C.white : C.tableAlt }, align: "center", valign: "middle" },
  })));
  s.addTable([hdrL, ...dataL], {
    x: 0.5, y: 3.65, w: 9.0,
    border: { pt: 0.5, color: "DDDDDD" },
    colW: [2.2, 2.0, 1.8, 3.0],
    rowH: [0.38, 0.35, 0.35, 0.35, 0.35],
    autoPage: false,
  });
}

// ====================================================================
// SLIDE 13 β€” Comprehensive Comparison
// ====================================================================
{
  const s = pres.addSlide();
  s.background = { color: C.white };
  addTitle(s, "Comprehensive Comparison", 13);

  const tbl = styledTable(
    ["Method", "Approach", "Pearson", "MSE", "DE Dir.", "Discrim."],
    [
      [{ text: "scDFM Baseline", bold: true }, "Flow Matching", { text: "0.866", bold: true }, { text: "0.003", bold: true }, { text: "0.937", bold: true }, { text: "0.980", bold: true }],
      [{ text: "SB A1", bold: true }, "Schrodinger Bridge", "0.858", "0.007", "0.902", "0.957"],
      ["SB A6", "SB + Aniso DSM", "0.849", "0.007", "0.901", "0.956"],
      [{ text: "dim1 ablation", bold: true }, "Cascaded (d=1)", "0.752", "0.006", "0.878", "0.914"],
      ["grn_dense4", "Cascaded (d=4)", "0.122", "0.020", "0.780", "0.521"],
      ["grn_scalar", "Cascaded (d=1, L2)", "0.087", "0.021", "0.793", "0.534"],
      ["grn_att_only", "Cascaded (bilinear)", "-0.097", "0.602", "0.747", "0.552"],
      ["grn_svd_cross", "Cascaded (SVD)", "-0.096", "0.575", "0.746", "0.492"],
      ["RegFM (20k)", "Structural Bias", "0.040", "0.128", "0.748", "0.505"],
    ]
  );
  s.addTable(tbl.rows, {
    x: 0.3, y: 1.1, w: 9.4,
    border: { pt: 0.5, color: "DDDDDD" },
    colW: [1.6, 1.7, 1.1, 1.0, 1.0, 1.0],
    rowH: [0.38, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35],
    autoPage: false,
  });

  // Color legend
  s.addShape(pres.shapes.RECTANGLE, {
    x: 0.5, y: 4.85, w: 9.0, h: 0.5,
    fill: { color: C.offWhite },
  });
  s.addText([
    { text: "Top tier: ", options: { bold: true, fontSize: 11, color: C.green } },
    { text: "Baseline (0.866), SB A1 (0.858)    ", options: { fontSize: 11, color: C.bodyText } },
    { text: "Mid tier: ", options: { bold: true, fontSize: 11, color: C.accent } },
    { text: "dim1 (0.752)    ", options: { fontSize: 11, color: C.bodyText } },
    { text: "Failed: ", options: { bold: true, fontSize: 11, color: C.red } },
    { text: "All high-dim cascaded variants", options: { fontSize: 11, color: C.bodyText } },
  ], { x: 0.7, y: 4.85, w: 8.6, h: 0.5, fontFace: FONT_B, valign: "middle" });
}

// ====================================================================
// SLIDE 14 β€” Key Takeaways
// ====================================================================
{
  const s = pres.addSlide();
  s.background = { color: C.white };
  addTitle(s, "Key Takeaways", 14);

  const takeaways = [
    { num: "1", title: "Cascaded GRN Generation Fails", desc: "High-dim latent target (G x G sparse) is fundamentally too hard to generate via flow matching." },
    { num: "2", title: "SB Competitive with FM Baseline", desc: "Schrodinger Bridge (A1: 0.858) nearly matches scDFM (0.866); source-anchored variants training." },
    { num: "3", title: "RegFM: New Paradigm", desc: "Treat delta_attn as privileged info; embed GRN as structural bias, not generation target." },
    { num: "4", title: "dim1 Confirms the Diagnosis", desc: "Only 1d latent converges; validates that task difficulty scales with latent dimensionality." },
  ];

  takeaways.forEach((t, i) => {
    const ty = 1.15 + i * 1.05;
    // Number circle
    s.addShape(pres.shapes.OVAL, {
      x: 0.6, y: ty + 0.05, w: 0.45, h: 0.45,
      fill: { color: C.primary },
    });
    s.addText(t.num, {
      x: 0.6, y: ty + 0.05, w: 0.45, h: 0.45,
      fontSize: 16, fontFace: FONT_H, color: C.white, bold: true, align: "center", valign: "middle",
    });
    // Title + description
    s.addText(t.title, {
      x: 1.25, y: ty, w: 8.2, h: 0.3,
      fontSize: 15, fontFace: FONT_H, color: C.primary, bold: true, margin: 0,
    });
    s.addText(t.desc, {
      x: 1.25, y: ty + 0.32, w: 8.2, h: 0.55,
      fontSize: 12, fontFace: FONT_B, color: C.bodyText, margin: 0,
    });
  });
}

// ====================================================================
// SLIDE 15 β€” Next Steps
// ====================================================================
{
  const s = pres.addSlide();
  s.background = { color: C.dark };
  s.addShape(pres.shapes.RECTANGLE, {
    x: 0, y: 0, w: 0.12, h: 5.625, fill: { color: C.primary },
  });

  s.addText("Next Steps", {
    x: 0.7, y: 0.6, w: 8.6, h: 0.6,
    fontSize: 32, fontFace: FONT_H, color: C.white, bold: true, margin: 0,
  });

  const steps = [
    { title: "RegFM Full Training", desc: "Continue to 100k+ steps; evaluate and compare with baseline at convergence" },
    { title: "SB Source-Anchored Eval", desc: "Evaluate SA1 / SA6 at 200k; compare ODE vs SDE transport" },
    { title: "RegFM vs SB vs Baseline", desc: "Head-to-head comparison on cell-eval + distributional metrics" },
    { title: "Distributional Evaluation", desc: "Apply new metrics (MMD, Energy Distance, C2ST, kNN) beyond conditional mean" },
    { title: "Interpretability Analysis", desc: "Visualize R_theta from RegFM; compare with known GRN structure" },
  ];

  steps.forEach((st, i) => {
    const sy = 1.5 + i * 0.78;
    s.addShape(pres.shapes.RECTANGLE, {
      x: 0.7, y: sy, w: 8.6, h: 0.65,
      fill: { color: "2A2A42" },
    });
    s.addShape(pres.shapes.RECTANGLE, {
      x: 0.7, y: sy, w: 0.07, h: 0.65,
      fill: { color: C.primary },
    });
    s.addText(st.title, {
      x: 1.0, y: sy + 0.03, w: 3.0, h: 0.3,
      fontSize: 14, fontFace: FONT_B, color: C.white, bold: true, margin: 0,
    });
    s.addText(st.desc, {
      x: 1.0, y: sy + 0.32, w: 8.1, h: 0.28,
      fontSize: 12, fontFace: FONT_B, color: "CCCCCC", margin: 0,
    });
  });

  addSlideNum(s, 15);
}

// ── Write file ─────────────────────────────────────────────────────
pres.writeFile({ fileName: "/home/hp250092/ku50001222/qian/aivc/lfj/Report/week10/GRN_Progress_Report.pptx" })
  .then(() => console.log("PPTX saved successfully."))
  .catch((err) => console.error("Error:", err));