Commit 4c376390 authored by SOLIMAN Sylvain's avatar SOLIMAN Sylvain
Browse files

first preliminary lemon graph format export

parent bc203f46
......@@ -88,6 +88,7 @@ influence_graph(GraphId) :-
inhibitors: Inhibitors,
products: Products
]),
Origin = Item,
substract_list(Reactants, Products, Difference),
(
member(_ * Input, Reactants),
......@@ -112,6 +113,7 @@ influence_graph(GraphId) :-
sign: RuleSign,
output: Output
]),
Origin = Item,
(
member(Input, PositiveInputs),
InputSign = +
......@@ -139,6 +141,13 @@ influence_graph(GraphId) :-
)
;
set_attribute(EdgeId, sign = Sign)
),
(
get_attribute(EdgeId, origin = OldOrigin)
->
set_attribute(EdgeId, origin = [(Sign, Origin) | OldOrigin])
;
set_attribute(EdgeId, origin = [(Sign, Origin)])
)
)
),
......
:- module(
lemon,
[
% Public API
export_lemon_graph/1
]
).
:- use_module(doc).
:- use_module(counters).
export_lemon_graph(OutputFile) :-
automatic_suffix(OutputFile, '.lgf', write, FilenameLgf),
setup_call_cleanup(
open(FilenameLgf, write, Stream),
export_lemon_stream(Stream),
close(Stream)
).
export_lemon_stream(Stream) :-
setup_call_cleanup(
new_graph(GraphId),
(
influence_graph(GraphId),
export_lemon_stream(GraphId, Stream)
),
delete_item(GraphId)
).
:- dynamic(species/2).
export_lemon_stream(Id, Stream) :-
write(Stream, '@nodes\nlabel\tspecies\n'),
set_counter(species, 0),
retractall(species(_, _)),
forall(
item([parent: Id, kind: vertex, item: VertexName]),
(
count(species, Count),
assertz(species(VertexName, Count)),
format(Stream, '~w\t~w\n', [Count, VertexName])
)
),
write(Stream, '@arcs\n\t\tlabel\treaction\tsign\n'),
number_reactions,
set_counter(influences, 0),
forall(
item([parent: Id, kind: edge, item: Edge, id: EdgeId]),
(
Edge = (VertexA -> VertexB),
species(VertexA, IdA),
species(VertexB, IdB),
count(influences, Count),
get_attribute(EdgeId, origin = Origin),
forall(
member((Sign, Reaction), Origin),
(
reactions(Reaction, RId),
sign(Sign, SignNumber),
format(
Stream,
'~w\t~w\t~w\t~w\t~w\n',
[IdA, IdB, Count, RId, SignNumber]
)
)
)
)
),
% TODO conservation laws
write(Stream, '@attributes\n').
:- dynamic(reactions/2).
% TODO handle reverse reactions
number_reactions :-
retractall(reactions(_, _)),
set_counter(reactions, 0),
forall(
item([kind: reaction, item: Item]),
(
count(reactions, Count),
assertz(reactions(Item, Count))
)
).
sign('+', 1).
sign('-', -1).
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