Skip to content

Commit

Permalink
Merge pull request #20 from FAIRChemistry/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
haeussma authored Jun 5, 2024
2 parents 65f8ad6 + 6a39248 commit fdcbf9e
Show file tree
Hide file tree
Showing 18 changed files with 11,916 additions and 300 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ share/python-wheels/
.installed.cfg
*.egg
MANIFEST
.pyrightconfig.json

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down
2 changes: 1 addition & 1 deletion MTPHandler/core/blankstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class BlankState(
default="https://github.com/FAIRChemistry/MTPHandler"
)
_commit: Optional[str] = PrivateAttr(
default="862fbd059c9b36c968c7988ff728719b3737ac24"
default="b67724f080afb13c3b78cd2a559646f8b3f2e6e7"
)

_raw_xml_data: Dict = PrivateAttr(default_factory=dict)
Expand Down
2 changes: 1 addition & 1 deletion MTPHandler/core/initcondition.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class InitCondition(
default="https://github.com/FAIRChemistry/MTPHandler"
)
_commit: Optional[str] = PrivateAttr(
default="862fbd059c9b36c968c7988ff728719b3737ac24"
default="b67724f080afb13c3b78cd2a559646f8b3f2e6e7"
)

_raw_xml_data: Dict = PrivateAttr(default_factory=dict)
Expand Down
2 changes: 1 addition & 1 deletion MTPHandler/core/photometricmeasurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class PhotometricMeasurement(
default="https://github.com/FAIRChemistry/MTPHandler"
)
_commit: Optional[str] = PrivateAttr(
default="862fbd059c9b36c968c7988ff728719b3737ac24"
default="b67724f080afb13c3b78cd2a559646f8b3f2e6e7"
)

_raw_xml_data: Dict = PrivateAttr(default_factory=dict)
Expand Down
100 changes: 27 additions & 73 deletions MTPHandler/core/plate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from plotly.subplots import make_subplots
from pydantic import PrivateAttr, model_validator
from pydantic_xml import attr, element
from rich.jupyter import print
from sdRDM.base.datatypes import Identifier, Unit
from sdRDM.base.listplus import ListPlus
from sdRDM.tools.utils import elem2dict
Expand Down Expand Up @@ -123,7 +124,7 @@ class Plate(
default="https://github.com/FAIRChemistry/MTPHandler"
)
_commit: Optional[str] = PrivateAttr(
default="862fbd059c9b36c968c7988ff728719b3737ac24"
default="b67724f080afb13c3b78cd2a559646f8b3f2e6e7"
)

_raw_xml_data: Dict = PrivateAttr(default_factory=dict)
Expand Down Expand Up @@ -343,7 +344,7 @@ def add_species(

if not id:
warnings.warn(
"""No ID provided for species. This might cause issues when referencing the species.
"""No ID provided for species. This might cause issues when referencing the species.
Consider providing an ID which references the species such as a Chebi ID."""
)

Expand Down Expand Up @@ -475,8 +476,8 @@ def assign_species_to_all(
)

print(
f"Assigned {species.name} ({species.id}) with {init_conc} {conc_unit} to"
" all wells."
f"Assigned [bold magenta]{species.name}[/] ({species.id}) with"
f" {init_conc} {conc_unit} to all wells."
)

def assign_species_to_columns(
Expand Down Expand Up @@ -511,7 +512,7 @@ def assign_species_to_columns(
assert len(init_concs) == len(
wells
), f"""
Number of initial concentrations ({len(init_concs)}) does not match number
Number of initial concentrations ({len(init_concs)}) does not match number
of wells ({len(wells)}) in columns ({column_ids}).
"""

Expand All @@ -527,8 +528,8 @@ def assign_species_to_columns(
)

print(
f"Assigned {species.name} ({species.id}) with concentrations of"
f" {init_concs} {conc_unit} to columns {column_ids}."
f"Assigned [bold magenta]{species.name}[/] ({species.id}) with"
f" concentrations of {init_concs} {conc_unit} to columns {column_ids}."
)

def assign_species_to_rows(
Expand Down Expand Up @@ -557,7 +558,7 @@ def assign_species_to_rows(
assert len(init_concs) == len(
wells
), f"""
Number of initial concentrations ({len(init_concs)}) does not match number
Number of initial concentrations ({len(init_concs)}) does not match number
of wells ({len(wells)}) in rows ({row_ids}).
"""

Expand All @@ -573,8 +574,8 @@ def assign_species_to_rows(
)

print(
f"Assigned {species.name} ({species.id}) with {init_conc} {conc_unit}"
f" to rows {row_ids}."
f"Assigned [bold magenta]{species.name}[/] ({species.id}) with"
f" {init_conc} {conc_unit} to rows {row_ids}."
)

@staticmethod
Expand All @@ -598,56 +599,6 @@ def _handle_blank_status(
contributes_to_signal=contributes,
)

def _handle_wavelength(self) -> float:
if len(self.measured_wavelengths) == 1:
return self.measured_wavelengths[0]

else:
raise AttributeError(
"Argument 'wavelength' must be provided. Measured wavelengths are:"
f" {self.measured_wavelengths}"
)

def get_wells(
self,
wavelength: int = None,
) -> List[Well]:
if not wavelength:
wavelength = self._handle_wavelength()

def get_well_by_id(self, _id: str) -> Well:
for well in self.wells:
if well.id == _id.upper():
return well

raise ValueError(f"No well found with id {_id}")

def _get_wells_by_column_id(self, column_id: int, wavelength: int) -> Well:
x_pos = column_id - 1
y_positions = [
well.y_pos
for well in self.wells
if well.x_pos == x_pos and well.wavelength == wavelength
]

return [self._get_well_by_xy(x_pos, y_pos, wavelength) for y_pos in y_positions]

def _get_wells_by_row_id(self, row_id: str) -> List[Well]:
return [well for well in self.wells if row_id in well.id and well.measurements]

def _get_well_by_xy(self, x_pos: int, y_pos: int, wavelength: int) -> Well:
for well in self.wells:
if (
well.x_pos == x_pos
and well.y_pos == y_pos
and well.wavelength == wavelength
):
return well

raise ValueError(
f"No well found with x position {x_pos} and y position {y_pos}"
)

def assign_species_to_all_except(
self,
well_ids: List[str],
Expand All @@ -672,8 +623,8 @@ def assign_species_to_all_except(
)

print(
f"Assigned {species.name} ({species.id}) with {init_conc} {conc_unit}"
f" to all wells except {well_ids}."
f"Assigned [bold magenta]{species.name}[/] ({species.id}) with"
f" {init_conc} {conc_unit} to all wells except {well_ids}."
)

def assign_species_from_spreadsheet(
Expand Down Expand Up @@ -730,8 +681,8 @@ def assign_species_from_spreadsheet(
)

print(
f"Assigned initial concentrations from {path} to"
f" {species.name} ({species.id})."
f"Assigned initial concentrations for [bold magenta]{species.name}[/]"
f" ({species.id}) from {path}."
)

def get_well(self, _id: str) -> Well:
Expand Down Expand Up @@ -804,7 +755,7 @@ def blank_species(
if len(wells) == 0:
print(
f"{species.name} ({species.id}) at {wavelength} nm does not contribute"
" to signal."
" to signal. Is the specified wavelength correct?print"
)

if len(blanking_wells) == 0:
Expand All @@ -815,7 +766,7 @@ def blank_species(

# get mapping of concentration to blank wells
conc_blank_mapping = self._get_conc_blank_mapping(
wells=blanking_wells, species_id=species, wavelength=wavelength
wells=blanking_wells, species=species, wavelength=wavelength
)

# apply to wells where species is present in respective concentration
Expand Down Expand Up @@ -846,14 +797,14 @@ def blank_species(

print(f"Blanked {len(blanked_wells)} wells containing {species.name}.\n")

def visualize(self, zoom: bool = False, wavelengths: float = None):
def visualize(self, zoom: bool = False, wavelengths: list[float] = []):
if zoom:
shared_yaxes = False
else:
shared_yaxes = True

if not wavelengths:
wavelengths = self.wells[0].measurements[0].wavelength
wavelengths = [self.wells[0].measurements[0].wavelength]

if not isinstance(wavelengths, list):
wavelengths = [wavelengths]
Expand Down Expand Up @@ -893,7 +844,7 @@ def visualize(self, zoom: bool = False, wavelengths: float = None):
plot_bgcolor="white",
hovermode="x",
title=dict(
text=f"{self.temperatures[0]} °{self.temperature_unit.name}",
text=f"{self.temperatures[0]} {self.temperature_unit.name}",
),
margin=dict(l=20, r=20, t=100, b=20),
)
Expand Down Expand Up @@ -926,7 +877,7 @@ def _get_conc_blank_mapping(
) -> Dict[float, List[Well]]:
blank_measurement_mapping = defaultdict(list)
for well in wells:
condition = well._get_species_condition(species)
condition = well._get_species_condition(species.id)

blank_measurement_mapping[condition.init_conc].append(
well.get_measurement(wavelength).absorption
Expand All @@ -935,10 +886,13 @@ def _get_conc_blank_mapping(
conc_mean_blank_mapping = {}
for conc, absorptions in blank_measurement_mapping.items():
mean_absorption = np.nanmean(absorptions)
std_absorption = np.nanstd(absorptions)
std_perc = abs(std_absorption / mean_absorption) * 100
print(
f"Mean absorption of {species.name} ({species.id}) at"
f" {conc} {condition.conc_unit.name}: {mean_absorption:.4f} calculated"
f" based on wells {[well.id for well in wells]}."
f"Mean absorption of [bold magenta]{species.name}[/] ({species.id}) at"
f" {conc} {condition.conc_unit.name}: {mean_absorption:.4f} ±"
f" {std_perc:.0f}% calculated based on wells"
f" {[well.id for well in wells]}."
)
conc_mean_blank_mapping[conc] = mean_absorption

Expand Down
2 changes: 1 addition & 1 deletion MTPHandler/core/protein.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Protein(
default="https://github.com/FAIRChemistry/MTPHandler"
)
_commit: Optional[str] = PrivateAttr(
default="862fbd059c9b36c968c7988ff728719b3737ac24"
default="b67724f080afb13c3b78cd2a559646f8b3f2e6e7"
)

_raw_xml_data: Dict = PrivateAttr(default_factory=dict)
Expand Down
2 changes: 1 addition & 1 deletion MTPHandler/core/species.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Species(
default="https://github.com/FAIRChemistry/MTPHandler"
)
_commit: Optional[str] = PrivateAttr(
default="862fbd059c9b36c968c7988ff728719b3737ac24"
default="b67724f080afb13c3b78cd2a559646f8b3f2e6e7"
)

_raw_xml_data: Dict = PrivateAttr(default_factory=dict)
Expand Down
2 changes: 1 addition & 1 deletion MTPHandler/core/well.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Well(
default="https://github.com/FAIRChemistry/MTPHandler"
)
_commit: Optional[str] = PrivateAttr(
default="862fbd059c9b36c968c7988ff728719b3737ac24"
default="b67724f080afb13c3b78cd2a559646f8b3f2e6e7"
)

_raw_xml_data: Dict = PrivateAttr(default_factory=dict)
Expand Down
14 changes: 12 additions & 2 deletions MTPHandler/readers/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def read(
from MTPHandler.readers.megellan_parser import read_magellan
from MTPHandler.readers.multiskan_spectrum_parser import read_multiskan_spectrum
from MTPHandler.readers.spectramax_parser import read_spectramax
from MTPHandler.readers.tekan_spark_parser import read_tekan_spark

try:
return read_magellan(
Expand All @@ -42,7 +43,7 @@ def read(
temperature=temperature,
temperature_unit=temperature_unit,
)
except ValueError:
except Exception:
pass

try:
Expand All @@ -52,7 +53,16 @@ def read(
ph=ph,
time_unit=time_unit,
)
except ValueError:
except Exception:
pass

try:
return read_tekan_spark(
cls=cls,
path=path,
ph=ph,
)
except Exception:
pass

raise ValueError("Could not read file with implemented readers.")
Expand Down
Loading

0 comments on commit fdcbf9e

Please sign in to comment.