core.annotation¶
MIRIAM annotations.
An annotation combines a qualifier (BQB, BQM) with a resource pointing at a
database entry, forming the statement this element is CHEBI:17234.
RDFAnnotation parses the notations found in the wild, normalizes them to
identifiers.org compact identifiers and validates them against the
identifiers.org registry. RDFAnnotationData resolves what an identifier refers
to via the Ontology Lookup Service.
from pymetadata.core.annotation import RDFAnnotation
from pymetadata.core.miriam import BQB
annotation = RDFAnnotation(qualifier=BQB.IS, resource="chebi/CHEBI:33699")
print(annotation.resource_normalized) # https://identifiers.org/CHEBI:33699
print(annotation.validate())
ProviderType
¶
Bases: str, Enum
Resolver a resource was written for.
IDENTIFIERS_ORG and BIOREGISTRY_IO resources can be normalized and
validated, NONE marks an arbitrary url which is kept as it is.
RDFAnnotation
¶
RDFAnnotation class.
Basic storage of annotation information. This consists of the relation and the resource. The annotations can be attached to other objects thereby forming triples which can be converted to RDF.
Resource can be either
http(s)://identifiers.org/collection/term, i.e., a identifiers.org URIcollection/term, i.e., the combination of collection and termhttp(s)://arbitrary.url, an arbitrary URL- urn:miriam:uniprot:P03023
- https://bioregistry.io/chebi:15996 urls via the bioregistry provider
Parse a resource into collection and term.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qualifier
|
BQB | BQM
|
MIRIAM qualifier of the annotation |
required |
resource
|
str
|
the annotated resource, as an identifiers.org url
( |
required |
validate
|
bool
|
log warnings and errors for an invalid annotation |
True
|
Raises:
| Type | Description |
|---|---|
ValueError
|
if the qualifier or the resource is missing, or if the resource is not a string |
resource_normalized
property
¶
Normalize resource for given annotation.
This is the correct usage. Resources are normalized to identifiers.org
compact identifiers of the form
https://identifiers.org/<prefix>:<accession>. If the namespace is
embedded in the LUI the prefix is already part of the term, otherwise
the prefix of the identifiers.org registry is prepended.
shorten_compact_term
staticmethod
¶
Shorten the compact terms and return term.
If the namespace is not embedded in the term return the shortened term.
check_miriam_term
¶
Check that term follows id pattern for collection.
Uses the Identifiers collection information.
check_qualifier
staticmethod
¶
validate
¶
Validate qualifier and term of the annotation.
Returns:
| Type | Description |
|---|---|
bool
|
True if the qualifier is a MIRIAM qualifier and the term matches the |
bool
|
pattern of its collection. |
RDFAnnotationData
¶
Bases: RDFAnnotation
An annotation with the information behind the identifier resolved.
Constructing the object resolves the cross references: for every provider
the identifiers.org registry lists for the collection, the url pattern is
filled in with the term. query_ols then adds label, description and
synonyms from the Ontology Lookup Service, and replaces xrefs with the
cross references reported by OLS.
Attributes:
| Name | Type | Description |
|---|---|---|
url |
str | None
|
url of the first provider of the collection |
label |
str | None
|
name of the term |
description |
str | None
|
definition of the term |
synonyms |
list
|
synonyms of the term |
xrefs |
list
|
cross references of the term |
warnings |
list
|
problems which do not invalidate the annotation |
errors |
list
|
problems which do |
Example
Raises:
| Type | Description |
|---|---|
ValueError
|
if the collection of the annotation is not in the registry |
Resolve the cross references of the annotation.
query_ols
¶
Resolve the term in the Ontology Lookup Service.
Fills in label, description and synonyms, and replaces xrefs
with the cross references reported by OLS. Requires network access;
errors are collected in errors instead of raising.
Returns:
| Type | Description |
|---|---|
dict
|
The processed OLS response. |