Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing enum str formatting and batch parsing of special cases #3

Merged
merged 3 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "geneweaver-core"
version = "0.8.0a0"
version = "0.8.0a1"
description = "The core of the Jax-Geneweaver Python library"
authors = ["Jax Computational Sciences <[email protected]>"]
readme = "README.md"
Expand Down
15 changes: 13 additions & 2 deletions src/geneweaver/core/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class GenesetScoreTypeStr(str, Enum):
CORRELATION = "correlation"
EFFECT = "effect"

def __str__(self) -> str:
"""Render as a string."""
return "-".join(part.capitalize() for part in self.name.split("_"))


class ScoreType(int, Enum):
"""Integer based Enum for the different types of geneset scores."""
Expand All @@ -31,6 +35,10 @@ class ScoreType(int, Enum):
CORRELATION = 4
EFFECT = 5

def __str__(self) -> str:
"""Render as a string."""
return "-".join(part.capitalize() for part in self.name.split("_"))


class GenesetAccess(str, Enum):
"""Enum for the different types of geneset access."""
Expand Down Expand Up @@ -72,7 +80,7 @@ class Species(int, Enum):

def __str__(self) -> str:
"""Render as a string."""
return self.name
return self.name.replace("_", " ").capitalize()


class GeneIdentifier(int, Enum):
Expand All @@ -97,6 +105,8 @@ class GeneIdentifier(int, Enum):

def __str__(self) -> str:
"""Render as a string."""
if len(self.name) > 4:
return " ".join(part.capitalize() for part in self.name.split("_"))
return self.name


Expand Down Expand Up @@ -151,4 +161,5 @@ class Microarray(int, Enum):

def __str__(self) -> str:
"""Render as a string."""
return self.name
formatted = " ".join(part.capitalize() for part in self.name.split("_"))
return f"microarray {formatted}"
4 changes: 4 additions & 0 deletions src/geneweaver/core/schema/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,15 @@ def initialize_score(cls, v) -> GenesetScoreType:
"""Initialize score type."""
if isinstance(v, GenesetScoreType):
return v
elif isinstance(v, dict):
return GenesetScoreType(**v)
return parse_score(v)

@validator("private", pre=True)
def private_to_bool(cls, v) -> bool:
"""Convert private str to bool."""
if isinstance(v, bool):
return v
return v.lower() != "public"

@validator("curation_id", pre=True)
Expand Down