diff --git a/civicpy/civic.py b/civicpy/civic.py index 721bc44..3d6d1db 100644 --- a/civicpy/civic.py +++ b/civicpy/civic.py @@ -446,12 +446,20 @@ class MolecularProfile(CivicRecord): 'evidence_items', 'sources', 'variants', + 'parsed_name' }) def __init__(self, **kwargs): self._evidence_items = [] self._assertions = [] self._variants = [] + + # Convert parsed name types from camel to snake case + parsed_name = kwargs.get('parsed_name') + if parsed_name: + for pn in parsed_name: + pn['type'] = ''.join(['_' + c.lower() if c.isupper() else c for c in pn['type']]).lstrip('_') + super().__init__(**kwargs) @property @@ -1413,6 +1421,21 @@ def _construct_get_molecular_profile_payload(): id } aliases: molecularProfileAliases + parsed_name: parsedName { + type: __typename + ... on MolecularProfileTextSegment { + text + } + ... on Feature { + id + name + } + ... on Variant { + id + name + deprecated + } + } sources { id name @@ -1459,6 +1482,21 @@ def _construct_get_all_molecular_profiles_payload(): id } aliases: molecularProfileAliases + parsed_name: parsedName { + type: __typename + ... on MolecularProfileTextSegment { + text + } + ... on Feature { + id + name + } + ... on Variant { + id + name + deprecated + } + } sources { id name diff --git a/civicpy/data/test_cache.pkl b/civicpy/data/test_cache.pkl index b109178..2cfd692 100644 Binary files a/civicpy/data/test_cache.pkl and b/civicpy/data/test_cache.pkl differ diff --git a/civicpy/tests/test_civic.py b/civicpy/tests/test_civic.py index 716d2d3..d43d34f 100644 --- a/civicpy/tests/test_civic.py +++ b/civicpy/tests/test_civic.py @@ -177,6 +177,30 @@ def test_get_by_id(self): assert mp.type == 'molecular_profile' assert mp.id == 12 + def test_get_by_id_complex_mp(self): + mp = civic.get_molecular_profile_by_id(4432) + assert mp.type == 'molecular_profile' + mp_parsed_name = mp.parsed_name + assert len(mp_parsed_name) == 5 + egfr_gene = mp_parsed_name[0] + assert egfr_gene.type == "feature" + assert egfr_gene.id == 19 + assert egfr_gene.name == "EGFR" + variant0 = mp_parsed_name[1] + assert variant0.type == "variant" + assert variant0.id == 33 + assert variant0.name == "L858R" + assert variant0.deprecated is False + text_segment = mp_parsed_name[2] + assert text_segment.type == "molecular_profile_text_segment" + assert text_segment.text == "OR" + assert mp_parsed_name[3] == egfr_gene + variant1 = mp_parsed_name[4] + assert variant1.type == "variant" + assert variant1.id == 133 + assert variant1.name == "Exon 19 Deletion" + assert variant1.deprecated is False + class TestVariantGroups(object): def test_get_all(self):