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

Implement variant search by HGVS expression #96

Merged
merged 1 commit into from
Jun 19, 2020
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
15 changes: 15 additions & 0 deletions civicpy/civic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1166,10 +1166,25 @@ def search_variants_by_name(name):
"""
return search_variants_by_attribute('name', name)

def search_variants_by_hgvs(hgvs):
"""
Search the cache for variants matching the queried HGVS expression

:param String name: HGVS expression to query

:return: Returns a list of variant hashes matching the HGVS expression
"""
return search_variants_by_list_field('hgvs_expressions', hgvs)

def search_variants_by_attribute(attribute, value):
variants = get_all_variants()
return [v for v in variants if getattr(v, attribute) == value]

def search_variants_by_list_field(field, value):
variants = get_all_variants()
matched_variants = []
return [v for v in variants if value in getattr(v, field)]

def search_variants_by_coordinates(coordinate_query, search_mode='any'):
"""
Search the cache for variants matching provided coordinates using the corresponding search mode.
Expand Down
5 changes: 5 additions & 0 deletions civicpy/tests/test_civic.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ def test_get_by_caid(self, v600e):
assert len(variants) == 1
assert variants[0] == v600e

def test_get_by_hgvs(self, v600e):
variants = civic.search_variants_by_hgvs("ENST00000288602.6:c.1799T>A")
assert len(variants) == 1
assert variants[0] == v600e

def test_sanitize_coordinate_bases(self):
variant1 = civic.get_variant_by_id(2696)
variant2 = civic.get_variant_by_id(558)
Expand Down