ppktstore.model module

class ppktstore.model.PhenopacketInfo[source]

Bases: object

Phenopacket info includes a phenopacket plus metadata, which at this time is just a relative path wrt. the enclosing cohort.

abstract property path: str

Path of the phenopacket source relative from the enclosing cohort.

abstract property phenopacket: Phenopacket

The phenopacket.

class ppktstore.model.EagerPhenopacketInfo(path: str, phenopacket: Phenopacket)[source]

Bases: PhenopacketInfo

Phenopacket info with eagerly loaded phenopacket.

static from_path(path: str, pp_path: Path) EagerPhenopacketInfo[source]

Load phenopacket from a pp_path.

static from_phenopacket(path: str, pp: Phenopacket) EagerPhenopacketInfo[source]

Create EagerPhenopacketInfo from a provided phenopacket.

property path: str

Path of the phenopacket source relative from the enclosing cohort.

property phenopacket: Phenopacket

The phenopacket.

class ppktstore.model.CohortInfo(name: str, path: str, phenopackets: Collection[PhenopacketInfo])[source]

Bases: object

Cohort of a Phenopacket store.

Includes cohort-level metadata and a sequence of phenopacket infos for the included phenopackets.

name: str

Cohort name, e.g. FBN1.

path: str

Path of the cohort relative from the enclosing source.

phenopackets: Collection[PhenopacketInfo]

The cohort phenopacket infos.

iter_phenopackets() Iterator[Phenopacket][source]

Get an iterator with all phenopackets belonging to the cohort.

class ppktstore.model.PhenopacketStore[source]

Bases: object

PhenopacketStore provides the data and metadata for Phenopacket Store cohorts.

Use from_release_zip() or from_notebook_dir() to open a store instance.

static from_release_zip(zip_file: ZipFile, strategy: Literal['eager', 'lazy'] = 'eager') PhenopacketStore[source]

Read PhenopacketStore from a release ZIP archive.

The archive structure must match the structure of the ZIP archives created by ppktstore.archive.PhenopacketStoreArchiver. Only JSON phenopacket format is supported at the moment.

Strategy

The phenopackets can be loaded in an eager or lazy fashion.

The ‘eager’ strategy loads all phenopackets during the execution of this function. This may do more work than necessary, especially if only several cohorts are needed.

The ‘lazy’ strategy only scans the ZIP for phenopackets and the actual parsing is done on demand, when accessing the PhenopacketInfo.phenopacket property. In result, the lazy loading will only succeed if the ZIP handle is kept open.

Note

We recommend using Python’s context manager to ensure zip_handle is closed:

>>> import zipfile
>>> with zipfile.ZipFile("all_phenopackets.zip") as zf:
...   ps = PhenopacketStore.from_release_zip(zf)
...   # Do things here...
param zip_file:

a ZIP archive handle.

param strategy:

a str with strategy for loading phenopackets, one of {‘eager’, ‘lazy’}.

returns:

PhenopacketStore with data read from the archive.

static from_notebook_dir(nb_dir: str, pp_dir: str = 'phenopackets') PhenopacketStore[source]

Create PhenopacketStore from Phenopacket store notebook dir nb_dir.

We expect the nb_dir to include a folder per cohort, and the phenopackets should be stored in pp_dir sub-folder (pp_dir="phenopackets" by default).

The phenopackets are loaded eagerly into memory.

Note

The function is intended for private use only and we encourage using the Phenopacket Store registry API presented in Load Phenopacket Store section.

static from_cohorts(name: str, path: Path, cohorts: Iterable[CohortInfo]) PhenopacketStore[source]

Create PhenopacketStore from cohorts.

Parameters:
  • name – a str with the store name (e.g. v0.1.23 or any other str will do).

  • path – a path to the store root to resolve phenopacket locations.

  • cohorts – an iterable with cohorts.

abstract property name: str

Get a str with the Phenopacket Store name. Most of the time, the name corresponds to the release tag (e.g. 0.1.18).

abstract property path: Path

Get path to the phenopacket store resource.

abstractmethod cohorts() Collection[CohortInfo][source]

Get a collection of all Phenopacket Store cohorts.

abstractmethod cohort_for_name(name: str) CohortInfo[source]

Retrieve a Phenopacket Store cohort by its name.

Parameters:

name – a str with the cohort name (e.g. SUOX).

Raises:

KeyError – if no cohort with such name exists.

iter_cohort_phenopackets(name: str) Iterator[Phenopacket][source]

Get an iterator with all phenopackets of a cohort.

Parameters:

name – a str with the cohort name.

cohort_names() Iterator[str][source]

Get an iterator with names of all Phenopacket Store cohorts.

cohort_count() int[source]

Compute the count of Phenopacket Store cohorts.

phenopacket_count() int[source]

Compute the total number of phenopackets available in Phenopacket Store.

class ppktstore.model.DefaultPhenopacketStore(name: str, path: Path, cohorts: Iterable[CohortInfo])[source]

Bases: PhenopacketStore

property name: str

Get a str with the Phenopacket Store name. Most of the time, the name corresponds to the release tag (e.g. 0.1.18).

property path: Path

Get path to the phenopacket store resource.

cohorts() Collection[CohortInfo][source]

Get a collection of all Phenopacket Store cohorts.

cohort_for_name(name: str) CohortInfo[source]

Retrieve a Phenopacket Store cohort by its name.

Parameters:

name – a str with the cohort name (e.g. SUOX).

Raises:

KeyError – if no cohort with such name exists.

class ppktstore.model.ZipPhenopacketInfo(path: str, pp_path: Path)[source]

Bases: PhenopacketInfo

Loads phenopacket from a Zip file on demand.

property path: str

Path of the phenopacket source relative from the enclosing cohort.

property phenopacket: Phenopacket

The phenopacket.