@@ -0,0 +1,2230 @@
+# -*- coding: utf-8 -*-%0A%0A%22%22%22Assess the completeness of a graph.%0A%0ARun on CONIB with %60%60python -m pybel_tools.assess_completeness %5BPMID%5D%60%60.%0A%22%22%22%0A%0Aimport logging%0A%0Aimport click%0Afrom indra.sources.indra_db_rest.api import get_statements_for_paper%0Afrom indra.sources.indra_db_rest.util import logger as indra_logger%0A%0Afrom pybel import BELGraph, from_indra_statements%0A%0A__all__ = %5B%0A    'assess_completeness',%0A%5D%0A%0A%0Adef assess_completeness(ids, graph: BELGraph, verbose_indra_logger: bool = False):%0A    %22%22%22Check INDRA if the given document has new interesting content compared to the graph.%0A%0A    :param ids: A CURIE (e.g., pmid:30606258, pmc:PMC6318896),%0A     a pair of database/identifier (e.g. %60('pmid', '30606258')%60) or a list of pairs.%0A    :param graph: A BEL graph%0A    %22%22%22%0A    if not verbose_indra_logger:%0A        indra_logger.setLevel(logging.WARNING)%0A%0A    if isinstance(ids, str):%0A        ids = %5Bids.split(':')%5D%0A    elif isinstance(ids, tuple):%0A        ids = %5Bids%5D%0A%0A    # Normalize PMC database name as well as stringify all identifiers%0A    ids = %5B%0A        ('pmcid' if db == 'pmc' else db, str(db_id))%0A        for db, db_id in ids%0A    %5D%0A%0A    stmts = get_statements_for_paper(ids=ids)%0A    indra_graph = from_indra_statements(stmts)%0A%0A    indra_nodes = set(indra_graph)%0A    if not indra_nodes:%0A        print(f'INDRA did not return any results for %7Bids%7D')%0A        return False%0A%0A    query_nodes = set(graph)%0A    new_nodes = indra_nodes - query_nodes%0A%0A    print(f%22%22%22%0A    Graph had:%0A        Total nodes: %7Blen(query_nodes)%7D%0A%0A    INDRA found (in %7Bids%7D):%0A        Total nodes: %7Blen(indra_nodes)%7D%0A        New nodes: %7Blen(new_nodes)%7D (%7Blen(new_nodes) / len(indra_nodes):.2%25%7D)%0A    %22%22%22)%0A    return True%0A%0A%0A@click.command()%0A@click.argument('pmid')%0A@click.option('-v', '--verbose', is_flag=True)%0Adef main(pmid: str, verbose: bool) -%3E None:%0A    %22%22%22Check CONIB for added value of a given article.%0A%0A    Example: 30606258 for paper entitled %22A pathogenic tau fragment compromises microtubules,%0A    disrupts insulin signaling and induces the unfolded protein response.%22%0A    %22%22%22%0A    import hbp_knowledge%0A    graph = hbp_knowledge.get_graph()%0A%0A    assess_completeness(('pmid', pmid), graph, verbose_indra_logger=verbose)%0A%0A%0Aif __name__ == '__main__':%0A    main()%0A

Add outline of INDRA-based graph completeness checker