Skip to content

Commit

Permalink
Merge branch 'main' into melter_interact
Browse files Browse the repository at this point in the history
  • Loading branch information
northwestwitch committed Dec 10, 2021
2 parents 2f629fa + cdc3cef commit b233b7f
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 37 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ About changelog [here](https://keepachangelog.com/en/1.0.0/)
- Add a toggle for melter rerun monitoring of cases
- Add an option to export cases with rerun monitoring enabled
### Changed
- Start Scout also when loqusdbapi is not reachable
### Fixed
- Gene panel crashing on edit action

Expand Down
15 changes: 10 additions & 5 deletions scout/server/blueprints/variant/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from base64 import b64encode
from datetime import date

from flask import url_for
from flask import flash, url_for
from flask_login import current_user

from scout.constants import (
Expand Down Expand Up @@ -401,6 +401,15 @@ def observations(store, loqusdb, case_obj, variant_obj):
Returns:
obs_data(dict)
"""
institute_id = variant_obj["institute"]
institute_obj = store.institute(institute_id)
loqusdb_id = institute_obj.get("loqusdb_id") or "default"
if loqusdb.loqusdb_settings[loqusdb_id]["version"] is None:
flash("Could not connect to the preselected loqusdb instance", "danger")
return {
"total": "N/A",
}

chrom = variant_obj["chromosome"]
end_chrom = variant_obj.get("end_chrom", chrom)
pos = variant_obj["position"]
Expand All @@ -426,10 +435,6 @@ def observations(store, loqusdb, case_obj, variant_obj):
"variant_type": variant_obj.get("sub_category", "").upper(),
"category": category,
}

institute_id = variant_obj["institute"]
institute_obj = store.institute(institute_id)
loqusdb_id = institute_obj.get("loqusdb_id") or "default"
obs_data = loqusdb.get_variant(variant_query, loqusdb_id=loqusdb_id)

if not obs_data:
Expand Down
1 change: 1 addition & 0 deletions scout/server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
# "default" : {"binary_path": "/miniconda3/envs/loqus2.5/bin/loqusdb", "config_path": "/home/user/settings/loqus_default.yaml"},
# "loqus_api" : {"api_url": "http://127.0.0.1:9000"},
# }

#
# Cloud IGV tracks can be configured here to allow users to enable them on their IGV views.
# CLOUD_IGV_TRACKS = [
Expand Down
16 changes: 9 additions & 7 deletions scout/server/extensions/loqus_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,18 @@ def init_app(self, app):
setting["version"] = "2.5"
else:
setting["version"] = self.get_instance_version(setting)
self.version_check(setting)

self.loqus_ids = self.loqusdb_settings.keys()
LOG.debug(f"LoqusDB setup: {self.__repr__()}")
try:
self.version_check(setting)
except EnvironmentError as env_ex:
LOG.warning(env_ex)
self.loqus_ids = self.loqusdb_settings.keys()
LOG.debug(f"LoqusDB setup: {self.__repr__()}")

def version_check(self, loqusdb_settings):
"""Check if a compatible version is used otherwise raise an error"""
if loqusdb_settings["version"] is None:
raise EnvironmentError("LoqusDB instance not available")

if not loqusdb_settings["version"] >= "2.5":
LOG.info("Please update your loqusdb version to >=2.5")
raise EnvironmentError("Only compatible with loqusdb version >= 2.5")
Expand Down Expand Up @@ -127,9 +132,6 @@ def get_api_loqus_version(api_url):
return None
json_resp = api_get("".join([api_url, "/"]))
version = json_resp.get("content", {}).get("loqusdb_version")
if version is None:
raise ConfigError(f"LoqusDB API url '{api_url}' did not return a valid response.")

return version

def get_exec_loqus_version(self, loqusdb_id=None):
Expand Down
8 changes: 8 additions & 0 deletions tests/server/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ class LoqusdbMock:
def __init__(self):
self.nr_cases = 130
self.variants = {"1_169898014_T_C": {"families": ["vitalmouse"]}}
self.loqusdb_settings = {
"default": {
"api_url": "http://127.0.0.1:9000",
"instance_type": "api",
"id": "default",
"version": "2.5",
}
}

def case_count(self):
return self.nr_cases
Expand Down
5 changes: 2 additions & 3 deletions tests/server/extensions/test_loqusdb_api_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ def test_get_api_loqus_version_no_connection(loqus_api_app):
"""Test function that returns the version of the LoqusDB API when the API is not available"""

# When the get_api_loqus_version function is invoked for a non-reachable API
# THEN it should raise ConfigError
# THEN it should set the loqus version to None
with loqus_api_app.app_context():
with pytest.raises(ConfigError):
assert loqusdb.get_api_loqus_version(api_url="test_url")
assert loqusdb.get_api_loqus_version(api_url="test_url") == None


def test_get_api_loqus_version(loqus_api_app, monkeypatch):
Expand Down
22 changes: 0 additions & 22 deletions tests/server/extensions/test_loqusdb_exe_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,28 +183,6 @@ def mockcommand(*args):
assert 0 == loqusdb.case_count(variant_category="snv")


def test_loqusdb_exe_wrong_version(monkeypatch, loqus_exe, loqus_config):
"""Test creating a loqus extension when loqusDB version is too old."""

# Given a mocked loqus exe instance returning a loqus version older than 2.5
def mockcommand(*args):
return "2.4"

monkeypatch.setattr(loqus_extension, "execute_command", mockcommand)

# WHEN instantiating an adapter
with pytest.raises(EnvironmentError):
# Then the app should not be created because of EnvironmentError
app = create_app(
config=dict(
LOQUSDB_SETTINGS={
"binary_path": loqus_exe,
"loqusdb_config": loqus_config,
}
)
)


def test_init_app_loqus_list(monkeypatch, loqus_exe, loqus_config):
"""Test creating a Loqus extension from a list of config params"""

Expand Down

0 comments on commit b233b7f

Please sign in to comment.