Commit 48f02cb8 authored by MARTINEZ Thierry 's avatar MARTINEZ Thierry

SBML

parent 694ac592
......@@ -9,9 +9,11 @@ $(foreach var, CC PLBASE PLCFLAGS PLLDFLAGS PLLIB, \
grep ^$(var)= | \
sed -E 's/="/=/;s/";$$//')))
CFLAGS=-I modules/graphviz -I $(PLBASE)/include $(PLCFLAGS)
INCLUDEDIRS=modules/graphviz $(PLBASE)/include
LDFLAGS=$(PLLDFLAGS) -L $(wildcard $(PLBASE)/lib/*)
CFLAGS=$(addprefix -I, $(INCLUDEDIRS)) $(PLCFLAGS)
LDFLAGS=$(PLLDFLAGS) $(addprefix -L, $(dir $(wildcard $(PLBASE)/lib/*/)))
LDLIBS=$(PLLIB) `pkg-config --libs libgvc`
......@@ -19,18 +21,26 @@ all: biocham biocham_debug test doc
.PHONY: test doc clean
biocham: swipl-biocham $(MODULES) toc.org Makefile
./swipl-biocham -o biocham \
biocham: platform/current swipl-biocham $(MODULES) toc.org Makefile
$(PWD)/swipl-biocham -o biocham \
--goal=start --toplevel=toplevel -c $(MODULES)
biocham_debug: swipl-biocham $(MODULES) $(TEST_MODULES) toc.org Makefile
./swipl-biocham -o biocham_debug \
biocham_debug: platform/current swipl-biocham $(MODULES) $(TEST_MODULES) \
toc.org Makefile
$(PWD)/swipl-biocham -o biocham_debug \
--goal=initialize -c $(MODULES) $(TEST_MODULES)
swipl-biocham: swipl-biocham.o modules/graphviz/graphviz_swiprolog.o
swipl-biocham.o: swipl-biocham.c
modules/graphviz/graphviz_swiprolog.o:
make -C modules/graphviz
platform/current:
- rm platform/current
ln -s `uname` platform/current
test: biocham_tests
./biocham_tests
......@@ -43,6 +53,8 @@ biocham_tests: $(MODULES) $(TEST_MODULES) Makefile
-c $(MODULES) $(TEST_MODULES)
clean:
- make -C modules/graphviz clean
- rm platform/current
- rm biocham
- rm biocham_debug
- rm biocham_tests
......
......@@ -39,6 +39,9 @@ initialize :-
prolog_history(enable),
set_counter(item_id, 0),
set_plot_driver(gnu_plot),
set_image_viewer_driver(open_file),
set_draw_graph_driver(graph_pdf),
nb_setval(graph_pdf, 0),
new_model.
......
......@@ -37,7 +37,8 @@ biocham_silent(_).
generate_doc :-
set_plot_driver(gnu_plot_png),
set_counter(plot_png, 0),
set_image_viewer_driver(img_tag),
set_draw_graph_driver(graph_svg),
generate_doc(doc),
generate_doc(devdoc).
......@@ -48,6 +49,8 @@ generate_doc(Type) :-
error(existence_error(directory, _), _),
true
),
set_counter(plot_png, 0),
set_counter(graph_svg, 0),
working_directory(OldDir, Type),
format(atom(IndexFilename), 'index.html', [Type]),
setup_call_cleanup(
......
......@@ -2,8 +2,8 @@
graphviz,
[
draw_graph/0,
draw_graph_png/1,
export_graph/1
export_graph/1,
set_draw_graph_driver/1
]
).
......@@ -13,32 +13,72 @@
draw_graph :-
biocham_command,
doc('').
doc('Draws the current graph.'),
get_draw_graph_driver(Driver),
Driver.
draw_graph_png(OutputFile) :-
export_graph(OutputFile) :-
biocham_command,
type(OutputFile, output_file),
doc('Draws the current graph in a \\texttt{.png} file.'),
get_current_graph(GraphId),
create_cgraph(GraphId, Graph),
gvLayout(Graph, dot),
gvRenderFilename(Graph, png, OutputFile),
gvFreeLayout(Graph),
agclose(Graph).
doc('
Exports the current graph in a file.
The format is chosen from the suffix:
\\texttt{.dot}, \ttexttt{.pdf}, \ttexttt{.eps}, \ttexttt{.ps},
\ttexttt{.png} or \ttexttt{.svg}
-- assuming no extension is \\texttt{.dot}.
'),
chop_suffix(OutputFile, Suffix),
export_graph(Suffix, OutputFile).
export_graph(OutputFile) :-
biocham_command,
type(OutputFile, output_file),
doc('Exports the current graph as a \\texttt{.dot} file.'),
:- devdoc('\\section{Public API}').
set_draw_graph_driver(Driver) :-
nb_setval(draw_graph_driver, Driver).
:- devdoc('\\section{Internal predicates}').
export_graph('', OutputFile) :-
atom_concat(OutputFile, '.dot', FilenameDot),
export_graph('.dot', FilenameDot).
export_graph('.dot', OutputFile) :-
get_current_graph(GraphId),
create_cgraph(GraphId, Graph),
agwrite(Graph, OutputFile),
agclose(Graph).
export_graph('.pdf', OutputFile) :-
render_current_graph('pdf', OutputFile).
:- devdoc('\\section{Internal predicates}').
export_graph('.eps', OutputFile) :-
render_current_graph('eps', OutputFile).
export_graph('.ps', OutputFile) :-
render_current_graph('ps', OutputFile).
export_graph('.png', OutputFile) :-
render_current_graph('png', OutputFile).
export_graph('.svg', OutputFile) :-
render_current_graph('svg', OutputFile).
get_draw_graph_driver(Driver) :-
nb_getval(draw_graph_driver, Driver).
render_current_graph(Format, OutputFile) :-
get_current_graph(GraphId),
create_cgraph(GraphId, Graph),
gvLayout(Graph, dot),
gvRenderFilename(Graph, Format, OutputFile),
gvFreeLayout(Graph),
agclose(Graph).
create_cgraph(GraphId, Graph) :-
......@@ -46,7 +86,7 @@ create_cgraph(GraphId, Graph) :-
agopen(GraphName, directed, Graph),
agattr(Graph, graph, size, '7.5,11', _),
agattr(Graph, graph, ratio, fill, _),
agattr(Graph, node, shape, circle, _),
agattr(Graph, node, shape, ellipse, _),
\+ (
item([parent: GraphId, kind: vertex, item: VertexName, id: VertexId]),
\+ (
......@@ -70,3 +110,24 @@ create_cgraph(GraphId, Graph) :-
agedge(Graph, NodeA, NodeB, EdgeName, true, _Edge)
)
).
graph_png :-
count(graph_png, Index),
format(atom(Filename), 'graph~d.png', [Index]),
export_graph(Filename),
view_image(Filename).
graph_svg :-
count(graph_svg, Index),
format(atom(Filename), 'graph~d.svg', [Index]),
export_graph(Filename),
view_image(Filename).
graph_pdf :-
count(graph_pdf, Index),
format(atom(Filename), 'graph~d.pdf', [Index]),
export_graph(Filename),
open_file(Filename).
......@@ -4,8 +4,10 @@
solve/2
]).
:- use_module(library(csv)).
solve(Options, Table) :-
\+ memberchk(jacobian: _, Options),
!,
......
......@@ -14,7 +14,7 @@ test(digraph) :-
digraph('test_digraph.dot').
test(simple) :-
simple('test.dot', 'target.dot').
simple('test_digraph.dot', 'target.dot').
test(png) :-
png('test_digraph.dot', 'target.png').
......
:- module(
sbml,
[
readSBML/2,
sbmlDocument_getNumErrors/2,
sbmlDocument_printErrors/2,
sbmlDocument_getModel/2,
sbmlDocument_free/1,
model_getListOfReactions/2,
listOf_get/3,
listOf_size/2,
reaction_getKineticLaw/2,
reaction_getListOfReactants/2,
reaction_getListOfModifiers/2,
reaction_getListOfProducts/2,
reaction_isSetReversible/1,
kineticsLaw_getMath/2,
speciesReference_getSpecies/2,
speciesReference_getStoichiometry/2,
modifierSpeciesReference_getSpecies/2,
modifierSpeciesReference_getStoichiometry/2,
species_getName/2,
species_getInitialAmount/2,
species_getInitialConcentration/2,
writeMathMLToString/2
]
).
:- use_foreign_library(foreign(sbml_swiprolog)).
#include <stdlib.h>
#include <iostream>
#include <sbml/SBMLTypes.h>
int
main (int argc, char *argv[])
{
if (argc != 2) {
std::cerr << "Usage: sbml2biocham filename\n";
return 2;
}
const char *filename = argv[1];
SBMLDocument *document = readSBML(filename);
int severeErrors =
document->getErrorLog()->getNumFailsWithSeverity(LIBSBML_SEV_ERROR);
if (severeErrors > 0) {
document->printErrors();
return EXIT_FAILURE;
}
Model *model = document->getModel();
ListOfReactions *listOfReactions = model->getListOfReactions();
delete document;
return 0;
}
#include <stdio.h>
#include <SWI-Prolog.h>
#include <sbml/SBMLTypes.h>
#include "sbml_swiprolog.h"
#define PL_check(result) \
if (!(result)) { \
PL_fail; \
}
int
PL_get_sbmlDocument(term_t document_term, SBMLDocument_t **document) {
return PL_get_pointer(document_term, (void **) document);
}
int
PL_unify_sbmlDocument_or_free(term_t document_term, SBMLDocument_t *document) {
int result = PL_unify_pointer(document_term, document);
if (!result) {
SBMLDocument_free(graph);
}
return result;
}
static foreign_t
pl_readSBML(term_t filename_term, term_t document_term) {
char *filename;
SBMLDocument_t *document;
PL_check(PL_get_atom_chars(filename_term, &filename));
PL_check(document = readSBML(filename));
PL_check(PL_unify_sbmlDocument_or_free(sbmlDocument_term, document));
PL_success;
}
static foreign_t
pl_sbmlDocument_getNumErrors(term_t document_term, term_t numErrors_term) {
SBMLDocument_t *document;
char *filename;
unsigned int numErrors;
PL_check(PL_get_sbmlDocument(document_term, &document));
PL_check(numErrors = SBMLDocument_getNumErrors(document));
PL_check(PL_unify_integer(numErrors_term, numErrors));
PL_success;
}
static foreign_t
pl_sbmlDocument_printErrors(term_t document_term, term_t output_term) {
SBMLDocument_t *document;
char *filename;
PL_check(PL_get_sbmlDocument(document_term, &document));
// TODO: Handle custom stream
PL_check(SBMLDocument_printErrors(document, stderr));
PL_success;
}
static foreign_t
pl_sbmlDocument_getModel(term_t document_term, term_t model_term) {
SBMLDocument_t *document;
Model_t *model;
PL_check(PL_get_sbmlDocument(document_term, &document));
PL_check(model = SBMLDocument_getModel(document));
PL_check(PL_unify_pointer(model_term, model));
PL_success;
}
static foreign_t
pl_sbmlDocument_free(term_t document_term) {
SBMLDocument_t *document;
PL_check(PL_get_sbmlDocument(document_term, &document));
SBMLDocument_free(document);
PL_success;
}
static foreign_t
pl_model_getListOfReactions(term_t model_term, term_t listOfReactions_term) {
Model_t *model;
ListOf_t *listOfReactions;
PL_check(PL_get_model(model_term, &model));
PL_check(listOfReactions = Model_getListOfReactions(model));
PL_check(PL_unify_pointer(listOfReactions_term, listOfReactions));
PL_success;
}
static foreign_t
pl_listOf_get(term_t listOf_term, term_t index_term, term_t base_term) {
ListOf_t *listOf;
unsigned int index;
SBase_t *base;
PL_check(PL_get_listOf(listOf_term, &listOf));
PL_check(PL_get_integer(index_term, &index));
PL_check(base = ListOf_get(listOf, index));
PL_check(PL_unify_pointer(base_term, base));
PL_success;
}
static foreign_t
pl_listOf_size(term_t listOf_term, term_t size_term) {
ListOf_t *listOf;
unsigned int size;
PL_check(PL_get_listOf(listOf_term, &listOf));
PL_check(size = ListOf_size(listOf));
PL_check(PL_unify_integer(size_term, size));
PL_success;
}
static foreign_t
pl_reaction_getKineticLaw(term_t) {
PL_success;
}
static foreign_t
pl_reaction_getListOfReactants(term_t) {
PL_success;
}
static foreign_t
pl_reaction_getListOfModifiers(term_t) {
PL_success;
}
static foreign_t
pl_reaction_getListOfProducts(term_t) {
PL_success;
}
static foreign_t
pl_reaction_isSetReversible(term_t) {
PL_success;
}
static foreign_t
pl_kineticsLaw_getMath(term_t) {
PL_success;
}
static foreign_t
pl_speciesReference_getSpecies(term_t) {
PL_success;
}
static foreign_t
pl_speciesReference_getStoichiometry(term_t) {
PL_success;
}
static foreign_t
pl_modifierSpeciesReference_getSpecies(term_t) {
PL_success;
}
static foreign_t
pl_modifierSpeciesReference_getStoichiometry(term_t) {
PL_success;
}
static foreign_t
pl_species_getName(term_t) {
PL_success;
}
static foreign_t
pl_species_getInitialAmount(term_t) {
PL_success;
}
static foreign_t
pl_species_getInitialConcentration(term_t) {
PL_success;
}
static foreign_t
pl_writeMathMLToString(term_t) {
PL_success;
}
PL_extension sbml_predicates[] = {
{ "readSBML", 2, pl_readSBML, 0 },
{ "sbmlDocument_getNumErrors", 2, pl_sbmlDocument_getNumErrors, 0 },
{ "sbmlDocument_printErrors", 2, pl_sbmlDocument_printErrors, 0 },
{ "sbmlDocument_getModel", 2, pl_sbmlDocument_getModel, 0 },
{ "sbmlDocument_free", 1, pl_sbmlDocument_free, 0 },
{ "model_getListOfReactions", 2, pl_model_getListOfReactions, 0 },
{ "listOf_get", 3, pl_listOf_get, 0 },
{ "listOf_size", 2, pl_listOf_size, 0 },
{ "reaction_getKineticLaw", 2, pl_reaction_getKineticLaw, 0 },
{ "reaction_getListOfReactants", 2, pl_reaction_getListOfReactants, 0 },
{ "reaction_getListOfModifiers", 2, pl_reaction_getListOfModifiers, 0 },
{ "reaction_getListOfProducts", 2, pl_reaction_getListOfProducts, 0 },
{ "reaction_isSetReversible", 1, pl_reaction_isSetReversible, 0 },
{ "kineticsLaw_getMath", 2, pl_kineticsLaw_getMath, 0 },
{ "speciesReference_getSpecies", 2, pl_speciesReference_getSpecies, 0 },
{ "speciesReference_getStoichiometry", 2,
pl_speciesReference_getStoichiometry, 0 },
{ "modifierSpeciesReference_getSpecies", 2,
pl_modifierSpeciesReference_getSpecies, 0 },
{ "modifierSpeciesReference_getStoichiometry", 2,
pl_modifierSpeciesReference_getStoichiometry, 0 },
{ "species_getName", 2, pl_species_getName, 0 },
{ "species_getInitialAmount", 2, pl_species_getInitialAmount, 0 },
{ "species_getInitialConcentration", 2,
pl_species_getInitialConcentration, 0 },
{ "writeMathMLToString", 2, pl_writeMathMLToString, 0 },
{ NULL, 0, NULL, 0 }
};
install_t
install_sbml_swiprolog(void) {
gvc = gvContext();
PL_register_extensions(sbml_predicates);
}
:- module(
platform,
[
open_file/1
]
).
open_file(Filename) :-
process_create(path('xdg-open'), [Filename], [process(Pid)]),
process_wait(Pid, exit(0)).
......@@ -34,7 +34,7 @@ gnu_plot_png :-
count(plot_png, Index),
format(atom(Filename), 'plot~d.png', [Index]),
export_plot_to_png(Filename),
format('<img src="~a">', [Filename]).
view_image(Filename).
execute_plot(Options) :-
......
......@@ -14,6 +14,7 @@
reaction_graph :-
biocham_command,
doc('Builds the reaction graph of the current model.'),
delete_items([kind: graph, key: reaction_graph]),
new_graph,
set_graph_name(reaction_graph),
set_counter(reaction, 0),
......@@ -86,7 +87,19 @@ import_reactions_from_graph :-
draw_reactions :-
biocham_command,
doc('').
doc('
Draws the reaction graph of the current model.
Equivalent to \\texttt{reaction_graph. draw_graph.}
\\begin{example}
'),
biocham_silent(clear_model),
biocham(load('../examples/mapk/mapk')),
biocham(draw_reactions),
doc('
\\end{example}
'),
reaction_graph,
draw_graph.
:- dynamic(vertex_transition/1).
......
......@@ -3,6 +3,7 @@
- doc.pl
- biocham.pl
- about.pl
- platform/current/platform.pl
** Installing and Running Biocham Locally
- commandline.pl
- util.pl
......
:- use_module(library(plunit)).
:- begin_tests(types).
test('compound', [true(Solution == 'RAF-RAFK')]) :-
check_type(solution, 'RAF'-'RAFK', Solution).
test(
'compound_reaction',
[true(Reaction == ('RAF' + 'RAFK' <=> 1 * 'RAF-RAFK'))]
) :-
check_type(reaction, 'RAF' + 'RAFK' <=> 1 * 'RAF'-'RAFK', Reaction).
:- end_tests(types).
......@@ -11,7 +11,10 @@
nth0_eqq/3,
executable_filename/1,
indent/1,
indent/2
indent/2,
view_image/1,
set_image_viewer_driver/1,
open_file/1
]).
name_variables(L) :-
......@@ -123,6 +126,24 @@ indent(Stream, Level) :-
).
view_image(Filename) :-
get_image_viewer_driver(Driver),
Goal =.. [Driver, Filename],
Goal.
img_tag(Filename) :-
format('<img src="~a">\n', [Filename]).
get_image_viewer_driver(Driver) :-
nb_getval(image_viewer_driver, Driver).
set_image_viewer_driver(Driver) :-
nb_setval(image_viewer_driver, Driver).
user:message_hook(_Msg, warning, _Lines) :-
catch(
count(warnings, _),
......
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