spatialcore 0.1.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 (38) hide show
  1. spatialcore-0.1.4/LICENSE +201 -0
  2. spatialcore-0.1.4/PKG-INFO +213 -0
  3. spatialcore-0.1.4/README.md +168 -0
  4. spatialcore-0.1.4/pyproject.toml +91 -0
  5. spatialcore-0.1.4/setup.cfg +4 -0
  6. spatialcore-0.1.4/src/spatialcore/__init__.py +122 -0
  7. spatialcore-0.1.4/src/spatialcore/annotation/__init__.py +253 -0
  8. spatialcore-0.1.4/src/spatialcore/annotation/acquisition.py +529 -0
  9. spatialcore-0.1.4/src/spatialcore/annotation/annotate.py +603 -0
  10. spatialcore-0.1.4/src/spatialcore/annotation/cellxgene.py +365 -0
  11. spatialcore-0.1.4/src/spatialcore/annotation/confidence.py +802 -0
  12. spatialcore-0.1.4/src/spatialcore/annotation/discovery.py +529 -0
  13. spatialcore-0.1.4/src/spatialcore/annotation/expression.py +363 -0
  14. spatialcore-0.1.4/src/spatialcore/annotation/loading.py +529 -0
  15. spatialcore-0.1.4/src/spatialcore/annotation/markers.py +297 -0
  16. spatialcore-0.1.4/src/spatialcore/annotation/ontology.py +1282 -0
  17. spatialcore-0.1.4/src/spatialcore/annotation/patterns.py +247 -0
  18. spatialcore-0.1.4/src/spatialcore/annotation/pipeline.py +606 -0
  19. spatialcore-0.1.4/src/spatialcore/annotation/synapse.py +380 -0
  20. spatialcore-0.1.4/src/spatialcore/annotation/training.py +1457 -0
  21. spatialcore-0.1.4/src/spatialcore/annotation/validation.py +422 -0
  22. spatialcore-0.1.4/src/spatialcore/core/__init__.py +34 -0
  23. spatialcore-0.1.4/src/spatialcore/core/cache.py +118 -0
  24. spatialcore-0.1.4/src/spatialcore/core/logging.py +135 -0
  25. spatialcore-0.1.4/src/spatialcore/core/metadata.py +149 -0
  26. spatialcore-0.1.4/src/spatialcore/core/utils.py +768 -0
  27. spatialcore-0.1.4/src/spatialcore/plotting/__init__.py +109 -0
  28. spatialcore-0.1.4/src/spatialcore/plotting/benchmark.py +477 -0
  29. spatialcore-0.1.4/src/spatialcore/plotting/celltype.py +329 -0
  30. spatialcore-0.1.4/src/spatialcore/plotting/confidence.py +413 -0
  31. spatialcore-0.1.4/src/spatialcore/plotting/spatial.py +505 -0
  32. spatialcore-0.1.4/src/spatialcore/plotting/utils.py +411 -0
  33. spatialcore-0.1.4/src/spatialcore/plotting/validation.py +1334 -0
  34. spatialcore-0.1.4/src/spatialcore.egg-info/PKG-INFO +213 -0
  35. spatialcore-0.1.4/src/spatialcore.egg-info/SOURCES.txt +36 -0
  36. spatialcore-0.1.4/src/spatialcore.egg-info/dependency_links.txt +1 -0
  37. spatialcore-0.1.4/src/spatialcore.egg-info/requires.txt +22 -0
  38. spatialcore-0.1.4/src/spatialcore.egg-info/top_level.txt +1 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,213 @@
1
+ Metadata-Version: 2.4
2
+ Name: spatialcore
3
+ Version: 0.1.4
4
+ Summary: Standardized spatial statistics tools for computational biology
5
+ Author: SpatialCore Contributors
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/mcap91/SpatialCore
8
+ Project-URL: Documentation, https://mcap91.github.io/SpatialCore
9
+ Project-URL: Repository, https://github.com/mcap91/SpatialCore
10
+ Project-URL: Issues, https://github.com/mcap91/SpatialCore/issues
11
+ Keywords: spatial-transcriptomics,single-cell,bioinformatics,scanpy,squidpy,xenium,cosmx,visium
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
20
+ Requires-Python: >=3.10
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: anndata>=0.10.0
24
+ Requires-Dist: scanpy>=1.9.0
25
+ Requires-Dist: squidpy>=1.3.0
26
+ Requires-Dist: numpy>=1.21.0
27
+ Requires-Dist: pandas>=1.5.0
28
+ Requires-Dist: scipy>=1.9.0
29
+ Requires-Dist: scikit-learn>=1.0.0
30
+ Requires-Dist: matplotlib>=3.5.0
31
+ Requires-Dist: seaborn>=0.12.0
32
+ Requires-Dist: celltypist>=1.6.0
33
+ Provides-Extra: dev
34
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
35
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
36
+ Requires-Dist: black>=23.0.0; extra == "dev"
37
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
38
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
39
+ Requires-Dist: pyyaml>=6.0.0; extra == "dev"
40
+ Requires-Dist: mkdocs>=1.5.0; extra == "dev"
41
+ Requires-Dist: mkdocs-material>=9.0.0; extra == "dev"
42
+ Requires-Dist: mkdocs-glightbox>=0.3.0; extra == "dev"
43
+ Requires-Dist: mkdocstrings[python]>=0.24.0; extra == "dev"
44
+ Dynamic: license-file
45
+
46
+ # SpatialCore
47
+
48
+ **Standardized spatial statistics for computational biology.**
49
+
50
+ [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
51
+ [![Python](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
52
+ [![PyPI](https://img.shields.io/pypi/v/spatialcore.svg)](https://pypi.org/project/spatialcore/)
53
+ [![Code Style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
54
+
55
+ ---
56
+
57
+ ## 🎯 The Mission
58
+
59
+ ### The Problem
60
+ Tools for spatial biology analysis are fragmented. Implementations packages and complex functions often differ between languages (R vs Python) and even between packages, making reproducibility difficult and benchmarking impossible. We believe simple statistical tools solve many of the core problems of spatial biology, and we have desinged them to be intuative, easy to use, and scaleable for millions of cells.
61
+
62
+ ### The Solution
63
+ SpatialCore serves as a package for computational biologists, by computational biologists. It provides robust, standardized implementations of core spatial statistics that ensure identical results across platforms, wrapping high-performance libraries where available.
64
+
65
+ ### The Goal
66
+ To make spatial analysis engineering boring, so you can focus on the exciting biology. **Standardized. Scalable. Reproducible.**
67
+
68
+ ---
69
+
70
+ ## 📦 Installation
71
+
72
+ ### Recommended: Conda/Mamba Environment
73
+
74
+ For the best experience, we recommend using a conda or mamba environment:
75
+
76
+ ```bash
77
+ # Create environment with Python 3.11
78
+ mamba create -n spatialcore python=3.11
79
+ mamba activate spatialcore
80
+
81
+ # Install SpatialCore
82
+ pip install spatialcore
83
+ ```
84
+
85
+ This installs all core Python dependencies including CellTypist for custom model training for cell type annotation.
86
+
87
+
88
+ ### R Requirements
89
+
90
+ SpatialCore uses R for certain operations that are statistically optimized or perform better in R. The `r_bridge` module handles R integration via subprocess (no rpy2 required).
91
+
92
+ **Install R packages in your environment:**
93
+
94
+ ```bash
95
+ # If using conda/mamba (recommended)
96
+ mamba install -c conda-forge r-base r-sf r-concaveman r-dplyr r-purrr r-jsonlite
97
+
98
+ # If using system R (Linux/macOS)
99
+ sudo apt-get install r-base # Ubuntu/Debian
100
+ R -e "install.packages(c('sf', 'concaveman', 'dplyr', 'purrr', 'jsonlite'), repos='https://cloud.r-project.org/')"
101
+ ```
102
+
103
+ **Verify R is configured correctly:**
104
+
105
+ ```python
106
+ from spatialcore.r_bridge import check_r_available, get_r_version
107
+ print(check_r_available()) # True
108
+ print(get_r_version()) # R version 4.x.x
109
+ ```
110
+
111
+ ### How r_bridge Works
112
+
113
+ The `r_bridge` automatically detects your environment:
114
+
115
+ | Environment | R Execution Method |
116
+ |-------------|-------------------|
117
+ | Conda/Mamba | `mamba run -n env_name Rscript ...` |
118
+ | System R | `Rscript` directly |
119
+
120
+ No manual configuration needed - it just works.
121
+
122
+ ---
123
+
124
+ ## 🚀 Quick Start
125
+
126
+ ```python
127
+ import spatialcore
128
+
129
+ # Check what's available in your installation
130
+ spatialcore.print_info()
131
+ # SpatialCore v0.1.3
132
+ # Available modules: core, annotation
133
+
134
+ # Cell type annotation with CellTypist
135
+ from spatialcore.annotation import annotate_celltypist, train_celltypist_model
136
+
137
+ # Annotate cells using CellTypist (auto-selects models based on tissue)
138
+ adata = annotate_celltypist(adata, tissue="colon")
139
+
140
+ # Train a custom model on your reference data
141
+ model = train_celltypist_model(adata_reference, label_column="cell_type")
142
+ ```
143
+
144
+ 📖 **Full documentation:** [mcap91.github.io/SpatialCore](https://mcap91.github.io/SpatialCore)
145
+
146
+ ---
147
+
148
+ ## 🧩 Modules & Features
149
+
150
+ | Module | Status | Features |
151
+ |--------|--------|----------|
152
+ | **`spatialcore.core`** | ✅ Available | Logging, metadata tracking, caching utilities |
153
+ | **`spatialcore.annotation`** | ✅ Available | CellTypist wrappers, custom model training, benchmarking |
154
+ | **`spatialcore.spatial`** | 🔜 Coming soon | Moran's I, Lee's L, neighborhoods, niches, domains |
155
+ | **`spatialcore.nmf`** | 🔜 Coming soon | Spatial non-negative matrix factorization |
156
+ | **`spatialcore.diffusion`** | 🔜 Coming soon | Diffusion maps, pseudotime analysis |
157
+
158
+ ---
159
+
160
+ ## 📚 Terminology
161
+
162
+ We strictly define our spatial units to ensure clarity:
163
+
164
+ | Term | Definition |
165
+ |------|------------|
166
+ | **Neighborhood** | The immediate spatial vicinity of a cell (e.g., k-Nearest Neighbors or fixed radius). |
167
+ | **Niche** | A functional microenvironment defined by a specific composition of cell types (e.g., "Tumor-immune border"). |
168
+ | **Domain** | A macroscopic, continuous tissue region with shared structural characteristics (e.g., "Cortex", "Medulla"). |
169
+
170
+ ---
171
+
172
+ ## 🤝 Ecosystem Integration
173
+
174
+ SpatialCore is designed to play nice with others. It fits seamlessly into the existing Python spatial biology stack:
175
+
176
+ * **[Scanpy](https://scanpy.readthedocs.io/)**: The backbone for single-cell analysis.
177
+ * **[Squidpy](https://squidpy.readthedocs.io/)**: Advanced spatial omics analysis.
178
+ * **[Seurat](https://satijalab.org/seurat/)**: Direct R interoperability for teams working across languages.
179
+
180
+ ---
181
+
182
+ ## ⚖️ Philosophy
183
+
184
+ This package is **for computational biologists, by computational biologists**.
185
+
186
+ * **Reproducibility**: Same inputs = Same outputs. Period.
187
+ * **Scalability**: Built for the era of millions of cells (Xenium/CosMx).
188
+ * **Transparency**: Thin wrappers, not black boxes. We verify, we don't obfuscate.
189
+ * **Documentation**: Clear docstrings with academic references.
190
+
191
+ **What we are NOT:**
192
+ * Inventing new, unproven math.
193
+ * Replacing Scanpy, Seurat, or other methods.
194
+
195
+ ---
196
+
197
+ ## 📝 Citation
198
+
199
+ If SpatialCore aids your research, please cite:
200
+
201
+ ```bibtex
202
+ @software{spatialcore,
203
+ title = {SpatialCore: Standardized spatial statistics for computational biology},
204
+ url = {https://github.com/mcap91/SpatialCore},
205
+ license = {Apache-2.0}
206
+ }
207
+ ```
208
+
209
+ ## License
210
+
211
+ **Apache License 2.0**
212
+
213
+ The SpatialCore name and trademarks are reserved to ensure the community can rely on the "Standardized" quality of the core library. You are free to use, modify, and distribute the code, including for commercial use.
@@ -0,0 +1,168 @@
1
+ # SpatialCore
2
+
3
+ **Standardized spatial statistics for computational biology.**
4
+
5
+ [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
6
+ [![Python](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
7
+ [![PyPI](https://img.shields.io/pypi/v/spatialcore.svg)](https://pypi.org/project/spatialcore/)
8
+ [![Code Style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
9
+
10
+ ---
11
+
12
+ ## 🎯 The Mission
13
+
14
+ ### The Problem
15
+ Tools for spatial biology analysis are fragmented. Implementations packages and complex functions often differ between languages (R vs Python) and even between packages, making reproducibility difficult and benchmarking impossible. We believe simple statistical tools solve many of the core problems of spatial biology, and we have desinged them to be intuative, easy to use, and scaleable for millions of cells.
16
+
17
+ ### The Solution
18
+ SpatialCore serves as a package for computational biologists, by computational biologists. It provides robust, standardized implementations of core spatial statistics that ensure identical results across platforms, wrapping high-performance libraries where available.
19
+
20
+ ### The Goal
21
+ To make spatial analysis engineering boring, so you can focus on the exciting biology. **Standardized. Scalable. Reproducible.**
22
+
23
+ ---
24
+
25
+ ## 📦 Installation
26
+
27
+ ### Recommended: Conda/Mamba Environment
28
+
29
+ For the best experience, we recommend using a conda or mamba environment:
30
+
31
+ ```bash
32
+ # Create environment with Python 3.11
33
+ mamba create -n spatialcore python=3.11
34
+ mamba activate spatialcore
35
+
36
+ # Install SpatialCore
37
+ pip install spatialcore
38
+ ```
39
+
40
+ This installs all core Python dependencies including CellTypist for custom model training for cell type annotation.
41
+
42
+
43
+ ### R Requirements
44
+
45
+ SpatialCore uses R for certain operations that are statistically optimized or perform better in R. The `r_bridge` module handles R integration via subprocess (no rpy2 required).
46
+
47
+ **Install R packages in your environment:**
48
+
49
+ ```bash
50
+ # If using conda/mamba (recommended)
51
+ mamba install -c conda-forge r-base r-sf r-concaveman r-dplyr r-purrr r-jsonlite
52
+
53
+ # If using system R (Linux/macOS)
54
+ sudo apt-get install r-base # Ubuntu/Debian
55
+ R -e "install.packages(c('sf', 'concaveman', 'dplyr', 'purrr', 'jsonlite'), repos='https://cloud.r-project.org/')"
56
+ ```
57
+
58
+ **Verify R is configured correctly:**
59
+
60
+ ```python
61
+ from spatialcore.r_bridge import check_r_available, get_r_version
62
+ print(check_r_available()) # True
63
+ print(get_r_version()) # R version 4.x.x
64
+ ```
65
+
66
+ ### How r_bridge Works
67
+
68
+ The `r_bridge` automatically detects your environment:
69
+
70
+ | Environment | R Execution Method |
71
+ |-------------|-------------------|
72
+ | Conda/Mamba | `mamba run -n env_name Rscript ...` |
73
+ | System R | `Rscript` directly |
74
+
75
+ No manual configuration needed - it just works.
76
+
77
+ ---
78
+
79
+ ## 🚀 Quick Start
80
+
81
+ ```python
82
+ import spatialcore
83
+
84
+ # Check what's available in your installation
85
+ spatialcore.print_info()
86
+ # SpatialCore v0.1.3
87
+ # Available modules: core, annotation
88
+
89
+ # Cell type annotation with CellTypist
90
+ from spatialcore.annotation import annotate_celltypist, train_celltypist_model
91
+
92
+ # Annotate cells using CellTypist (auto-selects models based on tissue)
93
+ adata = annotate_celltypist(adata, tissue="colon")
94
+
95
+ # Train a custom model on your reference data
96
+ model = train_celltypist_model(adata_reference, label_column="cell_type")
97
+ ```
98
+
99
+ 📖 **Full documentation:** [mcap91.github.io/SpatialCore](https://mcap91.github.io/SpatialCore)
100
+
101
+ ---
102
+
103
+ ## 🧩 Modules & Features
104
+
105
+ | Module | Status | Features |
106
+ |--------|--------|----------|
107
+ | **`spatialcore.core`** | ✅ Available | Logging, metadata tracking, caching utilities |
108
+ | **`spatialcore.annotation`** | ✅ Available | CellTypist wrappers, custom model training, benchmarking |
109
+ | **`spatialcore.spatial`** | 🔜 Coming soon | Moran's I, Lee's L, neighborhoods, niches, domains |
110
+ | **`spatialcore.nmf`** | 🔜 Coming soon | Spatial non-negative matrix factorization |
111
+ | **`spatialcore.diffusion`** | 🔜 Coming soon | Diffusion maps, pseudotime analysis |
112
+
113
+ ---
114
+
115
+ ## 📚 Terminology
116
+
117
+ We strictly define our spatial units to ensure clarity:
118
+
119
+ | Term | Definition |
120
+ |------|------------|
121
+ | **Neighborhood** | The immediate spatial vicinity of a cell (e.g., k-Nearest Neighbors or fixed radius). |
122
+ | **Niche** | A functional microenvironment defined by a specific composition of cell types (e.g., "Tumor-immune border"). |
123
+ | **Domain** | A macroscopic, continuous tissue region with shared structural characteristics (e.g., "Cortex", "Medulla"). |
124
+
125
+ ---
126
+
127
+ ## 🤝 Ecosystem Integration
128
+
129
+ SpatialCore is designed to play nice with others. It fits seamlessly into the existing Python spatial biology stack:
130
+
131
+ * **[Scanpy](https://scanpy.readthedocs.io/)**: The backbone for single-cell analysis.
132
+ * **[Squidpy](https://squidpy.readthedocs.io/)**: Advanced spatial omics analysis.
133
+ * **[Seurat](https://satijalab.org/seurat/)**: Direct R interoperability for teams working across languages.
134
+
135
+ ---
136
+
137
+ ## ⚖️ Philosophy
138
+
139
+ This package is **for computational biologists, by computational biologists**.
140
+
141
+ * **Reproducibility**: Same inputs = Same outputs. Period.
142
+ * **Scalability**: Built for the era of millions of cells (Xenium/CosMx).
143
+ * **Transparency**: Thin wrappers, not black boxes. We verify, we don't obfuscate.
144
+ * **Documentation**: Clear docstrings with academic references.
145
+
146
+ **What we are NOT:**
147
+ * Inventing new, unproven math.
148
+ * Replacing Scanpy, Seurat, or other methods.
149
+
150
+ ---
151
+
152
+ ## 📝 Citation
153
+
154
+ If SpatialCore aids your research, please cite:
155
+
156
+ ```bibtex
157
+ @software{spatialcore,
158
+ title = {SpatialCore: Standardized spatial statistics for computational biology},
159
+ url = {https://github.com/mcap91/SpatialCore},
160
+ license = {Apache-2.0}
161
+ }
162
+ ```
163
+
164
+ ## License
165
+
166
+ **Apache License 2.0**
167
+
168
+ The SpatialCore name and trademarks are reserved to ensure the community can rely on the "Standardized" quality of the core library. You are free to use, modify, and distribute the code, including for commercial use.
@@ -0,0 +1,91 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "spatialcore"
7
+ version = "0.1.4"
8
+ description = "Standardized spatial statistics tools for computational biology"
9
+ readme = "README.md"
10
+ license = "Apache-2.0"
11
+ requires-python = ">=3.10"
12
+ authors = [
13
+ {name = "SpatialCore Contributors"}
14
+ ]
15
+ keywords = [
16
+ "spatial-transcriptomics",
17
+ "single-cell",
18
+ "bioinformatics",
19
+ "scanpy",
20
+ "squidpy",
21
+ "xenium",
22
+ "cosmx",
23
+ "visium"
24
+ ]
25
+ classifiers = [
26
+ "Development Status :: 3 - Alpha",
27
+ "Intended Audience :: Science/Research",
28
+ "Operating System :: OS Independent",
29
+ "Programming Language :: Python :: 3",
30
+ "Programming Language :: Python :: 3.10",
31
+ "Programming Language :: Python :: 3.11",
32
+ "Programming Language :: Python :: 3.12",
33
+ "Topic :: Scientific/Engineering :: Bio-Informatics",
34
+ ]
35
+
36
+ dependencies = [
37
+ "anndata>=0.10.0",
38
+ "scanpy>=1.9.0",
39
+ "squidpy>=1.3.0",
40
+ "numpy>=1.21.0",
41
+ "pandas>=1.5.0",
42
+ "scipy>=1.9.0",
43
+ "scikit-learn>=1.0.0",
44
+ "matplotlib>=3.5.0",
45
+ "seaborn>=0.12.0",
46
+ "celltypist>=1.6.0",
47
+ ]
48
+
49
+ [project.optional-dependencies]
50
+ dev = [
51
+ "pytest>=7.0.0",
52
+ "pytest-cov>=4.0.0",
53
+ "black>=23.0.0",
54
+ "ruff>=0.1.0",
55
+ "mypy>=1.0.0",
56
+ "pyyaml>=6.0.0",
57
+ "mkdocs>=1.5.0",
58
+ "mkdocs-material>=9.0.0",
59
+ "mkdocs-glightbox>=0.3.0",
60
+ "mkdocstrings[python]>=0.24.0",
61
+ ]
62
+
63
+ [project.urls]
64
+ Homepage = "https://github.com/mcap91/SpatialCore"
65
+ Documentation = "https://mcap91.github.io/SpatialCore"
66
+ Repository = "https://github.com/mcap91/SpatialCore"
67
+ Issues = "https://github.com/mcap91/SpatialCore/issues"
68
+
69
+ [tool.setuptools.packages.find]
70
+ where = ["src"]
71
+
72
+ [tool.setuptools.package-data]
73
+ spatialcore = ["py.typed"]
74
+
75
+ [tool.black]
76
+ line-length = 88
77
+ target-version = ["py310", "py311", "py312"]
78
+
79
+ [tool.ruff]
80
+ line-length = 88
81
+ target-version = "py310"
82
+ select = ["E", "F", "W", "I", "UP", "B", "C4"]
83
+
84
+ [tool.mypy]
85
+ python_version = "3.10"
86
+ warn_return_any = true
87
+ warn_unused_configs = true
88
+
89
+ [tool.pytest.ini_options]
90
+ testpaths = ["tests"]
91
+ addopts = "-v --cov=spatialcore"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+