Skip to content

Commit

Permalink
Dedicated command-line compiler for Systems Biology
Browse files Browse the repository at this point in the history
  • Loading branch information
andreeabeica committed Mar 3, 2017
0 parents commit fa7b945
Show file tree
Hide file tree
Showing 52 changed files with 5,144 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
CMO=lexer.cmo parser.cmo main.cmo
GENERATED = lexer.ml parser.ml parser.mli
BIN=compilateur
FLAGS=str.cma

all:
ocamlbuild -libs str -use-menhir main.native
mv main.native ODEgen

.SUFFIXES: .mli .ml .cmi .cmo .mll .mly

.mli.cmi:
ocamlc $(FLAGS) -c $<

.ml.cmo:
ocamlc $(FLAGS) -c $<

.mll.ml:
ocamllex $<

.mly.ml:
menhir -v $<

.mly.mli:
ocamlyacc -v $<

clean:
rm -f *.cm[io] *.o *~ $(BIN) $(GENERATED)
rm -f parser.output parser.automaton parser.conflicts
rm -f .depend
rm -f ODEgen

.depend depend:$(GENERATED)
rm -f .depend
ocamldep *.ml *.mli > .depend
103 changes: 103 additions & 0 deletions Matlab_code/ODE.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
function dydt= ODE(t, y, parameters)
dmI = parameters(1);
Kq = parameters(2);
wt = parameters(3);
dA = parameters(4);
vm = parameters(5);
wm = parameters(6);
w0 = parameters(7);
nr = parameters(8);
s = parameters(9);
hA = parameters(10);
hI = parameters(11);
thetax = parameters(12);
wA = parameters(13);
kI = parameters(14);
nx = parameters(15);
wq = parameters(16);
kA = parameters(17);
we = parameters(18);
hq = parameters(19);
wr = parameters(20);
dm = parameters(21);
dI = parameters(22);
ns = parameters(23);
kb = parameters(24);
M = parameters(25);
Kt = parameters(26);
wI = parameters(27);
dmA = parameters(28);
thetar = parameters(29);
gammamax = parameters(30);
ku = parameters(31);
Kgamma = parameters(32);
Km = parameters(33);
vt = parameters(34);


si = y(1);
a = y(2);
mr = y(3);
mt = y(4);
mm = y(5);
mq = y(6);
mA = y(7);
mI = y(8);
r = y(9);
cr = y(10);
ct = y(11);
cm = y(12);
cq = y(13);
cA = y(14);
cI = y(15);
et = y(16);
em = y(17);
q = y(18);
A = y(19);
I = y(20);


Rt = cr+ct+cm+cq;
alpha = (A/kA)^hA;
beta = (I/kI)^hI;
gamma = gammamax*a/(Kgamma+a);
omegam = wm*a/(thetax+a);
omegaq = wq*a/(thetax+a)/(1+(q/Kq)^hq);
omegar = wr*a/(thetar+a);
omegat = we*a/(thetax+a);
vcat = em*vm*si/(Km+si);
vimp = et*vt*s/(Kt+s);
R = alpha/(1+alpha+beta+alpha*beta);
lam = gamma*Rt/M;
nuA = cA*gamma/nx;
nuI = cI*gamma/nx;
num = cm*gamma/nx;
nuq = cq*gamma/nx;
nur = cr*gamma/nr;
nut = ct*gamma/nx;
omegaA = wA*R*a/(thetax+a);
omegaI = wI*R*a/(thetax+a);


dydt(size(y,1),1)= 0;
dydt(1)= +vimp -vcat -lam*si ;
dydt(2)= + ns * vcat -nr * nur -nx * nut -nx * num -nx * nuq -nx * nuA -nx * nuI -lam*a ;
dydt(3)= +omegar -kb*r*mr +ku*cr +nur -dm*mr -lam*mr ;
dydt(4)= +omegat -kb*r*mt +ku*ct +nut -dm*mt -lam*mt ;
dydt(5)= +omegam -kb*r*mm +ku*cm +num -dm*mm -lam*mm ;
dydt(6)= +omegaq -kb*r*mq +ku*cq +nuq -dm*mq -lam*mq ;
dydt(7)= +w0 +omegaA -kb*r*mA +ku*cA +nuA -dmA*mA -lam*mA ;
dydt(8)= +w0 +omegaI -kb*r*mI +ku*cI +nuI -dmI*mI -lam*mI ;
dydt(9)= -kb*r*mr +ku*cr -kb*r*mt +ku*ct -kb*r*mm +ku*cm -kb*r*mq +ku*cq -kb*r*mA +ku*cA -kb*r*mI +ku*cI + 2. * nur +nut +num +nuq +nuA +nuI -lam*r ;
dydt(10)= +kb*r*mr -ku*cr -nur -lam*cr ;
dydt(11)= +kb*r*mt -ku*ct -nut -lam*ct ;
dydt(12)= +kb*r*mm -ku*cm -num -lam*cm ;
dydt(13)= +kb*r*mq -ku*cq -nuq -lam*cq ;
dydt(14)= +kb*r*mA -ku*cA -nuA -lam*cA ;
dydt(15)= +kb*r*mI -ku*cI -nuI -lam*cI ;
dydt(16)= +nut -lam*et ;
dydt(17)= +num -lam*em ;
dydt(18)= +nuq -lam*q ;
dydt(19)= +nuA -dA*A -lam*A ;
dydt(20)= +nuI -dI*I -lam*I ;
end
24 changes: 24 additions & 0 deletions Matlab_code/initial.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function init = initial ()
%define initial conditions
si = 0;
a = 10000.0;
mr = 0;
mt = 0;
mm = 0;
mq = 0;
mA = 0;
mI = 0;
r = 10.0;
cr = 0;
ct = 0;
cm = 0;
cq = 0;
cA = 0;
cI = 0;
et = 0;
em = 0;
q = 0;
A = 10.0;
I = 0;
init = [ si a mr mt mm mq mA mI r cr ct cm cq cA cI et em q A I ];
end
29 changes: 29 additions & 0 deletions Matlab_code/main.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
%parameters
params = parameters ();
%define initial conditions
init = initial ();
%call solver routine
t0 = 0;
tf = 1e5;
[t,y] = ode15s(@(t,y) ODE(t, y, parameters), [t0,tf], init);
%assign species names
si = y(:, 1);
a = y(:, 2);
mr = y(:, 3);
mt = y(:, 4);
mm = y(:, 5);
mq = y(:, 6);
mA = y(:, 7);
mI = y(:, 8);
r = y(:, 9);
cr = y(:, 10);
ct = y(:, 11);
cm = y(:, 12);
cq = y(:, 13);
cA = y(:, 14);
cI = y(:, 15);
et = y(:, 16);
em = y(:, 17);
q = y(:, 18);
A = y(:, 19);
I = y(:, 20);
38 changes: 38 additions & 0 deletions Matlab_code/parameters.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
function params = parameters ()
%define parameters
dmI = 0.12;
Kq = 152219;
wt = 4.14;
dA = 0.29;
vm = 5800;
wm = 4.14;
w0 = 0.01;
nr = 7459;
s = 1e4;
hA = 2;
hI = 4;
thetax = 4.38;
wA = 640;
kI = 160;
nx = 300;
wq = 948.93;
kA = 160;
we = 4.14;
hq = 4;
wr = 930;
dm = 0.1;
dI = 0.06;
ns = 0.5;
kb = 1;
M = 1e8;
Kt = 1000;
wI = 320;
dmA = 0.88;
thetar = 426.87;
gammamax = 1260;
ku = 1;
Kgamma = 7;
Km = 1000;
vt = 726;
params = [ dmI Kq wt dA vm wm w0 nr s hA hI thetax wA kI nx wq kA we hq wr dm dI ns kb M Kt wI dmA thetar gammamax ku Kgamma Km vt ];
end
1 change: 1 addition & 0 deletions ODEgen
47 changes: 47 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Generates Matlab ODE files, from a chemical-equation-style file.

USAGE WITH BINARIES:
Using the command line, place yourself inside the folder ODEgen; to generate the Matlab code, the command is: “_build/main.native file_name.txt”

e.g.: _build/main.native text/G.txt


USAGE:

"make clean" for cleanup

"make" to generate executable "ODEgen"

"./ODEgen filename.txt" to generate the code for the specified file; !FILE MUST HAVE EXTENSION .TXT

Matlab code generated in Matlab_code directory, executable in Matlab via the "main.m" file


FILE FORMAT:

The .txt file must contains three sections (in this order): EQN, PARAMS and INIT

EQN: contains declarations of the reactions, of one of the forms :


(coeff_1 "*" )? react_1 + (coeff_2 "*" )? react_2 +... -> (coeff_1 "*" )? prod_1 + (coeff_2 "*" )? prod_2 +... ; rate ("=" expression | value)?

(coeff_1 "*" )? react_1 + (coeff_2 "*" )? react_2 +... <-> (coeff_1 "*" )? prod_1 + (coeff_2 "*" )? prod_2 +... ; rate1 ("=" expression | value)?; rate2 ("=" expression | value)?


(coeff_1 "*" )? react_1 + (coeff_2 "*" )? react_2 +... => (coeff_1 "*" )? prod_1 + (coeff_2 "*" )? prod_2 +... ; rate ("=" expression | value)?

(coeff_1 "*" )? react_1 + (coeff_2 "*" )? react_2 +... <=> (coeff_1 "*" )? prod_1 + (coeff_2 "*" )? prod_2 +... ; rate1 ("=" expression | value)?; rate2 ("=" expression | value)?

Different types of arrows: "->" mass action, ireversible
"<->" mass action, reversible
"=>" rate law, the reaction velocity is specified by the user, ireversible
"<=>" rate law, the reaction velocity is specified by the user, reversible


PARAMS: contains parameter declarations of the form "param = value | expression"


INIT: contains initial conditions of the form "species = concentration"

See example files in the "test" folder.
26 changes: 26 additions & 0 deletions _build/_digests
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"Rule: ocaml dependencies ml (%=lexer )": "~g\226\141Fp\023\194\185>\224\181\245\244\176%"
"Rule: ocaml: menhir dependencies (%=parser )": "\001\158H\0294\173\242ubb\222\147\208K7\028"
"Resource: /Users/andreeabeica/Desktop/ODEgen/parser.mly": "\020\230\243\141\228|\236\018\242\152\018\161\158\142\255\002"
"Rule: ocaml: ml & cmi -> cmx & o (%=lexer )": "\190\151K\235)8\246\184V\141r/\233\156\146'"
"Rule: ocaml: ml & cmi -> cmx & o (%=parser )": "q\159\228\176 \227\\\224=\241\1297\188\251{>"
"Resource: /Users/andreeabeica/Desktop/ODEgen/main.ml": "\195\196\251\253\206\144Y\\\237\176[\247\167\232K\242"
"Resource: /home/andreea/Bureau/ODEgen/parser.mly": "\170\005\025~(^\182d\217\235\226\147\180>S>"
"Resource: /home/andreea/Bureau/ODEgen/lexer.mll": "\227\023\172\190\216g\199ZT\216\2327k\027K\r"
"Rule: ocamllex (%=lexer )": "|\209\151C\2214~\230\127\186\200L\169\202\b/"
"Rule: ocaml dependencies ml (%=parser )": "\178\154m fT]\199i\137\235r\166\255\210\002"
"Rule: ocaml: ml & cmi -> cmo (%=parser )": "C\175\2558\136\231\246\141`2a\219\178\029\220%"
"Resource: /home/andreea/Bureau/ODEgen/ast.mli": "k-\002\160+\149\012Q\174@%NT\006\231O"
"Rule: ocaml: ml -> cmo & cmi (%=lexer )": "^R\157x\016\165\130\218\166VD\158ZI\198\169"
"Rule: ocaml dependencies mli (%=ast )": "\001\1978\172\006\018Xn\b\194\158\214~\252Z\190"
"Resource: /Users/andreeabeica/Desktop/ODEgen/lexer.mll": "\227\023\172\190\216g\199ZT\216\2327k\027K\r"
"Rule: ocaml: ml & cmi -> cmx & o (%=main )": "U\180\141\189w})\213\228\164\221N\011\023\003\198"
"Rule: ocaml: cmo* -> byte (%=main )": "\152\186\184y*\142\133/\1782ax\012\189\012F"
"Rule: ocaml: ml -> cmo & cmi (%=main )": "\012Q\245\168\205\016|\247\162d\b\236fYyW"
"Rule: ocaml: mli -> cmi (%=ast )": "\142\235\172&\156A\232\147\153\029\179\127\181J\215]"
"Resource: /home/andreea/Bureau/ODEgen/main.ml": "_\195lwh_\028\254\203\207\234\229\159\027\215\163"
"Rule: ocaml dependencies mli (%=parser )": "\b\213\203\207\164N\146\156;\228\234\145\1585^\234"
"Rule: ocaml dependencies ml (%=main )": "\017\238\160\209I4a\1418\tD\017w:\181\137"
"Rule: ocaml: menhir (%=parser )": "\221$\r\204\176\206s\000!\180\172U\017/Z\017"
"Rule: ocaml: mli -> cmi (%=parser )": "LZ\247\133\007\1969\129T\r^\012\251\218\209\185"
"Resource: /Users/andreeabeica/Desktop/ODEgen/ast.mli": "k-\002\160+\149\012Q\174@%NT\006\231O"
"Rule: ocaml: cmx* & o* -> native (%=main )": "\135Yc\211\155\158\170\207 \212H\151*x\189\194"
40 changes: 40 additions & 0 deletions _build/_log
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
### Starting build.
# Target: main.ml.depends, tags: { extension:ml, file:main.ml, ocaml, ocamldep, quiet }
ocamldep.opt -modules main.ml > main.ml.depends
# Target: lexer.mll, tags: { extension:mll, file:lexer.mll, lexer, ocaml, ocamllex, quiet }
ocamllex.opt -q lexer.mll # cached
# Target: lexer.ml.depends, tags: { extension:ml, file:lexer.ml, ocaml, ocamldep, quiet }
ocamldep.opt -modules lexer.ml > lexer.ml.depends # cached
# Target: parser.mly.depends, tags: { extension:mly, file:parser.mly, infer, menhir_ocamldep, ocaml, ocamldep, quiet }
menhir --raw-depend --ocamldep 'ocamldep.opt -modules' parser.mly > parser.mly.depends # cached
# Target: ast.mli.depends, tags: { extension:mli, file:ast.mli, ocaml, ocamldep, quiet }
ocamldep.opt -modules ast.mli > ast.mli.depends # cached
# Target: ast.cmi, tags: { byte, compile, extension:mli, file:ast.mli, interf, ocaml, quiet }
ocamlc.opt -c -o ast.cmi ast.mli # cached
# Target: parser.mly, tags: { byte, compile, extension:ml, extension:mly, file:parser.ml, file:parser.mly, infer, menhir, ocaml, parser, quiet }
menhir --ocamlc ocamlc.opt --infer parser.mly # cached
# Target: parser.mli.depends, tags: { extension:mli, file:parser.mli, ocaml, ocamldep, quiet }
ocamldep.opt -modules parser.mli > parser.mli.depends # cached
# Target: parser.cmi, tags: { byte, compile, extension:mli, file:parser.mli, interf, ocaml, quiet }
ocamlc.opt -c -o parser.cmi parser.mli # cached
# Target: lexer.cmo, tags: { byte, compile, extension:cmo, extension:ml, file:lexer.cmo, file:lexer.ml, implem, ocaml, quiet }
ocamlc.opt -c -o lexer.cmo lexer.ml # cached
# Target: main.cmo, tags: { byte, compile, extension:cmo, extension:ml, file:main.cmo, file:main.ml, implem, ocaml, quiet }
ocamlc.opt -c -o main.cmo main.ml
+ ocamlc.opt -c -o main.cmo main.ml
File "main.ml", line 645, characters 6-603:
Warning 10: this expression should have type unit.
# Target: parser.ml.depends, tags: { extension:ml, file:parser.ml, ocaml, ocamldep, quiet }
ocamldep.opt -modules parser.ml > parser.ml.depends # cached
# Target: parser.cmx, tags: { compile, extension:cmx, extension:ml, file:parser.cmx, file:parser.ml, implem, native, ocaml, quiet }
ocamlopt.opt -c -o parser.cmx parser.ml # cached
# Target: lexer.cmx, tags: { compile, extension:cmx, extension:ml, file:lexer.cmx, file:lexer.ml, implem, native, ocaml, quiet }
ocamlopt.opt -c -o lexer.cmx lexer.ml # cached
# Target: main.cmx, tags: { compile, extension:cmx, extension:ml, file:main.cmx, file:main.ml, implem, native, ocaml, quiet }
ocamlopt.opt -c -o main.cmx main.ml
+ ocamlopt.opt -c -o main.cmx main.ml
File "main.ml", line 645, characters 6-603:
Warning 10: this expression should have type unit.
# Target: main.native, tags: { dont_link_with, extension:native, file:main.native, link, native, ocaml, program, quiet }
ocamlopt.opt str.cmxa parser.cmx lexer.cmx main.cmx -o main.native
# Compilation successful.
Binary file added _build/ast.cmi
Binary file not shown.
12 changes: 12 additions & 0 deletions _build/ast.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

type species = string * string ;;

type rates = species list;;

type reactants = species list;;

type products = species list ;;

type reaction = reactants * int * products * rates ;;

type file = reaction list;;
1 change: 1 addition & 0 deletions _build/ast.mli.depends
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ast.mli:
Binary file added _build/lexer.cmi
Binary file not shown.
Binary file added _build/lexer.cmo
Binary file not shown.
Binary file added _build/lexer.cmx
Binary file not shown.
Loading

0 comments on commit fa7b945

Please sign in to comment.