diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..f71cab0 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,4 @@ +[*] +max_line_length = 120 +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..fed4715 --- /dev/null +++ b/.flake8 @@ -0,0 +1,15 @@ +[flake8] +max-line-length = 120 + +# F405 - ignore error if class is imported in `*` import. +# W293 - blank line contains whitespace +# W503 - line break before binary operator +ignore = F405,W293,W503 + +exclude = + .git, + __pycache__, + docs/conf.py, + build, + dist, + venv, diff --git a/recipe/meta.yaml b/recipe/meta.yaml index 7d42c9d..de0df42 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -1,5 +1,5 @@ {% set name = "hpo-toolkit" %} -{% set version = "0.5.2" %} +{% set version = "0.5.3" %} package: name: {{ name|lower }} diff --git a/src/hpotk/__init__.py b/src/hpotk/__init__.py index 8b5c48c..aac1ebe 100644 --- a/src/hpotk/__init__.py +++ b/src/hpotk/__init__.py @@ -2,17 +2,7 @@ HPO toolkit is a library for working with Human Phenotype Ontology and the HPO annotation data. """ -__version__ = '0.5.2' - -from . import algorithm -from . import annotations -from . import constants -from . import graph -from . import model -from . import ontology -from . import store -from . import util -from . import validate +__version__ = "0.5.3" from .graph import OntologyGraph, GraphAware from .model import TermId, Term, MinimalTerm, Synonym, SynonymType, SynonymCategory @@ -20,3 +10,10 @@ from .ontology.load.obographs import load_minimal_ontology, load_ontology from .store import OntologyType, OntologyStore, configure_ontology_store + +__all__ = [ + "TermId", "MinimalTerm", "Term", + "OntologyGraph", "GraphAware", + "MinimalOntology", "Ontology", + "OntologyStore", "OntologyType", "configure_ontology_store", +] diff --git a/src/hpotk/ontology/load/obographs/_load.py b/src/hpotk/ontology/load/obographs/_load.py index 5789b10..ead05d2 100644 --- a/src/hpotk/ontology/load/obographs/_load.py +++ b/src/hpotk/ontology/load/obographs/_load.py @@ -15,10 +15,11 @@ logger = logging.getLogger(__name__) -# TODO - verify PURL works for other ontologies than HPO +# TODO: verify PURL works for other ontologies than HPO +# TODO: thoroughly test the PURL pattern # A pattern to match an obolibrary PURL. The PURL should is expected to have 3 parts: `prefix`, `id`, and `curie` # The `curie` is `prefix` + '_' + `id`. -PURL_PATTERN = re.compile(r'http://purl\.obolibrary\.org/obo/(?P(?P\w+)_(?P\d{7}))') +PURL_PATTERN = re.compile(r'http://purl\.obolibrary\.org/obo/(?P(?P\w+)_(?P\w+))') DATE_PATTERN = re.compile(r'.*/(?P\d{4}-\d{2}-\d{2})/.*') diff --git a/tests/test_term_id.py b/tests/test_term_id.py index e25f742..f03352f 100644 --- a/tests/test_term_id.py +++ b/tests/test_term_id.py @@ -1,13 +1,16 @@ import pytest -from hpotk.model import * +from hpotk.model import TermId class TestTermId: - @pytest.mark.parametrize('curie', - ("HP:1234567", "HP_1234567") - ) + @pytest.mark.parametrize( + 'curie', + ( + "HP:1234567", + "HP_1234567", + )) def test_from_curie(self, curie): term_id = TermId.from_curie(curie) assert term_id.value == "HP:1234567" @@ -17,22 +20,26 @@ def test_from_curie__unusual_input(self): assert term_id.prefix == 'SNOMEDCT_US' assert term_id.id == '313307000' - @pytest.mark.parametrize('curie, message', - (("HP1234567", "The CURIE HP1234567 has no colon `:` or underscore `_`"), - (None, "Curie must not be None")) - ) + @pytest.mark.parametrize( + 'curie, message', + [ + ("HP1234567", "The CURIE HP1234567 has no colon `:` or underscore `_`"), + (None, "Curie must not be None") + ] + ) def test_from_curie__failures(self, curie, message): with pytest.raises(ValueError) as cm: TermId.from_curie(curie) assert message == cm.value.args[0] - @pytest.mark.parametrize('curie, prefix, id', - ( - ["HP:1234567", "HP", "1234567"], - ["HP_1234567", "HP", "1234567"] - ) - ) + @pytest.mark.parametrize( + 'curie, prefix, id', + ( + ["HP:1234567", "HP", "1234567"], + ["HP_1234567", "HP", "1234567"] + ) + ) def test_properties(self, curie, prefix, id): term_id = TermId.from_curie(curie) @@ -40,30 +47,48 @@ def test_properties(self, curie, prefix, id): assert id == term_id.id assert f'{prefix}:{id}' == term_id.value - @pytest.mark.parametrize('left, right', - (["HP:1234567", "HP:1234567"], - ["HP:1234567", "HP_1234567"], - ["HP_1234567", "HP:1234567"], - ["HP_1234567", "HP_1234567"],) - ) + @pytest.mark.parametrize( + 'left, right', + ( + ["HP:1234567", "HP:1234567"], + ["HP:1234567", "HP_1234567"], + ["HP_1234567", "HP:1234567"], + ["HP_1234567", "HP_1234567"], + ) + ) def test_equality(self, left, right): left = TermId.from_curie(left) right = TermId.from_curie(right) assert left == right - @pytest.mark.parametrize('left, right, is_gt, is_eq, is_lt', - ( - # First compare by prefix - ["AA:0000000", "BB:0000000", False, False, True], - ["BB:0000000", "BB:0000000", False, True, False], - ["CC:0000000", "BB:0000000", True, False, False], - # Then by value - ["HP:0000001", "HP:0000002", False, False, True], - ["HP:0000002", "HP:0000002", False, True, False], - ["HP:0000003", "HP:0000002", True, False, False], - ) - ) + @pytest.mark.parametrize( + 'left, right', + ( + ["HP:1234567", "HP:1234567"], + ["HP:1234567", "HP_1234567"], + ["HP_1234567", "HP:1234567"], + ["HP_1234567", "HP_1234567"], + )) + def test_hash(self, left: str, right: str): + left = TermId.from_curie(left) + right = TermId.from_curie(right) + + assert hash(left) == hash(right) + + @pytest.mark.parametrize( + 'left, right, is_gt, is_eq, is_lt', + ( + # First compare by prefix + ["AA:0000000", "BB:0000000", False, False, True], + ["BB:0000000", "BB:0000000", False, True, False], + ["CC:0000000", "BB:0000000", True, False, False], + # Then by value + ["HP:0000001", "HP:0000002", False, False, True], + ["HP:0000002", "HP:0000002", False, True, False], + ["HP:0000003", "HP:0000002", True, False, False], + ) + ) def test_comparison(self, left, right, is_gt, is_eq, is_lt): left = TermId.from_curie(left) right = TermId.from_curie(right)