Skip to content

webservices.unichem

Substance cross references from UniChem.

UniChem maps a structure, identified by its InChIKey, to the entries of many chemistry databases, which gives cross references for a substance without having to query every database separately.

from pymetadata.webservices.unichem import UnichemQuery

query = UnichemQuery()
xrefs = query.query_xrefs_for_inchikey("AAOVKJBEBIDNHE-UHFFFAOYSA-N")

See https://www.ebi.ac.uk/unichem/info/webservices.

UnichemSource dataclass

UnichemSource(
    sourceID,
    name,
    nameLabel=None,
    nameLong=None,
    srcUrl=None,
    baseIdUrl=None,
    description=None,
    UCICount=None,
    created=None,
    lastChecked=None,
    srcLastUpdated=None,
    srcDetails=None,
    updateComments=None,
    private=None,
)

Database known to UniChem, see the sources endpoint of the web service.

Only sourceID and name are required. UniChem adds and removes the descriptive fields without notice, so they are optional, and UnichemSource.from_dict ignores fields which are not declared here.

Attributes:

Name Type Description
sourceID int

id of the source in UniChem

name str

unique name of the source in UniChem, always lower case

nameLabel str | None

name suitable as label of the source, in the case used by the source

nameLong str | None

full name of the source, as defined by the source

srcUrl str | None

home page of the source

baseIdUrl str | None

base url for links to a compound in the source; the identifier of the compound is appended or replaces {$id}

description str | None

description of the content of the source

UCICount int | None

number of UniChem compound identifiers in the source

created str | None

date the source was added to UniChem

lastChecked str | None

date UniChem checked the source for an update

srcLastUpdated str | None

date of the last update of the source

srcDetails str | None

details on the source

updateComments str | None

comments on the update of the source

private bool | None

the source is not public

from_dict classmethod

from_dict(data)

Create a source from a source of the web service or of the cache.

Parameters:

Name Type Description Default
data dict[str, Any]

fields of the source, fields unknown to UnichemSource are ignored

required

Returns:

Type Description
UnichemSource

The source.

UnichemQuery

UnichemQuery(cache_path=None, cache=None)

Queries against the UniChem web service.

The sources of UniChem are retrieved once and shared by all instances. Responses are cached on disk for CACHE_DURATION_ONTOLOGY hours, see pymetadata.CACHE_USE. If UniChem cannot be reached, cached content is used however old it is.

Initialize the query.

Parameters:

Name Type Description Default
cache_path Path | None

directory for cached responses, defaults to pymetadata.CACHE_PATH

None
cache bool | None

cache responses, defaults to pymetadata.CACHE_USE

None

get_sources

get_sources()

Get the databases known to UniChem, from the cache or the service.

Returns:

Type Description
dict[int, UnichemSource]

The sources by their UniChem source id.

Raises:

Type Description
WebserviceError

if the sources are neither cached nor retrievable

query_xrefs_for_inchikey

query_xrefs_for_inchikey(inchikey)

Get the cross references for a structure.

Parameters:

Name Type Description Default
inchikey str

InChIKey of the structure, e.g., AAOVKJBEBIDNHE-UHFFFAOYSA-N, case is ignored

required

Returns:

Type Description
list[CrossReference]

One cross reference per database which contains the structure,

list[CrossReference]

empty for an invalid InChIKey.