Skip to content

Commit

Permalink
Merge pull request #144 from griffithlab/issue-143
Browse files Browse the repository at this point in the history
feat: include molecular profile segment data in molecular profile response
  • Loading branch information
susannasiebert authored Apr 19, 2024
2 parents 3798e68 + 5095471 commit 96cfffe
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
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

0 comments on commit 96cfffe

Please sign in to comment.