cobra_component_models.serializer package

Submodules

cobra_component_models.serializer.abstract_serializer module

Provide an abstract serializer.

class cobra_component_models.serializer.abstract_serializer.AbstractSerializer(biology_qualifiers: Dict[str, cobra_component_models.orm.biology_qualifier.BiologyQualifier], namespaces: Dict[str, cobra_component_models.orm.namespace.Namespace], **kwargs)[source]

Bases: abc.ABC

Define an abstract serializer.

__init__(biology_qualifiers: Dict[str, cobra_component_models.orm.biology_qualifier.BiologyQualifier], namespaces: Dict[str, cobra_component_models.orm.namespace.Namespace], **kwargs)[source]

Initialize the abstract base serializer.

Parameters
  • biology_qualifiers (dict) – A mapping from biology qualifiers to their database instances.

  • namespaces (dict) – A mapping from namespace prefixes to their database instances.

Other Parameters

kwargs – Passed on to super class init method.

abstract deserialize(component_model: cobra_component_models.io.sbase_model.SBaseModel) → cobra_component_models.orm.abstract_component.AbstractComponent[source]

Deserialize a pydantic data model to an ORM model.

deserialize_annotation(annotation_data: Dict[str, List[cobra_component_models.io.type.annotation_type.AnnotationType]], orm_class: Type[cobra_component_models.orm.abstract_component.AbstractComponentAnnotation]) → List[cobra_component_models.orm.abstract_component.AbstractComponentAnnotation][source]

Deserialize the component annotation.

deserialize_names(names_data: Dict[str, List[str]], orm_class: Type[cobra_component_models.orm.abstract_component.AbstractComponentName]) → List[cobra_component_models.orm.abstract_component.AbstractComponentName][source]

Deserialize the component names.

abstract serialize(component: cobra_component_models.orm.abstract_component.AbstractComponent) → cobra_component_models.io.sbase_model.SBaseModel[source]

Serialize an ORM model to a pydantic data model.

serialize_annotation(annotation: List[cobra_component_models.orm.abstract_component.AbstractComponentAnnotation]) → Dict[str, List[cobra_component_models.io.type.annotation_type.AnnotationType]][source]

Serialize the component annotation.

serialize_names(names: List[cobra_component_models.orm.abstract_component.AbstractComponentName]) → Dict[str, List[str]][source]

Serialize the component names.

cobra_component_models.serializer.compartment_serializer module

Provide a compartment serializer.

class cobra_component_models.serializer.compartment_serializer.CompartmentSerializer(**kwargs)[source]

Bases: cobra_component_models.serializer.abstract_serializer.AbstractSerializer

Define a compartment serializer.

__init__(**kwargs)[source]

Initialize a compartment serializer.

deserialize(component_model: cobra_component_models.io.compartment_model.CompartmentModel) → cobra_component_models.orm.compartment.Compartment[source]

Deserialize a pydantic compartment data model to an ORM model.

Parameters

component_model (cobra_component_models.io.CompartmentModel) – The pydantic compartment data model instance to be deserialized.

Returns

A corresponding compartment ORM model.

Return type

cobra_component_models.orm.Compartment

serialize(component: cobra_component_models.orm.compartment.Compartment) → cobra_component_models.io.compartment_model.CompartmentModel[source]

Serialize a compartment ORM model to a pydantic data model.

Parameters

component (cobra_component_models.orm.Compartment) – The compartment ORM model instance to be serialized.

Returns

A corresponding pydantic compartment data model.

Return type

cobra_component_models.io.CompartmentModel

Warning

Please ensure that all relationships of the compartment object have been eagerly loaded in order to avoid \(N+1\) [CC1] problems that may easily occur here.

References

CC1

https://docs.sqlalchemy.org/en/13/glossary.html#term-n-plus-one-problem

cobra_component_models.serializer.compound_serializer module

Provide a compound serializer.

class cobra_component_models.serializer.compound_serializer.CompoundSerializer(**kwargs)[source]

Bases: cobra_component_models.serializer.abstract_serializer.AbstractSerializer

Define a compound serializer.

__init__(**kwargs)[source]

Initialize a compound serializer.

deserialize(component_model: cobra_component_models.io.compound_model.CompoundModel) → cobra_component_models.orm.compound.Compound[source]

Deserialize a pydantic compound data model to an ORM model.

Parameters

component_model (cobra_component_models.io.CompoundModel) – The pydantic compound data model instance to be deserialized.

Returns

A corresponding compound ORM model.

Return type

cobra_component_models.orm.Compound

serialize(component: cobra_component_models.orm.compound.Compound) → cobra_component_models.io.compound_model.CompoundModel[source]

Serialize a compound ORM model to a pydantic data model.

Parameters

component (cobra_component_models.orm.Compound) – The compound ORM model instance to be serialized.

Returns

A corresponding pydantic compound data model.

Return type

cobra_component_models.io.CompoundModel

Warning

Please ensure that all relationships of the compound object have been eagerly loaded in order to avoid \(N+1\) [C1] problems that may easily occur here.

References

C1

https://docs.sqlalchemy.org/en/13/glossary.html#term-n-plus-one-problem

cobra_component_models.serializer.reaction_serializer module

Provide a reaction serializer.

class cobra_component_models.serializer.reaction_serializer.ReactionSerializer(compartment2id: Optional[Dict[cobra_component_models.orm.compartment.Compartment, str]] = None, compound2id: Optional[Dict[cobra_component_models.orm.compound.Compound, str]] = None, id2compartment: Optional[Dict[str, cobra_component_models.orm.compartment.Compartment]] = None, id2compound: Optional[Dict[str, cobra_component_models.orm.compound.Compound]] = None, **kwargs)[source]

Bases: cobra_component_models.serializer.abstract_serializer.AbstractSerializer

Define a reaction serializer.

__init__(compartment2id: Optional[Dict[cobra_component_models.orm.compartment.Compartment, str]] = None, compound2id: Optional[Dict[cobra_component_models.orm.compound.Compound, str]] = None, id2compartment: Optional[Dict[str, cobra_component_models.orm.compartment.Compartment]] = None, id2compound: Optional[Dict[str, cobra_component_models.orm.compound.Compound]] = None, **kwargs)[source]

Initialize a reaction serializer.

Parameters
  • compartment2id (dict) – A map from compartment database instances to string identifiers for them. Needed for serialization only.

  • compound2id (dict) – A map from compound database instances to string identifiers for them. Needed for serialization only.

  • id2compartment (dict) – A map from string identifiers to compartment database instances. Needed for deserialization only.

  • id2compound (dict) – A map from string identifiers to compound database instances. Needed for deserialization only.

Other Parameters

kwargs – Passed on to super class init method.

deserialize(component_model: cobra_component_models.io.reaction_model.ReactionModel) → cobra_component_models.orm.reaction.Reaction[source]

Deserialize a pydantic reaction data model to an ORM model.

Parameters

component_model (cobra_component_models.io.ReactionModel) – The pydantic reaction data model instance to be deserialized.

Returns

A corresponding reaction ORM model.

Return type

cobra_component_models.orm.Reaction

deserialize_participants(reactants: Dict[str, cobra_component_models.io.reaction_model.ParticipantModel], products: Dict[str, cobra_component_models.io.reaction_model.ParticipantModel]) → List[cobra_component_models.orm.participant.Participant][source]

Deserialize the reactants and products.

serialize(component: cobra_component_models.orm.reaction.Reaction) → cobra_component_models.io.reaction_model.ReactionModel[source]

Serialize a reaction ORM model to a pydantic data model.

Parameters

component (cobra_component_models.orm.Reaction) – The reaction ORM model instance to be serialized.

Returns

A corresponding pydantic reaction data model.

Return type

cobra_component_models.io.ReactionModel

Warning

Please ensure that all relationships of the reaction object have been eagerly loaded in order to avoid \(N+1\) [R1] problems that may easily occur here.

References

R1

https://docs.sqlalchemy.org/en/13/glossary.html#term-n-plus-one-problem

serialize_participants(participants: List[cobra_component_models.orm.participant.Participant]) → Tuple[Dict[str, cobra_component_models.io.reaction_model.ParticipantModel], Dict[str, cobra_component_models.io.reaction_model.ParticipantModel]][source]

Serialize the reactants and products.

Module contents

Provide serialization classes for components.