def load_panel_app(adapter, panel_id=None, institute="cust000"): """Load PanelApp panels into scout database If no panel_id load all PanelApp panels Args: adapter(scout.adapter.MongoAdapter) panel_id(str): The panel app panel id """ base_url = "https://panelapp.genomicsengland.co.uk/WebServices/{0}/" hgnc_map = adapter.genes_by_alias() panel_ids = [panel_id] if not panel_id: LOG.info("Fetching all panel app panels") json_lines = fetch_resource(base_url.format("list_panels"), json=True) panel_ids = [ panel_info["Panel_Id"] for panel_info in json_lines["result"] ] for _panel_id in panel_ids: json_lines = fetch_resource(base_url.format("get_panel") + _panel_id, json=True) parsed_panel = parse_panel_app_panel(panel_info=json_lines["result"], hgnc_map=hgnc_map, institute=institute) parsed_panel["panel_id"] = _panel_id if len(parsed_panel["genes"]) == 0: LOG.warning("Panel %s is missing genes. Skipping.", parsed_panel["display_name"]) continue try: adapter.load_panel(parsed_panel=parsed_panel) except Exception as err: raise err
def test_fetch_resource(): """Test fetch resource""" # GIVEN an URL url = "http://www.github.com" content = "Some things\n That are not so\ninteresting" responses.add( responses.GET, url, body=content, status=200, ) # WHEN fetching the resource data = scout_requests.fetch_resource(url) # THEN assert that a list of lines are returned assert isinstance(data, list)
def test_fetch_resource_json(): """Test fetch resource""" # GIVEN an URL url = "http://www.github.com" content = [{"first": "second"}] responses.add( responses.GET, url, json=content, status=200, ) # WHEN fetching the resource data = scout_requests.fetch_resource(url, json=True) # THEN assert that a list of lines are returned assert isinstance(data, list) assert data[0]["first"] == "second"
def test_fetch_resource_gzipped(variant_clinical_file): """Test fetch resource""" # GIVEN an URL url = "http://www.github.com/things.txt.gz" with open(variant_clinical_file, "rb") as zipped_file: content = zipped_file.read() responses.add( responses.GET, url, body=content, status=200, ) # WHEN fetching the resource data = scout_requests.fetch_resource(url) # THEN assert that a list of lines are returned assert isinstance(data, list) # THEN assert that the vcf header is there assert "##fileformat" in data[0]