Commit 5fe362d4 authored by Thierry Martinez's avatar Thierry Martinez

export_biocham and list_model

parent 31a2ad61
:- module( :- module(
functions, functions,
[ [
% Commands
'function'/1, 'function'/1,
show_function/1, show_function/1,
list_functions/0, list_functions/0,
delete_function/1, delete_function/1,
% Public API
function_apply/2, function_apply/2,
list_model_functions/0,
op(1010, fx, function) op(1010, fx, function)
] ]
). ).
...@@ -82,3 +85,32 @@ function_apply(FunctionApplication, NewBody) :- ...@@ -82,3 +85,32 @@ function_apply(FunctionApplication, NewBody) :-
Head =.. [Functor | Parameters], Head =.. [Functor | Parameters],
FunctionApplication =.. [Functor | Arguments], FunctionApplication =.. [Functor | Arguments],
substitute(Parameters, Arguments, Body, NewBody). substitute(Parameters, Arguments, Body, NewBody).
list_model_functions :-
devdoc('
lists all the functions in a loadable syntax
(auxiliary predicate of list_model).
'),
(
item([no_inheritance, kind: function])
->
write('function(\n'),
assertz(first),
\+ (
item([no_inheritance, kind: function, item: function(Head = Body)]),
\+ (
(
retract(first)
->
true
;
write(',\n')
),
format(' ~w = ~w', [Head, Body])
)
),
write('\n).\n')
;
true
).
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
% Public API % Public API
is_influence_model/0, is_influence_model/0,
check_influence_model/0, check_influence_model/0,
list_model_influences/0,
influence/5 influence/5
] ]
). ).
...@@ -71,6 +72,19 @@ check_influence_model :- ...@@ -71,6 +72,19 @@ check_influence_model :-
). ).
list_model_influences :-
devdoc('
lists all the influence rules in a loadable syntax
(auxiliary predicate of list_model).
'),
\+ (
item([no_inheritance, kind: influence, item: Influence]),
\+ (
format('~w.\n', [Influence])
)
).
prolog:error_message(not_an_influence_model) --> prolog:error_message(not_an_influence_model) -->
['Not an influence model']. ['Not an influence model'].
......
:- module( :- module(
models, models,
[ [
% Commands
load/1, load/1,
add/1, add/1,
load_biocham/1, load_biocham/1,
add_biocham/1, add_biocham/1,
export_biocham/1,
new_model/0, new_model/0,
clear_model/0, clear_model/0,
list_models/0, list_models/0,
list_current_models/0, list_current_models/0,
list_model/0,
range/1, range/1,
ref/1, ref/1,
select_model/1, select_model/1,
...@@ -96,6 +99,22 @@ add_biocham(InputFile) :- ...@@ -96,6 +99,22 @@ add_biocham(InputFile) :-
add_all('bc', InputFile). add_all('bc', InputFile).
export_biocham(OutputFile) :-
biocham_command,
type(OutputFile, output_file),
doc('
exports the current model into a \\texttt{.bc} file.
'),
setup_call_cleanup(
open(OutputFile, write, Stream),
with_output_to(
Stream,
list_model
),
close(Stream)
).
new_model :- new_model :-
biocham_command, biocham_command,
doc('opens a new fresh model.'), doc('opens a new fresh model.'),
...@@ -116,17 +135,32 @@ clear_model :- ...@@ -116,17 +135,32 @@ clear_model :-
list_models :- list_models :-
biocham_command, biocham_command,
doc('lists all open models'), doc('lists all open models.'),
list_items([parent: top, kind: model]). list_items([parent: top, kind: model]).
list_current_models :- list_current_models :-
biocham_command, biocham_command,
doc('lists current models'), doc('lists current models.'),
current_models(CurrentModels), current_models(CurrentModels),
list_ids(CurrentModels). list_ids(CurrentModels).
list_model :-
biocham_command,
doc('lists the contents of the current Biocham model.'),
(
is_reaction_model
->
list_model_reactions
;
is_influence_model
->
list_model_influences
),
list_model_parameters,
list_model_functions.
:- grammar(range). :- grammar(range).
...@@ -889,3 +923,4 @@ at_delete(Id, Goal) :- ...@@ -889,3 +923,4 @@ at_delete(Id, Goal) :-
get_parent(Id, ParentId) :- get_parent(Id, ParentId) :-
item(Id, ParentId, _, _). item(Id, ParentId, _, _).
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
:- begin_tests(models). :- begin_tests(models).
test('new_model', [true(Reactions == [])]) :- test('new_model', [Reactions == []]) :-
new_model, new_model,
single_model(Id0), single_model(Id0),
add_reaction(a => b), add_reaction(a => b),
...@@ -21,11 +21,23 @@ test('new_model inherits from initial') :- ...@@ -21,11 +21,23 @@ test('new_model inherits from initial') :-
get_model_name(InitialId, 'initial') get_model_name(InitialId, 'initial')
)). )).
test('load', [true(Name == mapk)]) :- test('load', [Name == mapk]) :-
command(load(library:examples/mapk/mapk)), command(load(library:examples/mapk/mapk)),
single_model(Id), single_model(Id),
get_model_name(Id, Name), get_model_name(Id, Name),
delete_item(Id). delete_item(Id).
test(
'list_model',
[Output == 'MA(k)for a=>b.\nset_parameter(\n k = 1\n).\n']
) :-
clear_model,
command('MA'(k) for a => b),
command(set_parameter(k = 1)),
with_output_to(
atom(Output),
list_model
).
:- end_tests(models). :- end_tests(models).
:- module( :- module(
parameters, parameters,
[ [
% Commands
set_parameter/1, set_parameter/1,
get_parameter_value/2, get_parameter_value/2,
show_parameter/1, show_parameter/1,
list_parameters/0, list_parameters/0,
delete_parameter/1 delete_parameter/1,
% Public API
list_model_parameters/0
] ]
). ).
:- devdoc('\\section{Commands}').
set_parameter(ParameterList) :- set_parameter(ParameterList) :-
biocham_command(*), biocham_command(*),
type(ParameterList, '*'(parameter = arithmetic_expression)), type(ParameterList, '*'(parameter = arithmetic_expression)),
...@@ -25,6 +31,7 @@ set_parameter(ParameterList) :- ...@@ -25,6 +31,7 @@ set_parameter(ParameterList) :-
get_parameter_value(Parameter, Value) :- get_parameter_value(Parameter, Value) :-
find_item([kind: parameter, key: Parameter, item: parameter(_, Value)]). find_item([kind: parameter, key: Parameter, item: parameter(_, Value)]).
show_parameter(Parameter) :- show_parameter(Parameter) :-
biocham_command, biocham_command,
type(Parameter, parameter), type(Parameter, parameter),
...@@ -50,3 +57,35 @@ delete_parameter(ParameterSet) :- ...@@ -50,3 +57,35 @@ delete_parameter(ParameterSet) :-
delete_item([kind: parameter, key: Parameter]) delete_item([kind: parameter, key: Parameter])
) )
). ).
:- devdoc('\\section{Public API}').
list_model_parameters :-
devdoc('
lists all the parameters in a loadable syntax
(auxiliary predicate of list_model).
'),
(
item([no_inheritance, kind: parameter])
->
write('set_parameter(\n'),
assertz(first),
\+ (
item([kind: parameter, item: parameter(Parameter = Value)]),
\+ (
(
retract(first)
->
true
;
write(',\n')
),
format(' ~w = ~w', [Parameter, Value])
)
),
write('\n).\n')
;
true
).
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
% Public API % Public API
is_reaction_model/0, is_reaction_model/0,
check_reaction_model/0, check_reaction_model/0,
list_model_reactions/0,
reaction/5, reaction/5,
reaction/4, reaction/4,
enumerate_molecules/1, enumerate_molecules/1,
...@@ -81,6 +82,19 @@ check_reaction_model :- ...@@ -81,6 +82,19 @@ check_reaction_model :-
). ).
list_model_reactions :-
devdoc('
lists all the reaction rules in a loadable syntax
(auxiliary predicate of list_model).
'),
\+ (
item([no_inheritance, kind: reaction, item: Reaction]),
\+ (
format('~w.\n', [Reaction])
)
).
prolog:error_message(not_a_reaction_model) --> prolog:error_message(not_a_reaction_model) -->
['Not a reaction model']. ['Not a reaction model'].
......
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