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

Import SBML events in Biocham (see #1)

parent c78ab0f3
......@@ -93,6 +93,16 @@ PL_get_function(term_t function_term, FunctionDefinition_t **function) {
return PL_get_pointer(function_term, (void **) function);
}
int
PL_get_event(term_t event_term, Event_t **event) {
return PL_get_pointer(event_term, (void **) event);
}
int
PL_get_assignment(term_t assignment_term, EventAssignment_t **assignment) {
return PL_get_pointer(assignment_term, (void **) assignment);
}
int
PL_unify_sbmlDocument_or_free(term_t document_term, SBMLDocument_t *document) {
int result = PL_unify_pointer(document_term, document);
......@@ -212,6 +222,16 @@ pl_model_getListOfFunctions(term_t model_term, term_t listOfFunctions_term) {
PL_succeed;
}
static foreign_t
pl_model_getListOfEvents(term_t model_term, term_t listOfEvents_term) {
Model_t *model;
ListOf_t *listOfEvents;
PL_check(PL_get_model(model_term, &model));
PL_check(listOfEvents = Model_getListOfEvents(model));
PL_check(PL_unify_pointer(listOfEvents_term, listOfEvents));
PL_succeed;
}
static foreign_t
pl_model_getSpeciesById(
term_t model_term, term_t id_term, term_t species_term
......@@ -533,8 +553,7 @@ 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));
get_formula_from_math(FunctionDefinition_getBody(function), formula_term);
PL_succeed;
}
......@@ -560,6 +579,45 @@ pl_function_getArgument(term_t function_term, term_t num_term, term_t arg_term)
PL_succeed;
}
static foreign_t
pl_event_getTrigger(term_t event_term, term_t formula_term) {
Event_t *event;
const ASTNode_t *math;
PL_check(PL_get_event(event_term, &event));
PL_check(math = Trigger_getMath(Event_getTrigger(event)));
get_formula_from_math(math, formula_term);
PL_succeed;
}
static foreign_t
pl_event_getAssignments(term_t event_term, term_t list_term) {
Event_t *event;
ListOf_t *list;
PL_check(PL_get_event(event_term, &event));
PL_check(list = Event_getListOfEventAssignments(event));
PL_check(PL_unify_pointer(list_term, list));
PL_succeed;
}
static foreign_t
pl_assignment_getVar(term_t assignment_term, term_t formula_term) {
EventAssignment_t *assignment;
const char *name;
PL_check(PL_get_assignment(assignment_term, &assignment));
PL_check(name = EventAssignment_getVariable(assignment));
PL_check(PL_unify_atom_chars(formula_term, name));
PL_succeed;
}
static foreign_t
pl_assignment_getBody(term_t assignment_term, term_t formula_term) {
EventAssignment_t *assignment;
const char *formula;
PL_check(PL_get_assignment(assignment_term, &assignment));
get_formula_from_math(EventAssignment_getMath(assignment), formula_term);
PL_succeed;
}
static foreign_t
pl_is_assignment(term_t rule_term) {
Rule_t *rule;
......@@ -657,6 +715,7 @@ PL_extension sbml_predicates[] = {
{ "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_getListOfEvents", 2, (pl_function_t) pl_model_getListOfEvents, 0 },
{ "model_getSpeciesById", 3, (pl_function_t) pl_model_getSpeciesById, 0 },
{ "model_getTimeUnits", 2, (pl_function_t) pl_model_getTimeUnits, 0 },
{ "model_getSubstanceUnits", 2, (pl_function_t) pl_model_getSubstanceUnits, 0 },
......@@ -693,6 +752,10 @@ PL_extension sbml_predicates[] = {
{ "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 },
{ "event_getTrigger", 2, (pl_function_t) pl_event_getTrigger, 0 },
{ "event_getAssignments", 2, (pl_function_t) pl_event_getAssignments, 0 },
{ "assignment_getVar", 2, (pl_function_t) pl_assignment_getVar, 0 },
{ "assignment_getBody", 2, (pl_function_t) pl_assignment_getBody, 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 },
......
......@@ -6,6 +6,7 @@
model_species/2,
model_assignment_rule/2,
model_function/2,
model_event/2,
reaction_reactant/2,
reaction_modifier/2,
reaction_product/2,
......@@ -16,6 +17,7 @@
parameter_id_and_value/3,
rule_var_and_math/3,
function_name_args_body/4,
event_cond_assign/3,
model_compartment/2,
model_parameter/2,
compartment_volume/3,
......@@ -62,6 +64,11 @@ model_function(Model, Function) :-
member_listof(Function, ListOfFunctions).
model_event(Model, Event) :-
model_getListOfEvents(Model, ListOfEvents),
member_listof(Event, ListOfEvents).
reaction_reactant(Reaction, Reactant) :-
reaction_getListOfReactants(Reaction, ListOfReactants),
member_listof(Reactant, ListOfReactants).
......@@ -148,17 +155,40 @@ function_name_args_body(Function, Name, Args, Body) :-
).
event_cond_assign(Event, Cond, Assignments) :-
event_getTrigger(Event, CondAtom),
sbml_atom_to_term(CondAtom, Cond),
event_getAssignments(Event, AssignmentListPointer),
findall(
A,
member_listof(A, AssignmentListPointer),
AssignmentList
),
findall(
Param = Body,
(
member(Assignment, AssignmentList),
assignment_getVar(Assignment, Param),
%% FIXME we ignore silently assignments to non-parameters
parameter_value(Param, _),
assignment_getBody(Assignment, BodyAtom),
sbml_atom_to_term(BodyAtom, Body)
),
Assignments
).
sbml_atom_to_term(Atom, Term) :-
read_term_from_atom(Atom, STerm, [variable_names(Names)]),
name_variables_and_anonymous(STerm, Names),
substitute_functor(pow, ^, STerm, Term).
substitute_functor([(pow, ^), (gt, >), (geq, >=), (eq, =), (leq, =<), (lt, <), (neq, \=)], STerm, Term).
substitute_functor(F1, F2, X, Y) :-
substitute_functor(FList, X, Y) :-
X =.. [Functor | Args],
maplist(substitute_functor(F1, F2), Args, SArgs),
maplist(substitute_functor(FList), Args, SArgs),
(
Functor = F1
memberchk((Functor, F2), FList)
->
Y =.. [F2 | SArgs]
;
......
......@@ -78,6 +78,7 @@ add_sbml_model(Model) :-
add_global_parameters(Model),
add_assignment_rules(Model),
add_function_definitions(Model),
add_events(Model),
add_species(Model),
add_reactions(Model).
......@@ -188,6 +189,16 @@ add_function_definitions(Model) :-
).
add_events(Model) :-
forall(
model_event(Model, Event),
(
event_cond_assign(Event, Condition, Assignments),
add_event(Condition, Assignments)
)
).
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