def yield_nanopub(assertions, annotations, line_num):
    """Yield nanopub object"""

    if not assertions:
        return {}

    anno = copy.deepcopy(annotations)

    evidence = anno.pop("evidence", None)
    stmt_group = anno.pop("statement_group", None)
    citation = anno.pop("citation", None)

    anno_list = []
    for anno_type in anno:
        if isinstance(anno[anno_type], (list, tuple)):
            for val in anno[anno_type]:
                anno_list.append({"type": anno_type, "label": val})
        else:
            anno_list.append({"type": anno_type, "label": anno[anno_type]})

    assertions_list = []
    for assertion in assertions:
        (subj, rel, obj) = split_bel_stmt(assertion, line_num)
        assertions_list.append({"subject": subj, "relation": rel, "object": obj})

    nanopub = {
        "schema_uri": "https://raw.githubusercontent.com/belbio/schemas/master/schemas/nanopub_bel-1.0.0.yaml",
        "type": copy.deepcopy(nanopub_type),
        "annotations": copy.deepcopy(anno_list),
        "citation": copy.deepcopy(citation),
        "assertions": copy.deepcopy(assertions_list),
        "evidence": evidence,
        "metadata": {"statement_group": stmt_group},
    }

    return {"nanopub": copy.deepcopy(nanopub)}
def yield_nanopub ( assertions , annotations , line_num ) : if not assertions : return { } anno = copy . deepcopy ( annotations ) evidence = anno . pop ( "evidence" , None ) stmt_group = anno . pop ( "statement_group" , None ) citation = anno . pop ( "citation" , None ) anno_list = [ ] for anno_type in anno : if isinstance ( anno [ anno_type ] , ( list , tuple ) ) : for val in anno [ anno_type ] : anno_list . append ( { "type" : anno_type , "label" : val } ) else : anno_list . append ( { "type" : anno_type , "label" : anno [ anno_type ] } ) assertions_list = [ ] for assertion in assertions : ( subj , rel , obj ) = split_bel_stmt ( assertion , line_num ) assertions_list . append ( { "subject" : subj , "relation" : rel , "object" : obj } ) nanopub = { "schema_uri" : "https://raw.githubusercontent.com/belbio/schemas/master/schemas/nanopub_bel-1.0.0.yaml" , "type" : copy . deepcopy ( nanopub_type ) , "annotations" : copy . deepcopy ( anno_list ) , "citation" : copy . deepcopy ( citation ) , "assertions" : copy . deepcopy ( assertions_list ) , "evidence" : evidence , "metadata" : { "statement_group" : stmt_group } , } return { "nanopub" : copy . deepcopy ( nanopub ) }
Yield nanopub object