Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
model = copy.deepcopy(model_module.model)
model.name = 'test_model_presimulation_pysb'
outdir = model.name
amici.pysb2amici(model,
outdir,
verbose=False,
observables=['pPROT_obs'],
constant_parameters=['DRUG_0', 'KIN_0'])
sys.path.insert(0, outdir)
modelModulePYSB = importlib.import_module(outdir)
self.model = modelModulePYSB.getModel()
self.model.setReinitializeFixedParameterInitialStates(True)
self.solver = self.model.getSolver()
self.solver.setSensitivityOrder(amici.SensitivityOrder_first)
self.solver.setSensitivityMethod(amici.SensitivityMethod_forward)
self.edata = get_data(self.model)
self.edata.t_presim = 2
self.edata.fixedParameters = [10, 2]
self.edata.fixedParametersPresimulation = [3, 2]
self.edata.fixedParametersPreequilibration = [3, 0]
self.edata.setTimepoints([1, 5])
self.edata_preeq = amici.ExpData(self.edata)
self.edata_preeq.t_presim = 0
self.edata_preeq.setTimepoints([np.infty])
self.edata_preeq.fixedParameters = \
self.edata.fixedParametersPreequilibration
self.edata_preeq.fixedParametersPresimulation = ()
self.edata_preeq.fixedParametersPreequilibration = ()
def steadystate_simulation(self, model_module):
def assert_fun(x):
return self.assertTrue(x)
model = model_module.getModel()
model.setTimepoints(np.linspace(0, 60, 60))
solver = model.getSolver()
solver.setSensitivityOrder(amici.SensitivityOrder_first)
rdata = amici.runAmiciSimulation(model, solver)
edata = [amici.ExpData(rdata, 1, 0)]
rdata = amici.runAmiciSimulations(model, solver, edata)
# check roundtripping of DataFrame conversion
df_edata = amici.getDataObservablesAsDataFrame(model, edata)
edata_reconstructed = amici.getEdataFromDataFrame(model, df_edata)
self.assertTrue(
np.isclose(
amici.ExpDataView(edata[0])
['observedData'],
amici.ExpDataView(edata_reconstructed[0])
['observedData'],
).all()
)
sbml_importer = amici.SbmlImporter(sbml_file)
sbml_importer.sbml2amici(model_name,
model_output_dir,
verbose=False)
# load amici module (the usual starting point later for the analysis)
sys.path.insert(0, os.path.abspath(model_output_dir))
model_module = importlib.import_module(model_name)
model = model_module.getModel()
model.requireSensitivitiesForAllParameters()
model.setTimepoints(np.linspace(0, 10, 11))
model.setParameterScale(amici.ParameterScaling_log10)
model.setParameters([-0.3, -0.7])
solver = model.getSolver()
solver.setSensitivityMethod(amici.SensitivityMethod_forward)
solver.setSensitivityOrder(amici.SensitivityOrder_first)
# generate experimental data
rdata = amici.runAmiciSimulation(model, solver, None)
edata = amici.ExpData(rdata, 0.05, 0.0)
return (pypesto.AmiciObjective(model, solver, [edata], 2),
model)
sbmlImporter.sbml2amici('test_likelihoods',
outdir,
observables=observables,
constantParameters=['k0'],
sigmas={'observable_x1withsigma':
'observable_x1withsigma_sigma'},
noise_distributions=noise_distributions
)
sys.path.insert(0, outdir)
import test_likelihoods as modelModule
model = modelModule.getModel()
model.setTimepoints(np.linspace(0, 60, 60))
solver = model.getSolver()
solver.setSensitivityOrder(amici.SensitivityOrder_first)
# run model once to create an edata
rdata = amici.runAmiciSimulation(model, solver)
edata = [amici.ExpData(rdata, 1, 0)]
# just make all observables positive since some are logarithmic
for ed in edata:
y = ed.getObservedData()
y = tuple([max(val, 1e-4) for val in y])
ed.setObservedData(y)
# and now run for real and also compute likelihood values
rdata = amici.runAmiciSimulations(model, solver, edata)[0]
# output for easy debugging
for key in ['llh', 'sllh']: