Пример #1
0
def machine(manager: Manager, agents: List[str], local: bool, host: str):
    """Get content from the INDRA machine and upload to BEL Commons."""
    from indra.sources import indra_db_rest
    from pybel import from_indra_statements

    statements = indra_db_rest.get_statements(agents=agents)
    click.echo('got {} statements from INDRA'.format(len(statements)))

    graph = from_indra_statements(
        statements,
        name='INDRA Machine for {}'.format(', '.join(sorted(agents))),
        version=time.strftime('%Y%m%d'),
    )
    click.echo('built BEL graph with {} nodes and {} edges'.format(
        graph.number_of_nodes(), graph.number_of_edges()))

    if 0 == len(graph):
        click.echo('not uploading empty graph')
        sys.exit(-1)

    if local:
        to_database(graph, manager=manager)
    else:
        resp = to_web(graph, host=host)
        resp.raise_for_status()
Пример #2
0
def assess_completeness(
    ids: Union[str, Tuple[str, str], List[Tuple[str, str]]],
    reference_nodes: Union[Iterable[BaseEntity], BELGraph],
    *,
    verbose_indra_logger: bool = False,
) -> Optional[CompletenessSummary]:
    """Check INDRA if the given document has new interesting content compared to the graph.

    :param ids: A CURIE (e.g., pmid:30606258, pmc:PMC6318896),
     a pair of database/identifier (e.g. `('pmid', '30606258')`) or a list of pairs.
    :param reference_nodes: A set of nodes or a BEL graph (which is a set of nodes)
    :param verbose_indra_logger: Should the INDRA logger show any output below the WARNING level?
    """
    if not verbose_indra_logger:
        indra_logger.setLevel(logging.WARNING)

    if isinstance(ids, str):
        _ids = ids.split(':')
        if len(_ids) != 2:
            raise ValueError(f'String should be given as CURIE: {ids}')
        ids = [_ids]
    elif isinstance(ids, tuple):
        ids = [ids]

    # Normalize PMC database name as well as stringify all identifiers
    ids = [
        ('pmcid' if db == 'pmc' else db, str(db_id))
        for db, db_id in ids
    ]

    stmts = get_statements_for_paper(ids=ids)
    indra_graph = from_indra_statements(stmts)

    indra_nodes = set(indra_graph)
    if not indra_nodes:
        print(f'INDRA did not return any results for {ids}')
        return

    return CompletenessSummary(
        documents=ids,
        reference_nodes=set(reference_nodes),
        indra_nodes=indra_nodes,
    )
Пример #3
0
def run_one(directory):
    """

    :param str directory:
    """
    if not os.path.isdir(directory):
        return

    if not os.path.exists(os.path.join(directory, 'config.yaml')):
        return  # Skip non-INDRA machine directories

    log.info('running in %s', directory)
    # Use config=None so it looks in the subdirectory
    run_with_search_helper(directory, config=None)

    default_config_fname = os.path.join(directory, 'config.yaml')
    config = get_config(default_config_fname)
    ndex_cred = get_ndex_cred(config)
    name = ndex_cred.get('name') if ndex_cred is not None else None

    model = load_model(directory)
    stmts = model.get_statements()

    if not stmts:
        log.warning('no statements')
        return

    # Output CX
    if name:
        cx_str = assemble_cx(stmts, name)
        with open(os.path.join(directory, 'output.cx'), 'w') as file:
            print(cx_str, file=file)

    # Output BEL gpickle
    bel_graph = pybel.from_indra_statements(stmts)
    pybel.to_pickle(bel_graph, os.path.join(directory, 'output.gpickle'))

    return True