Skip to content

Commit 005c732

Browse files
committed
..
1 parent 6792a29 commit 005c732

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
@@ -114,13 +114,19 @@ class PriorType(str, Enum):
114114
class Observable(BaseModel):
115115
"""Observable definition."""
116116

117+
#: Observable ID
117118
id: str = Field(alias=C.OBSERVABLE_ID)
119+
#: Observable name
118120
name: str | None = Field(alias=C.OBSERVABLE_NAME, default=None)
121+
#: Observable formula
119122
formula: sp.Basic | None = Field(alias=C.OBSERVABLE_FORMULA, default=None)
123+
#: Observable transformation
120124
transformation: ObservableTransformation = Field(
121125
alias=C.OBSERVABLE_TRANSFORMATION, default=ObservableTransformation.LIN
122126
)
127+
#: Noise formula
123128
noise_formula: sp.Basic | None = Field(alias=C.NOISE_FORMULA, default=None)
129+
#: Noise distribution
124130
noise_distribution: NoiseDistribution = Field(
125131
alias=C.NOISE_DISTRIBUTION, default=NoiseDistribution.NORMAL
126132
)
@@ -167,6 +173,7 @@ class Config:
167173
class ObservablesTable(BaseModel):
168174
"""PEtab observables table."""
169175

176+
#: List of observables
170177
observables: list[Observable]
171178

172179
def __getitem__(self, observable_id: str) -> Observable:
@@ -178,6 +185,7 @@ def __getitem__(self, observable_id: str) -> Observable:
178185

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

@@ -189,14 +197,17 @@ def from_df(cls, df: pd.DataFrame) -> ObservablesTable:
189197
return cls(observables=observables)
190198

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

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

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

@@ -214,6 +225,7 @@ def __iadd__(self, other: Observable) -> ObservablesTable:
214225
return self
215226

216227

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

@@ -230,8 +242,11 @@ class Change(BaseModel):
230242
row of the PEtab conditions table.
231243
"""
232244

245+
#: The ID of the target entity to change
233246
target_id: str | None = Field(alias=C.TARGET_ID, default=None)
247+
# TODO: remove?!
234248
operation_type: OperationType = Field(alias=C.OPERATION_TYPE)
249+
#: The value to set the target entity to
235250
target_value: sp.Basic | None = Field(alias=C.TARGET_VALUE, default=None)
236251

237252
class Config:
@@ -271,7 +286,9 @@ class ChangeSet(BaseModel):
271286
to all rows of the PEtab conditions table with the same condition ID.
272287
"""
273288

289+
#: The condition ID
274290
id: str = Field(alias=C.CONDITION_ID)
291+
#: The changes associated with this condition
275292
changes: list[Change]
276293

277294
class Config:
@@ -303,6 +320,7 @@ def __iadd__(self, other: Change) -> ChangeSet:
303320
class ConditionsTable(BaseModel):
304321
"""PEtab conditions table."""
305322

323+
#: List of conditions
306324
conditions: list[ChangeSet] = []
307325

308326
def __getitem__(self, condition_id: str) -> ChangeSet:
@@ -314,6 +332,7 @@ def __getitem__(self, condition_id: str) -> ChangeSet:
314332

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

@@ -325,6 +344,7 @@ def from_df(cls, df: pd.DataFrame) -> ConditionsTable:
325344
return cls(conditions=conditions)
326345

327346
def to_df(self) -> pd.DataFrame:
347+
"""Convert the ConditionsTable to a DataFrame."""
328348
records = [
329349
{C.CONDITION_ID: condition.id, **change.model_dump()}
330350
for condition in self.conditions
@@ -334,10 +354,12 @@ def to_df(self) -> pd.DataFrame:
334354

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

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

@@ -356,12 +378,15 @@ def __iadd__(self, other: ChangeSet) -> ConditionsTable:
356378

357379

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

387+
#: The start time of the period
364388
start: float = Field(alias=C.TIME)
389+
#: The ID of the condition to be applied at the start time
365390
condition_id: str = Field(alias=C.CONDITION_ID)
366391

367392
class Config:
@@ -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
class Config:
@@ -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
class Config:
@@ -594,10 +632,12 @@ def validate_id(cls, v):
594632
class MappingTable(BaseModel):
595633
"""PEtab mapping table."""
596634

635+
#: List of mappings
597636
mappings: list[Mapping]
598637

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

@@ -608,14 +648,17 @@ def from_df(cls, df: pd.DataFrame) -> MappingTable:
608648
return cls(mappings=mappings)
609649

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

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

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

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

682+
#: Parameter ID
639683
id: str = Field(alias=C.PARAMETER_ID)
684+
#: Lower bound
640685
lb: float | None = Field(alias=C.LOWER_BOUND, default=None)
686+
#: Upper bound
641687
ub: float | None = Field(alias=C.UPPER_BOUND, default=None)
688+
#: Nominal value
642689
nominal_value: float | None = Field(alias=C.NOMINAL_VALUE, default=None)
690+
#: Parameter scale
643691
scale: ParameterScale = Field(
644692
alias=C.PARAMETER_SCALE, default=ParameterScale.LIN
645693
)
694+
#: Is the parameter to be estimated?
646695
estimate: bool = Field(alias=C.ESTIMATE, default=True)
647696
# TODO priors
648697

@@ -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)