patchkori 0.1.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.
- patchkori-0.1.0/.github/workflows/publish.yml +39 -0
- patchkori-0.1.0/.gitignore +48 -0
- patchkori-0.1.0/PKG-INFO +153 -0
- patchkori-0.1.0/README.md +131 -0
- patchkori-0.1.0/app.py +23 -0
- patchkori-0.1.0/assets/logo.svg +43 -0
- patchkori-0.1.0/assets/sample_data/sample_tonsil_pyramidal.ome.tif +0 -0
- patchkori-0.1.0/docs/adding-tools.md +30 -0
- patchkori-0.1.0/docs/index.md +40 -0
- patchkori-0.1.0/mkdocs.yml +15 -0
- patchkori-0.1.0/pyproject.toml +44 -0
- patchkori-0.1.0/src/patchkori/__init__.py +3 -0
- patchkori-0.1.0/src/patchkori/cli.py +107 -0
- patchkori-0.1.0/src/patchkori/config.py +32 -0
- patchkori-0.1.0/src/patchkori/core/__init__.py +17 -0
- patchkori-0.1.0/src/patchkori/core/models.py +111 -0
- patchkori-0.1.0/src/patchkori/core/pyramidal_cropper/__init__.py +5 -0
- patchkori-0.1.0/src/patchkori/core/pyramidal_cropper/adapter.py +476 -0
- patchkori-0.1.0/src/patchkori/core/sample_generator.py +77 -0
- patchkori-0.1.0/src/patchkori/ui/__init__.py +5 -0
- patchkori-0.1.0/src/patchkori/ui/app.py +42 -0
- patchkori-0.1.0/src/patchkori/ui/icons.py +38 -0
- patchkori-0.1.0/src/patchkori/ui/registry.py +40 -0
- patchkori-0.1.0/src/patchkori/ui/theme.py +287 -0
- patchkori-0.1.0/src/patchkori/ui/tools/__init__.py +5 -0
- patchkori-0.1.0/src/patchkori/ui/tools/pyramidal_cropper.py +666 -0
- patchkori-0.1.0/tests/conftest.py +19 -0
- patchkori-0.1.0/tests/test_cropper_adapter.py +116 -0
- patchkori-0.1.0/tests/test_registry.py +19 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
id-token: write # Mandatory for PyPI Trusted Publishing (OIDC)
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
pypi-publish:
|
|
14
|
+
name: Build & Upload to PyPI
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
environment:
|
|
17
|
+
name: pypi
|
|
18
|
+
url: https://pypi.org/p/patchkori
|
|
19
|
+
steps:
|
|
20
|
+
- name: Checkout code
|
|
21
|
+
uses: actions/checkout@v4
|
|
22
|
+
|
|
23
|
+
- name: Set up Python
|
|
24
|
+
uses: actions/setup-python@v5
|
|
25
|
+
with:
|
|
26
|
+
python-version: "3.11"
|
|
27
|
+
|
|
28
|
+
- name: Install build tools
|
|
29
|
+
run: |
|
|
30
|
+
python -m pip install --upgrade pip
|
|
31
|
+
python -m pip install build
|
|
32
|
+
|
|
33
|
+
- name: Build sdist and wheel
|
|
34
|
+
run: python -m build
|
|
35
|
+
|
|
36
|
+
- name: Publish package distributions to PyPI
|
|
37
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
38
|
+
with:
|
|
39
|
+
packages-dir: dist/
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Local plans directory (always ignored)
|
|
2
|
+
plans/
|
|
3
|
+
/plans/
|
|
4
|
+
|
|
5
|
+
# Python build & bytecode
|
|
6
|
+
__pycache__/
|
|
7
|
+
*.py[cod]
|
|
8
|
+
*$py.class
|
|
9
|
+
*.so
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
*.egg-info/
|
|
24
|
+
.installed.cfg
|
|
25
|
+
*.egg
|
|
26
|
+
|
|
27
|
+
# Virtual environments
|
|
28
|
+
.venv/
|
|
29
|
+
venv/
|
|
30
|
+
ENV/
|
|
31
|
+
env/
|
|
32
|
+
|
|
33
|
+
# Testing & linting caches
|
|
34
|
+
.pytest_cache/
|
|
35
|
+
.ruff_cache/
|
|
36
|
+
.mypy_cache/
|
|
37
|
+
.coverage
|
|
38
|
+
htmlcov/
|
|
39
|
+
|
|
40
|
+
# Gradio & local outputs
|
|
41
|
+
.gradio/
|
|
42
|
+
outputs/
|
|
43
|
+
tmp/
|
|
44
|
+
|
|
45
|
+
# macOS / IDE
|
|
46
|
+
.DS_Store
|
|
47
|
+
.idea/
|
|
48
|
+
.vscode/
|
patchkori-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: patchkori
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Modular open-source bioinformatics platform for large-scale pyramidal biological imaging
|
|
5
|
+
Author: Jubayer
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: bioinformatics,gradio,ome-tiff,pathology,qptiff,whole-slide-imaging,zarr
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Requires-Dist: gradio<6.0.0,>=5.0.0
|
|
10
|
+
Requires-Dist: imagecodecs>=2024.6.1
|
|
11
|
+
Requires-Dist: numpy>=1.26.0
|
|
12
|
+
Requires-Dist: pillow>=10.3.0
|
|
13
|
+
Requires-Dist: pydantic>=2.7.0
|
|
14
|
+
Requires-Dist: tifffile>=2024.5.22
|
|
15
|
+
Requires-Dist: typer>=0.12.0
|
|
16
|
+
Requires-Dist: zarr>=2.18.0
|
|
17
|
+
Provides-Extra: dev
|
|
18
|
+
Requires-Dist: mkdocs-material>=9.5.0; extra == 'dev'
|
|
19
|
+
Requires-Dist: pytest>=8.2.0; extra == 'dev'
|
|
20
|
+
Requires-Dist: ruff>=0.5.0; extra == 'dev'
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
<div align="center">
|
|
24
|
+
<img src="assets/logo.svg" alt="PatchKori Logo" width="96" height="96" />
|
|
25
|
+
<h1>PatchKori</h1>
|
|
26
|
+
<p><strong>Bioinformatics Patch Kits Hub for Gigapixel Biological Image Datasets</strong></p>
|
|
27
|
+
<p><em>Out-of-core, memory-safe pyramidal tile extraction & analysis platform (OME-TIFF, QPTIFF, Pyramidal TIFF)</em></p>
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## 🔬 What is PatchKori?
|
|
33
|
+
|
|
34
|
+
Whole-slide biological and multiplexed fluorescence images (**OME-TIFF, QPTIFF, Pyramidal TIFF, SVS, OME-Zarr**) frequently exceed **10 GB to 100+ GB per image**. Standard web tools and image viewers crash trying to load gigapixel planes into memory.
|
|
35
|
+
|
|
36
|
+
**PatchKori** solves this with a **zero-copy, out-of-core streaming architecture**:
|
|
37
|
+
- **Instant Header Inspection (<50ms):** Reads multi-resolution pyramid levels ($L_0 \dots L_N$) and channels without reading image pixels into RAM.
|
|
38
|
+
- **Interactive Low-Res Preview Canvas:** Displays an eye-soothing, colorblind-safe thumbnail preview. Draw an ROI box with your cursor or enter exact coordinates.
|
|
39
|
+
- **Direct-to-Disk Chunk Slicing:** Uses Zarr-backed `tifffile` tile streaming to extract only the compressed tiles you need directly to your local drive without memory spikes.
|
|
40
|
+
- **Extensible Hub Architecture:** Easily drop in future bioinformatics tools (e.g. segmentation, stain normalization) as self-contained plugins.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## 🚀 Quickstart: How to Use PatchKori
|
|
45
|
+
|
|
46
|
+
### 1. Installation
|
|
47
|
+
|
|
48
|
+
Clone and install PatchKori locally (Python 3.10+):
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
git clone git@github.com:jubayer98/PatchKori.git
|
|
52
|
+
cd PatchKori
|
|
53
|
+
pip install -e ".[dev]"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### 2. Launch the Web Interface
|
|
57
|
+
|
|
58
|
+
Start the local web application with one command:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
patchkori launch
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Your default browser will open automatically to **`http://127.0.0.1:7860`**.
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## 🖥️ How to Use the Web Interface (Step-by-Step)
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
┌─────────────────────────────────┬─────────────────────────────────┬─────────────────────────────────┐
|
|
72
|
+
│ 1. Configuration & Tiling │ 2. Interactive Canvas │ 3. Execution & Gallery │
|
|
73
|
+
│ • Local File Path │ • [📐 Full Level ROI] │ • Output Directory │
|
|
74
|
+
│ • Optional markerlist.txt │ • [✏️ Apply Hand-Drawn Box] │ • Format (ome.tif / png / zarr) │
|
|
75
|
+
│ • [🧪 Load Sample Dataset] │ • Thumbnail Preview │ • [✂️ Run Out-of-Core Crop] │
|
|
76
|
+
│ • Crop / Grid Tile Parameters │ • Pyramid Level Table (L0..LN) │ • Live Progress Feedback │
|
|
77
|
+
│ • Target Level & Channels │ • Full Channel Name Badges │ • Instant Preview Gallery │
|
|
78
|
+
└─────────────────────────────────┴─────────────────────────────────┴─────────────────────────────────┘
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
1. **Load Your Image:**
|
|
82
|
+
- Enter your **Local File Path** (e.g. `/path/to/my_slide.qptiff` or `.ome.tif`).
|
|
83
|
+
- *(Optional)* Provide a **`markerlist.txt`** file (one channel name per line) to automatically name multiplex channels. If omitted, channel names are read from OME-XML or fallback to index numbers `[0] Channel 0`, `[1] Channel 1`...
|
|
84
|
+
- Click **🔍 Inspect Pyramid** (or click **🧪 Load Sample Dataset** to test with the built-in 4-level pyramidal image).
|
|
85
|
+
2. **Select Region of Interest (ROI):**
|
|
86
|
+
- **Hand-Drawn Box:** Select the brush on the preview canvas, draw over your desired region, and click **✏️ Apply Hand-Drawn Box**.
|
|
87
|
+
- **Full Slide:** Click **📐 Full Level ROI** to select the entire slide.
|
|
88
|
+
- **Numeric Tuning:** Fine-tune `X`, `Y`, `Width`, and `Height` on the left.
|
|
89
|
+
3. **Choose Target Level & Channels:**
|
|
90
|
+
- **Target Level:** Choose from $L_0$ (highest resolution, 1.0×) down to $L_N$ (lowest resolution).
|
|
91
|
+
- **Channels Dropdown:** Pick any subset of markers (e.g. `[0] DAPI`, `[2] PanCK`). Leaving it empty extracts all channels.
|
|
92
|
+
4. **Choose Crop Mode:**
|
|
93
|
+
- **Single Bounding-Box ROI:** Extracts a single cropped patch of the chosen region.
|
|
94
|
+
- **Sliding-Window Tile Grid:** Slices the ROI into regular tiles (e.g. $256 \times 256$ or $512 \times 512$ with customizable overlap) for deep learning training datasets.
|
|
95
|
+
5. **Run Crop:**
|
|
96
|
+
- Click **✂️ Run Out-of-Core Crop**.
|
|
97
|
+
- Crops are written directly to your chosen local folder (`outputs/crops`) with instant visual previews in the gallery.
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## ⚡ Headless CLI Usage (For HPC, Clusters & Pipelines)
|
|
102
|
+
|
|
103
|
+
You can run PatchKori headless without opening the browser:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
# Slicing an ROI directly from the terminal
|
|
107
|
+
patchkori crop /data/wsi/sample.qptiff \
|
|
108
|
+
--level 0 \
|
|
109
|
+
--x 1024 --y 2048 --width 512 --height 512 \
|
|
110
|
+
--format ome.tif \
|
|
111
|
+
--output-dir ./results
|
|
112
|
+
|
|
113
|
+
# Sliding-window tiling for ML datasets
|
|
114
|
+
patchkori crop /data/wsi/sample.qptiff \
|
|
115
|
+
--level 1 \
|
|
116
|
+
--x 0 --y 0 --width 4096 --height 4096 \
|
|
117
|
+
--mode tile_grid --tile-size 512 --overlap 64 \
|
|
118
|
+
--format png \
|
|
119
|
+
--output-dir ./training_tiles
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## 🔌 Adding Future Bioinformatics Tools
|
|
125
|
+
|
|
126
|
+
Adding a 2nd or 3rd bioinformatics tool requires **zero modifications** to existing core code:
|
|
127
|
+
|
|
128
|
+
1. Add pure algorithmic logic to `src/patchkori/core/<my_tool>/`.
|
|
129
|
+
2. Create `src/patchkori/ui/tools/<my_tool>.py`:
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
import gradio as gr
|
|
133
|
+
from patchkori.ui.registry import BaseBioTool, ToolRegistry
|
|
134
|
+
|
|
135
|
+
@ToolRegistry.register
|
|
136
|
+
class MyBioTool(BaseBioTool):
|
|
137
|
+
tool_id = "my-tool"
|
|
138
|
+
title = "My Bio Tool"
|
|
139
|
+
icon = "🔬"
|
|
140
|
+
description = "Self-contained bioinformatics tool plugin."
|
|
141
|
+
order = 20
|
|
142
|
+
|
|
143
|
+
def build_ui(self, is_demo_mode: bool = False) -> None:
|
|
144
|
+
gr.Markdown("### Custom Tool Workspace")
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
3. Import it in `src/patchkori/ui/tools/__init__.py`. It automatically appears as a new tab in the Hub!
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## 🛡️ License
|
|
152
|
+
|
|
153
|
+
MIT License. Developed for open-source biological imaging and computational pathology research.
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="assets/logo.svg" alt="PatchKori Logo" width="96" height="96" />
|
|
3
|
+
<h1>PatchKori</h1>
|
|
4
|
+
<p><strong>Bioinformatics Patch Kits Hub for Gigapixel Biological Image Datasets</strong></p>
|
|
5
|
+
<p><em>Out-of-core, memory-safe pyramidal tile extraction & analysis platform (OME-TIFF, QPTIFF, Pyramidal TIFF)</em></p>
|
|
6
|
+
</div>
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## 🔬 What is PatchKori?
|
|
11
|
+
|
|
12
|
+
Whole-slide biological and multiplexed fluorescence images (**OME-TIFF, QPTIFF, Pyramidal TIFF, SVS, OME-Zarr**) frequently exceed **10 GB to 100+ GB per image**. Standard web tools and image viewers crash trying to load gigapixel planes into memory.
|
|
13
|
+
|
|
14
|
+
**PatchKori** solves this with a **zero-copy, out-of-core streaming architecture**:
|
|
15
|
+
- **Instant Header Inspection (<50ms):** Reads multi-resolution pyramid levels ($L_0 \dots L_N$) and channels without reading image pixels into RAM.
|
|
16
|
+
- **Interactive Low-Res Preview Canvas:** Displays an eye-soothing, colorblind-safe thumbnail preview. Draw an ROI box with your cursor or enter exact coordinates.
|
|
17
|
+
- **Direct-to-Disk Chunk Slicing:** Uses Zarr-backed `tifffile` tile streaming to extract only the compressed tiles you need directly to your local drive without memory spikes.
|
|
18
|
+
- **Extensible Hub Architecture:** Easily drop in future bioinformatics tools (e.g. segmentation, stain normalization) as self-contained plugins.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## 🚀 Quickstart: How to Use PatchKori
|
|
23
|
+
|
|
24
|
+
### 1. Installation
|
|
25
|
+
|
|
26
|
+
Clone and install PatchKori locally (Python 3.10+):
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
git clone git@github.com:jubayer98/PatchKori.git
|
|
30
|
+
cd PatchKori
|
|
31
|
+
pip install -e ".[dev]"
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### 2. Launch the Web Interface
|
|
35
|
+
|
|
36
|
+
Start the local web application with one command:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
patchkori launch
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Your default browser will open automatically to **`http://127.0.0.1:7860`**.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## 🖥️ How to Use the Web Interface (Step-by-Step)
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
┌─────────────────────────────────┬─────────────────────────────────┬─────────────────────────────────┐
|
|
50
|
+
│ 1. Configuration & Tiling │ 2. Interactive Canvas │ 3. Execution & Gallery │
|
|
51
|
+
│ • Local File Path │ • [📐 Full Level ROI] │ • Output Directory │
|
|
52
|
+
│ • Optional markerlist.txt │ • [✏️ Apply Hand-Drawn Box] │ • Format (ome.tif / png / zarr) │
|
|
53
|
+
│ • [🧪 Load Sample Dataset] │ • Thumbnail Preview │ • [✂️ Run Out-of-Core Crop] │
|
|
54
|
+
│ • Crop / Grid Tile Parameters │ • Pyramid Level Table (L0..LN) │ • Live Progress Feedback │
|
|
55
|
+
│ • Target Level & Channels │ • Full Channel Name Badges │ • Instant Preview Gallery │
|
|
56
|
+
└─────────────────────────────────┴─────────────────────────────────┴─────────────────────────────────┘
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
1. **Load Your Image:**
|
|
60
|
+
- Enter your **Local File Path** (e.g. `/path/to/my_slide.qptiff` or `.ome.tif`).
|
|
61
|
+
- *(Optional)* Provide a **`markerlist.txt`** file (one channel name per line) to automatically name multiplex channels. If omitted, channel names are read from OME-XML or fallback to index numbers `[0] Channel 0`, `[1] Channel 1`...
|
|
62
|
+
- Click **🔍 Inspect Pyramid** (or click **🧪 Load Sample Dataset** to test with the built-in 4-level pyramidal image).
|
|
63
|
+
2. **Select Region of Interest (ROI):**
|
|
64
|
+
- **Hand-Drawn Box:** Select the brush on the preview canvas, draw over your desired region, and click **✏️ Apply Hand-Drawn Box**.
|
|
65
|
+
- **Full Slide:** Click **📐 Full Level ROI** to select the entire slide.
|
|
66
|
+
- **Numeric Tuning:** Fine-tune `X`, `Y`, `Width`, and `Height` on the left.
|
|
67
|
+
3. **Choose Target Level & Channels:**
|
|
68
|
+
- **Target Level:** Choose from $L_0$ (highest resolution, 1.0×) down to $L_N$ (lowest resolution).
|
|
69
|
+
- **Channels Dropdown:** Pick any subset of markers (e.g. `[0] DAPI`, `[2] PanCK`). Leaving it empty extracts all channels.
|
|
70
|
+
4. **Choose Crop Mode:**
|
|
71
|
+
- **Single Bounding-Box ROI:** Extracts a single cropped patch of the chosen region.
|
|
72
|
+
- **Sliding-Window Tile Grid:** Slices the ROI into regular tiles (e.g. $256 \times 256$ or $512 \times 512$ with customizable overlap) for deep learning training datasets.
|
|
73
|
+
5. **Run Crop:**
|
|
74
|
+
- Click **✂️ Run Out-of-Core Crop**.
|
|
75
|
+
- Crops are written directly to your chosen local folder (`outputs/crops`) with instant visual previews in the gallery.
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## ⚡ Headless CLI Usage (For HPC, Clusters & Pipelines)
|
|
80
|
+
|
|
81
|
+
You can run PatchKori headless without opening the browser:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
# Slicing an ROI directly from the terminal
|
|
85
|
+
patchkori crop /data/wsi/sample.qptiff \
|
|
86
|
+
--level 0 \
|
|
87
|
+
--x 1024 --y 2048 --width 512 --height 512 \
|
|
88
|
+
--format ome.tif \
|
|
89
|
+
--output-dir ./results
|
|
90
|
+
|
|
91
|
+
# Sliding-window tiling for ML datasets
|
|
92
|
+
patchkori crop /data/wsi/sample.qptiff \
|
|
93
|
+
--level 1 \
|
|
94
|
+
--x 0 --y 0 --width 4096 --height 4096 \
|
|
95
|
+
--mode tile_grid --tile-size 512 --overlap 64 \
|
|
96
|
+
--format png \
|
|
97
|
+
--output-dir ./training_tiles
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## 🔌 Adding Future Bioinformatics Tools
|
|
103
|
+
|
|
104
|
+
Adding a 2nd or 3rd bioinformatics tool requires **zero modifications** to existing core code:
|
|
105
|
+
|
|
106
|
+
1. Add pure algorithmic logic to `src/patchkori/core/<my_tool>/`.
|
|
107
|
+
2. Create `src/patchkori/ui/tools/<my_tool>.py`:
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
import gradio as gr
|
|
111
|
+
from patchkori.ui.registry import BaseBioTool, ToolRegistry
|
|
112
|
+
|
|
113
|
+
@ToolRegistry.register
|
|
114
|
+
class MyBioTool(BaseBioTool):
|
|
115
|
+
tool_id = "my-tool"
|
|
116
|
+
title = "My Bio Tool"
|
|
117
|
+
icon = "🔬"
|
|
118
|
+
description = "Self-contained bioinformatics tool plugin."
|
|
119
|
+
order = 20
|
|
120
|
+
|
|
121
|
+
def build_ui(self, is_demo_mode: bool = False) -> None:
|
|
122
|
+
gr.Markdown("### Custom Tool Workspace")
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
3. Import it in `src/patchkori/ui/tools/__init__.py`. It automatically appears as a new tab in the Hub!
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## 🛡️ License
|
|
130
|
+
|
|
131
|
+
MIT License. Developed for open-source biological imaging and computational pathology research.
|
patchkori-0.1.0/app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Hugging Face Spaces / Cloud Demo Entry Point.
|
|
3
|
+
Run locally via `patchkori launch` or on HF Spaces via `python app.py`.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
import os
|
|
8
|
+
import sys
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
# Ensure `src/` is importable on Hugging Face Spaces without editable install
|
|
12
|
+
SRC_DIR = Path(__file__).resolve().parent / "src"
|
|
13
|
+
if str(SRC_DIR) not in sys.path:
|
|
14
|
+
sys.path.insert(0, str(SRC_DIR))
|
|
15
|
+
|
|
16
|
+
from patchkori.config import AppConfig # noqa: E402
|
|
17
|
+
from patchkori.ui.app import create_app # noqa: E402
|
|
18
|
+
|
|
19
|
+
if __name__ == "__main__":
|
|
20
|
+
os.environ.setdefault("PATCHKORI_MODE", "demo")
|
|
21
|
+
cfg = AppConfig.from_env()
|
|
22
|
+
demo = create_app(cfg)
|
|
23
|
+
demo.launch(show_api=False)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="128" height="128" fill="none">
|
|
2
|
+
<defs>
|
|
3
|
+
<!-- Eye-soothing, colorblind-safe palette: Deep Navy, Bio-Teal, Muted Amber (No violet/purple) -->
|
|
4
|
+
<linearGradient id="pk_tile_navy" x1="0%" y1="0%" x2="100%" y2="100%">
|
|
5
|
+
<stop offset="0%" stop-color="#1E3A8A" />
|
|
6
|
+
<stop offset="100%" stop-color="#2563EB" />
|
|
7
|
+
</linearGradient>
|
|
8
|
+
<linearGradient id="pk_tile_teal" x1="0%" y1="0%" x2="100%" y2="100%">
|
|
9
|
+
<stop offset="0%" stop-color="#0F766E" />
|
|
10
|
+
<stop offset="100%" stop-color="#14B8A6" />
|
|
11
|
+
</linearGradient>
|
|
12
|
+
<linearGradient id="pk_tile_slate" x1="0%" y1="0%" x2="100%" y2="100%">
|
|
13
|
+
<stop offset="0%" stop-color="#334155" />
|
|
14
|
+
<stop offset="100%" stop-color="#475569" />
|
|
15
|
+
</linearGradient>
|
|
16
|
+
<linearGradient id="pk_tile_amber" x1="0%" y1="0%" x2="100%" y2="100%">
|
|
17
|
+
<stop offset="0%" stop-color="#B45309" />
|
|
18
|
+
<stop offset="100%" stop-color="#F59E0B" />
|
|
19
|
+
</linearGradient>
|
|
20
|
+
</defs>
|
|
21
|
+
|
|
22
|
+
<!-- Whole-Slide Pyramidal Parent Tiles -->
|
|
23
|
+
<rect x="14" y="14" width="32" height="32" rx="6" fill="url(#pk_tile_navy)" />
|
|
24
|
+
<rect x="54" y="14" width="32" height="32" rx="6" fill="url(#pk_tile_teal)" />
|
|
25
|
+
<rect x="14" y="54" width="32" height="32" rx="6" fill="url(#pk_tile_slate)" />
|
|
26
|
+
|
|
27
|
+
<!-- Extracted Micro-Patch Grid (Lower Right) -->
|
|
28
|
+
<rect x="54" y="54" width="14" height="14" rx="3" fill="#0284C7" />
|
|
29
|
+
<rect x="72" y="54" width="14" height="14" rx="3" fill="#0D9488" />
|
|
30
|
+
<rect x="54" y="72" width="14" height="14" rx="3" fill="#475569" />
|
|
31
|
+
<rect x="72" y="72" width="14" height="14" rx="3" fill="url(#pk_tile_amber)" />
|
|
32
|
+
|
|
33
|
+
<!-- Central Optical Reticle & Lens Alignment -->
|
|
34
|
+
<circle cx="50" cy="50" r="14" stroke="#FFFFFF" stroke-width="2" stroke-dasharray="3 3" opacity="0.9" />
|
|
35
|
+
<circle cx="50" cy="50" r="4.5" fill="#FFFFFF" />
|
|
36
|
+
<circle cx="50" cy="50" r="2" fill="#0F766E" />
|
|
37
|
+
|
|
38
|
+
<!-- Precision Corner Crop Guides -->
|
|
39
|
+
<path d="M 8 22 L 8 8 L 22 8" stroke="#0284C7" stroke-width="2.5" stroke-linecap="round" />
|
|
40
|
+
<path d="M 78 8 L 92 8 L 92 22" stroke="#14B8A6" stroke-width="2.5" stroke-linecap="round" />
|
|
41
|
+
<path d="M 8 78 L 8 92 L 22 92" stroke="#64748B" stroke-width="2.5" stroke-linecap="round" />
|
|
42
|
+
<path d="M 78 92 L 92 92 L 92 78" stroke="#D97706" stroke-width="2.5" stroke-linecap="round" />
|
|
43
|
+
</svg>
|
|
Binary file
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Adding a New Bioinformatics Tool to PatchKori
|
|
2
|
+
|
|
3
|
+
PatchKori separates **headless bioinformatics logic** (`src/patchkori/core/`) from **Gradio UI plugins** (`src/patchkori/ui/tools/`).
|
|
4
|
+
|
|
5
|
+
## Step 1: Create Core Logic
|
|
6
|
+
Add your pure Python module under `src/patchkori/core/<tool_name>/`. Ensure it has no dependency on `gradio` so it can be imported in Jupyter notebooks, CLI commands, and Nextflow pipelines.
|
|
7
|
+
|
|
8
|
+
## Step 2: Register the Gradio Tool Plugin
|
|
9
|
+
Subclass `BaseBioTool` in `src/patchkori/ui/tools/<tool_name>.py` and decorate with `@ToolRegistry.register`:
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
import gradio as gr
|
|
13
|
+
from patchkori.ui.registry import BaseBioTool, ToolRegistry
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@ToolRegistry.register
|
|
17
|
+
class MyBioTool(BaseBioTool):
|
|
18
|
+
tool_id = "my-bio-tool"
|
|
19
|
+
title = "My Bio Tool"
|
|
20
|
+
icon = "🧪"
|
|
21
|
+
description = "Description shown at the top of the tool tab."
|
|
22
|
+
order = 30
|
|
23
|
+
|
|
24
|
+
def build_ui(self, is_demo_mode: bool = False) -> None:
|
|
25
|
+
with gr.Row():
|
|
26
|
+
gr.Markdown("Build your Gradio controls here!")
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Step 3: Export in `src/patchkori/ui/tools/__init__.py`
|
|
30
|
+
Import your module in `src/patchkori/ui/tools/__init__.py` so the decorator runs at startup. Your tool tab will automatically appear in `patchkori launch`!
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# 🧬 PatchKori: Bioinformatics Patch Kits Hub
|
|
2
|
+
|
|
3
|
+
**PatchKori** is an open-source, modular bioinformatics platform for out-of-core processing of gigapixel biological image datasets (**OME-TIFF, QPTIFF, Pyramidal TIFF**).
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Quickstart
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# 1. Install locally
|
|
11
|
+
pip install -e ".[dev]"
|
|
12
|
+
|
|
13
|
+
# 2. Launch the web interface
|
|
14
|
+
patchkori launch
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Key Features
|
|
20
|
+
|
|
21
|
+
1. **Out-of-Core Pyramidal Cropper:**
|
|
22
|
+
- Reads image headers in <50ms without loading gigapixel planes into RAM.
|
|
23
|
+
- Interactive preview with hand-drawn brush box selection.
|
|
24
|
+
- Slices tiles and single ROIs directly to local disk.
|
|
25
|
+
2. **Flexible Channel Mapping:**
|
|
26
|
+
- Accepts a `markerlist.txt` file (one marker name per line).
|
|
27
|
+
- Falls back to OME-XML tags or clean index numbers (`[0] Channel 0`, `[1] Channel 1`...).
|
|
28
|
+
3. **Dual Execution:**
|
|
29
|
+
- **Local Workstation:** Direct path reading on 50 GB+ whole-slide files.
|
|
30
|
+
- **Cloud Demo:** Sandboxed interactive testing with pre-loaded pyramidal datasets.
|
|
31
|
+
4. **Headless CLI & Scripting:**
|
|
32
|
+
- `patchkori crop` command for Slurm, HPC, Snakemake, and Nextflow pipelines.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Web Interface Overview
|
|
37
|
+
|
|
38
|
+
- **Left Panel:** File path, optional markerlist, crop & tile grid parameters, target pyramid level, and multi-select channels.
|
|
39
|
+
- **Center Panel:** Hand-drawn ROI canvas with **Full Level ROI** and **Apply Hand-Drawn Box** buttons, followed by the non-breaking Pyramid Levels overview table and dataset details.
|
|
40
|
+
- **Right Panel:** Output format selection (`ome.tif`, `tif`, `png`, `zarr`), single-click crop execution with live progress bar, and instant preview gallery.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
site_name: PatchKori — Bioinformatics Pyramidal Imaging Platform
|
|
2
|
+
site_description: Modular open-source bioinformatics imaging hub for gigapixel pyramidal datasets
|
|
3
|
+
theme:
|
|
4
|
+
name: material
|
|
5
|
+
palette:
|
|
6
|
+
- scheme: slate
|
|
7
|
+
primary: teal
|
|
8
|
+
accent: cyan
|
|
9
|
+
features:
|
|
10
|
+
- navigation.tabs
|
|
11
|
+
- content.code.copy
|
|
12
|
+
|
|
13
|
+
nav:
|
|
14
|
+
- Home: index.md
|
|
15
|
+
- Adding New Tools: adding-tools.md
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "patchkori"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Modular open-source bioinformatics platform for large-scale pyramidal biological imaging"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [{ name = "Jubayer" }]
|
|
13
|
+
keywords = ["bioinformatics", "whole-slide-imaging", "ome-tiff", "qptiff", "zarr", "gradio", "pathology"]
|
|
14
|
+
dependencies = [
|
|
15
|
+
"gradio>=5.0.0,<6.0.0",
|
|
16
|
+
"tifffile>=2024.5.22",
|
|
17
|
+
"imagecodecs>=2024.6.1",
|
|
18
|
+
"zarr>=2.18.0",
|
|
19
|
+
"numpy>=1.26.0",
|
|
20
|
+
"Pillow>=10.3.0",
|
|
21
|
+
"typer>=0.12.0",
|
|
22
|
+
"pydantic>=2.7.0",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[project.optional-dependencies]
|
|
26
|
+
dev = [
|
|
27
|
+
"pytest>=8.2.0",
|
|
28
|
+
"ruff>=0.5.0",
|
|
29
|
+
"mkdocs-material>=9.5.0",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.scripts]
|
|
33
|
+
patchkori = "patchkori.cli:app"
|
|
34
|
+
|
|
35
|
+
[tool.hatch.build.targets.wheel]
|
|
36
|
+
packages = ["src/patchkori"]
|
|
37
|
+
|
|
38
|
+
[tool.pytest.ini_options]
|
|
39
|
+
testpaths = ["tests"]
|
|
40
|
+
pythonpath = ["src"]
|
|
41
|
+
|
|
42
|
+
[tool.ruff]
|
|
43
|
+
line-length = 100
|
|
44
|
+
target-version = "py310"
|