Skip to content

Commit acba669

Browse files
Access models in BioModels.
1 parent d4eeb7f commit acba669

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

notebooks/evaluating_autoencoders.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,8 +1037,9 @@
10371037
}
10381038
],
10391039
"source": [
1040-
"PCA_RUNNER = ModelRunnerPCA(n_components=2, random_state=42)\n",
1041-
"CELL_CYCLE_RUNNER_PCA = plotSimulationFit(CELL_CYCLE_DF, offset=20, untrained_runner=PCA_RUNNER)"
1040+
"url = \"https://www.ebi.ac.uk/biomodels/services/download/get-files/MODEL2004140001/3/Garde2020.xml\"\n",
1041+
"runner = ModelRunnerUMAP.makeFromSBML(url, selections=['Gp', 'Gi', 'A'], num_epoch=5)\n",
1042+
"_ = runner.plotSimulationFit(is_plot=IS_PLOT, antimony_model=\"Sequential\")"
10421043
]
10431044
},
10441045
{

src/autoencodersb/model_runner.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ def plotSimulationFit(self,
302302
plt.show()
303303

304304
@classmethod
305-
def makeFromAntimony(cls,
306-
antimony_str: str,
305+
def makeFromSBML(cls,
306+
model_str: str,
307307
reduced_dimension: int = 2,
308308
start_time: int = 0,
309309
end_time: int = 10,
@@ -312,7 +312,7 @@ def makeFromAntimony(cls,
312312
**runner_kwargs) -> 'ModelRunner':
313313
"""Creates a ModelRunnerUMAP from an Antimony string and fits the model
314314
Args:
315-
antimony_str (str): Antimony string defining the model.
315+
model_str (str): Antimony or url string defining the model.
316316
reduced_dimension (int): The reduced dimension for the UMAP model.
317317
start_time (int): The start time for the simulation.
318318
end_time (int): The end time for the simulation.
@@ -325,7 +325,10 @@ def makeFromAntimony(cls,
325325
Returns:
326326
ModelRunnerUMAP
327327
"""
328-
rr = te.loada(antimony_str)
328+
if "http" in model_str:
329+
rr = te.loadSBMLModel(model_str)
330+
else:
331+
rr = te.loada(model_str)
329332
data_arr = rr.simulate(start_time, end_time, num_point)
330333
if selections is not None:
331334
num_input_feature = len(selections)

tests/test_model_runner.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def makeFromAntimony(self, cls, num_epoch=5) -> ModelRunner:
7676
D = 0
7777
E = 0
7878
"""
79-
runner = cls.makeFromAntimony(ant_str, selections=["B", "C", "D"], num_epoch=num_epoch)
79+
runner = cls.makeFromSBML(ant_str, selections=["B", "C", "D"], num_epoch=num_epoch)
8080
self.assertIsInstance(runner, cls)
8181
self.assertGreater(len(runner.train_runner_result.losses), 0) # type: ignore
8282
return runner
@@ -92,6 +92,10 @@ def testPlotSimulationFit(self):
9292
return
9393
runner = self.makeFromAntimony(ModelRunnerUMAP, num_epoch=10)
9494
_ = runner.plotSimulationFit(is_plot=IS_PLOT, antimony_model="Sequential")
95+
#
96+
url = "https://www.ebi.ac.uk/biomodels/services/download/get-files/MODEL2004140001/3/Garde2020.xml"
97+
runner = ModelRunnerUMAP.makeFromSBML(url, selections=['Gp', 'Gi', 'A'], num_epoch=10)
98+
_ = runner.plotSimulationFit(is_plot=IS_PLOT, antimony_model="Sequential")
9599

96100
if __name__ == '__main__':
97101
unittest.main()

0 commit comments

Comments
 (0)