cytorecorder 0.1.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.
Potentially problematic release.
This version of cytorecorder might be problematic. Click here for more details.
- cytorecorder/__init__.py +5 -0
- cytorecorder/_version.py +24 -0
- cytorecorder/cli.py +69 -0
- cytorecorder/images.py +35 -0
- cytorecorder/main.py +153 -0
- cytorecorder-0.1.0.dist-info/METADATA +51 -0
- cytorecorder-0.1.0.dist-info/RECORD +10 -0
- cytorecorder-0.1.0.dist-info/WHEEL +5 -0
- cytorecorder-0.1.0.dist-info/entry_points.txt +2 -0
- cytorecorder-0.1.0.dist-info/top_level.txt +1 -0
cytorecorder/__init__.py
ADDED
cytorecorder/_version.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# file generated by vcs-versioning
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"__version__",
|
|
7
|
+
"__version_tuple__",
|
|
8
|
+
"version",
|
|
9
|
+
"version_tuple",
|
|
10
|
+
"__commit_id__",
|
|
11
|
+
"commit_id",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
version: str
|
|
15
|
+
__version__: str
|
|
16
|
+
__version_tuple__: tuple[int | str, ...]
|
|
17
|
+
version_tuple: tuple[int | str, ...]
|
|
18
|
+
commit_id: str | None
|
|
19
|
+
__commit_id__: str | None
|
|
20
|
+
|
|
21
|
+
__version__ = version = '0.1.0'
|
|
22
|
+
__version_tuple__ = version_tuple = (0, 1, 0)
|
|
23
|
+
|
|
24
|
+
__commit_id__ = commit_id = None
|
cytorecorder/cli.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"""
|
|
2
|
+
CLI for cytorecorder
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import fire
|
|
6
|
+
from fire.decorators import SetParseFn
|
|
7
|
+
|
|
8
|
+
from cytorecorder.main import DEFAULT_APP_URL, review
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class cytorecorderCLI:
|
|
12
|
+
@SetParseFn(str, "input_dir", "output_dir", "project", "app_url")
|
|
13
|
+
def review( # noqa: PLR0913 (CLI config surface: one kwarg per launch option)
|
|
14
|
+
self,
|
|
15
|
+
input_dir: str,
|
|
16
|
+
output_dir: str,
|
|
17
|
+
project: str = "",
|
|
18
|
+
app_url: str = DEFAULT_APP_URL,
|
|
19
|
+
open_browser: bool = True,
|
|
20
|
+
force: bool = False,
|
|
21
|
+
enable_voice_notes: bool = False,
|
|
22
|
+
) -> None:
|
|
23
|
+
"""
|
|
24
|
+
Help a human complete a CytoRecorder whole-image quality review:
|
|
25
|
+
confirms real images exist under input_dir (recursively, including
|
|
26
|
+
subdirectories) and opens the hosted CytoRecorder app. The human
|
|
27
|
+
then drags input_dir into the app themselves and, when done,
|
|
28
|
+
exports quality_labels.csv into output_dir from the browser.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
input_dir (str):
|
|
32
|
+
Folder of whole images to review, scanned recursively.
|
|
33
|
+
output_dir (str):
|
|
34
|
+
Folder to save the exported quality_labels.csv into.
|
|
35
|
+
project (str):
|
|
36
|
+
Project name recorded on every label.
|
|
37
|
+
Defaults to the input folder's own name.
|
|
38
|
+
app_url (str):
|
|
39
|
+
Base URL of the hosted CytoRecorder app to open.
|
|
40
|
+
open_browser (bool):
|
|
41
|
+
Whether to open the system browser automatically.
|
|
42
|
+
Defaults to True.
|
|
43
|
+
force (bool):
|
|
44
|
+
Proceed even if output_dir already has a non-empty
|
|
45
|
+
quality_labels.csv. Defaults to False: refuse and raise.
|
|
46
|
+
enable_voice_notes (bool):
|
|
47
|
+
Opened with a project name, CytoRecorder normally skips
|
|
48
|
+
its default public-demo behavior (automatic BioImage
|
|
49
|
+
Archive fetch, per-object voice notes) and just waits for
|
|
50
|
+
the folder to be dragged in. Set this to open with that
|
|
51
|
+
default demo behavior (including voice notes) instead.
|
|
52
|
+
Defaults to False.
|
|
53
|
+
"""
|
|
54
|
+
review(
|
|
55
|
+
input_dir=input_dir,
|
|
56
|
+
output_dir=output_dir,
|
|
57
|
+
project=project,
|
|
58
|
+
app_url=app_url,
|
|
59
|
+
open_browser=open_browser,
|
|
60
|
+
force=force,
|
|
61
|
+
enable_voice_notes=enable_voice_notes,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def trigger() -> None:
|
|
66
|
+
"""
|
|
67
|
+
Trigger the CLI to run.
|
|
68
|
+
"""
|
|
69
|
+
fire.Fire(cytorecorderCLI)
|
cytorecorder/images.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Discover whole microscopy images under an input directory, recursively.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
IMAGE_SUFFIXES = (".png", ".tif", ".tiff")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def discover_images(input_dir: Path | str) -> list[Path]:
|
|
13
|
+
"""
|
|
14
|
+
Recursively find PNG/TIFF whole images under ``input_dir``, including
|
|
15
|
+
subdirectories, matching how a user dragging the same folder onto
|
|
16
|
+
CytoRecorder's browser upload would see it.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
input_dir (Path | str):
|
|
20
|
+
Root folder to scan.
|
|
21
|
+
|
|
22
|
+
Returns:
|
|
23
|
+
list[Path]:
|
|
24
|
+
Image paths relative to ``input_dir``, sorted deterministically.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
root = Path(input_dir)
|
|
28
|
+
if not root.is_dir():
|
|
29
|
+
raise NotADirectoryError(f"Input directory does not exist: {root}")
|
|
30
|
+
found = [
|
|
31
|
+
path.relative_to(root)
|
|
32
|
+
for path in root.rglob("*")
|
|
33
|
+
if path.is_file() and path.suffix.lower() in IMAGE_SUFFIXES
|
|
34
|
+
]
|
|
35
|
+
return sorted(found)
|
cytorecorder/main.py
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Helps a human complete a CytoRecorder whole-image QC review run: discovers
|
|
3
|
+
the images under a local folder (recursively) and opens the hosted
|
|
4
|
+
GitHub Pages app so a person can drag that folder in, review and label the
|
|
5
|
+
images there, and export the resulting CSV into the output folder
|
|
6
|
+
themselves. No local HTTP server, no network upload of the images — the
|
|
7
|
+
images never leave the machine except through the browser's own existing
|
|
8
|
+
local-folder upload, which already runs entirely client-side.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import webbrowser
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
from urllib.parse import parse_qsl, urlencode, urlsplit
|
|
16
|
+
|
|
17
|
+
from cytorecorder.images import discover_images
|
|
18
|
+
|
|
19
|
+
DEFAULT_APP_URL = "https://wayscience.github.io/CytoRecorder/"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def build_app_url(app_url: str, project: str, enable_voice_notes: bool = False) -> str:
|
|
23
|
+
"""
|
|
24
|
+
Builds the CytoRecorder URL to open, carrying only the project name
|
|
25
|
+
(prefilled into the whole-image QC panel's Project field) and an
|
|
26
|
+
optional voice-notes opt-in — there is no server behind this URL to
|
|
27
|
+
fetch images from or export to.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
app_url (str):
|
|
31
|
+
Base URL of the hosted CytoRecorder app.
|
|
32
|
+
project (str):
|
|
33
|
+
Project name to prefill in the browser.
|
|
34
|
+
enable_voice_notes (bool):
|
|
35
|
+
A project hint makes CytoRecorder skip its default public-demo
|
|
36
|
+
behavior (automatic BioImage Archive fetch, per-object voice
|
|
37
|
+
notes) and wait for a folder to be dragged in instead. Set this
|
|
38
|
+
to opt back into that default demo behavior anyway. Has no
|
|
39
|
+
effect when ``project`` is empty, since the demo already runs
|
|
40
|
+
by default in that case.
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
str:
|
|
44
|
+
The full CytoRecorder URL to open.
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
if not project:
|
|
48
|
+
return app_url
|
|
49
|
+
url = urlsplit(app_url)
|
|
50
|
+
params = [
|
|
51
|
+
(key, value)
|
|
52
|
+
for key, value in parse_qsl(url.query, keep_blank_values=True)
|
|
53
|
+
if key not in {"project", "voice"}
|
|
54
|
+
]
|
|
55
|
+
params.append(("project", project))
|
|
56
|
+
if enable_voice_notes:
|
|
57
|
+
params.append(("voice", "1"))
|
|
58
|
+
return url._replace(
|
|
59
|
+
path=f"{url.path.rstrip('/')}/", query=urlencode(params)
|
|
60
|
+
).geturl()
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def review( # noqa: PLR0913 (CLI config surface: one kwarg per launch option)
|
|
64
|
+
input_dir: str,
|
|
65
|
+
output_dir: str,
|
|
66
|
+
project: str = "",
|
|
67
|
+
app_url: str = DEFAULT_APP_URL,
|
|
68
|
+
open_browser: bool = True,
|
|
69
|
+
force: bool = False,
|
|
70
|
+
enable_voice_notes: bool = False,
|
|
71
|
+
) -> str:
|
|
72
|
+
"""
|
|
73
|
+
Validates the input folder, prints the steps a human takes to complete
|
|
74
|
+
the review in the browser, and (by default) opens CytoRecorder.
|
|
75
|
+
|
|
76
|
+
Args:
|
|
77
|
+
input_dir (str):
|
|
78
|
+
Folder of whole images to review; scanned recursively for
|
|
79
|
+
``.png``/``.tif``/``.tiff`` files to confirm there is something
|
|
80
|
+
to review before opening a browser tab.
|
|
81
|
+
output_dir (str):
|
|
82
|
+
Folder the human should save the exported quality_labels.csv
|
|
83
|
+
into, from the browser's "Export quality labels (CSV)" button.
|
|
84
|
+
project (str):
|
|
85
|
+
Project name; defaults to the input folder's own name.
|
|
86
|
+
app_url (str):
|
|
87
|
+
Base URL of the hosted CytoRecorder app to open.
|
|
88
|
+
open_browser (bool):
|
|
89
|
+
Whether to open the system browser automatically.
|
|
90
|
+
force (bool):
|
|
91
|
+
Proceed even if output_dir already has a non-empty
|
|
92
|
+
quality_labels.csv (which the browser export would overwrite).
|
|
93
|
+
Defaults to False: refuse and raise instead.
|
|
94
|
+
enable_voice_notes (bool):
|
|
95
|
+
Opened with a project name, CytoRecorder normally skips its
|
|
96
|
+
default public-demo behavior (automatic BioImage Archive
|
|
97
|
+
fetch, per-object voice notes) and just waits for the folder
|
|
98
|
+
to be dragged in. Set this to open with that default demo
|
|
99
|
+
behavior (including voice notes) instead. Defaults to False.
|
|
100
|
+
|
|
101
|
+
Returns:
|
|
102
|
+
str:
|
|
103
|
+
The CytoRecorder URL that was (or would be) opened.
|
|
104
|
+
"""
|
|
105
|
+
|
|
106
|
+
image_count = len(discover_images(input_dir))
|
|
107
|
+
if image_count == 0:
|
|
108
|
+
raise FileNotFoundError(
|
|
109
|
+
f"No PNG/TIFF images found under {input_dir} (recursively)."
|
|
110
|
+
)
|
|
111
|
+
# .resolve() first: Path(".").name and Path("..").name are "" and ".."
|
|
112
|
+
# respectively (pathlib treats them as literal path segments, not the
|
|
113
|
+
# real directory they refer to), which would silently make the CLI's
|
|
114
|
+
# own project-hint suppression mechanism never kick in for "review
|
|
115
|
+
# --input_dir=. ...".
|
|
116
|
+
project_name = project or Path(input_dir).resolve().name
|
|
117
|
+
output_path = Path(output_dir) / "quality_labels.csv"
|
|
118
|
+
if output_path.exists() and output_path.stat().st_size > 0 and not force:
|
|
119
|
+
raise FileExistsError(
|
|
120
|
+
f"{output_path} already has content and would be overwritten by a new "
|
|
121
|
+
"export. Pass force=True to proceed anyway, move/rename the existing "
|
|
122
|
+
"file first, or choose a different output_dir."
|
|
123
|
+
)
|
|
124
|
+
url = build_app_url(app_url, project_name, enable_voice_notes)
|
|
125
|
+
# flush=True: stdout is fully buffered (not line-buffered) once it is a
|
|
126
|
+
# pipe rather than a terminal, so a caller reading these lines live
|
|
127
|
+
# (e.g. this package's own CLI tests) would otherwise block waiting on
|
|
128
|
+
# data still sitting in this process's buffer.
|
|
129
|
+
print(f"Found {image_count} image(s) under {input_dir} (recursively).", flush=True)
|
|
130
|
+
if output_path.exists() and output_path.stat().st_size > 0:
|
|
131
|
+
print(
|
|
132
|
+
f"Warning: {output_path} already has content and will be overwritten.",
|
|
133
|
+
flush=True,
|
|
134
|
+
)
|
|
135
|
+
print(f"1. Open: {url}", flush=True)
|
|
136
|
+
print(
|
|
137
|
+
f"2. In CytoRecorder, drag the folder {input_dir} onto the mosaic", flush=True
|
|
138
|
+
)
|
|
139
|
+
print(
|
|
140
|
+
" (or use its Upload folder button) and switch to Single image mode.",
|
|
141
|
+
flush=True,
|
|
142
|
+
)
|
|
143
|
+
print(
|
|
144
|
+
"3. Review and label each image with the whole-image quality buttons.",
|
|
145
|
+
flush=True,
|
|
146
|
+
)
|
|
147
|
+
print(
|
|
148
|
+
f"4. Click 'Export quality labels (CSV)' and save it to {output_path}.",
|
|
149
|
+
flush=True,
|
|
150
|
+
)
|
|
151
|
+
if open_browser:
|
|
152
|
+
webbrowser.open(url)
|
|
153
|
+
return url
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cytorecorder
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Local companion CLI for CytoRecorder: confirms a folder of whole microscopy images exists (recursively) and opens the hosted CytoRecorder app so a human can complete the whole-image QC review and export themselves.
|
|
5
|
+
Author: Dave Bunten
|
|
6
|
+
Project-URL: Homepage, https://github.com/WayScience/CytoRecorder
|
|
7
|
+
Project-URL: Issues, https://github.com/WayScience/CytoRecorder/issues
|
|
8
|
+
Project-URL: Repository, https://github.com/WayScience/CytoRecorder
|
|
9
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Requires-Python: >=3.11
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
Requires-Dist: fire>=0.7
|
|
16
|
+
Requires-Dist: jinja2>=3.1.6
|
|
17
|
+
|
|
18
|
+
# cytorecorder
|
|
19
|
+
|
|
20
|
+
Local companion CLI for [CytoRecorder](https://wayscience.github.io/CytoRecorder/): confirms a folder of whole microscopy images exists (recursively, including subdirectories) and opens the hosted CytoRecorder app so a human can complete a whole-image quality review and export the results themselves.
|
|
21
|
+
|
|
22
|
+
This CLI does not run a server and does not push data into the browser. A human still drags the input folder into CytoRecorder (or uses its "Upload folder" button) and, when finished, saves the exported `quality_labels.csv` into the output folder themselves. Browsers cannot be made to silently read or write arbitrary local paths, so this stays a manual, two-step handoff by design.
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
pip install cytorecorder
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Use
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
cytorecorder review --input_dir=/path/to/images --output_dir=/path/to/results
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
This:
|
|
37
|
+
|
|
38
|
+
1. Scans `input_dir` recursively for `.png`/`.tif`/`.tiff` files and fails fast if none are found.
|
|
39
|
+
1. Refuses (unless `--force=True`) if `output_dir/quality_labels.csv` already exists and is non-empty, so a review run can't silently clobber a previous export.
|
|
40
|
+
1. Opens the hosted CytoRecorder app at a URL carrying a project name (defaulting to `input_dir`'s own folder name).
|
|
41
|
+
1. Prints the remaining manual steps: drag `input_dir` into the app, switch to Single image mode, label each image, then export the CSV into `output_dir`.
|
|
42
|
+
|
|
43
|
+
Run `cytorecorder review --help` for all options (`--project`, `--app_url`, `--open_browser`, `--force`).
|
|
44
|
+
|
|
45
|
+
## Develop
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
uv sync
|
|
49
|
+
uv run --frozen pytest
|
|
50
|
+
uv run pre-commit run --all-files
|
|
51
|
+
```
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
cytorecorder/__init__.py,sha256=mBGddynER6Dl3LaNEiIZ-nojFUWFgbCSkV5moRnx-1w,77
|
|
2
|
+
cytorecorder/_version.py,sha256=n_5vdJsPNu7wZ57LGuRL585uvll-hiuvZUBWzdG0RQU,520
|
|
3
|
+
cytorecorder/cli.py,sha256=pWYuIV3QhZlJlB-jXJm1RA2W4M2tKkzIaprswI7DLiI,2490
|
|
4
|
+
cytorecorder/images.py,sha256=jqZ1VeNv4JTuWf8FDwT9PzQXYOHqxbXxKt48N-9rsAM,951
|
|
5
|
+
cytorecorder/main.py,sha256=f_vCWiGb-2tvN26P7zqUcPUJl_fiSXvazSGacA7Qyuc,6203
|
|
6
|
+
cytorecorder-0.1.0.dist-info/METADATA,sha256=nwl_-KQGrBJOQtZZIhsxLOJ3hKsnJBxQc1TuZIIW5vQ,2416
|
|
7
|
+
cytorecorder-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
8
|
+
cytorecorder-0.1.0.dist-info/entry_points.txt,sha256=3FSfjR8eQ8A1KPBRlWZXzjgahuCfZDjb91zSA22B_o8,58
|
|
9
|
+
cytorecorder-0.1.0.dist-info/top_level.txt,sha256=e5UXz9oIsosun3rpMb4dpUhMWWTydX3-cCrC7wpZG4Y,13
|
|
10
|
+
cytorecorder-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
cytorecorder
|