def test_parse_panel_info_lines(): ## GIVEN a panel with some info panel_lines = [ '##panel_id=panel1', '##institute=cust000', '##version=1.0', '##date=2016-12-09', '##display_name=Test panel', '#hgnc_id\thgnc_symbol', '7481\tMT-TF' ] ## WHEN parsing the information panel_info = get_panel_info(panel_lines) ## THEN assert that no information except a date is returned for key in panel_info: if key == 'panel_id': assert panel_info[key] == 'panel1' elif key == 'institute': assert panel_info[key] == 'cust000' elif key == 'version': assert panel_info[key] == '1.0' elif key == 'display_name': assert panel_info[key] == 'Test panel' elif key == 'date': assert type(panel_info[key]) is type(datetime.datetime.now())
def test_parse_panel_info_lines(): ## GIVEN a panel with some info panel_lines = [ "##panel_id=panel1", "##institute=cust000", "##version=1.0", "##date=2016-12-09", "##display_name=Test panel", "#hgnc_id\thgnc_symbol", "7481\tMT-TF", ] ## WHEN parsing the information panel_info = get_panel_info(panel_lines) ## THEN assert that no information except a date is returned for key in panel_info: if key == "panel_id": assert panel_info[key] == "panel1" elif key == "institute": assert panel_info[key] == "cust000" elif key == "version": assert panel_info[key] == "1.0" elif key == "display_name": assert panel_info[key] == "Test panel" elif key == "date": assert type(panel_info[key]) is type(datetime.datetime.now())
def test_parse_panel_info_no_info(): ## GIVEN no information at all panel_lines = [] ## WHEN parsing the information panel_info = get_panel_info(panel_lines) ## THEN assert that no information except a date is returned for key in panel_info: if key != "date": assert panel_info[key] is None else: assert type(panel_info[key]) is type(datetime.datetime.now())
def test_parse_panel_info_no_info(): ## GIVEN no information at all panel_lines = [] ## WHEN parsing the information panel_info = get_panel_info(panel_lines) ## THEN assert that no information except a date is returned for key in panel_info: if key != 'date': assert panel_info[key] == None else: assert type(panel_info[key]) is type(datetime.datetime.now())
def test_parse_panel_file(panel_handle): ## GIVEN a panel with some info panel_lines = panel_handle ## WHEN parsing the information panel_info = get_panel_info(panel_lines) ## THEN assert that no information except a date is returned for key in panel_info: if key == "panel_id": assert panel_info[key] == "panel1" elif key == "institute": assert panel_info[key] == "cust000" elif key == "version": assert panel_info[key] == "1.0" elif key == "display_name": assert panel_info[key] == "Test panel" elif key == "date": assert type(panel_info[key]) is type(datetime.datetime.now())
def test_parse_panel_file(panel_handle): ## GIVEN a panel with some info panel_lines = panel_handle ## WHEN parsing the information panel_info = get_panel_info(panel_lines) ## THEN assert that no information except a date is returned for key in panel_info: if key == 'panel_id': assert panel_info[key] == 'panel1' elif key == 'institute': assert panel_info[key] == 'cust000' elif key == 'version': assert panel_info[key] == '1.0' elif key == 'display_name': assert panel_info[key] == 'Test panel' elif key == 'date': assert type(panel_info[key]) is type(datetime.datetime.now())
def panel(context, date, display_name, version, panel_type, panel_id, path, institute, omim, api_key): """Add a gene panel to the database.""" adapter = context.obj['adapter'] if not path: if not omim: LOG.warning("Please provide a gene panel file or specify omim") context.abort() if omim: api_key = api_key or context.obj.get('omim_api_key') if not api_key: LOG.warning("Please provide a omim api key to load the omim gene panel") context.abort() #Check if OMIM-AUTO exists if adapter.gene_panel(panel_id='OMIM-AUTO'): LOG.warning("OMIM-AUTO already exists in database") LOG.info("To create a new version use scout update omim") return try: adapter.load_omim_panel(api_key, version=1.0) except Exception as err: LOG.error(err) context.abort() return panel_lines = get_file_handle(path) try: panel_info = get_panel_info( panel_lines=panel_lines, panel_id=panel_id, institute=institute, version=version, date=date, display_name=display_name ) except Exception as err: LOG.warning(err) context.abort() version = None if panel_info.get('version'): version = float(panel_info['version']) panel_id = panel_info['panel_id'] display_name = panel_info['display_name'] or panel_id institute = panel_info['institute'] date = panel_info['date'] if not institute: LOG.warning("A Panel has to belong to a institute") context.abort() #Check if institute exists in database if not adapter.institute(institute): LOG.warning("Institute {0} does not exist in database".format(institute)) context.abort() if not panel_id: LOG.warning("A Panel has to have a panel id") context.abort() if version: existing_panel = adapter.gene_panel(panel_id, version) else: existing_panel = adapter.gene_panel(panel_id) ## Assuming version 1.0 version = 1.0 if existing_panel: LOG.info("found existing panel") if version == existing_panel['version']: LOG.warning("Panel with same version exists in database") LOG.info("Reload with updated version") context.abort() display_name = display_name or existing_panel['display_name'] institute = institute or existing_panel['institute'] try: adapter.load_panel( path=path, institute=institute, panel_id=panel_id, date=date, panel_type=panel_type, version=version, display_name=display_name ) except Exception as err: LOG.warning(err) context.abort()
def load_panel( panel_path, adapter, date=None, display_name=None, version=None, panel_type=None, panel_id=None, institute=None, ): """Load a manually curated gene panel into scout Args: panel_path(str): path to gene panel file adapter(scout.adapter.MongoAdapter) date(str): date of gene panel on format 2017-12-24 display_name(str) version(float) panel_type(str) panel_id(str) institute(str) """ panel_lines = get_file_handle(panel_path) try: # This will parse panel metadata if includeed in panel file panel_info = get_panel_info( panel_lines=panel_lines, panel_id=panel_id, institute=institute, version=version, date=date, display_name=display_name, ) except Exception as err: raise err version = None if panel_info.get("version"): version = float(panel_info["version"]) panel_id = panel_info["panel_id"] display_name = panel_info["display_name"] or panel_id institute = panel_info["institute"] date = panel_info["date"] if not institute: raise SyntaxError("A Panel has to belong to a institute") # Check if institute exists in database if not adapter.institute(institute): raise SyntaxError("Institute {0} does not exist in database".format(institute)) if not panel_id: raise SyntaxError("A Panel has to have a panel id") if version: existing_panel = adapter.gene_panel(panel_id, version) else: ## Assuming version 1.0 existing_panel = adapter.gene_panel(panel_id) version = 1.0 LOG.info("Set version to %s", version) if existing_panel: LOG.info("found existing panel") if version == existing_panel["version"]: LOG.warning("Panel with same version exists in database") LOG.info("Reload with updated version") raise SyntaxError() display_name = display_name or existing_panel["display_name"] institute = institute or existing_panel["institute"] parsed_panel = parse_gene_panel( path=panel_path, institute=institute, panel_type=panel_type, date=date, version=version, panel_id=panel_id, display_name=display_name, ) try: adapter.load_panel(parsed_panel=parsed_panel) except Exception as err: raise err
def panel(context, date, display_name, version, panel_type, panel_id, path, institute): """Add a gene panel to the database.""" adapter = context.obj['adapter'] panel_lines = get_file_handle(path) try: panel_info = get_panel_info(panel_lines=panel_lines, panel_id=panel_id, institute=institute, version=version, date=date, display_name=display_name) except Exception as err: LOG.warning(err) context.abort() version = None if panel_info.get('version'): version = float(panel_info['version']) panel_id = panel_info['panel_id'] display_name = panel_info['display_name'] or panel_id institute = panel_info['institute'] date = panel_info['date'] if not institute: LOG.warning("A Panel has to belong to a institute") context.abort() if not panel_id: LOG.warning("A Panel has to have a panel id") context.abort() if version: existing_panel = adapter.gene_panel(panel_id, version) else: existing_panel = adapter.gene_panel(panel_id) ## Assuming version 1.0 version = 1.0 if existing_panel: LOG.info("found existing panel") if version == existing_panel['version']: LOG.warning("Panel with same version exists in database") LOG.info("Reload with updated version") context.abort() display_name = display_name or existing_panel['display_name'] institute = institute or existing_panel['institute'] try: adapter.load_panel(path=path, institute=institute, panel_id=panel_id, date=date, panel_type=panel_type, version=version, display_name=display_name) except Exception as err: LOG.warning(err) context.abort()