{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Getting started with prtecan" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2\n", "\n", "import os\n", "import warnings\n", "from pathlib import Path\n", "\n", "import arviz as az\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import pandas as pd\n", "import seaborn as sb\n", "\n", "from clophfit import prtecan\n", "from clophfit.binding import fitting, plotting\n", "from clophfit.prtecan import Titration\n", "\n", "data_tests = (Path(\"..\") / \"..\" / \"tests\" / \"Tecan\").resolve().absolute()\n", "\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "os.chdir(data_tests / \"L1\")\n", "warnings.filterwarnings(\"ignore\", category=UserWarning, module=\"clophfit.prtecan\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Parsing a Single Tecan Files\n", "\n", "A Tecan file comprises of multiple label blocks, each with its unique metadata. This metadata provides critical details and context for the associated label block. In addition, the Tecan file itself also has its overarching metadata that describes its overall content.\n", "\n", "When the KEYS for label blocks are identical, it indicates that these label blocks are equivalent - meaning, they contain the same measurements. The equality of KEYS plays a significant role in parsing and analyzing Tecan files, as it assists in identifying and grouping similar measurement sets together. This understanding of label block equivalence based on KEY similarity is critical when working with Tecan files." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tf = prtecan.Tecanfile(\"290513_8.8.xls\")\n", "lb1 = tf.labelblocks[1]\n", "lb2 = tf.labelblocks[2]\n", "tf.metadata" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(\"Metadata:\\n\", lb1.metadata, \"\\n\")\n", "print(\"Data:\\n\", lb1.data)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tf1 = prtecan.Tecanfile(\"290513_8.2.xls\")\n", "\n", "tf1.labelblocks[1].__almost_eq__(lb1), tf1.labelblocks[1] == lb1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Titration inherits TecanfilesGroup" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tfg = prtecan.TecanfilesGroup([tf, tf1])\n", "lbg1 = tfg.labelblocksgroups[1]\n", "\n", "print(lbg1.data[\"A01\"])\n", "\n", "lbg1.data_nrm[\"A01\"]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tit = prtecan.Titration([tf, tf1], x=np.array([8.8, 8.2]), is_ph=True)\n", "print(tit)\n", "tit.labelblocksgroups[1].data_nrm[\"A01\"]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tit.labelblocksgroups == tfg.labelblocksgroups" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tit.additions = [100, 1]\n", "\n", "tit.params.nrm = True\n", "tit.params.dil = True\n", "tit.params.bg = True\n", "tit.params" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tit.buffer.wells = [\"B02\"]\n", "\n", "tit.buffer.dataframes" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tit.bg, tit.bg_err" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tit.labelblocksgroups[1].data_nrm[\"A01\"]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Group a list of tecan files into a titration\n", "\n", "The command Titration.fromlistfile(\"../listfile\") reads a list of Tecan files, identifies unique measurements in each file, groups matching ones, and combines them into a titration set for further analysis." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tit = Titration.fromlistfile(\"./list.pH.csv\", is_ph=True)\n", "print(tit.x)\n", "lbg1 = tit.labelblocksgroups[1]\n", "lbg2 = tit.labelblocksgroups[2]\n", "print(lbg2.labelblocks[6].metadata[\"Temperature\"])\n", "lbg1.metadata, lbg2.metadata" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Within each labelblockgroups `data_norm` is immediately calculated." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "(lbg1.data[\"H03\"], lbg2.data, lbg1.data_nrm[\"H03\"], lbg2.data_nrm[\"H03\"])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Start with platescheme loading to set buffer wells (and consequently buffer values).\n", "\n", "Labelblocks group will be populated with data buffer subtracted with/out normalization." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tit.load_scheme(\"./scheme.txt\")\n", "print(f\"Buffer wells : {tit.scheme.buffer}\")\n", "print(f\"Ctrl wells : {tit.scheme.ctrl}\")\n", "print(f\"CTR name:wells {tit.scheme.names}\")\n", "\n", "tit.scheme" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "(lbg1.data[\"H12\"], lbg2.data_nrm[\"H12\"])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tit.load_additions(\"./additions.pH\")\n", "tit.additions" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "(lbg1.data[\"H12\"], tit.data[1][\"H12\"], lbg1.data_nrm[\"H12\"], tit.bg[1])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The order in which you apply dilution correction and plate scheme can impact your intermediate results, even though the final results might be the same.\n", "\n", " Dilution correction adjusts the measured data to account for any dilutions made during sample preparation. This typically involves multiplying the measured values by the dilution factor to estimate the true concentration of the sample.\n", "\n", " A plate scheme describes the layout of the samples on a plate (common in laboratory experiments, such as those involving microtiter plates). The plate scheme may involve rearranging or grouping the data in some way based on the physical location of the samples on the plate." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Reassign Buffer Wells\n", "\n", "You can reassess buffer wells, updating the data to account for any dilution (additions) and subtracting the updated buffer value. This is a handy feature that gives you more control over your analysis.\n", "\n", "For instance, consider the following data for a particular well:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(tit.labelblocksgroups[2].data_nrm[\"D01\"])\n", "tit.data[2].get(\"D01\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tit.params.bg = False\n", "tit.params.dil = False\n", "print(tit.data[2][\"D02\"])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can reassign buffer wells using the `buffer_wells` attribute:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tit.params.bg = True\n", "tit.buffer.wells = [\"D01\", \"E01\"]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tit.bg" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This updates the data for the specified wells, correcting for dilution and subtracting the buffer value:" ] }, { "cell_type": "markdown", "metadata": { "jp-MarkdownHeadingCollapsed": true }, "source": [ "
- unchanged in labelblocksgroups[:].data
- buffer subtracted in labelblocksgroups[:].data_buffersubtracted
- buffer subtracted and dilution corrected in data