Skip to content

webservices.registry

The identifiers.org registry.

The registry defines, for every collection (chebi, uniprot, taxonomy, ...), the pattern a valid term matches and the providers which resolve a term to a web page. pymetadata uses it to validate annotations and to build cross references.

The registry is downloaded once and cached in CACHE_PATH / "identifiers_registry.json", and refreshed when the local copy is older than the cache duration of CACHE_DURATION_REGISTRY hours. Namespaces are added and corrected continuously, so the registry is refreshed daily, much more often than the ontology information of pymetadata.webservices.ols. If the refresh fails, because identifiers.org is unreachable, the outdated copy is used and a warning is logged.

from pymetadata.webservices.registry import Registry

registry = Registry()
namespace = registry.ns_dict["chebi"]
print(namespace.pattern)  # ^CHEBI:\d+$

See https://identifiers.org/ and https://docs.identifiers.org/articles/api.html.

Resource dataclass

Resource(
    id,
    providerCode,
    name,
    urlPattern,
    mirId,
    description,
    official,
    sampleId,
    resourceHomeUrl,
    institution,
    location,
    deprecated,
    deprecationDate,
    protectedUrls=False,
    renderProtectedLanding=False,
    authHelpUrl=None,
    authHelpDescription=None,
)

A provider which resolves terms of a collection.

A collection can have several providers; urlPattern contains the placeholder {$id} which is replaced by the term to build the url of an entry.

from_dict classmethod

from_dict(d)

Create a resource from a registry response, ignoring unknown keys.

Namespace dataclass

Namespace(
    id,
    prefix,
    name,
    pattern,
    namespaceEmbeddedInLui,
    description,
    mirId=None,
    resources=None,
    created=None,
    modified=None,
    sampleId=None,
    deprecated=False,
    deprecationDate=None,
)

A collection of the identifiers.org registry.

Attributes:

Name Type Description
prefix str | None

prefix of the collection, e.g., chebi

name str

name of the collection

pattern str

regular expression a valid term matches

namespaceEmbeddedInLui bool

whether the prefix is part of the term itself, as for CHEBI:33699 and GO:0005829

resources list | None

providers which resolve terms of this collection

from_dict classmethod

from_dict(d)

Create a namespace from a registry response, ignoring unknown keys.

Registry

Registry(
    cache_duration=CACHE_DURATION_REGISTRY, cache=True
)

The identifiers.org registry, cached on disk.

The cached registry is refreshed once it is older than the cache duration. If identifiers.org cannot be reached, the outdated copy is used however old it is, so that validating annotations keeps working offline.

Attributes:

Name Type Description
ns_dict dict[str, Namespace]

namespaces of the registry by prefix

registry_path

path of the cached registry

Load the registry, updating the cached copy if it is outdated.

Parameters:

Name Type Description Default
cache_duration float

maximum age of the cached registry in hours

CACHE_DURATION_REGISTRY
cache bool

use the cached registry; if False the registry is downloaded and the cache is not read, not even when the download fails

True

Raises:

Type Description
WebserviceError

if the registry is neither cached nor retrievable

update

update()

Download the registry and return the namespaces.

Returns:

Type Description
dict[str, Namespace]

Namespaces of the registry by prefix.

Raises:

Type Description
WebserviceError

if the registry could not be downloaded

namespaces_from_dict staticmethod

namespaces_from_dict(data)

Build the namespaces from the serialized registry.

Parameters:

Name Type Description Default
data dict[str, Any]

content of the cached registry

required

Returns:

Type Description
dict[str, Namespace]

Namespaces of the registry by prefix.

update_registry staticmethod

update_registry(registry_path=None)

Download the registry from the identifiers.org web service.

Namespaces without a prefix are skipped.

Parameters:

Name Type Description Default
registry_path Path | None

path to cache the registry in, not cached if None

None

Returns:

Type Description
dict[str, Namespace]

Namespaces of the registry by prefix.

Raises:

Type Description
WebserviceError

if the registry could not be downloaded

load_registry staticmethod

load_registry(registry_path)

Load the registry from the cached file, downloading it if missing.

Parameters:

Name Type Description Default
registry_path Path

path of the cached registry

required

Returns:

Type Description
dict[str, Namespace]

Namespaces of the registry by prefix.

get_registry

get_registry()

Get the shared registry, loading it on first use.

The registry is loaded lazily so that importing pymetadata does not query the identifiers.org web service.

Returns:

Type Description
Registry

The shared registry instance.