From 29d39e2f9362279ca6ebf743dfda0b59c536b3d2 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 18:52:29 +0000 Subject: [PATCH] html_report: place repeat_group as the repeat level (#642) html_report, plots and plots_of_data refused group_cols=("condition", "repeat_group"), the groups MorphoFeature's end-to-end notebook passes (section 4), with "group_cols [...] hold ['repeat_group'], which the figure does not place", so the coverage page failed on every run with repeat groups. One shared notion of the figures' biological-repeat level, _repeat_groups.repeat_level(group_cols): repeat_group when the analysis groups name it, else biological_repeat; both are refused, since a figure has one repeat level and keeping the folder label apart beside the repeat group would split or pair repeats by folder. plots._layout places it (and pools it with repeat_col=None), the pairwise matrix pairs by it, the HTML report's interactive figure reads it and the figure's words name it as a biological repeat. Nothing falls back to biological_repeat; the biological_repeat path is unchanged. Fixes #642 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01G3qp9AxjpGPw9xfWAUJNqc --- CHANGELOG.md | 10 + docs/common/function_index.jsonl | 19 +- docs/report/figures.md | 8 +- src/morphocoverage/_plots_text.py | 25 +- src/morphocoverage/_repeat_groups.py | 29 ++- src/morphocoverage/plots.py | 24 +- src/morphocoverage/plots_pairwise.py | 8 +- src/morphocoverage/workflows/_html_plotly.py | 4 +- tests/test_figure_repeat_level.py | 232 +++++++++++++++++++ 9 files changed, 325 insertions(+), 34 deletions(-) create mode 100644 tests/test_figure_repeat_level.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b98ba12..f648d166 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,16 @@ inventory's, not the Stage 2 MC-1/MC-2 of the experiment description. A `next_fov` table without `uninformative` and a `final` table without `warning_list` are no longer accepted. The joined `warnings` text is no longer read as a fallback. +### Fixed + +- **#642.** `html_report`, `plots` and `plots_of_data` with `group_cols=("condition", + "repeat_group")`, the groups of MorphoFeature's notebooks, no longer raise "group_cols ... + hold ['repeat_group'], which the figure does not place". The figures place `repeat_group` + as their biological-repeat level (`_repeat_groups.repeat_level`), labelled by its values; + the pairwise matrix pairs by it and the HTML report's interactive figures read it. Nothing + falls back to the folder label `biological_repeat`; `group_cols` naming both columns are + refused, since a figure has one repeat level. The `biological_repeat` path is unchanged. + ### Changed - **Q-MC-a.** `microscopist_report` refuses (`ValueError`) a result that records no acquisition diff --git a/docs/common/function_index.jsonl b/docs/common/function_index.jsonl index d606110c..c8adb4fd 100644 --- a/docs/common/function_index.jsonl +++ b/docs/common/function_index.jsonl @@ -296,14 +296,14 @@ {"arguments": 12, "called_by": ["plots:_draw_clusters"], "calls": ["?.append", "?.fromkeys", "?.hlines", "?.scatter", "?.setdefault", "?.uniform", "?.values", "?.vlines", "_plots_clusters:_unit_keys", "_plots_clusters:_unit_mask", "any", "float", "len", "numpy.flatnonzero", "numpy.isfinite", "numpy.isnan", "statistics:bootstrap_nested"], "complexity": 9, "decorators": [], "hash": "cb8d2898fe27cdb5", "kind": "function", "lines": 45, "module": "_plots_clusters", "name": "_draw_cluster", "public": false, "signature": "(ax: Axes, x: float, width: float, rows: np.ndarray, values: np.ndarray, fields: tuple[pd.DataFrame, pd.DataFrame, list[np.ndarray], np.ndarray], layout: Any, colour: str, statistic: Callable[[np.ndarray], float], n_boot: int, confidence: float, rng: np.random.Generator) -> tuple[float, float, float]", "summary": "One cluster (a condition and biological repeat): its points in the condition's", "varargs": []} {"arguments": 2, "called_by": ["plots:_figure"], "calls": ["?.append", "?.groupby", "?.nunique", "int", "len"], "complexity": 6, "decorators": [], "hash": "6ded7b557f0d7da8", "kind": "function", "lines": 13, "module": "_plots_clusters", "name": "_cluster_units", "public": false, "signature": "(observed: pd.DataFrame, layout: Any) -> list[tuple[int, list[int]]]", "summary": "Per cluster: its top-level units with observations, and each one's technical repeats.", "varargs": []} {"calls": [], "kind": "module", "module": "_plots_text", "name": "", "public": false, "summary": "The words of a ``plots.plots_of_data`` figure (private): its title, which says what is"} -{"arguments": 4, "called_by": ["plots:_figure"], "calls": ["?.legend", "?.scatter", "?.text", "_plots_text:_named", "_wording:ordinal", "len", "range"], "complexity": 4, "decorators": [], "hash": "ae8904d341379af5", "kind": "function", "lines": 39, "module": "_plots_text", "name": "legend", "public": true, "signature": "(ax: Axes, layout: Any, shapes: Sequence[str], n_technical: int) -> None", "summary": "The technical repeats' shapes, by rank, beside the plot; nothing when every biological", "varargs": []} +{"arguments": 4, "called_by": ["plots:_figure"], "calls": ["?.legend", "?.scatter", "?.text", "_plots_text:_named", "_wording:ordinal", "len", "range"], "complexity": 4, "decorators": [], "hash": "1ae1c748a06bf423", "kind": "function", "lines": 39, "module": "_plots_text", "name": "legend", "public": true, "signature": "(ax: Axes, layout: Any, shapes: Sequence[str], n_technical: int) -> None", "summary": "The technical repeats' shapes, by rank, beside the plot; nothing when every biological", "varargs": []} {"arguments": 1, "called_by": ["_plots_text:_resampled", "_plots_text:_technical_resampled"], "calls": ["max", "min"], "complexity": 2, "decorators": [], "hash": "2c2b3b4fa7bc46b0", "kind": "function", "lines": 1, "module": "_plots_text", "name": "_span", "public": false, "signature": "(counts: Sequence[int]) -> str", "summary": "``3`` or ``2 to 5``.", "varargs": []} -{"arguments": 3, "called_by": ["_plots_text:_pooled_name", "_plots_text:_split_phrase", "_plots_text:_technical_resampled", "_plots_text:legend", "_plots_text:title"], "calls": ["?.lower", "?.rstrip", "str"], "complexity": 3, "decorators": [], "hash": "81d0867a35657592", "kind": "function", "lines": 3, "module": "_plots_text", "name": "_named", "public": false, "signature": "(word: str, column: str | None, standard: str) -> str", "summary": "``word``, with its column in brackets when the column has another name than the", "varargs": []} -{"arguments": 1, "called_by": ["_plots_text:_resampled", "_plots_text:_split_phrase"], "calls": ["?.join", "_plots_text:_named", "len"], "complexity": 3, "decorators": [], "hash": "cee658a91b0220a8", "kind": "function", "lines": 6, "module": "_plots_text", "name": "_pooled_name", "public": false, "signature": "(layout: Any) -> str", "summary": "The pooled top-level units in words: ``biological repeats`` or their columns.", "varargs": []} -{"arguments": 7, "called_by": ["plots:_figure"], "calls": ["_plots_text:_named", "_plots_text:_resampled", "_plots_text:_split_phrase", "_wording:rate"], "complexity": 5, "decorators": [], "hash": "f35cf0a961f44cee", "kind": "function", "lines": 14, "module": "_plots_text", "name": "title", "public": true, "signature": "(feature: str, part: str, layout: Any, unit: str, summary: str, level: float, clusters: Sequence[tuple[int, list[int]]]=()) -> str", "summary": "Three lines: what is plotted and how it is split, what a point is, what the interval is.", "varargs": []} -{"arguments": 1, "called_by": ["_plots_text:title"], "calls": ["?.join", "_plots_text:_named", "_plots_text:_pooled_name"], "complexity": 5, "decorators": [], "hash": "361869b61888929f", "kind": "function", "lines": 15, "module": "_plots_text", "name": "_split_phrase", "public": false, "signature": "(layout: Any) -> str", "summary": "How the plot is split: biological repeats pooled or side by side, and the units", "varargs": []} +{"arguments": 3, "called_by": ["_plots_text:_pooled_name", "_plots_text:_split_phrase", "_plots_text:_technical_resampled", "_plots_text:legend", "_plots_text:title"], "calls": ["?.lower", "?.rstrip", "str"], "complexity": 4, "decorators": [], "hash": "88ac7048c439de86", "kind": "function", "lines": 3, "module": "_plots_text", "name": "_named", "public": false, "signature": "(word: str, column: str | None, standard: Sequence[str]) -> str", "summary": "``word``, with its column in brackets when the column has another name than the", "varargs": []} +{"arguments": 1, "called_by": ["_plots_text:_resampled", "_plots_text:_split_phrase"], "calls": ["?.join", "_plots_text:_named", "len"], "complexity": 3, "decorators": [], "hash": "83dec9969c243fb0", "kind": "function", "lines": 6, "module": "_plots_text", "name": "_pooled_name", "public": false, "signature": "(layout: Any) -> str", "summary": "The pooled top-level units in words: ``biological repeats`` or their columns.", "varargs": []} +{"arguments": 7, "called_by": ["plots:_figure"], "calls": ["_plots_text:_named", "_plots_text:_resampled", "_plots_text:_split_phrase", "_wording:rate"], "complexity": 5, "decorators": [], "hash": "f5d32ad572c98723", "kind": "function", "lines": 14, "module": "_plots_text", "name": "title", "public": true, "signature": "(feature: str, part: str, layout: Any, unit: str, summary: str, level: float, clusters: Sequence[tuple[int, list[int]]]=()) -> str", "summary": "Three lines: what is plotted and how it is split, what a point is, what the interval is.", "varargs": []} +{"arguments": 1, "called_by": ["_plots_text:title"], "calls": ["?.join", "_plots_text:_named", "_plots_text:_pooled_name"], "complexity": 5, "decorators": [], "hash": "d03e32a20e22d1f2", "kind": "function", "lines": 15, "module": "_plots_text", "name": "_split_phrase", "public": false, "signature": "(layout: Any) -> str", "summary": "How the plot is split: biological repeats pooled or side by side, and the units", "varargs": []} {"arguments": 3, "called_by": ["_plots_text:title"], "calls": ["?.append", "?.join", "_plots_text:_pooled_name", "_plots_text:_span", "_plots_text:_technical_resampled", "any"], "complexity": 6, "decorators": [], "hash": "6e9f1be95f61c17f", "kind": "function", "lines": 18, "module": "_plots_text", "name": "_resampled", "public": false, "signature": "(layout: Any, cluster: str, clusters: Sequence[tuple[int, list[int]]]) -> tuple[str, str]", "summary": "What the interval resamples, and the caveat lines on how few units it resamples.", "varargs": []} -{"arguments": 6, "called_by": ["_plots_text:_resampled"], "calls": ["?.append", "_plots_text:_named", "_plots_text:_span", "all", "any"], "complexity": 9, "decorators": [], "hash": "9a7c985f46ad1a16", "kind": "function", "lines": 22, "module": "_plots_text", "name": "_technical_resampled", "public": false, "signature": "(phrases: list[str], caveat: str, layout: Any, cluster: str, single: list[int], by_top: list[int]) -> str", "summary": "Add to ``phrases`` what is resampled within clusters of one top-level unit (whole", "varargs": []} +{"arguments": 6, "called_by": ["_plots_text:_resampled"], "calls": ["?.append", "_plots_text:_named", "_plots_text:_span", "all", "any"], "complexity": 9, "decorators": [], "hash": "3e9df6dd4c6768c9", "kind": "function", "lines": 22, "module": "_plots_text", "name": "_technical_resampled", "public": false, "signature": "(phrases: list[str], caveat: str, layout: Any, cluster: str, single: list[int], by_top: list[int]) -> str", "summary": "Add to ``phrases`` what is resampled within clusters of one top-level unit (whole", "varargs": []} {"calls": [], "kind": "module", "module": "_rare_label", "name": "", "public": false, "summary": "The one contract of a rare-state label column (private; issue 344)."} {"arguments": 2, "called_by": ["_rare_label:known_flags", "retrospective.inspection:_check_columns", "strategies.rare_incidence:_positive_fovs", "workflows._shared:_check_labels_and_scales"], "calls": ["?.dropna", "?.unique", "ValueError", "map", "pandas.api.types.is_bool_dtype", "set", "sorted"], "complexity": 3, "decorators": [], "hash": "08ac4a7ee40f026c", "kind": "function", "lines": 5, "module": "_rare_label", "name": "check_rare_labels", "public": true, "signature": "(values: pd.Series, name: str) -> None", "summary": "Refuse a label column holding anything but booleans, 0/1 or missing values;", "varargs": []} {"arguments": 2, "called_by": ["retrospective._field_reasons:_novel"], "calls": ["?.astype", "?.notna", "?.to_numpy", "?.where", "_rare_label:check_rare_labels"], "complexity": 1, "decorators": [], "hash": "a1f856b6ccd85fc1", "kind": "function", "lines": 4, "module": "_rare_label", "name": "known_flags", "public": true, "signature": "(values: pd.Series, name: str) -> tuple[np.ndarray, np.ndarray]", "summary": "``(known, flags)`` of a label column: which observations carry a label, and which of", "varargs": []} @@ -316,6 +316,7 @@ {"arguments": 2, "called_by": [], "calls": ["?.join", "_repeat_groups:_folder_path", "str"], "complexity": 3, "decorators": [], "hash": "ae8cc8f8d34236e8", "kind": "method", "lines": 3, "module": "_repeat_groups", "name": "Pairing.folder_of", "public": true, "signature": "(self, condition: Any, repeat: Any=None) -> str | None", "summary": "``\"control/rep1\"``: the folders of a working-table condition and repeat when they", "varargs": []} {"arguments": 6, "called_by": ["_repeat_groups:pair_by_repeat_group", "workflows._pairing:paired_inputs"], "calls": ["_condition_ids:checked_condition_ids", "_condition_ids:held_conditions", "_condition_ids:refuse_folder_names", "_condition_ids:refuse_unmatched", "_repeat_groups:_checked_groups", "_repeat_groups:_pairing", "_repeat_groups:_relabelled", "list"], "complexity": 3, "decorators": [], "hash": "e83be20316b8d9d6", "kind": "function", "lines": 10, "module": "_repeat_groups", "name": "paired_tables", "public": true, "signature": "(objects: pd.DataFrame, fovs: pd.DataFrame, *, condition_col: str=CONDITION_COLUMN, others: Sequence[pd.DataFrame]=(), names: Iterable[Any]=(), selected: Iterable[Any]=()) -> tuple[pd.DataFrame, pd.DataFrame, list[pd.DataFrame], Pairing]", "summary": "The tables with each folder label replaced by its repeat group and each condition", "varargs": []} {"arguments": 5, "called_by": ["normalize:_control_rows", "normalize:normalize_to_control", "normalize:normalize_to_own", "retrospective.controls:representation_control", "retrospective.effect_preservation:effect_preservation", "sampling_unit.contrast:condition_contrast", "sampling_unit.discovery:feature_discovery", "sampling_unit.distribution:distribution_contrast", "sampling_unit.object_rules:object_rule_check", "sampling_unit.ranking:feature_ranking", "sampling_unit.unusual:unusual_objects"], "calls": ["_condition_ids:PairingRefused", "_condition_ids:declared_conditions", "_repeat_groups:named_by_id", "_repeat_groups:paired_tables", "any"], "complexity": 4, "decorators": [], "hash": "57be6c69d913f106", "kind": "function", "lines": 15, "module": "_repeat_groups", "name": "pair_by_repeat_group", "public": true, "signature": "(objects: pd.DataFrame, fovs: pd.DataFrame, repeat_col: str | None, condition_col: str=CONDITION_COLUMN, control: Mapping[str, Any] | None=None) -> tuple[pd.DataFrame, pd.DataFrame, str | None, Pairing]", "summary": "The tables an analysis pairing by ``repeat_col`` reads, the repeat column to use in", "varargs": []} +{"arguments": 1, "called_by": ["plots:_layout", "plots_pairwise:pairwise_contrasts", "workflows._html_plotly:_observations"], "calls": ["ValueError", "len"], "complexity": 4, "decorators": [], "hash": "e02c4087d81b6ffd", "kind": "function", "lines": 8, "module": "_repeat_groups", "name": "repeat_level", "public": true, "signature": "(group_cols: Iterable[str] | None) -> str", "summary": "The column a figure places as its biological-repeat level, from the analysis groups.", "varargs": []} {"arguments": 4, "called_by": ["_repeat_groups:pair_by_repeat_group", "data_check:_named_by_id", "plots:plots_of_data", "plots_pairwise:pairwise_contrasts", "retrospective.overview:dataset_overview", "sampling_unit.clustering:fov_clustering", "workflows._scan_rules:named_tables"], "calls": ["_condition_ids:checked_condition_ids", "_condition_ids:declared_conditions", "_condition_ids:refuse_folder_names", "_repeat_groups:Pairing", "_repeat_groups:_pairing", "_repeat_groups:_relabelled", "isinstance", "type"], "complexity": 6, "decorators": [], "hash": "07cfc272412d82d1", "kind": "function", "lines": 9, "module": "_repeat_groups", "name": "named_by_id", "public": true, "signature": "(objects: pd.DataFrame, fovs: pd.DataFrame | None=None, control: Mapping[str, Any] | None=None, condition_col: str=CONDITION_COLUMN) -> tuple[pd.DataFrame, pd.DataFrame | None, Pairing]", "summary": "The tables with each condition folder replaced by its ``condition_id`` (the repeats as", "varargs": []} {"arguments": 3, "called_by": [], "calls": ["_repeat_groups:_checked_groups", "_repeat_groups:_renamed"], "complexity": 1, "decorators": [], "hash": "20e23f3c592e9631", "kind": "function", "lines": 1, "module": "_repeat_groups", "name": "repeat_groups", "public": true, "signature": "(objects: pd.DataFrame, fovs: pd.DataFrame, *, condition_col: str=CONDITION_COLUMN) -> dict[tuple[Any, Any], Any]", "summary": "Each ``(condition, folder label)`` whose repeat group is not its label, mapped to the", "varargs": []} {"arguments": 1, "called_by": ["_repeat_groups:_pairing", "_repeat_groups:repeat_groups"], "calls": ["?.items", "str"], "complexity": 1, "decorators": [], "hash": "eefa8629ec8fe0dc", "kind": "function", "lines": 1, "module": "_repeat_groups", "name": "_renamed", "public": false, "signature": "(groups: dict[tuple[Any, Any], Any]) -> dict[tuple[Any, Any], Any]", "summary": "The folders whose repeat group is not their label.", "varargs": []} @@ -795,7 +796,7 @@ {"called_by": ["plots:_layout"], "calls": ["dataclasses.dataclass"], "decorators": ["dataclass(frozen=True)"], "hash": "c0d75d155c7b9748", "kind": "class", "module": "plots", "name": "_Layout", "public": false, "signature": "()", "summary": "How the tables split into clusters: the columns used and their distinct values."} {"arguments": 2, "called_by": ["plots:_layout", "plots:plots_of_data"], "calls": ["?.any", "?.first", "?.fromkeys", "?.groupby", "?.isna", "?.nunique", "?.reindex", "?.reset_index", "?.sum", "?.to_numpy", "ValueError", "int", "metadata:empty_values", "pandas.DataFrame", "pandas.Series", "schema:fov_positions"], "complexity": 8, "decorators": [], "hash": "06dc70a73ea1e587", "kind": "function", "lines": 30, "module": "plots", "name": "_field_metadata", "public": false, "signature": "(data: ValidatedInput, columns: Sequence[str | None]) -> pd.DataFrame", "summary": "The layout's columns for every acquired field, from the FOV table.", "varargs": []} {"arguments": 4, "called_by": ["plots:_layout"], "calls": ["ValueError"], "complexity": 4, "decorators": [], "hash": "f87f814bef206d47", "kind": "function", "lines": 8, "module": "plots", "name": "_column", "public": false, "signature": "(columns: set[str], column: str | None, default: str | None, name: str) -> str | None", "summary": "``column`` when the tables have it, ``None`` when it is an absent default; else raise.", "varargs": []} -{"arguments": 6, "called_by": ["plots:plots_of_data"], "calls": ["ValueError", "len", "list", "metadata:sorted_labels", "plots:_Layout", "plots:_column", "plots:_field_metadata", "schema:fov_positions", "set", "tuple", "zip"], "complexity": 9, "decorators": [], "hash": "2c966aba2cc58c00", "kind": "function", "lines": 38, "module": "plots", "name": "_layout", "public": false, "signature": "(data: ValidatedInput, condition_col: str | None, repeat_col: str | None, technical_col: str | None, max_repeats: int, control: Any=None) -> _Layout", "summary": "Resolve the condition, repeat and technical columns and their values.", "varargs": []} +{"arguments": 6, "called_by": ["plots:plots_of_data"], "calls": ["ValueError", "_repeat_groups:repeat_level", "len", "list", "metadata:sorted_labels", "plots:_Layout", "plots:_column", "plots:_field_metadata", "schema:fov_positions", "set", "tuple", "zip"], "complexity": 10, "decorators": [], "hash": "23e4449494e54db1", "kind": "function", "lines": 42, "module": "plots", "name": "_layout", "public": false, "signature": "(data: ValidatedInput, condition_col: str | None, repeat_col: str | None, technical_col: str | None, max_repeats: int, control: Any=None) -> _Layout", "summary": "Resolve the condition, repeat and technical columns and their values.", "varargs": []} {"arguments": 20, "called_by": ["workflows.figures:plots"], "calls": ["?.get", "?.reset_index", "ValueError", "_condition_ids:declared_conditions", "_repeat_alias:refuse_repeat_alias", "_repeat_groups:named_by_id", "data_check:validate_input_tables", "dict", "len", "list", "metadata:column_names", "plots:_Plot", "plots:_counts", "plots:_feature_figures", "plots:_field_metadata", "plots:_layout", "schema:fov_positions", "sorted"], "complexity": 7, "decorators": [], "hash": "63dc18b5c6efde31", "kind": "function", "lines": 47, "module": "plots", "name": "plots_of_data", "public": true, "signature": "(objects: pd.DataFrame, fovs: pd.DataFrame, *, features: Sequence[str], condition_col: str | None=MORPHOBRICKS_GROUP_COLUMNS[0], repeat_col: str | None=MORPHOBRICKS_GROUP_COLUMNS[1], technical_col: str | None=None, summary: str='median', confidence: float=0.95, n_boot: int=1000, random_state: int=0, max_conditions: int=MAX_CONDITIONS, max_repeats: int=MAX_REPEATS, max_technical: int=MAX_TECHNICAL, max_features: int=MAX_FEATURES, fov_col: str | None=None, group_cols: Sequence[str] | None=None, observation_unit: str | None=None, value_note: str | None=None, control: Mapping[str, Any] | None=None, highlight: Sequence[Any]=()) -> dict[str, list[Figure]]", "summary": "One or more figures per feature (see the module); keys are the feature names.", "varargs": []} {"arguments": 4, "called_by": ["plots:plots_of_data"], "calls": ["ValueError", "_checks:is_integer", "int", "len"], "complexity": 5, "decorators": [], "hash": "5894af9bbd4378d3", "kind": "function", "lines": 15, "module": "plots", "name": "_counts", "public": false, "signature": "(n_boot: Any, max_conditions: Any, max_repeats: Any, max_technical: Any) -> tuple[int, int, int, int]", "summary": "The resamples and the most conditions, repeats and technical repeats, checked", "varargs": []} {"called_by": ["plots:plots_of_data"], "calls": ["dataclasses.dataclass"], "decorators": ["dataclass(frozen=True)"], "hash": "b6642ed5458fd53b", "kind": "class", "module": "plots", "name": "_Plot", "public": false, "signature": "()", "summary": "What every figure of one ``plots_of_data`` call shares: the data, the layout, every"} @@ -814,7 +815,7 @@ {"calls": ["?.replace"], "kind": "module", "module": "plots_pairwise", "name": "", "public": true, "summary": "Every pair of conditions for one feature, as the lab's Plot&Stats notebook shows them"} {"arguments": 1, "called_by": ["plots_pairwise:add_pairwise", "workflows._html_figures:_verdict_paragraph"], "calls": ["?.items", "?.join", "numpy.isfinite", "plots_pairwise:format_p"], "complexity": 3, "decorators": [], "hash": "aede0a62b2ffa447", "kind": "function", "lines": 6, "module": "plots_pairwise", "name": "verdict_note", "public": true, "signature": "(verdicts: Mapping[Any, float]) -> str", "summary": "The verdict's q of each condition against its control, the feature's family (audit", "varargs": []} {"arguments": 3, "called_by": ["plots_pairwise:_pair"], "calls": ["_repeat_statistics:paired_t", "_repeat_statistics:repeat_values", "len", "numpy.array", "numpy.mean"], "complexity": 2, "decorators": [], "hash": "cb3cd1ebb5bdc512", "kind": "function", "lines": 7, "module": "plots_pairwise", "name": "_paired", "public": false, "signature": "(first: dict, second: dict, log: bool | None=None) -> tuple[float, str, int]", "summary": "The paired t-test of two conditions on the repeats they share, on the feature's scale", "varargs": []} -{"arguments": 12, "called_by": ["workflows.figures:_add_pairwise"], "calls": ["?.append", "?.feature_values", "?.get", "?.groupby", "?.reset_index", "?.to_numpy", "_checks:as_count", "_checks:check_seed", "_repeat_groups:named_by_id", "_repeat_statistics:log_scale", "data_check:validate_input_tables", "itertools.combinations", "len", "list", "metadata:sorted_labels", "numpy.isnan", "pandas.DataFrame", "plots_pairwise:_apart", "plots_pairwise:_pair", "repr", "schema:fov_positions", "statistics:benjamini_hochberg"], "complexity": 12, "decorators": [], "hash": "7999c97cc9abdc60", "kind": "function", "lines": 42, "module": "plots_pairwise", "name": "pairwise_contrasts", "public": true, "signature": "(objects: pd.DataFrame, fovs: pd.DataFrame, *, feature: str, conditions: Sequence[Any] | None=None, control: Any=None, fov_col: str | None=None, group_cols: Sequence[str] | None=None, observation_unit: str | None=None, n_permutations: int=N_PERMUTATIONS, random_state: int=0, references: Mapping[Any, Any] | None=None, scale: str | None=None) -> pd.DataFrame", "summary": "One row per pair of ``conditions`` (all, the ``control`` first, by default); see the", "varargs": []} +{"arguments": 12, "called_by": ["workflows.figures:_add_pairwise"], "calls": ["?.append", "?.feature_values", "?.get", "?.groupby", "?.reset_index", "?.to_numpy", "_checks:as_count", "_checks:check_seed", "_repeat_groups:named_by_id", "_repeat_groups:repeat_level", "_repeat_statistics:log_scale", "data_check:validate_input_tables", "itertools.combinations", "len", "list", "metadata:sorted_labels", "numpy.isnan", "pandas.DataFrame", "plots_pairwise:_apart", "plots_pairwise:_pair", "repr", "schema:fov_positions", "statistics:benjamini_hochberg"], "complexity": 12, "decorators": [], "hash": "9e4be987a069295c", "kind": "function", "lines": 44, "module": "plots_pairwise", "name": "pairwise_contrasts", "public": true, "signature": "(objects: pd.DataFrame, fovs: pd.DataFrame, *, feature: str, conditions: Sequence[Any] | None=None, control: Any=None, fov_col: str | None=None, group_cols: Sequence[str] | None=None, observation_unit: str | None=None, n_permutations: int=N_PERMUTATIONS, random_state: int=0, references: Mapping[Any, Any] | None=None, scale: str | None=None) -> pd.DataFrame", "summary": "One row per pair of ``conditions`` (all, the ``control`` first, by default); see the", "varargs": []} {"arguments": 7, "called_by": ["plots_pairwise:pairwise_contrasts"], "calls": ["?.groupby", "?.isin", "?.to_numpy", "_seeds:group_rng", "len", "numpy.isfinite", "plots_pairwise:_paired", "sampling_unit.contrast_cells:cell_randomization", "set", "statistics:cohen_d"], "complexity": 3, "decorators": [], "hash": "4ca5c99bf20f6ebd", "kind": "function", "lines": 31, "module": "plots_pairwise", "name": "_pair", "public": false, "signature": "(feature: str, pair: tuple[Any, Any], a: pd.DataFrame, b: pd.DataFrame, log: bool, n_permutations: int, random_state: int) -> dict", "summary": "One pair of conditions compared: d and the cell-level test on the repeats that imaged", "varargs": []} {"arguments": 5, "called_by": ["plots_pairwise:pairwise_contrasts"], "calls": ["len", "set"], "complexity": 1, "decorators": [], "hash": "ba3edf92d64ed517", "kind": "function", "lines": 14, "module": "plots_pairwise", "name": "_apart", "public": false, "signature": "(feature: str, first: Any, second: Any, a: pd.DataFrame, b: pd.DataFrame) -> dict", "summary": "A pair normalised to different controls: counted, not compared (``APART``).", "varargs": []} {"arguments": 3, "called_by": ["plots_pairwise:d_colour", "plots_pairwise:p_colour"], "calls": ["tuple", "zip"], "complexity": 1, "decorators": [], "hash": "51f2e0c38d40ad63", "kind": "function", "lines": 1, "module": "plots_pairwise", "name": "_mix", "public": false, "signature": "(start: tuple, end: tuple, share: float) -> tuple[float, float, float]", "summary": "", "varargs": []} @@ -3121,7 +3122,7 @@ {"calls": ["?.with_name", "pathlib.Path"], "kind": "module", "module": "workflows._html_plotly", "name": "", "public": false, "summary": "The HTML report's interactive feature figures (private; ``html_report``), drawn by"} {"arguments": 0, "called_by": ["workflows._html_page:plotly_scripts"], "calls": ["?.read_text", "?.replace"], "complexity": 1, "decorators": ["cache"], "hash": "40b593d8a736bd65", "kind": "function", "lines": 1, "module": "workflows._html_plotly", "name": "plotly_js", "public": true, "signature": "() -> str", "summary": "The plotly.js bundle, as text for a ``', page).group(1)) + return next(s for s in specs if s["feature"] == "area")["views"]["raw"] + + +@pytest.mark.filterwarnings("ignore::UserWarning") +@pytest.mark.filterwarnings("ignore::FutureWarning") +def test_the_page_is_written_and_shows_the_repeat_groups(tmp_path): + objects, fovs = _tables(RENAMED) + drawn = {} + for group_cols in (("condition", "repeat_group"), ("condition", "biological_repeat")): + setup = Setup( + readout="area", + features=FEATURES, + control={"condition": "ctrl"}, + observation_unit="cell", + group_cols=group_cols, + ) + result = report(objects, fovs, setup) + folder = tmp_path / group_cols[1] + drawn[group_cols[1]] = _feature_specs( + html_report(result, objects, fovs, folder).read_text() + ) + clusters = drawn["repeat_group"]["clusters"] + assert sorted({c["biological_repeat"] for c in clusters}) == ["G1", "G2", "G3"] + # Every point's hover names its repeat group first, then its field. + labels = drawn["repeat_group"]["points"]["label"] + assert {label.split(" ยท ")[0] for label in labels} == {"G1", "G2", "G3"} + # The workflows read the tables paired by repeat group (#617): the folder-label path + # draws the same repeats, the same numbers. + assert clusters == drawn["biological_repeat"]["clusters"] + assert drawn["repeat_group"]["pairwise"] == drawn["biological_repeat"]["pairwise"] + + +@pytest.mark.filterwarnings("ignore::UserWarning") +@pytest.mark.filterwarnings("ignore::FutureWarning") +def test_the_page_refuses_group_cols_naming_both_repeat_columns(tmp_path): + objects, fovs = _tables() + setup = Setup( + readout="area", + features=FEATURES, + control={"condition": "ctrl"}, + observation_unit="cell", + group_cols=("condition", "biological_repeat", "repeat_group"), + ) + result = report(objects, fovs, setup) + with pytest.raises(ValueError, match=BOTH): + html_report(result, objects, fovs, tmp_path) + + +def _default_groups(fovs: pd.DataFrame) -> tuple[str, ...]: + """MorphoFeature's ``notebook_results.default_groups``: the condition and the canonical + ``repeat_group``, refused (never the folder label) when the FOV table has none.""" + if "repeat_group" not in fovs.columns: + raise ValueError("the coverage FOV table has no 'repeat_group' column") + return ("condition", "repeat_group") + + +@pytest.mark.filterwarnings("ignore::UserWarning") +@pytest.mark.filterwarnings("ignore::FutureWarning") +def test_the_morphofeature_notebook_writes_its_page(tmp_path): + """Section 4 of MorphoFeature's ``notebooks/MorphoBricks_end_to_end.ipynb`` (at + 70d4753): the widgets' defaults (the first control, no positive control, novelty with the + default definition, tolerances 0.05 and 0.025, ``default_groups``), then ``report`` and + ``html_report`` into ``/report``.""" + objects, fovs = _tables(CROSSED) + features = tuple(c for c in objects.columns if c.startswith(("area", "speed", "aspect"))) + setup = Setup( + readout="area", + features=features, + control={"condition": "ctrl"}, + positive=None, + novelty=default_novelty(features), + tolerances=(0.05, 0.025), + acquisition_order_col=None, + stage_cols=None, + fov_col=None, + group_cols=_default_groups(fovs), + observation_unit="cell", + n_jobs=1, + ) + report_result = report(objects, fovs, setup) + page = html_report(report_result, objects, fovs, tmp_path / "report") + assert page.exists() + clusters = _feature_specs(page.read_text())["clusters"] + assert sorted({c["biological_repeat"] for c in clusters}) == ["G1", "G2", "G3"]