Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Feb 6, 2025
1 parent 654f6ff commit 9de52c2
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 25 deletions.
17 changes: 10 additions & 7 deletions fluorescence_assay/analysis.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
"""Module to analyze data, including curve fitting."""

import logging
from typing import Dict, List
from typing import Dict, List, Union

import numpy as np
import pandas as pd

from typing import Dict, List, Union

from scipy.optimize import curve_fit

logger = logging.getLogger(__name__)

def calculate_dose_response(dosed: Union[List[float],List[np.array]], ref: Union[List[float],List[np.array]], conc: Union[List[float],List[np.array]]) -> pd.Series:

def calculate_dose_response(
dosed: Union[list[float], list[np.array]],
ref: Union[list[float], list[np.array]],
conc: Union[list[float], list[np.array]],
) -> pd.Series:
""""""

dosed = np.array(dosed)
Expand All @@ -23,6 +25,7 @@ def calculate_dose_response(dosed: Union[List[float],List[np.array]], ref: Union

return pd.Series(diff, index=conc)


def calculate_fraction_bound(dose_response: pd.Series) -> pd.Series:
""""""

Expand All @@ -32,6 +35,6 @@ def calculate_fraction_bound(dose_response: pd.Series) -> pd.Series:
F_max = np.max(arr)
F_min = np.min(arr)

F_bound = (arr - F_min)/(F_max - F_min)
F_bound = (arr - F_min) / (F_max - F_min)

return pd.Series(F_bound, index=conc)
return pd.Series(F_bound, index=conc)
21 changes: 15 additions & 6 deletions fluorescence_assay/plate_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,26 @@ def get_well(self, well: str) -> pd.Series:
""""""

return self.df[well]
def get_row(self, row: Union[str, int]) -> List[pd.Series]:

def get_row(self, row: Union[str, int]) -> list[pd.Series]:
""""""

num2alpha = {"0": "A", "1": "B", "2": "C", "3": "D", "4": "E", "5": "F", "6": "G", "7": "H"}
num2alpha = {
"0": "A",
"1": "B",
"2": "C",
"3": "D",
"4": "E",
"5": "F",
"6": "G",
"7": "H",
}

if type(row) == int:
row = num2alpha[str(row)]

return [self.get_well(pos) for pos in [f"{row}{i}" for i in range(1, 13)]]

@property
def pd(self):
""""""
Expand Down Expand Up @@ -145,10 +154,10 @@ def plate(self):
plate[row, col] = self.series.loc[series_index]

return plate

def get_row(self, row: Union[str, int]):

if type(row) == str:
row = self.alpha2num[row]

return self.plate[row]
return self.plate[row]
43 changes: 31 additions & 12 deletions fluorescence_assay/plotting.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
"""Module to plot parsed plate reader ouptputs."""

from dataclasses import dataclass
from typing import List, Dict, Tuple, Callable, Union, Optional

from matplotlib.axes import Axes
from matplotlib.figure import Figure
from typing import Callable, Dict, List, Optional, Tuple, Union

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from matplotlib.axes import Axes
from matplotlib.figure import Figure


def plot_fluorescence_spectra(spectra: List[pd.Series], concentrations: List[float], axes: Optional[Axes] = None, cmap: Optional[str] = None) -> None:
def plot_fluorescence_spectra(
spectra: list[pd.Series],
concentrations: list[float],
axes: Optional[Axes] = None,
cmap: Optional[str] = None,
) -> None:
""""""

if axes is None:
Expand All @@ -34,29 +37,45 @@ def plot_fluorescence_spectra(spectra: List[pd.Series], concentrations: List[flo
xx_i = [int(x) for x in spectrum.index.to_list()]
yy_i = spectrum.to_numpy()

c = cmap(1-norm(concentrations[i]))
c = cmap(1 - norm(concentrations[i]))

axes.plot(xx_i, yy_i, color=c)

# TODO: Colorbar

def plot_absorbance_spectrum(concentrations: List[float], spectrum: List[float], axes: Optional[Axes] = None) -> None:

def plot_absorbance_spectrum(
concentrations: list[float], spectrum: list[float], axes: Optional[Axes] = None
) -> None:
""""""

if axes is None:
fig, axes = plt.subplots()

axes.plot(concentrations, spectrum)

def plot_dose_response(concentrations: List[float], dose_response: List[float], axes: Optional[Axes] = None) -> None:

def plot_dose_response(
concentrations: list[float], dose_response: list[float], axes: Optional[Axes] = None
) -> None:
""""""

if axes is None:
fig, axes = plt.subplots()

axes.plot(concentrations, dose_response)

def create_grid_of_plots(rows: int, cols: int, hspace: Optional[float], wspace: Optional[float], xlabel: Optional[str] = None, ylabel: Optional[str] = None, titles: Optional[List[str]] = None, fig: Optional[Figure] = None) -> List[Axes]:

def create_grid_of_plots(
rows: int,
cols: int,
hspace: Optional[float],
wspace: Optional[float],
xlabel: Optional[str] = None,
ylabel: Optional[str] = None,
titles: Optional[list[str]] = None,
fig: Optional[Figure] = None,
) -> list[Axes]:
""""""

if fig is None:
Expand All @@ -75,12 +94,12 @@ def create_grid_of_plots(rows: int, cols: int, hspace: Optional[float], wspace:
ax.label_outer()

if xlabel is not None:
xplots = np.arange(rows*cols - cols, rows*cols)
xplots = np.arange(rows * cols - cols, rows * cols)
for i in xplots:
axes[i].set_xlabel(xlabel)

if ylabel is not None:
yplots = cols*np.arange(0, rows)
yplots = cols * np.arange(0, rows)
for i in yplots:
axes[i].set_ylabel(ylabel)

Expand All @@ -89,4 +108,4 @@ def create_grid_of_plots(rows: int, cols: int, hspace: Optional[float], wspace:
for i in titleplots:
axes[i].set_title(titles[i])

return axes
return axes

0 comments on commit 9de52c2

Please sign in to comment.