Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pnrobinson committed Jan 18, 2025
1 parent 4b90a1a commit 1cc5f8a
Show file tree
Hide file tree
Showing 14 changed files with 15 additions and 962 deletions.
2 changes: 1 addition & 1 deletion src/pyphetools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from . import validation


__version__ = "0.9.115"
__version__ = "0.9.116"


__all__ = [
Expand Down
2 changes: 0 additions & 2 deletions src/pyphetools/creation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@
from .metadata import MetaData
from .mode_of_inheritance import Moi
from .ontology_terms import OntologyTerms
from .option_column_mapper import OptionColumnMapper
from .intergenic_variant import IntergenicVariant
from .pyphetools_age import PyPheToolsAge, AgeSorter, HPO_ONSET_TERMS
from .sex_column_mapper import SexColumnMapper
from .simple_column_mapper import SimpleColumnMapper
from .scm_generator import SimpleColumnMapperGenerator
from .structural_variant import StructuralVariant
from .thresholded_column_mapper import ThresholdedColumnMapper
from .thresholder import Thresholder
Expand Down
22 changes: 1 addition & 21 deletions src/pyphetools/creation/hpo_base_cr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import abc
from collections import defaultdict

from .column_mapper import ColumnMapper
from .hp_term import HpTerm
from .hpo_cr import HpoConceptRecognizer
from .simple_column_mapper import SimpleColumnMapper


class ConceptMatch:
Expand Down Expand Up @@ -165,7 +163,7 @@ def parse_cell_for_exact_matches(self, cell_text, custom_d) -> typing.List[HpTer
results.extend(self._get_non_overlapping_matches(hits=hits))
return

def _get_non_overlapping_matches(self, hits: [typing.List[ConceptMatch]]) -> typing.List[HpTerm]:
def _get_non_overlapping_matches(self, hits: typing.List[ConceptMatch]) -> typing.List[HpTerm]:
"""The prupose of this method is to choose a list of non-overlapping matches
Sometimes, we get multiple matches that partially overlap. We will greedily take the longest matches and discard overlaps.
Expand Down Expand Up @@ -225,21 +223,3 @@ def contains_term_label(self, hpo_label) -> bool:
"""
return hpo_label.lower() in self._label_to_id

def initialize_simple_column_maps(self, column_name_to_hpo_label_map, observed, excluded):
if observed is None or excluded is None:
raise ValueError("Symbols for observed (e.g., +, Y, yes) and excluded (e.g., -, N, no) required")
if not isinstance(column_name_to_hpo_label_map, dict):
raise ValueError("column_name_to_hpo_label_map must be a dict with column to HPO label mappings")
simple_mapper_d = defaultdict(ColumnMapper)
for column_name, hpo_label_and_id in column_name_to_hpo_label_map.items():
if not isinstance(hpo_label_and_id, list):
raise ValueError(f"Expected {hpo_label_and_id} to be a two-item list with HPO label and id")
hpo_label = hpo_label_and_id[0]
expected_id = hpo_label_and_id[1]
hp_term = self.get_term_from_label(hpo_label)
if hp_term.id != expected_id:
raise ValueError(f"Got {hp_term.id} but was expecting {expected_id} for {hpo_label}")
mpr = SimpleColumnMapper(column_name=column_name, hpo_id=hp_term.id, hpo_label=hp_term.label,
observed=observed, excluded=excluded)
simple_mapper_d[column_name] = mpr
return simple_mapper_d
7 changes: 0 additions & 7 deletions src/pyphetools/creation/hpo_cr.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,3 @@ def get_term_from_label(self, label) -> HpTerm:
:rtype: HpTerm
"""
pass

@abc.abstractmethod
def initialize_simple_column_maps(self, column_name_to_hpo_label_map, observed, excluded, non_measured=None):
"""
Create a dictionary of SimpleColumnMappers
"""
pass
173 changes: 0 additions & 173 deletions src/pyphetools/creation/option_column_mapper.py

This file was deleted.

7 changes: 5 additions & 2 deletions src/pyphetools/creation/pyphetools_age.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
DAYS_IN_WEEK = 7
AVERAGE_DAYS_IN_MONTH = 30.437
AVERAGE_DAYS_IN_YEAR = 365.25

ISO8601_REGEX = r"^P(\d+Y)?(\d+M)?(\d+D)?"

from ..pp.v202 import OntologyClass as OntologyClass202
from ..pp.v202 import TimeElement as TimeElement202
Expand Down Expand Up @@ -255,7 +255,10 @@ def get_age_pp201(age_string: str) -> typing.Optional[TimeElement202]:
if isinstance(age_string, float) and math.isnan(age_string):
return None # sometimes pandas returns an empty cell as a float NaN
if age_string.startswith("P"):
return TimeElement202(Age202(age_string))
if re.fullmatch(ISO8601_REGEX, age_string):
return TimeElement202(Age202(age_string))
else:
raise ValueError(f"Invalid ISO8601 expression: '{age_string}'")
elif age_string in HPO_ONSET_TERMS:
hpo_id = HPO_ONSET_TERMS.get(age_string)
onsetClz = OntologyClass202(id=hpo_id, label=age_string)
Expand Down
Loading

0 comments on commit 1cc5f8a

Please sign in to comment.