hide-deconv 0.4.2__tar.gz → 0.4.4__tar.gz

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.
Files changed (69) hide show
  1. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/PKG-INFO +50 -31
  2. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/README.md +49 -30
  3. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/pyproject.toml +1 -1
  4. hide_deconv-0.4.4/src/hide_deconv/__init__.py +4 -0
  5. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/cli.py +24 -0
  6. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/cli_commands/__init__.py +2 -0
  7. hide_deconv-0.4.4/src/hide_deconv/cli_commands/example_command.py +76 -0
  8. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/cli_commands/help_command.py +1 -0
  9. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/cli_commands/simulate_command.py +0 -10
  10. hide_deconv-0.4.4/src/hide_deconv/example/__init__.py +3 -0
  11. hide_deconv-0.4.4/src/hide_deconv/example/generate_example.py +427 -0
  12. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/models/HIDE.py +24 -12
  13. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/pipelines/deconvolve_hide_pipeline.py +98 -13
  14. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/pipelines/lazy_deconvolution_pipeline.py +31 -16
  15. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/utils/mtx_utils.py +2 -2
  16. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/visualization/compositions.py +6 -4
  17. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/visualization/survival.py +3 -1
  18. hide_deconv-0.4.2/src/hide_deconv/__init__.py +0 -3
  19. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/LICENSE +0 -0
  20. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/cli_commands/analyze_command.py +0 -0
  21. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/cli_commands/anndata_command.py +0 -0
  22. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/cli_commands/bulk_command.py +0 -0
  23. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/cli_commands/cohort_command.py +0 -0
  24. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/cli_commands/config_command.py +0 -0
  25. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/cli_commands/deconvolve_command.py +0 -0
  26. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/cli_commands/download_command.py +0 -0
  27. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/cli_commands/preprocess_command.py +0 -0
  28. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/cli_commands/setup_command.py +0 -0
  29. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/cli_commands/train_command.py +0 -0
  30. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/config.py +0 -0
  31. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/constants/__init__.py +0 -0
  32. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/constants/messages.py +0 -0
  33. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/constants/misc.py +0 -0
  34. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/download/__init__.py +0 -0
  35. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/download/download_file.py +0 -0
  36. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/download/sc_repos.txt +0 -0
  37. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/lazy.py +0 -0
  38. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/models/__init__.py +0 -0
  39. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/pipelines/__init__.py +0 -0
  40. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/pipelines/anndata_preprocess_pipeline.py +0 -0
  41. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/pipelines/init_pipeline.py +0 -0
  42. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/pipelines/preprocess_pipeline.py +0 -0
  43. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/pipelines/training_pipeline.py +0 -0
  44. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/preprocessing/__init__.py +0 -0
  45. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/preprocessing/bulk_preprocessing.py +0 -0
  46. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/preprocessing/train_preprocessing.py +0 -0
  47. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/simulation/__init__.py +0 -0
  48. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/statistic/__init__.py +0 -0
  49. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/statistic/clustering.py +0 -0
  50. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/statistic/kruskal_wallis.py +0 -0
  51. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/statistic/mann_whitney_u.py +0 -0
  52. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/statistic/plsda.py +0 -0
  53. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/statistic/posthoc_dunn.py +0 -0
  54. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/statistic/pydeseq2.py +0 -0
  55. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/statistic/survival_analysis.py +0 -0
  56. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/utils/__init__.py +0 -0
  57. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/utils/anndata_utils.py +0 -0
  58. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/utils/cli_utils.py +0 -0
  59. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/utils/cohort_utils.py +0 -0
  60. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/utils/config_utils.py +0 -0
  61. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/utils/download_utils.py +0 -0
  62. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/utils/optimization_utils.py +0 -0
  63. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/utils/sample_sheet_utils.py +0 -0
  64. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/visualization/__init__.py +0 -0
  65. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/visualization/anndata.py +0 -0
  66. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/visualization/deg.py +0 -0
  67. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/visualization/heatmaps.py +0 -0
  68. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/visualization/loss.py +0 -0
  69. {hide_deconv-0.4.2 → hide_deconv-0.4.4}/src/hide_deconv/visualization/plsda.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hide-deconv
3
- Version: 0.4.2
3
+ Version: 0.4.4
4
4
  Summary: HIDE-Deconv - Hierarchical Cell Type Deconvolution
5
5
  License-Expression: MIT
6
6
  License-File: LICENSE
@@ -42,6 +42,10 @@ Description-Content-Type: text/markdown
42
42
 
43
43
  **A framework for characterizing cellular remodeling from bulk RNA-seq data through hierarchical cell-type deconvolution.**
44
44
 
45
+ > **Note:** HIDE-deconv is not the same method as our previously published
46
+ > [HIDE](https://academic.oup.com/bioinformatics/article/41/Supplement_1/i207/8199347) (Bioinformatics, 2025).
47
+ > HIDE-deconv uses a new model for hierarchical deconvolution that jointly optimizes all hierarchy levels.
48
+
45
49
  ---
46
50
  ![HIDE-Deconv Summary](https://github.com/dvoelkl/HIDE-deconv/blob/main/figures/HIDE-deconv-overview_extended.png)
47
51
  ---
@@ -73,21 +77,26 @@ As an additional evaluation on real world data, HIDE-deconv was benchmarked on t
73
77
  | MuSiC | 0.319 | 0.275 |
74
78
  | Scaden | 0.795 | 0.150 |
75
79
  | SCDC | 0.468 | 0.239 |
76
- | **HIDE-deconv (1)** | **0.934** | **0.094** |
77
- | **HIDE-deconv (2)** | **0.933** | **0.094** |
80
+ | **HIDE-deconv v0.1.10** | **0.926** | **0.098** |
81
+ | **HIDE-deconv v0.4.0** | **0.933** | **0.094** |
78
82
 
79
- HIDE-deconv (1) was trained and evaluated at the resolution of the cell types defined in the Hao single-cell reference, without specifying a hierarchy.
83
+ Both HIDE-deconv runs were trained and evaluated using a three-level cell-type hierarchy, analogous to the hierarchical aggregation used for the FACS benchmarking. HIDE-deconv v0.1.10 corresponds to the version used in the preprint.
80
84
 
81
- HIDE-deconv (2) was trained and evaluated using a three-level cell-type hierarchy, analogous to the hierarchical aggregation used for the FACS benchmarking.
85
+ HIDE-deconv was evaluated independently. Benchmark scripts and results for further configurations, including runs without a cell-type hierarchy, are available in the [benchmark repository](https://github.com/dvoelkl/HIDE-Deconv-Benchmarks). Results for the other methods are taken from [Dietrich et al. (2026)](https://doi.org/10.1186/s13059-026-03955-w).
82
86
 
83
- HIDE-deconv was evaluated independently ([Benchmark scripts](https://github.com/dvoelkl/HIDE-Deconv-Benchmarks)). Results for the other methods are taken from [Dietrich et al. (2026)](https://doi.org/10.1186/s13059-026-03955-w)
84
87
 
85
88
 
89
+ ## Installation
86
90
 
91
+ **Installation with Bioconda**
87
92
 
93
+ [![install with bioconda](https://img.shields.io/badge/install%20with-bioconda-brightgreen.svg?style=flat)](http://bioconda.github.io/recipes/hide-deconv/README.html)
94
+ ```bash
95
+ conda install hide-deconv
96
+ ```
88
97
 
89
- ## Installation
90
98
 
99
+ **Installation with PIP**
91
100
  ```bash
92
101
  # Create and activate a new virtual environment (recommended)
93
102
  python3 -m venv .venv
@@ -140,6 +149,7 @@ This displays a short introduction to the command line interface and gives an ov
140
149
 
141
150
  ## Quick Deconvolution API Example
142
151
  HIDE-deconv contains a "lazy" API for users who want quick access to deconvolution.
152
+ Both API examples run on a synthetic example dataset, which can be created with `hide-deconv example` or `from hide_deconv import generate_example`.
143
153
 
144
154
  ```python
145
155
  import anndata as ad
@@ -149,7 +159,9 @@ from hide_deconv import deconvolution
149
159
  adata = ad.read_h5ad("single_cells.h5ad")
150
160
  bulk = pd.read_csv("bulk.csv", index_col=0) # genes x samples
151
161
 
152
- results = deconvolution(adata, bulk, celltype_cols=["cell_type", "major"]) # Two layer hierarchy
162
+ # Reduced settings for the example data. For real data we recommend the
163
+ # defaults of 5000 genes and at least 10000 training bulks.
164
+ results = deconvolution(adata, bulk, celltype_cols=["cell_type", "major"], n_genes=1000, n_train_bulks=5000) # Two layer hierarchy
153
165
  # results = deconvolution(adata, bulk, celltype_cols="major") # Deconvolution only on major level
154
166
 
155
167
  # results is a list of pandas DataFrames, one per hierarchy layer
@@ -165,34 +177,48 @@ For experienced users offers HIDE-deconv a highly customizable API, where they c
165
177
  import anndata as ad
166
178
  import pandas as pd
167
179
  import numpy as np
168
- from hide_deconv.preprocessing import create_reference, create_bulks
180
+ import scanpy as sc
181
+ from hide_deconv.preprocessing import create_reference, create_bulks, reduce_genes
169
182
  from hide_deconv.models import HIDE
170
- from hide_deconv.statistic import run_mann_whitney_u
183
+ from hide_deconv.statistic import run_kruskal_wallis
171
184
  from hide_deconv.preprocessing.bulk_preprocessing import get_domain_transfer_factor
172
185
  from hide_deconv.pipelines.deconvolve_hide_pipeline import normalize_bulk_to_cpm
173
186
 
174
187
  # 1. Load single-cell, bulk and sample sheet data
175
188
  adata = ad.read_h5ad("single_cells.h5ad")
176
189
  bulk = pd.read_csv("bulk.csv", index_col=0) # genes x samples
177
- sample_sheet = pd.read_csv("sample_sheet.csv", index_col=0)
190
+ sample_sheet = pd.read_csv("sample_sheet.csv") # sample IDs in column "SampleID"
191
+
192
+ # Calculate library sizes on the raw counts of the complete single-cell gene set
193
+ library_sizes = (
194
+ adata.obs.assign(library_size=np.asarray(adata.X.sum(axis=1)).ravel())
195
+ .groupby("cell_type")["library_size"]
196
+ .median()
197
+ )
198
+
199
+ # Normalize single cells on the complete gene set before simulating bulks
200
+ sc.pp.normalize_total(adata, target_sum=1e4)
178
201
 
179
- # The sample sheet index must contain the corresponding bulk sample IDs.
180
- sample_sheet = sample_sheet.reindex(bulk.columns)
202
+ # Use healthy samples as reference domain and deconvolve the remaining samples
203
+ healthy_ids = sample_sheet.loc[sample_sheet["disease"] == "healthy", "SampleID"]
181
204
  bulk = normalize_bulk_to_cpm(bulk)
182
- healthy_bulk = bulk.loc[:, sample_sheet["disease"] == "healthy"]
183
- bulk = bulk.loc[:, sample_sheet["disease"] != "healthy"]
205
+ healthy_bulk = bulk.loc[:, healthy_ids]
206
+ bulk = bulk.drop(columns=healthy_ids)
184
207
  common_genes = adata.var_names.intersection(bulk.index).intersection(healthy_bulk.index)
185
208
  adata = adata[:, common_genes].copy()
186
- healthy_bulk = healthy_bulk.loc[common_genes]
187
- bulk = bulk.loc[common_genes]
209
+
210
+ # Reduce to the most informative genes (for real data we recommend 5000 genes)
211
+ adata = reduce_genes(adata, 1000, ct_col="cell_type")
212
+ healthy_bulk = healthy_bulk.loc[adata.var_names]
213
+ bulk = bulk.loc[adata.var_names]
188
214
 
189
215
  # 2. Create reference profiles and hierarchy (single layer example)
190
216
  X_sub = create_reference(adata, celltype_col="cell_type")
191
217
  A_l = [pd.DataFrame(np.eye(X_sub.shape[1]), index=X_sub.columns, columns=X_sub.columns)]
192
218
  X_l = [X_sub]
193
219
 
194
- # 3. Simulate training bulks
195
- Y_train, C_train = create_bulks(adata, n_bulks=1000, n_cells_per_bulk=100, celltype_col="cell_type")
220
+ # 3. Simulate training bulks (for real data we recommend at least 10000 bulks)
221
+ Y_train, C_train = create_bulks(adata, n_bulks=5000, n_cells_per_bulk=100, celltype_col="cell_type")
196
222
 
197
223
  # 4. Initialize and train model
198
224
  hide = HIDE(X_l, A_l)
@@ -205,37 +231,30 @@ Y_domain, _ = create_bulks(
205
231
  n_cells_per_bulk=100,
206
232
  celltype_col="cell_type",
207
233
  )
208
- Y_domain = Y_domain.loc[common_genes]
209
234
  alpha = get_domain_transfer_factor(healthy_bulk, Y_domain)
210
235
  alpha_inv = (1 / alpha).replace([np.inf, -np.inf], 0).fillna(1.0)
211
236
  bulk = bulk.mul(alpha_inv, axis=0)
212
237
 
213
- # 6. Calculate library sizes on the complete single-cell gene set
214
- library_sizes = (
215
- adata.obs.assign(library_size=np.asarray(adata.X.sum(axis=1)).ravel())
216
- .groupby("cell_type")["library_size"]
217
- .median()
218
- )
219
-
220
- # 7. Deconvolution on the batch-corrected bulk data
238
+ # 6. Deconvolution on the batch-corrected bulk data
221
239
  results = hide.predict(
222
240
  bulk.loc[hide.gene_labels],
223
241
  norm=True,
224
242
  library_sizes=library_sizes,
225
243
  )["prediction"]
226
244
 
227
- # 8. Optional: Difference in composition analysis
228
- # diff = run_mann_whitney_u(results[0], sample_sheet, sample_id_col="SampleID", cohort_col="Cohort")
245
+ # 7. Optional: Difference in composition between medications
246
+ diff = run_kruskal_wallis(results[0], sample_sheet, sample_id_col="SampleID", cohort_col="medication")
229
247
  ```
230
248
 
231
249
  ---
232
250
 
251
+
233
252
  ## Citation
234
253
  If you use HIDE-deconv, please cite the following preprint.
235
254
 
236
255
  HIDE-Deconv: A hierarchical deconvolution framework for multiscale characterization of cellular remodeling
237
256
 
238
- Dennis Voelkl, Sarah Bolz, Austin Rayford, Thomas Stevenson, Thomas Sterr, Malte Mensching-Buhr, Nicole Seifert, Julia Arp, Cornelia Schuster, Jana Tausche, Laurenz Engel, Helena U. Zacharias, Michael Altenbuchinger, Franziska Görter
257
+ Dennis Voelkl, Sarah Bolz, Austin Rayford, Thomas Stevenson, Thomas Sterr, Malte Mensching-Buhr, Nicole Seifert, Julia Arp, Cornelia Schuster, Jana Tausche, Laurenz Engel, Helena U. Zacharias, Michael Altenbuchinger, Franziska Görtler
239
258
  bioRxiv 2026.08.24.746754; doi: https://doi.org/10.64898/2026.08.24.746754
240
259
 
241
260
  ---
@@ -2,6 +2,10 @@
2
2
 
3
3
  **A framework for characterizing cellular remodeling from bulk RNA-seq data through hierarchical cell-type deconvolution.**
4
4
 
5
+ > **Note:** HIDE-deconv is not the same method as our previously published
6
+ > [HIDE](https://academic.oup.com/bioinformatics/article/41/Supplement_1/i207/8199347) (Bioinformatics, 2025).
7
+ > HIDE-deconv uses a new model for hierarchical deconvolution that jointly optimizes all hierarchy levels.
8
+
5
9
  ---
6
10
  ![HIDE-Deconv Summary](https://github.com/dvoelkl/HIDE-deconv/blob/main/figures/HIDE-deconv-overview_extended.png)
7
11
  ---
@@ -33,21 +37,26 @@ As an additional evaluation on real world data, HIDE-deconv was benchmarked on t
33
37
  | MuSiC | 0.319 | 0.275 |
34
38
  | Scaden | 0.795 | 0.150 |
35
39
  | SCDC | 0.468 | 0.239 |
36
- | **HIDE-deconv (1)** | **0.934** | **0.094** |
37
- | **HIDE-deconv (2)** | **0.933** | **0.094** |
40
+ | **HIDE-deconv v0.1.10** | **0.926** | **0.098** |
41
+ | **HIDE-deconv v0.4.0** | **0.933** | **0.094** |
38
42
 
39
- HIDE-deconv (1) was trained and evaluated at the resolution of the cell types defined in the Hao single-cell reference, without specifying a hierarchy.
43
+ Both HIDE-deconv runs were trained and evaluated using a three-level cell-type hierarchy, analogous to the hierarchical aggregation used for the FACS benchmarking. HIDE-deconv v0.1.10 corresponds to the version used in the preprint.
40
44
 
41
- HIDE-deconv (2) was trained and evaluated using a three-level cell-type hierarchy, analogous to the hierarchical aggregation used for the FACS benchmarking.
45
+ HIDE-deconv was evaluated independently. Benchmark scripts and results for further configurations, including runs without a cell-type hierarchy, are available in the [benchmark repository](https://github.com/dvoelkl/HIDE-Deconv-Benchmarks). Results for the other methods are taken from [Dietrich et al. (2026)](https://doi.org/10.1186/s13059-026-03955-w).
42
46
 
43
- HIDE-deconv was evaluated independently ([Benchmark scripts](https://github.com/dvoelkl/HIDE-Deconv-Benchmarks)). Results for the other methods are taken from [Dietrich et al. (2026)](https://doi.org/10.1186/s13059-026-03955-w)
44
47
 
45
48
 
49
+ ## Installation
46
50
 
51
+ **Installation with Bioconda**
47
52
 
53
+ [![install with bioconda](https://img.shields.io/badge/install%20with-bioconda-brightgreen.svg?style=flat)](http://bioconda.github.io/recipes/hide-deconv/README.html)
54
+ ```bash
55
+ conda install hide-deconv
56
+ ```
48
57
 
49
- ## Installation
50
58
 
59
+ **Installation with PIP**
51
60
  ```bash
52
61
  # Create and activate a new virtual environment (recommended)
53
62
  python3 -m venv .venv
@@ -100,6 +109,7 @@ This displays a short introduction to the command line interface and gives an ov
100
109
 
101
110
  ## Quick Deconvolution API Example
102
111
  HIDE-deconv contains a "lazy" API for users who want quick access to deconvolution.
112
+ Both API examples run on a synthetic example dataset, which can be created with `hide-deconv example` or `from hide_deconv import generate_example`.
103
113
 
104
114
  ```python
105
115
  import anndata as ad
@@ -109,7 +119,9 @@ from hide_deconv import deconvolution
109
119
  adata = ad.read_h5ad("single_cells.h5ad")
110
120
  bulk = pd.read_csv("bulk.csv", index_col=0) # genes x samples
111
121
 
112
- results = deconvolution(adata, bulk, celltype_cols=["cell_type", "major"]) # Two layer hierarchy
122
+ # Reduced settings for the example data. For real data we recommend the
123
+ # defaults of 5000 genes and at least 10000 training bulks.
124
+ results = deconvolution(adata, bulk, celltype_cols=["cell_type", "major"], n_genes=1000, n_train_bulks=5000) # Two layer hierarchy
113
125
  # results = deconvolution(adata, bulk, celltype_cols="major") # Deconvolution only on major level
114
126
 
115
127
  # results is a list of pandas DataFrames, one per hierarchy layer
@@ -125,34 +137,48 @@ For experienced users offers HIDE-deconv a highly customizable API, where they c
125
137
  import anndata as ad
126
138
  import pandas as pd
127
139
  import numpy as np
128
- from hide_deconv.preprocessing import create_reference, create_bulks
140
+ import scanpy as sc
141
+ from hide_deconv.preprocessing import create_reference, create_bulks, reduce_genes
129
142
  from hide_deconv.models import HIDE
130
- from hide_deconv.statistic import run_mann_whitney_u
143
+ from hide_deconv.statistic import run_kruskal_wallis
131
144
  from hide_deconv.preprocessing.bulk_preprocessing import get_domain_transfer_factor
132
145
  from hide_deconv.pipelines.deconvolve_hide_pipeline import normalize_bulk_to_cpm
133
146
 
134
147
  # 1. Load single-cell, bulk and sample sheet data
135
148
  adata = ad.read_h5ad("single_cells.h5ad")
136
149
  bulk = pd.read_csv("bulk.csv", index_col=0) # genes x samples
137
- sample_sheet = pd.read_csv("sample_sheet.csv", index_col=0)
150
+ sample_sheet = pd.read_csv("sample_sheet.csv") # sample IDs in column "SampleID"
151
+
152
+ # Calculate library sizes on the raw counts of the complete single-cell gene set
153
+ library_sizes = (
154
+ adata.obs.assign(library_size=np.asarray(adata.X.sum(axis=1)).ravel())
155
+ .groupby("cell_type")["library_size"]
156
+ .median()
157
+ )
158
+
159
+ # Normalize single cells on the complete gene set before simulating bulks
160
+ sc.pp.normalize_total(adata, target_sum=1e4)
138
161
 
139
- # The sample sheet index must contain the corresponding bulk sample IDs.
140
- sample_sheet = sample_sheet.reindex(bulk.columns)
162
+ # Use healthy samples as reference domain and deconvolve the remaining samples
163
+ healthy_ids = sample_sheet.loc[sample_sheet["disease"] == "healthy", "SampleID"]
141
164
  bulk = normalize_bulk_to_cpm(bulk)
142
- healthy_bulk = bulk.loc[:, sample_sheet["disease"] == "healthy"]
143
- bulk = bulk.loc[:, sample_sheet["disease"] != "healthy"]
165
+ healthy_bulk = bulk.loc[:, healthy_ids]
166
+ bulk = bulk.drop(columns=healthy_ids)
144
167
  common_genes = adata.var_names.intersection(bulk.index).intersection(healthy_bulk.index)
145
168
  adata = adata[:, common_genes].copy()
146
- healthy_bulk = healthy_bulk.loc[common_genes]
147
- bulk = bulk.loc[common_genes]
169
+
170
+ # Reduce to the most informative genes (for real data we recommend 5000 genes)
171
+ adata = reduce_genes(adata, 1000, ct_col="cell_type")
172
+ healthy_bulk = healthy_bulk.loc[adata.var_names]
173
+ bulk = bulk.loc[adata.var_names]
148
174
 
149
175
  # 2. Create reference profiles and hierarchy (single layer example)
150
176
  X_sub = create_reference(adata, celltype_col="cell_type")
151
177
  A_l = [pd.DataFrame(np.eye(X_sub.shape[1]), index=X_sub.columns, columns=X_sub.columns)]
152
178
  X_l = [X_sub]
153
179
 
154
- # 3. Simulate training bulks
155
- Y_train, C_train = create_bulks(adata, n_bulks=1000, n_cells_per_bulk=100, celltype_col="cell_type")
180
+ # 3. Simulate training bulks (for real data we recommend at least 10000 bulks)
181
+ Y_train, C_train = create_bulks(adata, n_bulks=5000, n_cells_per_bulk=100, celltype_col="cell_type")
156
182
 
157
183
  # 4. Initialize and train model
158
184
  hide = HIDE(X_l, A_l)
@@ -165,37 +191,30 @@ Y_domain, _ = create_bulks(
165
191
  n_cells_per_bulk=100,
166
192
  celltype_col="cell_type",
167
193
  )
168
- Y_domain = Y_domain.loc[common_genes]
169
194
  alpha = get_domain_transfer_factor(healthy_bulk, Y_domain)
170
195
  alpha_inv = (1 / alpha).replace([np.inf, -np.inf], 0).fillna(1.0)
171
196
  bulk = bulk.mul(alpha_inv, axis=0)
172
197
 
173
- # 6. Calculate library sizes on the complete single-cell gene set
174
- library_sizes = (
175
- adata.obs.assign(library_size=np.asarray(adata.X.sum(axis=1)).ravel())
176
- .groupby("cell_type")["library_size"]
177
- .median()
178
- )
179
-
180
- # 7. Deconvolution on the batch-corrected bulk data
198
+ # 6. Deconvolution on the batch-corrected bulk data
181
199
  results = hide.predict(
182
200
  bulk.loc[hide.gene_labels],
183
201
  norm=True,
184
202
  library_sizes=library_sizes,
185
203
  )["prediction"]
186
204
 
187
- # 8. Optional: Difference in composition analysis
188
- # diff = run_mann_whitney_u(results[0], sample_sheet, sample_id_col="SampleID", cohort_col="Cohort")
205
+ # 7. Optional: Difference in composition between medications
206
+ diff = run_kruskal_wallis(results[0], sample_sheet, sample_id_col="SampleID", cohort_col="medication")
189
207
  ```
190
208
 
191
209
  ---
192
210
 
211
+
193
212
  ## Citation
194
213
  If you use HIDE-deconv, please cite the following preprint.
195
214
 
196
215
  HIDE-Deconv: A hierarchical deconvolution framework for multiscale characterization of cellular remodeling
197
216
 
198
- Dennis Voelkl, Sarah Bolz, Austin Rayford, Thomas Stevenson, Thomas Sterr, Malte Mensching-Buhr, Nicole Seifert, Julia Arp, Cornelia Schuster, Jana Tausche, Laurenz Engel, Helena U. Zacharias, Michael Altenbuchinger, Franziska Görter
217
+ Dennis Voelkl, Sarah Bolz, Austin Rayford, Thomas Stevenson, Thomas Sterr, Malte Mensching-Buhr, Nicole Seifert, Julia Arp, Cornelia Schuster, Jana Tausche, Laurenz Engel, Helena U. Zacharias, Michael Altenbuchinger, Franziska Görtler
199
218
  bioRxiv 2026.08.24.746754; doi: https://doi.org/10.64898/2026.08.24.746754
200
219
 
201
220
  ---
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "hide-deconv"
3
- version = "0.4.2"
3
+ version = "0.4.4"
4
4
  description = "HIDE-Deconv - Hierarchical Cell Type Deconvolution"
5
5
  authors = [
6
6
  {name = "Dennis Voelkl",email = "dennis.k.volkl@uib.no"},
@@ -0,0 +1,4 @@
1
+ from .lazy import deconvolution
2
+ from .example import generate_example
3
+
4
+ __all__ = ["deconvolution", "generate_example"]
@@ -934,6 +934,30 @@ def cli_download() -> None:
934
934
  # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
935
935
 
936
936
 
937
+ @cli.command("example")
938
+ @click.option(
939
+ "--out",
940
+ "-o",
941
+ "out_path",
942
+ default=None,
943
+ show_default=False,
944
+ type=click.Path(
945
+ exists=True, file_okay=False, dir_okay=True, writable=True, path_type=Path
946
+ ),
947
+ help="Path where the example AnnData file, bulk and sample sheet will be stored.",
948
+ )
949
+ def cli_example(out_path: Path | None = None) -> None:
950
+ """
951
+ Generate a synthetic example dataset (AnnData file, bulk and sample sheet) to test HIDE-Deconv.
952
+ """
953
+ from .cli_commands import create_example_data
954
+
955
+ create_example_data(out_path)
956
+
957
+
958
+ # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
959
+
960
+
937
961
  @cli_anndata.command("preprocess")
938
962
  def cli_anndata_preprocess() -> None:
939
963
  """
@@ -20,6 +20,7 @@ from .analyze_command import (
20
20
  create_celltype_scatter_plot,
21
21
  )
22
22
  from .download_command import download_single_cells
23
+ from .example_command import create_example_data
23
24
  from .anndata_command import (
24
25
  preprocess_anndata,
25
26
  inspect_anndata,
@@ -60,6 +61,7 @@ __all__ = [
60
61
  "create_pca_plot",
61
62
  "create_plsda_plot",
62
63
  "download_single_cells",
64
+ "create_example_data",
63
65
  "preprocess_anndata",
64
66
  "survival_analysis",
65
67
  "create_umap_plot",
@@ -0,0 +1,76 @@
1
+ """
2
+ =====================================================
3
+ ViewModel functions for CLI example command
4
+ =====================================================
5
+ """
6
+
7
+ from pathlib import Path
8
+
9
+ from rich.console import Console
10
+
11
+ from InquirerPy import inquirer
12
+ from InquirerPy.validator import PathValidator
13
+
14
+ from ..constants import MSG_SUCCESS, MSG_FAILURE
15
+
16
+ # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17
+
18
+ console = Console()
19
+
20
+ # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21
+
22
+
23
+ def create_example_data(out_path: Path | None = None) -> int:
24
+ """
25
+ Generate a synthetic example dataset and store the AnnData file, bulk and sample sheet.
26
+
27
+ Parameters
28
+ ----------
29
+ out_path : Path | None = None
30
+ Folder, where the example files will be stored. If None, the user is prompted.
31
+
32
+ Returns
33
+ -------
34
+ int
35
+ MSG_SUCCESS if the files were created, MSG_FAILURE otherwise.
36
+ """
37
+
38
+ from ..example import generate_example
39
+
40
+ try:
41
+ if out_path is None:
42
+ out_path = inquirer.filepath(
43
+ message="Enter path, where the example data will be stored:",
44
+ default="./",
45
+ mandatory=True,
46
+ mandatory_message="A folder must be selected to store the example data.",
47
+ validate=PathValidator(
48
+ is_file=False, is_dir=True, message="Input is not a folder."
49
+ ),
50
+ ).execute()
51
+
52
+ out_path = Path(out_path).expanduser()
53
+
54
+ with console.status(
55
+ "[bold blue]Generating example data...[/bold blue]", spinner="dots"
56
+ ):
57
+ adata, bulk, sample_sheet = generate_example()
58
+
59
+ adata.write_h5ad(out_path / "single_cells.h5ad")
60
+ bulk.to_csv(out_path / "bulk.csv")
61
+ sample_sheet.to_csv(out_path / "sample_sheet.csv", index=False)
62
+
63
+ except Exception:
64
+ console.print_exception()
65
+ return MSG_FAILURE
66
+
67
+ console.print(f"[green]Example data stored in {out_path}[/green]")
68
+ console.print(
69
+ "[dim]single_cells.h5ad: cell type columns 'cell_type' (finest layer) and 'major'[/dim]"
70
+ )
71
+ console.print(
72
+ "[dim]sample_sheet.csv: sample ids in column 'SampleID', cohorts in 'disease' and 'medication', "
73
+ "survival in 'survival_time' and 'event'[/dim]"
74
+ )
75
+
76
+ return MSG_SUCCESS
@@ -72,6 +72,7 @@ def show_help():
72
72
  "[bold]hide-deconv cohort km[/bold] Plot a Kaplan Meier curve based on pure sample sheet information.\n"
73
73
  "\n"
74
74
  "[bold]hide-deconv download[/bold] Download example AnnData Single Cells\n"
75
+ "[bold]hide-deconv example[/bold] Generate synthetic example data to test HIDE-Deconv\n"
75
76
  "[bold]hide-deconv simulate[/bold] Split AnnData in train and create test data\n"
76
77
  "\n"
77
78
  "[bold]hide-deconv bulk pca[/bold] Plots bulk RNA-seq data as PCA plot\n"
@@ -17,17 +17,7 @@ from InquirerPy.validator import PathValidator
17
17
 
18
18
  from rich.console import Console
19
19
 
20
- """
21
- Planned implementations:
22
- - AnnData Train Test split
23
- - Interface to various scanpy function:
24
- - scanpy.pp.filter_cells ?
25
- - scanpy.pp.filter_genes
26
- -
27
- - Analysis functions, e.g.
28
- - https://pydeseq2.readthedocs.io/en/stable/
29
20
 
30
- """
31
21
  # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32
22
 
33
23
  console = Console()
@@ -0,0 +1,3 @@
1
+ from .generate_example import generate_example
2
+
3
+ __all__ = ["generate_example"]