reader-workbench 1.0.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.
- reader_workbench/__init__.py +22 -0
- reader_workbench/__main__.py +4 -0
- reader_workbench/_version.py +17 -0
- reader_workbench/api/__init__.py +74 -0
- reader_workbench/api/_record_reads.py +75 -0
- reader_workbench/api/artifacts.py +79 -0
- reader_workbench/api/facade.py +538 -0
- reader_workbench/api/models.py +285 -0
- reader_workbench/api/notebooks.py +63 -0
- reader_workbench/contracts/__init__.py +18 -0
- reader_workbench/contracts/builtins/__init__.py +36 -0
- reader_workbench/contracts/builtins/cytometry.py +140 -0
- reader_workbench/contracts/builtins/four_state_event_window.py +214 -0
- reader_workbench/contracts/builtins/generic.py +21 -0
- reader_workbench/contracts/builtins/logic.py +149 -0
- reader_workbench/contracts/builtins/plate_reader.py +47 -0
- reader_workbench/contracts/catalog.py +257 -0
- reader_workbench/contracts/model.py +109 -0
- reader_workbench/domains/__init__.py +1 -0
- reader_workbench/domains/cytometry/__init__.py +3 -0
- reader_workbench/domains/cytometry/analysis/__init__.py +29 -0
- reader_workbench/domains/cytometry/analysis/events.py +182 -0
- reader_workbench/domains/cytometry/analysis/gating.py +175 -0
- reader_workbench/domains/cytometry/analysis/workflow.py +248 -0
- reader_workbench/domains/cytometry/io/__init__.py +3 -0
- reader_workbench/domains/cytometry/io/fcs.py +135 -0
- reader_workbench/domains/cytometry/plots/__init__.py +5 -0
- reader_workbench/domains/cytometry/plots/diagnostic.py +155 -0
- reader_workbench/domains/logic/__init__.py +3 -0
- reader_workbench/domains/logic/crosstalk/__init__.py +3 -0
- reader_workbench/domains/logic/crosstalk/pairs.py +661 -0
- reader_workbench/domains/logic/four_state_vector/__init__.py +7 -0
- reader_workbench/domains/logic/four_state_vector/builder.py +321 -0
- reader_workbench/domains/logic/four_state_vector/collection/__init__.py +20 -0
- reader_workbench/domains/logic/four_state_vector/collection/checks.py +49 -0
- reader_workbench/domains/logic/four_state_vector/collection/constants.py +29 -0
- reader_workbench/domains/logic/four_state_vector/collection/model.py +19 -0
- reader_workbench/domains/logic/four_state_vector/collection/render.py +383 -0
- reader_workbench/domains/logic/four_state_vector/collection/sources.py +185 -0
- reader_workbench/domains/logic/four_state_vector/config.py +214 -0
- reader_workbench/domains/logic/four_state_vector/diagnostic.py +361 -0
- reader_workbench/domains/logic/four_state_vector/heatmap.py +86 -0
- reader_workbench/domains/logic/four_state_vector/math.py +191 -0
- reader_workbench/domains/logic/four_state_vector/reference.py +85 -0
- reader_workbench/domains/logic/four_state_vector/selection.py +228 -0
- reader_workbench/domains/logic/four_state_vector/treatment_semantics.py +51 -0
- reader_workbench/domains/logic/four_state_vector/validation.py +19 -0
- reader_workbench/domains/logic/logic_symmetry/__init__.py +3 -0
- reader_workbench/domains/logic/logic_symmetry/encodings.py +93 -0
- reader_workbench/domains/logic/logic_symmetry/extract_corners.py +192 -0
- reader_workbench/domains/logic/logic_symmetry/main.py +236 -0
- reader_workbench/domains/logic/logic_symmetry/metrics.py +96 -0
- reader_workbench/domains/logic/logic_symmetry/overlay.py +129 -0
- reader_workbench/domains/logic/logic_symmetry/prep.py +138 -0
- reader_workbench/domains/logic/logic_symmetry/render.py +356 -0
- reader_workbench/domains/logic/treatment_columns.py +42 -0
- reader_workbench/domains/plate_reader/__init__.py +1 -0
- reader_workbench/domains/plate_reader/analysis/__init__.py +14 -0
- reader_workbench/domains/plate_reader/analysis/fold_change.py +474 -0
- reader_workbench/domains/plate_reader/analysis/four_state_event_window/__init__.py +21 -0
- reader_workbench/domains/plate_reader/analysis/four_state_event_window/aggregation.py +191 -0
- reader_workbench/domains/plate_reader/analysis/four_state_event_window/contract_fields.py +50 -0
- reader_workbench/domains/plate_reader/analysis/four_state_event_window/contracts.py +320 -0
- reader_workbench/domains/plate_reader/analysis/four_state_event_window/design_dispositions.py +54 -0
- reader_workbench/domains/plate_reader/analysis/four_state_event_window/disposition_records.py +140 -0
- reader_workbench/domains/plate_reader/analysis/four_state_event_window/event_sensitivity.py +27 -0
- reader_workbench/domains/plate_reader/analysis/four_state_event_window/materialize.py +274 -0
- reader_workbench/domains/plate_reader/analysis/four_state_event_window/observation_resampling.py +97 -0
- reader_workbench/domains/plate_reader/analysis/four_state_event_window/reduction.py +62 -0
- reader_workbench/domains/plate_reader/analysis/four_state_event_window/seeds.py +15 -0
- reader_workbench/domains/plate_reader/analysis/four_state_event_window/sources.py +308 -0
- reader_workbench/domains/plate_reader/analysis/four_state_event_window/well_exclusion_validation.py +94 -0
- reader_workbench/domains/plate_reader/analysis/four_state_event_window/well_exclusions.py +54 -0
- reader_workbench/domains/plate_reader/analysis/timepoints.py +76 -0
- reader_workbench/domains/plate_reader/io/__init__.py +6 -0
- reader_workbench/domains/plate_reader/io/sample_map.py +65 -0
- reader_workbench/domains/plate_reader/io/synergy_h1/__init__.py +6 -0
- reader_workbench/domains/plate_reader/io/synergy_h1/_kinetic.py +141 -0
- reader_workbench/domains/plate_reader/io/synergy_h1/_parser.py +295 -0
- reader_workbench/domains/plate_reader/io/synergy_h1/_shared.py +195 -0
- reader_workbench/domains/plate_reader/io/synergy_h1/_snapshot.py +130 -0
- reader_workbench/domains/plate_reader/ordering.py +59 -0
- reader_workbench/domains/plate_reader/plots/__init__.py +15 -0
- reader_workbench/domains/plate_reader/plots/_data.py +29 -0
- reader_workbench/domains/plate_reader/plots/common.py +346 -0
- reader_workbench/domains/plate_reader/plots/distributions.py +324 -0
- reader_workbench/domains/plate_reader/plots/dual_reporter_triptych.py +525 -0
- reader_workbench/domains/plate_reader/plots/dual_reporter_triptych_render.py +195 -0
- reader_workbench/domains/plate_reader/plots/four_state_event_window/__init__.py +26 -0
- reader_workbench/domains/plate_reader/plots/four_state_event_window/diagnostic.py +295 -0
- reader_workbench/domains/plate_reader/plots/four_state_event_window/diagnostic_components.py +149 -0
- reader_workbench/domains/plate_reader/plots/four_state_event_window/diagnostic_render.py +308 -0
- reader_workbench/domains/plate_reader/plots/four_state_event_window/diagnostic_style.py +51 -0
- reader_workbench/domains/plate_reader/plots/four_state_event_window/schema.py +8 -0
- reader_workbench/domains/plate_reader/plots/four_state_event_window/summary.py +140 -0
- reader_workbench/domains/plate_reader/plots/grouping.py +53 -0
- reader_workbench/domains/plate_reader/plots/panels/__init__.py +12 -0
- reader_workbench/domains/plate_reader/plots/panels/snapshot.py +161 -0
- reader_workbench/domains/plate_reader/plots/panels/snapshot_data.py +91 -0
- reader_workbench/domains/plate_reader/plots/panels/time_series.py +296 -0
- reader_workbench/domains/plate_reader/plots/single_reporter_diagnostic.py +435 -0
- reader_workbench/domains/plate_reader/plots/single_reporter_diagnostic_render.py +300 -0
- reader_workbench/domains/plate_reader/plots/snapshot_barplot/__init__.py +315 -0
- reader_workbench/domains/plate_reader/plots/snapshot_barplot/planning.py +168 -0
- reader_workbench/domains/plate_reader/plots/snapshot_heatmap/__init__.py +205 -0
- reader_workbench/domains/plate_reader/plots/snapshot_heatmap/inputs.py +103 -0
- reader_workbench/domains/plate_reader/plots/time_series.py +317 -0
- reader_workbench/domains/plate_reader/plots/ts_and_snap/__init__.py +479 -0
- reader_workbench/domains/plate_reader/plots/ts_and_snap/planning.py +283 -0
- reader_workbench/domains/time_series/__init__.py +29 -0
- reader_workbench/domains/time_series/aggregation.py +60 -0
- reader_workbench/domains/time_series/contracts.py +368 -0
- reader_workbench/domains/time_series/reduction.py +395 -0
- reader_workbench/errors.py +55 -0
- reader_workbench/maintenance/__init__.py +6 -0
- reader_workbench/maintenance/docs.py +335 -0
- reader_workbench/maintenance/model.py +28 -0
- reader_workbench/maintenance/release.py +39 -0
- reader_workbench/maintenance/skills.py +124 -0
- reader_workbench/plotting/__init__.py +20 -0
- reader_workbench/plotting/mpl.py +56 -0
- reader_workbench/plotting/sinks.py +69 -0
- reader_workbench/plotting/style.py +175 -0
- reader_workbench/plotting/utils.py +27 -0
- reader_workbench/plugins/__init__.py +1 -0
- reader_workbench/plugins/catalog.py +33 -0
- reader_workbench/plugins/export/__init__.py +0 -0
- reader_workbench/plugins/export/_paths.py +21 -0
- reader_workbench/plugins/export/csv.py +41 -0
- reader_workbench/plugins/export/xlsx.py +44 -0
- reader_workbench/plugins/ingest/__init__.py +0 -0
- reader_workbench/plugins/ingest/_discovery.py +58 -0
- reader_workbench/plugins/ingest/discovery_policy.py +66 -0
- reader_workbench/plugins/ingest/flow_cytometer.py +139 -0
- reader_workbench/plugins/ingest/synergy_h1.py +234 -0
- reader_workbench/plugins/manifests/__init__.py +1 -0
- reader_workbench/plugins/manifests/export.py +29 -0
- reader_workbench/plugins/manifests/ingest.py +29 -0
- reader_workbench/plugins/manifests/plot.py +161 -0
- reader_workbench/plugins/manifests/transform.py +172 -0
- reader_workbench/plugins/manifests/validator.py +18 -0
- reader_workbench/plugins/plot/__init__.py +0 -0
- reader_workbench/plugins/plot/_shared.py +55 -0
- reader_workbench/plugins/plot/cytometry_diagnostic.py +54 -0
- reader_workbench/plugins/plot/distributions.py +58 -0
- reader_workbench/plugins/plot/dual_reporter_triptych.py +224 -0
- reader_workbench/plugins/plot/four_state_event_window_diagnostic.py +133 -0
- reader_workbench/plugins/plot/four_state_event_window_summary.py +53 -0
- reader_workbench/plugins/plot/four_state_vector_collection.py +45 -0
- reader_workbench/plugins/plot/four_state_vector_diagnostic.py +105 -0
- reader_workbench/plugins/plot/four_state_vector_heatmap.py +63 -0
- reader_workbench/plugins/plot/logic_symmetry.py +56 -0
- reader_workbench/plugins/plot/single_reporter_diagnostic.py +279 -0
- reader_workbench/plugins/plot/snapshot_barplot.py +65 -0
- reader_workbench/plugins/plot/snapshot_heatmap.py +104 -0
- reader_workbench/plugins/plot/time_series.py +114 -0
- reader_workbench/plugins/plot/ts_and_snap.py +210 -0
- reader_workbench/plugins/transform/__init__.py +0 -0
- reader_workbench/plugins/transform/_four_state_vector.py +204 -0
- reader_workbench/plugins/transform/_labeling.py +109 -0
- reader_workbench/plugins/transform/alias.py +70 -0
- reader_workbench/plugins/transform/assay_labels.py +62 -0
- reader_workbench/plugins/transform/blank.py +79 -0
- reader_workbench/plugins/transform/crosstalk_pairs.py +180 -0
- reader_workbench/plugins/transform/cytometry_gating.py +120 -0
- reader_workbench/plugins/transform/fold_change.py +79 -0
- reader_workbench/plugins/transform/four_state_event_window.py +93 -0
- reader_workbench/plugins/transform/four_state_vector.py +62 -0
- reader_workbench/plugins/transform/four_state_vector_collection.py +41 -0
- reader_workbench/plugins/transform/logic_symmetry.py +67 -0
- reader_workbench/plugins/transform/outlier_filter.py +60 -0
- reader_workbench/plugins/transform/overflow.py +197 -0
- reader_workbench/plugins/transform/ratio.py +237 -0
- reader_workbench/plugins/transform/sample_map.py +170 -0
- reader_workbench/plugins/transform/sample_metadata.py +94 -0
- reader_workbench/plugins/validator/__init__.py +1 -0
- reader_workbench/plugins/validator/to_tidy_plus_map.py +155 -0
- reader_workbench/protocols/__init__.py +80 -0
- reader_workbench/protocols/_builtins_plate_reader_growth.py +179 -0
- reader_workbench/protocols/_builtins_plate_reader_variants.py +274 -0
- reader_workbench/protocols/builtins.py +1656 -0
- reader_workbench/protocols/compiler.py +22 -0
- reader_workbench/protocols/compilers/__init__.py +1 -0
- reader_workbench/protocols/compilers/common.py +100 -0
- reader_workbench/protocols/compilers/cytometry.py +87 -0
- reader_workbench/protocols/compilers/generic.py +14 -0
- reader_workbench/protocols/compilers/logic.py +245 -0
- reader_workbench/protocols/compilers/plate_reader.py +937 -0
- reader_workbench/protocols/compilers/plate_reader_pipeline.py +197 -0
- reader_workbench/protocols/model.py +1486 -0
- reader_workbench/protocols/semantic_coverage.py +234 -0
- reader_workbench/runtime/__init__.py +12 -0
- reader_workbench/runtime/builtin.py +23 -0
- reader_workbench/runtime/model.py +42 -0
- reader_workbench/workbench/__init__.py +60 -0
- reader_workbench/workbench/assets/__init__.py +22 -0
- reader_workbench/workbench/assets/types.py +118 -0
- reader_workbench/workbench/audit/__init__.py +5 -0
- reader_workbench/workbench/audit/experiments.py +307 -0
- reader_workbench/workbench/audit/staging.py +187 -0
- reader_workbench/workbench/cli/__init__.py +51 -0
- reader_workbench/workbench/cli/_lazy.py +9 -0
- reader_workbench/workbench/cli/_records_view.py +150 -0
- reader_workbench/workbench/cli/_surface_execution.py +443 -0
- reader_workbench/workbench/cli/audit.py +95 -0
- reader_workbench/workbench/cli/automation.py +229 -0
- reader_workbench/workbench/cli/demo.py +46 -0
- reader_workbench/workbench/cli/dop.py +91 -0
- reader_workbench/workbench/cli/experiments.py +635 -0
- reader_workbench/workbench/cli/helpers.py +232 -0
- reader_workbench/workbench/cli/main.py +59 -0
- reader_workbench/workbench/cli/maintenance.py +82 -0
- reader_workbench/workbench/cli/notebooks.py +260 -0
- reader_workbench/workbench/cli/pagination.py +117 -0
- reader_workbench/workbench/cli/protocols.py +336 -0
- reader_workbench/workbench/cli/shared.py +309 -0
- reader_workbench/workbench/cli/surfaces.py +534 -0
- reader_workbench/workbench/cli/verification.py +128 -0
- reader_workbench/workbench/commands.py +10 -0
- reader_workbench/workbench/config/__init__.py +47 -0
- reader_workbench/workbench/config/identity.py +13 -0
- reader_workbench/workbench/config/load.py +405 -0
- reader_workbench/workbench/config/model.py +274 -0
- reader_workbench/workbench/context.py +26 -0
- reader_workbench/workbench/decl/__init__.py +31 -0
- reader_workbench/workbench/decl/build.py +190 -0
- reader_workbench/workbench/decl/model.py +81 -0
- reader_workbench/workbench/dop/__init__.py +12 -0
- reader_workbench/workbench/dop/builtins.py +261 -0
- reader_workbench/workbench/dop/model.py +209 -0
- reader_workbench/workbench/engine/__init__.py +42 -0
- reader_workbench/workbench/engine/_shared.py +76 -0
- reader_workbench/workbench/engine/contracts.py +283 -0
- reader_workbench/workbench/engine/execution.py +326 -0
- reader_workbench/workbench/engine/file_outputs.py +260 -0
- reader_workbench/workbench/engine/inputs.py +161 -0
- reader_workbench/workbench/engine/invocations.py +507 -0
- reader_workbench/workbench/engine/planning.py +72 -0
- reader_workbench/workbench/engine/runtime.py +464 -0
- reader_workbench/workbench/engine/setup.py +149 -0
- reader_workbench/workbench/engine/validation.py +684 -0
- reader_workbench/workbench/experiment/__init__.py +47 -0
- reader_workbench/workbench/experiment/model.py +381 -0
- reader_workbench/workbench/experiments.py +133 -0
- reader_workbench/workbench/graph/__init__.py +47 -0
- reader_workbench/workbench/graph/nodes.py +102 -0
- reader_workbench/workbench/graph/normalize.py +177 -0
- reader_workbench/workbench/graph/refs.py +148 -0
- reader_workbench/workbench/input_discovery.py +19 -0
- reader_workbench/workbench/inspection/__init__.py +3 -0
- reader_workbench/workbench/inspection/catalogs.py +128 -0
- reader_workbench/workbench/inspection/common.py +92 -0
- reader_workbench/workbench/inspection/dop.py +64 -0
- reader_workbench/workbench/inspection/experiments.py +449 -0
- reader_workbench/workbench/inspection/inventory.py +68 -0
- reader_workbench/workbench/inspection/protocols.py +368 -0
- reader_workbench/workbench/inspection/readiness.py +333 -0
- reader_workbench/workbench/inspection/reports.py +367 -0
- reader_workbench/workbench/inspection/results.py +166 -0
- reader_workbench/workbench/inspection/runtime.py +287 -0
- reader_workbench/workbench/inspection/semantics.py +192 -0
- reader_workbench/workbench/inspection/validation.py +30 -0
- reader_workbench/workbench/notebooks/__init__.py +17 -0
- reader_workbench/workbench/notebooks/_launch_registry.py +112 -0
- reader_workbench/workbench/notebooks/_launch_runtime.py +104 -0
- reader_workbench/workbench/notebooks/components/__init__.py +21 -0
- reader_workbench/workbench/notebooks/components/deliverables.py +403 -0
- reader_workbench/workbench/notebooks/components/overview.py +119 -0
- reader_workbench/workbench/notebooks/eda.marimo.py.txt +153 -0
- reader_workbench/workbench/notebooks/launch.py +274 -0
- reader_workbench/workbench/notebooks/presentation.py +136 -0
- reader_workbench/workbench/notebooks/scaffold.py +60 -0
- reader_workbench/workbench/ontology.py +78 -0
- reader_workbench/workbench/paths.py +44 -0
- reader_workbench/workbench/ports/__init__.py +31 -0
- reader_workbench/workbench/ports/model.py +168 -0
- reader_workbench/workbench/records/__init__.py +44 -0
- reader_workbench/workbench/records/epoch.py +329 -0
- reader_workbench/workbench/records/evidence.py +247 -0
- reader_workbench/workbench/records/identity.py +87 -0
- reader_workbench/workbench/records/locking.py +185 -0
- reader_workbench/workbench/records/model.py +711 -0
- reader_workbench/workbench/records/sources.py +73 -0
- reader_workbench/workbench/records/store.py +1022 -0
- reader_workbench/workbench/records/verification.py +998 -0
- reader_workbench/workbench/registry.py +333 -0
- reader_workbench/workbench/spec_overrides.py +215 -0
- reader_workbench-1.0.0.dist-info/METADATA +91 -0
- reader_workbench-1.0.0.dist-info/RECORD +293 -0
- reader_workbench-1.0.0.dist-info/WHEEL +5 -0
- reader_workbench-1.0.0.dist-info/entry_points.txt +2 -0
- reader_workbench-1.0.0.dist-info/licenses/LICENSE +21 -0
- reader_workbench-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"""Static diagnostic figure for one resolved cytometry gating workflow."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
import pandas as pd
|
|
7
|
+
import polars as pl
|
|
8
|
+
|
|
9
|
+
from reader_workbench.domains.cytometry.analysis import CytometryAnalysisError, prepare_event_table
|
|
10
|
+
from reader_workbench.plotting.style import use_style
|
|
11
|
+
|
|
12
|
+
_DEFINITION_COLUMNS = (
|
|
13
|
+
"cells_enabled",
|
|
14
|
+
"cells_x_channel",
|
|
15
|
+
"cells_x_min",
|
|
16
|
+
"cells_x_max",
|
|
17
|
+
"cells_y_channel",
|
|
18
|
+
"cells_y_min",
|
|
19
|
+
"cells_y_max",
|
|
20
|
+
"singlets_enabled",
|
|
21
|
+
"singlet_x_channel",
|
|
22
|
+
"singlet_y_channel",
|
|
23
|
+
"singlet_ratio_min",
|
|
24
|
+
"singlet_ratio_max",
|
|
25
|
+
"fluorescence_channel",
|
|
26
|
+
"threshold_value",
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def render_cytometry_diagnostic(
|
|
31
|
+
original_events: pd.DataFrame,
|
|
32
|
+
gate_definition: pd.DataFrame,
|
|
33
|
+
gated_events: pd.DataFrame,
|
|
34
|
+
*,
|
|
35
|
+
max_events: int,
|
|
36
|
+
title: str | None = None,
|
|
37
|
+
):
|
|
38
|
+
"""Render configured cells, singlets, fluorescence, and retention panels."""
|
|
39
|
+
|
|
40
|
+
if max_events <= 0:
|
|
41
|
+
raise CytometryAnalysisError("max_events must be positive.")
|
|
42
|
+
if len(gate_definition) != 1:
|
|
43
|
+
raise CytometryAnalysisError("Cytometry diagnostic requires exactly one resolved gate definition row.")
|
|
44
|
+
missing = [column for column in _DEFINITION_COLUMNS if column not in gate_definition.columns]
|
|
45
|
+
if missing:
|
|
46
|
+
raise CytometryAnalysisError("Cytometry gate definition is missing column(s): " + ", ".join(missing) + ".")
|
|
47
|
+
definition = gate_definition.iloc[0]
|
|
48
|
+
channel_columns = ["fluorescence_channel"]
|
|
49
|
+
if bool(definition["cells_enabled"]):
|
|
50
|
+
channel_columns.extend(("cells_x_channel", "cells_y_channel"))
|
|
51
|
+
if bool(definition["singlets_enabled"]):
|
|
52
|
+
channel_columns.extend(("singlet_x_channel", "singlet_y_channel"))
|
|
53
|
+
channels = tuple(dict.fromkeys(str(definition[column]) for column in channel_columns))
|
|
54
|
+
original_wide = prepare_event_table(pl.from_pandas(original_events), channels=channels).to_pandas()
|
|
55
|
+
_require_wide_columns(gated_events, ("sample_id", "event_index", *channels))
|
|
56
|
+
original_plot = _bounded_events(original_wide, max_events=max_events)
|
|
57
|
+
gated_plot = _bounded_events(gated_events, max_events=max_events)
|
|
58
|
+
|
|
59
|
+
try:
|
|
60
|
+
import matplotlib.pyplot as plt # noqa: PLC0415
|
|
61
|
+
from matplotlib.patches import Rectangle # noqa: PLC0415
|
|
62
|
+
except Exception as exc: # pragma: no cover - dependency guard
|
|
63
|
+
raise CytometryAnalysisError("Cytometry diagnostic plotting requires matplotlib.") from exc
|
|
64
|
+
|
|
65
|
+
with use_style({"figure_figsize": (11.0, 8.0), "axes_grid": False}):
|
|
66
|
+
figure, axes = plt.subplots(2, 2, figsize=(11.0, 8.0), constrained_layout=True)
|
|
67
|
+
cells_ax, singlets_ax, fluorescence_ax, retention_ax = axes.flat
|
|
68
|
+
if bool(definition["cells_enabled"]):
|
|
69
|
+
_scatter_gate(
|
|
70
|
+
cells_ax,
|
|
71
|
+
original_plot,
|
|
72
|
+
gated_plot,
|
|
73
|
+
x_channel=str(definition["cells_x_channel"]),
|
|
74
|
+
y_channel=str(definition["cells_y_channel"]),
|
|
75
|
+
)
|
|
76
|
+
cells_ax.add_patch(
|
|
77
|
+
Rectangle(
|
|
78
|
+
(float(definition["cells_x_min"]), float(definition["cells_y_min"])),
|
|
79
|
+
float(definition["cells_x_max"] - definition["cells_x_min"]),
|
|
80
|
+
float(definition["cells_y_max"] - definition["cells_y_min"]),
|
|
81
|
+
fill=False,
|
|
82
|
+
color="#c96845",
|
|
83
|
+
linewidth=1.6,
|
|
84
|
+
)
|
|
85
|
+
)
|
|
86
|
+
else:
|
|
87
|
+
_mark_gate_disabled(cells_ax)
|
|
88
|
+
cells_ax.set_title("Cells gate")
|
|
89
|
+
|
|
90
|
+
if bool(definition["singlets_enabled"]):
|
|
91
|
+
singlet_x = str(definition["singlet_x_channel"])
|
|
92
|
+
singlet_y = str(definition["singlet_y_channel"])
|
|
93
|
+
_scatter_gate(singlets_ax, original_plot, gated_plot, x_channel=singlet_x, y_channel=singlet_y)
|
|
94
|
+
finite_x = pd.to_numeric(original_plot[singlet_x], errors="coerce")
|
|
95
|
+
finite_x = finite_x[np.isfinite(finite_x)]
|
|
96
|
+
if not finite_x.empty:
|
|
97
|
+
line_x = np.array([float(finite_x.min()), float(finite_x.max())])
|
|
98
|
+
for ratio in (float(definition["singlet_ratio_min"]), float(definition["singlet_ratio_max"])):
|
|
99
|
+
singlets_ax.plot(line_x, ratio * line_x, color="#c96845", linewidth=1.4)
|
|
100
|
+
else:
|
|
101
|
+
_mark_gate_disabled(singlets_ax)
|
|
102
|
+
singlets_ax.set_title("Singlets gate")
|
|
103
|
+
|
|
104
|
+
fluor = str(definition["fluorescence_channel"])
|
|
105
|
+
original_fluor = _finite_values(original_plot[fluor])
|
|
106
|
+
gated_fluor = _finite_values(gated_plot[fluor])
|
|
107
|
+
fluorescence_ax.hist(original_fluor, bins=40, color="#b8b8b8", alpha=0.65, label="all")
|
|
108
|
+
fluorescence_ax.hist(gated_fluor, bins=40, color="#315f7d", alpha=0.70, label="gated")
|
|
109
|
+
fluorescence_ax.axvline(float(definition["threshold_value"]), color="#c96845", linewidth=1.6)
|
|
110
|
+
fluorescence_ax.set_xlabel(fluor)
|
|
111
|
+
fluorescence_ax.set_ylabel("Events")
|
|
112
|
+
fluorescence_ax.set_title("Fluorescence")
|
|
113
|
+
fluorescence_ax.legend(frameon=False)
|
|
114
|
+
|
|
115
|
+
original_counts = original_wide.groupby("sample_id", sort=True).size()
|
|
116
|
+
gated_counts = gated_events.groupby("sample_id", sort=True).size().reindex(original_counts.index, fill_value=0)
|
|
117
|
+
positions = np.arange(len(original_counts))
|
|
118
|
+
retention_ax.bar(positions - 0.18, original_counts.values, width=0.36, color="#b8b8b8", label="all")
|
|
119
|
+
retention_ax.bar(positions + 0.18, gated_counts.values, width=0.36, color="#315f7d", label="gated")
|
|
120
|
+
retention_ax.set_xticks(positions, original_counts.index.astype(str), rotation=30, ha="right")
|
|
121
|
+
retention_ax.set_ylabel("Events")
|
|
122
|
+
retention_ax.set_title("Final retention")
|
|
123
|
+
retention_ax.legend(frameon=False)
|
|
124
|
+
figure.suptitle(title or "Cytometry gating diagnostic")
|
|
125
|
+
return figure
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def _scatter_gate(ax, original: pd.DataFrame, gated: pd.DataFrame, *, x_channel: str, y_channel: str) -> None:
|
|
129
|
+
ax.scatter(original[x_channel], original[y_channel], s=9, alpha=0.18, color="#767676", rasterized=True)
|
|
130
|
+
ax.scatter(gated[x_channel], gated[y_channel], s=10, alpha=0.45, color="#315f7d", rasterized=True)
|
|
131
|
+
ax.set_xlabel(x_channel)
|
|
132
|
+
ax.set_ylabel(y_channel)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _mark_gate_disabled(ax) -> None:
|
|
136
|
+
ax.text(0.5, 0.5, "Disabled", ha="center", va="center", transform=ax.transAxes)
|
|
137
|
+
ax.set_xticks([])
|
|
138
|
+
ax.set_yticks([])
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def _bounded_events(frame: pd.DataFrame, *, max_events: int) -> pd.DataFrame:
|
|
142
|
+
if len(frame) <= max_events:
|
|
143
|
+
return frame.copy()
|
|
144
|
+
return frame.sample(n=max_events, random_state=0).sort_values(["sample_id", "event_index"])
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def _finite_values(series: pd.Series) -> np.ndarray:
|
|
148
|
+
values = pd.to_numeric(series, errors="coerce").to_numpy(dtype=float)
|
|
149
|
+
return values[np.isfinite(values)]
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def _require_wide_columns(frame: pd.DataFrame, columns: tuple[str, ...]) -> None:
|
|
153
|
+
missing = [column for column in columns if column not in frame.columns]
|
|
154
|
+
if missing:
|
|
155
|
+
raise CytometryAnalysisError("Cytometry diagnostic data is missing column(s): " + ", ".join(missing) + ".")
|