Exemplo n.º 1
0
def diseases(api_key, genemap2):
    """
    Update disease terms in mongo database.

    If no file is specified the file will be fetched from OMIM with the api-key
    """
    adapter = store

    # Fetch the omim information
    api_key = api_key or current_app.config.get("OMIM_API_KEY")
    if genemap2:
        genemap_lines = get_file_handle(genemap2)

    else:
        if not api_key:
            LOG.warning("Please provide a omim api key to load the omim gene panel")
            raise click.Abort()

        try:
            mim_files = fetch_mim_files(api_key, genemap2=True)
            genemap_lines = mim_files["genemap2"]
        except Exception as err:
            LOG.warning(err)
            raise click.Abort()

    LOG.info("Dropping DiseaseTerms")
    adapter.disease_term_collection.drop()
    LOG.debug("DiseaseTerms dropped")
    load_disease_terms(adapter=adapter, genemap_lines=genemap_lines)

    LOG.info("Successfully loaded all disease terms")
Exemplo n.º 2
0
def diseases(context, api_key):
    """
    Update disease terms in mongo database.
    """
    adapter = context.obj['adapter']

    # Fetch the omim information
    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()

    try:
        mim_files = fetch_mim_files(api_key, genemap2=True)
    except Exception as err:
        LOG.warning(err)
        context.abort()

    LOG.info("Dropping DiseaseTerms")
    adapter.disease_term_collection.drop()
    LOG.debug("DiseaseTerms dropped")

    load_disease_terms(
        adapter=adapter,
        genemap_lines=mim_files['genemap2'],
    )

    LOG.info("Successfully loaded all disease terms")
Exemplo n.º 3
0
def diseases(api_key):
    """
    Update disease terms in mongo database.
    """
    adapter = store

    # Fetch the omim information
    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()

    try:
        mim_files = fetch_mim_files(api_key, genemap2=True)
    except Exception as err:
        LOG.warning(err)
        raise click.Abort()

    LOG.info("Dropping DiseaseTerms")
    adapter.disease_term_collection.drop()
    LOG.debug("DiseaseTerms dropped")

    load_disease_terms(
        adapter=adapter,
        genemap_lines=mim_files['genemap2'],
    )

    LOG.info("Successfully loaded all disease terms")
Exemplo n.º 4
0
def diseases(ctx):
    """
    Load the disease terms to the mongo database.
    """
    adapter = ctx.obj['adapter']
    
    logger.info("Dropping Disease Terms")
    adapter.disease_term_collection.drop()
    logger.debug("Disease Terms dropped")
    
    logger.info("Loading disease info from file {0}".format(genemap2_path))
    logger.info("Loading hpo info from file {0}".format(hpo_phenotype_to_terms_path))
    
    disease_handle = get_file_handle(genemap2_path)
    hpo_handle = get_file_handle(hpo_phenotype_to_terms_path)

    alias_genes = adapter.genes_by_alias()
    
    load_disease_terms(
        adapter=adapter,
        genemap_lines=disease_handle, 
        genes=alias_genes,
        hpo_disease_lines=hpo_handle,
    )

    logger.info("Successfully loaded all hpo terms")
Exemplo n.º 5
0
def test_load_disease_terms(gene_database, genemap_handle, hpo_disease_handle):
    adapter = gene_database
    alias_genes = adapter.genes_by_alias()

    # GIVEN a populated database with genes and no disease terms
    assert len([term for term in adapter.disease_terms()]) == 0

    # WHEN loading the disease terms
    load_disease_terms(
        adapter=adapter,
        genemap_lines=genemap_handle,
        genes=alias_genes,
        hpo_disease_lines=hpo_disease_handle,
    )

    # THEN make sure that the disease terms are in the database
    disease_objs = adapter.disease_terms()

    assert len([disease for disease in disease_objs]) > 0
Exemplo n.º 6
0
def diseases(downloads_folder, api_key):
    """
    Update disease terms in mongo database. Use pre-downloaded resource files (phenotype_to_genes and genemap2) or download them from OMIM.
    Both options require using a valid omim api key.
    """
    adapter = store
    api_key = api_key or current_app.config.get("OMIM_API_KEY")
    resources = {}

    if downloads_folder:
        api_key = None
        # Fetch required resource lines after making sure that are present in downloads folder and that contain valid data
        _fetch_downloaded_resources(resources, downloads_folder)
    else:
        # Download resources
        if not api_key:
            LOG.warning(
                "Please provide a omim api key to load the omim gene panel")
            raise click.Abort()

        try:
            mim_files = fetch_mim_files(api_key, genemap2=True)
            resources["genemap_lines"] = mim_files["genemap2"]
            resources["hpo_gene_lines"] = fetch_hpo_to_genes_to_disease()

        except Exception as err:
            LOG.warning(err)
            raise click.Abort()

    _check_resources(resources)

    LOG.info("Dropping DiseaseTerms")
    adapter.disease_term_collection.delete_many({})
    LOG.debug("DiseaseTerms dropped")

    load_disease_terms(
        adapter=adapter,
        genemap_lines=resources["genemap_lines"],
        hpo_disease_lines=resources["hpo_gene_lines"],
    )

    LOG.info("Successfully loaded all disease terms")
Exemplo n.º 7
0
def test_load_disease_terms(gene_database, genemap_file, hpo_disease_handle):
    adapter = gene_database
    alias_genes = adapter.genes_by_alias()
    
    # GIVEN a populated database with genes and no disease terms
    assert len([term for term in adapter.disease_terms()]) == 0
    genemap_handle = get_file_handle(genemap_file)
    
    
    # WHEN loading the disease terms
    load_disease_terms(
        adapter=adapter,
        genemap_lines=genemap_handle,
        genes=alias_genes,
        hpo_disease_lines=hpo_disease_handle,
    )

    # THEN make sure that the disease terms are in the database
    disease_objs = adapter.disease_terms()
    
    assert len([disease for disease in disease_objs]) > 0