Commit cf1322a5 authored by Thierry Martinez's avatar Thierry Martinez
Browse files

SBML

parent 48f02cb8
......@@ -15,7 +15,7 @@ CFLAGS=$(addprefix -I, $(INCLUDEDIRS)) $(PLCFLAGS)
LDFLAGS=$(PLLDFLAGS) $(addprefix -L, $(dir $(wildcard $(PLBASE)/lib/*/)))
LDLIBS=$(PLLIB) `pkg-config --libs libgvc`
LDLIBS=$(PLLIB) `pkg-config --libs libgvc libsbml`
all: biocham biocham_debug test doc
......@@ -30,13 +30,18 @@ biocham_debug: platform/current swipl-biocham $(MODULES) $(TEST_MODULES) \
$(PWD)/swipl-biocham -o biocham_debug \
--goal=initialize -c $(MODULES) $(TEST_MODULES)
swipl-biocham: swipl-biocham.o modules/graphviz/graphviz_swiprolog.o
swipl-biocham: swipl-biocham.o \
modules/graphviz/graphviz_swiprolog.o \
modules/sbml/sbml_swiprolog.o
swipl-biocham.o: swipl-biocham.c
modules/graphviz/graphviz_swiprolog.o:
make -C modules/graphviz
modules/sbml/sbml_swiprolog.o:
make -C modules/sbml
platform/current:
- rm platform/current
ln -s `uname` platform/current
......@@ -54,6 +59,7 @@ biocham_tests: $(MODULES) $(TEST_MODULES) Makefile
clean:
- make -C modules/graphviz clean
- make -C modules/sbml clean
- rm platform/current
- rm biocham
- rm biocham_debug
......
#!/bin/bash
set -e
i=1
while true; do
filename=`printf BIOMD%.10d $i`
url="https://www.ebi.ac.uk/biomodels-main/download?mid=$filename"
if ! curl $url >$filename.xml; then
break
fi
((i++))
done
CC=swipl-ld
CFLAGS=`pkg-config --cflags libsbml`
LDLIBSx=`pkg-config --libs libsbml`
LDFLAGS=-shared
LDLIBS=`pkg-config --libs libsbml`
all: sbml2biocham
$(foreach var, PLSOEXT, \
$(eval \
$(shell \
swipl -dump-runtime-variables | \
grep ^$(var)= | \
sed -E 's/="/=/;s/";$$//')))
all: sbml_swiprolog test
.PHONY: clean test
clean:
rm -rf sbml2biocham sbml2biocham.o
- rm sbml_swiprolog
- rm sbml_swiprolog.o
sbml_swiprolog: sbml_swiprolog.o
swipl-ld -shared -o sbml_swiprolog sbml_swiprolog.o $(LDLIBS)
mv sbml_swiprolog.$(PLSOEXT) sbml_swiprolog
sbml_swiprolog.o: sbml_swiprolog.c
sbml2biocham: sbml2biocham.o
test:
swipl -g "\
call_cleanup((['sbml.plt'], run_tests, halt(0)), halt(1))\
"
:- module(
echo,
[
echo/1
]
).
:- use_module('../sbml').
echo(Filename) :-
readSBML(Filename, _SBML).
......@@ -18,11 +18,9 @@
speciesReference_getSpecies/2,
speciesReference_getStoichiometry/2,
modifierSpeciesReference_getSpecies/2,
modifierSpeciesReference_getStoichiometry/2,
species_getName/2,
species_getInitialAmount/2,
species_getInitialConcentration/2,
writeMathMLToString/2
species_getInitialConcentration/2
]
).
......
......@@ -13,11 +13,54 @@ PL_get_sbmlDocument(term_t document_term, SBMLDocument_t **document) {
return PL_get_pointer(document_term, (void **) document);
}
int
PL_get_model(term_t model_term, Model_t **model) {
return PL_get_pointer(model_term, (void **) model);
}
int
PL_get_listOf(term_t list_term, ListOf_t **list) {
return PL_get_pointer(list_term, (void **) list);
}
int
PL_get_reaction(term_t reaction_term, Reaction_t **reaction) {
return PL_get_pointer(reaction_term, (void **) reaction);
}
int
PL_get_kineticLaw(term_t kineticLaw_term, KineticLaw_t **kineticLaw) {
return PL_get_pointer(kineticLaw_term, (void **) kineticLaw);
}
int
PL_get_speciesReference(
term_t speciesReference_term, SpeciesReference_t **speciesReference
) {
return PL_get_pointer(speciesReference_term, (void **) speciesReference);
}
int
PL_get_modifierSpeciesReference(
term_t modifierSpeciesReference_term,
ModifierSpeciesReference_t **modifierSpeciesReference
) {
return PL_get_pointer(
modifierSpeciesReference_term,
(void **) modifierSpeciesReference
);
}
int
PL_get_species(term_t species_term, Species_t **species) {
return PL_get_pointer(species_term, (void **) species);
}
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);
SBMLDocument_free(document);
}
return result;
}
......@@ -28,8 +71,8 @@ pl_readSBML(term_t filename_term, term_t document_term) {
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;
PL_check(PL_unify_sbmlDocument_or_free(document_term, document));
PL_succeed;
}
static foreign_t
......@@ -40,7 +83,7 @@ pl_sbmlDocument_getNumErrors(term_t document_term, term_t numErrors_term) {
PL_check(PL_get_sbmlDocument(document_term, &document));
PL_check(numErrors = SBMLDocument_getNumErrors(document));
PL_check(PL_unify_integer(numErrors_term, numErrors));
PL_success;
PL_succeed;
}
static foreign_t
......@@ -49,8 +92,8 @@ pl_sbmlDocument_printErrors(term_t document_term, term_t output_term) {
char *filename;
PL_check(PL_get_sbmlDocument(document_term, &document));
// TODO: Handle custom stream
PL_check(SBMLDocument_printErrors(document, stderr));
PL_success;
SBMLDocument_printErrors(document, stderr);
PL_succeed;
}
static foreign_t
......@@ -60,7 +103,7 @@ pl_sbmlDocument_getModel(term_t document_term, term_t model_term) {
PL_check(PL_get_sbmlDocument(document_term, &document));
PL_check(model = SBMLDocument_getModel(document));
PL_check(PL_unify_pointer(model_term, model));
PL_success;
PL_succeed;
}
static foreign_t
......@@ -68,7 +111,7 @@ pl_sbmlDocument_free(term_t document_term) {
SBMLDocument_t *document;
PL_check(PL_get_sbmlDocument(document_term, &document));
SBMLDocument_free(document);
PL_success;
PL_succeed;
}
static foreign_t
......@@ -78,99 +121,166 @@ pl_model_getListOfReactions(term_t model_term, term_t listOfReactions_term) {
PL_check(PL_get_model(model_term, &model));
PL_check(listOfReactions = Model_getListOfReactions(model));
PL_check(PL_unify_pointer(listOfReactions_term, listOfReactions));
PL_success;
PL_succeed;
}
static foreign_t
pl_listOf_get(term_t listOf_term, term_t index_term, term_t base_term) {
ListOf_t *listOf;
unsigned int index;
pl_listOf_get(term_t list_term, term_t index_term, term_t base_term) {
ListOf_t *list;
int index;
SBase_t *base;
PL_check(PL_get_listOf(listOf_term, &listOf));
PL_check(PL_get_listOf(list_term, &list));
PL_check(PL_get_integer(index_term, &index));
PL_check(base = ListOf_get(listOf, index));
PL_check(base = ListOf_get(list, index));
PL_check(PL_unify_pointer(base_term, base));
PL_success;
PL_succeed;
}
static foreign_t
pl_listOf_size(term_t listOf_term, term_t size_term) {
ListOf_t *listOf;
pl_listOf_size(term_t list_term, term_t size_term) {
ListOf_t *list;
unsigned int size;
PL_check(PL_get_listOf(listOf_term, &listOf));
PL_check(size = ListOf_size(listOf));
PL_check(PL_get_listOf(list_term, &list));
PL_check(size = ListOf_size(list));
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;
PL_succeed;
}
static foreign_t
pl_reaction_getListOfModifiers(term_t) {
PL_success;
pl_reaction_getKineticLaw(term_t reaction_term, term_t kineticLaw_term) {
Reaction_t *reaction;
KineticLaw_t *kineticLaw;
PL_check(PL_get_reaction(reaction_term, &reaction));
PL_check(kineticLaw = Reaction_getKineticLaw(reaction));
PL_check(PL_unify_pointer(kineticLaw_term, kineticLaw));
PL_succeed;
}
static foreign_t
pl_reaction_getListOfProducts(term_t) {
PL_success;
pl_reaction_getListOfReactants(term_t reaction_term, term_t list_term) {
Reaction_t *reaction;
ListOf_t *list;
PL_check(PL_get_reaction(reaction_term, &reaction));
PL_check(list = Reaction_getListOfReactants(reaction));
PL_check(PL_unify_pointer(list_term, list));
PL_succeed;
}
static foreign_t
pl_reaction_isSetReversible(term_t) {
PL_success;
pl_reaction_getListOfModifiers(term_t reaction_term, term_t list_term) {
Reaction_t *reaction;
ListOf_t *list;
PL_check(PL_get_reaction(reaction_term, &reaction));
PL_check(list = Reaction_getListOfModifiers(reaction));
PL_check(PL_unify_pointer(list_term, list));
PL_succeed;
}
static foreign_t
pl_kineticsLaw_getMath(term_t) {
PL_success;
pl_reaction_getListOfProducts(term_t reaction_term, term_t list_term) {
Reaction_t *reaction;
ListOf_t *list;
PL_check(PL_get_reaction(reaction_term, &reaction));
PL_check(list = Reaction_getListOfProducts(reaction));
PL_check(PL_unify_pointer(list_term, list));
PL_succeed;
}
static foreign_t
pl_speciesReference_getSpecies(term_t) {
PL_success;
pl_reaction_isSetReversible(term_t reaction_term, term_t reversible_term) {
Reaction_t *reaction;
int reversible;
PL_check(PL_get_reaction(reaction_term, &reaction));
PL_check(reversible = Reaction_isSetReversible(reaction));
PL_check(PL_unify_bool(reversible_term, reversible));
PL_succeed;
}
static foreign_t
pl_speciesReference_getStoichiometry(term_t) {
PL_success;
pl_kineticsLaw_getMath(term_t kineticLaw_term, term_t astNode_term) {
KineticLaw_t *kineticLaw;
const ASTNode_t *astNode;
PL_check(PL_get_kineticLaw(kineticLaw_term, &kineticLaw));
PL_check(astNode = KineticLaw_getMath(kineticLaw));
PL_check(PL_unify_pointer(astNode_term, (void *) astNode));
PL_succeed;
}
static foreign_t
pl_modifierSpeciesReference_getSpecies(term_t) {
PL_success;
pl_speciesReference_getSpecies(
term_t speciesReference_term, term_t species_term
) {
SpeciesReference_t *speciesReference;
const char *species;
PL_check(PL_get_speciesReference(speciesReference_term, &speciesReference));
PL_check(species = SpeciesReference_getSpecies(speciesReference));
PL_check(PL_unify_atom_chars(species_term, species));
PL_succeed;
}
static foreign_t
pl_modifierSpeciesReference_getStoichiometry(term_t) {
PL_success;
pl_speciesReference_getStoichiometry(
term_t speciesReference_term, term_t stoichiometry_term
) {
SpeciesReference_t *speciesReference;
double stoichiometry;
PL_check(PL_get_speciesReference(speciesReference_term, &speciesReference));
PL_check(
stoichiometry = SpeciesReference_getStoichiometry(speciesReference)
);
PL_check(PL_unify_float(stoichiometry_term, stoichiometry));
PL_succeed;
}
static foreign_t
pl_species_getName(term_t) {
PL_success;
pl_modifierSpeciesReference_getSpecies(
term_t modifierSpeciesReference_term, term_t species_term
) {
ModifierSpeciesReference_t *modifierSpeciesReference;
const char *species;
PL_check(
PL_get_modifierSpeciesReference(
modifierSpeciesReference_term, &modifierSpeciesReference
)
);
PL_check(
species =
ModifierSpeciesReference_getSpecies(modifierSpeciesReference)
);
PL_check(PL_unify_atom_chars(species_term, species));
PL_succeed;
}
static foreign_t
pl_species_getInitialAmount(term_t) {
PL_success;
pl_species_getName(term_t species_term, term_t name_term) {
Species_t *species;
const char *name;
PL_check(PL_get_species(species_term, &species));
PL_check(name = Species_getName(species));
PL_check(PL_unify_atom_chars(name_term, name));
PL_succeed;
}
static foreign_t
pl_species_getInitialConcentration(term_t) {
PL_success;
pl_species_getInitialAmount(term_t species_term, term_t initialAmount_term) {
Species_t *species;
double initialAmount;
PL_check(PL_get_species(species_term, &species));
PL_check(initialAmount = Species_getInitialAmount(species));
PL_check(PL_unify_float(initialAmount_term, initialAmount));
PL_succeed;
}
static foreign_t
pl_writeMathMLToString(term_t) {
PL_success;
pl_species_getInitialConcentration(
term_t species_term, term_t initialConcentration_term
) {
Species_t *species;
double initialConcentration;
PL_check(PL_get_species(species_term, &species));
PL_check(initialConcentration = Species_getInitialConcentration(species));
PL_check(PL_unify_float(initialConcentration_term, initialConcentration));
PL_succeed;
}
......@@ -194,18 +304,14 @@ PL_extension sbml_predicates[] = {
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('open'), [Filename], [process(Pid)]),
process_wait(Pid, exit(0)).
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