Skip to content

Commit

Permalink
Merge 5b88870 into d3f1fc3
Browse files Browse the repository at this point in the history
  • Loading branch information
northwestwitch committed Dec 29, 2020
2 parents d3f1fc3 + 5b88870 commit 5435ea0
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 6 deletions.
7 changes: 1 addition & 6 deletions docker-compose.yml
Expand Up @@ -26,9 +26,6 @@ services:

pmatcher-cli:
container_name: pmatcher-cli
build:
context: .
dockerfile: Dockerfile
image: clinicalgenomics/patientmatcher
environment:
MONGODB_HOST: mongodb
Expand All @@ -41,9 +38,7 @@ services:

pmatcher-web:
container_name: pmatcher-web
build:
context: .
dockerfile: Dockerfile
image: clinicalgenomics/patientmatcher
environment:
MONGODB_HOST: mongodb
PMATCHER_CONFIG: '/home/worker/app/patientMatcher/patientMatcher/instance/config.py'
Expand Down
34 changes: 34 additions & 0 deletions patientMatcher/utils/variant.py
@@ -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")
78 changes: 78 additions & 0 deletions tests/utils/test_variant.py
@@ -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

0 comments on commit 5435ea0

Please sign in to comment.