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

export_biocham and list_model

parent 31a2ad61
:- module(
functions,
[
% Commands
'function'/1,
show_function/1,
list_functions/0,
delete_function/1,
% Public API
function_apply/2,
list_model_functions/0,
op(1010, fx, function)
]
).
......@@ -82,3 +85,32 @@ function_apply(FunctionApplication, NewBody) :-
Head =.. [Functor | Parameters],
FunctionApplication =.. [Functor | Arguments],
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 @@
% Public API
is_influence_model/0,
check_influence_model/0,
list_model_influences/0,
influence/5
]
).
......@@ -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) -->
['Not an influence model'].
......
:- module(
models,
[
% Commands
load/1,
add/1,
load_biocham/1,
add_biocham/1,
export_biocham/1,
new_model/0,
clear_model/0,
list_models/0,
list_current_models/0,
list_model/0,
range/1,
ref/1,
select_model/1,
......@@ -96,6 +99,22 @@ add_biocham(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 :-
biocham_command,
doc('opens a new fresh model.'),
......@@ -116,17 +135,32 @@ clear_model :-
list_models :-
biocham_command,
doc('lists all open models'),
doc('lists all open models.'),
list_items([parent: top, kind: model]).
list_current_models :-
biocham_command,
doc('lists current models'),
doc('lists current models.'),
current_models(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).
......@@ -889,3 +923,4 @@ at_delete(Id, Goal) :-
get_parent(Id, ParentId) :-
item(Id, ParentId, _, _).
......@@ -3,7 +3,7 @@
:- begin_tests(models).
test('new_model', [true(Reactions == [])]) :-
test('new_model', [Reactions == []]) :-
new_model,
single_model(Id0),
add_reaction(a => b),
......@@ -21,11 +21,23 @@ test('new_model inherits from initial') :-
get_model_name(InitialId, 'initial')
)).
test('load', [true(Name == mapk)]) :-
test('load', [Name == mapk]) :-
command(load(library:examples/mapk/mapk)),
single_model(Id),
get_model_name(Id, Name),
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).
:- module(
parameters,
[
% Commands
set_parameter/1,
get_parameter_value/2,
show_parameter/1,
list_parameters/0,
delete_parameter/1
delete_parameter/1,
% Public API
list_model_parameters/0
]
).
:- devdoc('\\section{Commands}').
set_parameter(ParameterList) :-
biocham_command(*),
type(ParameterList, '*'(parameter = arithmetic_expression)),
......@@ -25,6 +31,7 @@ set_parameter(ParameterList) :-
get_parameter_value(Parameter, Value) :-
find_item([kind: parameter, key: Parameter, item: parameter(_, Value)]).
show_parameter(Parameter) :-
biocham_command,
type(Parameter, parameter),
......@@ -50,3 +57,35 @@ delete_parameter(ParameterSet) :-
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 @@
% Public API
is_reaction_model/0,
check_reaction_model/0,
list_model_reactions/0,
reaction/5,
reaction/4,
enumerate_molecules/1,
......@@ -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) -->
['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