wsi-toolbox 0.2.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.
- wsi_toolbox/__init__.py +122 -0
- wsi_toolbox/app.py +874 -0
- wsi_toolbox/cli.py +599 -0
- wsi_toolbox/commands/__init__.py +66 -0
- wsi_toolbox/commands/clustering.py +198 -0
- wsi_toolbox/commands/data_loader.py +219 -0
- wsi_toolbox/commands/dzi.py +160 -0
- wsi_toolbox/commands/patch_embedding.py +196 -0
- wsi_toolbox/commands/pca.py +206 -0
- wsi_toolbox/commands/preview.py +394 -0
- wsi_toolbox/commands/show.py +171 -0
- wsi_toolbox/commands/umap_embedding.py +174 -0
- wsi_toolbox/commands/wsi.py +223 -0
- wsi_toolbox/common.py +148 -0
- wsi_toolbox/models.py +30 -0
- wsi_toolbox/utils/__init__.py +109 -0
- wsi_toolbox/utils/analysis.py +174 -0
- wsi_toolbox/utils/hdf5_paths.py +232 -0
- wsi_toolbox/utils/plot.py +227 -0
- wsi_toolbox/utils/progress.py +207 -0
- wsi_toolbox/utils/seed.py +26 -0
- wsi_toolbox/utils/st.py +55 -0
- wsi_toolbox/utils/white.py +121 -0
- wsi_toolbox/watcher.py +256 -0
- wsi_toolbox/wsi_files.py +619 -0
- wsi_toolbox-0.2.0.dist-info/METADATA +253 -0
- wsi_toolbox-0.2.0.dist-info/RECORD +30 -0
- wsi_toolbox-0.2.0.dist-info/WHEEL +4 -0
- wsi_toolbox-0.2.0.dist-info/entry_points.txt +3 -0
- wsi_toolbox-0.2.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: wsi-toolbox
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: A comprehensive toolkit for Whole Slide Image processing, feature extraction, and clustering analysis
|
|
5
|
+
Project-URL: Homepage, https://github.com/technoplasm/wsi-toolbox
|
|
6
|
+
Project-URL: Repository, https://github.com/technoplasm/wsi-toolbox
|
|
7
|
+
Project-URL: Documentation, https://github.com/technoplasm/wsi-toolbox/blob/master/README.md
|
|
8
|
+
Author-email: Ken Enda <ken@endaaman.com>
|
|
9
|
+
License: MIT License
|
|
10
|
+
|
|
11
|
+
Copyright (c) 2025 Ken Enda
|
|
12
|
+
|
|
13
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
in the Software without restriction, including without limitation the rights
|
|
16
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
furnished to do so, subject to the following conditions:
|
|
19
|
+
|
|
20
|
+
The above copyright notice and this permission notice shall be included in all
|
|
21
|
+
copies or substantial portions of the Software.
|
|
22
|
+
|
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
+
SOFTWARE.
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Keywords: clustering,deep-learning,histopathology,pathology,wsi
|
|
32
|
+
Classifier: Development Status :: 4 - Beta
|
|
33
|
+
Classifier: Intended Audience :: Science/Research
|
|
34
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
35
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
36
|
+
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
|
|
37
|
+
Requires-Python: >=3.11
|
|
38
|
+
Requires-Dist: h5py>=3.13.0
|
|
39
|
+
Requires-Dist: hdbscan>=0.8.40
|
|
40
|
+
Requires-Dist: imagecodecs>=2024.12.30
|
|
41
|
+
Requires-Dist: joblib>=1.4.2
|
|
42
|
+
Requires-Dist: leidenalg>=0.10.2
|
|
43
|
+
Requires-Dist: matplotlib>=3.9.4
|
|
44
|
+
Requires-Dist: networkx>=3.3
|
|
45
|
+
Requires-Dist: numpy<2
|
|
46
|
+
Requires-Dist: opencv-python-headless>=4.11.0.86
|
|
47
|
+
Requires-Dist: openpyxl>=3.1.5
|
|
48
|
+
Requires-Dist: openslide-python>=1.4.1
|
|
49
|
+
Requires-Dist: pandas>=2.2.3
|
|
50
|
+
Requires-Dist: pillow>=11.0.0
|
|
51
|
+
Requires-Dist: pydantic-autocli>=0.2.0
|
|
52
|
+
Requires-Dist: pyqt6>=6.8.1
|
|
53
|
+
Requires-Dist: python-igraph>=0.11.8
|
|
54
|
+
Requires-Dist: rich>=14.0.0
|
|
55
|
+
Requires-Dist: scikit-learn>=1.6.1
|
|
56
|
+
Requires-Dist: seaborn>=0.13.2
|
|
57
|
+
Requires-Dist: streamlit-aggrid>=0.3.4.post3
|
|
58
|
+
Requires-Dist: streamlit-antd-components>=0.3.2
|
|
59
|
+
Requires-Dist: streamlit>=1.43.2
|
|
60
|
+
Requires-Dist: taskipy>=1.14.1
|
|
61
|
+
Requires-Dist: tifffile>=2025.2.18
|
|
62
|
+
Requires-Dist: timm>=0.9.16
|
|
63
|
+
Requires-Dist: torch>=2.5.1
|
|
64
|
+
Requires-Dist: torchvision>=0.20.1
|
|
65
|
+
Requires-Dist: umap-learn>=0.5.7
|
|
66
|
+
Requires-Dist: zarr>=3
|
|
67
|
+
Provides-Extra: build
|
|
68
|
+
Requires-Dist: packaging; extra == 'build'
|
|
69
|
+
Requires-Dist: setuptools; extra == 'build'
|
|
70
|
+
Requires-Dist: torch; extra == 'build'
|
|
71
|
+
Requires-Dist: wheel; extra == 'build'
|
|
72
|
+
Provides-Extra: compile
|
|
73
|
+
Requires-Dist: flash-attn; extra == 'compile'
|
|
74
|
+
Description-Content-Type: text/markdown
|
|
75
|
+
|
|
76
|
+
# WSI Toolbox
|
|
77
|
+
|
|
78
|
+
> **Note**: This package is currently unstable. API may change without notice.
|
|
79
|
+
|
|
80
|
+
A comprehensive toolkit for Whole Slide Image (WSI) processing, feature extraction, and clustering analysis.
|
|
81
|
+
|
|
82
|
+
## Installation
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
# From PyPI
|
|
86
|
+
pip install wsi-toolbox
|
|
87
|
+
|
|
88
|
+
# From GitHub (latest)
|
|
89
|
+
pip install git+https://github.com/technoplasm/wsi-toolbox.git
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Quick Start
|
|
93
|
+
|
|
94
|
+
### As a Python Library
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
import wsi_toolbox as wt
|
|
98
|
+
|
|
99
|
+
wt.set_default_model_preset('uni')
|
|
100
|
+
cmd = wt.Wsi2HDF5Command(patch_size=256)
|
|
101
|
+
result = cmd('input.ndpi', 'output.h5')
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
See [README_API.md](README_API.md) for API documentation.
|
|
105
|
+
|
|
106
|
+
### As a CLI Tool
|
|
107
|
+
|
|
108
|
+
After `pip install wsi-toolbox`, the CLI is available as `wsi-toolbox` or `wt`.
|
|
109
|
+
For development, use `uv run wt`.
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
# Extract tile patches from WSI into HDF5
|
|
113
|
+
wt wsi2h5 -i input.ndpi -o output.h5
|
|
114
|
+
|
|
115
|
+
# Extract patch embeddings using foundation model
|
|
116
|
+
wt embed -i output.h5
|
|
117
|
+
|
|
118
|
+
# Run Leiden clustering on embeddings
|
|
119
|
+
wt cluster -i output.h5
|
|
120
|
+
|
|
121
|
+
# Compute UMAP projection
|
|
122
|
+
wt umap -i output.h5
|
|
123
|
+
|
|
124
|
+
# Compute PCA projection
|
|
125
|
+
wt pca -i output.h5
|
|
126
|
+
|
|
127
|
+
# Generate cluster overlay preview image
|
|
128
|
+
wt preview -i output.h5
|
|
129
|
+
|
|
130
|
+
# Generate PCA score heatmap preview
|
|
131
|
+
wt preview-pca -i output.h5 -n pca1
|
|
132
|
+
|
|
133
|
+
# Show HDF5 file structure
|
|
134
|
+
wt show -i output.h5
|
|
135
|
+
|
|
136
|
+
# Export WSI to Deep Zoom Image format
|
|
137
|
+
wt dzi -i input.ndpi -o ./output
|
|
138
|
+
|
|
139
|
+
# Generate thumbnail from WSI
|
|
140
|
+
wt thumb -i input.ndpi
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Each subcommand has detailed help: `wt <subcommand> --help`
|
|
144
|
+
|
|
145
|
+
### Streamlit Web Application
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
uv run task app
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## HDF5 File Structure
|
|
152
|
+
|
|
153
|
+
WSI-toolbox stores all data in a single HDF5 file.
|
|
154
|
+
|
|
155
|
+
### Core Data
|
|
156
|
+
|
|
157
|
+
```
|
|
158
|
+
patches # Patch images: [N, H, W, 3]
|
|
159
|
+
coordinates # Patch pixel coordinates: [N, 2]
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Metadata
|
|
163
|
+
|
|
164
|
+
Metadata is stored in **file attrs** (recommended):
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
with h5py.File('output.h5', 'r') as f:
|
|
168
|
+
mpp = f.attrs['mpp']
|
|
169
|
+
patch_size = f.attrs['patch_size']
|
|
170
|
+
patch_count = f.attrs['patch_count']
|
|
171
|
+
# ...
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Available attrs: `original_mpp`, `original_width`, `original_height`, `image_level`, `mpp`, `scale`, `patch_size`, `patch_count`, `cols`, `rows`
|
|
175
|
+
|
|
176
|
+
> Legacy `metadata/*` datasets are kept for backward compatibility but attrs are preferred.
|
|
177
|
+
|
|
178
|
+
### Model Features
|
|
179
|
+
|
|
180
|
+
```
|
|
181
|
+
{model}/features # Patch features: [N, D]
|
|
182
|
+
# uni: [N, 1024]
|
|
183
|
+
# gigapath: [N, 1536]
|
|
184
|
+
# virchow2: [N, 2560]
|
|
185
|
+
{model}/latent_features # Latent features (optional): [N, L, D]
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Clustering & Analysis (Hierarchical)
|
|
189
|
+
|
|
190
|
+
Results are stored in a hierarchical namespace structure:
|
|
191
|
+
|
|
192
|
+
```
|
|
193
|
+
{model}/{namespace}/clusters # Cluster labels: [N]
|
|
194
|
+
{model}/{namespace}/umap # UMAP coordinates: [N, 2]
|
|
195
|
+
{model}/{namespace}/pca1 # PCA scores: [N] or [N, k]
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
**Namespace**:
|
|
199
|
+
- Single file: `default`
|
|
200
|
+
- Multiple files: `file1+file2+...` (auto-generated from filenames)
|
|
201
|
+
|
|
202
|
+
**Filter hierarchy**: Sub-clustering creates nested paths:
|
|
203
|
+
|
|
204
|
+
```
|
|
205
|
+
# Base clustering
|
|
206
|
+
uni/default/clusters
|
|
207
|
+
|
|
208
|
+
# Sub-cluster patches in clusters 1, 2, 3
|
|
209
|
+
uni/default/filter/1+2+3/clusters
|
|
210
|
+
|
|
211
|
+
# Further sub-cluster within that
|
|
212
|
+
uni/default/filter/1+2+3/filter/0+1/clusters
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Each level stores its own clusters, umap, pca results independently.
|
|
216
|
+
|
|
217
|
+
## Features
|
|
218
|
+
|
|
219
|
+
- WSI processing (.ndpi, .svs, .tiff → HDF5)
|
|
220
|
+
- Feature extraction (UNI, Gigapath, Virchow2)
|
|
221
|
+
- Leiden clustering with UMAP visualization
|
|
222
|
+
- Preview generation (cluster overlays, PCA heatmaps)
|
|
223
|
+
- Type-safe command pattern with Pydantic results
|
|
224
|
+
- CLI, Python API, and Streamlit GUI
|
|
225
|
+
|
|
226
|
+
## Documentation
|
|
227
|
+
|
|
228
|
+
- [API Guide](README_API.md) - Python API documentation
|
|
229
|
+
|
|
230
|
+
## Development
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
# Clone and install
|
|
234
|
+
git clone https://github.com/technoplasm/wsi-toolbox.git
|
|
235
|
+
cd wsi-toolbox
|
|
236
|
+
uv sync
|
|
237
|
+
|
|
238
|
+
# Run CLI
|
|
239
|
+
uv run wt --help
|
|
240
|
+
|
|
241
|
+
# Run Streamlit app
|
|
242
|
+
uv run task app
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### Optional: Gigapath support
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
uv sync --group gigapath
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## License
|
|
252
|
+
|
|
253
|
+
MIT
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
wsi_toolbox/__init__.py,sha256=oAhGxi1bhoWnox-ItOTSLsqAdLxOcAlOmBxq7aWHWQE,2838
|
|
2
|
+
wsi_toolbox/app.py,sha256=QkgaU9D29z_stSAQkCLFxtaICQtCJ3nW6yD4gjhfYM8,32599
|
|
3
|
+
wsi_toolbox/cli.py,sha256=EQUGWFbwEVTp9mz528MKCIGO424bww4VC3jW1athRwc,22632
|
|
4
|
+
wsi_toolbox/common.py,sha256=a9rDFOCuuY8pFRw1WXBKTmA8le-upBQCgk-Vn4qNqFk,4250
|
|
5
|
+
wsi_toolbox/models.py,sha256=HsI-A-R51KVl3MDTxxewGQi68S2G1mSYVGKFQFmd1xA,1095
|
|
6
|
+
wsi_toolbox/watcher.py,sha256=K09zKaarMkIeG3xVW9HgtgrByyYiFiFulsK5lUjoPc4,9990
|
|
7
|
+
wsi_toolbox/wsi_files.py,sha256=hTw3GH1RlHc1DR1Ll6N9BSywuI_f7hD52QIKA2LroYk,20840
|
|
8
|
+
wsi_toolbox/commands/__init__.py,sha256=PpvRzZ47eIpOhZ-M0VP7mFKPvQ32KEgQTc6aHWFx_eA,1511
|
|
9
|
+
wsi_toolbox/commands/clustering.py,sha256=WUqPmEuj-Z5jKN8VmBa4yOUjznAbD4Dc29Glct3uRUM,7134
|
|
10
|
+
wsi_toolbox/commands/data_loader.py,sha256=0vhzmNDBTrVnF3APvk_v0pY5RIM0tKgN-C7LV5YYNLw,7439
|
|
11
|
+
wsi_toolbox/commands/dzi.py,sha256=7QApixPe2WjjlPNykLG9DhF7_YDrsb2r9aELvC3ZUrE,4882
|
|
12
|
+
wsi_toolbox/commands/patch_embedding.py,sha256=KX0jr4UJV0ojNI8v_-5R_xRpCqESN906dse7EevdN_s,7086
|
|
13
|
+
wsi_toolbox/commands/pca.py,sha256=x2WZfjozuaefq32O0B7QOUsT31Tad6LB3Yj5bZT3hmo,7208
|
|
14
|
+
wsi_toolbox/commands/preview.py,sha256=PpMCi7Qq7s7D_Obj2EZJ4_vx0w8DUm1pizBm-LaVoM0,12490
|
|
15
|
+
wsi_toolbox/commands/show.py,sha256=4cTulTIW6KOjxtbTVkqTTmbsFLI1MuKr5-YpJjKN0Og,6354
|
|
16
|
+
wsi_toolbox/commands/umap_embedding.py,sha256=PnNfUCuohOcpcIwlLj1N9MFCKMKVKmUV87vacqoqD6M,6272
|
|
17
|
+
wsi_toolbox/commands/wsi.py,sha256=ctI4iTntYJCNSalqOkgPHgzMp_1uxR0_pRnuy5i0ykM,7873
|
|
18
|
+
wsi_toolbox/utils/__init__.py,sha256=JAih9kAplR8JCZ6I7NGDBJQ3GStUuhrr_f1lQdBvtQA,3465
|
|
19
|
+
wsi_toolbox/utils/analysis.py,sha256=ugLhr_HmF7mT9073qyRCKVWnJEzRmT8mFppdhYHNdb0,5863
|
|
20
|
+
wsi_toolbox/utils/hdf5_paths.py,sha256=xBe3mQ06-QOy3PnnMYEZK5dNdyCrhABZLpDKfo0i-co,6410
|
|
21
|
+
wsi_toolbox/utils/plot.py,sha256=tu15GQrGebjLrCJGL2OTkTqj5IEN26x_imFOSSorhhg,7387
|
|
22
|
+
wsi_toolbox/utils/progress.py,sha256=uHuiCq0T1xkrZQKUVF5NNhu0gAZaoTauF1hfeVk5zOo,6504
|
|
23
|
+
wsi_toolbox/utils/seed.py,sha256=eMCr9BssUG8hqQ6xK6FqFJgdiXU6nnBX5iXO2gIzViE,582
|
|
24
|
+
wsi_toolbox/utils/st.py,sha256=OavRVC9TcnoLo0AwpRIlDI3VWinj83nxGsp_7lJyDZs,2036
|
|
25
|
+
wsi_toolbox/utils/white.py,sha256=XNZz-Wq9rXJym9hC1cqiawG_UxJcUARWuxSKnc2s63g,4006
|
|
26
|
+
wsi_toolbox-0.2.0.dist-info/METADATA,sha256=6-G7OOhaal1jScFgapKyq5hPP0r5-m9f3afsL28nlzc,7175
|
|
27
|
+
wsi_toolbox-0.2.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
28
|
+
wsi_toolbox-0.2.0.dist-info/entry_points.txt,sha256=xyCLZAoyQxi2v-Dh8IIUrqxC6Sr_8WDgWbrceNTFiNk,79
|
|
29
|
+
wsi_toolbox-0.2.0.dist-info/licenses/LICENSE,sha256=YEzz8a8Kd5ZhRNItsiPJYFMfgXN1JDVZ9UG7UzTYvNU,1065
|
|
30
|
+
wsi_toolbox-0.2.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ken Enda
|
|
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.
|