Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/normalization.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ planes and what to do:
|---|---|
| *The preprocessing run in ... cannot be used: The experiment holds ... that the preprocessing run did not record* (`unrecorded_files`) | Since preprocessing v0.4.0rc2: images or masks were added to the experiment (or masks folder) after the run. None is left out: run preprocessing again on the experiment as it is, or exclude the images there. |
| *... the zarr package is not installed* (`zarr_extra_missing`) | The run holds OME-Zarr images: `pip install "cellpatcher[zarr]"`. |
| *The preprocessing run in ... cannot be used* (`preprocessing_run_refused`) | The preprocessing brick's `RunInputs` refuses the run (since v0.2.0): no `run_manifest.json` next to the table, a run written before preprocessing v0.4.0, a table or description changed since the run, or an image or mask changed or missing since the run where CellPatcher reads it. Run preprocessing v0.5 on the experiment as it is now; an experiment only moved or copied (times kept) since its run is read where it is now when CellPatcher is given that folder and its masks folder (since CP-2a). |
| *The preprocessing run in ... cannot be used* (`preprocessing_run_refused`) | The preprocessing brick's `RunInputs` refuses the run (since v0.2.0): no `run_manifest.json` next to the table, a run written before preprocessing v0.4.0, a table or description changed since the run, or an image or mask changed or missing since the run where CellPatcher reads it. Run preprocessing v0.5 on the experiment as it is now; an experiment only moved or copied (times kept) since its run is read where it is now when CellPatcher is given that folder and its masks folder (since CP-2a). A folder where preprocessing **stopped** without writing a run (for example Spec `v29`, RGB units beside fluorescence units, `R_HETEROGENEOUS_LAYOUT_NOT_ENABLED`) is refused with preprocessing's own errors first, in order, their codes, messages, paths and suggested actions unchanged (from preprocessing's `RunInputs.open`, `RunStoppedError`, `RUN_FOLDER_STOPPED`; CellPatcher reads no `discovery_report.json`), and no advice to run preprocessing again, which would stop the same way (issue #126). A run report preprocessing cannot read there is refused with its code, `RUN_FOLDER_REPORT_UNREADABLE`, naming the report. |
| *The preprocessing run in ... has no published experiment description* (`A_DESCRIPTION_REQUIRED`) | Every run needs one (Spec ADR 0002 AR10): describe the experiment and publish its description in the preprocessing notebook, run preprocessing again and give CellPatcher that run. |
| *normalization.plane_histograms/manifest names ...* (`not_the_run_output`) | Only the run's own files, unrenamed in its output folder, are read. Give that folder's `plane_histograms.csv` (and leave `manifest` empty). |
| *... these images of the run have no repeat group* (`missing_repeat_group`) / *... several repeat groups to the images of one condition and biological-repeat folder* (`repeat_group_conflict`) | The `biological_repeat` scope pools the repeat groups of the run's description: run preprocessing again with its published description. `normalization.experiment_design` was removed (the derived `experiment_design.csv` is never read). |
Expand Down
23 changes: 21 additions & 2 deletions notebooks/CellPatcher/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,26 @@ Release v0.3.0
Pin preprocessing v0.4.0rc4; prepare v0.2.0rc2

---
## [Unreleased] - Channel IDs on every patch (#125)
## [Unreleased] - Channel IDs on every patch (#125); a stopped preprocessing run's refusal passed on (#126)

For v0.7.2. Found by the S3.4 adversarial suite (MorphoFeature draft PR #240, gate G3).
For v0.7.2. Found by the S3.4 adversarial suite (MorphoFeature draft PR #240, gate G3 (#125) and row A07 (#126)).
#126 needs the preprocessing release after v0.6.1 (preprocessing #322, merged in #324); until it is tagged,
draft PR #128 pins preprocessing's main commit b24371a, and it is not merged before that release.

### Fixed
- **#126: a run preprocessing stopped on purpose is refused with preprocessing's own errors, without re-run
advice.** On an output folder where preprocessing stopped without writing a run (Spec `v29`: RGB units beside
fluorescence units, `R_HETEROGENEOUS_LAYOUT_NOT_ENABLED`), v0.7.1 refused with `preprocessing_run_refused`
("holds no run_manifest.json") and advised running preprocessing again, which stops the same way. Preprocessing's
`RunInputs.open` now raises `RunStoppedError` (`RUN_FOLDER_STOPPED`) there, carrying the stopped run's error
issues; CellPatcher passes them on first, in order, with their codes, messages, paths and suggested actions
unchanged (Spec ADR 0005, construction and propagation), then `preprocessing_run_refused` naming the folder,
still "holds no run_manifest.json", whose action is to follow preprocessing's, with no re-run advice. A run
report preprocessing cannot read (`RunReportUnreadableError`) is refused with its code,
`RUN_FOLDER_REPORT_UNREADABLE`, naming the report. CellPatcher reads no `discovery_report.json` itself. A folder
with neither a run nor a stopped run's report still says to give a written run or run preprocessing first, and a
run that was written but is stale (an image changed since, an older manifest) keeps the advice to run
preprocessing again, which fixes it. `tests/test_stopped_run.py`.
- **#125: every patch of a described run records its channel IDs, in its C order.** Without normalization and
without channel splitting, v0.7.1 recorded no channel ID at all (`c`, `channel_id` and `normalization_channels`
empty, on the patch and in `patches.csv`), so the patches of two units storing DNA, ACTIN and ACTIN, DNA could
Expand Down Expand Up @@ -108,6 +123,10 @@ For v0.7.2. Found by the S3.4 adversarial suite (MorphoFeature draft PR #240, ga
without the `channel_ids` column, like any table missing a column CellPatcher writes (nothing is defaulted): a
table written by v0.7.1 or earlier must be written again by running CellPatcher again. A `channel_ids` cell is
read as a tuple and checked with the normalization brick's `check_channel_ids`.
- **Dependencies (draft only, `TODO(tag)`):** preprocessing (core and `zarr` extra) is pinned to its main commit
`b24371abe0a728995f44b2f8f1dd6d36b4a4addc` (`RunStoppedError`, #324), not a release tag, so
`test_preprocessing_is_pinned_to_a_release_tag_not_a_commit` accepts that one commit until the next preprocessing
release is tagged; the pin and the test go back to a tag before #126 is merged. Normalization stays `v0.7.0`.

## [0.7.1] - 2026-11-16 - Fixes from the external audit of v0.7.0 (CP1, CP2, CP3, F3, F4); preprocessing v0.6.1

Expand Down
10 changes: 8 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@
# below adds its OME-Zarr reader at the same tag. v0.6.0 is Spec ADR 0005
# steps 2 and 2b (resolver contract v3, RunInputs.read_objects, the
# conversion helpers); v0.6.1 fixes the checked-fingerprint race.
# TODO(tag): draft PR #128 only. RunStoppedError (preprocessing #322, merged
# in #324) is on preprocessing's main, not yet in a release: pinned to that
# commit until the next preprocessing release is tagged, then back to its
# tag (here, in the zarr extra and in tests/test_dependency_pins.py) before
# #128 is merged.
"morphobricks-preprocessing @ git+https://github.com/CellMigrationLab/"
"morphobricks-preprocessing@v0.6.1",
"morphobricks-preprocessing@b24371abe0a728995f44b2f8f1dd6d36b4a4addc",
# CellPatcher imports the normalization brick directly (plane histograms,
# the plane table, pooling, normalization parameters, SINGLE), so it
# declares it, at the tag the preprocessing tag above pins (owner
Expand Down Expand Up @@ -62,8 +67,9 @@
# name of this extra, ``preprocessing``, is gone: the preprocessing brick
# is a core dependency.
"zarr": [
# TODO(tag): the commit of the core pin above until the preprocessing release.
"morphobricks-preprocessing[zarr] @ git+https://github.com/CellMigrationLab/"
"morphobricks-preprocessing@v0.6.1",
"morphobricks-preprocessing@b24371abe0a728995f44b2f8f1dd6d36b4a4addc",
],
},
)
52 changes: 50 additions & 2 deletions src/cellpatcher/run_open.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ def open_run(
``unrecorded_files`` (images or masks the run did not record),
``zarr_extra_missing`` or ``preprocessing_run_refused``, with the brick's
reason, when ``RunInputs`` refuses the run, or
``unreadable_plane_histograms`` when its table cannot be read.
``unreadable_plane_histograms`` when its table cannot be read. For a folder
where preprocessing stopped without writing a run (``RunStoppedError``),
preprocessing's own errors come first, unchanged (:func:`_refusal_issues`,
issue #126); ``RUN_FOLDER_REPORT_UNREADABLE`` when its report cannot be read.
"""
from morphobricks_normalization.csv_io import CsvFormatError
from morphobricks_preprocessing.manifest import ManifestFormatError
Expand All @@ -190,7 +193,7 @@ def open_run(
except (RunInputsError, ManifestFormatError) as exc:
# ManifestFormatError: a manifest of another version (preprocessing v0.5.1 reads version 4 only,
# older runs are refused, never converted) or not a manifest at all.
raise PreprocessingCheckError([_refusal_issue(exc, folder)]) from exc
raise PreprocessingCheckError(_refusal_issues(exc, folder)) from exc
except CsvFormatError as exc:
raise PreprocessingCheckError([
error(
Expand All @@ -208,6 +211,51 @@ def open_run(
"""The code of a run without a published experiment description (Spec ADR 0002 AR10, AR11 (1))."""


def _refusal_issues(exc: Exception, folder: Path) -> list[ValidationIssue]:
"""Return the issues for ``RunInputs.open`` refusing the run in *folder*.

Where preprocessing stopped on purpose without writing a run (Spec ``v29``:
``R_HETEROGENEOUS_LAYOUT_NOT_ENABLED``), ``RunInputs.open`` raises ``RunStoppedError``
(``RUN_FOLDER_STOPPED``, preprocessing contract §9.1) with the stopped run's error issues. A run
of the same experiment stops the same way, so "run preprocessing again" would loop (issue #126):
those issues are passed on first, unchanged and in order (Spec ADR 0005, construction and
propagation), followed by CellPatcher's ``preprocessing_run_refused`` naming the folder, which
gives no re-run advice. A report preprocessing cannot read (``RunReportUnreadableError``) is
refused with its code, ``RUN_FOLDER_REPORT_UNREADABLE``. CellPatcher never reads the report.
"""
from morphobricks_preprocessing import MANIFEST_FILENAME, RunReportUnreadableError, RunStoppedError
from morphobricks_preprocessing.validation import error

if isinstance(exc, RunStoppedError):
return [*exc.issues, error(
"preprocessing_run_refused",
f"The preprocessing run in {folder} cannot be used: it holds no run_manifest.json, because "
f"preprocessing stopped there without writing a run ({RunStoppedError.code}), for the errors "
"listed above.",
[str(folder)],
"Do what preprocessing's suggested actions above say; the run is written only once preprocessing "
"no longer stops there. Then give CellPatcher that run.",
)]
if isinstance(exc, RunReportUnreadableError):
return [error(
RunReportUnreadableError.code,
f"The preprocessing run in {folder} cannot be used: {exc}",
[str(exc.path)],
"Run preprocessing again into that folder with the preprocessing CellPatcher installs, which "
"writes a report it can read, then give CellPatcher that run.",
)]
if (folder / MANIFEST_FILENAME).exists(): # a written run: stale, older or changed since
return [_refusal_issue(exc, folder)]
return [error(
"preprocessing_run_refused",
f"The preprocessing run in {folder} cannot be used: {exc}",
[str(folder)],
"Give CellPatcher the output folder of a preprocessing run that was written (it holds "
"run_manifest.json), or run preprocessing on the experiment first. If preprocessing stopped in "
"that folder, its discovery_report.txt there says why and what to fix.",
)]


def _refusal_issue(exc: Exception, folder: Path) -> ValidationIssue:
"""Return the issue for ``RunInputs.open`` refusing the run in *folder*, by its reason.

Expand Down
8 changes: 7 additions & 1 deletion tests/test_dependency_pins.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,20 @@ def test_the_zarr_extra_installs_the_core_preprocessing_tag():
assert _url(zarr) == _url(_by_name(core)["morphobricks-preprocessing"])


PREPROCESSING_MAIN_COMMIT = "b24371abe0a728995f44b2f8f1dd6d36b4a4addc"
"""TODO(tag): draft PR #128 only. Preprocessing's main with RunStoppedError (#322, merged in #324),
not yet released. Remove it, and pin the release tag, before #128 is merged."""


def test_preprocessing_is_pinned_to_a_release_tag_not_a_commit():
# Stage 2 CP-1 pinned the v0.5.0 release-candidate commit until the tag existed; a commit pin
# is not a release, and every brick must spell the same URL (pip refuses two for one package).
# TODO(tag): on draft PR #128 the one accepted commit is PREPROCESSING_MAIN_COMMIT, until the tag.
core, extras = _setup_requirements()
for requirement in (_by_name(core)["morphobricks-preprocessing"], *extras["zarr"]):
repository, ref = _url(requirement).rsplit("@", 1)
assert repository == "git+https://github.com/CellMigrationLab/morphobricks-preprocessing", requirement
assert re.fullmatch(r"v\d+\.\d+\.\d+", ref), (
assert re.fullmatch(r"v\d+\.\d+\.\d+", ref) or ref == PREPROCESSING_MAIN_COMMIT, (
f"{requirement}: pin a release tag, not {ref!r}"
)

Expand Down
Loading
Loading