zhouwanding commited on
Commit
2a5d398
·
verified ·
1 Parent(s): 024b52b

hg38_celltype: violation framework, 33 classes; .ubjx -> .clfx

Browse files

hg38_celltype is now a violation-framework model with no fitted parameters: it reads each class's expected methylation state off the MRMP binstrings and calls the class the query contradicts least, weighting patterns by sqrt(n_cpg). Confidence is the margin to the runner-up, which collapses when no class fits.

External test 0.842 / macro-F1 0.853 at >=100k covered CpGs. Colorectal cancer single cells call 100% gastrointestinal from liver and lymph metastases alike, and the sink that sent globally demethylated tumours to Acinar.(Pancreas) drops from 30.0% of TCGA calls to 2.3%.

Classifier bundles are renamed .ubjx -> .clfx: .ubjx named a payload format rather than a role and had already stopped being accurate (hg38_sex carried a plain-text linear spec, no UBJSON). Bundles are detected by MSBNDL1 magic, never by extension, so .ubjx stays accepted. The previous filenames remain available at --revision v5.

mm10_celltype.ubjx is unchanged, pending a Liu 2021 rebuild.

.gitattributes CHANGED
@@ -36,6 +36,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
36
  hg38_wg.updecx filter=lfs diff=lfs merge=lfs -text
37
  hg38_10k1.updecx filter=lfs diff=lfs merge=lfs -text
38
  hg38_65celltypes.refx filter=lfs diff=lfs merge=lfs -text
39
- hg38_celltype.ubjx filter=lfs diff=lfs merge=lfs -text
40
  mm10_celltype.ubjx filter=lfs diff=lfs merge=lfs -text
41
  mm10_wg.updecx filter=lfs diff=lfs merge=lfs -text
 
36
  hg38_wg.updecx filter=lfs diff=lfs merge=lfs -text
37
  hg38_10k1.updecx filter=lfs diff=lfs merge=lfs -text
38
  hg38_65celltypes.refx filter=lfs diff=lfs merge=lfs -text
39
+ hg38_celltype.clfx filter=lfs diff=lfs merge=lfs -text
40
  mm10_celltype.ubjx filter=lfs diff=lfs merge=lfs -text
41
  mm10_wg.updecx filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -23,14 +23,21 @@ runs directly — no separate annotation files.
23
 
24
  ```sh
25
  # fetch one model (or --local-dir models to grab all)
26
- hf download zhou-lab/methscope hg38_celltype.ubjx --local-dir .
27
 
28
- methscope predict query.cg hg38_celltype.ubjx # cell type / label
29
  methscope deconv mixture.cg hg38_65celltypes.refx # cell-type proportions (NNLS)
30
  methscope upscale -o out.cg hg38_wg.updecx query.cg # genome-wide CpG upscaling
31
- methscope inspect hg38_sex.ubjx # framework, labels, features
32
  ```
33
 
 
 
 
 
 
 
 
34
  Small query `.cg` test fixtures (typed cells, a deconvolution mixture, an
35
  upscale input + truth) live in the GitHub repo
36
  [`zhou-lab/methscope_data`](https://github.com/zhou-lab/methscope_data) under
@@ -42,16 +49,85 @@ upscale input + truth) live in the GitHub repo
42
  |------|------|-----------|----------------|
43
  | `hg38_wg.updecx` | whole-genome CpG upscaling | `UPDEC2` | all 29,401,795 hg38 CpGs; the primary upscaler (2.8 GB) |
44
  | `hg38_10k1.updecx` | CpG upscaling (single block) | MLP decoder | block 10k1 (10,000 CpGs); small demo model |
45
- | `hg38_celltype.ubjx` | cell-type annotation | xgboost | 62 human cell types |
46
- | `mm10_celltype.ubjx` | cell-type annotation | xgboost | 41 mouse-brain cell types |
47
- | `hg38_sex.ubjx` | sex prediction | logistic | Female, Male (XCI `Xa_hi`/`Xa_lo` markers) |
48
  | `hg38_65celltypes.refx` | cell-type deconvolution (NNLS) | refx | 65 types = 58 Zhou + 7 Loyfer organ/blood; split MRMP, 15,300 patterns |
49
 
50
  `methscope inspect <model>` prints the exact framework, full label list, and (for
51
  linear models) per-feature weights. Classifiers carry a required framework `kind`
52
- mark (`xgboost` / `threshold` / `logistic`); `predict` rejects an unmarked
53
- bundle. Upscale decoders (`.updecx`) run via `upscale`, deconvolution references
54
- (`.refx`, `kind=refx`) via `deconv`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
 
56
  See the [methscope-cli documentation](https://zhou-lab.github.io/methscope-cli/)
57
  for the full command reference and runnable examples.
 
23
 
24
  ```sh
25
  # fetch one model (or --local-dir models to grab all)
26
+ hf download zhou-lab/methscope hg38_celltype.clfx --local-dir .
27
 
28
+ methscope classify query.cg hg38_celltype.clfx # cell type / label
29
  methscope deconv mixture.cg hg38_65celltypes.refx # cell-type proportions (NNLS)
30
  methscope upscale -o out.cg hg38_wg.updecx query.cg # genome-wide CpG upscaling
31
+ methscope inspect hg38_sex.clfx # framework, labels, features
32
  ```
33
 
34
+ The file extension names the model's **role** — `.clfx` classifier, `.refx`
35
+ deconvolution reference, `.updecx` upscale decoder. All three are the same
36
+ `MSBNDL1` container and are detected by magic, never by name. Classifiers used
37
+ to be `.ubjx`, which described a payload format (a UBJSON booster) rather than a
38
+ role and had already stopped being accurate for the non-booster frameworks;
39
+ `.ubjx` is still accepted everywhere and nothing needs renaming locally.
40
+
41
  Small query `.cg` test fixtures (typed cells, a deconvolution mixture, an
42
  upscale input + truth) live in the GitHub repo
43
  [`zhou-lab/methscope_data`](https://github.com/zhou-lab/methscope_data) under
 
49
  |------|------|-----------|----------------|
50
  | `hg38_wg.updecx` | whole-genome CpG upscaling | `UPDEC2` | all 29,401,795 hg38 CpGs; the primary upscaler (2.8 GB) |
51
  | `hg38_10k1.updecx` | CpG upscaling (single block) | MLP decoder | block 10k1 (10,000 CpGs); small demo model |
52
+ | `hg38_celltype.clfx` | cell-type annotation | `violation` | 33 human cell types; **no fitted parameter** — see below |
53
+ | `mm10_celltype.ubjx` | cell-type annotation (brain) | xgboost | 41 mouse-brain cell types; rename to `mm10_celltype_brain.clfx` pending a Liu 2021 rebuild |
54
+ | `hg38_sex.clfx` | sex prediction | logistic | Female, Male (XCI `Xa_hi`/`Xa_lo` markers) |
55
  | `hg38_65celltypes.refx` | cell-type deconvolution (NNLS) | refx | 65 types = 58 Zhou + 7 Loyfer organ/blood; split MRMP, 15,300 patterns |
56
 
57
  `methscope inspect <model>` prints the exact framework, full label list, and (for
58
  linear models) per-feature weights. Classifiers carry a required framework `kind`
59
+ mark (`xgboost` / `violation` / `threshold` / `logistic`); `classify` rejects an
60
+ unmarked bundle. Upscale decoders (`.updecx`) run via `upscale`, deconvolution
61
+ references (`.refx`, `kind=refx`) via `deconv`.
62
+
63
+ ## The `violation` framework
64
+
65
+ `hg38_celltype.clfx` has **no trained parameters at all**. Every MRMP
66
+ already carries a binstring — the methylation state each reference class takes
67
+ at that pattern — so the reference *is* a per-class prediction. The model just
68
+ asks which class the query contradicts least:
69
+
70
+ ```
71
+ E1 = patterns the class expects methylated; E0 = expects unmethylated
72
+ w_j = sqrt(n_cpg_j)
73
+
74
+ v1 = Σ_{j∈E1, observed} w_j·[β_j ≤ 0.5] / Σ_{j∈E1, observed} w_j
75
+ v0 = Σ_{j∈E0, observed} w_j·[β_j > 0.5] / Σ_{j∈E0, observed} w_j
76
+
77
+ predict argmin_class (v1 + v0), needing ≥20 observed patterns per side
78
+ ```
79
+
80
+ `confidence` is the **margin** to the runner-up, not a probability. It is
81
+ calibrated (accuracy 0.757 / 0.820 / 0.899 at margin ≥ 0.02 / 0.05 / 0.10) and,
82
+ unlike a softmax, it collapses toward zero when *no* class fits — which is how
83
+ the model signals that the query's true type is missing from the reference.
84
+ Records too sparse to clear the minimum are reported `NA` rather than guessed.
85
+
86
+ Held out **across cohorts** (each class's reference and its test samples come
87
+ from different studies), 113 donor-resolved pseudobulks at ≥100k covered CpGs:
88
+ **accuracy 0.842, macro-F1 0.853** — against 0.873 / 0.868 for an xgboost model
89
+ on the identical MRMP. It trades ~3 points of normal-tissue accuracy for
90
+ behaviour that holds up on tumours.
91
+
92
+ **Single-cell tumours**, where it earns that trade. Bian is split by anatomical
93
+ site because that is the whole point — a colorectal cancer cell sitting in liver
94
+ must still read as colon:
95
+
96
+ | cohort | GI fraction | top call |
97
+ |---|---|---|
98
+ | Bian 2018 CRC, **liver metastases** | **100.0%** | `Enterocyte.(Colon)` |
99
+ | Bian 2018 CRC, **lymph metastases** | **100.0%** | `Enterocyte.(Colon)` |
100
+ | Bian 2018 CRC, primaries (L/R colon, rectum) | 97.1–100.0% | `Enterocyte.(Colon)` |
101
+ | Bian 2018 adjacent normal (within-patient control) | 100.0% | `Enterocyte.(Colon)` |
102
+ | Gaiti 2019 CLL | — | `B.Cell` |
103
+ | Chaligne 2021 glioma | — | `Oligodendrocyte` |
104
+
105
+ Nothing in the reference anticipates the metastatic case, and no bulk cohort can
106
+ separate origin from site the way these cells do. It also resists the
107
+ mitotic-age confound that dominates trained models on this feature space: the
108
+ "most-hypomethylated-class sink" sending globally demethylated tumours to
109
+ `Acinar.(Pancreas)` drops from 30.0% of TCGA calls to 2.3%, with no
110
+ residualisation and no tumour data anywhere in its construction.
111
+
112
+ Accuracy is coverage-dependent: 0.163 below 8k covered CpGs, 0.719 at 8–32k,
113
+ plateauing near 0.85 above ~130k. **Do not use below ~30k covered CpGs.**
114
+
115
+ Limitations: `Macrophage` (0.27) and `Monocyte` (0.74) bleed into
116
+ `Dendritic.Cell` — the macrophage reference here is BLUEPRINT's, which is
117
+ monocyte-derived and differentiated *in vitro*, a poor match for tissue
118
+ macrophages. `T.Cell.CD8` leaks to `CD4` at 27%. Every remaining error is a
119
+ within-lineage confusion; none cross lineages. The atlas is also incomplete, and
120
+ a missing origin surfaces as a **low margin** rather than an error — glioma has
121
+ the lowest median margin of any cohort tested, because neither OPC nor astrocyte
122
+ is a class. Margins are not comparable between models with different class
123
+ counts, so recalibrate any threshold per model. For a bulk tumour, deconvolve
124
+ rather than classify: a classifier assigns one label to a mixture.
125
+
126
+ Rebuild from any MRMP artifact, with no training data, in about 7 seconds:
127
+
128
+ ```sh
129
+ methscope classify-train --framework violation -p 1000 -o out.clfx ref.mrmp
130
+ ```
131
 
132
  See the [methscope-cli documentation](https://zhou-lab.github.io/methscope-cli/)
133
  for the full command reference and runnable examples.
SHA256SUMS CHANGED
@@ -1,7 +1,7 @@
1
  8f7f2d6d42f64daaba5bf9cede5146fa52c0f62b5c76b3d5c6680c5c7554b1b7 hg38_10k1.updecx
2
  ce16678dd410c83e3df1c6f1c9b912a796f69c77722b28fc83c5690df69a6c03 hg38_65celltypes.refx
3
- e1f738290b05f824873b599894228a33b189ffbda0644ed2aad0e82e7768bc7c hg38_celltype.ubjx
4
- 3d1618f6ca24d9a9d5b0fe1806673540515e5f6e7d7950e7c8873a85bb5c742b hg38_sex.ubjx
5
  60c786aa383c27461e7a5de37d6b17d2e01b33c5f8a6553f3df7083035fac65a hg38_wg.updecx
6
  3bbdfeabbc59c2e5810eee06c07d24c8fc9826926dd59ddd167ff46b4cb028de mm10_celltype.ubjx
7
  f25cc5317a892105a121300fef009e29e96677f9a43fd02c3b47a59bf64cd482 mm10_wg.updecx
 
1
  8f7f2d6d42f64daaba5bf9cede5146fa52c0f62b5c76b3d5c6680c5c7554b1b7 hg38_10k1.updecx
2
  ce16678dd410c83e3df1c6f1c9b912a796f69c77722b28fc83c5690df69a6c03 hg38_65celltypes.refx
3
+ 00216ef333e3fede15b1bce1c820af23f2c0436b1c9d13b97132add311f17e05 hg38_celltype.clfx
4
+ 3d1618f6ca24d9a9d5b0fe1806673540515e5f6e7d7950e7c8873a85bb5c742b hg38_sex.clfx
5
  60c786aa383c27461e7a5de37d6b17d2e01b33c5f8a6553f3df7083035fac65a hg38_wg.updecx
6
  3bbdfeabbc59c2e5810eee06c07d24c8fc9826926dd59ddd167ff46b4cb028de mm10_celltype.ubjx
7
  f25cc5317a892105a121300fef009e29e96677f9a43fd02c3b47a59bf64cd482 mm10_wg.updecx
hg38_celltype.ubjx → hg38_celltype.clfx RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:e1f738290b05f824873b599894228a33b189ffbda0644ed2aad0e82e7768bc7c
3
- size 25661483
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:00216ef333e3fede15b1bce1c820af23f2c0436b1c9d13b97132add311f17e05
3
+ size 5738519
hg38_sex.ubjx → hg38_sex.clfx RENAMED
File without changes