junidude14 commited on
Commit
50b2616
·
verified ·
1 Parent(s): 03369f2

Archive 4 checkpoints (1-4)

Browse files
paper-releases/20260928/diffusion/data/annotator/aifi_scanvi_f01common_v1/metrics.json ADDED
@@ -0,0 +1,503 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "contract": {
3
+ "layer": "counts",
4
+ "labels_key": "aifi_l2_train",
5
+ "unlabeled_category": "Unknown",
6
+ "batch_key": "batch_key",
7
+ "query_train_epochs": 0
8
+ },
9
+ "in_sample_l2": {
10
+ "n": 20000,
11
+ "accuracy": 0.87645,
12
+ "macro_f1_present_classes": 0.8696383455603359,
13
+ "macro_f1_all_labels": 0.8696383455603359,
14
+ "n_classes_present_in_truth": 29,
15
+ "per_class": {
16
+ "ASDC": {
17
+ "precision": 0.9565217391304348,
18
+ "recall": 1.0,
19
+ "f1": 0.9777777777777777,
20
+ "support": 22
21
+ },
22
+ "CD14 monocyte": {
23
+ "precision": 0.9969135802469136,
24
+ "recall": 0.8532075471698113,
25
+ "f1": 0.9194794631964213,
26
+ "support": 2650
27
+ },
28
+ "CD16 monocyte": {
29
+ "precision": 0.951063829787234,
30
+ "recall": 0.9738562091503268,
31
+ "f1": 0.9623250807319699,
32
+ "support": 459
33
+ },
34
+ "CD56bright NK cell": {
35
+ "precision": 0.8673469387755102,
36
+ "recall": 0.9883720930232558,
37
+ "f1": 0.9239130434782609,
38
+ "support": 258
39
+ },
40
+ "CD56dim NK cell": {
41
+ "precision": 0.9910130718954249,
42
+ "recall": 0.8919117647058824,
43
+ "f1": 0.9388544891640866,
44
+ "support": 1360
45
+ },
46
+ "CD8aa": {
47
+ "precision": 0.6733167082294265,
48
+ "recall": 0.989010989010989,
49
+ "f1": 0.8011869436201781,
50
+ "support": 273
51
+ },
52
+ "DN T cell": {
53
+ "precision": 0.6111111111111112,
54
+ "recall": 0.9734513274336283,
55
+ "f1": 0.7508532423208191,
56
+ "support": 113
57
+ },
58
+ "Effector B cell": {
59
+ "precision": 0.760932944606414,
60
+ "recall": 0.9190140845070423,
61
+ "f1": 0.8325358851674641,
62
+ "support": 284
63
+ },
64
+ "Erythrocyte": {
65
+ "precision": 0.9102564102564102,
66
+ "recall": 0.9726027397260274,
67
+ "f1": 0.9403973509933775,
68
+ "support": 73
69
+ },
70
+ "ILC": {
71
+ "precision": 0.7307692307692307,
72
+ "recall": 1.0,
73
+ "f1": 0.8444444444444444,
74
+ "support": 38
75
+ },
76
+ "Intermediate monocyte": {
77
+ "precision": 0.4312393887945671,
78
+ "recall": 0.9694656488549618,
79
+ "f1": 0.5969447708578144,
80
+ "support": 262
81
+ },
82
+ "MAIT": {
83
+ "precision": 0.7555938037865749,
84
+ "recall": 0.9690949227373068,
85
+ "f1": 0.8491295938104448,
86
+ "support": 453
87
+ },
88
+ "Memory B cell": {
89
+ "precision": 0.9072164948453608,
90
+ "recall": 0.8349146110056926,
91
+ "f1": 0.8695652173913043,
92
+ "support": 527
93
+ },
94
+ "Memory CD4 T cell": {
95
+ "precision": 0.9453662484823958,
96
+ "recall": 0.7397086763774541,
97
+ "f1": 0.8299875643986498,
98
+ "support": 3158
99
+ },
100
+ "Memory CD8 T cell": {
101
+ "precision": 0.9319338422391857,
102
+ "recall": 0.8102876106194691,
103
+ "f1": 0.8668639053254438,
104
+ "support": 1808
105
+ },
106
+ "Naive B cell": {
107
+ "precision": 0.9506666666666667,
108
+ "recall": 0.7783842794759825,
109
+ "f1": 0.8559423769507803,
110
+ "support": 916
111
+ },
112
+ "Naive CD4 T cell": {
113
+ "precision": 0.917295188556567,
114
+ "recall": 0.9382814578345304,
115
+ "f1": 0.927669647553919,
116
+ "support": 3759
117
+ },
118
+ "Naive CD8 T cell": {
119
+ "precision": 0.9371165644171779,
120
+ "recall": 0.9721559268098647,
121
+ "f1": 0.9543147208121827,
122
+ "support": 1257
123
+ },
124
+ "Plasma cell": {
125
+ "precision": 1.0,
126
+ "recall": 0.989247311827957,
127
+ "f1": 0.9945945945945946,
128
+ "support": 93
129
+ },
130
+ "Platelet": {
131
+ "precision": 0.9926739926739927,
132
+ "recall": 1.0,
133
+ "f1": 0.9963235294117647,
134
+ "support": 271
135
+ },
136
+ "Progenitor cell": {
137
+ "precision": 0.9848484848484849,
138
+ "recall": 0.9848484848484849,
139
+ "f1": 0.9848484848484849,
140
+ "support": 66
141
+ },
142
+ "Proliferating NK cell": {
143
+ "precision": 0.5787037037037037,
144
+ "recall": 0.9398496240601504,
145
+ "f1": 0.7163323782234957,
146
+ "support": 133
147
+ },
148
+ "Proliferating T cell": {
149
+ "precision": 0.7704918032786885,
150
+ "recall": 0.9494949494949495,
151
+ "f1": 0.8506787330316742,
152
+ "support": 99
153
+ },
154
+ "Transitional B cell": {
155
+ "precision": 0.5714285714285714,
156
+ "recall": 0.9156626506024096,
157
+ "f1": 0.7037037037037037,
158
+ "support": 249
159
+ },
160
+ "Treg": {
161
+ "precision": 0.6443298969072165,
162
+ "recall": 0.9715025906735751,
163
+ "f1": 0.7747933884297521,
164
+ "support": 386
165
+ },
166
+ "cDC1": {
167
+ "precision": 1.0,
168
+ "recall": 1.0,
169
+ "f1": 1.0,
170
+ "support": 48
171
+ },
172
+ "cDC2": {
173
+ "precision": 0.8079710144927537,
174
+ "recall": 0.9695652173913043,
175
+ "f1": 0.8814229249011858,
176
+ "support": 230
177
+ },
178
+ "gdT": {
179
+ "precision": 0.5710594315245479,
180
+ "recall": 0.8308270676691729,
181
+ "f1": 0.6768759571209801,
182
+ "support": 532
183
+ },
184
+ "pDC": {
185
+ "precision": 1.0,
186
+ "recall": 0.9955156950672646,
187
+ "f1": 0.9977528089887641,
188
+ "support": 223
189
+ }
190
+ }
191
+ },
192
+ "held_out_donors": {
193
+ "n_cells": 39690,
194
+ "donors": [
195
+ "BR1007",
196
+ "BR1016",
197
+ "BR1033",
198
+ "BR1042",
199
+ "BR1059",
200
+ "BR2013",
201
+ "BR2024",
202
+ "BR2037",
203
+ "BR2053",
204
+ "UP1022",
205
+ "UP1025"
206
+ ],
207
+ "predict_seconds": 0.1,
208
+ "atlas_L1_vs_map_collapse_agreement": 1.0,
209
+ "l2": {
210
+ "n": 39690,
211
+ "accuracy": 0.8692869740488788,
212
+ "macro_f1_present_classes": 0.8500925599737216,
213
+ "macro_f1_all_labels": 0.8500925599737216,
214
+ "n_classes_present_in_truth": 29,
215
+ "per_class": {
216
+ "ASDC": {
217
+ "precision": 0.9482758620689655,
218
+ "recall": 0.9482758620689655,
219
+ "f1": 0.9482758620689655,
220
+ "support": 58
221
+ },
222
+ "CD14 monocyte": {
223
+ "precision": 0.9984364529819075,
224
+ "recall": 0.8068592057761733,
225
+ "f1": 0.8924827792752321,
226
+ "support": 5540
227
+ },
228
+ "CD16 monocyte": {
229
+ "precision": 0.9467570183930301,
230
+ "recall": 0.9839034205231388,
231
+ "f1": 0.9649728663048841,
232
+ "support": 994
233
+ },
234
+ "CD56bright NK cell": {
235
+ "precision": 0.800718132854578,
236
+ "recall": 0.975929978118162,
237
+ "f1": 0.8796844181459567,
238
+ "support": 457
239
+ },
240
+ "CD56dim NK cell": {
241
+ "precision": 0.9756852343059239,
242
+ "recall": 0.8567546583850931,
243
+ "f1": 0.9123604795369987,
244
+ "support": 2576
245
+ },
246
+ "CD8aa": {
247
+ "precision": 0.4610951008645533,
248
+ "recall": 0.9580838323353293,
249
+ "f1": 0.622568093385214,
250
+ "support": 167
251
+ },
252
+ "DN T cell": {
253
+ "precision": 0.6060606060606061,
254
+ "recall": 0.9486166007905138,
255
+ "f1": 0.7395993836671803,
256
+ "support": 253
257
+ },
258
+ "Effector B cell": {
259
+ "precision": 0.663093415007657,
260
+ "recall": 0.9232409381663113,
261
+ "f1": 0.7718360071301248,
262
+ "support": 469
263
+ },
264
+ "Erythrocyte": {
265
+ "precision": 0.9230769230769231,
266
+ "recall": 0.9795918367346939,
267
+ "f1": 0.9504950495049505,
268
+ "support": 343
269
+ },
270
+ "ILC": {
271
+ "precision": 0.8536585365853658,
272
+ "recall": 0.9459459459459459,
273
+ "f1": 0.8974358974358975,
274
+ "support": 111
275
+ },
276
+ "Intermediate monocyte": {
277
+ "precision": 0.3270758122743682,
278
+ "recall": 0.9476987447698745,
279
+ "f1": 0.4863123993558776,
280
+ "support": 478
281
+ },
282
+ "MAIT": {
283
+ "precision": 0.7421746293245469,
284
+ "recall": 0.9688172043010753,
285
+ "f1": 0.8404850746268657,
286
+ "support": 930
287
+ },
288
+ "Memory B cell": {
289
+ "precision": 0.892485549132948,
290
+ "recall": 0.7790110998990918,
291
+ "f1": 0.8318965517241379,
292
+ "support": 991
293
+ },
294
+ "Memory CD4 T cell": {
295
+ "precision": 0.9367541766109785,
296
+ "recall": 0.7681017612524462,
297
+ "f1": 0.8440860215053764,
298
+ "support": 6132
299
+ },
300
+ "Memory CD8 T cell": {
301
+ "precision": 0.9470023186485591,
302
+ "recall": 0.8019635343618513,
303
+ "f1": 0.8684690157958688,
304
+ "support": 3565
305
+ },
306
+ "Naive B cell": {
307
+ "precision": 0.9472789115646258,
308
+ "recall": 0.7262059973924381,
309
+ "f1": 0.822140221402214,
310
+ "support": 1534
311
+ },
312
+ "Naive CD4 T cell": {
313
+ "precision": 0.9268385621745205,
314
+ "recall": 0.9384002057613169,
315
+ "f1": 0.9325835516646431,
316
+ "support": 7776
317
+ },
318
+ "Naive CD8 T cell": {
319
+ "precision": 0.9565373563218391,
320
+ "recall": 0.9761730205278593,
321
+ "f1": 0.966255442670537,
322
+ "support": 2728
323
+ },
324
+ "Plasma cell": {
325
+ "precision": 1.0,
326
+ "recall": 1.0,
327
+ "f1": 1.0,
328
+ "support": 170
329
+ },
330
+ "Platelet": {
331
+ "precision": 0.9846547314578005,
332
+ "recall": 0.9897172236503856,
333
+ "f1": 0.9871794871794872,
334
+ "support": 389
335
+ },
336
+ "Progenitor cell": {
337
+ "precision": 1.0,
338
+ "recall": 0.9939759036144579,
339
+ "f1": 0.9969788519637462,
340
+ "support": 166
341
+ },
342
+ "Proliferating NK cell": {
343
+ "precision": 0.536036036036036,
344
+ "recall": 0.918918918918919,
345
+ "f1": 0.6770981507823614,
346
+ "support": 259
347
+ },
348
+ "Proliferating T cell": {
349
+ "precision": 0.6543624161073825,
350
+ "recall": 0.9154929577464789,
351
+ "f1": 0.7632093933463796,
352
+ "support": 213
353
+ },
354
+ "Transitional B cell": {
355
+ "precision": 0.5990566037735849,
356
+ "recall": 0.9304029304029304,
357
+ "f1": 0.7288378766140603,
358
+ "support": 546
359
+ },
360
+ "Treg": {
361
+ "precision": 0.6267409470752089,
362
+ "recall": 0.9401114206128134,
363
+ "f1": 0.7520891364902507,
364
+ "support": 718
365
+ },
366
+ "cDC1": {
367
+ "precision": 1.0,
368
+ "recall": 0.9850746268656716,
369
+ "f1": 0.9924812030075187,
370
+ "support": 67
371
+ },
372
+ "cDC2": {
373
+ "precision": 0.8149253731343283,
374
+ "recall": 0.9891304347826086,
375
+ "f1": 0.8936170212765957,
376
+ "support": 552
377
+ },
378
+ "gdT": {
379
+ "precision": 0.5901183020180932,
380
+ "recall": 0.8514056224899599,
381
+ "f1": 0.6970817920263049,
382
+ "support": 996
383
+ },
384
+ "pDC": {
385
+ "precision": 0.9941176470588236,
386
+ "recall": 0.990234375,
387
+ "f1": 0.9921722113502935,
388
+ "support": 512
389
+ }
390
+ }
391
+ },
392
+ "l1": {
393
+ "n": 39690,
394
+ "accuracy": 0.9918367346938776,
395
+ "macro_f1_present_classes": 0.9715232379009036,
396
+ "macro_f1_all_labels": 0.9715232379009036,
397
+ "n_classes_present_in_truth": 9,
398
+ "per_class": {
399
+ "B cell": {
400
+ "precision": 0.9994612068965517,
401
+ "recall": 1.0,
402
+ "f1": 0.9997305308542171,
403
+ "support": 3710
404
+ },
405
+ "DC": {
406
+ "precision": 0.9056748466257669,
407
+ "recall": 0.9932716568544996,
408
+ "f1": 0.9474528680304853,
409
+ "support": 1189
410
+ },
411
+ "Erythrocyte": {
412
+ "precision": 0.9230769230769231,
413
+ "recall": 0.9795918367346939,
414
+ "f1": 0.9504950495049505,
415
+ "support": 343
416
+ },
417
+ "ILC": {
418
+ "precision": 0.8536585365853658,
419
+ "recall": 0.9459459459459459,
420
+ "f1": 0.8974358974358975,
421
+ "support": 111
422
+ },
423
+ "Monocyte": {
424
+ "precision": 0.9991298042059463,
425
+ "recall": 0.9824586423274386,
426
+ "f1": 0.990724095779104,
427
+ "support": 7012
428
+ },
429
+ "NK cell": {
430
+ "precision": 0.9816120134845234,
431
+ "recall": 0.9729647630619684,
432
+ "f1": 0.9772692601067887,
433
+ "support": 3292
434
+ },
435
+ "Platelet": {
436
+ "precision": 0.9846547314578005,
437
+ "recall": 0.9897172236503856,
438
+ "f1": 0.9871794871794872,
439
+ "support": 389
440
+ },
441
+ "Progenitor cell": {
442
+ "precision": 1.0,
443
+ "recall": 0.9939759036144579,
444
+ "f1": 0.9969788519637462,
445
+ "support": 166
446
+ },
447
+ "T cell": {
448
+ "precision": 0.996549226771184,
449
+ "recall": 0.9963369963369964,
450
+ "f1": 0.9964431002534557,
451
+ "support": 23478
452
+ }
453
+ }
454
+ },
455
+ "pbmc5_plus_other": {
456
+ "n": 39690,
457
+ "accuracy": 0.9920886873267826,
458
+ "macro_f1_present_classes": 0.9812088972148597,
459
+ "macro_f1_all_labels": 0.9812088972148597,
460
+ "n_classes_present_in_truth": 6,
461
+ "per_class": {
462
+ "T cell": {
463
+ "precision": 0.996549226771184,
464
+ "recall": 0.9963369963369964,
465
+ "f1": 0.9964431002534557,
466
+ "support": 23478
467
+ },
468
+ "B cell": {
469
+ "precision": 0.9994612068965517,
470
+ "recall": 1.0,
471
+ "f1": 0.9997305308542171,
472
+ "support": 3710
473
+ },
474
+ "Monocyte": {
475
+ "precision": 0.9991298042059463,
476
+ "recall": 0.9824586423274386,
477
+ "f1": 0.990724095779104,
478
+ "support": 7012
479
+ },
480
+ "NK cell": {
481
+ "precision": 0.9816120134845234,
482
+ "recall": 0.9729647630619684,
483
+ "f1": 0.9772692601067887,
484
+ "support": 3292
485
+ },
486
+ "DC": {
487
+ "precision": 0.9056748466257669,
488
+ "recall": 0.9932716568544996,
489
+ "f1": 0.9474528680304853,
490
+ "support": 1189
491
+ },
492
+ "Other": {
493
+ "precision": 0.959731543624161,
494
+ "recall": 0.9920713577799801,
495
+ "f1": 0.9756335282651072,
496
+ "support": 1009
497
+ }
498
+ }
499
+ },
500
+ "mean_max_prob": 0.9731612739454262,
501
+ "frac_max_prob_ge_0.5": 0.9962711010330058
502
+ }
503
+ }
paper-releases/20260928/diffusion/data/annotator/aifi_scanvi_f01common_v1/predict_scanvi.py ADDED
@@ -0,0 +1,307 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ """Annotate query cells with a frozen AIFI scANVI model (zero query-training epochs).
3
+
4
+ Rebuilt 2026-09-16 to the surviving query-side contract of ``aifi_scanvi_new_blocks_v1``
5
+ (``aifi_recon_annotation_grid.py`` lines 103-128):
6
+
7
+ obs["aifi_l2_train"] = "Unknown" obs["batch_key"] = <one batch per sample>
8
+ layers["counts"] = integer counts on the model's gene space
9
+ SCANVI.prepare_query_anndata -> SCANVI.load_query_data -> predict(soft=True) (no training)
10
+
11
+ Input
12
+ -----
13
+ ``--query`` is either
14
+ * an ``.npz`` of generated cells (``generated_counts``, ``gene_ids``, ``bulk_index``,
15
+ ``sample_ids``) -> Poisson-integerised by ``poisson_readout.py`` (seeded), or
16
+ * an ``.h5ad`` (real cells) carrying integer counts in ``layers["counts"]`` or ``X``.
17
+
18
+ Gene space
19
+ ----------
20
+ The model's genes must all be present in the query. ``prepare_query_anndata`` would pad
21
+ missing genes with zeros; that fabricates measurements, so it is refused unless
22
+ ``--allow-missing-genes`` is passed (and then the count is recorded in the manifest).
23
+ Query genes outside the model panel are dropped (recorded).
24
+
25
+ Output (``--out-dir``)
26
+ ----------------------
27
+ ``labels.parquet`` -- same schema as the benchmark's representative centroid transfer
28
+ (``label_transfer_representative_centroid.py`` scheme ``pbmc5``), consumed by
29
+ ``evaluate_generated_vs_truth.py``::
30
+
31
+ sample_id, group, source, cell_index, celltype_l1_pred, label_confidence,
32
+ aifi_l1, aifi_l2, aifi_l2_confidence (+ aifi_l1_confidence, npz_row)
33
+
34
+ ``celltype_l1_pred`` is the AIFI L1 collapsed to PBMC5; L1 classes outside PBMC5
35
+ (Platelet, Erythrocyte, Progenitor cell, ILC) become ``--other-label`` (default
36
+ ``Other``) -- kept, never dropped. ``aifi_l1`` keeps the full L1 name.
37
+ ``label_confidence`` = summed L2 probability mass of the predicted L1;
38
+ ``aifi_l2_confidence`` = max L2 probability.
39
+ ``labels.manifest.json`` -- provenance for the evaluator (``target_truth_used_for_fitting``
40
+ = false, ``training_source`` = reference h5ad, ``labels`` = PBMC5 + Other so
41
+ ``--labels-from-manifest`` yields the 6-way scheme).
42
+ ``soft_probabilities_l2.parquet`` / ``probabilities_l1.parquet`` -- full soft outputs.
43
+ """
44
+
45
+ from __future__ import annotations
46
+
47
+ import argparse
48
+ import json
49
+ import os
50
+ import sys
51
+ import time
52
+ from datetime import datetime, timezone
53
+ from importlib.metadata import version as _pkg_version
54
+ from pathlib import Path
55
+
56
+ import numpy as np
57
+ import pandas as pd
58
+ import scipy.sparse as sp
59
+
60
+ PLAN_DIR = Path(__file__).resolve().parent
61
+ sys.path.insert(0, str(PLAN_DIR))
62
+ import scanvi_common as C # noqa: E402
63
+
64
+ UNSPEC = "__unspecified__"
65
+
66
+
67
+ def parse_args(argv=None) -> argparse.Namespace:
68
+ p = argparse.ArgumentParser(description="Frozen scANVI annotation of query cells.", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
69
+ p.add_argument("--model-dir", required=True, type=Path, help=".../scanvi_model directory (contains model.pt)")
70
+ p.add_argument("--query", required=True, type=Path, help=".npz (generated) or .h5ad (real) query cells")
71
+ p.add_argument("--out-dir", required=True, type=Path)
72
+ p.add_argument("--device", choices=["cpu", "cuda"], default="cpu")
73
+ p.add_argument("--seed", type=int, default=20260916, help="Poisson readout seed (npz input)")
74
+ p.add_argument("--npz-matrix-key", default="generated_counts")
75
+ p.add_argument("--library-scale", type=float, default=1.0, help="Poisson rate multiplier; 1.0 = no rescaling")
76
+ p.add_argument("--max-cells", type=int, default=None, help="SMOKE: seeded random subset of query cells (output is then NOT evaluator-aligned)")
77
+ p.add_argument("--subset-seed", type=int, default=0)
78
+ p.add_argument("--method-name", default=None, help="obs['source'] / manifest method (default: query stem)")
79
+ p.add_argument("--dataset-id", default="")
80
+ p.add_argument("--split", default="")
81
+ p.add_argument("--batch-prefix", default="", help="batch_key = prefix + sample_id (e.g. '004_A_GSE135779_SLE_PBMC_')")
82
+ p.add_argument("--sample-id-col", default=None, help="h5ad: obs column with sample ids (default: sample_id, sample_ids, donor_id)")
83
+ p.add_argument("--batch-key-col", default=None, help="h5ad: obs column to use as batch_key (default: prefix + sample id)")
84
+ p.add_argument("--other-label", default=C.OTHER_LABEL)
85
+ p.add_argument("--confidence-threshold", type=float, default=0.0, help="cells with max L2 prob below this get aifi_l2='__unspecified__' and celltype_l1_pred=other-label")
86
+ p.add_argument("--allow-missing-genes", action="store_true", help="permit zero-padding of model genes absent from the query (recorded)")
87
+ p.add_argument("--eval-batch-size", type=int, default=2048)
88
+ p.add_argument("--num-threads", type=int, default=8)
89
+ p.add_argument("--model-manifest", type=Path, default=None, help="MODEL_MANIFEST.json (default: <model-dir>/../MODEL_MANIFEST.json)")
90
+ return p.parse_args(argv)
91
+
92
+
93
+ def _load_h5ad_query(path: Path, *, sample_id_col: str | None, batch_key_col: str | None, batch_prefix: str, method: str):
94
+ import anndata as ad
95
+
96
+ adata = ad.read_h5ad(path)
97
+ if "counts" in adata.layers:
98
+ counts = adata.layers["counts"]
99
+ else:
100
+ counts = adata.X
101
+ counts = sp.csr_matrix(counts) if not sp.issparse(counts) else counts.tocsr()
102
+ if counts.nnz and not np.all(counts.data == np.round(counts.data)):
103
+ raise SystemExit(f"{path}: counts are not integer-valued; scANVI needs integer counts (Poisson-integerise generated cells first)")
104
+ counts = counts.astype(np.float32)
105
+ adata.layers["counts"] = counts
106
+ adata.X = counts.copy()
107
+ sid_col = sample_id_col or next((c for c in ("sample_id", "sample_ids", "donor_id") if c in adata.obs.columns), None)
108
+ if sid_col is None:
109
+ raise SystemExit(f"{path}: obs lacks a sample id column (pass --sample-id-col)")
110
+ adata.obs["sample_id"] = adata.obs[sid_col].astype(str).to_numpy()
111
+ if batch_key_col is not None:
112
+ adata.obs["batch_key"] = pd.Categorical(adata.obs[batch_key_col].astype(str))
113
+ else:
114
+ adata.obs["batch_key"] = pd.Categorical([f"{batch_prefix}{s}" for s in adata.obs["sample_id"]])
115
+ adata.obs["aifi_l2_train"] = pd.Categorical([C.UNLABELED_CATEGORY] * adata.n_obs)
116
+ adata.obs["npz_row"] = np.arange(adata.n_obs, dtype=np.int64)
117
+ adata.obs["cell_index"] = np.arange(adata.n_obs, dtype=np.int64)
118
+ if "source" not in adata.obs.columns:
119
+ adata.obs["source"] = method
120
+ query_input = {"kind": "h5ad", "path": str(path), "counts_from": "layers['counts']" if "counts" in adata.layers else "X", "n_input_cells": int(adata.n_obs)}
121
+ # Carry provenance written by build_benchmark_queries.py (Poisson readout seed, source, join rule).
122
+ for key in ("poisson_readout", "query_build"):
123
+ if key in adata.uns:
124
+ query_input[key] = _plain(adata.uns[key])
125
+ adata.uns["query_input"] = query_input
126
+ return adata
127
+
128
+
129
+ def _plain(obj):
130
+ """h5ad-loaded uns -> plain JSON-able Python."""
131
+ if isinstance(obj, dict):
132
+ return {str(k): _plain(v) for k, v in obj.items()}
133
+ if isinstance(obj, (list, tuple)):
134
+ return [_plain(v) for v in obj]
135
+ if isinstance(obj, np.ndarray):
136
+ return obj.tolist()
137
+ if isinstance(obj, np.generic):
138
+ return obj.item()
139
+ return obj
140
+
141
+
142
+ def main(argv=None) -> int:
143
+ args = parse_args(argv)
144
+ if args.device == "cpu":
145
+ os.environ["CUDA_VISIBLE_DEVICES"] = ""
146
+ import anndata as ad # noqa: E402
147
+ import scvi # noqa: E402
148
+ import torch # noqa: E402
149
+ from scvi.model import SCANVI # noqa: E402
150
+
151
+ import poisson_readout as PR # noqa: E402
152
+
153
+ torch.set_num_threads(int(args.num_threads))
154
+ if args.device == "cuda" and not torch.cuda.is_available():
155
+ raise SystemExit("cuda requested but not available")
156
+ accelerator = "gpu" if args.device == "cuda" else "cpu"
157
+ scvi.settings.seed = int(args.seed)
158
+ t_start = time.monotonic()
159
+ out_dir: Path = args.out_dir
160
+ out_dir.mkdir(parents=True, exist_ok=True)
161
+ model_dir: Path = args.model_dir
162
+ if not (model_dir / "model.pt").exists():
163
+ raise SystemExit(f"{model_dir} has no model.pt")
164
+ method = args.method_name or args.query.stem
165
+ l2_to_l1 = C.load_l2_to_l1()
166
+
167
+ # ---- query -------------------------------------------------------------
168
+ suffix = args.query.suffix.lower()
169
+ readout_info = None
170
+ if suffix == ".npz":
171
+ adata = PR.readout_npz(
172
+ args.query,
173
+ seed=args.seed,
174
+ matrix_key=args.npz_matrix_key,
175
+ max_cells=args.max_cells,
176
+ subset_seed=args.subset_seed,
177
+ batch_prefix=args.batch_prefix,
178
+ method_name=method,
179
+ library_scale=args.library_scale,
180
+ )
181
+ readout_info = dict(adata.uns["poisson_readout"])
182
+ adata.obs["group"] = "unknown"
183
+ elif suffix == ".h5ad":
184
+ adata = _load_h5ad_query(args.query, sample_id_col=args.sample_id_col, batch_key_col=args.batch_key_col, batch_prefix=args.batch_prefix, method=method)
185
+ if args.max_cells is not None and args.max_cells < adata.n_obs:
186
+ rows = np.sort(np.random.default_rng(args.subset_seed).choice(adata.n_obs, size=args.max_cells, replace=False))
187
+ adata = adata[rows].copy()
188
+ adata.obs["npz_row"] = rows
189
+ adata.obs["cell_index"] = np.arange(adata.n_obs, dtype=np.int64)
190
+ adata.obs["group"] = adata.obs["condition"].astype(str).to_numpy() if "condition" in adata.obs.columns else "unknown"
191
+ readout_info = adata.uns["query_input"].get("poisson_readout")
192
+ else:
193
+ raise SystemExit(f"unsupported query format {suffix!r}")
194
+ query_build_info = adata.uns.get("query_input", {}).get("query_build") if suffix == ".h5ad" else None
195
+ n_query_genes = adata.n_vars
196
+ n_input_cells = int(readout_info["input_n_cells"]) if readout_info else int(adata.uns.get("query_input", {}).get("n_input_cells", adata.n_obs))
197
+ subset = adata.n_obs < n_input_cells
198
+
199
+ # ---- gene-space guard (no fabricated zeros) -------------------------------
200
+ ref_vars = SCANVI.prepare_query_anndata(None, str(model_dir), return_reference_var_names=True)
201
+ ref_set, q_set = set(map(str, ref_vars)), set(map(str, adata.var_names))
202
+ missing = sorted(ref_set - q_set)
203
+ dropped = len(q_set - ref_set)
204
+ if missing and not args.allow_missing_genes:
205
+ raise SystemExit(
206
+ f"{len(missing)} of {len(ref_set)} model genes are absent from the query "
207
+ f"(e.g. {missing[:5]}); prepare_query_anndata would zero-pad them. Use a model "
208
+ "trained on a panel contained in the query, or pass --allow-missing-genes."
209
+ )
210
+ SCANVI.prepare_query_anndata(adata, str(model_dir))
211
+ assert list(map(str, adata.var_names)) == list(map(str, ref_vars))
212
+
213
+ # ---- frozen prediction ----------------------------------------------------
214
+ query = SCANVI.load_query_data(adata, str(model_dir), accelerator=accelerator)
215
+ t0 = time.monotonic()
216
+ soft = query.predict(soft=True, batch_size=int(args.eval_batch_size))
217
+ predict_seconds = time.monotonic() - t0
218
+ pred_l2, conf_l2, probs_l2 = C.soft_to_predictions(soft)
219
+ l1_mass = C.l1_probability_mass(probs_l2, l2_to_l1)
220
+ pred_l1 = C.collapse_l1(pred_l2, l2_to_l1)
221
+ conf_l1 = l1_mass.to_numpy()[np.arange(len(pred_l1)), [list(l1_mass.columns).index(x) for x in pred_l1]]
222
+ pred_p5 = C.collapse_pbmc5(pred_l1, other=args.other_label)
223
+ if args.confidence_threshold > 0:
224
+ low = conf_l2 < args.confidence_threshold
225
+ pred_l2 = np.where(low, UNSPEC, pred_l2).astype(object)
226
+ pred_l1 = np.where(low, UNSPEC, pred_l1).astype(object)
227
+ pred_p5 = np.where(low, args.other_label, pred_p5).astype(object)
228
+
229
+ # ---- outputs --------------------------------------------------------------
230
+ sample_ids = adata.obs["sample_id"].astype(str).to_numpy()
231
+ frame = pd.DataFrame(
232
+ {
233
+ "sample_id": sample_ids.astype(object),
234
+ "group": adata.obs["group"].astype(str).to_numpy().astype(object),
235
+ "source": adata.obs["source"].astype(str).to_numpy().astype(object),
236
+ "cell_index": adata.obs["cell_index"].to_numpy().astype(np.int64),
237
+ "celltype_l1_pred": pred_p5,
238
+ "label_confidence": conf_l1.astype(np.float32),
239
+ "aifi_l1": pred_l1,
240
+ "aifi_l2": pred_l2,
241
+ "aifi_l2_confidence": conf_l2.astype(np.float32),
242
+ "aifi_l1_confidence": conf_l1.astype(np.float32),
243
+ "npz_row": adata.obs["npz_row"].to_numpy().astype(np.int64),
244
+ }
245
+ )
246
+ frame.to_parquet(out_dir / "labels.parquet", index=False)
247
+ probs_l2.astype(np.float32).reset_index(names="obs_name").to_parquet(out_dir / "soft_probabilities_l2.parquet", index=False)
248
+ l1_mass.astype(np.float32).reset_index(names="obs_name").to_parquet(out_dir / "probabilities_l1.parquet", index=False)
249
+
250
+ model_manifest_path = args.model_manifest or (model_dir.parent / "MODEL_MANIFEST.json")
251
+ model_manifest = json.loads(model_manifest_path.read_text()) if model_manifest_path.exists() else {}
252
+ training_source = model_manifest.get("reference", {}).get("h5ad")
253
+ labels_6 = list(C.PBMC5_LABELS) + [args.other_label]
254
+ payload = {
255
+ "dataset_id": args.dataset_id,
256
+ "split": args.split,
257
+ "input_h5ad": str(args.query),
258
+ "method": method,
259
+ "out_parquet": str(out_dir / "labels.parquet"),
260
+ "training_source": training_source,
261
+ "target_truth_used_for_fitting": False,
262
+ "classifier": f"aifi_scanvi_rebuild_20260916_frozen_predict[{model_manifest.get('run_name', model_dir.parent.name)}]",
263
+ "labels": labels_6,
264
+ "l2_labels": [str(c) for c in probs_l2.columns],
265
+ "n_cells": int(adata.n_obs),
266
+ "n_genes": int(adata.n_vars),
267
+ "note": "Evaluation-only annotation with a frozen AIFI scANVI (zero query-training epochs); L1 outside PBMC5 -> Other, never dropped.",
268
+ "label_source_column": "AIFI_L2 (reference) -> AIFI_L2_TO_L1 -> PBMC5 + Other",
269
+ "query_train_epochs": 0,
270
+ "confidence_threshold": float(args.confidence_threshold),
271
+ "subset": bool(subset),
272
+ "evaluator_aligned": not bool(subset),
273
+ "gene_space": {
274
+ "join_key": "ensembl_id",
275
+ "model_genes": int(len(ref_set)),
276
+ "query_genes": int(n_query_genes),
277
+ "model_genes_missing_from_query_zero_padded": int(len(missing)),
278
+ "query_genes_outside_model_dropped": int(dropped),
279
+ "rule": "query is subset/reordered to the model's gene list; zero-padding of absent model genes is refused unless --allow-missing-genes",
280
+ },
281
+ "readout": readout_info,
282
+ "query_build": query_build_info,
283
+ "model": {
284
+ "scanvi_model_dir": str(model_dir),
285
+ "model_pt_sha256": C.sha256_file(model_dir / "model.pt"),
286
+ "model_manifest": str(model_manifest_path) if model_manifest_path.exists() else None,
287
+ "held_out_summary": model_manifest.get("held_out_summary"),
288
+ },
289
+ "label_counts": {
290
+ "celltype_l1_pred": {k: int(v) for k, v in pd.Series(pred_p5).value_counts().items()},
291
+ "aifi_l1": {k: int(v) for k, v in pd.Series(pred_l1).value_counts().items()},
292
+ "aifi_l2": {k: int(v) for k, v in pd.Series(pred_l2).value_counts().items()},
293
+ },
294
+ "confidence": {"mean_l2_max_prob": float(conf_l2.mean()), "mean_l1_mass": float(conf_l1.mean()), "frac_l2_max_prob_ge_0.5": float(np.mean(conf_l2 >= 0.5))},
295
+ "timings_s": {"predict": round(predict_seconds, 1), "total": round(time.monotonic() - t_start, 1)},
296
+ "versions": {"scvi-tools": scvi.__version__, "torch": torch.__version__, "anndata": _pkg_version("anndata")},
297
+ "device": args.device,
298
+ "created_at_utc": datetime.now(timezone.utc).isoformat(),
299
+ }
300
+ C.write_json(out_dir / "labels.manifest.json", payload)
301
+ print(json.dumps({k: payload[k] for k in ("method", "n_cells", "n_genes", "label_counts", "confidence", "timings_s", "subset")}, indent=2))
302
+ print(f"-> {out_dir / 'labels.parquet'}")
303
+ return 0
304
+
305
+
306
+ if __name__ == "__main__":
307
+ raise SystemExit(main())
paper-releases/20260928/diffusion/data/annotator/aifi_scanvi_f01common_v1/reference/REFERENCE_MANIFEST.json ADDED
@@ -0,0 +1,572 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "schema_version": "aifi_scanvi_rebuild.reference_manifest.v1",
3
+ "built_at_utc": "2026-09-15T16:05:57.806936+00:00",
4
+ "atlas": {
5
+ "path": "/home/sj_server_1/gblee/datalake/single-cell-RNA-seq-datasets/PBMC-cells/009_A_Human_Immune_Health_Atlas_Human_Immune_Health_Atlas_AIFI_immune_dynamics_across_healthy_age/39832a61-3df1-4f1f-971d-3c2a74539047.h5ad",
6
+ "size_bytes": 10162450774,
7
+ "mtime": "2025-10-30T00:12:32+00:00",
8
+ "n_cells": 1821725,
9
+ "n_genes": 32357
10
+ },
11
+ "panel": {
12
+ "path": "/home/sj_server_1/PBISC/PBISC-data/single-cell-data-block-blood/metadata/var.parquet",
13
+ "n_genes": 20097
14
+ },
15
+ "gene_match": {
16
+ "canonical_20097": {
17
+ "matched": 19642,
18
+ "unmatched": 455
19
+ },
20
+ "tier_6k": {
21
+ "n": 6000,
22
+ "matched": 5944,
23
+ "unmatched": 56
24
+ },
25
+ "tier_2k": {
26
+ "n": 2000,
27
+ "matched": 1984
28
+ },
29
+ "tier_broad": {
30
+ "n": 11589,
31
+ "matched": 11517
32
+ },
33
+ "rule": "join on Ensembl ID without version; panel genes absent from the atlas are absent from the reference (no zero columns)",
34
+ "intersection_2980": {
35
+ "n": 2980,
36
+ "matched": 2977,
37
+ "unmatched": 3,
38
+ "absent_gene_ids": [
39
+ "ENSG00000233276",
40
+ "ENSG00000168255",
41
+ "ENSG00000158427"
42
+ ],
43
+ "list_source": "/home/sj_server_1/PBISC/immun-pbmc-fm/model_8_sparse_data_diffusion/analysis/scsemi_benchmark_diffusion_20260913/metrics/panel_6k_e4_2980genes/pbmc5/evaluation_manifest.json",
44
+ "list_sha256": "f40ee3fd60a0b75ba35cd79d76837eecc1c7698a245b810e8cf28ab1dd3b447a",
45
+ "rule": "verbatim 2,980-gene intersection (6k tier x benchmark working panel); join on Ensembl ID; absent genes are absent"
46
+ },
47
+ "f01_common": {
48
+ "n": 1006,
49
+ "matched": 1005,
50
+ "unmatched": 1,
51
+ "absent_gene_ids": [
52
+ "ENSG00000233276"
53
+ ],
54
+ "list_source": "/home/sj_server_1/PBISC/immun-pbmc-fm/model_8_sparse_data_diffusion/plans/floor01_campaign_20260923/evaluation_manifest_common.json",
55
+ "list_sha256": "0749a7af9eb20bf301f63e9dc5dc6735782248823e6f732c643584c89c5af5c1",
56
+ "rule": "verbatim 2,980-gene intersection (6k tier x benchmark working panel); join on Ensembl ID; absent genes are absent"
57
+ }
58
+ },
59
+ "sampling": {
60
+ "seed": 20260916,
61
+ "target_cells": 400000,
62
+ "min_per_class": 5000,
63
+ "proportional_rate": 0.20016128631272764,
64
+ "strata": "AIFI_L2 x donor_id, largest-remainder allocation within class, uniform without replacement within stratum",
65
+ "n_selected": 400000,
66
+ "dev_row_limit": null
67
+ },
68
+ "donor_split": {
69
+ "val_donor_frac": 0.1,
70
+ "stratified_by": "cohort",
71
+ "n_train_donors": 97,
72
+ "n_val_donors": 11,
73
+ "train_donors": [
74
+ "BR1001",
75
+ "BR1002",
76
+ "BR1003",
77
+ "BR1004",
78
+ "BR1005",
79
+ "BR1006",
80
+ "BR1008",
81
+ "BR1009",
82
+ "BR1010",
83
+ "BR1011",
84
+ "BR1012",
85
+ "BR1013",
86
+ "BR1014",
87
+ "BR1015",
88
+ "BR1017",
89
+ "BR1018",
90
+ "BR1019",
91
+ "BR1021",
92
+ "BR1023",
93
+ "BR1024",
94
+ "BR1025",
95
+ "BR1026",
96
+ "BR1028",
97
+ "BR1030",
98
+ "BR1031",
99
+ "BR1032",
100
+ "BR1037",
101
+ "BR1040",
102
+ "BR1041",
103
+ "BR1043",
104
+ "BR1044",
105
+ "BR1045",
106
+ "BR1047",
107
+ "BR1048",
108
+ "BR1049",
109
+ "BR1050",
110
+ "BR1051",
111
+ "BR1052",
112
+ "BR1054",
113
+ "BR1056",
114
+ "BR1057",
115
+ "BR1058",
116
+ "BR2002",
117
+ "BR2003",
118
+ "BR2005",
119
+ "BR2008",
120
+ "BR2009",
121
+ "BR2010",
122
+ "BR2012",
123
+ "BR2014",
124
+ "BR2015",
125
+ "BR2016",
126
+ "BR2018",
127
+ "BR2019",
128
+ "BR2020",
129
+ "BR2021",
130
+ "BR2022",
131
+ "BR2023",
132
+ "BR2025",
133
+ "BR2026",
134
+ "BR2028",
135
+ "BR2029",
136
+ "BR2030",
137
+ "BR2031",
138
+ "BR2032",
139
+ "BR2033",
140
+ "BR2034",
141
+ "BR2035",
142
+ "BR2036",
143
+ "BR2038",
144
+ "BR2039",
145
+ "BR2040",
146
+ "BR2041",
147
+ "BR2042",
148
+ "BR2043",
149
+ "BR2044",
150
+ "BR2045",
151
+ "BR2046",
152
+ "BR2047",
153
+ "BR2048",
154
+ "BR2050",
155
+ "BR2051",
156
+ "BR2052",
157
+ "UP1008",
158
+ "UP1011",
159
+ "UP1012",
160
+ "UP1014",
161
+ "UP1015",
162
+ "UP1017",
163
+ "UP1018",
164
+ "UP1021",
165
+ "UP1023",
166
+ "UP1024",
167
+ "UP1026",
168
+ "UP1031",
169
+ "UP1032",
170
+ "UP1034"
171
+ ],
172
+ "val_donors": [
173
+ "BR1007",
174
+ "BR1016",
175
+ "BR1033",
176
+ "BR1042",
177
+ "BR1059",
178
+ "BR2013",
179
+ "BR2024",
180
+ "BR2037",
181
+ "BR2053",
182
+ "UP1022",
183
+ "UP1025"
184
+ ]
185
+ },
186
+ "cells_by_split": {
187
+ "train": 360310,
188
+ "val": 39690
189
+ },
190
+ "classes_AIFI_L2": {
191
+ "Naive CD4 T cell": {
192
+ "train": 67899,
193
+ "val": 7776,
194
+ "total": 75675
195
+ },
196
+ "Memory CD4 T cell": {
197
+ "train": 58278,
198
+ "val": 6132,
199
+ "total": 64410
200
+ },
201
+ "CD14 monocyte": {
202
+ "train": 48369,
203
+ "val": 5540,
204
+ "total": 53909
205
+ },
206
+ "Memory CD8 T cell": {
207
+ "train": 33084,
208
+ "val": 3565,
209
+ "total": 36649
210
+ },
211
+ "CD56dim NK cell": {
212
+ "train": 24222,
213
+ "val": 2576,
214
+ "total": 26798
215
+ },
216
+ "Naive CD8 T cell": {
217
+ "train": 21525,
218
+ "val": 2728,
219
+ "total": 24253
220
+ },
221
+ "Naive B cell": {
222
+ "train": 15822,
223
+ "val": 1534,
224
+ "total": 17356
225
+ },
226
+ "gdT": {
227
+ "train": 9130,
228
+ "val": 996,
229
+ "total": 10126
230
+ },
231
+ "Memory B cell": {
232
+ "train": 8594,
233
+ "val": 991,
234
+ "total": 9585
235
+ },
236
+ "MAIT": {
237
+ "train": 8306,
238
+ "val": 930,
239
+ "total": 9236
240
+ },
241
+ "CD16 monocyte": {
242
+ "train": 8197,
243
+ "val": 994,
244
+ "total": 9191
245
+ },
246
+ "Treg": {
247
+ "train": 7106,
248
+ "val": 718,
249
+ "total": 7824
250
+ },
251
+ "cDC2": {
252
+ "train": 4448,
253
+ "val": 552,
254
+ "total": 5000
255
+ },
256
+ "Transitional B cell": {
257
+ "train": 4454,
258
+ "val": 546,
259
+ "total": 5000
260
+ },
261
+ "Platelet": {
262
+ "train": 4611,
263
+ "val": 389,
264
+ "total": 5000
265
+ },
266
+ "pDC": {
267
+ "train": 4488,
268
+ "val": 512,
269
+ "total": 5000
270
+ },
271
+ "Intermediate monocyte": {
272
+ "train": 4522,
273
+ "val": 478,
274
+ "total": 5000
275
+ },
276
+ "Effector B cell": {
277
+ "train": 4531,
278
+ "val": 469,
279
+ "total": 5000
280
+ },
281
+ "CD8aa": {
282
+ "train": 4833,
283
+ "val": 167,
284
+ "total": 5000
285
+ },
286
+ "CD56bright NK cell": {
287
+ "train": 4543,
288
+ "val": 457,
289
+ "total": 5000
290
+ },
291
+ "Proliferating NK cell": {
292
+ "train": 2566,
293
+ "val": 259,
294
+ "total": 2825
295
+ },
296
+ "DN T cell": {
297
+ "train": 2096,
298
+ "val": 253,
299
+ "total": 2349
300
+ },
301
+ "Proliferating T cell": {
302
+ "train": 2107,
303
+ "val": 213,
304
+ "total": 2320
305
+ },
306
+ "Plasma cell": {
307
+ "train": 1981,
308
+ "val": 170,
309
+ "total": 2151
310
+ },
311
+ "Progenitor cell": {
312
+ "train": 1360,
313
+ "val": 166,
314
+ "total": 1526
315
+ },
316
+ "Erythrocyte": {
317
+ "train": 1165,
318
+ "val": 343,
319
+ "total": 1508
320
+ },
321
+ "cDC1": {
322
+ "train": 876,
323
+ "val": 67,
324
+ "total": 943
325
+ },
326
+ "ILC": {
327
+ "train": 733,
328
+ "val": 111,
329
+ "total": 844
330
+ },
331
+ "ASDC": {
332
+ "train": 464,
333
+ "val": 58,
334
+ "total": 522
335
+ }
336
+ },
337
+ "classes_AIFI_L1": {
338
+ "T cell": {
339
+ "train": 214364,
340
+ "val": 23478,
341
+ "total": 237842
342
+ },
343
+ "Monocyte": {
344
+ "train": 61088,
345
+ "val": 7012,
346
+ "total": 68100
347
+ },
348
+ "B cell": {
349
+ "train": 35382,
350
+ "val": 3710,
351
+ "total": 39092
352
+ },
353
+ "NK cell": {
354
+ "train": 31331,
355
+ "val": 3292,
356
+ "total": 34623
357
+ },
358
+ "DC": {
359
+ "train": 10276,
360
+ "val": 1189,
361
+ "total": 11465
362
+ },
363
+ "Platelet": {
364
+ "train": 4611,
365
+ "val": 389,
366
+ "total": 5000
367
+ },
368
+ "Progenitor cell": {
369
+ "train": 1360,
370
+ "val": 166,
371
+ "total": 1526
372
+ },
373
+ "Erythrocyte": {
374
+ "train": 1165,
375
+ "val": 343,
376
+ "total": 1508
377
+ },
378
+ "ILC": {
379
+ "train": 733,
380
+ "val": 111,
381
+ "total": 844
382
+ }
383
+ },
384
+ "obs_columns": [
385
+ "AIFI_L1",
386
+ "AIFI_L2",
387
+ "AIFI_L3",
388
+ "donor_id",
389
+ "batch_id",
390
+ "cohort",
391
+ "age_group",
392
+ "sex",
393
+ "cmv",
394
+ "n_umis_atlas",
395
+ "n_genes_atlas",
396
+ "atlas_row",
397
+ "split",
398
+ "batch_key",
399
+ "aifi_l2_train"
400
+ ],
401
+ "outputs": {
402
+ "full": {
403
+ "path": "reference/aifi_reference_20097.h5ad",
404
+ "n_cells": 400000,
405
+ "n_genes": 19642,
406
+ "nnz": 658152192,
407
+ "size_bytes": 5307926173,
408
+ "sha256": "e80b6047a0983a47fa8fca3c6d44c66d425ea647fe519fd1c7b404869e5459cb",
409
+ "library_size_median": 4560.0,
410
+ "library_size_mean": 5204.40234375,
411
+ "integer_valued_fraction": 1.0
412
+ },
413
+ "tier": {
414
+ "path": "reference/aifi_reference_6k.h5ad",
415
+ "n_cells": 400000,
416
+ "n_genes": 5944,
417
+ "nnz": 240804030,
418
+ "size_bytes": 1967088729,
419
+ "sha256": "60683789c961e7e3b8241d004f6d881fc6b42b3393aab8e1fd623e58884e082f",
420
+ "library_size_median": 2885.0,
421
+ "library_size_mean": 3206.773681640625,
422
+ "integer_valued_fraction": 1.0
423
+ },
424
+ "intersection_2980": {
425
+ "path": "reference/aifi_reference_2980.h5ad",
426
+ "n_cells": 400000,
427
+ "n_genes": 2977,
428
+ "nnz": 133667869,
429
+ "size_bytes": 1107879357,
430
+ "sha256": "e7c8a45724e978a5f32112a4bdb0db1f76821d883d9f1b6ff444c55ddf00b39d",
431
+ "library_size_median": 1361.0,
432
+ "library_size_mean": 1614.7176513671875,
433
+ "integer_valued_fraction": 1.0
434
+ },
435
+ "f01_common": {
436
+ "path": "reference/aifi_reference_f01common.h5ad",
437
+ "n_cells": 400000,
438
+ "n_genes": 1005,
439
+ "nnz": 40618563,
440
+ "size_bytes": 362998569,
441
+ "sha256": "e90de26e48ec905215e6f33057fb4f57d0cecc7f4c820b6bbf26497b0e45e1e1",
442
+ "library_size_median": 537.0,
443
+ "library_size_mean": 677.409423828125,
444
+ "integer_valued_fraction": 1.0
445
+ }
446
+ },
447
+ "side_files": {
448
+ "panel_presence_20097": "reference/panel_presence_20097.csv",
449
+ "panel_presence_6k": "reference/panel_presence_6k.csv",
450
+ "donor_split": "reference/donor_split.csv",
451
+ "stratum_allocation": "reference/stratum_allocation.csv",
452
+ "cell_selection": "reference/cell_selection.parquet",
453
+ "log": "reference/build_reference.log",
454
+ "panel_presence_2980": "reference/panel_presence_2980.csv",
455
+ "gene_list_2980_json": "queries_2980/gene_list_2980.json",
456
+ "build_reference_2980_log": "reference/build_reference_2980.log"
457
+ },
458
+ "environment": {
459
+ "python": "3.12.14",
460
+ "argv": [
461
+ "build_reference.py",
462
+ "--out-dir",
463
+ "reference"
464
+ ]
465
+ },
466
+ "derived_builds": [
467
+ {
468
+ "name": "intersection_2980",
469
+ "built_at_utc": "2026-09-15T16:53:20.289987+00:00",
470
+ "script": "build_reference_2980.py",
471
+ "derived_from": "/home/sj_server_1/PBISC/immun-pbmc-fm/model_8_sparse_data_diffusion/plans/aifi_scanvi_rebuild_20260916/reference/aifi_reference_6k.h5ad",
472
+ "derived_from_sha256": "60683789c961e7e3b8241d004f6d881fc6b42b3393aab8e1fd623e58884e082f",
473
+ "cells": "identical rows, order, obs and counts to the source (verified against cell_selection.parquet / donor_split.csv)",
474
+ "cell_check": {
475
+ "rows": 400000,
476
+ "obs_columns_equal": [
477
+ "atlas_row",
478
+ "split",
479
+ "donor_id",
480
+ "batch_id",
481
+ "batch_key",
482
+ "aifi_l2_train",
483
+ "AIFI_L1",
484
+ "AIFI_L2",
485
+ "AIFI_L3",
486
+ "cohort"
487
+ ],
488
+ "cells_by_split": {
489
+ "train": 360310,
490
+ "val": 39690
491
+ },
492
+ "val_donors": [
493
+ "BR1007",
494
+ "BR1016",
495
+ "BR1033",
496
+ "BR1042",
497
+ "BR1059",
498
+ "BR2013",
499
+ "BR2024",
500
+ "BR2037",
501
+ "BR2053",
502
+ "UP1022",
503
+ "UP1025"
504
+ ]
505
+ },
506
+ "gene_list_source": "/home/sj_server_1/PBISC/immun-pbmc-fm/model_8_sparse_data_diffusion/analysis/scsemi_benchmark_diffusion_20260913/metrics/panel_6k_e4_2980genes/pbmc5/evaluation_manifest.json",
507
+ "n_genes": 2977,
508
+ "output": "reference/aifi_reference_2980.h5ad",
509
+ "argv": [
510
+ "build_reference_2980.py"
511
+ ]
512
+ },
513
+ {
514
+ "name": "f01_common",
515
+ "built_at_utc": "2026-09-23T17:24:11.636292+00:00",
516
+ "script": "build_reference_2980.py",
517
+ "derived_from": "/home/sj_server_1/PBISC/immun-pbmc-fm/model_8_sparse_data_diffusion/plans/aifi_scanvi_rebuild_20260916/reference/aifi_reference_6k.h5ad",
518
+ "derived_from_sha256": "60683789c961e7e3b8241d004f6d881fc6b42b3393aab8e1fd623e58884e082f",
519
+ "cells": "identical rows, order, obs and counts to the source (verified against cell_selection.parquet / donor_split.csv)",
520
+ "cell_check": {
521
+ "rows": 400000,
522
+ "obs_columns_equal": [
523
+ "atlas_row",
524
+ "split",
525
+ "donor_id",
526
+ "batch_id",
527
+ "batch_key",
528
+ "aifi_l2_train",
529
+ "AIFI_L1",
530
+ "AIFI_L2",
531
+ "AIFI_L3",
532
+ "cohort"
533
+ ],
534
+ "cells_by_split": {
535
+ "train": 360310,
536
+ "val": 39690
537
+ },
538
+ "val_donors": [
539
+ "BR1007",
540
+ "BR1016",
541
+ "BR1033",
542
+ "BR1042",
543
+ "BR1059",
544
+ "BR2013",
545
+ "BR2024",
546
+ "BR2037",
547
+ "BR2053",
548
+ "UP1022",
549
+ "UP1025"
550
+ ]
551
+ },
552
+ "gene_list_source": "/home/sj_server_1/PBISC/immun-pbmc-fm/model_8_sparse_data_diffusion/plans/floor01_campaign_20260923/evaluation_manifest_common.json",
553
+ "n_genes": 1005,
554
+ "output": "reference/aifi_reference_f01common.h5ad",
555
+ "argv": [
556
+ "/home/sj_server_1/PBISC/immun-pbmc-fm/model_8_sparse_data_diffusion/plans/aifi_scanvi_rebuild_20260916/build_reference_2980.py",
557
+ "--gene-list-source",
558
+ "/home/sj_server_1/PBISC/immun-pbmc-fm/model_8_sparse_data_diffusion/plans/floor01_campaign_20260923/evaluation_manifest_common.json",
559
+ "--expected-n",
560
+ "1006",
561
+ "--gene-list-json",
562
+ "/home/sj_server_1/PBISC/immun-pbmc-fm/model_8_sparse_data_diffusion/plans/floor01_campaign_20260923/queries/gene_list_common.json",
563
+ "--gene-list-txt",
564
+ "/home/sj_server_1/PBISC/immun-pbmc-fm/model_8_sparse_data_diffusion/plans/floor01_campaign_20260923/queries/gene_list_common.txt",
565
+ "--name",
566
+ "aifi_reference_f01common.h5ad",
567
+ "--manifest-key",
568
+ "f01_common"
569
+ ]
570
+ }
571
+ ]
572
+ }
paper-releases/20260928/diffusion/data/annotator/aifi_scanvi_f01common_v1/reference/donor_split.csv ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ donor_id,cohort,batch_id,n_cells,split
2
+ BR1001,BR1,B001,18527,train
3
+ BR1002,BR1,B001,18957,train
4
+ BR1003,BR1,B001,19002,train
5
+ BR1004,BR1,B002,17350,train
6
+ BR1005,BR1,B002,17688,train
7
+ BR1006,BR1,B078,17318,train
8
+ BR1007,BR1,B002,17096,val
9
+ BR1008,BR1,B002,15905,train
10
+ BR1009,BR1,B078,17723,train
11
+ BR1010,BR1,B002,15060,train
12
+ BR1011,BR1,B078,16031,train
13
+ BR1012,BR1,B078,15153,train
14
+ BR1013,BR1,B078,20880,train
15
+ BR1014,BR1,B078,18561,train
16
+ BR1015,BR1,B041,15071,train
17
+ BR1016,BR1,B040,14992,val
18
+ BR1017,BR1,B041,15909,train
19
+ BR1018,BR1,B007,16299,train
20
+ BR1019,BR1,B039,19495,train
21
+ BR1021,BR1,B036,13097,train
22
+ BR1023,BR1,B040,15076,train
23
+ BR1024,BR1,B040,16748,train
24
+ BR1025,BR1,B040,16667,train
25
+ BR1026,BR1,B047,19307,train
26
+ BR1028,BR1,B039,17840,train
27
+ BR1030,BR1,B045,19469,train
28
+ BR1031,BR1,B041,15670,train
29
+ BR1032,BR1,B040,16626,train
30
+ BR1033,BR1,B010,17164,val
31
+ BR1037,BR1,B036,17890,train
32
+ BR1040,BR1,B040,15892,train
33
+ BR1041,BR1,B056,17489,train
34
+ BR1042,BR1,B040,18473,val
35
+ BR1043,BR1,B041,13953,train
36
+ BR1044,BR1,B041,14594,train
37
+ BR1045,BR1,B041,14985,train
38
+ BR1047,BR1,B046,17666,train
39
+ BR1048,BR1,B046,17836,train
40
+ BR1049,BR1,B046,17964,train
41
+ BR1050,BR1,B072,15463,train
42
+ BR1051,BR1,B072,22931,train
43
+ BR1052,BR1,B072,20144,train
44
+ BR1054,BR1,B073,14198,train
45
+ BR1056,BR1,B072,15475,train
46
+ BR1057,BR1,B072,16962,train
47
+ BR1058,BR1,B073,20720,train
48
+ BR1059,BR1,B085,14974,val
49
+ BR2002,BR2,B002,16670,train
50
+ BR2003,BR2,B002,15590,train
51
+ BR2005,BR2,B142,14993,train
52
+ BR2008,BR2,B078,17620,train
53
+ BR2009,BR2,B039,11724,train
54
+ BR2010,BR2,B078,23108,train
55
+ BR2012,BR2,B045,14953,train
56
+ BR2013,BR2,B046,15529,val
57
+ BR2014,BR2,B046,16482,train
58
+ BR2015,BR2,B040,13527,train
59
+ BR2016,BR2,B040,17686,train
60
+ BR2018,BR2,B047,18471,train
61
+ BR2019,BR2,B048,17234,train
62
+ BR2020,BR2,B048,15328,train
63
+ BR2021,BR2,B048,16802,train
64
+ BR2022,BR2,B043,18494,train
65
+ BR2023,BR2,B046,16175,train
66
+ BR2024,BR2,B045,18458,val
67
+ BR2025,BR2,B050,24539,train
68
+ BR2026,BR2,B053,18955,train
69
+ BR2028,BR2,B054,20762,train
70
+ BR2029,BR2,B132,12658,train
71
+ BR2030,BR2,B054,22728,train
72
+ BR2031,BR2,B056,16208,train
73
+ BR2032,BR2,B073,14161,train
74
+ BR2033,BR2,B067,12746,train
75
+ BR2034,BR2,B053,16734,train
76
+ BR2035,BR2,B055,10217,train
77
+ BR2036,BR2,B053,14677,train
78
+ BR2037,BR2,B056,17483,val
79
+ BR2038,BR2,B056,15915,train
80
+ BR2039,BR2,B077,18063,train
81
+ BR2040,BR2,B082,13397,train
82
+ BR2041,BR2,B064,18764,train
83
+ BR2042,BR2,B060,16943,train
84
+ BR2043,BR2,B080,16064,train
85
+ BR2044,BR2,B080,17604,train
86
+ BR2045,BR2,B073,13951,train
87
+ BR2046,BR2,B145,14290,train
88
+ BR2047,BR2,B077,18200,train
89
+ BR2048,BR2,B077,26131,train
90
+ BR2050,BR2,B084,18111,train
91
+ BR2051,BR2,B084,18490,train
92
+ BR2052,BR2,B060,16312,train
93
+ BR2053,BR2,B145,12571,val
94
+ UP1008,UP1,B053,20902,train
95
+ UP1011,UP1,B060,14645,train
96
+ UP1012,UP1,B053,16176,train
97
+ UP1014,UP1,B063,20613,train
98
+ UP1015,UP1,B063,18620,train
99
+ UP1017,UP1,B094,16871,train
100
+ UP1018,UP1,B094,17486,train
101
+ UP1021,UP1,B094,14124,train
102
+ UP1022,UP1,B094,21689,val
103
+ UP1023,UP1,B096,13291,train
104
+ UP1024,UP1,B096,6632,train
105
+ UP1025,UP1,B096,13282,val
106
+ UP1026,UP1,B096,17517,train
107
+ UP1031,UP1,B138,17706,train
108
+ UP1032,UP1,B138,16345,train
109
+ UP1034,UP1,B138,18018,train