Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: include molecular profile segment data in molecular profile response #144

Merged
merged 2 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions civicpy/civic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Binary file modified civicpy/data/test_cache.pkl
Binary file not shown.
24 changes: 24 additions & 0 deletions civicpy/tests/test_civic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading