Skip to content

Commit

Permalink
improved id generation
Browse files Browse the repository at this point in the history
  • Loading branch information
pnrobinson committed Apr 29, 2024
1 parent 9f5f161 commit a459f0b
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/pyphetools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from . import visualization
from . import validation

__version__ = "0.9.80"
__version__ = "0.9.81"

__all__ = [
"creation",
Expand Down
6 changes: 5 additions & 1 deletion src/pyphetools/creation/individual.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,11 @@ def get_phenopacket_id(self, phenopacket_id=None) -> str:
ppkt_id = indi_id
else:
ppkt_id = phenopacket_id
ppkt_id = ppkt_id.replace(" ", "_")
# strip non alphanumeric characters
ppkt_id = ''.join(e if e.isalnum() else "_" for e in ppkt_id)
ppkt_id = ppkt_id.replace("__", "_")
if ppkt_id.endswith("_"):
ppkt_id = ppkt_id[:-1]
return ppkt_id

def get_citation(self) -> Citation:
Expand Down
58 changes: 58 additions & 0 deletions test/test_individual.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import hpotk
import pytest

from pyphetools.creation import Citation, Disease,Individual, HpTerm



# The API requires us to pass a column name but the column name will not be used in the tests
TEST_COLUMN = "test"


class TestIndividual:

@pytest.fixture
def ind_a(self) -> Individual:
cite = Citation(pmid="PMID:1234", title="some title")
i = Individual(individual_id="Individual A (from previous publication)", citation=cite)
i.add_hpo_term(HpTerm(hpo_id="HP:0000490", label="Deeply set eye"))
i.set_disease(disease=Disease(disease_id="OMIM:123456", disease_label="label"))
return i

@pytest.fixture
def ind_b(self) -> Individual:
cite = Citation(pmid="PMID:36446582", title="some title")
i = Individual(individual_id="Alves, 2019", citation=cite)
i.add_hpo_term(HpTerm(hpo_id="HP:0000490", label="Deeply set eye"))
i.set_disease(disease=Disease(disease_id="OMIM:123456", disease_label="label"))
return i

@pytest.fixture
def ind_c(self) -> Individual:
cite = Citation(pmid="PMID:36446582", title="some title")
i = Individual(individual_id="Low, 2016_P17 (10)", citation=cite)
i.add_hpo_term(HpTerm(hpo_id="HP:0000490", label="Deeply set eye"))
i.set_disease(disease=Disease(disease_id="OMIM:123456", disease_label="label"))
return i




def test_phenopacket_identifier(
self,
ind_a: Individual,
):
phenopacket_id = ind_a.get_phenopacket_id()
expected = "PMID_1234_Individual_A_from_previous_publication"
assert expected == phenopacket_id


def test_phenopacket_id_B(self, ind_b: Individual):
phenopacket_id = ind_b.get_phenopacket_id()
expected = "PMID_36446582_Alves_2019"
assert expected == phenopacket_id

def test_phenopacket_id_C(self, ind_c: Individual):
phenopacket_id = ind_c.get_phenopacket_id()
expected = "PMID_36446582_Low_2016_P17_10"
assert expected == phenopacket_id

0 comments on commit a459f0b

Please sign in to comment.