Commit cf6e0676 authored by SOLIMAN Sylvain's avatar SOLIMAN Sylvain
Browse files

import function definitions from SBML

parent 5225eb58
......@@ -35,6 +35,10 @@
parameter_getValue/2,
rule_getVariable/2,
rule_getMath/2,
function_getName/2,
function_getBody/2,
function_getNumArguments/2,
function_getArgument/3,
is_assignment/1,
compartment_getId/2,
compartment_getVolume/2
......
......@@ -67,6 +67,11 @@ PL_get_rule(term_t rule_term, Rule_t **rule) {
return PL_get_pointer(rule_term, (void **) rule);
}
int
PL_get_function(term_t function_term, FunctionDefinition_t **function) {
return PL_get_pointer(function_term, (void **) function);
}
int
PL_unify_sbmlDocument_or_free(term_t document_term, SBMLDocument_t *document) {
int result = PL_unify_pointer(document_term, document);
......@@ -176,6 +181,16 @@ pl_model_getListOfRules(term_t model_term, term_t listOfRules_term) {
PL_succeed;
}
static foreign_t
pl_model_getListOfFunctions(term_t model_term, term_t listOfFunctions_term) {
Model_t *model;
ListOf_t *listOfFunctions;
PL_check(PL_get_model(model_term, &model));
PL_check(listOfFunctions = Model_getListOfFunctionDefinitions(model));
PL_check(PL_unify_pointer(listOfFunctions_term, listOfFunctions));
PL_succeed;
}
static foreign_t
pl_model_getSpeciesById(
term_t model_term, term_t id_term, term_t species_term
......@@ -482,6 +497,48 @@ pl_rule_getMath(term_t rule_term, term_t formula_term) {
PL_succeed;
}
static foreign_t
pl_function_getName(term_t function_term, term_t formula_term) {
FunctionDefinition_t *function;
const char *name;
PL_check(PL_get_function(function_term, &function));
PL_check(name = FunctionDefinition_getId(function));
PL_check(PL_unify_atom_chars(formula_term, name));
PL_succeed;
}
static foreign_t
pl_function_getBody(term_t function_term, term_t formula_term) {
FunctionDefinition_t *function;
const char *formula;
PL_check(PL_get_function(function_term, &function));
PL_check(formula = SBML_formulaToString(FunctionDefinition_getBody(function)));
PL_check(PL_unify_atom_chars(formula_term, formula));
PL_succeed;
}
static foreign_t
pl_function_getNumArguments(term_t function_term, term_t num_term) {
FunctionDefinition_t *function;
unsigned int n;
PL_check(PL_get_function(function_term, &function));
PL_check(n = FunctionDefinition_getNumArguments(function));
PL_check(PL_unify_integer(num_term, n));
PL_succeed;
}
static foreign_t
pl_function_getArgument(term_t function_term, term_t num_term, term_t arg_term) {
FunctionDefinition_t *function;
const char *argument;
int num;
PL_check(PL_get_function(function_term, &function));
PL_check(PL_get_integer(num_term, &num));
PL_check(argument = SBML_formulaToString(FunctionDefinition_getArgument(function, num)));
PL_check(PL_unify_atom_chars(arg_term, argument));
PL_succeed;
}
static foreign_t
pl_is_assignment(term_t rule_term) {
Rule_t *rule;
......@@ -521,6 +578,7 @@ PL_extension sbml_predicates[] = {
{ "model_getListOfCompartments", 2, (pl_function_t) pl_model_getListOfCompartments, 0 },
{ "model_getListOfParameters", 2, (pl_function_t) pl_model_getListOfParameters, 0 },
{ "model_getListOfRules", 2, (pl_function_t) pl_model_getListOfRules, 0 },
{ "model_getListOfFunctions", 2, (pl_function_t) pl_model_getListOfFunctions, 0 },
{ "model_getSpeciesById", 3, (pl_function_t) pl_model_getSpeciesById, 0 },
{ "listOf_get", 3, (pl_function_t) pl_listOf_get, 0 },
{ "listOf_size", 2, (pl_function_t) pl_listOf_size, 0 },
......@@ -550,6 +608,10 @@ PL_extension sbml_predicates[] = {
{ "parameter_getValue", 2, (pl_function_t) pl_parameter_getValue, 0 },
{ "rule_getVariable", 2, (pl_function_t) pl_rule_getVariable, 0 },
{ "rule_getMath", 2, (pl_function_t) pl_rule_getMath, 0 },
{ "function_getName", 2, (pl_function_t) pl_function_getName, 0 },
{ "function_getBody", 2, (pl_function_t) pl_function_getBody, 0 },
{ "function_getNumArguments", 2, (pl_function_t) pl_function_getNumArguments, 0 },
{ "function_getArgument", 3, (pl_function_t) pl_function_getArgument, 0 },
{ "compartment_getId", 2, (pl_function_t) pl_compartment_getId, 0 },
{ "compartment_getVolume", 2, (pl_function_t) pl_compartment_getVolume, 0 },
{ "is_assignment", 1, (pl_function_t) pl_is_assignment, 0 },
......
......@@ -5,6 +5,7 @@
model_reaction/2,
model_species/2,
model_assignment_rule/2,
model_function/2,
reaction_reactant/2,
reaction_modifier/2,
reaction_product/2,
......@@ -14,6 +15,7 @@
species_has_only_substance_units/1,
parameter_id_and_value/3,
rule_var_and_math/3,
function_name_args_body/4,
model_compartment/2,
model_parameter/2,
compartment_volume/3,
......@@ -55,6 +57,11 @@ model_assignment_rule(Model, Rule) :-
is_assignment(Rule).
model_function(Model, Function) :-
model_getListOfFunctions(Model, ListOfFunctions),
member_listof(Function, ListOfFunctions).
reaction_reactant(Reaction, Reactant) :-
reaction_getListOfReactants(Reaction, ListOfReactants),
member_listof(Reactant, ListOfReactants).
......@@ -126,6 +133,21 @@ rule_var_and_math(Rule, Variable, Math) :-
sbml_atom_to_term(MathAtom, Math).
function_name_args_body(Function, Name, Args, Body) :-
function_getName(Function, Name),
function_getBody(Function, BodyAtom),
sbml_atom_to_term(BodyAtom, Body),
function_getNumArguments(Function, NumArgs),
findall(
Arg,
(
between(0, NumArgs, Index),
function_getArgument(Function, Index, Arg)
),
Args
).
sbml_atom_to_term(Atom, Term) :-
read_term_from_atom(Atom, STerm, [variable_names(Names)]),
name_variables_and_anonymous(STerm, Names),
......
......@@ -76,6 +76,7 @@ add_sbml_model(Model) :-
add_compartments(Model),
add_global_parameters(Model),
add_assignment_rules(Model),
add_function_definitions(Model),
add_species(Model),
add_reactions(Model).
......@@ -167,6 +168,17 @@ add_assignment_rules(Model) :-
).
add_function_definitions(Model) :-
forall(
model_function(Model, Function),
(
function_name_args_body(Function, Name, Args, Body),
Func =.. [Name | Args],
function([Func = Body])
)
).
global_local_parameters([], _Rid, Kinetics, Kinetics).
global_local_parameters([Parameter | LocalParameters], Rid, LKinetics, GKinetics) :-
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment