Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
113 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# -*- coding: utf-8 -*- | ||
import patientMatcher.utils.ensembl_rest_client as ensembl_client | ||
|
||
|
||
def liftover(build, chrom, start, end): | ||
"""Perform variant liftover using Ensembl REST API | ||
Accepts: | ||
build(str): genome build: GRCh37 or GRCh38 | ||
chrom(str): 1-22,X,Y,MT | ||
start(int): start coordinate | ||
stop(int): stop coordinate | ||
Returns | ||
mappings(list of dict): | ||
example: https://rest.ensembl.org/map/human/GRCh37/X:1000000..1000100:1/GRCh38?content-type=application/json | ||
""" | ||
assembly2 = "GRCh38" | ||
if build == "GRCh38": | ||
assembly2 = "GRCh37" | ||
|
||
client = ensembl_client.EnsemblRestApiClient() | ||
url = "/".join( | ||
[ | ||
client.server, | ||
"map/human", | ||
build, | ||
f"{chrom}:{start}..{end}", | ||
f"{assembly2}?content-type=application/json", | ||
] | ||
) | ||
result = client.send_request(url) | ||
if isinstance(result, dict): | ||
return result.get("mappings") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from patientMatcher.utils.variant import liftover | ||
|
||
|
||
def test_liftover_37_38(): | ||
"""Test variant liftover from GRCh37 to GRCh38""" | ||
|
||
# WHEN sending a liftover request with suitable coordinates in genome build 37 | ||
chromosome = "X" | ||
start = 1000000 | ||
end = 1000000 | ||
|
||
# THEN the service should return valid mappings | ||
mappings = liftover("GRCh37", chromosome, start, end) | ||
|
||
# Each mapping should have the expected output format | ||
assert isinstance(mappings, list) | ||
assert isinstance(mappings[0], dict) | ||
for item in ["assembly", "seq_region_name", "start", "end"]: | ||
assert mappings[0]["mapped"][item] | ||
|
||
# And genome assembly should be GRCh38 | ||
assert mappings[0]["mapped"]["assembly"] == "GRCh38" | ||
|
||
|
||
def test_liftover_38_37(): | ||
"""Test variant liftover from GRCh38 to GRCh37""" | ||
|
||
# WHEN sending a liftover request with suitable coordinates in genome build 38 | ||
chromosome = "X" | ||
start = 1039265 | ||
end = 1039265 | ||
|
||
# THEN the service should return valid mappings | ||
mappings = liftover("GRCh38", chromosome, start, end) | ||
|
||
# Each mapping should have the expected output format | ||
assert isinstance(mappings, list) | ||
assert isinstance(mappings[0], dict) | ||
|
||
for item in ["assembly", "seq_region_name", "start", "end"]: | ||
assert mappings[0]["mapped"][item] | ||
|
||
# And genome assembly should be GRCh37 | ||
assert mappings[0]["mapped"]["assembly"] == "GRCh37" | ||
|
||
|
||
def test_liftover_MT_variant(): | ||
"""Test liftover for a mitochondrial variant from GRCh37 to GRCh38""" | ||
|
||
# GIVEN a mitochondrial variant | ||
chromosome = "MT" | ||
start = 7278 | ||
end = 7278 | ||
|
||
# THEN the service should return valid mappings | ||
mappings = liftover("GRCh37", chromosome, start, end) | ||
|
||
# Each mapping should have the expected output format | ||
assert isinstance(mappings, list) | ||
assert isinstance(mappings[0], dict) | ||
for item in ["assembly", "seq_region_name", "start", "end"]: | ||
assert mappings[0]["mapped"][item] | ||
|
||
# And genome assembly should be GRCh38 | ||
assert mappings[0]["mapped"]["assembly"] == "GRCh38" | ||
|
||
|
||
def test_liftover_bad_request(): | ||
"""Test variant liftover with non-valid request params""" | ||
|
||
# WHEN sending a liftover request with non-standard chromosome (M instead of MT) | ||
chromosome = "M" | ||
start = 7278 | ||
end = 7278 | ||
|
||
# THEN the service should not return mappings | ||
mappings = liftover("GRCh37", chromosome, start, end) | ||
assert mappings is None |