Commit 384e3f6c authored by FAGES Francois's avatar FAGES Francois

ode

parent b84bdd14
......@@ -10,6 +10,9 @@
]
).
:- doc('Petri Net Place-invariants provide linear conservation laws for the differential semantics of a reaction system.
They can be verified or computed with the commands below. Note that such invariants are useful information but it may be not a good idea to use them to reduce
the dimensionality of the system since it may introduce numerical unstabilities.').
add_conservation(Conservation) :-
biocham_command,
......
......@@ -40,19 +40,6 @@ devcom(_) :-
grammar_doc(_) :-
doc('Writes documentation annotation for a grammar.').
:- devcom('FF: As a general rule I would like that the output of a biocham command be always accepted as input as a Biocham command, making possible to edit a model by copy and paste. For instance for list-parameters etc.').
:- devcom('SS: for some commands, it seems like a good idea, but for others I
am not so sure. A well formatted table might be more readable than a list of
commands…').
:- devcom('FF: If so it may mean that the well formatted table should be accepted as input of the command').
:- devcom('FF: I would like that also for creating the tests .plt but this is even more complicated with the distinction between prolog predicates, command(), biocham() and the differences for passing the options which seem to me artificially complicated and should be uniform. To discuss together to see how to improve that...').
:- devcom('FF: Unitary tests on biocham predicates should rather be integration tests in different files: .plt for unitary tests and .bct or perhaps .ipynb for integration tests.').
:- devcom('FF: I twould be nice to put the Prolog edition styles in the git to uniformize the edition the source code but we had problems for emacs on Mac').
devdoc_biocham(_) :-
doc('Writes the trace of a Biocham execution in the Developer Manual.').
......
......@@ -13,7 +13,10 @@
:- use_module(reaction_rules).
:- doc('Events can be used to change some parameter values once a condition gets satisfied. This is useful to implement discrete events such as a the division of cell mass by 2 at each division in a model of the cell cycle, or hybrid automata which chain different continuous semantics (ODEs), or massively for stochastic simulators defined by events and hybrid differential-stochastic silmulators \\cite{CFJS15tomacs}. ').
:- doc('Events can be used to change some parameter values once a condition gets satisfied. This is useful to implement discrete events in a variety of situations.
Events can be used in modelling, for instance for dividing the cell mass by 2 at each division in a model of the cell cycle,
or for creating hybrid automata model, which chain different continuous semantics (ODEs).
Events can also be intensively used to implement stochastic simulators defined by events, and hybrid differential-stochastic simulators \\cite{CFJS15tomacs}. ').
:- devdoc('\\section{Commands}').
......
......@@ -18,9 +18,9 @@
:- use_module(influence_rules).
:- doc('The following commands enumerate all the boolean attractors of the positive boolean semantics of influence (and reaction?) systems \\cite{FMSR16cmsb}.').
:- doc('The following commands refer to the Boolean semantics of BIOCHAM models which can be either positive (i.e. without negation, the inhibitors are ignored)
or negative (the inhibitors of a reaction or an influence are interpreted as negative conditions) \\cite{FMSR16cmsb}.').
:- devcom('FF: to generalize to reaction systems. Check the positive semantics option (rather than influence model) both for reaction and influence systems').
list_stable_states :-
biocham_command,
......
......@@ -19,6 +19,7 @@
:- use_module(doc).
:- use_module(reaction_rules).
:- doc('BIOCHAM models can also be defined by influence systems with forces. In the syntax described below, one influence rule (either positive "->" or negative "-<") expresses that a conjunction of sources (or their negation after the "/") has an influence on a target molecular species. This syntax necessitates to write the Boolean activation (resp. deactivation) function of a molecular species in Disjunctive Normal Form with several positive (resp. negative) influences \\cite{FMRS16cmsb}.').
:- devdoc('\\section{Grammars}').
......@@ -37,16 +38,14 @@ influence(BasicInfluence) :-
:- grammar(basic_influence).
basic_influence(Inputs -> Output) :-
basic_influence(Inputs -> Output) :-
inputs(Inputs),
object(Output).
basic_influence(Inputs -< Output) :-
basic_influence(Inputs -< Output) :-
inputs(Inputs),
object(Output).
:- grammar(inputs).
......
......@@ -20,9 +20,12 @@
import_ode/1,
import_reactions_from_ode_system/0,
(init)/1,
load_ode_system/1,
add_ode_system/1,
export_ode_system/1,
% load_ode_system/1,
load_reactions_from_ode/1,
% add_ode_system/1,
add_reactions_from_ode/1,
% export_ode_system/1,
export_ode/1,
% Public API
add_ode_system_file/1,
new_ode_system/1,
......@@ -50,6 +53,8 @@
:- doc('Biocham can also manipulate ODE systems written in the following XPP syntax, and infer a reaction system, or an influence system, with the same ODE semantics. This is useful for using Biocham analyzers on ODE models.').
:- doc('Warning: XPP format has restrictions on names and does not distinguish between upper case and lower case letters. As a consequence, some complex names may be not properly exported in ode files, and when an ode file is imported, the names are read in lower case.').
:- devdoc('\\section{Grammars}').
:- grammar(ode).
......@@ -73,6 +78,86 @@ oderef(X) :-
:- doc('The following commands list or save in a file the ODE system of the current model.').
list_ode :-
biocham_command,
doc('
returns the set of ordinary differential equations
and initial concentrations (one line per molecule)
associated to the current model.
\\begin{example}
'),
biocham_silent(clear_model),
biocham(a => b),
biocham(list_ode),
doc('
\\end{example}
'),
with_current_ode_system((
get_current_ode_system(Id),
list_items([parent: Id, kind: ode])
)).
%export_ode_system(OutputFile) :-
export_ode(OutputFile) :-
biocham_command,
type(OutputFile, output_file),
doc('exports the ODE system of the current model.'),
with_current_ode_system(with_output_to_file(OutputFile, print_ode_system)).
:- doc('The following commands infer a reaction system, or an influence system, equivalent to an ODE system in a file.').
%load_ode_system(InputFile) :-
load_reactions_from_ode(InputFile) :-
biocham_command,
type(InputFile, input_file),
doc('
infers a reaction system from an ODE system and loads it as \\command{load_biocham/1}.
'),
models:load_all('ode', InputFile).
%add_ode(InputFile) :-
add_reactions_from_ode(InputFile) :-
biocham_command,
type(InputFile, input_file),
doc('
infers a set of reactions equivalent to an ODE system and add it to the current model as \\command{add_biocham/1}.
'),
models:add_all('ode', InputFile).
:- doc('ODE systems can also be created and manipulated in BIOCHAM with the following commands.').
ode_system :-
biocham_command,
doc('
builds the set of ODES corresponding to the reactions of the current model.
'),
delete_ode_system('ode_system'),
new_ode_system,
set_ode_system_name('ode_system'),
with_clean(
[ode:assoc/2],
(
ode:compute_ode,
ode:simplify_ode,
ode:put_ode_into_system
)
),
get_current_ode_system(Id),
forall(
item([kind: parameter, item: parameter(Parameter = Value)]),
set_ode_parameters(Id, Parameter = Value)
),
forall(
item([no_inheritance, kind: function, item: function(Function = Definition)]),
set_ode_function(Id, Function = Definition)
).
import_ode(InputFile) :-
biocham_command,
......@@ -82,12 +167,6 @@ import_ode(InputFile) :-
set_current_ode_system(Id).
export_ode_system(OutputFile) :-
biocham_command,
type(OutputFile, output_file),
doc('exports the current ODE system.'),
with_current_ode_system(with_output_to_file(OutputFile, print_ode_system)).
new_ode_system :-
biocham_command,
doc('creates an ODE system.'),
......@@ -124,8 +203,6 @@ select_ode_system(Name) :-
set_current_ode_system(Id).
:- doc('The following commands manipulate the current ODE system.').
add_ode(ODE) :-
ode(ODE),
......@@ -175,85 +252,16 @@ init(InitList) :-
)
).
:- doc('The following commands list or create the ODE system associated to the current model.').
list_ode :-
biocham_command,
doc('
returns the set of ordinary differential equations
and initial concentrations (one line per molecule)
associated to the current model.
\\begin{example}
'),
biocham_silent(clear_model),
biocham(a => b),
biocham(list_ode),
doc('
\\end{example}
'),
with_current_ode_system((
get_current_ode_system(Id),
list_items([parent: Id, kind: ode])
)).
ode_system :-
biocham_command,
doc('
builds the set of ODES corresponding to the reactions of the current model.
'),
delete_ode_system('ode_system'),
new_ode_system,
set_ode_system_name('ode_system'),
with_clean(
[ode:assoc/2],
(
ode:compute_ode,
ode:simplify_ode,
ode:put_ode_into_system
)
),
get_current_ode_system(Id),
forall(
item([kind: parameter, item: parameter(Parameter = Value)]),
set_ode_parameters(Id, Parameter = Value)
),
forall(
item([no_inheritance, kind: function, item: function(Function = Definition)]),
set_ode_function(Id, Function = Definition)
).
:- doc('The following commands infer a reaction system, or an influence system, from an ODE system.').
import_reactions_from_ode_system :-
biocham_command,
doc('adds the reactions that match the current ODE system.'),
doc('adds the reactions inferred from the current ODE system.'),
get_current_ode_system(Id),
!,
import_reactions_from_ode_system(Id).
:- devcom('FF: import_influences_from_odes should be useful also.').
load_ode_system(InputFile) :-
biocham_command,
type(InputFile, input_file),
doc('
infers a reaction system from an ODE system and loads it as \\command{load_biocham/1}.
'),
models:load_all('ode', InputFile).
import_reactions_from_ode_system :-
print_message(warning,'there is no current ode system').
add_ode_system(InputFile) :-
biocham_command,
type(InputFile, input_file),
doc('
infers a set of reactions equivalent to an ODE system and add it to the current model as \\command{add_biocham/1}.
'),
models:load_all('ode', InputFile).
:- devdoc('\\section{Public API}').
......@@ -783,21 +791,21 @@ print_ode_system :-
\+ (
item([parent: Id, kind: initial_concentration, item: (init X = E)]),
\+ (
format('init ~p = ~p\n', [X, E])
format('init ~w = ~w\n', [X, E]) % ~p would quote atoms which is not accepted in xpp syntax
)
),
forall(
item([parent: Id, kind: parameter, item: (par K = V)]),
format('par ~p = ~p\n', [K, V])
format('par ~w = ~w\n', [K, V])
),
forall(
item([parent: Id, kind: function, item: (func F = D)]),
format('~p = ~p\n', [F, D])
format('~w = ~w\n', [F, D])
),
\+ (
item([parent: Id, kind: ode, item: (d(X)/dt = E)]),
\+ (
format('d~p/dt = ~p\n', [X, E])
format('d~w/dt = ~w\n', [X, E])
)
),
format('done\n').
......
......@@ -51,7 +51,7 @@ test(
test(
'export_ode_system',
'export_ode', %'export_ode_system',
[true((Lines, Reactions) == (
[
'init b = 0', 'init a = 1', 'par k = 2',
......@@ -64,7 +64,7 @@ test(
command('MA'(k) for a => b),
command(parameter(k = 2)),
command(present(a)),
export_ode_system('test.ode'),
export_ode('test.ode'), %export_ode_system('test.ode'),
list_file_lines('test.ode', Lines),
import_ode('test.ode'),
delete_file('test.ode'),
......
......@@ -13,39 +13,39 @@ add_function(FunctionList) :-
biocham_command(*),
type(FunctionList, '*'(term = term)),
doc('
adds reactions to compute the result of a function of the current variables in the concentration of a new variable at steady state.
adds reactions to compute the result of a function of the current variables in the concentration of a new variable, at steady state.
\\begin{example}
'),
biocham_silent(clear_model),
biocham(present(x,1)),
biocham(present(y,3)),
biocham(add_function(z=x+y)),
biocham(list_reactions),
biocham(list_ode),
biocham(list_model),
doc('
\\end{example}
'),
new_ode_system(OdeSystem),
export_ode(FunctionList, OdeSystem),
create_ode(FunctionList, OdeSystem),
import_reactions_from_ode_system(OdeSystem),
delete_item(OdeSystem).
export_ode(_, OdeSystem) :-
enumerate_molecules(L), % useless if item backtracks on Object (not clear to FF)
create_ode(_, OdeSystem) :-
enumerate_molecules(L), % useless if item backtracks on Object
member(Object, L),
get_initial_concentration(Object, Concentration),
set_ode_initial_value(OdeSystem, Object, Concentration),
fail.
export_ode(FunctionList, OdeSystem) :-
create_ode(FunctionList, OdeSystem) :-
member(Variable = _, FunctionList),
set_ode_initial_value(OdeSystem, Variable, 0),
fail.
export_ode(FunctionList, OdeSystem) :-
create_ode(FunctionList, OdeSystem) :-
member(Variable = Value, FunctionList),
add_ode(OdeSystem, d(Variable)/dt = Value - Variable),
fail.
export_ode(_,_).
create_ode(_,_).
......@@ -14,9 +14,11 @@
:- use_module(doc).
:- use_module(biocham).
:- dynamic(state/1).
:- doc('Boolean traces can also be generated from the stochastic semantics of a BIOCHAM (reaction or influence) model.').
:- doc('Instantiation of Leslie Valiant''s PAC-Learning framework to influence
systems and time-series data \\cite{CFS17cmsb}.').
:- doc('Threshold values can be specified to transform a stochastic trace in a Boolean trace with the following syntax:').
:- grammar(transform).
......@@ -28,83 +30,6 @@ transform(threshold(T)) :-
integer(T).
pac_learning(TimeSeriesFiles) :-
biocham_command,
type(TimeSeriesFiles, {input_file}),
doc(
'Uses every time-series \\texttt{.csv} file in \\argument{TimeSeriesFiles}
as source of samples to learn an influence system.'
),
option(cnf_clause_size, integer, _, 'Maximum size of CNF clauses learnt.'),
retractall(state(_)),
forall(
(
member(TimeSeriesPattern, TimeSeriesFiles),
filename(TimeSeriesPattern, Filename),
csv_read_file(Filename, Data),
member(Row, Data),
Row =.. [row | State]
),
assertz(state(State))
),
pac_learning.
:- initial(option(data_transform: none)).
:- initial(option(cnf_clause_size: 3)).
:- initial(option(boolean_simulation: no)).
pac_learning(ModelFile, NInitialStates, TimeHorizon) :-
biocham_command,
type(ModelFile, input_file),
type(NInitialStates, integer),
type(TimeHorizon, integer),
doc(
'Loads \\argument{ModelFile} and runs \\command{generate_traces/3} with
the provided arguments and then loads the generated files for
\\command{pac_learning/1}.
\\begin{example}
\\trace{
biocham: pac_learning(library:examples/lotka_volterra/LVi.bc, 200, 10,
boolean_simulation: yes).
biocham: pac_learning(library:examples/circadian_cycle/bernot_comet.bc, 100, 10).
}
\\end{example}
\\clearmodel'
),
option(cnf_clause_size, integer, _, 'Maximum size of CNF clauses learnt.'),
option(data_transform, transform, Transform,
'transformation of the traces before learning'
),
option(boolean_simulation, yesno, Boolean,
'use a boolean simulation (sbn) instead of the default stochastic one
(spn) to generate the data'
),
load(ModelFile),
with_option(
[data_transform: Transform, boolean_simulation: Boolean],
generate_traces(NInitialStates, TimeHorizon, '')
),
statistics(walltime, _),
pac_learning,
% TODO maybe we should clear_model here
statistics(walltime, [_, MilliTime]),
debug(pac_learning, 'Clause learning time: ~p ms', [MilliTime]).
pac_learning :-
state([_ | MList]),
!,
length(MList, NbMolecules),
learn_k_cnf(NbMolecules).
:- dynamic(state/1).
generate_traces(NInitialStates, TimeHorizon, FilePrefix) :-
......@@ -211,6 +136,89 @@ threshold(T, N, TN) :-
TN = 0
).
:- doc('Implementation of Leslie Valiant''s PAC-Learning algoritm for k-CNF formulae, for learning influence systems from time-series data \\cite{CFS17cmsb}.').
pac_learning(TimeSeriesFiles) :-
biocham_command,
type(TimeSeriesFiles, {input_file}),
doc(
'Uses every time-series \\texttt{.csv} file in \\argument{TimeSeriesFiles}
as source of samples to learn an influence system.'
),
option(cnf_clause_size, integer, _, 'Maximum size of CNF clauses learnt.'),
retractall(state(_)),
forall(
(
member(TimeSeriesPattern, TimeSeriesFiles),
filename(TimeSeriesPattern, Filename),
csv_read_file(Filename, Data),
member(Row, Data),
Row =.. [row | State]
),
assertz(state(State))
),
pac_learning.
:- initial(option(data_transform: none)).
:- initial(option(cnf_clause_size: 3)).
:- initial(option(boolean_simulation: no)).
pac_learning(ModelFile, NInitialStates, TimeHorizon) :-
biocham_command,
type(ModelFile, input_file),
type(NInitialStates, integer),
type(TimeHorizon, integer),
doc(
'Loads \\argument{ModelFile} and runs \\command{generate_traces/3} with
the provided arguments and then loads the generated files for
\\command{pac_learning/1}.
\\begin{example}
Learning Lotka-Volterra model from Boolean traces and comparison to the hidden original model.
\\trace{
biocham: pac_learning(library:examples/lotka_volterra/LVi.bc, 200, 10,
boolean_simulation: yes).
biocham: list_model.
biocham: pac_learning(library:examples/circadian_cycle/bernot_comet.bc, 100, 10).
biocham: list_model.
}
\\end{example}
\\clearmodel'
),
option(cnf_clause_size, integer, _, 'Maximum size of CNF clauses learnt.'),
option(data_transform, transform, Transform,
'transformation of the traces before learning'
),
option(boolean_simulation, yesno, Boolean,
'use a boolean simulation (sbn) instead of the default stochastic one
(spn) to generate the data'
),
load(ModelFile),
with_option(
[data_transform: Transform, boolean_simulation: Boolean],
generate_traces(NInitialStates, TimeHorizon, '')
),
statistics(walltime, _),
pac_learning,
% TODO maybe we should clear_model here
statistics(walltime, [_, MilliTime]),
debug(pac_learning, 'Clause learning time: ~p ms', [MilliTime]).
pac_learning :-
state([_ | MList]),
!,
length(MList, NbMolecules),
learn_k_cnf(NbMolecules).
:- dynamic(clauses/3).
......
......@@ -37,7 +37,7 @@ reaction_graph :-
rule_graph :-
biocham_command,
doc('
Builds the rule graph of the current model, \emph{i.e.} the union of
Builds the rule graph of the current model, \\emph{i.e.} the union of
the reaction graph and the influence graph.
'),
delete_items([kind: graph, key: rule_graph]),
......
......@@ -23,6 +23,9 @@
:- use_module(doc).
:- use_module(objects).
:- doc('A BIOCHAM model can be defined by a reaction system, i.e. a finite (multi)set of directed reaction rules with rate functions using the syntax below.
A reaction system represents a Chemical Reaction Network (CRN) and is compatible with the Systems Biology Markup Language SBML.').
:- devdoc('\\section{Grammars}').
......
% BIOCHAM model file
% Reaction rules
[a] for a=>b.
% Initial state
absent(a).
absent(b).
......@@ -11,7 +11,8 @@
- toplevel.pl
- about.pl
- namespace.pl
* Part I: Rule-based Models of Biochemical Processes
* Part I: Biochemical Reaction Networks
- part1.pl
* Biochemical Objects
** Syntax
- filename.pl
......@@ -27,7 +28,7 @@
** Initial state
- initial_state.pl
* Reaction Systems
** Syntax of reactions and transport rules
#** Syntax of reactions and transport rules
- reaction_rules.pl
- kinetics.pl
- types.pl
......@@ -39,7 +40,7 @@
- graph_editor.pl
- graphviz.pl
* Influence Systems
** Syntax of influence systems
#** Syntax of influence systems
- influence_rules.pl
** Influence editor
- influence_editor.pl
......@@ -55,28 +56,32 @@
- qual_files.pl
** ODE files
- ode.pl
** Graphics files
** Other files
* Part II: Qualitative Analyses
#** Graphics files
#** Other files
* Part II: Qualitative Analyses and Synthesis
* Static Analyses
** Dimensional analysis
- na.pl
** Conservation laws and invariants
- conservation_laws.pl
- invariants.pl
** Tropical algebra equilibrations
- tropical.pl
** Detecting model reduction relationships
- na.pl
* Qualitative Behavior Specification, Verification and Synthesis
** Boolean attractors
- influence_properties.pl
** Boolean temporal logic CTL
** Computation Tree Logic (CTL) properties
- ctl.pl
- nusmv.pl
** Model reduction from CTL specification
- reduce.pl
** Model revision from CTL specification
- revision.pl
** PAC Learning
** PAC Learning influence models from Boolean traces
- pac_learning.pl
* Part III: Quantitative Analyses and Model Synthesis
* Part III: Quantitative Analyses and Synthesis
* Numerical Simulations
** ODE and stochastic simulations
- arithmetic_rules.pl
......@@ -86,6 +91,7 @@
- numerical_simulation.pl
- markov.pl
** Hybrid simulations
- na.pl
** Plotting and exporting the result of simulations
- plot.pl
** Variations and bifurcations
......@@ -93,13 +99,13 @@
* Quantitative Behavior Specification, Verification and Synthesis
** Numerical data time series
- tables.pl
** Tropical equilibrations
- tropical.pl
** Temporal logic FO-LTL(Rlin)
** Temporal logic FO-LTL(Rlin) properties
- foltl.pl
** Robustness of FO-LTL(Rlin) properties
** Sensitivity to parameters
** Synthesis of parameter values
- na.pl
** Parameter sensitivity
- na.pl
** Synthesis of parameter values satisfying FO-LTL(Rlin) properties
- search.pl
* Reaction System Synthesis from Input/Output Functions and Programs
** Synthesis from mathematical expressions
......@@ -110,11 +116,11 @@
- gpac.pl
** Synthesis from transfer functions
- transfer_function.pl
** Synthesis from programs
- analog_digital.pl
* Part IV: Wrap-Up
* Biocham Model Analyzer
- analysis.pl
#** Synthesis from programs
#- analog_digital.pl
#* Part IV: Wrap-Up
#* Biocham Model Analyzer
#- analysis.pl
* Index
- index
* Bibliography
......
......@@ -13,7 +13,8 @@
:- use_module(library(clpfd)).
:- doc('Tropical equilibration search as per \\cite{SFR14almob}.').
:- doc('Tropical algebra can be used to reason about orders of magnitude of molecular concentrations, kinetic parameters and reactions rates.
The solutions to tropical equilibration problems provide candidates for regimes exhibiting fast-slow dynamics leading to model reductions \\cite{SFR14almob}.').
% store monomials of -inf degree
......
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