What a model is: the dataclasses behind model.toml, and the rules a model.toml must follow
parse_model checks every rule that can be checked without the files on disk; the rest (files
exist, hashes match, licence texts are there) is odezoo registry check.
Paper¶
Paper(title: str, authors: tuple[str, ...], journal: str, year: int, doi: str | None = None, pubmed: int | None = None, note: str | None = None)A paper: the one that describes a model, or another one it refers to
Attributes
title: str- The paper’s title
authors: tuple[str, ...]- The authors, in the paper’s order
journal: str- The journal it was published in
year: int- The year it was published
doi: str | None- The DOI, without
https://doi.org/ pubmed: int | None- The PubMed id; a paper has a DOI, a PubMed id or both
note: str | None- For a reference, how it relates to the model
Source¶
Source(type: str, workspace: str | None = None, commit: str | None = None, path: str | None = None, exposure: str | None = None, repo: str | None = None, record: int | None = None, filename: str | None = None, url: str | None = None)Where upstream keeps a file; which fields are set depends on type
Attributes
type: strpmr,github,zenodoorurlworkspace: str | None- PMR: the workspace URL
commit: str | None- PMR and GitHub: the full commit id the file is pinned to
path: str | None- PMR and GitHub: the file’s path in the workspace or repository
exposure: str | None- PMR: the exposure page, if the workspace has one
repo: str | None- GitHub: the repository, as
owner/name record: int | None- Zenodo: the record id
filename: str | None- Zenodo: the file’s name in the record
url: str | None- Any other host: the URL the file downloads from
Source.url_for_download¶
Source.url_for_download() -> strReturn the URL that serves the file’s bytes
Returns
- str
- For PMR the workspace’s
rawfileURL atcommit, for GitHub theraw.githubusercontent.comURL atcommit, for Zenodo the record’s download URL, and otherwiseurl
Source.page_url¶
Source.page_url() -> strReturn a page about the file for people to open, rather than the file itself
Returns
- str
- For PMR the exposure (else the workspace), for GitHub the file at
commit, for Zenodo the record, and otherwiseurl
Version¶
Version(id: str, format: str, sha256: str, license: str, added: date, file: str | None = None, source: Source | None = None, derived_from: str | None = None, notes: str | None = None)One version of a model: a file, identified by its sha256
Attributes
id: str- The version’s id, such as
pmr-cb090c9for a file from PMR orv1for one of our own format: strcellmlorodesha256: str- The sha256 of the file’s bytes, in lowercase hex
license: str- The SPDX id of the file’s licence
added: date- When the version was added to the registry
file: str | None- The name of the copy kept in the model’s folder,
<id>.<ext>, if there is one source: Source | None- Where upstream keeps the file, if anywhere
derived_from: str | None- The id of the version this one was edited from
notes: str | None- What was changed, and why
Attributes
| Name | Type | Description |
|---|---|---|
ext | str | The file extension of the version’s format, such as .cellml |
Model¶
Model(id: str, name: str, categories: tuple[str, ...], reviewed: bool, paper: Paper, versions: tuple[Version, ...], family: str | None = None, description: str | None = None, keywords: tuple[str, ...] = (), species: str | None = None, cell_type: str | None = None, default_version: str | None = None, references: tuple[Paper, ...] = ())A model in the registry: its paper, how to find it, and its versions
Attributes
id: str- The model’s id, which is also its folder’s name, such as
beeler_reuter_1977 name: str- A name for people to read
categories: tuple[str, ...]- Categories from
CATEGORIES, PMR’s top-level ones reviewed: bool- True once a maintainer has run the model and compared it with the paper
paper: Paper- The paper that describes the model
versions: tuple[Version, ...]- Every version, oldest first
family: str | None- An id shared by models that are cell-type variants of one another
description: str | None- A few sentences about the model
keywords: tuple[str, ...]- Keywords for search, as
normalize_keywordwrites them species: str | None- The species, in lowercase
cell_type: str | None- The cell type, such as
ventricular myocyte, epicardial default_version: str | None- The version to fetch when none is asked for; without it, the newest
references: tuple[Paper, ...]- Other papers the model draws on
Attributes
| Name | Type | Description |
|---|---|---|
formats | tuple[str, ...] | The formats the versions are in, each once, in the order of the versions |
Model.version¶
Model.version(id: str) -> VersionReturn the version with the id id
Parameters
id: str- A version id, such as
pmr-cb090c9
Returns
- Version
- The version
Raises
VersionNotFound- If the model has no such version
normalize_keyword¶
normalize_keyword(text: str) -> strWrite a keyword the way the registry stores it
Parameters
text: str- A keyword as typed
Returns
- str
textin lowercase, each run of whitespace made one space, none at the ends
parse_model¶
parse_model(data: Mapping[str, Any], *, where: str) -> ModelBuild a Model from a parsed model.toml (or its model_to_dict form)
Parameters
data: Mapping[str, Any]- The parsed TOML or JSON
where: str- The file it comes from, which error messages name
Returns
- Model
- The model
Raises
RegistryError- At the first rule that is broken, naming
whereand the field
version_to_dict¶
version_to_dict(version: Version) -> dict[str, Any]Return the dict form of a version, as in model.toml
Parameters
version: Version- The version
Returns
- dict[str, Any]
- The fields that are set, with
addedas aYYYY-MM-DDstring
model_to_dict¶
model_to_dict(model: Model) -> dict[str, Any]Return the JSON form of a model, in the field order of model.toml
Parameters
model: Model- The model
Returns
- dict[str, Any]
- The fields that are set, which
parse_modelreads back as the same model
Attributes¶
| Name | Type | Value |
|---|---|---|
CATEGORIES | tuple[str, ...] | ('calcium_dynamics', 'cardiovascular_circulation', 'cell_cycle', 'cell_migration', 'circadian_rhythms', 'electrophysiology', 'endocrine', 'excitation_contraction_coupling', 'gene_regulation', 'hepatology', 'immunology', 'ion_transport', 'mechanical_constitutive_laws', 'metabolism', 'myofilament_mechanics', 'neurobiology', 'ph_regulation', 'protein_modules', 'signal_transduction', 'synthetic_biology') |
FORMATS | dict[str, str] | {'cellml': '.cellml', 'ode': '.ode'} |
MIRROR_LICENSES | frozenset[str] | frozenset({'CC-BY-3.0', 'CC-BY-4.0', 'CC-BY-SA-3.0', 'CC-BY-SA-4.0', 'CC0-1.0', 'MIT', 'BSD-2-Clause', 'BSD-3-Clause', 'Apache-2.0', 'GPL-2.0-only', 'GPL-2.0-or-later', 'GPL-3.0-only', 'GPL-3.0-or-later', 'LGPL-2.1-or-later', 'LGPL-3.0-or-later'}) |
MODEL_ID | re.compile('^[a-z][a-z0-9_]*$') | |
VERSION_ID | re.compile('^[a-z0-9][a-z0-9.-]*$') | |
SHA256 | re.compile('^[0-9a-f]{64}$') | |
GIT_COMMIT | re.compile('^[0-9a-f]{40}$') | |
GITHUB_REPO | re.compile('^[^/\\s]+/[^/\\s]+$') | |
LICENSE_ID | re.compile('^[A-Za-z0-9][A-Za-z0-9.+-]*$') | |
KNOWN_LICENSES | dict[str, str] | {id.lower(): id for id in (*MIRROR_LICENSES, 'unknown')} |
DOI | re.compile('^10\\.\\d{4,9}/\\S+$') | |
ISO_DATE | re.compile('^\\d{4}-\\d{2}-\\d{2}$') | |
SOURCE_FIELDS | dict[str, tuple[tuple[str, ...], tuple[str, ...]]] | {'pmr': (('workspace', 'commit', 'path'), ('exposure',)), 'github': (('repo', 'commit', 'path'), ()), 'zenodo': (('record', 'filename'), ()), 'url': (('url',), ())} |
PAPER_FIELDS | ('title', 'authors', 'journal', 'year', 'doi', 'pubmed') | |
VERSION_FIELDS | ('id', 'format', 'sha256', 'license', 'file', 'source', 'derived_from', 'added', 'notes') | |
MODEL_FIELDS | ('id', 'name', 'family', 'description', 'categories', 'keywords', 'species', 'cell_type', 'reviewed', 'default_version', 'paper', 'references', 'versions') |