clophfit.prtecan.titration#

Prtecan/prtecan.py.

Classes#

TitrationConfig

Parameters defining the fitting data with callback support.

BufferFit

Store (robust) linear fit result.

Buffer

Buffer handling for a titration.

TitrationResults

Manage titration results with optional lazy computation.

Titration

Build titrations from grouped Tecanfiles and concentrations or pH values.

TecanConfig

Group tecan cli options.

Module Contents#

class clophfit.prtecan.titration.TitrationConfig#

Parameters defining the fitting data with callback support.

noise_alpha: tuple[float, Ellipsis] = ()#

Proportional noise coefficients per label (y1, y2, …).

When provided, adds an alpha^2*signal^2 term to the y_err^2 estimate so that high-signal wells are appropriately down-weighted:

y_err^2 = gain*signal + bg_err^2 + (alpha*signal)^2

Values from MCMC multi-noise shared_noise_params.csv (alpha_y1, alpha_y2). Empty tuple disables the correction (legacy behaviour).

noise_gain: tuple[float, Ellipsis] = ()#

Poisson gain coefficients per label (y1, y2, …).

Replaces the hardcoded gain=1 in the shot-noise Poisson term:

y_err^2 = gain*signal + bg_err^2 + (alpha*signal)^2

Values from MCMC multi-noise shared_noise_params.csv (gain_y1, gain_y2). Empty tuple keeps gain=1 (legacy behaviour).

mask_outliers: bool = False#

Mask geometric outliers in each well’s curve before fitting. Default is False.

outlier_threshold: float = 0.2#

Threshold for geometric outlier scoring (0-1). Default is 0.2.

discard_bad_wells: bool = False#

Automatically detect and discard bad wells before fitting. Default is False.

set_callback(callback)#

Set the callback to be triggered on parameter change.

Parameters:

callback (collections.abc.Callable[[], None])

Return type:

None

class clophfit.prtecan.titration.BufferFit#

Store (robust) linear fit result.

property empty: bool#

Return True if all attributes are NaN, emulating DataFrame’s empty behavior.

Return type:

bool

class clophfit.prtecan.titration.Buffer#

Buffer handling for a titration.

Manages background correction and fitting for buffer wells.

property dataframes: dict[int, pandas.DataFrame]#

Buffer dataframes with fit.

Return type:

dict[int, pandas.DataFrame]

property dataframes_nrm: dict[int, pandas.DataFrame]#

Buffer normalized dataframes with fit.

Return type:

dict[int, pandas.DataFrame]

property wells: list[str]#

List of buffer wells.

Return type:

list[str]

property bg: dict[int, clophfit.clophfit_types.ArrayF]#

List of buffer values.

Return type:

dict[int, clophfit.clophfit_types.ArrayF]

property bg_err: dict[int, clophfit.clophfit_types.ArrayF]#

List of buffer SEM values.

Return type:

dict[int, clophfit.clophfit_types.ArrayF]

property bg_noise: dict[int, float]#

Intrinsic well noise (RMSE/pooled SD) values.

Return type:

dict[int, float]

plot(*, nrm=False, title=None)#

Plot buffers of all labelblocksgroups.

Parameters:
  • nrm (bool)

  • title (str | None)

Return type:

seaborn.FacetGrid

class clophfit.prtecan.titration.TitrationResults#

Manage titration results with optional lazy computation.

property dataframe: pandas.DataFrame#

Convert FitResult dictionary to a DataFrame.

Return type:

pandas.DataFrame

compute_all()#

Compute results for all keys.

Return type:

None

n_sd(par='K', expected_sd=0.15)#

Compute median of K.

Parameters:
  • par (str)

  • expected_sd (float)

Return type:

float

static all_computed()#

Check if all keys have been computed.

Return type:

bool

export_pngs(folder)#

Export all fit result plots as PNG files.

Parameters:

folder (str | pathlib.Path)

Return type:

None

export_data(folder)#

Export all datasets as CSV files.

Parameters:

folder (str | pathlib.Path)

Return type:

None

plot_k(xlim=None, title='')#

Plot K values as stripplot.

Parameters:
  • xlim (tuple[float, float] | None, optional) – Range.

  • title (str, optional) – To name the plot.

Returns:

The figure.

Return type:

figure.Figure

class clophfit.prtecan.titration.Titration#

Bases: clophfit.prtecan.models.TecanfilesGroup

Build titrations from grouped Tecanfiles and concentrations or pH values.

Parameters:
  • tecanfiles (list[Tecanfile]) – List of Tecanfiles.

  • x (ArrayF) – Concentration or pH values.

  • is_ph

  • x_err

Raises:

ValueError – For unexpected file format, e.g. header names.

is_ph: bool = False#

Indicate if x values represent pH.

x_err: clophfit.clophfit_types.ArrayF#

Uncertainties for x values (default is empty array).

buffer: Buffer#

Buffer wells data and fit results. Set during initialization.

property fit_keys: set[str]#

Set of wells to be fitted.

Return type:

set[str]

detect_and_discard_bad_wells(smoothness_threshold=None, roughness_threshold=None, z_threshold=None, *, outlier_threshold=0.2, bg_multiplier=3.0)#

Detect and discard bad wells from masked per-label signal quality.

By default, each well is converted to a per-label dataset with _create_ds(), masked with apply_outlier_mask(), and then discarded when the mean masked signal of any label falls below a background-derived floor. The floor uses bg_err when available and falls back to bg_noise.

Legacy smoothness, roughness, and trendline criteria are still available as optional extra filters when their thresholds are provided explicitly.

Parameters:
  • smoothness_threshold (float | None) – Optional maximum allowed smoothness value.

  • roughness_threshold (float | None) – Optional maximum allowed roughness value.

  • z_threshold (float | None) – Optional trendline outlier threshold on max signal vs span.

  • outlier_threshold (float | None) – Threshold passed to apply_outlier_mask() before computing per-label summary statistics. If None, no masking is applied.

  • bg_multiplier (float | None) – Discard a well when any masked per-label mean signal is below bg_multiplier * mean(background_floor). If None, this check is disabled.

Returns:

Newly discarded well keys.

Return type:

list[str]

clear_all_data_results()#

Clear fit keys, data, results and bg when buffer or scheme properties change.

Return type:

None

property params: TitrationConfig#

Get the datafit parameters.

Return type:

TitrationConfig

property bg: dict[int, clophfit.clophfit_types.ArrayF]#

List of buffer values.

Return type:

dict[int, clophfit.clophfit_types.ArrayF]

property bg_err: dict[int, clophfit.clophfit_types.ArrayF]#

List of buffer SEM values.

Return type:

dict[int, clophfit.clophfit_types.ArrayF]

property bg_noise: dict[int, float]#

Intrinsic well noise (RMSE/pooled SD) values.

Return type:

dict[int, float]

classmethod fromlistfile(list_file, *, is_ph)#

Build Titration from a list[.pH|.Cl] file.

Parameters:
  • list_file (Path | str) – Path to the list file containing [filenames x x_err].

  • is_ph (bool) – Whether x values represent pH (True) or concentrations (False).

Returns:

The constructed Titration object.

Return type:

Titration

property additions: list[float] | None#

List of initial volume followed by additions.

Return type:

list[float] | None

load_additions(additions_file)#

Load additions from file.

Reads a CSV file with a single column ‘add’ containing addition volumes, and updates the Titration’s additions property.

Parameters:

additions_file (Path) – Path to the additions CSV file.

Return type:

None

property data: dict[int, dict[str, clophfit.clophfit_types.ArrayF]]#

Buffer subtracted and corrected for dilution data.

Return type:

dict[int, dict[str, clophfit.clophfit_types.ArrayF]]

property scheme: clophfit.prtecan.models.PlateScheme#

Scheme for known samples like {‘buffer’, [‘H12’, ‘H01’], ‘ctrl’…}.

Return type:

clophfit.prtecan.models.PlateScheme

load_scheme(schemefile)#

Load scheme from file and set buffer wells.

Reads a scheme file to define buffer wells, known samples, and control wells, then updates the Titration’s scheme and buffer wells.

Parameters:

schemefile (Path) – Path to the scheme CSV file.

Return type:

None

create_ds(key, label)#

Create a dataset for the given key.

Parameters:
  • key (str)

  • label (int)

Return type:

clophfit.fitting.data_structures.Dataset

create_global_ds(key)#

Create a global dataset for the given key.

Parameters:

key (str)

Return type:

clophfit.fitting.data_structures.Dataset

plot_temperature(title='')#

Plot temperatures of all labelblocksgroups.

Creates a line plot showing measured temperatures versus concentration/pH values, with statistics overlays.

Parameters:

title (str, optional) – Additional title text to append to the plot.

Returns:

The matplotlib Figure object containing the plot.

Return type:

figure.Figure

class clophfit.prtecan.titration.TecanConfig#

Group tecan cli options.

detect_bad: bool = True#

Run bad-well detection before fitting (pre-fit) and after (post-fit).