diff --git a/.gitignore b/.gitignore index b988b16..a4f0315 100644 --- a/.gitignore +++ b/.gitignore @@ -161,3 +161,7 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. .idea/ + +# VsCode +*.code-workspace +.vscode \ No newline at end of file diff --git a/src/phenopacket_mapper/_api/__init__.py b/src/phenopacket_mapper/_api/__init__.py new file mode 100644 index 0000000..6f77c4d --- /dev/null +++ b/src/phenopacket_mapper/_api/__init__.py @@ -0,0 +1,76 @@ +""" +This package is intended to expose the PhenopacketMapper API to the user. +""" + +import abc +from typing import Tuple, Iterable, Iterator +from dataclasses import dataclass + + +class DataModelDefiner(metaclass=abc.ABCMeta): + """ + Take some data model definition and try to load it into :class:`DataModel`. + + E.g. protobuf model "definer". + """ + pass + + +class DataModel(metaclass=abc.ABCMeta): + """ + Value class. + The fields: + - label, version + - a root `DataNode`, it must be there (not `Optional`) + - resources (maybe generate dynamically, or keep as a list) + + We want to be able to (de)serialize this. + """ + pass + + +@dataclass +class DataNode(metaclass=abc.ABCMeta): + """ + This is very much like Jackson (Java) `TreeNode`, + because it can be many things. + + The common things may include + - label + - maybe it knows about the parent (optional) and children + + We want to be able to (de)serialize this. + """ + label: str + id: str + required: bool + + +class DataInstance: + pass + + +class Transformation(metaclass=abc.ABCMeta): + """ + + """ + steps: Tuple + + +class Mapper: + + def __init__( + self, + transformation: Transformation, + ): + pass + + def transform_dataset( + self, + data_set: Iterable[DataInstance], + ) -> Iterator[DataInstance]: + return map(lambda item: self.transform(item), data_set) + + def transform(self, item: DataInstance) -> DataInstance: + # TODO: implement based on self.transformation + pass diff --git a/src/phenopacket_mapper/data_standards/data_model.py b/src/phenopacket_mapper/data_standards/data_model.py index 7596cbd..bd13228 100644 --- a/src/phenopacket_mapper/data_standards/data_model.py +++ b/src/phenopacket_mapper/data_standards/data_model.py @@ -55,6 +55,7 @@ class DataField: :ivar required: Required flag of the field :ivar ordinal: Ordinal of the field (E.g. 1.1, 1.2, 2.1, etc.) """ + # TODO: change section into path to data name: str = field() specification: Union[ValueSet, type, List[type]] = field() id: str = field(default=None) diff --git a/src/phenopacket_mapper/mapping/phenopacket_building_block.py b/src/phenopacket_mapper/mapping/phenopacket_building_block.py index efe98a9..bdab1c5 100644 --- a/src/phenopacket_mapper/mapping/phenopacket_building_block.py +++ b/src/phenopacket_mapper/mapping/phenopacket_building_block.py @@ -44,7 +44,7 @@ def map(self, instance: DataModelInstance): return self.phenopacket_element(**kwargs) -def map_single(key, e, instance, kwargs): +def map_single(key, e, instance: DataModelInstance, kwargs): if isinstance(e, DataField): data_field = e try: