hide-deconv 0.1.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.
- hide_deconv/__init__.py +0 -0
- hide_deconv/cli.py +592 -0
- hide_deconv/cli_commands/__init__.py +36 -0
- hide_deconv/cli_commands/analyze_command.py +601 -0
- hide_deconv/cli_commands/anndata_command.py +205 -0
- hide_deconv/cli_commands/config_command.py +175 -0
- hide_deconv/cli_commands/deconvolve_command.py +139 -0
- hide_deconv/cli_commands/download_command.py +72 -0
- hide_deconv/cli_commands/help_command.py +69 -0
- hide_deconv/cli_commands/preprocess_command.py +46 -0
- hide_deconv/cli_commands/setup_command.py +241 -0
- hide_deconv/cli_commands/simulate_command.py +154 -0
- hide_deconv/cli_commands/train_command.py +29 -0
- hide_deconv/config.py +106 -0
- hide_deconv/constants/__init__.py +29 -0
- hide_deconv/constants/messages.py +18 -0
- hide_deconv/constants/misc.py +9 -0
- hide_deconv/download/__init__.py +3 -0
- hide_deconv/download/download_file.py +60 -0
- hide_deconv/download/sc_repos.txt +11 -0
- hide_deconv/models/HIDE.py +222 -0
- hide_deconv/models/__init__.py +3 -0
- hide_deconv/pipelines/__init__.py +14 -0
- hide_deconv/pipelines/anndata_preprocess_pipeline.py +117 -0
- hide_deconv/pipelines/deconvolve_hide_pipeline.py +113 -0
- hide_deconv/pipelines/init_pipeline.py +80 -0
- hide_deconv/pipelines/preprocess_pipeline.py +124 -0
- hide_deconv/pipelines/training_pipeline.py +68 -0
- hide_deconv/preprocessing/__init__.py +21 -0
- hide_deconv/preprocessing/bulk_preprocessing.py +69 -0
- hide_deconv/preprocessing/train_preprocessing.py +350 -0
- hide_deconv/simulation/__init__.py +1 -0
- hide_deconv/statistic/__init__.py +14 -0
- hide_deconv/statistic/kruskal_wallis.py +86 -0
- hide_deconv/statistic/mann_whitney_u.py +141 -0
- hide_deconv/statistic/posthoc_dunn.py +129 -0
- hide_deconv/statistic/survival_analysis.py +207 -0
- hide_deconv/utils/__init__.py +21 -0
- hide_deconv/utils/cli_utils.py +330 -0
- hide_deconv/utils/config_utils.py +11 -0
- hide_deconv/utils/download_utils.py +47 -0
- hide_deconv/utils/optimization_utils.py +5 -0
- hide_deconv/utils/sample_sheet_utils.py +18 -0
- hide_deconv/visualization/__init__.py +5 -0
- hide_deconv/visualization/compositions.py +189 -0
- hide_deconv/visualization/loss.py +48 -0
- hide_deconv/visualization/survival.py +220 -0
- hide_deconv-0.1.0.dist-info/METADATA +165 -0
- hide_deconv-0.1.0.dist-info/RECORD +52 -0
- hide_deconv-0.1.0.dist-info/WHEEL +4 -0
- hide_deconv-0.1.0.dist-info/entry_points.txt +3 -0
- hide_deconv-0.1.0.dist-info/licenses/LICENSE +21 -0
hide_deconv/__init__.py
ADDED
|
File without changes
|
hide_deconv/cli.py
ADDED
|
@@ -0,0 +1,592 @@
|
|
|
1
|
+
"""
|
|
2
|
+
=====================================================
|
|
3
|
+
Commandline interface for executing pipelines
|
|
4
|
+
without coding
|
|
5
|
+
=====================================================
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
import click
|
|
10
|
+
|
|
11
|
+
from rich.console import Console
|
|
12
|
+
from rich.panel import Panel
|
|
13
|
+
from rich.prompt import Confirm
|
|
14
|
+
|
|
15
|
+
from .constants import MSG_SUCCESS, MSG_FAILURE, MSG_USER_ABORT
|
|
16
|
+
from .utils import assert_init, assert_preprocessed, assert_trained
|
|
17
|
+
from .cli_commands import (
|
|
18
|
+
setup_config,
|
|
19
|
+
show_config,
|
|
20
|
+
preprocess,
|
|
21
|
+
setup_project,
|
|
22
|
+
train_model,
|
|
23
|
+
show_help,
|
|
24
|
+
deconvolve_hide,
|
|
25
|
+
deconvolve_command,
|
|
26
|
+
create_simulation,
|
|
27
|
+
analyze_differences,
|
|
28
|
+
benchmark_result,
|
|
29
|
+
create_pca_plot,
|
|
30
|
+
download_single_cells,
|
|
31
|
+
preprocess_anndata,
|
|
32
|
+
survival_analysis,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
36
|
+
|
|
37
|
+
console = Console()
|
|
38
|
+
|
|
39
|
+
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@click.group(invoke_without_command=True)
|
|
43
|
+
@click.pass_context
|
|
44
|
+
def cli(ctx: click.Context) -> None:
|
|
45
|
+
"""
|
|
46
|
+
HIDE-Deconv command line interface entry point.
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
if ctx.invoked_subcommand is None:
|
|
50
|
+
console.print(
|
|
51
|
+
Panel.fit(
|
|
52
|
+
"Interactive command line tool and python package for hierarchical deconvolution and analysis of bulk RNA-seq data.\n\n"
|
|
53
|
+
"---\n\n"
|
|
54
|
+
"[bold]Features[/bold]\n\n"
|
|
55
|
+
"- Designed for AnnData single cell datasets\n"
|
|
56
|
+
"- Open Source package, that can be run on safe servers\n"
|
|
57
|
+
"- Hierarchical cell type deconvolution for any number of cell type annotation layers\n"
|
|
58
|
+
"- Includes methods for post-deconvolution analysis\n"
|
|
59
|
+
"- Usable via command line interface and Python API\n"
|
|
60
|
+
"- Provides a guided workflow that allows users without programming experience to perform deconvolution on their own\n\n"
|
|
61
|
+
"[dim]Run [i]hide-deconv help[/i] to read the quickstart guide.[/dim]",
|
|
62
|
+
title="[bold]HIDE-Deconv[/bold]",
|
|
63
|
+
)
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
@cli.group("config")
|
|
71
|
+
def cli_config() -> None:
|
|
72
|
+
"""
|
|
73
|
+
Commands related to the HIDE-Deconv config.
|
|
74
|
+
"""
|
|
75
|
+
pass
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@cli.group("deconv", invoke_without_command=True)
|
|
82
|
+
@click.pass_context
|
|
83
|
+
@click.option(
|
|
84
|
+
"--path",
|
|
85
|
+
"-p",
|
|
86
|
+
"hidedeconv_path",
|
|
87
|
+
default=".",
|
|
88
|
+
show_default=True,
|
|
89
|
+
type=click.Path(
|
|
90
|
+
exists=True, file_okay=False, dir_okay=True, writable=True, path_type=Path
|
|
91
|
+
),
|
|
92
|
+
help="Path, where the HIDE-Deconv project structure is located.",
|
|
93
|
+
)
|
|
94
|
+
@click.option(
|
|
95
|
+
"--bulk",
|
|
96
|
+
"-b",
|
|
97
|
+
"alternative_bulk",
|
|
98
|
+
default=None,
|
|
99
|
+
show_default=False,
|
|
100
|
+
type=click.Path(exists=True, file_okay=True, dir_okay=False, writable=True),
|
|
101
|
+
help="Filepath of bulk to deconvolve. If not given, the bulk set in configuration is used",
|
|
102
|
+
)
|
|
103
|
+
@assert_trained
|
|
104
|
+
def cli_deconvolve(ctx, hidedeconv_path: Path, alternative_bulk=None) -> None:
|
|
105
|
+
"""
|
|
106
|
+
Commands related to deconvolution.
|
|
107
|
+
"""
|
|
108
|
+
|
|
109
|
+
# Only open deconvolution menu if no other submodel is invoked
|
|
110
|
+
if ctx.invoked_subcommand is None:
|
|
111
|
+
deconvolve_command(hidedeconv_path, alternative_bulk)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
@cli.group("analyze")
|
|
118
|
+
def cli_analyze() -> None:
|
|
119
|
+
"""
|
|
120
|
+
Commands related to the analysis of the deconvoluted results.
|
|
121
|
+
"""
|
|
122
|
+
pass
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
@cli.group("anndata")
|
|
129
|
+
def cli_anndata() -> None:
|
|
130
|
+
"""
|
|
131
|
+
Commands related to the processing of anndata files.
|
|
132
|
+
"""
|
|
133
|
+
pass
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
137
|
+
@cli.command("help")
|
|
138
|
+
def cli_help_command():
|
|
139
|
+
"""
|
|
140
|
+
Display a quick start guide for HIDE-Deconv.
|
|
141
|
+
"""
|
|
142
|
+
show_help()
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
@cli.command("run")
|
|
149
|
+
@click.option(
|
|
150
|
+
"--path",
|
|
151
|
+
"-p",
|
|
152
|
+
"hidedeconv_path",
|
|
153
|
+
default=".",
|
|
154
|
+
show_default=True,
|
|
155
|
+
type=click.Path(
|
|
156
|
+
exists=True, file_okay=False, dir_okay=True, writable=True, path_type=Path
|
|
157
|
+
),
|
|
158
|
+
help="Path, where the HIDE-Deconv project structure will be initialized.",
|
|
159
|
+
)
|
|
160
|
+
@click.option(
|
|
161
|
+
"--domain_transfer",
|
|
162
|
+
"-dt",
|
|
163
|
+
"fDomTransfer",
|
|
164
|
+
is_flag=False,
|
|
165
|
+
default=True,
|
|
166
|
+
show_default=True,
|
|
167
|
+
help="Account for domain transfer between single cell and bulks",
|
|
168
|
+
)
|
|
169
|
+
def cli_run_command(hidedeconv_path: Path, fAdv=False, fDomTransfer=True) -> int:
|
|
170
|
+
"""
|
|
171
|
+
Complete walkthrough of the standard deconvolution process.
|
|
172
|
+
Executes all commands necessary from starting a project until the final deconvolution.
|
|
173
|
+
|
|
174
|
+
Note: This is not an automation command, as constant user input is necessary.
|
|
175
|
+
"""
|
|
176
|
+
|
|
177
|
+
hidedeconv_path = hidedeconv_path.expanduser().resolve()
|
|
178
|
+
|
|
179
|
+
console.print(
|
|
180
|
+
Panel.fit(
|
|
181
|
+
f"[bold]HIDE-Deconv[/bold]\nProject Path: [cyan]{hidedeconv_path}[/cyan]",
|
|
182
|
+
border_style="blue",
|
|
183
|
+
)
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
# Setup folder structure
|
|
187
|
+
ret = setup_project(hidedeconv_path, fAdv)
|
|
188
|
+
if ret == MSG_FAILURE:
|
|
189
|
+
console.print("[red]Run failed.[/red]")
|
|
190
|
+
console.print_exception()
|
|
191
|
+
return MSG_FAILURE
|
|
192
|
+
elif ret == MSG_USER_ABORT:
|
|
193
|
+
console.print("[red]Run aborted.[/red]")
|
|
194
|
+
return MSG_FAILURE
|
|
195
|
+
|
|
196
|
+
if Confirm.ask("Run preprocessing now?", default=True):
|
|
197
|
+
preprocess(hidedeconv_path, fDomTransfer)
|
|
198
|
+
console.print("[green]Preprocessing completed successfully.[/green]")
|
|
199
|
+
|
|
200
|
+
if Confirm.ask("Train model now?", default=True):
|
|
201
|
+
train_model(hidedeconv_path)
|
|
202
|
+
console.print("[green]Model trained successfully.[/green]")
|
|
203
|
+
if Confirm.ask(
|
|
204
|
+
"Choose deconvolution model and deconvolve now?", default=True
|
|
205
|
+
):
|
|
206
|
+
deconvolve_command(hidedeconv_path, None)
|
|
207
|
+
else:
|
|
208
|
+
console.print("[dim]Next step [i]hide-deconv deconv[/i].[/dim]")
|
|
209
|
+
else:
|
|
210
|
+
console.print("[dim]Next step [i]hide-deconv train[/i].[/dim]")
|
|
211
|
+
else:
|
|
212
|
+
console.print("[dim]Next step [i]hide-deconv preprocess[/i].[/dim]")
|
|
213
|
+
|
|
214
|
+
return MSG_SUCCESS
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
@cli.command("init")
|
|
221
|
+
@click.option(
|
|
222
|
+
"--path",
|
|
223
|
+
"-p",
|
|
224
|
+
"hidedeconv_path",
|
|
225
|
+
default=".",
|
|
226
|
+
show_default=True,
|
|
227
|
+
type=click.Path(
|
|
228
|
+
exists=True, file_okay=False, dir_okay=True, writable=True, path_type=Path
|
|
229
|
+
),
|
|
230
|
+
help="Path, where the HIDE-deconv project structure will be initialized.",
|
|
231
|
+
)
|
|
232
|
+
def cli_init_command(hidedeconv_path: Path, fAdv=False, fDomTransfer=True) -> int:
|
|
233
|
+
"""
|
|
234
|
+
Initialize the HIDE-Deconv project structure at a given path.
|
|
235
|
+
"""
|
|
236
|
+
|
|
237
|
+
hidedeconv_path = hidedeconv_path.expanduser().resolve()
|
|
238
|
+
|
|
239
|
+
# Setup folder structure
|
|
240
|
+
if setup_project(hidedeconv_path, fAdv) != MSG_SUCCESS:
|
|
241
|
+
console.print("[red]Setup failed[/red]")
|
|
242
|
+
console.print_exception()
|
|
243
|
+
return MSG_FAILURE
|
|
244
|
+
|
|
245
|
+
return MSG_SUCCESS
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
@cli_config.command("edit")
|
|
252
|
+
@click.option(
|
|
253
|
+
"--path",
|
|
254
|
+
"-p",
|
|
255
|
+
"hidedeconv_path",
|
|
256
|
+
default=".",
|
|
257
|
+
show_default=True,
|
|
258
|
+
type=click.Path(
|
|
259
|
+
exists=True, file_okay=False, dir_okay=True, writable=True, path_type=Path
|
|
260
|
+
),
|
|
261
|
+
help="Path, where the HIDE-Deconv project structure is located.",
|
|
262
|
+
)
|
|
263
|
+
@assert_init
|
|
264
|
+
def cli_config_edit(hidedeconv_path: Path, fAdv: bool = False) -> None:
|
|
265
|
+
"""
|
|
266
|
+
Edits the parameters necessary for preprocessing.
|
|
267
|
+
"""
|
|
268
|
+
|
|
269
|
+
setup_config(hidedeconv_path, fAdv)
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
@cli.command("preprocess")
|
|
276
|
+
@click.option(
|
|
277
|
+
"--path",
|
|
278
|
+
"-p",
|
|
279
|
+
"hidedeconv_path",
|
|
280
|
+
default=".",
|
|
281
|
+
show_default=True,
|
|
282
|
+
type=click.Path(
|
|
283
|
+
exists=True, file_okay=False, dir_okay=True, writable=True, path_type=Path
|
|
284
|
+
),
|
|
285
|
+
help="Path, where the HIDE-Deconv project structure is located.",
|
|
286
|
+
)
|
|
287
|
+
@click.option(
|
|
288
|
+
"--domain_transfer",
|
|
289
|
+
"-dt",
|
|
290
|
+
"fDomTransfer",
|
|
291
|
+
is_flag=True,
|
|
292
|
+
default=True,
|
|
293
|
+
show_default=True,
|
|
294
|
+
help="Account for domain transfer between single cell and bulks",
|
|
295
|
+
)
|
|
296
|
+
@assert_init
|
|
297
|
+
def cli_preprocess(hidedeconv_path: Path, fDomTransfer) -> None:
|
|
298
|
+
"""
|
|
299
|
+
Run preprocessing for HIDE-Deconv by aligning genes between single-cell and bulk data,
|
|
300
|
+
creating reference/hierarchy matrices, generating training bulks and optionally
|
|
301
|
+
accounting for domain transfer.
|
|
302
|
+
"""
|
|
303
|
+
|
|
304
|
+
preprocess(hidedeconv_path, fDomTransfer)
|
|
305
|
+
console.print("[green]Preprocessing completed successfully[/green]")
|
|
306
|
+
|
|
307
|
+
if Confirm.ask("Train model now?", default=True):
|
|
308
|
+
train_model(hidedeconv_path)
|
|
309
|
+
console.print("[green]Model trained successfully.[/green]")
|
|
310
|
+
else:
|
|
311
|
+
console.print("[dim]Next step [i]hide-deconv train[/i][/dim]")
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
@cli.command("train")
|
|
318
|
+
@click.option(
|
|
319
|
+
"--path",
|
|
320
|
+
"-p",
|
|
321
|
+
"hidedeconv_path",
|
|
322
|
+
default=".",
|
|
323
|
+
show_default=True,
|
|
324
|
+
type=click.Path(
|
|
325
|
+
exists=True, file_okay=False, dir_okay=True, writable=True, path_type=Path
|
|
326
|
+
),
|
|
327
|
+
help="Path, where the HIDE-Deconv project structure is located.",
|
|
328
|
+
)
|
|
329
|
+
@assert_preprocessed
|
|
330
|
+
def cli_train(hidedeconv_path: Path) -> None:
|
|
331
|
+
"""
|
|
332
|
+
Train the model.
|
|
333
|
+
"""
|
|
334
|
+
train_model(hidedeconv_path)
|
|
335
|
+
|
|
336
|
+
console.print("[green]Model trained successfully.[/green]")
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
@cli_config.command("show")
|
|
343
|
+
@click.option(
|
|
344
|
+
"--path",
|
|
345
|
+
"-p",
|
|
346
|
+
"hidedeconv_path",
|
|
347
|
+
default=".",
|
|
348
|
+
show_default=True,
|
|
349
|
+
type=click.Path(
|
|
350
|
+
exists=True, file_okay=False, dir_okay=True, writable=True, path_type=Path
|
|
351
|
+
),
|
|
352
|
+
help="Path, where the HIDE-Deconv project structure is located.",
|
|
353
|
+
)
|
|
354
|
+
@assert_init
|
|
355
|
+
def cli_config_show(hidedeconv_path: Path) -> None:
|
|
356
|
+
"""
|
|
357
|
+
Displays the current HIDE-Deconv configuration.
|
|
358
|
+
"""
|
|
359
|
+
show_config(hidedeconv_path)
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
@cli_deconvolve.command("hide")
|
|
366
|
+
@click.option(
|
|
367
|
+
"--path",
|
|
368
|
+
"-p",
|
|
369
|
+
"hidedeconv_path",
|
|
370
|
+
default=".",
|
|
371
|
+
show_default=True,
|
|
372
|
+
type=click.Path(
|
|
373
|
+
exists=True, file_okay=False, dir_okay=True, writable=True, path_type=Path
|
|
374
|
+
),
|
|
375
|
+
help="Path, where the HIDE-Deconv project structure is located.",
|
|
376
|
+
)
|
|
377
|
+
@click.option(
|
|
378
|
+
"--bulk",
|
|
379
|
+
"-b",
|
|
380
|
+
"alternative_bulk",
|
|
381
|
+
default=None,
|
|
382
|
+
show_default=False,
|
|
383
|
+
type=click.Path(exists=True, file_okay=True, dir_okay=False, writable=True),
|
|
384
|
+
help="Filepath of bulk to deconvolve. If not given, the bulk set in configuration is used",
|
|
385
|
+
)
|
|
386
|
+
@assert_trained
|
|
387
|
+
def cli_deconv_hide(hidedeconv_path: Path, alternative_bulk=None) -> None:
|
|
388
|
+
"""
|
|
389
|
+
Runs the deconvolution with HIDE.
|
|
390
|
+
"""
|
|
391
|
+
|
|
392
|
+
deconvolve_hide(hidedeconv_path, alternative_bulk)
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
@cli.command("simulate")
|
|
399
|
+
@click.option(
|
|
400
|
+
"--ad_path",
|
|
401
|
+
"-ap",
|
|
402
|
+
"ad_path",
|
|
403
|
+
default=None,
|
|
404
|
+
show_default=False,
|
|
405
|
+
type=click.Path(
|
|
406
|
+
exists=True, file_okay=True, dir_okay=False, writable=True, path_type=Path
|
|
407
|
+
),
|
|
408
|
+
help="Path to the AnnData file.",
|
|
409
|
+
)
|
|
410
|
+
@click.option(
|
|
411
|
+
"--out",
|
|
412
|
+
"-o",
|
|
413
|
+
"out_path",
|
|
414
|
+
default=None,
|
|
415
|
+
show_default=False,
|
|
416
|
+
type=click.Path(
|
|
417
|
+
exists=True, file_okay=False, dir_okay=True, writable=True, path_type=Path
|
|
418
|
+
),
|
|
419
|
+
help="Path where created anndata and bulk files will be stored.",
|
|
420
|
+
)
|
|
421
|
+
@click.option(
|
|
422
|
+
"--train_frac",
|
|
423
|
+
"-tf",
|
|
424
|
+
"train_frac",
|
|
425
|
+
default=None,
|
|
426
|
+
show_default=False,
|
|
427
|
+
type=click.FLOAT,
|
|
428
|
+
help="Percentage of all cells used for training data.",
|
|
429
|
+
)
|
|
430
|
+
@click.option(
|
|
431
|
+
"--n_bulks",
|
|
432
|
+
"-nb",
|
|
433
|
+
"n_bulks",
|
|
434
|
+
default=None,
|
|
435
|
+
show_default=False,
|
|
436
|
+
type=click.IntRange(min=1),
|
|
437
|
+
help="Number of bulks simulated for testing.",
|
|
438
|
+
)
|
|
439
|
+
@click.option(
|
|
440
|
+
"--n_cells_bulk",
|
|
441
|
+
"-cb",
|
|
442
|
+
"n_cell_per_bulks",
|
|
443
|
+
default=None,
|
|
444
|
+
show_default=False,
|
|
445
|
+
type=click.IntRange(min=1),
|
|
446
|
+
help="Number of cells accumulated to a single in-silico bulk.",
|
|
447
|
+
)
|
|
448
|
+
def cli_simulate(
|
|
449
|
+
ad_path="", out_path="", train_frac=-1.0, n_bulks=-1, n_cell_per_bulks=-1
|
|
450
|
+
) -> None:
|
|
451
|
+
"""
|
|
452
|
+
Split an AnnData file into a train and test anndata file and create bulks with known ground truth for testing purposes.
|
|
453
|
+
"""
|
|
454
|
+
|
|
455
|
+
create_simulation(ad_path, out_path, train_frac, n_bulks, n_cell_per_bulks)
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
@cli_analyze.command("diff")
|
|
462
|
+
@click.option(
|
|
463
|
+
"--path",
|
|
464
|
+
"-p",
|
|
465
|
+
"hidedeconv_path",
|
|
466
|
+
default=".",
|
|
467
|
+
show_default=True,
|
|
468
|
+
type=click.Path(
|
|
469
|
+
exists=True, file_okay=False, dir_okay=True, writable=True, path_type=Path
|
|
470
|
+
),
|
|
471
|
+
help="Path, where the HIDE-Deconv project structure is located.",
|
|
472
|
+
)
|
|
473
|
+
@assert_trained
|
|
474
|
+
def cli_analyze_diff(hidedeconv_path: Path) -> None:
|
|
475
|
+
"""
|
|
476
|
+
Analyze cohort differences in deconvolution results.
|
|
477
|
+
|
|
478
|
+
Chooses either Mann-Withney U for two cohorts or Kruskal-Wallis and posthoc Dunn test
|
|
479
|
+
for multiple cohorts.
|
|
480
|
+
|
|
481
|
+
This command requires a sample sheet, where one column links the column names of the bulks
|
|
482
|
+
with the metadata used for cohort splitting.
|
|
483
|
+
"""
|
|
484
|
+
|
|
485
|
+
analyze_differences(hidedeconv_path)
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
@cli_analyze.command("benchmark")
|
|
492
|
+
@click.option(
|
|
493
|
+
"--path",
|
|
494
|
+
"-p",
|
|
495
|
+
"hidedeconv_path",
|
|
496
|
+
default=".",
|
|
497
|
+
show_default=True,
|
|
498
|
+
type=click.Path(
|
|
499
|
+
exists=True, file_okay=False, dir_okay=True, writable=True, path_type=Path
|
|
500
|
+
),
|
|
501
|
+
help="Path, where the HIDE-Deconv project structure is located.",
|
|
502
|
+
)
|
|
503
|
+
@assert_trained
|
|
504
|
+
def cli_analyze_benchmark(hidedeconv_path: Path) -> None:
|
|
505
|
+
"""
|
|
506
|
+
Benchmark the deconvoluted results against a ground truth compositions and save the results.
|
|
507
|
+
|
|
508
|
+
Used metrics include: Spearman Correlation, Pearson Correlation, RMSE, NMAE, Cosine Similarity, Kendall Tau.
|
|
509
|
+
|
|
510
|
+
The ground truth composition file must be on the same cell type layer as the compositions that should be benchmarked.
|
|
511
|
+
"""
|
|
512
|
+
|
|
513
|
+
benchmark_result(hidedeconv_path)
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
@cli_analyze.command("pca")
|
|
520
|
+
@click.option(
|
|
521
|
+
"--path",
|
|
522
|
+
"-p",
|
|
523
|
+
"hidedeconv_path",
|
|
524
|
+
default=".",
|
|
525
|
+
show_default=True,
|
|
526
|
+
type=click.Path(
|
|
527
|
+
exists=True, file_okay=False, dir_okay=True, writable=True, path_type=Path
|
|
528
|
+
),
|
|
529
|
+
help="Path, where the HIDE-Deconv project structure is located.",
|
|
530
|
+
)
|
|
531
|
+
@assert_trained
|
|
532
|
+
def cli_analyze_pca(hidedeconv_path: Path) -> None:
|
|
533
|
+
"""
|
|
534
|
+
Perform a principal component analysis on the deconvoluted bulk and save the resulting scatter plot.
|
|
535
|
+
"""
|
|
536
|
+
|
|
537
|
+
create_pca_plot(hidedeconv_path)
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
@cli_analyze.command("survival")
|
|
544
|
+
@click.option(
|
|
545
|
+
"--path",
|
|
546
|
+
"-p",
|
|
547
|
+
"hidedeconv_path",
|
|
548
|
+
default=".",
|
|
549
|
+
show_default=True,
|
|
550
|
+
type=click.Path(
|
|
551
|
+
exists=True, file_okay=False, dir_okay=True, writable=True, path_type=Path
|
|
552
|
+
),
|
|
553
|
+
help="Path, where the HIDE-Deconv project structure is located.",
|
|
554
|
+
)
|
|
555
|
+
@assert_trained
|
|
556
|
+
def cli_analyze_survival(hidedeconv_path: Path) -> None:
|
|
557
|
+
"""
|
|
558
|
+
Performs a survival analysis on selected results.
|
|
559
|
+
"""
|
|
560
|
+
|
|
561
|
+
survival_analysis(hidedeconv_path)
|
|
562
|
+
|
|
563
|
+
|
|
564
|
+
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
@cli.command("download")
|
|
568
|
+
def cli_download() -> None:
|
|
569
|
+
"""
|
|
570
|
+
Select and download an AnnData Single Cell file for certain pre-curated repositories.
|
|
571
|
+
"""
|
|
572
|
+
|
|
573
|
+
download_single_cells()
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
@cli_anndata.command("preprocess")
|
|
580
|
+
def cli_anndata_preprocess() -> None:
|
|
581
|
+
"""
|
|
582
|
+
Applies a standard AnnData preprocessing pipeline to a given AnnData file.
|
|
583
|
+
Removes cells with low quality or high mitochondrial rna expression.
|
|
584
|
+
Additionally excludes celltypes, that are below the min_cell threshold and removes genes that are either ribosomal, mitochondrial or have a very low expression level.
|
|
585
|
+
"""
|
|
586
|
+
|
|
587
|
+
preprocess_anndata()
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
591
|
+
if __name__ == "__main__":
|
|
592
|
+
cli()
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from .config_command import setup_config, show_config
|
|
2
|
+
from .preprocess_command import preprocess
|
|
3
|
+
from .setup_command import init, load_anndata, load_bulk, setup_project
|
|
4
|
+
from .train_command import train_model
|
|
5
|
+
from .help_command import show_help
|
|
6
|
+
from .deconvolve_command import deconvolve_hide, deconvolve_command
|
|
7
|
+
from .simulate_command import create_simulation
|
|
8
|
+
from .analyze_command import (
|
|
9
|
+
analyze_differences,
|
|
10
|
+
benchmark_result,
|
|
11
|
+
create_pca_plot,
|
|
12
|
+
survival_analysis,
|
|
13
|
+
)
|
|
14
|
+
from .download_command import download_single_cells
|
|
15
|
+
from .anndata_command import preprocess_anndata
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"setup_config",
|
|
19
|
+
"show_config",
|
|
20
|
+
"preprocess",
|
|
21
|
+
"setup_project",
|
|
22
|
+
"init",
|
|
23
|
+
"load_anndata",
|
|
24
|
+
"load_bulk",
|
|
25
|
+
"train_model",
|
|
26
|
+
"show_help",
|
|
27
|
+
"deconvolve_hide",
|
|
28
|
+
"deconvolve_command",
|
|
29
|
+
"create_simulation",
|
|
30
|
+
"analyze_differences",
|
|
31
|
+
"benchmark_result",
|
|
32
|
+
"create_pca_plot",
|
|
33
|
+
"download_single_cells",
|
|
34
|
+
"preprocess_anndata",
|
|
35
|
+
"survival_analysis",
|
|
36
|
+
]
|