mortis-spatial 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.
mortis/__init__.py ADDED
@@ -0,0 +1,395 @@
1
+ """
2
+ MORTIS
3
+ ======
4
+ Downstream analysis for spatial metabolomics (imaging mass spectrometry),
5
+ on top of AnnData and scanpy.
6
+
7
+ The short version of what it is for: an imaging run gives you tens of
8
+ thousands of pixels per section, but a study has a handful of patients. Tests
9
+ that treat pixels as replicates will report differences that are not there.
10
+ Everything here that makes a claim about a group does it at the sample level.
11
+
12
+ Typical workflow
13
+ ----------------
14
+ >>> import mortis as mt
15
+ >>>
16
+ >>> # 1. Load and clean
17
+ >>> adatas = mt.load_from_folder("./data")
18
+ >>> clean, stats = mt.filter_background(adatas, cutoff=1.5, mode="sample")
19
+ >>> adata = mt.merge_samples(clean, sample_col="section")
20
+ >>> adata = mt.preprocess(adata)
21
+ >>>
22
+ >>> # 2. Look at it
23
+ >>> adata = mt.cluster(adata)
24
+ >>> mt.plot_spatial(adata, color="cluster")
25
+ >>>
26
+ >>> # 3. Test at the level of the patient, not the pixel
27
+ >>> pb = mt.pseudobulk(adata, sample_key="section", carry_obs=["response"])
28
+ >>> abundance = mt.differential_abundance(pb, "response", "R", "NR")
29
+ >>>
30
+ >>> # 4. Then ask whether the arrangement changed, not just the amount
31
+ >>> org = mt.spatial_organization(adata, sample_key="section",
32
+ ... carry_obs=["response"])
33
+ >>> layout = mt.differential_spatial_organization(org, "response", "R", "NR")
34
+ >>>
35
+ >>> # 5. Write down what was run, so the numbers can be checked later
36
+ >>> mt.export_manifest(adata, "run/manifest.json")
37
+ """
38
+
39
+ from __future__ import annotations
40
+
41
+ from importlib.metadata import PackageNotFoundError as _PackageNotFoundError
42
+ from importlib.metadata import version as _version
43
+
44
+ try:
45
+ __version__ = _version("mortis-spatial")
46
+ except _PackageNotFoundError: # pragma: no cover - not installed, e.g. running from source
47
+ __version__ = "0.0.0+unknown"
48
+
49
+ # Analysis
50
+ from .analysis import (
51
+ batch_mixing_score,
52
+ cluster,
53
+ cluster_diversity,
54
+ cluster_nmf,
55
+ cluster_validation,
56
+ co_occurrence,
57
+ compare_clusterings,
58
+ compare_groups,
59
+ diversity_index,
60
+ find_markers,
61
+ getis_ord_gi,
62
+ lipid_class_summary,
63
+ local_moran,
64
+ merge_samples,
65
+ metabolite_colocalization,
66
+ metabolite_set_enrichment,
67
+ multi_group_test,
68
+ neighborhood_enrichment,
69
+ rename_clusters,
70
+ run_paga,
71
+ save_adata,
72
+ save_results,
73
+ score_metabolite_set,
74
+ spatial_autocorrelation,
75
+ spatial_de,
76
+ spatial_domains,
77
+ spatial_domains_kmeans,
78
+ spatial_gradient,
79
+ spatial_neighbors,
80
+ spatially_weighted_nmf,
81
+ split_by_obs,
82
+ subset_obs,
83
+ unmix_pixels,
84
+ )
85
+
86
+ # Annotation & enrichment
87
+ from .annotate import (
88
+ CHEMICAL_CLASSES,
89
+ class_enrichment,
90
+ classification_report,
91
+ classify_compounds,
92
+ pathway_ora,
93
+ )
94
+
95
+ # Cross-cohort / longitudinal comparison
96
+ from .compare import (
97
+ compare_signatures,
98
+ cross_cohort_profile,
99
+ track_flow,
100
+ )
101
+
102
+ # Exceptions
103
+ from .exceptions import (
104
+ FileFormatError,
105
+ InsufficientSamplesError,
106
+ InvalidParameterError,
107
+ MissingROIError,
108
+ MissingSpatialError,
109
+ MortisError,
110
+ NoClustersError,
111
+ NoEmbeddingError,
112
+ NotPreprocessedError,
113
+ PseudoreplicationWarning,
114
+ )
115
+
116
+ # Filtering
117
+ from .filter import (
118
+ filter_by_score,
119
+ filter_drugs,
120
+ list_drug_matches,
121
+ )
122
+
123
+ # Image (histology overlay)
124
+ from .image import (
125
+ align_image,
126
+ extract_image_features,
127
+ load_image,
128
+ plot_image_overlay,
129
+ )
130
+
131
+ # Interactive
132
+ from .interactive import (
133
+ draw_ROIs,
134
+ draw_ROIs_for_folder,
135
+ )
136
+
137
+ # I/O
138
+ from .io import (
139
+ check_rois,
140
+ from_dataframe,
141
+ load_annotation_scores,
142
+ load_from_folder,
143
+ make_writable,
144
+ read_metabolomics_data,
145
+ save_spatial_data,
146
+ )
147
+
148
+ # Spatial organization (differential spatial pattern)
149
+ from .organization import (
150
+ compare_abundance_and_organization,
151
+ differential_spatial_organization,
152
+ spatial_organization,
153
+ )
154
+
155
+ # Compound ID mapping & KEGG pathways (network)
156
+ from .pathway import (
157
+ annotate_pathways,
158
+ clear_cache,
159
+ fetch_kegg_pathway_sets,
160
+ map_compound_ids,
161
+ )
162
+
163
+ # Plotting
164
+ from .plotting import (
165
+ plot_cluster_composition,
166
+ plot_colocalization_network,
167
+ plot_embedding_grid,
168
+ plot_heatmap,
169
+ plot_markers,
170
+ plot_morans,
171
+ plot_qc,
172
+ plot_spatial,
173
+ plot_spatial_gradient,
174
+ plot_spatial_metabolite,
175
+ plot_umap,
176
+ plot_violin,
177
+ plot_volcano,
178
+ )
179
+
180
+ # Preprocessing
181
+ from .preprocessing import (
182
+ correct_batches,
183
+ filter_background,
184
+ log1p_transform,
185
+ median_normalize,
186
+ preprocess,
187
+ run_harmony,
188
+ run_neighbors,
189
+ run_pca,
190
+ run_umap,
191
+ scale,
192
+ tic_normalize,
193
+ )
194
+
195
+ # Reproducibility manifests
196
+ from .reproducibility import (
197
+ MANIFEST_VERSION,
198
+ data_fingerprint,
199
+ export_manifest,
200
+ provenance,
201
+ record_step,
202
+ result_fingerprint,
203
+ verify_manifest,
204
+ )
205
+
206
+ # Statistics (sample-level / patient-level)
207
+ from .stats import (
208
+ cliffs_delta,
209
+ differential_abundance,
210
+ paired_differential_abundance,
211
+ pseudobulk,
212
+ )
213
+
214
+ # Publication figures & export
215
+ from .viz import (
216
+ PALETTE,
217
+ diverging_cmap,
218
+ ion_cmap,
219
+ plot_abundance_vs_organization,
220
+ plot_class_enrichment,
221
+ plot_delta_volcano,
222
+ plot_effect_forest,
223
+ plot_effect_size,
224
+ plot_embedding,
225
+ plot_ion_images,
226
+ plot_organization_heatmap,
227
+ plot_pathway_dotplot,
228
+ plot_signature_comparison,
229
+ plot_spatial_panels,
230
+ reset_style,
231
+ save_figure,
232
+ set_publication_style,
233
+ )
234
+
235
+ __all__ = [
236
+ # Exceptions
237
+ "MortisError",
238
+ "MissingROIError",
239
+ "MissingSpatialError",
240
+ "NotPreprocessedError",
241
+ "NoClustersError",
242
+ "NoEmbeddingError",
243
+ "InsufficientSamplesError",
244
+ "InvalidParameterError",
245
+ "FileFormatError",
246
+ "PseudoreplicationWarning",
247
+
248
+ # I/O
249
+ "read_metabolomics_data",
250
+ "from_dataframe",
251
+ "make_writable",
252
+ "load_from_folder",
253
+ "load_annotation_scores",
254
+ "check_rois",
255
+ "save_spatial_data",
256
+
257
+ # Interactive
258
+ "draw_ROIs",
259
+ "draw_ROIs_for_folder",
260
+
261
+ # Preprocessing
262
+ "filter_background",
263
+ "tic_normalize",
264
+ "median_normalize",
265
+ "log1p_transform",
266
+ "scale",
267
+ "run_pca",
268
+ "run_neighbors",
269
+ "run_umap",
270
+ "correct_batches",
271
+ "run_harmony",
272
+ "preprocess",
273
+
274
+ # Filtering
275
+ "filter_by_score",
276
+ "filter_drugs",
277
+ "list_drug_matches",
278
+
279
+ # Image (histology overlay)
280
+ "load_image",
281
+ "align_image",
282
+ "extract_image_features",
283
+ "plot_image_overlay",
284
+
285
+ # Statistics (sample-level)
286
+ "pseudobulk",
287
+ "differential_abundance",
288
+ "paired_differential_abundance",
289
+ "cliffs_delta",
290
+
291
+ # Annotation & enrichment
292
+ "classify_compounds",
293
+ "classification_report",
294
+ "class_enrichment",
295
+ "pathway_ora",
296
+ "CHEMICAL_CLASSES",
297
+
298
+ # Reproducibility
299
+ "export_manifest",
300
+ "verify_manifest",
301
+ "record_step",
302
+ "provenance",
303
+ "data_fingerprint",
304
+ "result_fingerprint",
305
+ "MANIFEST_VERSION",
306
+
307
+ # Compound ID mapping & KEGG pathways
308
+ "map_compound_ids",
309
+ "fetch_kegg_pathway_sets",
310
+ "annotate_pathways",
311
+ "clear_cache",
312
+
313
+ # Publication figures & export
314
+ "set_publication_style",
315
+ "reset_style",
316
+ "save_figure",
317
+ "plot_effect_size",
318
+ "plot_effect_forest",
319
+ "plot_delta_volcano",
320
+ "plot_abundance_vs_organization",
321
+ "plot_signature_comparison",
322
+ "plot_ion_images",
323
+ "plot_spatial_panels",
324
+ "plot_embedding",
325
+ "plot_organization_heatmap",
326
+ "plot_class_enrichment",
327
+ "plot_pathway_dotplot",
328
+ "PALETTE",
329
+ "diverging_cmap",
330
+ "ion_cmap",
331
+
332
+ # Cross-cohort comparison
333
+ "cross_cohort_profile",
334
+ "track_flow",
335
+ "compare_signatures",
336
+
337
+ # Spatial organization
338
+ "spatial_organization",
339
+ "differential_spatial_organization",
340
+ "compare_abundance_and_organization",
341
+
342
+ # Analysis
343
+ "cluster",
344
+ "cluster_nmf",
345
+ "spatial_domains",
346
+ "spatial_domains_kmeans",
347
+ "rename_clusters",
348
+ "find_markers",
349
+ "compare_groups",
350
+ "multi_group_test",
351
+ "spatial_autocorrelation",
352
+ "spatial_de",
353
+ "local_moran",
354
+ "getis_ord_gi",
355
+ "spatial_neighbors",
356
+ "neighborhood_enrichment",
357
+ "co_occurrence",
358
+ "score_metabolite_set",
359
+ "metabolite_set_enrichment",
360
+ "lipid_class_summary",
361
+ "diversity_index",
362
+ "cluster_diversity",
363
+ "unmix_pixels",
364
+ "cluster_validation",
365
+ "compare_clusterings",
366
+ "batch_mixing_score",
367
+ "run_paga",
368
+ "subset_obs",
369
+ "merge_samples",
370
+ "split_by_obs",
371
+ "save_results",
372
+ "save_adata",
373
+
374
+ # Spatial structure
375
+ "spatially_weighted_nmf",
376
+ "spatial_gradient",
377
+ "metabolite_colocalization",
378
+
379
+ # Plotting
380
+ "plot_qc",
381
+ "plot_spatial",
382
+ "plot_spatial_metabolite",
383
+ "plot_embedding_grid",
384
+ "plot_umap",
385
+ "plot_markers",
386
+ "plot_volcano",
387
+ "plot_heatmap",
388
+ "plot_violin",
389
+ "plot_cluster_composition",
390
+ "plot_morans",
391
+
392
+ # Spatial structure plots
393
+ "plot_spatial_gradient",
394
+ "plot_colocalization_network",
395
+ ]