Skip to content

Commit

Permalink
Major refactor for first stable release (#21)
Browse files Browse the repository at this point in the history
* added example and parser

* fixed stash error

* API update

* fixed test

* API update

* fixed parser

* API update

* functionality now in PlateManager class

* Refactor import statements for PlateManager class

* Refactor import statements for PlateManager class

---------

Co-authored-by: sdRDM Bot <sdRDM@bot.com>
  • Loading branch information
haeussma and sdRDM Bot authored Sep 16, 2024
1 parent fdcbf9e commit 5cb74cd
Show file tree
Hide file tree
Showing 64 changed files with 32,226 additions and 2,758 deletions.
12 changes: 0 additions & 12 deletions .github/workflows/generate_api.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ jobs:
with:
path: .cache
key: ${{ github.ref }}
- run: pip install mkdocs-material
- run: pip install mkdocs-material mkdocs-plotly-plugin mkdocstrings-python
- run: mkdocs gh-deploy --force
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.10", "3.11"]
python-version: ["3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
Expand All @@ -27,4 +27,4 @@ jobs:
- name: Run tests with pytest
run: |
poetry run pytest
poetry run pytest
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ poetry.lock
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# DS_Store files
.DS_Store

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

Expand Down
9 changes: 1 addition & 8 deletions MTPHandler/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
import os

from .core.blankstate import BlankState
from .core.initcondition import InitCondition
from .core.photometricmeasurement import PhotometricMeasurement
from .core.plate import Plate
from .core.protein import Protein
from .core.reactant import Reactant
from .core.species import Species
from .core.well import Well
from MTPHandler.plate_manager import PlateManager
98 changes: 61 additions & 37 deletions MTPHandler/ioutils/calipytion.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,42 @@
from __future__ import annotations

from typing import TYPE_CHECKING, List, Union
from typing import List, Optional

import numpy as np
from calipytion.core import Sample, SignalType, Standard
from calipytion.model import Sample, SignalType, Standard, UnitDefinition
from calipytion.tools.calibrator import Calibrator

from MTPHandler.core.well import Well

if TYPE_CHECKING:
from MTPHandler.core import Plate, Protein, Reactant
from MTPHandler.model import Molecule, Plate, Protein, Species, Well
from MTPHandler.tools import (
get_measurement,
get_species_condition,
measurement_is_blanked_for,
well_contains_species,
)


def _get_standard_wells(
plate: Plate,
species: Union[Protein, Reactant],
wavelength: int,
species: Species | Molecule | Protein,
wavelength: float,
) -> List[Well]:
# handel wavelength
if not wavelength:
if len(plate.measured_wavelengths) == 1:
wavelength = plate.measured_wavelengths[0]
else:
raise AttributeError(
f"Argument 'wavelength' must be provided. Measured wavelengths are: {plate.measured_wavelengths}"
)

# Subset of wells, that contain specified species, do not contain a protein, and are blanked
protein_ids = [
species.id for species in plate.species if isinstance(species, Protein)
]

standard_wells = []
for well in plate.wells:
if not well._contains_species(species.id):
if not well_contains_species(well, species.id):
continue

if any([well._contains_species(catalyst_id) for catalyst_id in protein_ids]):
if any(
[well_contains_species(well, catalyst_id) for catalyst_id in protein_ids]
):
continue

measurement = well.get_measurement(wavelength)
if measurement.is_blanked_for(species.id):
measurement = get_measurement(well, wavelength)
if measurement_is_blanked_for(measurement, species.id):
standard_wells.append(well)

# Add wells with zero concentration to standard wells
Expand All @@ -57,9 +53,9 @@ def _get_standard_wells(

def map_to_standard(
plate: Plate,
species: Union[Protein, Reactant],
wavelength: int = None,
signal_type: str = "abs",
species: Species | Molecule | Protein,
wavelength: float,
signal_type: SignalType = SignalType.ABSORBANCE,
) -> Standard:
standard_wells = _get_standard_wells(
plate=plate,
Expand All @@ -71,14 +67,15 @@ def map_to_standard(
samples = []
phs = []
for well in standard_wells:
condition = well._get_species_condition(species.id)
measurement = well.get_measurement(wavelength)
condition = get_species_condition(well, species.id)
measurement = get_measurement(well, wavelength)

samples.append(
Sample(
id=well.id,
# id=well.id,
concentration=condition.init_conc,
conc_unit=condition.conc_unit,
signal=float(np.nanmean(measurement.absorptions)),
conc_unit=UnitDefinition(**condition.conc_unit.model_dump()),
signal=float(np.nanmean(measurement.absorption)),
)
)
phs.append(well.ph)
Expand All @@ -90,27 +87,54 @@ def map_to_standard(
)
ph = phs[0]

if species.ld_id:
species_id = species.ld_id
else:
species_id = species.id

temp_unit = UnitDefinition(**plate.temperature_unit.model_dump())

# Create standard
return Standard(
species_id=species.id,
name=species.name,
molecule_id=species_id,
molecule_symbol=species.id,
molecule_name=species.name,
wavelength=wavelength,
signal_type=signal_type,
samples=samples,
ph=ph,
temperature=plate.temperatures[0],
temperature_unit=plate.temperature_unit,
created=plate.date_measured,
temp_unit=temp_unit,
)


def initialize_calibrator(
plate: "Plate",
species: Union[Protein, Reactant],
wavelength: int = None,
plate: Plate,
wavelength: float,
species: Species | Molecule | Protein,
signal_type: SignalType = SignalType.ABSORBANCE,
cutoff: float = None,
cutoff: Optional[float] = None,
) -> Calibrator:
"""
Initialize a calibrator for a given species.
Parameters
----------
plate : Plate
The plate containing the wells.
wavelength : float
The wavelength of the measurements.
species : Species | Molecule | Protein
The species to calibrate.
signal_type : SignalType, optional
The type of signal to calibrate, by default SignalType.ABSORBANCE.
Returns
-------
Calibrator
The initialized calibrator for creating a calibration curve.
"""
standard = map_to_standard(
plate=plate,
species=species,
Expand Down
Loading

0 comments on commit 5cb74cd

Please sign in to comment.