diff --git a/pyproject.toml b/pyproject.toml index 6f6f2df..90f8fe0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "geneweaver-core" -version = "0.10.0a0" +version = "0.10.0a1" description = "The core of the Jax-Geneweaver Python library" authors = ["Jax Computational Sciences "] readme = "README.md" diff --git a/src/geneweaver/core/schema/score.py b/src/geneweaver/core/schema/score.py index 804b210..d2e1daa 100644 --- a/src/geneweaver/core/schema/score.py +++ b/src/geneweaver/core/schema/score.py @@ -1,17 +1,19 @@ """Pydantic schema for defining score types.""" +# ruff: noqa: N805 + from typing import Optional from geneweaver.core.enum import ScoreType -from pydantic import BaseModel +from pydantic import BaseModel, validator class GenesetScoreType(BaseModel): """Pydantic schema for defining score types.""" score_type: ScoreType - threshold_low: Optional[float] = None threshold: float = 0.05 + threshold_low: Optional[float] = None def __str__(self: "GenesetScoreType") -> str: """Return a string representation of the score type.""" @@ -26,3 +28,27 @@ def threshold_as_db_string(self) -> str: return f"{self.threshold_low},{self.threshold}" else: return str(self.threshold) + + @validator("threshold_low") + def threshold_low_must_be_less_than_threshold( + cls, v: Optional[float], values: dict + ) -> Optional[float]: + """Threshold low must be less than threshold.""" + if v is not None and v > values.get("threshold"): + raise ValueError("threshold_low must be less than threshold") + return v + + @validator("threshold_low") + def threshold_low_correlation_and_effect_only( + cls, v: Optional[float], values: dict + ) -> Optional[float]: + """Threshold low should only be set for correlation and effect score types.""" + if v is not None and values.get("score_type") not in [ + ScoreType.CORRELATION, + ScoreType.EFFECT, + ]: + raise ValueError( + "threshold_low should only be set for " + "correlation and effect score types" + ) + return v