spacr.settings_advisor¶
Inspect screen tables and propose regression settings.
The advisor separates measured choices, settings that remain undecided, and questions the data cannot answer. Each proposed value includes its reason, and this module never writes settings itself.
Count-table summaries use every available well. Object-level score tables
may be large, so response diagnostics use a capped sample and mark the
resulting Reading accordingly. Family, control, and fraction choices
reuse the same analysis helpers as the regression pipeline.
Classes¶
What the data decided, what it would not, and what it was read from. |
|
One setting the data decided, and what decided it. |
|
Something the data cannot answer. |
|
What was measured, before any advice is derived from it. |
|
A setting this module will not guess, and why not. |
Functions¶
|
Build a regression-setting proposal from measurements and answers. |
|
Build advice and withdraw choices that fail runtime preflight. |
|
Read screen inputs and return a regression-settings recommendation. |
|
Return questions that cannot be answered from this screen's data. |
|
Measure plates, wells, guides, genes, and replication from count data. |
|
Read a finished run's own diagnostics off disk. |
|
Measure response range, shape, and per-well support. |
|
Measure both halves of the input and return one |
|
Return reasons a regression settings mapping cannot be run. |
|
Return settings required by an analysis unit. |
Module Contents¶
- class spacr.settings_advisor.Advice[source]¶
What the data decided, what it would not, and what it was read from.
- Parameters:
chosen – ordered setting proposals carrying their keys, values, and evidence;
as_settings()converts them to a mapping.undecided – unresolved or withdrawn proposals with explanations returned by
why()and displayed to the user.reading – optional measured screen and completed-run evidence from which the proposals were derived.
- class spacr.settings_advisor.Choice[source]¶
One setting the data decided, and what decided it.
- Parameters:
key – the setting name, exactly as the panel spells it.
value – what to put in it.
why – the reason, naming the measurement. Not “recommended” – a reason a user cannot check against their own data is a slogan.
- class spacr.settings_advisor.Question[source]¶
Something the data cannot answer.
- Parameters:
key – an identifier for the answer, not a setting name – one answer can move several settings.
prompt – the question shown to the user.
kind –
'number'or'choice'.options – for
'choice',((value, label), ...).default – the starting value, which is a position and is defended in
why_it_mattersrather than left as an unexplained number.why_it_matters – what changes in the settings depending on the answer. Shown beside the question, because a user who cannot see what a question buys cannot answer it well.
- class spacr.settings_advisor.Reading[source]¶
What was measured, before any advice is derived from it.
Separate from
Adviceon purpose: the reading is checkable against the user’s own data, and the advice is an argument FROM it. A reader who disagrees with a choice can see which number produced it.
- class spacr.settings_advisor.Undecided[source]¶
A setting this module will not guess, and why not.
- Parameters:
key – setting name or advisory topic left unresolved;
Advice.why()uses it to retrieve this record’s explanation.why – evidence-based explanation of why no value was proposed or why a refused proposal was withdrawn.
- spacr.settings_advisor.advise(reading: Reading, answers: Dict[str, Any] | None = None) Advice[source]¶
Build a regression-setting proposal from measurements and answers.
This function has no settings side effects. The caller decides whether and how to display or apply the returned
Advice.- Parameters:
reading – measured screen properties from which settings are derived.
- spacr.settings_advisor.advise_that_runs(reading: Reading, answers: Dict[str, Any] | None = None) Advice[source]¶
Build advice and withdraw choices that fail runtime preflight.
A choice named by
refusals()moves fromchosentoundecidedwith the validation message. The function does not silently substitute a different value.
- spacr.settings_advisor.advise_the_screen(counts: Sequence[str] = (), scores: Sequence[str] = (), dependent_variable: str = '', answers: Dict[str, Any] | None = None, *, row_cap: int = ROW_CAP, run_folder: str = '', settings: Mapping[str, Any] | None = None) Advice[source]¶
Read screen inputs and return a regression-settings recommendation.
- Parameters:
run_folder – optional completed run whose recorded diagnostics can refine the input-based recommendation. An empty value requires no prior fit.
settings – current panel settings used to reject diagnostics from a run fitted with an incompatible model family.
- Returns:
recommended and unresolved settings with the evidence used to derive them.
- spacr.settings_advisor.questions_for(reading: Reading) Tuple[Question, ...][source]¶
Return questions that cannot be answered from this screen’s data.
The direction question is omitted for a binary response, where only an increase can represent the positive outcome.
- Parameters:
reading – measured screen properties used to omit answered questions.
- spacr.settings_advisor.read_the_counts(paths: Sequence[str]) Dict[str, Any][source]¶
Measure plates, wells, guides, genes, and replication from count data.
All count rows are used. Per-well fractions are calculated with
spacr.cell_montage.fractions_from_counts(), matching the values used by the regression pipeline.- Parameters:
paths – count-table paths to read together as one screen design.
- spacr.settings_advisor.read_the_last_run(folder: str, settings: Mapping[str, Any] | None = None) Dict[str, Any][source]¶
Read a finished run’s own diagnostics off disk.
A READ OF WHAT ALREADY EXISTS, never a second diagnostic pass. The numbers are the ones
regression_qcmeasured and printed onto its own report; recomputing them here would let the advisor and the QC panel disagree about the same fit, and the user would have no way to tell which was right.- Parameters:
folder – the run folder, or the
regression_qcfolder inside it.settings – the settings now in the panel, so a run fitted under different ones is reported as STALE rather than used silently.
- Returns:
the fields to merge into a
Reading. Always includesrun_folderwhen a run was found, andrun_notewhen one was found and is not being used.
- spacr.settings_advisor.read_the_response(paths: Sequence[str], dependent_variable: str = '', *, row_cap: int = ROW_CAP) Dict[str, Any][source]¶
Measure response range, shape, and per-well support.
At most
row_capobject rows are read across the supplied score tables. The returned mapping records whether that cap was reached so callers can qualify sample-derived recommendations.- Parameters:
- Returns:
dict – Measured response properties and any non-fatal problems in
"trouble".
- spacr.settings_advisor.read_the_screen(counts: Sequence[str] = (), scores: Sequence[str] = (), dependent_variable: str = '', *, row_cap: int = ROW_CAP) Reading[source]¶
Measure both halves of the input and return one
Reading.
- spacr.settings_advisor.refusals(settings: Mapping[str, Any]) Tuple[str, ...][source]¶
Return reasons a regression settings mapping cannot be run.
This check covers incompatible setting combinations that default filling and type coercion cannot resolve. Messages follow the runtime validation wording so an application can explain a refusal before starting a fit.
- Parameters:
settings (mapping) – Proposed regression settings.
- Returns:
tuple of str – One actionable message per refusal, or an empty tuple when the settings pass these preflight checks.
- spacr.settings_advisor.requirements_for_unit(unit: str) Dict[str, Any][source]¶
Return settings required by an analysis unit.
- Parameters:
unit –
'cell'or'well'.- Returns:
{setting: required value}, empty when the unit constrains nothing.
User interfaces can apply these values immediately and disable the corresponding controls, preventing incompatible combinations from reaching runtime validation.
Nested helpers¶
- _from_the_run.replace(key: str, value: str, why: str) None¶
Replace or append one recommendation in the captured choices.
- Parameters:
key – setting-choice key to update.
value – value recommended from the completed run.
why – user-facing evidence for the recommendation.
- Returns:
None. The first same-key choice is replaced at its existing position; a key not already present is appended once.
spacr/settings_advisor.py:1015