cytocommunity2 0.1.7__tar.gz → 1.0.0__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 (43) hide show
  1. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/LICENSE +21 -21
  2. {cytocommunity2-0.1.7/src/cytocommunity2.egg-info → cytocommunity2-1.0.0}/PKG-INFO +156 -166
  3. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/README.md +136 -145
  4. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/pyproject.toml +27 -31
  5. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/setup.cfg +4 -4
  6. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/__init__.py +23 -23
  7. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/config.py +70 -69
  8. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/downstream/__init__.py +16 -16
  9. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/downstream/coherence.py +97 -115
  10. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/downstream/communication/__init__.py +2 -2
  11. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/downstream/communication/between.py +132 -142
  12. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/downstream/communication/cca.py +319 -320
  13. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/downstream/communication/utils.py +63 -63
  14. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/downstream/communication/within.py +264 -264
  15. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/downstream/differential_composition.py +218 -224
  16. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/downstream/dominant_celltype.py +55 -63
  17. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/downstream/moran.py +265 -309
  18. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/downstream/plotting/__init__.py +3 -3
  19. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/downstream/plotting/cn_selection.py +2 -11
  20. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/downstream/plotting/coherence.py +0 -5
  21. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/downstream/plotting/common.py +79 -79
  22. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/downstream/plotting/communication.py +5 -7
  23. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/downstream/plotting/composition.py +80 -80
  24. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/downstream/plotting/dominant.py +3 -6
  25. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/downstream/plotting/dotplots.py +255 -255
  26. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/downstream/plotting/recurrence.py +0 -6
  27. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/downstream/runtime.py +13 -13
  28. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/ensemble.py +261 -255
  29. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/learning/__init__.py +7 -7
  30. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/learning/api.py +136 -141
  31. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/learning/dataset.py +129 -129
  32. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/learning/model.py +122 -122
  33. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/learning/selection.py +184 -200
  34. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/learning/training.py +201 -201
  35. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/paths.py +50 -50
  36. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/visualization/__init__.py +5 -5
  37. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/visualization/spatial.py +94 -116
  38. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0/src/cytocommunity2.egg-info}/PKG-INFO +156 -166
  39. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2.egg-info/requires.txt +3 -5
  40. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2/colors.py +0 -0
  41. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2.egg-info/SOURCES.txt +0 -0
  42. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2.egg-info/dependency_links.txt +0 -0
  43. {cytocommunity2-0.1.7 → cytocommunity2-1.0.0}/src/cytocommunity2.egg-info/top_level.txt +0 -0
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 huBioinfo
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 huBioinfo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,166 +1,156 @@
1
- Metadata-Version: 2.4
2
- Name: cytocommunity2
3
- Version: 0.1.7
4
- Summary: Weakly supervised cellular-neighborhood learning for spatial omics
5
- Requires-Python: >=3.10
6
- Description-Content-Type: text/markdown
7
- License-File: LICENSE
8
- Requires-Dist: matplotlib>=3.6
9
- Requires-Dist: numpy<2,>=1.23
10
- Requires-Dist: pandas<3,>=1.5
11
- Requires-Dist: sci-palettes
12
- Requires-Dist: scikit-learn>=1.1
13
- Requires-Dist: scipy>=1.11
14
- Requires-Dist: seaborn>=0.12
15
- Requires-Dist: torch-geometric>=2.0
16
- Provides-Extra: downstream
17
- Requires-Dist: esda<2.6,>=2.5; extra == "downstream"
18
- Requires-Dist: jupyter; extra == "downstream"
19
- Requires-Dist: libpysal<4.10,>=4.9; extra == "downstream"
20
- Dynamic: license-file
21
-
22
- # CytoCommunity2
23
-
24
- ## Contents
25
-
26
- - [Overview](#overview)
27
- - [Installation](#installation)
28
- - [Usage](#usage)
29
- - [Maintainers](#maintainers)
30
- - [Citation](#citation)
31
-
32
- ## Overview
33
-
34
- To enhance CytoCommunity (https://github.com/huBioinfo/CytoCommunity), we
35
- present CytoCommunity2, **a unified weakly-supervised framework** for
36
- identifying and comparing tissue cellular neighborhoods (TCNs or CNs) across
37
- **large-scale spatial omics samples with single or multiple biological
38
- conditions**.
39
-
40
- Inspired by histopathology workflows, CytoCommunity2 first hierarchically
41
- partitions the large single-cell spatial map into small patches, performs graph
42
- construction and weakly supervised TCN learning for each patch, and finally
43
- merges results through KNN-based TCN reassignment at segmentation boundaries to
44
- ensure TCN spatial continuity. This strategy divides the original sample into
45
- patches for TCN learning, achieving **memory efficiency (typical 24G graphics
46
- memory is enough)** and also increased sample throughput. These optimizations
47
- significantly **enhance the robustness of TCNs and cross-sample alignment
48
- performance**.
49
-
50
- Furthermore, to make CytoCommunity2 a unified framework that is also
51
- **applicable for single-condition spatial omics datasets**, pseudo-samples with
52
- artificial labels are generated, enabling automatic TCN alignment across real
53
- samples via **contrastive learning**.
54
-
55
- **_In summary, the advantages of CytoCommunity2 include:_**
56
-
57
- **_(1) Using significantly less memory for large-scale spatial omics samples
58
- with millions of cells._**
59
-
60
- **_(2) A unified weakly-supervised model applicable for both multi-condition
61
- and single-condition datasets._**
62
-
63
- **_(3) High TCN alignment performance makes it well-suited for comparative
64
- analysis in large cohort studies._**
65
-
66
- ## Installation
67
-
68
- ### Hardware requirement
69
-
70
- Graphics memory: 24G
71
-
72
- Storage: 10GB or more
73
-
74
- ### Install CytoCommunity2
75
-
76
- CytoCommunity2 requires Python 3.10 or newer. We recommend creating and
77
- activating a Conda environment first:
78
-
79
- ```bash
80
- conda create -n cytocommunity2 python=3.10
81
- conda activate cytocommunity2
82
- ```
83
-
84
- For an NVIDIA GPU on Windows or Linux, first install the appropriate
85
- CUDA-enabled PyTorch build from the
86
- [official PyTorch installation page](https://pytorch.org/get-started/locally/).
87
-
88
- Install the package:
89
-
90
- ```bash
91
- pip install cytocommunity2
92
- ```
93
-
94
- To run the downstream analyses, install the
95
- optional downstream dependencies with:
96
-
97
- ```bash
98
- pip install "cytocommunity2[downstream]"
99
- ```
100
-
101
- This extra includes `esda`, `libpysal`, and Jupyter; they are not installed
102
- by the basic command above.
103
-
104
- ## Usage
105
-
106
- ### 1. Prepare input data
107
-
108
- The input data to CytoCommunity2 includes four types of files :
109
-
110
- (1) An image (sample) name list file, named as "ImageNameList.txt".
111
-
112
- (2) A cell type label file for each image (sample), named as "[image
113
- name]_CellTypeLabel.txt". Note that [image_name] should be consistent with your
114
- customized image names listed in the "ImageNameList.txt". This file lists cell
115
- type names of all cells in an image (sample).
116
-
117
- (3) A cell spatial coordinate file for each image (sample), named as "[image
118
- name]_Coordinates.txt". Note that [image_name] should be consistent with your
119
- customized image names listed in the "ImageNameList.txt". This file lists cell
120
- coordinates (tab-delimited x/y) of all cells in an image (sample). The cell
121
- orders should be exactly the same with "[image name]_CellTypeLabel.txt".
122
-
123
- (4) A graph label file for each image (sample), named as "[image
124
- name]_GraphLabel.txt". For multi-condition datasets, this file must be provided
125
- for every image (sample) and contain one integer indicating its biological
126
- condition. For single-condition datasets, graph label
127
- files can be omitted for all images (samples), and CytoCommunity2 will generate
128
- pseudo-samples for weakly-supervised learning.
129
-
130
- ### 2. Configure CytoCommunity2
131
-
132
- Before running CytoCommunity2, set `input_dir` and review all
133
- model and downstream parameters in
134
- [`hyperparameters.json`](https://github.com/LiukangWu/CytoCommunity2/blob/main/hyperparameters.json). The Python workflow will use this configuration file.
135
-
136
- ### 3. Run CytoCommunity2
137
-
138
- The tutorial uses a TNBC dataset as a worked example and demonstrates the
139
- entire CytoCommunity2 workflow, from model training and CN identification to
140
- downstream analysis:
141
-
142
- ```bash
143
- jupyter notebook tutorial/TNBC_workflow.ipynb
144
- ```
145
-
146
- ### 4. Output files
147
-
148
- The main output directories are:
149
-
150
- - `CNLearning_Output/`: CN-number screening, trained models and CN labels.
151
- - `CNVisualization_Output/`: spatial plots and result tables.
152
- - `data/`: downstream analysis results and intermediate data tables.
153
- - `plot/`: figures generated by downstream analyses.
154
-
155
- ## Maintainers
156
-
157
- - Liukang Wu (yetong@stu.xidian.edu.cn)
158
- - Yafei Xu (22031212416@stu.xidian.edu.cn)
159
- - Yuxuan Hu (huyuxuan@xidian.edu.cn)
160
-
161
- ## Citation
162
-
163
- Yuxuan Hu, Jiazhen Rong, Yafei Xu, Runzhi Xie, Jacqueline Peng, Lin Gao, and
164
- Kai Tan. “Unsupervised and supervised discovery of tissue cellular
165
- neighborhoods from cell phenotypes.” *Nature Methods* 21 (2024): 267–278.
166
- https://doi.org/10.1038/s41592-023-02124-2
1
+ Metadata-Version: 2.4
2
+ Name: cytocommunity2
3
+ Version: 1.0.0
4
+ Summary: Weakly supervised cellular-neighborhood learning for spatial omics
5
+ Requires-Python: >=3.10
6
+ Description-Content-Type: text/markdown
7
+ License-File: LICENSE
8
+ Requires-Dist: esda<2.6,>=2.5
9
+ Requires-Dist: jupyter
10
+ Requires-Dist: libpysal<4.10,>=4.9
11
+ Requires-Dist: matplotlib>=3.6
12
+ Requires-Dist: numpy<2,>=1.23
13
+ Requires-Dist: pandas<3,>=1.5
14
+ Requires-Dist: sci-palettes
15
+ Requires-Dist: scikit-learn>=1.1
16
+ Requires-Dist: scipy>=1.11
17
+ Requires-Dist: seaborn>=0.12
18
+ Requires-Dist: torch-geometric>=2.0
19
+ Dynamic: license-file
20
+
21
+ # CytoCommunity2
22
+
23
+ ## Contents
24
+
25
+ - [Overview](#overview)
26
+ - [Installation](#installation)
27
+ - [Usage](#usage)
28
+ - [Maintainers](#maintainers)
29
+ - [Citation](#citation)
30
+
31
+ ## Overview
32
+
33
+ To enhance CytoCommunity (https://github.com/huBioinfo/CytoCommunity), we
34
+ present CytoCommunity2, **a unified weakly-supervised framework** for
35
+ identifying and comparing tissue cellular neighborhoods (TCNs or CNs) across
36
+ **large-scale spatial omics samples with single or multiple biological
37
+ conditions**.
38
+
39
+ Inspired by histopathology workflows, CytoCommunity2 first hierarchically
40
+ partitions the large single-cell spatial map into small patches, performs graph
41
+ construction and weakly supervised CN learning for each patch, and finally
42
+ merges results through KNN-based CN reassignment at segmentation boundaries to
43
+ ensure CN spatial continuity. This strategy divides the original sample into
44
+ patches for CN learning, achieving **memory efficiency (typical 24G graphics
45
+ memory is enough)** and also increased sample throughput. These optimizations
46
+ significantly **enhance the robustness of CNs and cross-sample alignment
47
+ performance**.
48
+
49
+ Furthermore, to make CytoCommunity2 a unified framework that is also
50
+ **applicable for single-condition spatial omics datasets**, pseudo-samples with
51
+ artificial labels are generated, enabling automatic CN alignment across real
52
+ samples via **contrastive learning**.
53
+
54
+ **_In summary, the advantages of CytoCommunity2 include:_**
55
+
56
+ **_(1) Using significantly less memory for large-scale spatial omics samples
57
+ with millions of cells._**
58
+
59
+ **_(2) A unified weakly-supervised model applicable for both multi-condition
60
+ and single-condition datasets._**
61
+
62
+ **_(3) High CN alignment performance makes it well-suited for comparative
63
+ analysis in large cohort studies._**
64
+
65
+ ## Installation
66
+
67
+ ### Hardware requirement
68
+
69
+ Graphics memory: 24G
70
+
71
+ Storage: 10GB or more
72
+
73
+ ### Install CytoCommunity2
74
+
75
+ CytoCommunity2 requires Python 3.10 or newer. We recommend creating and
76
+ activating a Conda environment first:
77
+
78
+ ```bash
79
+ conda create -n cytocommunity2 python=3.10
80
+ conda activate cytocommunity2
81
+ ```
82
+
83
+ For an NVIDIA GPU on Windows or Linux, first install the appropriate
84
+ CUDA-enabled PyTorch build from the
85
+ [official PyTorch installation page](https://pytorch.org/get-started/locally/).
86
+
87
+ Install the package via pip:
88
+
89
+ ```bash
90
+ pip install cytocommunity2
91
+ ```
92
+
93
+ ## Usage
94
+
95
+ ### 1. Prepare input data
96
+
97
+ The input data to CytoCommunity2 includes four types of files :
98
+
99
+ (1) An image (sample) name list file, named as "ImageNameList.txt".
100
+
101
+ (2) A cell type label file for each image (sample), named as "[image
102
+ name]_CellTypeLabel.txt". Note that [image_name] should be consistent with your
103
+ customized image names listed in the "ImageNameList.txt". This file lists cell
104
+ type names of all cells in an image (sample).
105
+
106
+ (3) A cell spatial coordinate file for each image (sample), named as "[image
107
+ name]_Coordinates.txt". Note that [image_name] should be consistent with your
108
+ customized image names listed in the "ImageNameList.txt". This file lists cell
109
+ coordinates (tab-delimited x/y) of all cells in an image (sample). The cell
110
+ orders should be exactly the same with "[image name]_CellTypeLabel.txt".
111
+
112
+ (4) A graph label file for each image (sample), named as "[image
113
+ name]_GraphLabel.txt". For multi-condition datasets, this file must be provided
114
+ for every image (sample) and contain one integer indicating its biological
115
+ condition. For single-condition datasets, graph label
116
+ files can be omitted for all images (samples), and CytoCommunity2 will generate
117
+ pseudo-samples for weakly-supervised learning.
118
+
119
+ ### 2. Configure CytoCommunity2
120
+
121
+ Before running CytoCommunity2, set `input_dir` and review all
122
+ model and downstream parameters in
123
+ [`hyperparameters.json`](https://github.com/LiukangWu/CytoCommunity2/blob/main/hyperparameters.json). The Python workflow will use this configuration file.
124
+
125
+ ### 3. Run CytoCommunity2
126
+
127
+ The tutorial uses a TNBC dataset as a worked example and demonstrates the
128
+ entire CytoCommunity2 workflow, from model training and CN identification to
129
+ downstream analysis:
130
+
131
+ ```bash
132
+ jupyter notebook tutorial/TNBC_workflow.ipynb
133
+ ```
134
+
135
+ ### 4. Output files
136
+
137
+ The main output directories are:
138
+
139
+ - `CNLearning_Output/`: CN-number screening, trained models, and final result
140
+ tables.
141
+ - `CNVisualization_Output/`: CN and cell-type spatial plots.
142
+ - `data/`: downstream analysis results.
143
+ - `plot/`: figures generated by downstream analyses.
144
+
145
+ ## Maintainers
146
+
147
+ - Liukang Wu (yetong@stu.xidian.edu.cn)
148
+ - Yafei Xu (22031212416@stu.xidian.edu.cn)
149
+ - Yuxuan Hu (huyuxuan@xidian.edu.cn)
150
+
151
+ ## Citation
152
+
153
+ Yuxuan Hu, Jiazhen Rong, Yafei Xu, Runzhi Xie, Jacqueline Peng, Lin Gao, and
154
+ Kai Tan. “Unsupervised and supervised discovery of tissue cellular
155
+ neighborhoods from cell phenotypes.” *Nature Methods* 21 (2024): 267–278.
156
+ https://doi.org/10.1038/s41592-023-02124-2