phenopacket_mapper package

A package to map data from a tabular format to the GA4GH Phenopacket schema (v2).

class phenopacket_mapper.PhenopacketMapper(datamodel: DataModel)[source]

Bases: object

Class to map data using a DataModel to Phenopackets

This class is central to the pipeline for mapping data from a DataModel to Phenopackets. A dataset can be mapped from its tabular format to the Phenopacket schema in a few simple steps: 1. Define the DataModel for the dataset, if it does not exist yet 2. Load the data from the dataset 3. Define the mapping from the DataModel to the Phenopacket schema 4. Perform the mapping 5. Write the Phenopackets to a file 6. Optionally validate the Phenopackets

load_data(path: str | Path) List[DataModelInstance][source]

Load data from a file using the DataModel

Will raise an error if the file type is not recognized or the file does not follow the DataModel

Parameters:

path – Path to the file to load

Returns:

List of DataModelInstances

map(mapping_: DataModel2PhenopacketSchema, data: List[DataModelInstance]) List[Phenopacket][source]

Map data from the DataModel to Phenopackets

The mapping is based on the definition of the DataModel and the DataModel2PhenopacketSchema mapping.

If successful, a list of Phenopackets will be returned

Parameters:
  • mapping – Mapping from the DataModel to the Phenopacket schema, defined in DataModel2PhenopacketSchema

  • data – List of DataModelInstances created from the data using the DataModel

Returns:

List of Phenopackets

write(phenopackets: List[Phenopacket], output_path: str | Path) bool[source]

Write Phenopackets to a file

Parameters:
  • phenopackets – List of Phenopackets to write

  • output_path – Path to write the Phenopackets to

Returns:

True if successful, False otherwise

Subpackages