Esempio n. 1
0
def get_concept_categories():  # noqa: E501
    """get_concept_categories

    Get a list of concept categories and number of their concept instances documented by the knowledge source. These types should be mapped onto the Translator-endorsed Biolink Model concept type classes with local types, explicitly added as mappings to the Biolink Model YAML file.  # noqa: E501


    :rtype: List[BeaconConceptCategory]
    """
    data = utils.load_bioentities()

    categories = []

    for key in data['bioentity'].keys():
        if key in blm.schema().classes:
            category_id = f'blm:{key}'
            category = key
            uri = blm.class_uri(key)
        else:
            category_id = f'blm:{blm.DEFAULT_CATEGORY}'
            category = blm.DEFAULT_CATEGORY
            uri = blm.class_uri(blm.DEFAULT_CATEGORY)

        categories.append(
            BeaconConceptCategory(
                category=category,
                local_category=key,
                description=None,
                frequency=None,
            ))

    return categories
Esempio n. 2
0
def get_predicates():  # noqa: E501
    """get_predicates

    Get a list of predicates used in statements issued by the knowledge source  # noqa: E501


    :rtype: List[BeaconPredicate]
    """
    data = utils.load_kmap()

    predicates = []

    s = set()
    for a in data['associations']:
        s.add(safe_get(a, 'predicate'))

    for p in s:
        if p.replace('_', ' ') in blm.schema().slots:
            edge_label = p.replace(' ', '_')
            predicate_id = f'blm:{edge_label}'
            relation = edge_label
            uri = blm.slot_uri(edge_label)
        else:
            predicate_id = f'blm:{blm.DEFAULT_EDGE_LABEL}'
            edge_label = blm.DEFAULT_EDGE_LABEL
            relation = p
            uri = blm.slot_uri(blm.DEFAULT_EDGE_LABEL)

        try:
            description = blm.schema().slots[edge_label.replace(
                '_', ' ')].description
        except:
            description = None

        predicates.append(
            BeaconPredicate(description=description,
                            edge_label=edge_label,
                            relation=relation,
                            frequency=None))

    return predicates
Esempio n. 3
0
def build_statement(object_id, object_name, object_category, subject_id,
                    subject_name, subject_category, predicate_id,
                    predicate_name):
    if predicate_id is None:
        predicate_id = predicate_name
    if predicate_name.replace('_', ' ') not in blm.schema().slots:
        predicate_name = blm.DEFAULT_EDGE_LABEL

    beacon_subject = BeaconStatementSubject(id=utils.fix_curie(subject_id),
                                            name=subject_name,
                                            categories=[subject_category])
    beacon_object = BeaconStatementObject(id=utils.fix_curie(object_id),
                                          name=object_name,
                                          categories=[object_category])
    beacon_predicate = BeaconStatementPredicate(edge_label=predicate_name,
                                                relation=predicate_id,
                                                negated=False)
    statement_id = '{}:{}:{}'.format(subject_id, predicate_name, object_id)
    return BeaconStatement(id=statement_id,
                           subject=beacon_subject,
                           predicate=beacon_predicate,
                           object=beacon_object)
def lookup_category(prefix:str) -> str:
    """
    Returns the category that this prefix belongs to
    """
    global _category_map

    if _category_map == None:
        response = requests.get(bioentities_endpoint)

        if response.ok:
            _category_map = {}
            data = response.json()
            for category, prefixes in data['bioentity'].items():
                for prefix in prefixes:
                    _category_map[prefix.lower()] = category
        else:
            abort(500, 'Could not connect to: {}'.format(bioentities_endpoint))

    category = _category_map.get(prefix.lower())

    if category in blm.schema().classes:
        return category
    else:
        return blm.DEFAULT_CATEGORY
Esempio n. 5
0
def get_knowledge_map():  # noqa: E501
    """get_knowledge_map

    Get a high level knowledge map of the all the beacons by subject semantic type, predicate and semantic object type  # noqa: E501


    :rtype: List[BeaconKnowledgeMapStatement]
    """
    data = utils.load_kmap()

    d = defaultdict(lambda: defaultdict(set))

    statements = []

    for a in data['associations']:
        subject_category = safe_get(a, 'subject', 'semantic_type')
        subject_prefix = safe_get(a, 'subject', 'prefix')
        predicate = safe_get(a, 'predicate')
        object_category = safe_get(a, 'object', 'semantic_type')
        object_prefix = safe_get(a, 'object', 'prefix')
        endpoint = safe_get(a, 'endpoint')

        k = f'{subject_category}{predicate}{object_category}'

        d[k]['subject_prefix'].add(subject_prefix)
        d[k]['object_prefix'].add(object_prefix)
        d[k]['subject_category'] = subject_category
        d[k]['object_category'] = object_category
        d[k]['predicate'] = predicate
        d[k]['endpoint'] = endpoint

    for p in d.values():
        object_category = p['object_category']
        subject_category = p['subject_category']

        if object_category not in blm.schema().classes:
            object_category = blm.DEFAULT_CATEGORY

        if subject_category not in blm.schema().classes:
            subject_category = blm.DEFAULT_CATEGORY

        if p['predicate'].replace('_', ' ') in blm.schema().slots:
            edge_label = p['predicate'].replace(' ', '_')
            relation = edge_label
        else:
            edge_label = blm.DEFAULT_EDGE_LABEL
            relation = p['predicate']

        o = BeaconKnowledgeMapObject(category=object_category,
                                     prefixes=list(p['object_prefix']))
        s = BeaconKnowledgeMapSubject(category=subject_category,
                                      prefixes=list(p['subject_prefix']))

        r = BeaconKnowledgeMapPredicate(edge_label=edge_label,
                                        relation=relation,
                                        negated=False)

        statements.append(
            BeaconKnowledgeMapStatement(subject=s, object=o, predicate=r))

    return statements