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:
|
Parse a label block. |
|
Group labelblocks with compatible metadata. |
|
Represents the value of a metadata dictionary. |
|
Define buffer, ctrl and unk wells, and ctrl names. |
|
Parse a Tecan .xls file. |
|
Group of Tecanfiles containing at least one common Labelblock. |
|
Build titrations from grouped Tecanfiles and corresponding concentrations or pH values. |
|
Perform analysis of a titration. |
Functions:
|
Calculate concentration values. |
|
Apply dilution correction. |
|
Extract metadata into both Tecanfile and Labelblock. |
|
Lookup line numbers (row index) where given pattern occurs. |
|
Merge a list of metadata dict if the key value is the same in the list. |
|
Read first sheet of an xls file. |
|
Remove empty fields/cells from lines read from a csv file. |
- class clophfit.prtecan.Labelblock(_lines, path=None)#
Parse a label block.
- Parameters:
_lines (list[list[str | int | float]]) – Lines to create this Labelblock.
path (Path, optional) – Path to the containing file, if it exists.
- Raises:
Exception – When data do not correspond to a complete 96-well plate.
- Warns:
Warning – When it replaces “OVER” with
np.nanfor saturated values.
Attributes:
Metadata specific for this Labelblock.
The 96 data values as {'well_name', value}.
Background value to be subtracted before dilution correction.
Background value to be subtracted before dilution correction.
Get standard deviation of buffer_wells values.
Get standard deviation of normalized buffer_wells values.
Normalize data by number of flashes, integration time and gain.
Buffer subtracted data.
Normalize buffer-subtracted data.
Methods:
__almost_eq__(other)Two labelblocks are almost equal when they could be merged after normalization.
- path: Path | None = None#
- metadata: dict[str, Metadata]#
Metadata specific for this Labelblock.
- data: dict[str, float]#
The 96 data values as {‘well_name’, value}.
- property buffer: float | None#
Background value to be subtracted before dilution correction.
- property buffer_norm: float | None#
Background value to be subtracted before dilution correction.
- property buffer_sd: float | None#
Get standard deviation of buffer_wells values.
- property buffer_norm_sd: float | None#
Get standard deviation of normalized buffer_wells values.
- property data_norm: dict[str, float]#
Normalize data by number of flashes, integration time and gain.
- property data_buffersubtracted: dict[str, float]#
Buffer subtracted data.
- property data_buffersubtracted_norm: dict[str, float]#
Normalize buffer-subtracted data.
- __almost_eq__(other)#
Two labelblocks are almost equal when they could be merged after normalization.
- Return type:
bool- Parameters:
other (Labelblock) –
- class clophfit.prtecan.LabelblocksGroup(labelblocks, allequal=False)#
Group labelblocks with compatible metadata.
data_norm always exist.
- 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:
Metadata shared by all labelblocks.
Return None or data.
Normalize data by number of flashes, integration time and gain.
Buffer subtracted data.
Buffer subtracted data.
-
labelblocks:
list[Labelblock]#
-
allequal:
bool= False#
- property data: dict[str, list[float]] | None#
Return None or data.
- property data_norm: dict[str, list[float]]#
Normalize data by number of flashes, integration time and gain.
- property data_buffersubtracted: dict[str, list[float]] | None#
Buffer subtracted data.
- property data_buffersubtracted_norm: dict[str, list[float]]#
Buffer subtracted data.
- 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:
UnionType[int,str,float,None]#
-
unit:
Optional[Sequence[str|float|int]] = None#
- class clophfit.prtecan.PlateScheme(file=None)#
Define buffer, ctrl and unk wells, and ctrl names.
- Parameters:
file (Path) – File path to the scheme file [<well Id, sample name>].
Attributes:
List of buffer wells.
List of CTR wells.
A dictionary mapping sample names to their associated list of wells.
-
file:
Optional[Path] = None#
- property buffer: list[str]#
List of buffer 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.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:
General metadata for Tecanfile, like Date and Shaking Duration.
All labelblocks contained in this file.
-
path:
Path#
-
labelblocks:
list[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:
Exception – When all Labelblocks are not at least almost equal.
- Warns:
Warning – The Tecanfiles listed in tecanfiles are expected to contain the “same” list (of length N) of Labelblocks. Normally, N labelblocksgroups will be created. However, if not all Tecanfiles contain the same number of Labelblocks that can be merged (‘equal’ mergeable) in the same order, then a warning will be raised. In this case, a number M < N of groups can be built.
Attributes:
Each group contains its own data like a titration.
Metadata shared by all tecanfiles.
-
labelblocksgroups:
list[LabelblocksGroup]# Each group contains its own data like a titration. ??
- class clophfit.prtecan.Titration(tecanfiles, conc, is_ph)#
Build titrations from grouped Tecanfiles and corresponding concentrations or pH values.
- Parameters:
tecanfiles (list[Tecanfile]) – Tecanfiles to be grouped.
conc (ArrayF) – Concentration or pH values.
is_ph (bool) – Indicate if x values represent pH (default is False).
Attributes:
List of initial volume followed by additions.
Buffer subtracted and corrected for dilution data.
Buffer subtracted, corrected for dilution and normalized data.
Scheme for known samples like {'buffer', ['H12', 'H01'], 'ctrl'...}.
Methods:
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(out_folder)Export dat files [x,y1,..,yN] from labelblocksgroups.
-
conc:
ndarray[Any,dtype[float64]]#
-
is_ph:
bool#
- classmethod fromlistfile(list_file, is_ph)#
Build Titration from a list[.pH|.Cl] file.
- Parameters:
list_file (Path | str) – File path to the listfile ([fpath conc]).
is_ph (bool) – Indicate if x values represent pH.
- Return type:
- 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: list[dict[str, list[float]] | None] | None#
Buffer subtracted and corrected for dilution data.
- property data_nrm: list[dict[str, list[float]]] | None#
Buffer subtracted, corrected for dilution and normalized 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(out_folder)#
Export dat files [x,y1,..,yN] from labelblocksgroups.
Remember that a Titration has at least 1 normalized Lbg dataset dat_nrm.
dat: [d1, None] | [d1, d2] dat_bg: [{}, None] | [d1, None] | [{}, {}] | [d1, d2] dat_bg_dil: [{}, None] | [d1, None] | [{}, {}] | [d1, d2] dat_nrm: [d1,d2] dat_bg_nrm: [{}, {}] | [d1, d2] dat_bg_dil_nrm: [{}, {}] | [d1, d2]
- Parameters:
out_folder (Path) – Path to output folder.
- Return type:
None
-
labelblocksgroups:
list[LabelblocksGroup]# Each group contains its own data like a titration. ??
- class clophfit.prtecan.TitrationAnalysis(tecanfiles, conc, is_ph)#
Perform analysis of a titration.
- Raises:
ValueError – For unexpected file format, e.g. header names.
- Parameters:
tecanfiles (list[Tecanfile]) –
conc (ArrayF) –
is_ph (bool) –
Classes:
FitKwargs([ini, fin, weight])Represent arguments for fit method.
Attributes:
A list of wells containing samples that are neither buffer nor CTR samples.
Data used for fitting.
Get the datafit parameters.
Get the arguments for fitting.
Result dataframes.
Result dataframes.
Methods:
fromlistfile(list_file, is_ph)Build TitrationAnalysis from a list[.pH|.Cl] file.
fit()Fit titrations.
plot_k(lb, hue_column[, xlim, title])Plot K values as stripplot.
plot_all_wells(lb, path)Plot all wells into a pdf.
plot_ebar(lb, y, yerr[, x, xerr, xmin, ...])Plot SA vs.
print_fitting(lb)Print fitting parameters for the whole plate.
plot_buffer([title])Plot buffers of all labelblocksgroups.
export_png(lb, path)Export png like lb1/ lb2/ lb1_lb2/.
- class FitKwargs(ini=0, fin=None, weight=True)#
Represent arguments for fit method.
Attributes:
- Parameters:
ini (int) –
fin (int | None) –
weight (bool) –
-
ini:
int= 0#
-
fin:
Optional[int] = None#
-
weight:
bool= True#
- keys_unk: list[str]#
A list of wells containing samples that are neither buffer nor CTR samples.
- classmethod fromlistfile(list_file, is_ph)#
Build TitrationAnalysis from a list[.pH|.Cl] file.
- Return type:
- Parameters:
list_file (Path | str) –
is_ph (bool) –
- property fitdata: Sequence[dict[str, list[float]] | None]#
Data used for fitting.
- property fitdata_params: dict[str, bool]#
Get the datafit parameters.
- tecanfiles: list[Tecanfile]#
- conc: ArrayF#
- is_ph: bool#
- labelblocksgroups: list[LabelblocksGroup]#
Each group contains its own data like a titration. ??
- metadata: dict[str, Metadata]#
Metadata shared by all tecanfiles.
- property results: list[dict[str, FitResult]]#
Result dataframes.
- property result_dfs: list[DataFrame]#
Result dataframes.
- fit()#
Fit titrations.
The fitting process uses the initial point (ini), the final point (fin), and weighting (weight) parameters defined in the FitKwargs instance (accessible through self.fitkws).
To perform a fit, you would first define the fit parameters and then call the fit method: titan.fitkws = TitrationAnalysis.FitKwargs(ini=0, fin=None, weight=True)
- Returns:
A list of dictionaries with fitting results.
- Return type:
list[dict[str, FitResult]]
Notes
This method is less general and is designed for two label blocks.
- plot_k(lb, hue_column, xlim=None, title=None)#
Plot K values as stripplot.
- Parameters:
lb (int) – Labelblock index.
hue_column (str) – Column in fitresults_df used for color-coding data points in the stripplot.
xlim (tuple[float, float], optional) – Range.
title (str, optional) – To name the plot.
- Returns:
The figure.
- Return type:
plt.figure
- plot_all_wells(lb, path)#
Plot all wells into a pdf.
- Return type:
None- Parameters:
lb (int) –
path (str | Path) –
- plot_ebar(lb, y, yerr, x='K', xerr='sK', xmin=None, ymin=None, xmax=None, title=None)#
Plot SA vs. K with errorbar for the whole plate.
- Return type:
Figure- Parameters:
lb (int) –
y (str) –
yerr (str) –
x (str) –
xerr (str) –
xmin (float | None) –
ymin (float | None) –
xmax (float | None) –
title (str | None) –
- print_fitting(lb)#
Print fitting parameters for the whole plate.
- Return type:
None- Parameters:
lb (int) –
- plot_buffer(title=None)#
Plot buffers of all labelblocksgroups.
- Return type:
Figure- Parameters:
title (str | None) –
- export_png(lb, path)#
Export png like lb1/ lb2/ lb1_lb2/.
- Return type:
None- Parameters:
lb (int) –
path (str | Path) –
- 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_of_lines) – Lines that are a list of fields, typically from a csv/xls file.
- Returns:
Metadata for Tecanfile or Labelblock.
- Return type:
dict[str, str | list[str | int | float]]
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_of_lines) – 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.
- clophfit.prtecan.read_xls(path)#
Read first sheet of an xls file.
- Parameters:
path (Path) – Path to .xls file.
- Returns:
Lines.
- Return type:
list_of_lines
- clophfit.prtecan.strip_lines(lines)#
Remove empty fields/cells from lines read from a csv file.
- Parameters:
lines (list_of_lines) – Lines that are a list of fields, typically from a csv/xls file.
- Returns:
Lines removed from blank cells.
- Return type:
list_of_lines
Examples
>>> lines = [['Shaking (Linear) Amplitude:', '', '', '', 2, 'mm', '', '', '', '', '']] >>> strip_lines(lines) [['Shaking (Linear) Amplitude:', 2, 'mm']]