SpatialQuery 0.0.3__tar.gz → 0.0.5__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.
- spatialquery-0.0.5/PKG-INFO +101 -0
- spatialquery-0.0.5/README.md +64 -0
- {spatialquery-0.0.3 → spatialquery-0.0.5}/SpatialQuery/spatial_query.py +46 -39
- spatialquery-0.0.5/SpatialQuery.egg-info/PKG-INFO +101 -0
- {spatialquery-0.0.3 → spatialquery-0.0.5}/pyproject.toml +2 -1
- spatialquery-0.0.3/PKG-INFO +0 -379
- spatialquery-0.0.3/README.md +0 -343
- spatialquery-0.0.3/SpatialQuery.egg-info/PKG-INFO +0 -379
- {spatialquery-0.0.3 → spatialquery-0.0.5}/LICENSE +0 -0
- {spatialquery-0.0.3 → spatialquery-0.0.5}/MANIFEST.in +0 -0
- {spatialquery-0.0.3 → spatialquery-0.0.5}/SpatialQuery/__init__.py +0 -0
- {spatialquery-0.0.3 → spatialquery-0.0.5}/SpatialQuery/plotting.py +0 -0
- {spatialquery-0.0.3 → spatialquery-0.0.5}/SpatialQuery/scfind4sp/__init__.py +0 -0
- {spatialquery-0.0.3 → spatialquery-0.0.5}/SpatialQuery/scfind4sp/core_methods.py +0 -0
- {spatialquery-0.0.3 → spatialquery-0.0.5}/SpatialQuery/scfind4sp/cpp_src/EliasFano.h +0 -0
- {spatialquery-0.0.3 → spatialquery-0.0.5}/SpatialQuery/scfind4sp/cpp_src/QueryScore.cpp +0 -0
- {spatialquery-0.0.3 → spatialquery-0.0.5}/SpatialQuery/scfind4sp/cpp_src/QueryScore.h +0 -0
- {spatialquery-0.0.3 → spatialquery-0.0.5}/SpatialQuery/scfind4sp/cpp_src/Serialization.h +0 -0
- {spatialquery-0.0.3 → spatialquery-0.0.5}/SpatialQuery/scfind4sp/cpp_src/__init__.py +0 -0
- {spatialquery-0.0.3 → spatialquery-0.0.5}/SpatialQuery/scfind4sp/cpp_src/const.h +0 -0
- {spatialquery-0.0.3 → spatialquery-0.0.5}/SpatialQuery/scfind4sp/cpp_src/eliasFano.cpp +0 -0
- {spatialquery-0.0.3 → spatialquery-0.0.5}/SpatialQuery/scfind4sp/cpp_src/fp_growth.cpp +0 -0
- {spatialquery-0.0.3 → spatialquery-0.0.5}/SpatialQuery/scfind4sp/cpp_src/fp_growth.h +0 -0
- {spatialquery-0.0.3 → spatialquery-0.0.5}/SpatialQuery/scfind4sp/cpp_src/serialization.cpp +0 -0
- {spatialquery-0.0.3 → spatialquery-0.0.5}/SpatialQuery/scfind4sp/cpp_src/typedef.h +0 -0
- {spatialquery-0.0.3 → spatialquery-0.0.5}/SpatialQuery/scfind4sp/cpp_src/utils.cpp +0 -0
- {spatialquery-0.0.3 → spatialquery-0.0.5}/SpatialQuery/scfind4sp/cpp_src/utils.h +0 -0
- {spatialquery-0.0.3 → spatialquery-0.0.5}/SpatialQuery/spatial_differential_pattern.py +0 -0
- {spatialquery-0.0.3 → spatialquery-0.0.5}/SpatialQuery/spatial_gene_covarying.py +0 -0
- {spatialquery-0.0.3 → spatialquery-0.0.5}/SpatialQuery/spatial_query_multiple_fov.py +0 -0
- {spatialquery-0.0.3 → spatialquery-0.0.5}/SpatialQuery/spatial_utils.py +0 -0
- {spatialquery-0.0.3 → spatialquery-0.0.5}/SpatialQuery/utils.py +0 -0
- {spatialquery-0.0.3 → spatialquery-0.0.5}/SpatialQuery.egg-info/SOURCES.txt +0 -0
- {spatialquery-0.0.3 → spatialquery-0.0.5}/SpatialQuery.egg-info/dependency_links.txt +0 -0
- {spatialquery-0.0.3 → spatialquery-0.0.5}/SpatialQuery.egg-info/requires.txt +0 -0
- {spatialquery-0.0.3 → spatialquery-0.0.5}/SpatialQuery.egg-info/top_level.txt +0 -0
- {spatialquery-0.0.3 → spatialquery-0.0.5}/setup.cfg +0 -0
- {spatialquery-0.0.3 → spatialquery-0.0.5}/setup.py +0 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: SpatialQuery
|
|
3
|
+
Version: 0.0.5
|
|
4
|
+
Summary: Spatial query tools for analyzing spatial transcriptomics data
|
|
5
|
+
Author-email: Shaokun An <shan12@bwh.harvard.edu>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/ShaokunAn/Spatial-Query
|
|
8
|
+
Project-URL: Documentation, https://spatial-query.readthedocs.io
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: numpy>=1.23.0
|
|
19
|
+
Requires-Dist: anndata>=0.8.0
|
|
20
|
+
Requires-Dist: pandas>=2.0.3
|
|
21
|
+
Requires-Dist: scipy>=1.10.0
|
|
22
|
+
Requires-Dist: matplotlib>=3.7.5
|
|
23
|
+
Requires-Dist: scikit-learn>=1.3.2
|
|
24
|
+
Requires-Dist: scanpy>=1.9.5
|
|
25
|
+
Requires-Dist: statsmodels>=0.14.0
|
|
26
|
+
Requires-Dist: seaborn>=0.13.2
|
|
27
|
+
Requires-Dist: mlxtend>=0.23.1
|
|
28
|
+
Requires-Dist: tqdm>=4.60.0
|
|
29
|
+
Requires-Dist: zarr>=2.14.0
|
|
30
|
+
Provides-Extra: docs
|
|
31
|
+
Requires-Dist: sphinx>=5.3; extra == "docs"
|
|
32
|
+
Requires-Dist: sphinx-rtd-theme; extra == "docs"
|
|
33
|
+
Requires-Dist: sphinx-autodoc-typehints; extra == "docs"
|
|
34
|
+
Requires-Dist: sphinx-copybutton; extra == "docs"
|
|
35
|
+
Requires-Dist: myst-parser; extra == "docs"
|
|
36
|
+
Dynamic: license-file
|
|
37
|
+
|
|
38
|
+
# SpatialQuery
|
|
39
|
+
|
|
40
|
+
SpatialQuery is a Python package for systematic spatial analysis of single-cell resolution spatial omics data. It provides a unified framework to discover, quantify, and compare recurring spatial cell type patterns — termed *motifs* — across single or multiple fields of view (FOVs).
|
|
41
|
+
|
|
42
|
+
Starting from annotated spatial omics datasets (spatial transcriptomics and spatial proteomics data), SpatialQuery constructs cell neighborhoods using KNN or distance-based approaches and mines frequent cell type co-occurrence patterns via the FP-Growth algorithm. It then tests whether these motifs are statistically enriched beyond what is expected by chance, and supports comparison of motif compositions across biological conditions (e.g., healthy vs. disease) through differential motif analysis.
|
|
43
|
+
|
|
44
|
+
Beyond spatial structure, SpatialQuery links motifs to molecular phenotypes. For cells participating in a given motif, it performs motif-associated differential expression analysis to identify genes whose expression differs between motif-positive and motif-negative cells or across conditions. It further detects cross-cell gene-gene covariation — spatially dependent correlations between gene expression in anchor cells and their neighbors — to reveal intercellular signaling relationships that are specific to particular spatial contexts.
|
|
45
|
+
|
|
46
|
+
Key capabilities include:
|
|
47
|
+
|
|
48
|
+
- **Spatial motif discovery**: Identify frequent cell type patterns in local neighborhoods
|
|
49
|
+
- **Motif enrichment analysis**: Statistically test whether motifs occur more than expected
|
|
50
|
+
- **Differential motif analysis**: Compare spatial compositions across conditions
|
|
51
|
+
- **Motif-associated differential expression**: Find DE genes linked to specific motifs
|
|
52
|
+
- **Cross-cell gene-gene covariation**: Detect spatially dependent intercellular gene correlations
|
|
53
|
+
- **Multi-FOV support**: Pool and compare results across multiple tissue sections or samples
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install SpatialQuery
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Documentation
|
|
62
|
+
|
|
63
|
+
Full documentation, tutorials, and API reference: **[https://spatialquery.readthedocs.io/en/latest/](https://spatialquery.readthedocs.io/en/latest/)**
|
|
64
|
+
|
|
65
|
+
## Reproducibility
|
|
66
|
+
|
|
67
|
+
The following tutorials reproduce the main analyses presented in our manuscript:
|
|
68
|
+
|
|
69
|
+
- [Mouse organogenesis — single-FOV analysis (seqFISH)](https://spatialquery.readthedocs.io/en/latest/tutorials/tutorial_1.html)
|
|
70
|
+
- [Kidney disease atlas — multi-condition analysis (MERFISH)](https://spatialquery.readthedocs.io/en/latest/tutorials/tutorial_2.html)
|
|
71
|
+
- [Colorectal cancer microenvironment — spatial proteomics (CODEX)](https://spatialquery.readthedocs.io/en/latest/tutorials/tutorial_3.html)
|
|
72
|
+
- [Whole-brain atlas — large-scale analysis (MERFISH)](https://spatialquery.readthedocs.io/en/latest/tutorials/tutorial_4.html)
|
|
73
|
+
|
|
74
|
+
## Quick Start
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from SpatialQuery import spatial_query
|
|
78
|
+
|
|
79
|
+
# Single FOV analysis
|
|
80
|
+
sq = spatial_query(adata, spatial_key="X_spatial", label_key="cell_type", feature_name="gene")
|
|
81
|
+
enrich_motif = sq.motif_enrichment_dist(ct="T_cell", max_dist=10, min_support=0.5)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
from SpatialQuery import spatial_query_multi
|
|
86
|
+
|
|
87
|
+
# Multi-FOV analysis
|
|
88
|
+
spm = spatial_query_multi(adatas=adatas, datasets=datasets,
|
|
89
|
+
spatial_key="X_spatial", label_key="cell_type", feature_name="gene")
|
|
90
|
+
enrich_motif = spm.motif_enrichment_dist(ct="T_cell", dataset="healthy", max_dist=10, min_support=0.5)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## License
|
|
94
|
+
|
|
95
|
+
MIT
|
|
96
|
+
|
|
97
|
+
## Contact
|
|
98
|
+
|
|
99
|
+
- **Author**: Shaokun An
|
|
100
|
+
- **Email**: shaokunan1@gmail.com
|
|
101
|
+
- **GitHub**: [ShaokunAn](https://github.com/ShaokunAn)
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# SpatialQuery
|
|
2
|
+
|
|
3
|
+
SpatialQuery is a Python package for systematic spatial analysis of single-cell resolution spatial omics data. It provides a unified framework to discover, quantify, and compare recurring spatial cell type patterns — termed *motifs* — across single or multiple fields of view (FOVs).
|
|
4
|
+
|
|
5
|
+
Starting from annotated spatial omics datasets (spatial transcriptomics and spatial proteomics data), SpatialQuery constructs cell neighborhoods using KNN or distance-based approaches and mines frequent cell type co-occurrence patterns via the FP-Growth algorithm. It then tests whether these motifs are statistically enriched beyond what is expected by chance, and supports comparison of motif compositions across biological conditions (e.g., healthy vs. disease) through differential motif analysis.
|
|
6
|
+
|
|
7
|
+
Beyond spatial structure, SpatialQuery links motifs to molecular phenotypes. For cells participating in a given motif, it performs motif-associated differential expression analysis to identify genes whose expression differs between motif-positive and motif-negative cells or across conditions. It further detects cross-cell gene-gene covariation — spatially dependent correlations between gene expression in anchor cells and their neighbors — to reveal intercellular signaling relationships that are specific to particular spatial contexts.
|
|
8
|
+
|
|
9
|
+
Key capabilities include:
|
|
10
|
+
|
|
11
|
+
- **Spatial motif discovery**: Identify frequent cell type patterns in local neighborhoods
|
|
12
|
+
- **Motif enrichment analysis**: Statistically test whether motifs occur more than expected
|
|
13
|
+
- **Differential motif analysis**: Compare spatial compositions across conditions
|
|
14
|
+
- **Motif-associated differential expression**: Find DE genes linked to specific motifs
|
|
15
|
+
- **Cross-cell gene-gene covariation**: Detect spatially dependent intercellular gene correlations
|
|
16
|
+
- **Multi-FOV support**: Pool and compare results across multiple tissue sections or samples
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install SpatialQuery
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Documentation
|
|
25
|
+
|
|
26
|
+
Full documentation, tutorials, and API reference: **[https://spatialquery.readthedocs.io/en/latest/](https://spatialquery.readthedocs.io/en/latest/)**
|
|
27
|
+
|
|
28
|
+
## Reproducibility
|
|
29
|
+
|
|
30
|
+
The following tutorials reproduce the main analyses presented in our manuscript:
|
|
31
|
+
|
|
32
|
+
- [Mouse organogenesis — single-FOV analysis (seqFISH)](https://spatialquery.readthedocs.io/en/latest/tutorials/tutorial_1.html)
|
|
33
|
+
- [Kidney disease atlas — multi-condition analysis (MERFISH)](https://spatialquery.readthedocs.io/en/latest/tutorials/tutorial_2.html)
|
|
34
|
+
- [Colorectal cancer microenvironment — spatial proteomics (CODEX)](https://spatialquery.readthedocs.io/en/latest/tutorials/tutorial_3.html)
|
|
35
|
+
- [Whole-brain atlas — large-scale analysis (MERFISH)](https://spatialquery.readthedocs.io/en/latest/tutorials/tutorial_4.html)
|
|
36
|
+
|
|
37
|
+
## Quick Start
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from SpatialQuery import spatial_query
|
|
41
|
+
|
|
42
|
+
# Single FOV analysis
|
|
43
|
+
sq = spatial_query(adata, spatial_key="X_spatial", label_key="cell_type", feature_name="gene")
|
|
44
|
+
enrich_motif = sq.motif_enrichment_dist(ct="T_cell", max_dist=10, min_support=0.5)
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from SpatialQuery import spatial_query_multi
|
|
49
|
+
|
|
50
|
+
# Multi-FOV analysis
|
|
51
|
+
spm = spatial_query_multi(adatas=adatas, datasets=datasets,
|
|
52
|
+
spatial_key="X_spatial", label_key="cell_type", feature_name="gene")
|
|
53
|
+
enrich_motif = spm.motif_enrichment_dist(ct="T_cell", dataset="healthy", max_dist=10, min_support=0.5)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## License
|
|
57
|
+
|
|
58
|
+
MIT
|
|
59
|
+
|
|
60
|
+
## Contact
|
|
61
|
+
|
|
62
|
+
- **Author**: Shaokun An
|
|
63
|
+
- **Email**: shaokunan1@gmail.com
|
|
64
|
+
- **GitHub**: [ShaokunAn](https://github.com/ShaokunAn)
|
|
@@ -31,39 +31,6 @@ class spatial_query:
|
|
|
31
31
|
|
|
32
32
|
A class for performing spatial query analysis on spatial transcriptomics data of a single field of view,
|
|
33
33
|
including pattern discovery, enrichment analysis, differential analysis, and gene-gene covariation assessment.
|
|
34
|
-
|
|
35
|
-
Parameters
|
|
36
|
-
----------
|
|
37
|
-
adata : AnnData
|
|
38
|
-
Annotated data object containing expression matrix and metadata.
|
|
39
|
-
dataset : str, default='ST'
|
|
40
|
-
Dataset identifier.
|
|
41
|
-
spatial_key : str, default='X_spatial'
|
|
42
|
-
Key in adata.obsm containing spatial coordinates (n_obs, 2).
|
|
43
|
-
label_key : str, default='cell_type'
|
|
44
|
-
Key in adata.obs containing cell type annotations.
|
|
45
|
-
leaf_size : int, default=10
|
|
46
|
-
Leaf size parameter for KDTree construction. Larger values reduce tree depth
|
|
47
|
-
but increase computation per query.
|
|
48
|
-
build_gene_index : bool, default=False
|
|
49
|
-
If True, constructs SCFind index by compressing original data to binary format to save memory.
|
|
50
|
-
If False, uses original expression matrix from adata.X directly.
|
|
51
|
-
feature_name : str, default='gene'
|
|
52
|
-
Column name in adata.var containing feature identifiers.
|
|
53
|
-
if_lognorm : bool, default=True
|
|
54
|
-
If True, applies log1p transformation after library size normalization.
|
|
55
|
-
Set to False if expression data is already normalized and no more transformation is required.
|
|
56
|
-
if_normalize_spatial_coord : bool, default=True
|
|
57
|
-
If True, normalizes spatial coordinates so mean nearest neighbor distance equals 1.
|
|
58
|
-
This makes max_dist parameter interpretable as "number of cell diameters."
|
|
59
|
-
Set to False if original spatial units (e.g., micrometers) are required and
|
|
60
|
-
should be preserved for downstream analysis.
|
|
61
|
-
|
|
62
|
-
Notes
|
|
63
|
-
-----
|
|
64
|
-
When if_normalize_spatial_coord=True, the max_dist parameter in query functions
|
|
65
|
-
represents relative spatial scale (in units of mean nearest neighbor distance).
|
|
66
|
-
When if_normalize_spatial_coord=False, max_dist uses original coordinate units.
|
|
67
34
|
"""
|
|
68
35
|
def __init__(
|
|
69
36
|
self,
|
|
@@ -77,6 +44,42 @@ class spatial_query:
|
|
|
77
44
|
if_lognorm: bool = True,
|
|
78
45
|
if_normalize_spatial_coord: bool = True
|
|
79
46
|
):
|
|
47
|
+
"""
|
|
48
|
+
Initialize spatial_query object.
|
|
49
|
+
|
|
50
|
+
Parameters
|
|
51
|
+
----------
|
|
52
|
+
adata : AnnData
|
|
53
|
+
Annotated data object containing expression matrix and metadata.
|
|
54
|
+
dataset : str, default='ST'
|
|
55
|
+
Dataset identifier.
|
|
56
|
+
spatial_key : str, default='X_spatial'
|
|
57
|
+
Key in adata.obsm containing spatial coordinates (n_obs, 2).
|
|
58
|
+
label_key : str, default='cell_type'
|
|
59
|
+
Key in adata.obs containing cell type annotations.
|
|
60
|
+
leaf_size : int, default=10
|
|
61
|
+
Leaf size parameter for KDTree construction. Larger values reduce tree depth
|
|
62
|
+
but increase computation per query.
|
|
63
|
+
build_gene_index : bool, default=False
|
|
64
|
+
If True, constructs SCFind index by compressing original data to binary format to save memory.
|
|
65
|
+
If False, uses original expression matrix from adata.X directly.
|
|
66
|
+
feature_name : str, default='gene'
|
|
67
|
+
Column name in adata.var containing feature identifiers.
|
|
68
|
+
if_lognorm : bool, default=True
|
|
69
|
+
If True, applies log1p transformation after library size normalization.
|
|
70
|
+
Set to False if expression data is already normalized and no more transformation is required.
|
|
71
|
+
if_normalize_spatial_coord : bool, default=True
|
|
72
|
+
If True, normalizes spatial coordinates so mean nearest neighbor distance equals 1.
|
|
73
|
+
This makes max_dist parameter interpretable as "number of cell diameters."
|
|
74
|
+
Set to False if original spatial units (e.g., micrometers) are required and
|
|
75
|
+
should be preserved for downstream analysis.
|
|
76
|
+
|
|
77
|
+
Notes
|
|
78
|
+
-----
|
|
79
|
+
When if_normalize_spatial_coord=True, the max_dist parameter in query functions
|
|
80
|
+
represents relative spatial scale (in units of mean nearest neighbor distance).
|
|
81
|
+
When if_normalize_spatial_coord=False, max_dist uses original coordinate units.
|
|
82
|
+
"""
|
|
80
83
|
if spatial_key not in adata.obsm.keys() or label_key not in adata.obs.keys():
|
|
81
84
|
raise ValueError(f"The Anndata object must contain {spatial_key} in obsm and {label_key} in obs.")
|
|
82
85
|
|
|
@@ -1533,6 +1536,7 @@ def interactive_motif(
|
|
|
1533
1536
|
sp,
|
|
1534
1537
|
zarr_path: str,
|
|
1535
1538
|
spatialSpotRadius: float = 1,
|
|
1539
|
+
use_adata_store: bool = False,
|
|
1536
1540
|
):
|
|
1537
1541
|
"""
|
|
1538
1542
|
Create an interactive Vitessce widget to explore spatial motifs.
|
|
@@ -1555,6 +1559,9 @@ def interactive_motif(
|
|
|
1555
1559
|
spatialSpotRadius : float, default=1
|
|
1556
1560
|
Radius for spatial spots in the Vitessce visualization. Adjust based
|
|
1557
1561
|
on data density and spatial coordinate scale.
|
|
1562
|
+
use_adata_store : bool, default=False
|
|
1563
|
+
If True, pass the zarr path via ``adata_store`` (for HubMAP workspace).
|
|
1564
|
+
If False, pass via ``adata_path`` (for local usage).
|
|
1558
1565
|
|
|
1559
1566
|
Returns
|
|
1560
1567
|
-------
|
|
@@ -1635,8 +1642,9 @@ def interactive_motif(
|
|
|
1635
1642
|
|
|
1636
1643
|
vc = VitessceConfig(schema_version="1.0.16", name="SpatialQuery")
|
|
1637
1644
|
|
|
1645
|
+
_adata_key = "adata_store" if use_adata_store else "adata_path"
|
|
1638
1646
|
wrapper_kwargs = dict(
|
|
1639
|
-
|
|
1647
|
+
**{_adata_key: zarr_path},
|
|
1640
1648
|
obs_set_paths=[f"obs/{label_key}"],
|
|
1641
1649
|
obs_set_names=["Cell Type"],
|
|
1642
1650
|
obs_spots_path=f"obsm/{spatial_key}",
|
|
@@ -1649,7 +1657,6 @@ def interactive_motif(
|
|
|
1649
1657
|
dataset = vc.add_dataset("Query results").add_object(AnnDataWrapper(**wrapper_kwargs))
|
|
1650
1658
|
|
|
1651
1659
|
spatial_view = vc.add_view("spatialBeta", dataset=dataset)
|
|
1652
|
-
lc_view = vc.add_view("layerControllerBeta", dataset=dataset)
|
|
1653
1660
|
sets_view = vc.add_view("obsSets", dataset=dataset)
|
|
1654
1661
|
sq_view = vc.add_view("spatialQuery", dataset=dataset)
|
|
1655
1662
|
sq_heatmap_view = vc.add_view("spatialQueryHeatmap", dataset=dataset)
|
|
@@ -1658,7 +1665,7 @@ def interactive_motif(
|
|
|
1658
1665
|
["Cell Type", ct] for ct in sp.labels.unique().tolist()
|
|
1659
1666
|
]
|
|
1660
1667
|
|
|
1661
|
-
linked_views = [spatial_view,
|
|
1668
|
+
linked_views = [spatial_view, sets_view, sq_view]
|
|
1662
1669
|
if has_expression:
|
|
1663
1670
|
features_view = vc.add_view("featureList", dataset=dataset)
|
|
1664
1671
|
linked_views.append(features_view)
|
|
@@ -1669,21 +1676,21 @@ def interactive_motif(
|
|
|
1669
1676
|
[plugin.additional_obs_sets, plugin.obs_set_color, initial_obs_set_selection, "cellSetSelection"],
|
|
1670
1677
|
)
|
|
1671
1678
|
|
|
1672
|
-
vc.link_views_by_dict([spatial_view
|
|
1679
|
+
vc.link_views_by_dict([spatial_view], {
|
|
1673
1680
|
"spotLayer": CL([{"obsType": "cell", "spatialSpotRadius": spatialSpotRadius}]),
|
|
1674
1681
|
})
|
|
1675
1682
|
|
|
1676
1683
|
if has_expression:
|
|
1677
1684
|
vc.layout(
|
|
1678
1685
|
vconcat(
|
|
1679
|
-
hconcat(spatial_view,
|
|
1686
|
+
hconcat(spatial_view, features_view, split=[2, 1]),
|
|
1680
1687
|
hconcat(sets_view, sq_heatmap_view, sq_view),
|
|
1681
1688
|
)
|
|
1682
1689
|
)
|
|
1683
1690
|
else:
|
|
1684
1691
|
vc.layout(
|
|
1685
1692
|
vconcat(
|
|
1686
|
-
|
|
1693
|
+
spatial_view,
|
|
1687
1694
|
hconcat(sets_view, sq_heatmap_view, sq_view),
|
|
1688
1695
|
)
|
|
1689
1696
|
)
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: SpatialQuery
|
|
3
|
+
Version: 0.0.5
|
|
4
|
+
Summary: Spatial query tools for analyzing spatial transcriptomics data
|
|
5
|
+
Author-email: Shaokun An <shan12@bwh.harvard.edu>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/ShaokunAn/Spatial-Query
|
|
8
|
+
Project-URL: Documentation, https://spatial-query.readthedocs.io
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: numpy>=1.23.0
|
|
19
|
+
Requires-Dist: anndata>=0.8.0
|
|
20
|
+
Requires-Dist: pandas>=2.0.3
|
|
21
|
+
Requires-Dist: scipy>=1.10.0
|
|
22
|
+
Requires-Dist: matplotlib>=3.7.5
|
|
23
|
+
Requires-Dist: scikit-learn>=1.3.2
|
|
24
|
+
Requires-Dist: scanpy>=1.9.5
|
|
25
|
+
Requires-Dist: statsmodels>=0.14.0
|
|
26
|
+
Requires-Dist: seaborn>=0.13.2
|
|
27
|
+
Requires-Dist: mlxtend>=0.23.1
|
|
28
|
+
Requires-Dist: tqdm>=4.60.0
|
|
29
|
+
Requires-Dist: zarr>=2.14.0
|
|
30
|
+
Provides-Extra: docs
|
|
31
|
+
Requires-Dist: sphinx>=5.3; extra == "docs"
|
|
32
|
+
Requires-Dist: sphinx-rtd-theme; extra == "docs"
|
|
33
|
+
Requires-Dist: sphinx-autodoc-typehints; extra == "docs"
|
|
34
|
+
Requires-Dist: sphinx-copybutton; extra == "docs"
|
|
35
|
+
Requires-Dist: myst-parser; extra == "docs"
|
|
36
|
+
Dynamic: license-file
|
|
37
|
+
|
|
38
|
+
# SpatialQuery
|
|
39
|
+
|
|
40
|
+
SpatialQuery is a Python package for systematic spatial analysis of single-cell resolution spatial omics data. It provides a unified framework to discover, quantify, and compare recurring spatial cell type patterns — termed *motifs* — across single or multiple fields of view (FOVs).
|
|
41
|
+
|
|
42
|
+
Starting from annotated spatial omics datasets (spatial transcriptomics and spatial proteomics data), SpatialQuery constructs cell neighborhoods using KNN or distance-based approaches and mines frequent cell type co-occurrence patterns via the FP-Growth algorithm. It then tests whether these motifs are statistically enriched beyond what is expected by chance, and supports comparison of motif compositions across biological conditions (e.g., healthy vs. disease) through differential motif analysis.
|
|
43
|
+
|
|
44
|
+
Beyond spatial structure, SpatialQuery links motifs to molecular phenotypes. For cells participating in a given motif, it performs motif-associated differential expression analysis to identify genes whose expression differs between motif-positive and motif-negative cells or across conditions. It further detects cross-cell gene-gene covariation — spatially dependent correlations between gene expression in anchor cells and their neighbors — to reveal intercellular signaling relationships that are specific to particular spatial contexts.
|
|
45
|
+
|
|
46
|
+
Key capabilities include:
|
|
47
|
+
|
|
48
|
+
- **Spatial motif discovery**: Identify frequent cell type patterns in local neighborhoods
|
|
49
|
+
- **Motif enrichment analysis**: Statistically test whether motifs occur more than expected
|
|
50
|
+
- **Differential motif analysis**: Compare spatial compositions across conditions
|
|
51
|
+
- **Motif-associated differential expression**: Find DE genes linked to specific motifs
|
|
52
|
+
- **Cross-cell gene-gene covariation**: Detect spatially dependent intercellular gene correlations
|
|
53
|
+
- **Multi-FOV support**: Pool and compare results across multiple tissue sections or samples
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install SpatialQuery
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Documentation
|
|
62
|
+
|
|
63
|
+
Full documentation, tutorials, and API reference: **[https://spatialquery.readthedocs.io/en/latest/](https://spatialquery.readthedocs.io/en/latest/)**
|
|
64
|
+
|
|
65
|
+
## Reproducibility
|
|
66
|
+
|
|
67
|
+
The following tutorials reproduce the main analyses presented in our manuscript:
|
|
68
|
+
|
|
69
|
+
- [Mouse organogenesis — single-FOV analysis (seqFISH)](https://spatialquery.readthedocs.io/en/latest/tutorials/tutorial_1.html)
|
|
70
|
+
- [Kidney disease atlas — multi-condition analysis (MERFISH)](https://spatialquery.readthedocs.io/en/latest/tutorials/tutorial_2.html)
|
|
71
|
+
- [Colorectal cancer microenvironment — spatial proteomics (CODEX)](https://spatialquery.readthedocs.io/en/latest/tutorials/tutorial_3.html)
|
|
72
|
+
- [Whole-brain atlas — large-scale analysis (MERFISH)](https://spatialquery.readthedocs.io/en/latest/tutorials/tutorial_4.html)
|
|
73
|
+
|
|
74
|
+
## Quick Start
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from SpatialQuery import spatial_query
|
|
78
|
+
|
|
79
|
+
# Single FOV analysis
|
|
80
|
+
sq = spatial_query(adata, spatial_key="X_spatial", label_key="cell_type", feature_name="gene")
|
|
81
|
+
enrich_motif = sq.motif_enrichment_dist(ct="T_cell", max_dist=10, min_support=0.5)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
from SpatialQuery import spatial_query_multi
|
|
86
|
+
|
|
87
|
+
# Multi-FOV analysis
|
|
88
|
+
spm = spatial_query_multi(adatas=adatas, datasets=datasets,
|
|
89
|
+
spatial_key="X_spatial", label_key="cell_type", feature_name="gene")
|
|
90
|
+
enrich_motif = spm.motif_enrichment_dist(ct="T_cell", dataset="healthy", max_dist=10, min_support=0.5)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## License
|
|
94
|
+
|
|
95
|
+
MIT
|
|
96
|
+
|
|
97
|
+
## Contact
|
|
98
|
+
|
|
99
|
+
- **Author**: Shaokun An
|
|
100
|
+
- **Email**: shaokunan1@gmail.com
|
|
101
|
+
- **GitHub**: [ShaokunAn](https://github.com/ShaokunAn)
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "SpatialQuery"
|
|
7
|
-
version = "0.0.
|
|
7
|
+
version = "0.0.5"
|
|
8
8
|
description = "Spatial query tools for analyzing spatial transcriptomics data"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
@@ -37,6 +37,7 @@ dependencies = [
|
|
|
37
37
|
|
|
38
38
|
[project.urls]
|
|
39
39
|
Homepage = "https://github.com/ShaokunAn/Spatial-Query"
|
|
40
|
+
Documentation = "https://spatial-query.readthedocs.io"
|
|
40
41
|
|
|
41
42
|
[project.optional-dependencies]
|
|
42
43
|
docs = [
|