Skip to content

Commit

Permalink
Merge pull request #167 from BIH-CEI/165-api-design-with-abc
Browse files Browse the repository at this point in the history
165 api design with abc
  • Loading branch information
frehburg authored Oct 11, 2024
2 parents 8b934fe + 42d9ba8 commit df5ff8a
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
76 changes: 76 additions & 0 deletions src/phenopacket_mapper/_api/__init__.py
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions src/phenopacket_mapper/data_standards/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit df5ff8a

Please sign in to comment.