Beispiel #1
0
def real_database(database_name, institute_obj, user_obj, genes, panel_info):
    """Setup a real database with populated data"""
    mongo_client = pymongo.MongoClient()
    mongo_client.drop_database(database_name)

    database = mongo_client[database_name]
    adapter = MongoAdapter(database)

    # Populate the database
    adapter.add_institute(institute_obj)
    adapter.add_user(user_obj)

    load_hgnc_genes(adapter, genes)
    adapter.hgnc_collection.create_index([('build', pymongo.ASCENDING),
                                          ('hgnc_symbol', pymongo.ASCENDING)])
    load_panel(adapter=adapter, panel_info=panel_info)

    # load_hpo(adapter=gene_database, hpo_lines=hpo_terms_handle, disease_lines=genemap_handle)
    # adapter.add_case(case_obj)

    # for variant in variant_objs:
    #     adapter.load_variant(variant)

    yield adapter

    mongo_client.drop_database(database_name)
Beispiel #2
0
def test_load_panel(gene_database, panel_info):
    # GIVEN an database with genes but no panels

    assert gene_database.gene_panels().count() == 0

    # WHEN loading a gene panel
    load_panel(adapter=gene_database, panel_info=panel_info)

    # THEN make sure that the panel is loaded

    assert gene_database.gene_panel(panel_id=panel_info['panel_name'])
Beispiel #3
0
def panel(
    path,
    date,
    display_name,
    version,
    panel_type,
    panel_id,
    institute,
    maintainer,
    omim,
    genemap2,
    mim2genes,
    api_key,
    panel_app,
):
    """Add a gene panel to the database."""

    adapter = store
    institute = institute or "cust000"

    if omim:
        _panel_omim(adapter, genemap2, mim2genes, api_key, institute,
                    maintainer)
        return

    if panel_app:
        # try:
        load_panel_app(adapter, panel_id, institute=institute)
        # except Exception as err:
        #     LOG.warning(err)
        #     raise click.Abort()
        return

    if path is None:
        LOG.info("Please provide a panel")
        return
    try:
        load_panel(
            panel_path=path,
            adapter=adapter,
            date=date,
            display_name=display_name,
            version=version,
            panel_type=panel_type,
            panel_id=panel_id,
            institute=institute,
            maintainer=maintainer,
        )
    except Exception as err:
        LOG.warning(err)
        raise click.Abort()

    return
Beispiel #4
0
def panel(path, date, display_name, version, panel_type, panel_id, institute,
          omim, api_key, panel_app):
    """Add a gene panel to the database."""

    adapter = store
    institute = institute or 'cust000'

    if not path and not omim:
        LOG.warning("Please provide a gene panel file or specify omim")
        context.abort()

    if omim:
        api_key = api_key or current_app.config.get('OMIM_API_KEY')
        if not api_key:
            LOG.warning(
                "Please provide a omim api key to load the omim gene panel")
            raise click.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

        # Here we know that there is no panel loaded
        try:
            adapter.load_omim_panel(api_key, institute=institute)
        except Exception as err:
            LOG.error(err)
            raise click.Abort()

    if panel_app:
        # try:
        load_panel_app(adapter, panel_id, institute=institute)
        # except Exception as err:
        #     LOG.warning(err)
        #     raise click.Abort()

    if (omim or panel_app):
        return

    if path is None:
        LOG.info("Please provide a panel")
        return
    try:
        load_panel(path, adapter, date, display_name, version, panel_type,
                   panel_id, institute)
    except Exception as err:
        LOG.warning(err)
        raise click.Abort()
Beispiel #5
0
def test_load_panel(gene_database, panel_info):
    # GIVEN an database with genes but no panels
    adapter = gene_database
    assert sum(1 for i in adapter.gene_panels()) == 0

    # WHEN loading a gene panel
    load_panel(panel_path=panel_info['file'],
               adapter=adapter,
               institute=panel_info['institute'],
               panel_id=panel_info['panel_name'],
               panel_type=panel_info['type'],
               version=panel_info['version'],
               display_name=panel_info['full_name'])

    # THEN make sure that the panel is loaded

    assert adapter.gene_panel(panel_id=panel_info['panel_name'])
def test_load_panel(gene_database, panel_info):
    # GIVEN an database with genes but no panels
    adapter = gene_database
    assert adapter.gene_panels().count() == 0
    
    # WHEN loading a gene panel
    load_panel(
        panel_path=panel_info['file'], 
        adapter=adapter,
        institute=panel_info['institute'], 
        panel_id=panel_info['panel_name'], 
        panel_type=panel_info['type'], 
        version=panel_info['version'], 
        display_name=panel_info['full_name']
    )
    
    # THEN make sure that the panel is loaded
    
    assert adapter.gene_panel(panel_id=panel_info['panel_name'])
Beispiel #7
0
def panel(context, path, date, display_name, version, panel_type, panel_id, institute, omim, api_key, panel_app):
    """Add a gene panel to the database."""

    adapter = context.obj['adapter']
    institute = institute or 'cust000'

    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

        # Here we know that there is no panel loaded
        try:
            adapter.load_omim_panel(api_key, institute=institute)
        except Exception as err:
            LOG.error(err)
            context.abort()
    
    if panel_app:
        # try:
        load_panel_app(adapter, panel_id, institute=institute)
        # except Exception as err:
        #     LOG.warning(err)
        #     context.abort()

    if (omim or panel_app):
        return

    if path is None:
        LOG.info("Please provide a panel")
        return
    try:
        load_panel(path, adapter, date, display_name, version, panel_type, panel_id, institute)
    except Exception as err:
        LOG.warning(err)
        context.abort()
Beispiel #8
0
def panel(
    path,
    date,
    display_name,
    version,
    panel_type,
    panel_id,
    institute,
    omim,
    genemap2,
    mim2genes,
    api_key,
    panel_app,
):
    """Add a gene panel to the database."""

    adapter = store
    institute = institute or "cust000"

    if omim:
        mim_files = None
        if genemap2 and mim2genes:
            mim_files = {
                "genemap2": list(get_file_handle(genemap2)),
                "mim2genes": list(get_file_handle(mim2genes)),
            }

        api_key = api_key or current_app.config.get("OMIM_API_KEY")
        if not api_key and mim_files is None:
            LOG.warning(
                "Please provide a omim api key to load the omim gene panel")
            raise click.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

        if not mim_files:
            try:
                mim_files = fetch_mim_files(api_key=api_key,
                                            genemap2=True,
                                            mim2genes=True)
            except Exception as err:
                raise err

        # Here we know that there is no panel loaded
        try:
            adapter.load_omim_panel(
                genemap2_lines=mim_files["genemap2"],
                mim2gene_lines=mim_files["mim2genes"],
                institute=institute,
            )
        except Exception as err:
            LOG.error(err)
            raise click.Abort()

    if panel_app:
        # try:
        load_panel_app(adapter, panel_id, institute=institute)
        # except Exception as err:
        #     LOG.warning(err)
        #     raise click.Abort()

    if omim or panel_app:
        return

    if path is None:
        LOG.info("Please provide a panel")
        return
    try:
        load_panel(path, adapter, date, display_name, version, panel_type,
                   panel_id, institute)
    except Exception as err:
        LOG.warning(err)
        raise click.Abort()