Commit c8678513 authored by Mathieu Hemery's avatar Mathieu Hemery
Browse files

Better test for recognizing reactant, inhibitor and catalyst

parent 4052e698
......@@ -334,8 +334,7 @@ check_model :-
format("The model is NOT wellformed.~n", [])
),
(
maplist(test_all_reactions(catalyst, test_strictness), List_Molecule),
maplist(test_all_reactions(reactant, test_strictness), List_Molecule)
test_strictness(List_Molecule, List_Reaction)
->
format("The model is strict.~n", [])
;
......@@ -1321,20 +1320,36 @@ introduce_param(Func, Func2) :-
introduce_param(O,O).
%! test_all_reactions(+Type, +Test, +Molecule)
%
% apply test to all the reactions where Molecule is present as Type (catalyst, etc.)
% Type is concatenate with 'reactions_with_', cf reaction_rules.pl
%! formal_reactant(+Molecule, +Reaction)
test_all_reactions(Type, Test, Molecule) :-
atomic_concat('reactions_with_', Type, Apply),
Constructor =.. [Apply, [Molecule], List_Reactions],
call(Constructor),
forall(
member(Expression for _Reaction, List_Reactions),
(The_test =.. [Test, Molecule, Expression],
call(The_test))
).
formal_reactant(Mol, Reactants => _Products) :- !,
is_present(Mol, Reactants).
formal_reactant(Mol, Reactants/_Inhibtors => _Products) :- !,
is_present(Mol, Reactants).
%! formal_catalyst(+Molecule, +Reaction)
formal_catalyst(Mol, Reactants => Products) :- !,
is_present(Mol, Reactants),
is_present(Mol, Products).
formal_catalyst(Mol, Reactants/_Inhibtors => Products) :- !,
is_present(Mol, Reactants),
is_present(Mol, Products).
%! formal_inhibitor(+Molecule, +Reaction)
formal_inhibitor(Mol, _Reactants/Inhibitors => _Products) :- !,
is_present(Mol, Inhibitors).
% is_present(Mol, Expr)
is_present(A, A) :- !.
is_present(A, A+_Tail) :- !.
is_present(A, _K*A+_Tail) :- !.
is_present(A, _H+Tail) :- is_present(A, Tail).
%! test_wellformed(+List_Molecule, +Reaction)
......@@ -1345,7 +1360,8 @@ test_wellformed([], _Reaction).
test_wellformed(_Molecules, 'MA'(_R) for _Reaction).
test_wellformed([Molecule|Tail], Expression for Reaction) :-
test_wellformed([Molecule|Tail], Expression_raw for Reaction) :-
ode:substitute_functions(Expression_raw, Expression),
(
% detect null kinetics as a warning
is_null(Expression)
......@@ -1353,11 +1369,11 @@ test_wellformed([Molecule|Tail], Expression for Reaction) :-
format("WARNING: Some kinetics are detected as null: ~w~n", [Expression]),
fail
;
is_reactant(Molecule, Expression for Reaction)
formal_reactant(Molecule, Reaction)
->
test_wf_reactant(Molecule, Expression)
;
is_inhibitor(Molecule, Expression for Reaction)
formal_inhibitor(Molecule, Reaction)
->
test_wf_inhibitor(Molecule, Expression)
;
......@@ -1405,15 +1421,36 @@ test_wf_other(Molecule, Expression) :-
),!.
%! test_strictness(+Molecule, +Expression)
%! test_strictness(+List_Molecule, +List_Reaction)
%
% Check if Expression is null when Molecule is absent
test_strictness(Molecule, Expression) :-
substitute([Molecule], [0], Expression, Output),
test_strictness(_List_Molecules, []).
test_strictness(List_Molecules, [Expr for Reaction|TailReac]) :-
ode:substitute_functions(Expr, Expression),
test_strictness_sr(List_Molecules, Expression for Reaction),
test_strictness(List_Molecules, TailReac).
test_strictness_sr(_Molecules, 'MA'(_R) => _).
test_strictness_sr([], _).
test_strictness_sr([Molecule|Tail], Expression for Reaction) :-
(
is_null(Output)
formal_catalyst(Molecule, Reaction),
test_strictness_sr(Tail, Expression for Reaction)
;
format("Due to: ~w while checking ~w;~n", [Expression, Molecule]),
fail
),!.
formal_reactant(Molecule, Reaction)
->
substitute([Molecule], [0], Expression, Output),
(
is_null(Output)
;
format("Due to: ~w while checking ~w;~n", [Expression, Molecule]),
fail
),!
;
test_strictness_sr(Tail, Expression for Reaction)
).
......@@ -67,4 +67,11 @@ test('test_strictness', []):-
\+(test_strictness(a, k1*a - k2*b))
)).
test('test_model_with_function', []) :-
(
biocham(function(f(a,b)=a*b)),
biocham(f(a,b) for a+b => c),
biocham(check_model)
).
:- end_tests(models).
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