Skip to content

Commit

Permalink
Fix for SBML kinetic law formula when importing and writing SBML #89 (#…
Browse files Browse the repository at this point in the history
…93)

* add priors, and custom prior

* py_inference wrapper added

* merge master

* add beta and gamma prior

* add custom prior documenting notebook

* all notebooks work

* typo bug fix

* minor update to inference notebooks

* gaussian prior fix

* bug fixes for log uniform prior and pdf computation bound checks

* add checks to rate law math ast
  • Loading branch information
ayush9pandey authored Apr 3, 2021
1 parent 4449f5b commit aeaac92
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 0 additions & 4 deletions bioscrape/pid_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ def exponential_prior(self, param_name, param_value):
lambda_p = prior_dict[param_name][1]

prob = lambda_p * np.exp(-lambda_p * param_value)

if prob < 0:
warnings.warn('Probability less than 0 while checking Exponential prior! Current parameter name and value: {0}:{1}.'.format(param_name, param_value))
return np.inf
Expand Down Expand Up @@ -180,10 +179,8 @@ def log_uniform_prior(self, param_name, param_value):
return np.inf

prob = 1/(param_value* (np.log(upper_bound) - np.log(lower_bound)))

if prob < 0:
warnings.warn('Probability less than 0 while checking Log-Uniform prior! Current parameter name and value: {0}:{1}.'.format(param_name, param_value))

return np.inf
else:
return np.log(prob)
Expand All @@ -204,7 +201,6 @@ def log_gaussian_prior(self, param_name, param_value):
prob = 1/(param_value * np.sqrt(2*np.pi) * sigma) * np.exp((-0.5 * (np.log(param_value) - mu)**2)/sigma**2)
if prob < 0:
warnings.warn('Probability less than 0 while checking log-normal prior! Current parameter name and value: {0}:{1}.'.format(param_name, param_value))

return np.inf
else:
return np.log(prob)
Expand Down
9 changes: 7 additions & 2 deletions bioscrape/sbmlutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ def import_sbml(sbml_file, bioscrape_model = None, input_printout = False, **kwa
allparams[pid] = p.getValue()
# get the formula as a string and then add
# a leading _ to parameter names
kl_formula = libsbml.formulaToL3String(kl.getMath())
math_ast = kl.getMath()
if math_ast is None:
raise ValueError("Could not import the rate law for reaction to SBML.")
kl_formula = libsbml.formulaToL3String(math_ast)
#We should no longer add underscores to parameters
#rate_string = _add_underscore_to_parameters(kl_formula, allparams)
rate_string = kl_formula
Expand Down Expand Up @@ -629,7 +632,9 @@ def add_reaction(model, inputs_list, outputs_list,
ratestring = _remove_underscore_from_parameters(ratestring, allparams)
# Set the ratelaw to the ratestring
math_ast = libsbml.parseL3Formula(ratestring)
ratelaw.setMath(math_ast)
flag = ratelaw.setMath(math_ast)
if not flag == libsbml.LIBSBML_OPERATION_SUCCESS or math_ast is None:
raise ValueError("Could not write the rate law for reaction to SBML. Check the reaction definition.")

#Add propensity annotation
if propensity_annotation and propensity_type != "general":
Expand Down

0 comments on commit aeaac92

Please sign in to comment.