codeconv 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,73 @@
1
+ {
2
+ "_comment": "Mouse HK values and engine_parameters are placeholders mirroring the human reference. Recalibrate from a mouse scRNA reference before publication-grade runs. The 'other' block is intentionally empty: users targeting non hs/mm organisms must supply their own hk_profiles and engine_parameters.",
3
+ "min_topic_percentage": 0.05,
4
+ "species_profiles": {
5
+ "hs": {
6
+ "noise_regex": "^MT-|^RP[SL][0-9]+|^LINC|^MIR|^AC[0-9]+",
7
+ "hk_profiles": {
8
+ "RPL19": 2.529822467672188,
9
+ "TUBB": 0.6653868555153559,
10
+ "EEF1G": 1.409845725236883,
11
+ "PPIA": 1.4689432838260164,
12
+ "GAPDH": 1.9870339974714675,
13
+ "ABCF1": 0.2683943094020617,
14
+ "SDHA": 0.22436799098809676,
15
+ "OAZ1": 1.5212192863178522,
16
+ "G6PD": 0.10922542882001043,
17
+ "ALAS1": 0.10135028595398016,
18
+ "GUSB": 0.1690932556829679,
19
+ "HPRT1": 0.18642984163014426,
20
+ "POLR2A": 0.36647764940764155,
21
+ "POLR1B": 0.040193901737717995,
22
+ "TBP": 0.060567363961918315
23
+ },
24
+ "qc_markers": [
25
+ "CD3E", "CD4", "CD8A", "MS4A1", "CD19", "PTPRC",
26
+ "HBB", "CD14", "FCGR3A", "CD34", "NCAM1", "JCHAIN",
27
+ "EPCAM", "KRT18", "COL1A1", "DCN", "PECAM1", "ERBB2"
28
+ ],
29
+ "engine_parameters": {
30
+ "mu": 5483.714684902277,
31
+ "phi": 0.7002926708915271
32
+ }
33
+ },
34
+ "mm": {
35
+ "noise_regex": "^mt-|^Rp[sl][0-9]+|^Gm[0-9]+|^Mir|^Rik$",
36
+ "hk_profiles": {
37
+ "Rpl19": 2.529822467672188,
38
+ "Tubb5": 0.6653868555153559,
39
+ "Eef1g": 1.409845725236883,
40
+ "Ppia": 1.4689432838260164,
41
+ "Gapdh": 1.9870339974714675,
42
+ "Abcf1": 0.2683943094020617,
43
+ "Sdha": 0.22436799098809676,
44
+ "Oaz1": 1.5212192863178522,
45
+ "G6pdx": 0.10922542882001043,
46
+ "Alas1": 0.10135028595398016,
47
+ "Gusb": 0.1690932556829679,
48
+ "Hprt": 0.18642984163014426,
49
+ "Polr2a": 0.36647764940764155,
50
+ "Polr1b": 0.040193901737717995,
51
+ "Tbp": 0.060567363961918315
52
+ },
53
+ "qc_markers": [
54
+ "Cd3e", "Cd4", "Cd8a", "Ms4a1", "Cd19", "Ptprc",
55
+ "Hbb-bs", "Cd14", "Fcgr3", "Cd34", "Ncam1", "Jchain",
56
+ "Epcam", "Krt18", "Col1a1", "Dcn", "Pecam1", "Erbb2"
57
+ ],
58
+ "engine_parameters": {
59
+ "mu": 5483.714684902277,
60
+ "phi": 0.7002926708915271
61
+ }
62
+ },
63
+ "other": {
64
+ "noise_regex": "",
65
+ "hk_profiles": {},
66
+ "qc_markers": [],
67
+ "engine_parameters": {
68
+ "mu": 5000.0,
69
+ "phi": 0.7
70
+ }
71
+ }
72
+ }
73
+ }
@@ -0,0 +1,220 @@
1
+ Metadata-Version: 2.4
2
+ Name: codeconv
3
+ Version: 1.0.0
4
+ Summary: Reference-free single-cell-resolution deconvolution of spot-based spatial transcriptomics
5
+ Author: Roman Perik-Zavodskii, Saleh Alrhmoun
6
+ Author-email: Olga Perik-Zavodskaia <perik.zavodskaia@gmail.com>, Sergey Sennikov <sennikov@niikim.ru>
7
+ Maintainer-email: Olga Perik-Zavodskaia <perik.zavodskaia@gmail.com>
8
+ License-Expression: MIT
9
+ Project-URL: Homepage, https://github.com/Perik-Zavodskii/CoexpressDeconvolve
10
+ Project-URL: Repository, https://github.com/Perik-Zavodskii/CoexpressDeconvolve
11
+ Project-URL: Publication, https://doi.org/10.1016/j.isci.2026.116824
12
+ Project-URL: Archive, https://doi.org/10.5281/zenodo.21860849
13
+ Project-URL: Issues, https://github.com/Perik-Zavodskii/CoexpressDeconvolve/issues
14
+ Keywords: spatial transcriptomics,deconvolution,single-cell,Visium,DBiT-seq,topic model,bioinformatics
15
+ Classifier: Development Status :: 4 - Beta
16
+ Classifier: Intended Audience :: Science/Research
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
25
+ Requires-Python: >=3.9
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ Requires-Dist: numpy>=1.21
29
+ Requires-Dist: pandas>=1.3
30
+ Requires-Dist: scipy>=1.7
31
+ Requires-Dist: scikit-learn>=1.0
32
+ Requires-Dist: matplotlib>=3.5
33
+ Requires-Dist: seaborn>=0.11
34
+ Requires-Dist: h5py>=3.1
35
+ Requires-Dist: tqdm>=4.62
36
+ Requires-Dist: umap-learn>=0.5.3
37
+ Provides-Extra: notebook
38
+ Requires-Dist: jupyter>=1.0; extra == "notebook"
39
+ Requires-Dist: ipywidgets>=8.0; extra == "notebook"
40
+ Provides-Extra: dev
41
+ Requires-Dist: pytest>=7.0; extra == "dev"
42
+ Requires-Dist: build>=1.0; extra == "dev"
43
+ Requires-Dist: twine>=4.0; extra == "dev"
44
+ Dynamic: license-file
45
+
46
+ # CoexpressDeconvolve
47
+
48
+ Spot-based spatial transcriptomics measures whole transcriptomes in place, but every spot pools
49
+ several cells, so a spot profile is a mixture rather than a cell. CoexpressDeconvolve resolves that
50
+ mixture into single-cell-like profiles, without needing a matched single-cell dataset to learn from.
51
+
52
+ The problem it addresses is that the usual route out of the mixture is a reference atlas, and a
53
+ reference is often unavailable, mismatched to the tissue, or missing the very populations that were
54
+ lost during dissociation. CoexpressDeconvolve works from the slide alone.
55
+
56
+ Three quantities carry the method. How many cells a spot captured is estimated from the
57
+ housekeeping-gene signal together with the total UMI count. Which expression programmes are present
58
+ is learned de novo from gene co-expression across the whole slide. How the spot's transcripts belong
59
+ to those cells follows from distributing its UMIs among them, conserving the per-spot total exactly:
60
+ the reconstructed cells of a spot add back up to the transcriptome measured there.
61
+
62
+ Each cell comes out with a whole transcriptome, absolute counts and a coordinate inside its parent
63
+ spot, written in the standard 10x SpaceRanger layout, so the result opens in Seurat or scanpy like
64
+ any other single-cell object.
65
+
66
+ Method and benchmarks: Perik-Zavodskaia, O., Perik-Zavodskii, R., Alrhmoun, S. & Sennikov, S.
67
+ *iScience* **29**, 116824 (2026). https://doi.org/10.1016/j.isci.2026.116824
68
+
69
+ ## Supported platforms
70
+
71
+ The platform is detected from the input layout and announced at load. Everything downstream is
72
+ platform-agnostic: Step 1 normalizes every input to counts, coordinates, a capture footprint and a
73
+ pitch.
74
+
75
+ | Platform | Capture unit | Pitch | Layout expected | Histology |
76
+ |---|---|---|---|---|
77
+ | **10x Visium** (any capture area) | 55 µm | 100 µm | SpaceRanger: `filtered_feature_bc_matrix.h5` (or the `.mtx` folder) + `spatial/` | yes |
78
+ | **DBiT-seq** | 10 / 25 / 50 µm | 2 × channel width | one count table on the 50 × 50 grid, labels `AxB` | no |
79
+
80
+ The DBiT-seq channel width is read from the sample name when it carries one (`GSM4189611_50t` -> 50 µm),
81
+ and the pitch is twice the width. Platforms that ship no tissue image get a black placeholder canvas
82
+ sized to the capture grid, with synthesized scale factors, so `Seurat::Load10X_Spatial()` and every
83
+ spatial plot still work.
84
+
85
+ Capture units at or below the size of one cell are out of scope: there is nothing to deconvolve, and
86
+ segmentation rather than a mixture model is the right step there.
87
+
88
+ ## Installation
89
+
90
+ ```bash
91
+ pip install codeconv
92
+ ```
93
+
94
+ Human (`hs`) and mouse (`mm`) species profiles are built into the module, so nothing else has to be
95
+ downloaded to get started.
96
+
97
+ ## Usage
98
+
99
+ ```python
100
+ import codeconv
101
+ codeconv.set_seed(42)
102
+
103
+ spatial_path = "./Glioblastoma"
104
+ output_folder = "."
105
+ species = "hs" # "hs" | "mm" | anything in your config
106
+
107
+ slices = codeconv.step1_acquisition_and_anchoring(spatial_path)
108
+ slices = codeconv.step2_estimate_cell_density(slices, species=species,
109
+ min_umi=900, anchor_mean_factor=0.7)
110
+ odg_pack = codeconv.step3_feature_selection(slices, species=species, n_odg=3000)
111
+ manifold = codeconv.step4_gene_manifold(slices, odg_pack, n_components=30)
112
+
113
+ ksweep = codeconv.step5_ksweep(odg_pack, min_k=3, max_k=15)
114
+ print(ksweep.summary()) # per-K perplexity, rare topics, which K are in the low band
115
+
116
+ model = codeconv.step6_final_deconvolution(slices, odg_pack, manifold,
117
+ n_topics=codeconv.recommended_K, # or your own K
118
+ k_neighbors=3)
119
+ cells = codeconv.step7_sampling_engine(slices, model, species=species)
120
+ codeconv.step8_geometry_and_placement(cells, slices)
121
+ codeconv.step9_export_results(cells, slices, output_folder, interaction_range_um=50.0)
122
+ ```
123
+
124
+ ### Several slices at once
125
+
126
+ Pass a dict instead of a string. Topics are aligned across slices, so the reconstructed cell types
127
+ are comparable between samples:
128
+
129
+ ```python
130
+ spatial_path = {"sample_A": "./A", "sample_B": "./B"}
131
+ ```
132
+
133
+ Per-slice parameters (`min_umi`, `anchor_mean_factor`, `low_slice_quality`) take either a scalar,
134
+ broadcast to every slice, or a dict keyed by slice name:
135
+
136
+ ```python
137
+ slices = codeconv.step2_estimate_cell_density(
138
+ slices, species="hs",
139
+ min_umi={"sample_A": 900, "sample_B": 1200},
140
+ anchor_mean_factor=0.7,
141
+ )
142
+ ```
143
+
144
+ A list of paths also works, with slice names taken from the folder names.
145
+
146
+ ### Choosing K automatically
147
+
148
+ The number of topics used to be a visual judgement call. It no longer is:
149
+
150
+ ```python
151
+ ksweep = codeconv.step5_ksweep(odg_pack, min_k=3, max_k=15) # prints the recommendation
152
+ ```
153
+
154
+ The default rule keeps every K whose held-out perplexity lands in the best 5% of the sweep by rank
155
+ and returns the **largest** of them, which is the highest K still in the low-perplexity regime. That
156
+ is deliberate: because CoexpressDeconvolve returns individual cells rather than fractions, a rare
157
+ topic is a minor cell population worth recovering, not evidence of over-splitting. Alternatives:
158
+
159
+ ```python
160
+ codeconv.recommend_k(ksweep.perplexity['Glioblastoma'], rule="relative_tolerance", tol=0.01)
161
+ codeconv.recommend_k(ksweep.perplexity['Glioblastoma'], rule="lowest_perplexity")
162
+ ```
163
+
164
+ A recommendation landing on `max_k` means perplexity had not turned back up yet and the sweep is too
165
+ narrow; you get a warning. Pass `n_topics=` to record a manual choice, and it is drawn on the plot
166
+ next to the automatic one.
167
+
168
+ ### The 9 steps
169
+
170
+ 1. **Acquisition** - detect the platform, load counts and coordinates, per-spot UMI QC.
171
+ 2. **Density** - cells per spot from a hybrid housekeeping/UMI calibration. `low_slice_quality=True`
172
+ enforces a floor of one cell on every spot passing the UMI gate.
173
+ 3. **Feature selection** - noise-gene regex, presence filter, overdispersed genes from the
174
+ mean-variance trend.
175
+ 4. **Manifold** - joint gene co-expression topology via ICA + UMAP.
176
+ 5. **K-sweep** - held-out perplexity across K, rare-topic counts, automatic recommendation.
177
+ 6. **Deconvolution** - per-slice LDA, Hungarian topic alignment across slices, mean-consensus beta,
178
+ per-slice theta refit against the frozen consensus, projection onto each slice's full gene list.
179
+ 7. **Sampling** - discrete cells drawn per spot; per-spot UMI totals are conserved exactly.
180
+ 8. **Placement** - cells positioned inside their parent spot footprint by Vogel packing.
181
+ 9. **Export** - 10x layout under `output_folder/slice_<name>/deconvolved/`, one folder per slice.
182
+
183
+ ## Downstream analysis
184
+
185
+ Each slice exports a `filtered_feature_bc_matrix.h5` and a `spatial/` folder. From there the
186
+ reconstruction is an ordinary single-cell spatial object and goes wherever such objects go:
187
+
188
+ ```r
189
+ library(Seurat)
190
+ seurat_obj <- Load10X_Spatial("./slice_Glioblastoma/deconvolved")
191
+ ```
192
+
193
+ ```python
194
+ import scanpy as sc
195
+ adata = sc.read_visium("./slice_Glioblastoma/deconvolved")
196
+ ```
197
+
198
+ Clustering, annotation, trajectory inference, cell-cell communication - anything that takes a
199
+ single-cell object works, with no adapters. `Seurat Spatial.ipynb` in the repository is a worked
200
+ example. Topics are aligned across slices, so cluster comparison between samples is meaningful.
201
+
202
+ ## Citation
203
+
204
+ ```bibtex
205
+ @article{PerikZavodskaia2026CoexpressDeconvolve,
206
+ title = {CoexpressDeconvolve enables reference-free single-cell-resolution
207
+ deconvolution from spot-based spatial transcriptomics},
208
+ author = {Perik-Zavodskaia, Olga and Perik-Zavodskii, Roman and
209
+ Alrhmoun, Saleh and Sennikov, Sergey},
210
+ journal = {iScience},
211
+ volume = {29},
212
+ pages = {116824},
213
+ year = {2026},
214
+ doi = {10.1016/j.isci.2026.116824}
215
+ }
216
+ ```
217
+
218
+ ## License
219
+
220
+ MIT, see `LICENSE`.
@@ -0,0 +1,7 @@
1
+ codeconv.py,sha256=kO9IDnBSXITRH2_XzWqBq4YM_jomGgJlJWinrCW4vP8,143440
2
+ codeconv-1.0.0.data/data/share/codeconv/codeconv_config.json,sha256=j-8N0bD2WvV-Y2n-yfO5ewG7Bw2Cs13MVvyyKt4qMhs,2998
3
+ codeconv-1.0.0.dist-info/licenses/LICENSE,sha256=9bFAnlFtue0S42EAu1bwmLIdhyGYIvexRTXksl_c5Ug,1078
4
+ codeconv-1.0.0.dist-info/METADATA,sha256=L1AexHUOnF6tVKTqe2cl89tz51XO-uWaJQwQ3XZ0qs0,9764
5
+ codeconv-1.0.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
6
+ codeconv-1.0.0.dist-info/top_level.txt,sha256=ZJaJH6-gaqbopn1qWSSOEvaNT8GVdDkXDlZlPdqy_98,9
7
+ codeconv-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Roman Perik-Zavodskii
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ codeconv