-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
65026f8
commit 1cc586f
Showing
8 changed files
with
153 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
from . import validation | ||
|
||
|
||
__version__ = "0.9.92" | ||
__version__ = "0.9.93" | ||
|
||
|
||
__all__ = [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from enum import Enum | ||
from .hp_term import HpTerm | ||
|
||
class Moi(Enum): | ||
AD="Autosomal dominant inheritance" | ||
AR="Autosomal recessive inheritance" | ||
XLI="X-linked inheritance" | ||
XLR="X-linked recessive inheritance" | ||
XLD="X-linked dominant inheritance" | ||
MITO="Mitochondrial inheritance" | ||
YLI="Y-linked inheritance" | ||
|
||
|
||
def to_HPO(self): | ||
if self == Moi.AD: | ||
return HpTerm(hpo_id="HP:0000006", label="Autosomal dominant inheritance") | ||
elif self == Moi.AR: | ||
return HpTerm(hpo_id="HP:0000007", label="Autosomal recessive inheritance") | ||
elif self == Moi.XLI: | ||
return HpTerm(hpo_id="HP:0001417", label="X-linked inheritance") | ||
elif self == Moi.XLR: | ||
return HpTerm(hpo_id="HP:0001419", label="X-linked recessive inheritance") | ||
elif self == Moi.XLD: | ||
return HpTerm(hpo_id="HP:0001423", label="X-linked dominant inheritance") | ||
elif self == Moi.MITO: | ||
return HpTerm(hpo_id="HP:0001427", label="Mitochondrial inheritance") | ||
elif self == Moi.YLI: | ||
return HpTerm(hpo_id="HP:0001450", label="Y-linked inheritance") | ||
|
||
else: | ||
raise ValueError(f"Unrecognized Moi enum (should never happen)") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,54 @@ | ||
import unittest | ||
import pytest | ||
|
||
from pyphetools.creation import AgeIsoFormater | ||
|
||
|
||
class TestAgeIsoFormater: | ||
|
||
@pytest.mark.parametrize( | ||
'year, month, day, iso', | ||
[ | ||
( 2, 3, 5, "P2Y3M5D"), | ||
( 29, 5, 25, "P29Y5M25D"), | ||
( 99,1,24,"P99Y1M24D"), | ||
] | ||
) | ||
def test_ymd( | ||
self, | ||
year: int, | ||
month: int, | ||
day: int, | ||
iso:str, | ||
): | ||
iso_age = AgeIsoFormater.to_string(y=year, m=month, d=day) | ||
assert iso == iso_age | ||
|
||
@pytest.mark.parametrize( | ||
'month, iso', | ||
[ | ||
( 5, "P5M"), | ||
( 0.5,"P15D"), | ||
(0.8, "P24D"), | ||
(11, "P11M"), | ||
(12, "P1Y"), | ||
(16, "P1Y4M"), | ||
("n.a.", "NOT_PROVIDED"), | ||
(None, "NOT_PROVIDED"), | ||
(float("nan"), "NOT_PROVIDED"), | ||
(0, "P0D") | ||
] | ||
) | ||
def test_numerical_month( | ||
self, | ||
month: float, | ||
iso: str | ||
): | ||
iso_age = AgeIsoFormater.from_numerical_month(month=month) | ||
assert iso == iso_age | ||
|
||
|
||
|
||
class TestAgeIsoFormater(unittest.TestCase): | ||
|
||
def test_basic1(self): | ||
iso_age = AgeIsoFormater.to_string(y=2, m=3, d=5) | ||
self.assertEqual("P2Y3M5D", iso_age) | ||
|
||
def test_basic2(self): | ||
""" | ||
test that 13 months are normalized to 1 year 1 month | ||
""" | ||
iso_age = AgeIsoFormater.to_string(y=42, m=13, d=5) | ||
self.assertEqual("P43Y1M5D", iso_age) | ||
|
||
def test_5m(self): | ||
iso_age = AgeIsoFormater.from_numerical_month(5) | ||
self.assertEqual("P5M", iso_age) | ||
|
||
def test_15d(self): | ||
iso_age = AgeIsoFormater.from_numerical_month(0.5) | ||
self.assertEqual("P15D", iso_age) | ||
|
||
def test_24d(self): | ||
iso_age = AgeIsoFormater.from_numerical_month(0.8) | ||
self.assertEqual("P24D", iso_age) | ||
|
||
def test_12m(self): | ||
iso_age = AgeIsoFormater.from_numerical_month(12) | ||
self.assertEqual("P1Y", iso_age) | ||
|
||
def test_16m(self): | ||
iso_age = AgeIsoFormater.from_numerical_month(16) | ||
self.assertEqual("P1Y4M", iso_age) | ||
|
||
def test_na(self): | ||
""" | ||
Test we return NOT_PROVIDED (from the Contants class) if we cannot parse the cell contents | ||
""" | ||
iso_age = AgeIsoFormater.from_numerical_month("n.a.") | ||
self.assertEqual("NOT_PROVIDED", iso_age) | ||
|
||
def test_none(self): | ||
""" | ||
Test we return NOT_PROVIDED (from the Contants class) if we cannot parse the cell contents | ||
""" | ||
iso_age = AgeIsoFormater.from_numerical_month(None) | ||
self.assertEqual("NOT_PROVIDED", iso_age) | ||
|
||
def test_nan(self): | ||
""" | ||
Test we return NOT_PROVIDED (from the Contants class) if we cannot parse the cell contents | ||
""" | ||
iso_age = AgeIsoFormater.from_numerical_month(float("nan")) | ||
self.assertEqual("NOT_PROVIDED", iso_age) | ||
|
||
def test_newborn(self): | ||
iso_age = AgeIsoFormater.from_numerical_month(0) | ||
self.assertEqual("P0D", iso_age) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import pytest | ||
|
||
from pyphetools.creation import Moi | ||
|
||
|
||
class TestMoi: | ||
|
||
@pytest.mark.parametrize( | ||
'moi, hpterm_id, hpterm_label', | ||
[ | ||
( | ||
Moi.AD, | ||
'HP:0000006', | ||
'Autosomal dominant inheritance', | ||
), | ||
( | ||
Moi.AR, | ||
'HP:0000007', | ||
'Autosomal recessive inheritance', | ||
), | ||
( | ||
Moi.XLI, | ||
'HP:0001417', | ||
'X-linked inheritance' | ||
), | ||
( | ||
Moi.XLR, | ||
'HP:0001419', | ||
'X-linked recessive inheritance' | ||
), | ||
( | ||
Moi.XLD, | ||
'HP:0001423', | ||
'X-linked dominant inheritance' | ||
), | ||
( | ||
Moi.MITO, | ||
'HP:0001427', | ||
'Mitochondrial inheritance' | ||
), | ||
( | ||
Moi.YLI, | ||
'HP:0001450', | ||
'Y-linked inheritance' | ||
) | ||
] | ||
) | ||
def test_moi( | ||
self, | ||
moi: Moi, | ||
hpterm_id: str, | ||
hpterm_label: str, | ||
): | ||
hpterm = moi.to_HPO() | ||
|
||
assert hpterm_id == hpterm.id | ||
assert hpterm_label == hpterm.label | ||
|