clophfit.prtecan#

Parse Tecan files and fit files that are grouped into titrations.

A ‘titration’ in this context is defined within a list.pH or list.cl file. These files describe the properties and parameters of the titration experiment.

The command-line interface ‘prtecan’ is used to construct 96 distinct titrations and export the results to .txt files. This allows for further analysis or visualization of the titration data.

In cases where two label blocks exist in the Tecan files, the module performs a ‘global fitting’ operation. Global fitting is a method used in data analysis to best fit a model to multiple data sets simultaneously, under the assumption that some underlying parameters are shared between the data sets.

Please consult the documentation for each function in this module for more detailed information on their operation and use.

Classes:

Labelblock(_lines[, filename])

Parse a label block.

LabelblocksGroup(labelblocks[, allequal])

Group labelblocks with compatible metadata.

Metadata(value[, unit])

Represents the value of a metadata dictionary.

PlateScheme([file])

Define buffer, discard, ctrl and unk wells, and ctrl names.

TecanConfig(out_fp, comb, lim, title, fit, png)

Group tecan cli options.

Tecanfile(path)

Parse a Tecan .xls file.

TecanfilesGroup(tecanfiles)

Group of Tecanfiles containing at least one common Labelblock.

Titration(tecanfiles, x, is_ph[, x_err])

Build titrations from grouped Tecanfiles and concentrations or pH values.

TitrationConfig([bg, bg_adj, dil, nrm, ...])

Parameters defining the fitting data with callback support.

TitrationResults(scheme, fit_keys, compute_func)

Manage titration results with optional lazy computation.

Functions:

calculate_conc(additions, conc_stock[, conc_ini])

Calculate concentration values.

dilution_correction(additions)

Apply dilution correction.

extract_metadata(lines)

Extract metadata into both Tecanfile and Labelblock.

lookup_listoflines(csvl[, pattern, col])

Lookup line numbers (row index) where given pattern occurs.

merge_md(mds)

Merge a list of metadata dict if the key value is the same in the list.

read_xls(path)

Read first sheet of an xls file.

strip_lines(lines)

Remove empty fields/cells from lines read from a csv file.

class clophfit.prtecan.Labelblock(_lines, filename='')#

Parse a label block.

Parameters:
  • _lines (list[list[str | int | float]]) – Lines to create this Labelblock.

  • filename (str)

Raises:
  • Exception – When data do not correspond to a complete 96-well plate.

  • ValueError – When something went wrong. Possibly because not 96-well.

  • TypeError – When normalization parameters are not numerical.

  • Logging

  • -------

  • Logs a warning – When it replaces “OVER” with np.nan for saturated values.

Attributes:

filename

Path of the corresponding Tecan file.

metadata

Metadata specific for this Labelblock.

data

Plate data values as {'well_name', value}.

data_nrm

Plate data values normalized as {'well_name', value}.

Methods:

__almost_eq__(other)

Check if two Labelblocks are almost equal (same excitation and emission).

filename: str = ''#

Path of the corresponding Tecan file.

metadata: dict[str, Metadata]#

Metadata specific for this Labelblock.

data: dict[str, float]#

Plate data values as {‘well_name’, value}.

data_nrm: dict[str, float]#

Plate data values normalized as {‘well_name’, value}.

__almost_eq__(other)#

Check if two Labelblocks are almost equal (same excitation and emission).

Return type:

bool

Parameters:

other (Labelblock)

class clophfit.prtecan.LabelblocksGroup(labelblocks, allequal=False)#

Group labelblocks with compatible metadata.

Parameters:
  • labelblocks (list[Labelblock]) – Labelblocks to be grouped.

  • allequal (bool) – True if labelblocks already tested equal.

Raises:

Exception – When labelblocks are neither equal nor almost equal.

Attributes:

labelblocks

allequal

metadata

Metadata shared by all labelblocks.

data

Grouped data if labelblocks are equal, otherwise empty.

data_nrm

Normalized data by number of flashes, integration time and gain.

labelblocks: list[Labelblock]#
allequal: bool = False#
metadata: dict[str, Metadata]#

Metadata shared by all labelblocks.

property data: dict[str, list[float]]#

Grouped data if labelblocks are equal, otherwise empty.

property data_nrm: dict[str, list[float]]#

Normalized data by number of flashes, integration time and gain.

class clophfit.prtecan.Metadata(value, unit=None)#

Represents the value of a metadata dictionary.

Parameters:
  • value (int | str | float | None) – The value for the dictionary key.

  • unit (Sequence[str | float | int] | None, optional) – The first element represents the unit, while the following elements are only listed.

Attributes:

value: int | str | float | None#
unit: Sequence[str | float | int] | None = None#
class clophfit.prtecan.PlateScheme(file=None)#

Define buffer, discard, ctrl and unk wells, and ctrl names.

Parameters:

file (Path) – File path to the scheme file [<well Id, sample name>].

Attributes:

file

nofit_keys

Buffer and discarded wells.

buffer

List of buffer wells.

discard

List of discard wells.

ctrl

List of CTR wells.

names

A dictionary mapping sample names to their associated list of wells.

file: Path | None = None#
property nofit_keys: set[str]#

Buffer and discarded wells.

property buffer: list[str]#

List of buffer wells.

property discard: list[str]#

List of discard wells.

property ctrl: list[str]#

List of CTR wells.

property names: dict[str, set[str]]#

A dictionary mapping sample names to their associated list of wells.

class clophfit.prtecan.TecanConfig(out_fp, comb, lim, title, fit, png)#

Group tecan cli options.

Attributes:

Parameters:
  • out_fp (Path)

  • comb (bool)

  • lim (tuple[float, float] | None)

  • title (str)

  • fit (bool)

  • png (bool)

out_fp: Path#
comb: bool#
lim: tuple[float, float] | None#
title: str#
fit: bool#
png: bool#
class clophfit.prtecan.Tecanfile(path)#

Parse a Tecan .xls file.

Parameters:

path (Path) – Path to .xls file.

Raises:
  • FileNotFoundError – When path does not exist.

  • Exception – When no Labelblock is found.

Attributes:

path

metadata

General metadata for Tecanfile, like Date and Shaking Duration.

labelblocks

All labelblocks contained in this file.

path: Path#
metadata: dict[str, Metadata]#

General metadata for Tecanfile, like Date and Shaking Duration.

labelblocks: dict[int, Labelblock]#

All labelblocks contained in this file.

class clophfit.prtecan.TecanfilesGroup(tecanfiles)#

Group of Tecanfiles containing at least one common Labelblock.

Parameters:

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

Raises:
  • ValueError – When no common Labelblock is found across all Tecanfiles.

  • Logging

  • -------

  • Logs a warning – If the Tecanfiles do not contain the same number of Labelblocks that can be merged in the same order, a warning is logged. In such cases, fewer LabelblocksGroup may be created.

Attributes:

tecanfiles

labelblocksgroups

Each group contains its own data like a titration.

metadata

Metadata shared by all tecanfiles.

tecanfiles: list[Tecanfile]#
labelblocksgroups: dict[int, LabelblocksGroup]#

Each group contains its own data like a titration. ??

metadata: dict[str, Metadata]#

Metadata shared by all tecanfiles.

class clophfit.prtecan.Titration(tecanfiles, x, is_ph, x_err=<factory>)#

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 (bool) – Indicate if x values represent pH (default is False).

  • x_err (ArrayF | None) – Uncertainties of concentration or pH values.

Raises:

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

Attributes:

x

is_ph

x_err

buffer

fit_keys

Set of wells to be fitted.

params

Get the datafit parameters.

bg

List of buffer values.

bg_err

List of buffer SEM values.

additions

List of initial volume followed by additions.

data

Buffer subtracted and corrected for dilution data.

scheme

Scheme for known samples like {'buffer', ['H12', 'H01'], 'ctrl'...}.

results

Fit results for all single titration dataset.

result_global

Perform global fitting lazily.

result_odr

Perform global ODR fitting.

result_mcmc

Perform global MCMC fitting.

Methods:

clear_all_data_results()

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

fromlistfile(list_file, is_ph)

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

load_additions(additions_file)

Load additions from file.

load_scheme(schemefile)

Load scheme from file.

export_data_fit(tecan_config)

Export dat files [x,y1,..,yN] from copy of self.data.

plot_temperature([title])

Plot temperatures of all labelblocksgroups.

x: ndarray[tuple[int, ...], dtype[float64]]#
is_ph: bool#
x_err: ndarray[tuple[int, ...], dtype[float64]]#
buffer: Buffer#
property fit_keys: set[str]#

Set of wells to be fitted.

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.

property bg: dict[int, ndarray[tuple[int, ...], dtype[float64]]]#

List of buffer values.

property bg_err: dict[int, ndarray[tuple[int, ...], dtype[float64]]]#

List of buffer SEM values.

classmethod fromlistfile(list_file, is_ph)#

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

Return type:

Titration

Parameters:
  • list_file (Path | str)

  • is_ph (bool)

property additions: list[float] | None#

List of initial volume followed by additions.

load_additions(additions_file)#

Load additions from file.

Return type:

None

Parameters:

additions_file (Path)

property data: dict[int, dict[str, ndarray[tuple[int, ...], dtype[float64]]]]#

Buffer subtracted and corrected for dilution data.

property scheme: PlateScheme#

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

load_scheme(schemefile)#

Load scheme from file. Set buffer_wells.

Return type:

None

Parameters:

schemefile (Path)

export_data_fit(tecan_config)#

Export dat files [x,y1,..,yN] from copy of self.data.

Return type:

None

Parameters:

tecan_config (TecanConfig)

property results: dict[int, TitrationResults]#

Fit results for all single titration dataset.

property result_global: TitrationResults#

Perform global fitting lazily.

property result_odr: TitrationResults#

Perform global ODR fitting.

tecanfiles: list[Tecanfile]#
labelblocksgroups: dict[int, LabelblocksGroup]#

Each group contains its own data like a titration. ??

metadata: dict[str, Metadata]#

Metadata shared by all tecanfiles.

property result_mcmc: TitrationResults#

Perform global MCMC fitting.

plot_temperature(title='')#

Plot temperatures of all labelblocksgroups.

Return type:

Figure

Parameters:

title (str)

class clophfit.prtecan.TitrationConfig(bg=True, bg_adj=False, dil=True, nrm=True, bg_mth='mean', mcmc=False, _callback=None)#

Parameters defining the fitting data with callback support.

Attributes:

Methods:

set_callback(callback)

Set the callback to be triggered on parameter change.

Parameters:
  • bg (bool)

  • bg_adj (bool)

  • dil (bool)

  • nrm (bool)

  • bg_mth (str)

  • mcmc (bool)

  • _callback (Callable[[], None] | None)

bg: bool = True#
bg_adj: bool = False#
dil: bool = True#
nrm: bool = True#
bg_mth: str = 'mean'#
mcmc: bool = False#
set_callback(callback)#

Set the callback to be triggered on parameter change.

Return type:

None

Parameters:

callback (Callable[[], None])

class clophfit.prtecan.TitrationResults(scheme, fit_keys, compute_func, results=<factory>, _dataframe=<factory>)#

Manage titration results with optional lazy computation.

Attributes:

scheme

fit_keys

compute_func

results

dataframe

Convert FitResult dictionary to a DataFrame.

Methods:

compute_all()

Compute results for all keys.

n_sd([par, expected_sd])

Compute median of K.

all_computed()

Check if all keys have been computed.

export_pngs(folder)

Export all fit result plots as PNG files.

export_data(folder)

Export all datasets as CSV files.

plot_k([xlim, title])

Plot K values as stripplot.

Parameters:
  • scheme (PlateScheme)

  • fit_keys (set[str])

  • compute_func (Callable[[str], FitResult])

  • results (dict[str, FitResult])

  • _dataframe (DataFrame)

scheme: PlateScheme#
fit_keys: set[str]#
compute_func: Callable[[str], FitResult]#
results: dict[str, FitResult]#
property dataframe: DataFrame#

Convert FitResult dictionary to a DataFrame.

compute_all()#

Compute results for all keys.

Return type:

None

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

Compute median of K.

Return type:

float

Parameters:
  • par (str)

  • expected_sd (float)

all_computed()#

Check if all keys have been computed.

Return type:

bool

export_pngs(folder)#

Export all fit result plots as PNG files.

Return type:

None

Parameters:

folder (str | Path)

export_data(folder)#

Export all datasets as CSV files.

Return type:

None

Parameters:

folder (str | Path)

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

clophfit.prtecan.calculate_conc(additions, conc_stock, conc_ini=0.0)#

Calculate concentration values.

additions[0]=vol_ini; Stock concentration is a parameter.

Parameters:
  • additions (Sequence[float]) – Initial volume and all subsequent additions.

  • conc_stock (float) – Concentration of the stock used for additions.

  • conc_ini (float) – Initial concentration (default=0).

Returns:

Concentrations as vector.

Return type:

ArrayF

clophfit.prtecan.dilution_correction(additions)#

Apply dilution correction.

Parameters:

additions (list[float]) – List of initial volume (index=0) followed by all additions.

Returns:

Dilution correction vector.

Return type:

ArrayF

clophfit.prtecan.extract_metadata(lines)#

Extract metadata into both Tecanfile and Labelblock.

From a list of stripped lines takes the first field as the key of the metadata dictionary, remaining fields goes into a list of values with the exception of Label ([str]) and Temperature ([float]).

Parameters:

lines (list[list[str | int | float]]) – Lines (list_of_lines) that are a list of fields, typically from a csv/xls file.

Returns:

Metadata for Tecanfile or Labelblock.

Return type:

dict[str, Metadata]

Examples

>>> lines = [
...     ["Shaking (Linear) Amplitude:", "", "", "", 2, "mm", "", "", "", "", ""]
... ]
>>> extract_metadata(lines)
{'Shaking (Linear) Amplitude:': Metadata(value=2, unit=['mm'])}
>>> lines = [["", "Temperature: 26 °C", "", "", "", "", "", "", "", "", ""]]
>>> extract_metadata(lines)
{'Temperature': Metadata(value=26.0, unit=['°C'])}
>>> lines = [["Excitation Wavelength", "", "", "", 400, "nm", "", "", "", "", ""]]
>>> extract_metadata(lines)
{'Excitation Wavelength': Metadata(value=400, unit=['nm'])}
>>> lines = [["Label: Label1", "", "", "", "", "", "", "", "", "", "", "", ""]]
>>> extract_metadata(lines)
{'Label': Metadata(value='Label1', unit=None)}
>>> lines = [["Mode", "", "", "", "Fluorescence Top Reading", "", "", "", "", ""]]
>>> extract_metadata(lines)["Mode"].value
'Fluorescence Top Reading'
clophfit.prtecan.lookup_listoflines(csvl, pattern='Label: Label', col=0)#

Lookup line numbers (row index) where given pattern occurs.

Parameters:
  • csvl (list[list[str | int | float]] | list[list[str]]) – Lines (list_of_lines) of a csv/xls file.

  • pattern (str) – Pattern to be searched (default=”Label: Label”).

  • col (int) – Column to search (default=0).

Returns:

Row/line index for all occurrences of pattern. Empty list for no occurrences.

Return type:

list[int]

clophfit.prtecan.merge_md(mds)#

Merge a list of metadata dict if the key value is the same in the list.

Return type:

dict[str, Metadata]

Parameters:

mds (list[dict[str, Metadata]])

clophfit.prtecan.read_xls(path)#

Read first sheet of an xls file.

Parameters:

path (Path) – Path to .xls file.

Returns:

Lines as list_of_lines.

Return type:

list[list[str | int | float]]

clophfit.prtecan.strip_lines(lines)#

Remove empty fields/cells from lines read from a csv file.

Parameters:

lines (list[list[str | int | float]]) – Lines (list_of_lines) that are a list of fields, typically from a csv/xls file.

Returns:

Lines (list_of_lines) removed from blank cells.

Return type:

list[list[str | int | float]]

Examples

>>> lines = [
...     ["Shaking (Linear) Amplitude:", "", "", "", 2, "mm", "", "", "", "", ""]
... ]
>>> strip_lines(lines)
[['Shaking (Linear) Amplitude:', 2, 'mm']]