src/pybel/grounding.py
def _process_annotations(
    data,
    remove_ungrounded: bool = False,
    skip_namespaces: Optional[Collection[str]] = None,
) -> None:
    """Process the annotations in a PyBEL edge data dictionary."""
    cell_line_entities = data[ANNOTATIONS].get('CellLine')
    if cell_line_entities:
        ne = []
        for entity in cell_line_entities:
            if entity[NAMESPACE] == 'CellLine':
                _namespaces = [
                    'efo',
                    # 'clo',  # FIXME implement CLO in PyOBO then uncomment
                ]
                g_prefix, g_identifier, g_name = pyobo.ground(_namespaces, entity[IDENTIFIER])
                if g_prefix and g_identifier:
                    ne.append(Entity(namespace=g_prefix, identifier=g_identifier, name=g_name))
                elif not remove_ungrounded:
                    logger.warning('could not ground CellLine: "%s"', entity[IDENTIFIER])
                    ne.append(entity)
        data[ANNOTATIONS]['CellLine'] = ne

    # fix text locations
    text_location = data[ANNOTATIONS].get('TextLocation')
    if text_location:
        data[ANNOTATIONS]['TextLocation'] = [
            text_location_labels.get(entity.identifier, entity)
            for entity in text_location
        ]

    # remap category names
    data[ANNOTATIONS] = {
        _BEL_ANNOTATION_PREFIX_CATEGORY_MAP.get(category, category): entities
        for category, entities in data[ANNOTATIONS].items()
    }
    # fix namespaces that were categories before
    for category, entities in data[ANNOTATIONS].items():
        if category in CATEGORY_BLACKLIST:
            continue

        ne = []
        for entity in entities:
            if not isinstance(entity, dict):
                raise TypeError(f'entity should be a dict. got: {entity}')
            nn = _BEL_ANNOTATION_PREFIX_MAP.get(entity[NAMESPACE])
            if nn is not None:
                entity[NAMESPACE] = nn

            _process_concept(concept=entity, skip_namespaces=skip_namespaces)
            ne.append(entity)
        data[ANNOTATIONS][category] = ne
Process the annotations in a PyBEL edge data dictionary.
Process the annotations in a PyBEL edge data dictionary.
Process the annotations in a PyBEL edge data dictionary .
def _process_annotations(
    data,
    remove_ungrounded: bool = False,
    skip_namespaces: Optional[Collection[str]] = None,
) -> None:
    cell_line_entities = data[ANNOTATIONS].get('CellLine')
    if cell_line_entities:
        ne = []
        for entity in cell_line_entities:
            if entity[NAMESPACE] == 'CellLine':
                _namespaces = [
                    'efo',
                ]
                g_prefix, g_identifier, g_name = pyobo.ground(_namespaces, entity[IDENTIFIER])
                if g_prefix and g_identifier:
                    ne.append(Entity(namespace=g_prefix, identifier=g_identifier, name=g_name))
                elif not remove_ungrounded:
                    logger.warning('could not ground CellLine: "%s"', entity[IDENTIFIER])
                    ne.append(entity)
        data[ANNOTATIONS]['CellLine'] = ne
    text_location = data[ANNOTATIONS].get('TextLocation')
    if text_location:
        data[ANNOTATIONS]['TextLocation'] = [
            text_location_labels.get(entity.identifier, entity)
            for entity in text_location
        ]
    data[ANNOTATIONS] = {
        _BEL_ANNOTATION_PREFIX_CATEGORY_MAP.get(category, category): entities
        for category, entities in data[ANNOTATIONS].items()
    }
    for category, entities in data[ANNOTATIONS].items():
        if category in CATEGORY_BLACKLIST:
            continue
        ne = []
        for entity in entities:
            if not isinstance(entity, dict):
                raise TypeError(f'entity should be a dict. got: {entity}')
            nn = _BEL_ANNOTATION_PREFIX_MAP.get(entity[NAMESPACE])
            if nn is not None:
                entity[NAMESPACE] = nn
            _process_concept(concept=entity, skip_namespaces=skip_namespaces)
            ne.append(entity)
        data[ANNOTATIONS][category] = ne
def _process_annotations ( data , remove_ungrounded : bool = False , skip_namespaces : Optional [ Collection [ str ] ] = None , ) -> None : cell_line_entities = data [ ANNOTATIONS ] . get ( 'CellLine' ) if cell_line_entities : ne = [ ] for entity in cell_line_entities : if entity [ NAMESPACE ] == 'CellLine' : _namespaces = [ 'efo' , ] g_prefix , g_identifier , g_name = pyobo . ground ( _namespaces , entity [ IDENTIFIER ] ) if g_prefix and g_identifier : ne . append ( Entity ( namespace = g_prefix , identifier = g_identifier , name = g_name ) ) elif not remove_ungrounded : logger . warning ( 'could not ground CellLine: "%s"' , entity [ IDENTIFIER ] ) ne . append ( entity ) data [ ANNOTATIONS ] [ 'CellLine' ] = ne text_location = data [ ANNOTATIONS ] . get ( 'TextLocation' ) if text_location : data [ ANNOTATIONS ] [ 'TextLocation' ] = [ text_location_labels . get ( entity . identifier , entity ) for entity in text_location ] data [ ANNOTATIONS ] = { _BEL_ANNOTATION_PREFIX_CATEGORY_MAP . get ( category , category ) : entities for category , entities in data [ ANNOTATIONS ] . items ( ) } for category , entities in data [ ANNOTATIONS ] . items ( ) : if category in CATEGORY_BLACKLIST : continue ne = [ ] for entity in entities : if not isinstance ( entity , dict ) : raise TypeError ( f'entity should be a dict. got: {entity}' ) nn = _BEL_ANNOTATION_PREFIX_MAP . get ( entity [ NAMESPACE ] ) if nn is not None : entity [ NAMESPACE ] = nn _process_concept ( concept = entity , skip_namespaces = skip_namespaces ) ne . append ( entity ) data [ ANNOTATIONS ] [ category ] = ne
Process the annotations in a PyBEL edge data dictionary.
Process the annotations in a PyBEL edge data dictionary .
"""Process the annotations in a PyBEL edge data dictionary.""" # 'clo',  # FIXME implement CLO in PyOBO then uncomment # fix text locations # remap category names # fix namespaces that were categories before
data
remove_ungrounded
bool
skip_namespaces
Optional[Collection[str]]