Skip to content

Commit

Permalink
chore: WIP get unit_test passing with py311 deps
Browse files Browse the repository at this point in the history
  • Loading branch information
wholtz committed Oct 10, 2023
1 parent 57b9ee6 commit 4adc223
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 28 deletions.
2 changes: 1 addition & 1 deletion docker/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ gspread
h5py
humanize
ipykernel
ipympl==0.8.6
ipympl==0.9.3
ipysheet
ipywidgets
jupyter-client
Expand Down
2 changes: 1 addition & 1 deletion docker/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ ipykernel==6.25.2
# via
# -r requirements.in
# jupyterlab
ipympl==0.8.6
ipympl==0.9.3
# via -r requirements.in
ipysheet==0.7.0
# via -r requirements.in
Expand Down
21 changes: 12 additions & 9 deletions metatlas/tools/cheminfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import matchms
import numpy as np

from matchms.filtering.load_adducts import load_adducts_dict
from matchms.filtering.filter_utils.load_known_adducts import (
load_known_adducts)
from rdkit import Chem

from metatlas.interfaces.compounds import structure_cleaning as cleaning
Expand All @@ -28,21 +29,23 @@ def get_parent_mass(precursor_mz: float, adduct: str) -> float:
@functools.lru_cache
def get_precursor_mz(parent_mass: float, adduct: str) -> float:
"""For an input molecule with parent_mass that generates adduct, return the resutling precursor_mz"""
adducts = load_adducts_dict()
if adduct not in adducts:
adducts = load_known_adducts()
if adduct not in adducts["adduct"].values:
raise KeyError("Adduct '%s' is not supported")
multiplier = adducts[adduct]["mass_multiplier"]
correction_mass = adducts[adduct]["correction_mass"]
row = adducts.loc[adducts["adduct"] == adduct].iloc[0]
multiplier = row["mass_multiplier"]
correction_mass = row["correction_mass"]
return (parent_mass + correction_mass) / multiplier


@functools.lru_cache
def is_positive_mode(adduct: str) -> bool:
"""Returns True if the MS mode for an adduct is positive"""
adducts = load_adducts_dict()
if adduct not in adducts:
adducts = load_known_adducts()
if adduct not in adducts["adduct"].values:
raise KeyError("Adduct '%s' is not supported")
return adducts[adduct]["ionmode"] == "positive"
row = adducts.loc[adducts["adduct"] == adduct].iloc[0]
return row["ionmode"] == "positive"


@functools.lru_cache
Expand Down Expand Up @@ -149,7 +152,7 @@ def valid_adduct(value: str) -> bool:
True if the value is an adduct listed supported by the matchms package
This is not a comprehensive list, so it will return False for some uncommon adducts
"""
adducts = load_adducts_dict()
adducts = load_known_adducts()
return value in adducts


Expand Down
2 changes: 1 addition & 1 deletion metatlas/tools/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class BaseNotebookParameters(BaseModel):
project_directory: Path = Path().home() / "metabolomics_data"
max_cpus: int = 4
log_level: str = "INFO"
resolve_msms_matches_by = "distance"
resolve_msms_matches_by: str = "distance"

def update(self, override_parameters: Dict) -> None:
"""update all parameters with any non-None values in override_parameters"""
Expand Down
17 changes: 6 additions & 11 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@

import nox

py_versions = ["3.8", "3.9"]
py_versions = ["3.11"]

nox.options.sessions = [
"flake8",
"black",
"pylint-3.8",
"mypy-3.8",
"unit_tests-3.8",
"pylint-3.11",
"mypy-3.11",
"unit_tests-3.11",
"flake8_nb",
"black_nb",
"pylint_nb-3.8",
"system_tests-3.8",
"pylint_nb-3.11",
"system_tests-3.11",
"update_git_hooks",
]

Expand Down Expand Up @@ -69,15 +69,10 @@
]

pytest_deps = [
"attrs==22.1.0",
"coverage==7.0.5",
"iniconfig==2.0.0",
"numpy==1.22.4",
"packaging==21.3",
"pandas==1.4.2",
"pluggy==1.0.0",
"py==1.11.0",
"pyparsing==3.0.9",
"pytest==7.2.1",
"pytest-cov==3.0.0",
"pytest-mock==3.10.0",
Expand Down
11 changes: 6 additions & 5 deletions tests/unit/test_cheminfo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# pylint: disable=missing-function-docstring, missing-module-docstring, line-too-long

from matchms.filtering.load_adducts import load_adducts_dict
from matchms.filtering.filter_utils.load_known_adducts import (
load_known_adducts)
from rdkit import Chem

from metatlas.tools import cheminfo
Expand All @@ -11,11 +12,11 @@


def test_get_parent_mass01():
adducts = load_adducts_dict()
adducts = load_known_adducts()
original_parent = 100
for name in adducts:
pre = cheminfo.get_precursor_mz(original_parent, name)
parent = cheminfo.get_parent_mass(pre, name)
for _, row in adducts.iterrows():
pre = cheminfo.get_precursor_mz(original_parent, row["adduct"])
parent = cheminfo.get_parent_mass(pre, row["adduct"])
assert abs(original_parent - parent) < 1e-7


Expand Down

0 comments on commit 4adc223

Please sign in to comment.