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

Add tests for model_correction

parent 08502566
......@@ -21,7 +21,7 @@ Coder: M. Hemery
correct_model :-
biocham_command,
doc(''),
doc('Improve wellformedness and strictness of a CRN model by removing reactions of null kinetics, splitting reactions that are implicitely reversible in two and adding correct annotation for modifiers.'),
single_model(ModelId),
setof(
Molecule,
......@@ -70,12 +70,20 @@ split_bidirectional_reaction(Expression for Reactant => Product) :-
ode:substitute_functions(Expression, Expr),
distribute(Expr, DistExpr),
DistExpr = Up - Down,
% test if it is effectively a bidir. reaction
models:formal_product(P, Reactant => Product),
present_in_kinetics(P, Down)
->
delete_reaction(Expression for Reactant => Product),
add_reaction(Up for Reactant => Product),
add_reaction(Down for Product => Reactant)
(
Reactant = Reac/Inhib
->
add_reaction(Up for Reactant => Product),
add_reaction(Down for Product/Inhib => Reac)
;
add_reaction(Up for Reactant => Product),
add_reaction(Down for Product => Reactant)
)
).
%! reverse_reaction(+Reaction)
......@@ -110,6 +118,11 @@ correct_modifiers(List_Molecule, Expression_raw for Reaction) :-
).
%! detect_modifiers(+List_Molecule, +Expression, -Catalyst, -Inhibitor)
%
% Search among the list of molecules for catalysts and inhibitors
% note that as only Expression is look at, reactants are sorted as catalysts
detect_modifiers([], _Expression, [], []).
detect_modifiers([Mol|TailM], Expression, NewC, NewI) :-
......@@ -130,11 +143,18 @@ detect_modifiers([Mol|TailM], Expression, NewC, NewI) :-
),
detect_modifiers(TailM, Expression, TailC, TailI).
%! add_catalysts(+List_catalyst, +Reaction, -Modified_Reaction)
%
% modify reaction to add catalysts (let untouch if already present)
add_catalysts([], Reaction, Reaction).
add_catalysts([Head|Tail], Reaction, NewReaction) :-
models:formal_reactant(Head, Reaction),
!,
add_catalysts(Tail, Reaction, NewReaction).
add_catalysts([Head|Tail], Reactants => Products, NewReactants => NProducts+Head) :-
add_catalysts(Tail, Reactants => Products, NReactants => NProducts),
(
......@@ -145,12 +165,18 @@ add_catalysts([Head|Tail], Reactants => Products, NewReactants => NProducts+Head
NewReactants = Reactants+Head
).
% TODO -- remove Head from Reactants & Products if necessary
%! add_inhibitors(+List_inhibitors, +Reaction, -Modified_Reaction)
%
% same as add_catalysts for inhibitors
add_inhibitors([], Reaction, Reaction).
add_inhibitors([Head|Tail], Reaction, NewReaction) :-
models:formal_inhibitor(Head, Reaction),
!,
add_inhibitors(Tail, Reaction, NewReaction).
add_inhibitors(Tail, Reaction, NewReaction).
add_inhibitors([Head|Tail], Reactants => Products, NewReactants => NProducts) :-
add_inhibitors(Tail, Reactants => Products, ReactantsTempo => ProductsTempo),
(
......@@ -168,9 +194,12 @@ add_inhibitors([Head|Tail], Reactants => Products, NewReactants => NProducts) :-
NewReactants = NReactants / Head
).
% remove_molecule(Species, Molecule, Without)
%! remove_molecule(+Species, +Molecule, -Without)
%
% Remove one occurence of Molecule from the Species input
remove_molecule(Molecule, Molecule, '_') :- !.
remove_molecule(P*Molecule, Molecule, Result) :-
(
P = 1
......@@ -184,7 +213,9 @@ remove_molecule(P*Molecule, Molecule, Result) :-
Pm is P-1,
Result = Pm*Molecule
),!.
remove_molecule(Species+Molecule, Molecule, Species) :- !.
remove_molecule(Species+P*Molecule, Molecule, Result) :-
(
P = 1
......@@ -198,9 +229,19 @@ remove_molecule(Species+P*Molecule, Molecule, Result) :-
Pm is P-1,
Result = Species+Pm*Molecule
),!.
remove_molecule(Molecule+Other, Molecule, Result) :- !,
remove_molecule(Other+Molecule, Molecule, Result).
remove_molecule(P*Molecule+Other, Molecule, Result) :- !,
remove_molecule(Other+P*Molecule, Molecule, Result).
remove_molecule(P*Molecule, Molecule, ResultTempo),
(
ResultTempo = '_'
->
Result = Other
;
Result = ResultTempo+Other
).
remove_molecule(Species+Other, Molecule, Without+Other) :-
remove_molecule(Species, Molecule, Without).
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