Skip to content

Commit

Permalink
feat: include molecular profile segment data in molecular profile res…
Browse files Browse the repository at this point in the history
…ponse
  • Loading branch information
korikuzma committed Aug 12, 2023
1 parent 65ff07f commit 685cb7f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 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 @@ -1408,6 +1416,21 @@ def _construct_get_molecular_profile_payload():
id
}
aliases: molecularProfileAliases
parsed_name: parsedName {
type: __typename
... on MolecularProfileTextSegment {
text
}
... on Gene {
id
name
}
... on Variant {
id
name
deprecated
}
}
sources {
id
name
Expand Down Expand Up @@ -1454,6 +1477,21 @@ def _construct_get_all_molecular_profiles_payload():
id
}
aliases: molecularProfileAliases
parsed_name: parsedName {
type: __typename
... on MolecularProfileTextSegment {
text
}
... on Gene {
id
name
}
... on Variant {
id
name
deprecated
}
}
sources {
id
name
Expand Down
25 changes: 23 additions & 2 deletions civicpy/tests/test_civic.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,30 @@ def test_get_accepted_only(self):
assert len(mps) >= 1333

def test_get_by_id(self):
mp = civic.get_molecular_profile_by_id(6353)
# Complex MP
mp = civic.get_molecular_profile_by_id(4432)
assert mp.type == 'molecular_profile'
assert mp.id == 6353
mp_parsed_name = mp.parsed_name
assert len(mp_parsed_name) == 5
egfr_gene = mp_parsed_name[0]
assert egfr_gene.type == "gene"
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):

Expand Down

0 comments on commit 685cb7f

Please sign in to comment.