Skip to content

Commit 684f164

Browse files
committed
..
1 parent 9d545e9 commit 684f164

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

petab/v2/core.py

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,19 @@ class PriorType(str, Enum):
115115
class Observable(BaseModel):
116116
"""Observable definition."""
117117

118+
#: Observable ID
118119
id: str = Field(alias=C.OBSERVABLE_ID)
120+
#: Observable name
119121
name: str | None = Field(alias=C.OBSERVABLE_NAME, default=None)
122+
#: Observable formula
120123
formula: sp.Basic | None = Field(alias=C.OBSERVABLE_FORMULA, default=None)
124+
#: Observable transformation
121125
transformation: ObservableTransformation = Field(
122126
alias=C.OBSERVABLE_TRANSFORMATION, default=ObservableTransformation.LIN
123127
)
128+
#: Noise formula
124129
noise_formula: sp.Basic | None = Field(alias=C.NOISE_FORMULA, default=None)
130+
#: Noise distribution
125131
noise_distribution: NoiseDistribution = Field(
126132
alias=C.NOISE_DISTRIBUTION, default=NoiseDistribution.NORMAL
127133
)
@@ -168,6 +174,7 @@ def sympify(cls, v):
168174
class ObservablesTable(BaseModel):
169175
"""PEtab observables table."""
170176

177+
#: List of observables
171178
observables: list[Observable]
172179

173180
def __getitem__(self, observable_id: str) -> Observable:
@@ -179,6 +186,7 @@ def __getitem__(self, observable_id: str) -> Observable:
179186

180187
@classmethod
181188
def from_df(cls, df: pd.DataFrame) -> ObservablesTable:
189+
"""Create an ObservablesTable from a DataFrame."""
182190
if df is None:
183191
return cls(observables=[])
184192

@@ -190,14 +198,17 @@ def from_df(cls, df: pd.DataFrame) -> ObservablesTable:
190198
return cls(observables=observables)
191199

192200
def to_df(self) -> pd.DataFrame:
201+
"""Convert the ObservablesTable to a DataFrame."""
193202
return pd.DataFrame(self.model_dump()["observables"])
194203

195204
@classmethod
196205
def from_tsv(cls, file_path: str | Path) -> ObservablesTable:
206+
"""Create an ObservablesTable from a TSV file."""
197207
df = pd.read_csv(file_path, sep="\t")
198208
return cls.from_df(df)
199209

200210
def to_tsv(self, file_path: str | Path) -> None:
211+
"""Write the ObservablesTable to a TSV file."""
201212
df = self.to_df()
202213
df.to_csv(file_path, sep="\t", index=False)
203214

@@ -215,6 +226,7 @@ def __iadd__(self, other: Observable) -> ObservablesTable:
215226
return self
216227

217228

229+
# TODO remove?!
218230
class OperationType(str, Enum):
219231
"""Operation types for model changes in the PEtab conditions table."""
220232

@@ -231,8 +243,11 @@ class Change(BaseModel):
231243
row of the PEtab conditions table.
232244
"""
233245

246+
#: The ID of the target entity to change
234247
target_id: str | None = Field(alias=C.TARGET_ID, default=None)
248+
# TODO: remove?!
235249
operation_type: OperationType = Field(alias=C.OPERATION_TYPE)
250+
#: The value to set the target entity to
236251
target_value: sp.Basic | None = Field(alias=C.TARGET_VALUE, default=None)
237252

238253
model_config = ConfigDict(
@@ -273,7 +288,9 @@ class ChangeSet(BaseModel):
273288
to all rows of the PEtab conditions table with the same condition ID.
274289
"""
275290

291+
#: The condition ID
276292
id: str = Field(alias=C.CONDITION_ID)
293+
#: The changes associated with this condition
277294
changes: list[Change]
278295

279296
model_config = ConfigDict(populate_by_name=True)
@@ -304,6 +321,7 @@ def __iadd__(self, other: Change) -> ChangeSet:
304321
class ConditionsTable(BaseModel):
305322
"""PEtab conditions table."""
306323

324+
#: List of conditions
307325
conditions: list[ChangeSet] = []
308326

309327
def __getitem__(self, condition_id: str) -> ChangeSet:
@@ -315,6 +333,7 @@ def __getitem__(self, condition_id: str) -> ChangeSet:
315333

316334
@classmethod
317335
def from_df(cls, df: pd.DataFrame) -> ConditionsTable:
336+
"""Create a ConditionsTable from a DataFrame."""
318337
if df is None:
319338
return cls(conditions=[])
320339

@@ -326,6 +345,7 @@ def from_df(cls, df: pd.DataFrame) -> ConditionsTable:
326345
return cls(conditions=conditions)
327346

328347
def to_df(self) -> pd.DataFrame:
348+
"""Convert the ConditionsTable to a DataFrame."""
329349
records = [
330350
{C.CONDITION_ID: condition.id, **change.model_dump()}
331351
for condition in self.conditions
@@ -335,10 +355,12 @@ def to_df(self) -> pd.DataFrame:
335355

336356
@classmethod
337357
def from_tsv(cls, file_path: str | Path) -> ConditionsTable:
358+
"""Create a ConditionsTable from a TSV file."""
338359
df = pd.read_csv(file_path, sep="\t")
339360
return cls.from_df(df)
340361

341362
def to_tsv(self, file_path: str | Path) -> None:
363+
"""Write the ConditionsTable to a TSV file."""
342364
df = self.to_df()
343365
df.to_csv(file_path, sep="\t", index=False)
344366

@@ -357,12 +379,15 @@ def __iadd__(self, other: ChangeSet) -> ConditionsTable:
357379

358380

359381
class ExperimentPeriod(BaseModel):
360-
"""A period of a timecourse defined by a start time and a set changes.
382+
"""A period of a timecourse or experiment defined by a start time
383+
and a condition ID.
361384
362385
This corresponds to a row of the PEtab experiments table.
363386
"""
364387

388+
#: The start time of the period
365389
start: float = Field(alias=C.TIME)
390+
#: The ID of the condition to be applied at the start time
366391
condition_id: str = Field(alias=C.CONDITION_ID)
367392

368393
model_config = ConfigDict(populate_by_name=True)
@@ -385,7 +410,9 @@ class Experiment(BaseModel):
385410
experiment ID.
386411
"""
387412

413+
#: The experiment ID
388414
id: str = Field(alias=C.EXPERIMENT_ID)
415+
#: The periods of the experiment
389416
periods: list[ExperimentPeriod] = []
390417

391418
model_config = ConfigDict(
@@ -418,10 +445,12 @@ def __iadd__(self, other: ExperimentPeriod) -> Experiment:
418445
class ExperimentsTable(BaseModel):
419446
"""PEtab experiments table."""
420447

448+
#: List of experiments
421449
experiments: list[Experiment]
422450

423451
@classmethod
424452
def from_df(cls, df: pd.DataFrame) -> ExperimentsTable:
453+
"""Create an ExperimentsTable from a DataFrame."""
425454
if df is None:
426455
return cls(experiments=[])
427456

@@ -438,14 +467,17 @@ def from_df(cls, df: pd.DataFrame) -> ExperimentsTable:
438467
return cls(experiments=experiments)
439468

440469
def to_df(self) -> pd.DataFrame:
470+
"""Convert the ExperimentsTable to a DataFrame."""
441471
return pd.DataFrame(self.model_dump()["experiments"])
442472

443473
@classmethod
444474
def from_tsv(cls, file_path: str | Path) -> ExperimentsTable:
475+
"""Create an ExperimentsTable from a TSV file."""
445476
df = pd.read_csv(file_path, sep="\t")
446477
return cls.from_df(df)
447478

448479
def to_tsv(self, file_path: str | Path) -> None:
480+
"""Write the ExperimentsTable to a TSV file."""
449481
df = self.to_df()
450482
df.to_csv(file_path, sep="\t", index=False)
451483

@@ -532,6 +564,7 @@ def from_df(
532564
cls,
533565
df: pd.DataFrame,
534566
) -> MeasurementTable:
567+
"""Create a MeasurementTable from a DataFrame."""
535568
if df is None:
536569
return cls(measurements=[])
537570

@@ -545,14 +578,17 @@ def from_df(
545578
return cls(measurements=measurements)
546579

547580
def to_df(self) -> pd.DataFrame:
581+
"""Convert the MeasurementTable to a DataFrame."""
548582
return pd.DataFrame(self.model_dump()["measurements"])
549583

550584
@classmethod
551585
def from_tsv(cls, file_path: str | Path) -> MeasurementTable:
586+
"""Create a MeasurementTable from a TSV file."""
552587
df = pd.read_csv(file_path, sep="\t")
553588
return cls.from_df(df)
554589

555590
def to_tsv(self, file_path: str | Path) -> None:
591+
"""Write the MeasurementTable to a TSV file."""
556592
df = self.to_df()
557593
df.to_csv(file_path, sep="\t", index=False)
558594

@@ -573,7 +609,9 @@ def __iadd__(self, other: Measurement) -> MeasurementTable:
573609
class Mapping(BaseModel):
574610
"""Mapping PEtab entities to model entities."""
575611

612+
#: PEtab entity ID
576613
petab_id: str = Field(alias=C.PETAB_ENTITY_ID)
614+
#: Model entity ID
577615
model_id: str = Field(alias=C.MODEL_ENTITY_ID)
578616

579617
model_config = ConfigDict(populate_by_name=True)
@@ -593,10 +631,12 @@ def validate_id(cls, v):
593631
class MappingTable(BaseModel):
594632
"""PEtab mapping table."""
595633

634+
#: List of mappings
596635
mappings: list[Mapping]
597636

598637
@classmethod
599638
def from_df(cls, df: pd.DataFrame) -> MappingTable:
639+
"""Create a MappingTable from a DataFrame."""
600640
if df is None:
601641
return cls(mappings=[])
602642

@@ -607,14 +647,17 @@ def from_df(cls, df: pd.DataFrame) -> MappingTable:
607647
return cls(mappings=mappings)
608648

609649
def to_df(self) -> pd.DataFrame:
650+
"""Convert the MappingTable to a DataFrame."""
610651
return pd.DataFrame(self.model_dump()["mappings"])
611652

612653
@classmethod
613654
def from_tsv(cls, file_path: str | Path) -> MappingTable:
655+
"""Create a MappingTable from a TSV file."""
614656
df = pd.read_csv(file_path, sep="\t")
615657
return cls.from_df(df)
616658

617659
def to_tsv(self, file_path: str | Path) -> None:
660+
"""Write the MappingTable to a TSV file."""
618661
df = self.to_df()
619662
df.to_csv(file_path, sep="\t", index=False)
620663

@@ -635,13 +678,19 @@ def __iadd__(self, other: Mapping) -> MappingTable:
635678
class Parameter(BaseModel):
636679
"""Parameter definition."""
637680

681+
#: Parameter ID
638682
id: str = Field(alias=C.PARAMETER_ID)
683+
#: Lower bound
639684
lb: float | None = Field(alias=C.LOWER_BOUND, default=None)
685+
#: Upper bound
640686
ub: float | None = Field(alias=C.UPPER_BOUND, default=None)
687+
#: Nominal value
641688
nominal_value: float | None = Field(alias=C.NOMINAL_VALUE, default=None)
689+
#: Parameter scale
642690
scale: ParameterScale = Field(
643691
alias=C.PARAMETER_SCALE, default=ParameterScale.LIN
644692
)
693+
#: Is the parameter to be estimated?
645694
estimate: bool = Field(alias=C.ESTIMATE, default=True)
646695
# TODO priors
647696

@@ -671,10 +720,12 @@ def convert_nan_to_none(cls, v):
671720
class ParameterTable(BaseModel):
672721
"""PEtab parameter table."""
673722

723+
#: List of parameters
674724
parameters: list[Parameter]
675725

676726
@classmethod
677727
def from_df(cls, df: pd.DataFrame) -> ParameterTable:
728+
"""Create a ParameterTable from a DataFrame."""
678729
if df is None:
679730
return cls(parameters=[])
680731

@@ -686,14 +737,17 @@ def from_df(cls, df: pd.DataFrame) -> ParameterTable:
686737
return cls(parameters=parameters)
687738

688739
def to_df(self) -> pd.DataFrame:
740+
"""Convert the ParameterTable to a DataFrame."""
689741
return pd.DataFrame(self.model_dump()["parameters"])
690742

691743
@classmethod
692744
def from_tsv(cls, file_path: str | Path) -> ParameterTable:
745+
"""Create a ParameterTable from a TSV file."""
693746
df = pd.read_csv(file_path, sep="\t")
694747
return cls.from_df(df)
695748

696749
def to_tsv(self, file_path: str | Path) -> None:
750+
"""Write the ParameterTable to a TSV file."""
697751
df = self.to_df()
698752
df.to_csv(file_path, sep="\t", index=False)
699753

0 commit comments

Comments
 (0)