src/pybel/io/jgif.py
def from_jgif(graph_jgif_dict, parser_kwargs: Optional[Mapping[str, Any]] = None):  # noqa:C901
    """Build a BEL graph from a JGIF JSON object.

    :param dict graph_jgif_dict: The JSON object representing the graph in JGIF format
    :rtype: BELGraph
    """
    graph = BELGraph()

    root = graph_jgif_dict['graph']

    if 'label' in root:
        graph.name = root['label']

    if 'metadata' in root:
        metadata = root['metadata']

        for key in METADATA_INSERT_KEYS:
            if key in metadata:
                graph.document[key] = metadata[key]

    for k in (GRAPH_ANNOTATION_URL, GRAPH_NAMESPACE_URL):
        if k in root:
            graph.graph[k] = root[k]

    parser = BELParser(graph, namespace_to_pattern=NAMESPACE_TO_PATTERN)
    parser.bel_term.addParseAction(parser.handle_term)

    for node in root['nodes']:
        node_label = node.get('label')

        if node_label is None:
            logger.warning('node missing label: %s', node)
            continue

        try:
            parser.bel_term.parseString(node_label)
        except NakedNameWarning as e:
            logger.info('Naked name: %s', e)
        except UndefinedNamespaceWarning as e:
            logger.info('Undefined namespace: %s', e)
        except ParseException:
            logger.info('Parse exception for %s', node_label)

    for i, edge in enumerate(root['edges']):
        relation = edge.get('relation')
        if relation is None:
            logger.warning('no relation for edge: %s', edge)

        if relation in {'actsIn', 'translocates'}:
            continue  # don't need legacy BEL format

        edge_metadata = edge.get('metadata')
        if edge_metadata is None:
            logger.warning('no metadata for edge: %s', edge)
            continue

        bel_statement = edge.get('label')
        if bel_statement is None:
            logger.debug('No BEL statement for edge %s', edge)

        evidences = edge_metadata.get('evidences')

        if relation in UNQUALIFIED_EDGES:
            pass  # FIXME?

        else:
            if not evidences:  # is none or is empty list
                logger.debug('No evidence for edge %s', edge)
                continue

            for evidence in evidences:
                citation = evidence.get('citation')

                if not citation:
                    continue

                if 'type' not in citation or 'id' not in citation:
                    continue

                summary_text = evidence['summary_text'].strip()

                if not summary_text or summary_text == placeholder_evidence:
                    continue

                parser.control_parser.clear()
                citation_namespace = citation['type'].lower().strip()
                citation_namespace = pc.CITATION_NORMALIZER.get(citation_namespace, citation_namespace)
                parser.control_parser.citation_db = citation_namespace
                parser.control_parser.citation_db_id = citation['id'].strip()
                parser.control_parser.evidence = summary_text
                annotations = parser.graph._clean_annotations(evidence[EXPERIMENT_CONTEXT])
                parser.control_parser.annotations.update(annotations)

                try:
                    parser.parseString(bel_statement, line_number=i)
                except Exception as e:
                    logger.warning('JGIF relation parse error: %s for %s', e, bel_statement)

    return graph
Build a BEL graph from a JGIF JSON object.

    :param dict graph_jgif_dict: The JSON object representing the graph in JGIF format
    :rtype: BELGraph
    
Build a BEL graph from a JGIF JSON object.
Build a BEL graph from a JGIF JSON object .
def from_jgif(graph_jgif_dict, parser_kwargs: Optional[Mapping[str, Any]] = None):  
    graph = BELGraph()
    root = graph_jgif_dict['graph']
    if 'label' in root:
        graph.name = root['label']
    if 'metadata' in root:
        metadata = root['metadata']
        for key in METADATA_INSERT_KEYS:
            if key in metadata:
                graph.document[key] = metadata[key]
    for k in (GRAPH_ANNOTATION_URL, GRAPH_NAMESPACE_URL):
        if k in root:
            graph.graph[k] = root[k]
    parser = BELParser(graph, namespace_to_pattern=NAMESPACE_TO_PATTERN)
    parser.bel_term.addParseAction(parser.handle_term)
    for node in root['nodes']:
        node_label = node.get('label')
        if node_label is None:
            logger.warning('node missing label: %s', node)
            continue
        try:
            parser.bel_term.parseString(node_label)
        except NakedNameWarning as e:
            logger.info('Naked name: %s', e)
        except UndefinedNamespaceWarning as e:
            logger.info('Undefined namespace: %s', e)
        except ParseException:
            logger.info('Parse exception for %s', node_label)
    for i, edge in enumerate(root['edges']):
        relation = edge.get('relation')
        if relation is None:
            logger.warning('no relation for edge: %s', edge)
        if relation in {'actsIn', 'translocates'}:
            continue  
        edge_metadata = edge.get('metadata')
        if edge_metadata is None:
            logger.warning('no metadata for edge: %s', edge)
            continue
        bel_statement = edge.get('label')
        if bel_statement is None:
            logger.debug('No BEL statement for edge %s', edge)
        evidences = edge_metadata.get('evidences')
        if relation in UNQUALIFIED_EDGES:
            pass  
        else:
            if not evidences:  
                logger.debug('No evidence for edge %s', edge)
                continue
            for evidence in evidences:
                citation = evidence.get('citation')
                if not citation:
                    continue
                if 'type' not in citation or 'id' not in citation:
                    continue
                summary_text = evidence['summary_text'].strip()
                if not summary_text or summary_text == placeholder_evidence:
                    continue
                parser.control_parser.clear()
                citation_namespace = citation['type'].lower().strip()
                citation_namespace = pc.CITATION_NORMALIZER.get(citation_namespace, citation_namespace)
                parser.control_parser.citation_db = citation_namespace
                parser.control_parser.citation_db_id = citation['id'].strip()
                parser.control_parser.evidence = summary_text
                annotations = parser.graph._clean_annotations(evidence[EXPERIMENT_CONTEXT])
                parser.control_parser.annotations.update(annotations)
                try:
                    parser.parseString(bel_statement, line_number=i)
                except Exception as e:
                    logger.warning('JGIF relation parse error: %s for %s', e, bel_statement)
    return graph
def from_jgif ( graph_jgif_dict , parser_kwargs : Optional [ Mapping [ str , Any ] ] = None ) : graph = BELGraph ( ) root = graph_jgif_dict [ 'graph' ] if 'label' in root : graph . name = root [ 'label' ] if 'metadata' in root : metadata = root [ 'metadata' ] for key in METADATA_INSERT_KEYS : if key in metadata : graph . document [ key ] = metadata [ key ] for k in ( GRAPH_ANNOTATION_URL , GRAPH_NAMESPACE_URL ) : if k in root : graph . graph [ k ] = root [ k ] parser = BELParser ( graph , namespace_to_pattern = NAMESPACE_TO_PATTERN ) parser . bel_term . addParseAction ( parser . handle_term ) for node in root [ 'nodes' ] : node_label = node . get ( 'label' ) if node_label is None : logger . warning ( 'node missing label: %s' , node ) continue try : parser . bel_term . parseString ( node_label ) except NakedNameWarning as e : logger . info ( 'Naked name: %s' , e ) except UndefinedNamespaceWarning as e : logger . info ( 'Undefined namespace: %s' , e ) except ParseException : logger . info ( 'Parse exception for %s' , node_label ) for i , edge in enumerate ( root [ 'edges' ] ) : relation = edge . get ( 'relation' ) if relation is None : logger . warning ( 'no relation for edge: %s' , edge ) if relation in { 'actsIn' , 'translocates' } : continue edge_metadata = edge . get ( 'metadata' ) if edge_metadata is None : logger . warning ( 'no metadata for edge: %s' , edge ) continue bel_statement = edge . get ( 'label' ) if bel_statement is None : logger . debug ( 'No BEL statement for edge %s' , edge ) evidences = edge_metadata . get ( 'evidences' ) if relation in UNQUALIFIED_EDGES : pass else : if not evidences : logger . debug ( 'No evidence for edge %s' , edge ) continue for evidence in evidences : citation = evidence . get ( 'citation' ) if not citation : continue if 'type' not in citation or 'id' not in citation : continue summary_text = evidence [ 'summary_text' ] . strip ( ) if not summary_text or summary_text == placeholder_evidence : continue parser . control_parser . clear ( ) citation_namespace = citation [ 'type' ] . lower ( ) . strip ( ) citation_namespace = pc . CITATION_NORMALIZER . get ( citation_namespace , citation_namespace ) parser . control_parser . citation_db = citation_namespace parser . control_parser . citation_db_id = citation [ 'id' ] . strip ( ) parser . control_parser . evidence = summary_text annotations = parser . graph . _clean_annotations ( evidence [ EXPERIMENT_CONTEXT ] ) parser . control_parser . annotations . update ( annotations ) try : parser . parseString ( bel_statement , line_number = i ) except Exception as e : logger . warning ( 'JGIF relation parse error: %s for %s' , e , bel_statement ) return graph
Build a BEL graph from a JGIF JSON object.
Build a BEL graph from a JGIF JSON object .
# noqa:C901 """Build a BEL graph from a JGIF JSON object.

    :param dict graph_jgif_dict: The JSON object representing the graph in JGIF format
    :rtype: BELGraph
    """ # don't need legacy BEL format # FIXME? # is none or is empty list
None
BELGraph
graph_jgif_dict
The JSON object representing the graph in JGIF format
The JSON object representing the graph in JGIF format
parser_kwargs
Optional[Mapping[str, Any]]