src/pybel/io/jgif.py
def map_cbn(d):
    """Pre-processes the JSON from the CBN.

    - removes statements without evidence, or with placeholder evidence

    :param dict d: Raw JGIF from the CBN
    :return: Preprocessed JGIF
    :rtype: dict
    """
    for i, edge in enumerate(d['graph']['edges']):
        if 'metadata' not in edge:
            continue

        if 'evidences' not in edge['metadata']:
            continue

        for j, evidence in enumerate(edge['metadata']['evidences']):
            if EXPERIMENT_CONTEXT not in evidence:
                continue

            # ctx = {k.strip().lower(): v.strip() for k, v in evidence[EXPERIMENT_CONTEXT].items() if v.strip()}

            new_context = {}

            for key, value in evidence[EXPERIMENT_CONTEXT].items():
                if not value:
                    logger.debug('key %s without value', key)
                    continue

                value = value.strip()

                if not value:
                    logger.debug('key %s without value', key)
                    continue

                key = key.strip().lower()

                if key == 'species_common_name':
                    new_context['Species'] = species_map[value.lower()]
                elif key in annotation_map:
                    new_context[annotation_map[key]] = value
                else:
                    new_context[key] = value

            '''
            for k, v in annotation_map.items():
                if k not in ctx:
                    continue

                d['graph']['edges'][i]['metadata']['evidences'][j][EXPERIMENT_CONTEXT][v] = ctx[k]
                del d['graph']['edges'][i]['metadata']['evidences'][j][EXPERIMENT_CONTEXT][k]

            if 'species_common_name' in ctx:
                species_name = ctx['species_common_name'].strip().lower()
                d['graph']['edges'][i]['metadata']['evidences'][j][EXPERIMENT_CONTEXT]['Species'] = species_map[
                    species_name]
                del d['graph']['edges'][i]['metadata']['evidences'][j][EXPERIMENT_CONTEXT][
                    'species_common_name']
            '''

            # TODO can this be replaced with edge as well?
            d['graph']['edges'][i]['metadata']['evidences'][j][EXPERIMENT_CONTEXT] = new_context

    return d
Pre-processes the JSON from the CBN.

    - removes statements without evidence, or with placeholder evidence

    :param dict d: Raw JGIF from the CBN
    :return: Preprocessed JGIF
    :rtype: dict
    
Pre-processes the JSON from the CBN.
removes statements without evidence, or with placeholder evidence
Pre - processes the JSON from the CBN . removes statements without evidence or with placeholder evidence
def map_cbn(d):
    for i, edge in enumerate(d['graph']['edges']):
        if 'metadata' not in edge:
            continue
        if 'evidences' not in edge['metadata']:
            continue
        for j, evidence in enumerate(edge['metadata']['evidences']):
            if EXPERIMENT_CONTEXT not in evidence:
                continue
            new_context = {}
            for key, value in evidence[EXPERIMENT_CONTEXT].items():
                if not value:
                    logger.debug('key %s without value', key)
                    continue
                value = value.strip()
                if not value:
                    logger.debug('key %s without value', key)
                    continue
                key = key.strip().lower()
                if key == 'species_common_name':
                    new_context['Species'] = species_map[value.lower()]
                elif key in annotation_map:
                    new_context[annotation_map[key]] = value
                else:
                    new_context[key] = value
            d['graph']['edges'][i]['metadata']['evidences'][j][EXPERIMENT_CONTEXT] = new_context
    return d
def map_cbn ( d ) : for i , edge in enumerate ( d [ 'graph' ] [ 'edges' ] ) : if 'metadata' not in edge : continue if 'evidences' not in edge [ 'metadata' ] : continue for j , evidence in enumerate ( edge [ 'metadata' ] [ 'evidences' ] ) : if EXPERIMENT_CONTEXT not in evidence : continue new_context = { } for key , value in evidence [ EXPERIMENT_CONTEXT ] . items ( ) : if not value : logger . debug ( 'key %s without value' , key ) continue value = value . strip ( ) if not value : logger . debug ( 'key %s without value' , key ) continue key = key . strip ( ) . lower ( ) if key == 'species_common_name' : new_context [ 'Species' ] = species_map [ value . lower ( ) ] elif key in annotation_map : new_context [ annotation_map [ key ] ] = value else : new_context [ key ] = value '''
            for k, v in annotation_map.items():
                if k not in ctx:
                    continue

                d['graph']['edges'][i]['metadata']['evidences'][j][EXPERIMENT_CONTEXT][v] = ctx[k]
                del d['graph']['edges'][i]['metadata']['evidences'][j][EXPERIMENT_CONTEXT][k]

            if 'species_common_name' in ctx:
                species_name = ctx['species_common_name'].strip().lower()
                d['graph']['edges'][i]['metadata']['evidences'][j][EXPERIMENT_CONTEXT]['Species'] = species_map[
                    species_name]
                del d['graph']['edges'][i]['metadata']['evidences'][j][EXPERIMENT_CONTEXT][
                    'species_common_name']
            ''' d [ 'graph' ] [ 'edges' ] [ i ] [ 'metadata' ] [ 'evidences' ] [ j ] [ EXPERIMENT_CONTEXT ] = new_context return d
Pre-processes the JSON from the CBN.
Pre - processes the JSON from the CBN .
"""Pre-processes the JSON from the CBN.

    - removes statements without evidence, or with placeholder evidence

    :param dict d: Raw JGIF from the CBN
    :return: Preprocessed JGIF
    :rtype: dict
    """ # ctx = {k.strip().lower(): v.strip() for k, v in evidence[EXPERIMENT_CONTEXT].items() if v.strip()} '''
            for k, v in annotation_map.items():
                if k not in ctx:
                    continue

                d['graph']['edges'][i]['metadata']['evidences'][j][EXPERIMENT_CONTEXT][v] = ctx[k]
                del d['graph']['edges'][i]['metadata']['evidences'][j][EXPERIMENT_CONTEXT][k]

            if 'species_common_name' in ctx:
                species_name = ctx['species_common_name'].strip().lower()
                d['graph']['edges'][i]['metadata']['evidences'][j][EXPERIMENT_CONTEXT]['Species'] = species_map[
                    species_name]
                del d['graph']['edges'][i]['metadata']['evidences'][j][EXPERIMENT_CONTEXT][
                    'species_common_name']
            ''' # TODO can this be replaced with edge as well?
None
dict
d
Raw JGIF from the CBN
Raw JGIF from the CBN