Source code for app.model.orm.perturbation

from typing import Optional

import sqlalchemy as sql
from sqlalchemy.orm import (
    Mapped,
    mapped_column,
    relationship,
)
from sqlalchemy.ext.hybrid import hybrid_property

from app.model.orm.orm_base import OrmBase


[docs] class Perturbation(OrmBase): """ The description of a change over time in a particular experiment's environment. A perturbation is described by the addition or removal of a ``Compartment`` to the experiment or by the change from one ``Community`` to another. This may be changed in the future as we collect more studies with perturbations. """
[docs] __tablename__ = 'Perturbations'
[docs] id: Mapped[int] = mapped_column(primary_key=True)
[docs] description: Mapped[str] = mapped_column(sql.String)
[docs] experimentId: Mapped[str] = mapped_column(sql.ForeignKey('Experiments.publicId'), nullable=False)
[docs] experiment: Mapped['Experiment'] = relationship(back_populates='perturbations')
[docs] study: Mapped['Study'] = relationship( secondary='Experiments', viewonly=True, )
[docs] startTimeInSeconds: Mapped[int] = mapped_column(sql.Integer, nullable=False)
[docs] endTimeInSeconds: Mapped[int] = mapped_column(sql.Integer, nullable=False)
[docs] removedCompartmentId: Mapped[int] = mapped_column(sql.ForeignKey('Compartments.id'))
[docs] addedCompartmentId: Mapped[int] = mapped_column(sql.ForeignKey('Compartments.id'))
[docs] oldCommunityId: Mapped[int] = mapped_column(sql.ForeignKey('Communities.id'))
[docs] newCommunityId: Mapped[int] = mapped_column(sql.ForeignKey('Communities.id'))
[docs] oldCommunity: Mapped[Optional['Community']] = relationship(foreign_keys=[oldCommunityId])
[docs] newCommunity: Mapped[Optional['Community']] = relationship(foreign_keys=[newCommunityId])
[docs] removedCompartment: Mapped[Optional['Compartment']] = relationship(foreign_keys=[removedCompartmentId])
[docs] addedCompartment: Mapped[Optional['Compartment']] = relationship(foreign_keys=[addedCompartmentId])
@hybrid_property
[docs] def startTimeInHours(self): return self.startTimeInSeconds / 3600
@hybrid_property
[docs] def endTimeInHours(self): return self.endTimeInSeconds and self.endTimeInSeconds / 3600