-
Notifications
You must be signed in to change notification settings - Fork 17
/
overview.py
executable file
·138 lines (118 loc) · 4.45 KB
/
overview.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env python3
"""Print some stats for each benchmark PEtab problem"""
import os
from typing import Dict, List
import libsbml
import numpy as np
import pandas as pd
import petab
from _helpers import petab_yamls
markdown_columns = {
'conditions': 'Conditions',
'estimated_parameters': 'Estimated Parameters',
'events': 'Events',
'preequilibration': 'Preequilibration',
'postequilibration': 'Postequilibration',
'measurements': 'Measurements',
'petab_problem_id': 'PEtab Problem ID',
'observables': 'Observables',
'species': 'Species',
'noise_distributions': 'Noise distribution(s)',
'reference_uris': 'References',
}
index_column = 'petab_problem_id'
def get_summary(
petab_problem: petab.Problem,
petab_problem_id: str = None,
) -> Dict:
"""Get dictionary with stats for the given PEtab problem"""
return {
'petab_problem_id':
petab_problem_id,
'conditions':
petab_problem.get_simulation_conditions_from_measurement_df().shape[0],
'estimated_parameters':
np.sum(petab_problem.parameter_df[petab.ESTIMATE]),
'events':
len(petab_problem.sbml_model.getListOfEvents()),
'preequilibration':
0 if petab.PREEQUILIBRATION_CONDITION_ID not in
petab_problem.measurement_df.columns or
pd.isnull(petab_problem.measurement_df[
petab.PREEQUILIBRATION_CONDITION_ID]).all()
else (pd.isnull(petab_problem.measurement_df[
petab.PREEQUILIBRATION_CONDITION_ID].unique()) == False
).sum(),
'postequilibration':
petab.measurements.get_simulation_conditions(
petab_problem.measurement_df[
petab_problem.measurement_df[petab.TIME] == np.inf]).shape[
0] if
np.isinf(petab_problem.measurement_df[petab.TIME]).any()
else 0,
'measurements':
len(petab_problem.measurement_df.index),
'observables':
len(petab_problem.measurement_df[petab.OBSERVABLE_ID].unique()),
'noise_distributions':
get_noise_distributions(petab_problem.observable_df),
'species':
len(petab_problem.sbml_model.getListOfSpecies()),
'reference_uris':
get_reference_uris(petab_problem.sbml_model),
}
def get_reference_uris(sbml_model: libsbml.Model) -> List[str]:
"""Get publication URIs from SBML is-described-by annotation"""
cv_terms = sbml_model.getCVTerms()
reference_uris = []
for anno in cv_terms:
if anno.getBiologicalQualifierType() != libsbml.BQB_IS_DESCRIBED_BY:
continue
resources = anno.getResources()
for i in range(resources.getNumAttributes()):
uri = resources.getValue(i)
reference_uris.append(uri)
return reference_uris
def get_noise_distributions(observable_df):
if petab.NOISE_DISTRIBUTION in observable_df.columns:
noise_distrs = ['normal' if dist is np.nan else dist for dist in
observable_df[petab.NOISE_DISTRIBUTION]]
noise_distrs = set(noise_distrs)
else:
noise_distrs = {'normal'}
return "; ".join(noise_distrs)
def get_overview_table() -> pd.DataFrame:
"""Get overview table with stats for all benchmark PEtab problems"""
data = []
for petab_problem_id, petab_yaml in petab_yamls.items():
petab_problem = petab.Problem.from_yaml(petab_yaml)
summary = get_summary(petab_problem, petab_problem_id)
data.append(summary)
df = pd.DataFrame(data)
df.set_index([index_column], inplace=True)
return df
def main(
markdown: bool = False,
):
df = get_overview_table()
pd.options.display.width = 0
if markdown:
# directory as markdown link
df.rename(index=lambda x: f"[{x}](Benchmark-Models/{x}/)",
inplace=True)
# references to markdown links
df['reference_uris'] = df['reference_uris'].apply(
lambda x: " ".join([f"[\\[{i + 1}\\]]({uri})"
for i, uri in enumerate(x)])
)
df.index.rename(markdown_columns[index_column], inplace=True)
df.rename(columns=markdown_columns, inplace=True)
print(df.to_markdown())
else:
print(df)
if __name__ == '__main__':
import sys
markdown = False
if '--markdown' in sys.argv:
markdown = True
main(markdown)