reduce.pl 5.92 KB
Newer Older
FAGES Francois's avatar
FAGES Francois committed
1 2 3
:- module(
  reduce,
  [
FAGES Francois's avatar
FAGES Francois committed
4 5
    reduce_model/1,
    reduce_model/0,
FAGES Francois's avatar
FAGES Francois committed
6 7
    delete_molecule/1,
    merge_molecules/2
FAGES Francois's avatar
FAGES Francois committed
8 9 10 11 12 13 14 15 16
  ]
).

:- use_module(ctl).

% Only for separate compilation/linting
:- use_module(nusmv).
:- use_module(util).

FAGES Francois's avatar
FAGES Francois committed
17
:- doc('This section describes commands to reduce a reaction model by deleting species, deleting reactions, merging species and merging reactions. We refer to \\cite{GSF10bi} for the use of these operations for detecting model reduction relationships in BioModels, and to \\cite{GFS14dam} for the theory of these graphical operations which are equivalent to subgraph epimorphisms (SEPI). We also provide a model reduction command which automatically finds a model reduction preserving the CTL specification of the behavior.').
FAGES Francois's avatar
FAGES Francois committed
18 19

:- devcom('FF: These commands should be generalized, 
FAGES Francois's avatar
FAGES Francois committed
20
first, to deletions and merge of molecules and reactions (easy SEPI linear for deletions quadratic for mergings) done!
FAGES Francois's avatar
FAGES Francois committed
21

FAGES Francois's avatar
FAGES Francois committed
22 23 24
second, to influence systems and hybrid reaction-influence systems (great SEPI unification),  See CMSB 2017 paper ;-)

and third, to hybrid attractors, CTL, FOLTL, trace specifications of the behavior.').
FAGES Francois's avatar
FAGES Francois committed
25 26 27 28

:- devdoc('\\section{Commands}').


FAGES Francois's avatar
FAGES Francois committed
29
reduce_model(Query) :-
FAGES Francois's avatar
FAGES Francois committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43
    biocham_command,
    type(Query, ctl),
    doc(
	          'Deletes reactions as long as the specification of the behavior given by a CTL formula passed as
    argument remains satisfied in the current initial state.'
	      ),
    (
	      ctl_truth(Query,true)
     ->
	       reduce_model(Query, Removed),
	       format('removed ~p\n',[Removed])
     ;
     print('Error: the specification is not satisfied in the current model.')
    ).
FAGES Francois's avatar
FAGES Francois committed
44

FAGES Francois's avatar
FAGES Francois committed
45
reduce_model :-
FAGES Francois's avatar
FAGES Francois committed
46 47
    biocham_command,
    doc('Same as above using the current CTL
FAGES Francois's avatar
FAGES Francois committed
48
    specification of the behavior.'),
FAGES Francois's avatar
FAGES Francois committed
49 50 51
    findall(Formula, item([kind: ctl_spec, item: Formula]), Specs),
    join_with_op(Specs, '/\\', Spec),
    reduce_model(Spec).
FAGES Francois's avatar
FAGES Francois committed
52

53 54 55 56 57 58 59 60 61 62
:- doc('\\begin{example}').
:- biocham_silent(clear_model).
:- biocham(a=>b).
:- biocham(b=>c).
:- biocham(c=>d).
:- biocham(present(b)).
:- biocham(make_absent_not_present).
:- biocham(generate_ctl).
:- biocham(reduce_model).
:- doc('\\end{example}').  
FAGES Francois's avatar
FAGES Francois committed
63

FAGES Francois's avatar
FAGES Francois committed
64 65 66 67
:- doc("\\begin{example}
Reduction of the MAPK model with respect to the output reachability property only:
all dephosphorylation reactions can be removed, resulting in a different bifurcation diagram with full memory effect.
\\trace{
68
biocham: load('library:examples/mapk/mapk.bc').
FAGES Francois's avatar
FAGES Francois committed
69 70
biocham: reduce_model(reachable('MAPK~{p1,p2}')).
removed ['RAF-RAFK'=>'RAF'+'RAFK','RAF~{p1}'+'RAFPH'=>'RAF~{p1}-RAFPH','RAF~{p1}-RAFPH'=>'RAF~{p1}'+'RAFPH','MEK-RAF~{p1}'=>'MEK'+'RAF~{p1}','MEK~{p1}-RAF~{p1}'=>'MEK~{p1}'+'RAF~{p1}','MEKPH'+'MEK~{p1}'=>'MEK~{p1}-MEKPH','MEK~{p1}-MEKPH'=>'MEKPH'+'MEK~{p1}','MEKPH'+'MEK~{p1,p2}'=>'MEK~{p1,p2}-MEKPH','MEK~{p1,p2}-MEKPH'=>'MEKPH'+'MEK~{p1,p2}','MAPK-MEK~{p1,p2}'=>'MAPK'+'MEK~{p1,p2}','MAPK~{p1}-MEK~{p1,p2}'=>'MAPK~{p1}'+'MEK~{p1,p2}','MAPKPH'+'MAPK~{p1}'=>'MAPK~{p1}-MAPKPH','MAPK~{p1}-MAPKPH'=>'MAPKPH'+'MAPK~{p1}','MAPKPH'+'MAPK~{p1,p2}'=>'MAPK~{p1,p2}-MAPKPH','MAPK~{p1,p2}-MAPKPH'=>'MAPKPH'+'MAPK~{p1,p2}','RAF~{p1}-RAFPH'=>'RAF'+'RAFPH','MEK~{p1}-MEKPH'=>'MEK'+'MEKPH','MEK~{p1,p2}-MEKPH'=>'MEK~{p1}'+'MEKPH','MAPK~{p1}-MAPKPH'=>'MAPK'+'MAPKPH','MAPK~{p1,p2}-MAPKPH'=>'MAPK~{p1}'+'MAPKPH']
71
biocham: dose_response('RAFK',1e-5,1e-3, time:200, show:'MAPK~{p1,p2}').
FAGES Francois's avatar
FAGES Francois committed
72 73 74
}
\\end{example}
").
FAGES Francois's avatar
FAGES Francois committed
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90

:- devcom(
	          'FF: todo with options sepi_reduce_model Deletes and/or merges molecules and/or reactions (aka subgraph epimorphism, SEPI reduction) as long as the specification of the behavior given by a CTL formula passed as
    argument remains satisfied in the current initial state.
').

%	       delete_molecules(Query, MoleculesRemoved),
%	       format('molecules removed ~p\n',[MoleculesRemoved]),
%	       merge_molecules(Query, MoleculesMerged),
%	       format('removed ~p\n',[MoleculesMerged]),
%	       delete_reactions(Query, ReactionsRemoved),
%	       format('removed ~p\n',[ReactionsRemoved]),
%	       merge_reactions(Query, ReactionsMerged),
%	       format('removed ~p\n',[ReactionsMerged])


FAGES Francois's avatar
FAGES Francois committed
91
delete_molecule(M):-
92 93 94 95
  biocham_command,
  doc('Deletes a molecule and its aliases from the current model, by replacing them by a parameter set to the initial value of the concentration.'),
  get_initial_concentration(M, C),
  \+ (
FAGES Francois's avatar
FAGES Francois committed
96
    item([kind: initial_state, id: Id, key:M]),
97 98 99 100 101 102
    \+ (
      delete_item(Id)
    )
  ),
  set_parameter(M, C),
  \+ (
FAGES Francois's avatar
FAGES Francois committed
103
    item([kind: reaction, id: Id, item: Reaction]),
104 105 106 107 108 109 110 111 112 113 114 115
    reaction(Reaction, [
      reactants: Reactants,
      inhibitors: Inhibitors,
      products: Products
    ]),
    (member(_ * M, Reactants) ; member(_ * M, Inhibitors) ; member(_ * M, Products)),
    \+ (
      delete_item(Id),
      rewrite_molecule_in_reaction(M, Reaction, SimplifiedReaction),
      add_item([kind: reaction, item: SimplifiedReaction])
    )
  ).
FAGES Francois's avatar
FAGES Francois committed
116

FAGES Francois's avatar
FAGES Francois committed
117 118 119

merge_molecules(M,N):-
  biocham_command,
FAGES Francois's avatar
FAGES Francois committed
120 121
  type(M, object),
  type(N, object),
FAGES Francois's avatar
FAGES Francois committed
122
  doc('
FAGES Francois's avatar
FAGES Francois committed
123
    merges two molecules by creating an alias making the second molecule canonical, and with initial concentration set to the sum of the initial concentrations of the merged molecules.
FAGES Francois's avatar
FAGES Francois committed
124
  '),
FAGES Francois's avatar
FAGES Francois committed
125
  devcom('FF should be the semantics of alias which should be synonymous'),
FAGES Francois's avatar
FAGES Francois committed
126 127 128 129 130 131 132 133
  get_initial_concentration(M, CM),
  get_initial_concentration(N, CN),
  alias(M=N),
  canonical(N),
  C is CM+CN,
  present(N,C).


FAGES Francois's avatar
FAGES Francois committed
134 135
:- devdoc('\\section{Public API}').

FAGES Francois's avatar
FAGES Francois committed
136

FAGES Francois's avatar
FAGES Francois committed
137
reduce_model(Query,Removed):-
FAGES Francois's avatar
FAGES Francois committed
138 139
    findall(Item, item([kind: reaction, item: Item]), Reactions),
    reduce_model(Reactions,Query, Removed).
FAGES Francois's avatar
FAGES Francois committed
140 141


FAGES Francois's avatar
FAGES Francois committed
142 143
:- devdoc('\\section{Internal predicates}').

FAGES Francois's avatar
FAGES Francois committed
144 145 146 147 148 149 150 151 152 153 154 155 156 157
reduce_model([R|Reactions],Query, Result) :-
  delete_item([kind: reaction, item: R]),
  item([kind: option, item: option(nusmv_initial_states: Init)]),
  item([kind: option, item: option(boolean_semantics: Bool)]),
  check_ctl_impl(Query, Init, no, Bool, true),
  !,
  Result=[R|Removed],
  reduce_model(Reactions,Query,Removed).

reduce_model([R|Reactions],Query, Removed) :-
  add_item([kind: reaction, item: R]),
  reduce_model(Reactions,Query,Removed).

reduce_model([],_,[]).