Commit 197cfed1 authored by Sylvain Soliman's avatar Sylvain Soliman

Proper SBML-qual import as influences, yay!

parent 618accbc
......@@ -3,6 +3,7 @@
[
load_qual/1,
add_qual/1,
% API
add_qual_file/1
]
).
......@@ -49,7 +50,7 @@ add_qual_file(Filename) :-
retractall(qual_species(_)),
forall(
(
xpath(Model, //'qual:qualitativeSpecies',
xpath(Model, '//'('qual:qualitativeSpecies'),
element('qual:qualitativeSpecies', Attributes, [])),
member('qual:id'=Id, Attributes)
),
......@@ -63,7 +64,7 @@ add_qual_file(Filename) :-
)
),
forall(
xpath(Model, //'qual:transition',
xpath(Model, '//'('qual:transition'),
element('qual:transition', _, Transition)),
add_qual_transition(Transition)
).
......@@ -105,11 +106,20 @@ add_qual_functions([], OutputId) :-
default_term(
element('qual:defaultTerm', ['qual:resultLevel'=ResultLevel], [])
),
atom_bool(ResultLevel, AtomLevel),
forall(
function_terms(MathElt, Level),
add_qual_influence(MathElt, OutputId, Level)
),
format('otherwise ~w -> ~w~n', [OutputId, ResultLevel]).
findall(Cond, function_terms(and(Cond), _), Conds),
forall(
maplist(member, NonCond, Conds),
(
notlist(NonCond, NegatedCond),
bool_simplify(and(NegatedCond), SimpleCond),
add_qual_influence(SimpleCond, OutputId, AtomLevel)
)
).
add_qual_functions([Function | L], OutputId) :-
Function = element('qual:functionTerm', ['qual:resultLevel'=Level], [Maths]),
......@@ -119,7 +129,16 @@ add_qual_functions([Function | L], OutputId) :-
mathml_to_bool(MathElt, Bool),
dnf(Bool, DBool),
bool_simplify(DBool, SBool),
assertz(function_terms(SBool, Result)),
(
SBool = or(LBool)
->
forall(
member(OBool, LBool),
assertz(function_terms(OBool, Result))
)
;
assertz(function_terms(SBool, Result))
),
add_qual_functions(L, OutputId).
add_qual_functions([Default | L], OutputId) :-
......@@ -137,6 +156,8 @@ add_qual_influence(and(L), OutputId, Level) :-
Influence =.. [Arrow, Inputs, OutputId],
add_influence(Influence).
add_qual_influence(false, _, _).
level_arrow(Level, Arrow) :-
(
......@@ -189,23 +210,32 @@ atom_bool(Atom, Bool) :-
).
bool_simplify(geq(_, 0), true).
bool_simplify(geq(_, 0), true) :-
!.
bool_simplify(geq(X, 1), X).
bool_simplify(geq(X, 1), X) :-
!.
bool_simplify(gt(X, _), X).
bool_simplify(gt(X, _), X) :-
!.
bool_simplify(leq(_, 1), true).
bool_simplify(leq(_, 1), true) :-
!.
bool_simplify(leq(X, 0), not(X)).
bool_simplify(leq(X, 0), not(X)) :-
!.
bool_simplify(lt(X, _), not(X)).
bool_simplify(lt(X, _), not(X)) :-
!.
bool_simplify(eq(X, 0), not(X)).
bool_simplify(eq(X, 0), not(X)) :-
!.
bool_simplify(eq(X, 1), X).
bool_simplify(eq(X, 1), X) :-
!.
bool_simplify(and(L), And) :-
!,
maplist(bool_simplify, L, LL),
list_to_set(LL, S),
subtract(S, [true], LLL),
......@@ -227,6 +257,7 @@ bool_simplify(and(L), And) :-
).
bool_simplify(or(L), Or) :-
!,
maplist(bool_simplify, L, LL),
list_to_set(LL, S),
subtract(S, [false], LLL),
......@@ -251,6 +282,8 @@ bool_simplify(or(L), Or) :-
Or = or(LLL)
).
bool_simplify(X, X).
dnf(and(X, Y), And) :-
!,
......@@ -314,3 +347,13 @@ dnf(or(X, Y), Or) :-
).
dnf(X, and([X])).
notlist([], []).
notlist([not(H) | T], [H | NotT]) :-
!,
notlist(T, NotT).
notlist([H | T], [not(H) | NotT]) :-
notlist(T, NotT).
:- use_module(library(plunit)).
:- use_module(reaction_rules).
:- use_module(influence_rules).
:- begin_tests(sbml_qual_files).
% FIXME no unit test, only one integration test, could be better
test(
'load_qual',
[true(Influences = [ 'B' -> 'BL', 'BL' -> 'BLL' | _ ])]
[true(Influences = [
('A'->'B'), (/'A'-<'B'),
('C','A'->'A'), ('C'/'A'->'A'),
('A'/'C'-<'A'), (/'C'-<'A'), (/'A','C'-<'A'),
('B'->'C'), (/'B'-<'C')])]
) :-
load('modules/sbml/examples/foo_grn.sbml'),
all_items([kind: influence], Influences).
......
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