@@ -0,0 +1,1430 @@
+import logging%0Afrom indra.sources import indra_db_rest%0Afrom indra.pipeline import AssemblyPipeline%0Afrom indra.sources.hypothesis import upload_statement_annotation%0A%0Aref_priority = %5B'TRID', 'PMCID', 'PMID'%5D%0A%0Alogger = logging.getLogger(__name__)%0A%0A%0Adef annotate_paper(text_refs, pipeline=None):%0A    %22%22%22Upload INDRA Statements as annotations for a given paper.%0A%0A    Parameters%0A    ----------%0A    text_refs : dict%0A        A dict of text references, following the same format as%0A        the INDRA Evidence text_refs attribute.%0A%0A    pipeline : Optional%5Bjson%5D%0A        A list of pipeline steps (typically filters) that are applied%0A        before uploading statements to hypothes.is as annotations.%0A    %22%22%22%0A    for ref_ns in ref_priority:%0A        ref_id = text_refs.get(ref_ns)%0A        if ref_id:%0A            break%0A    else:%0A        logger.info('Could not find appropriate text refs')%0A        return%0A    ip = indra_db_rest.get_statements_for_paper(%5B(ref_ns.lower(), ref_id)%5D)%0A    stmts = ip.statements%0A    # Cut down evidences to ones just from this paper%0A    for stmt in stmts:%0A        stmt.evidence = %5Bev for ev in stmt.evidence if%0A                         ev.text_refs.get(ref_ns) == ref_id%5D%0A    if pipeline:%0A        ap = AssemblyPipeline(pipeline)%0A        stmts = ap.run(stmts)%0A%0A    logger.info('Uploading %25d statements to hypothes.is' %25 len(stmts))%0A    for stmt in stmts:%0A        upload_statement_annotation(stmt, annotate_agents=True)

Add tool for annotating a given paper