User:James Chappell /R RK4 Modeling: Difference between revisions
mNo edit summary |
mNo edit summary |
||
Line 48: | Line 48: | ||
library(odesolve) | library(odesolve) | ||
'''<nowiki>#recalls the rk4 allgorithm - need to have install packages to be able to recall and use this function</nowiki>''' | <font color=#99CCFF>'''<nowiki>#recalls the rk4 allgorithm - need to have install packages to be able to recall and use this function</nowiki>'''</font> | ||
rm(list=objects()) | rm(list=objects()) | ||
'''<nowiki>#Function removes any previous objects from previous simulations using this or other functions, means always need to define any objects for each simulation</nowiki>''' | <font color=#99CCFF>'''<nowiki>#Function removes any previous objects from previous simulations using this or other functions, means always need to define any objects for each simulation</nowiki>'''</font> | ||
(constitutiveexpression <- function(t, x, parms) { | (constitutiveexpression <- function(t, x, parms) { | ||
'''<nowiki>#Define the name of the model, in this case "constitutiveexpression"</nowiki>''' | <font color=#99CCFF>'''<nowiki>#Define the name of the model, in this case "constitutiveexpression"</nowiki>'''</font> | ||
mRNA <- x[1] | mRNA <- x[1] | ||
Line 62: | Line 62: | ||
protein <- x[2] | protein <- x[2] | ||
'''<nowiki>#Name the response variables, which are the outputs of the model. So in this case the two outputs of this model are the mRNA and protein species, which will both be solved over time given the parameters defined below</nowiki>''' | <font color=#99CCFF>'''<nowiki>#Name the response variables, which are the outputs of the model. So in this case the two outputs of this model are the mRNA and protein species, which will both be solved over time given the parameters defined below</nowiki>'''</font> | ||
with(as.list(parms),{ | with(as.list(parms),{ | ||
Line 70: | Line 70: | ||
dprotein <- k2*mRNA - d2*protein | dprotein <- k2*mRNA - d2*protein | ||
'''<nowiki>#Define the differential equations in the format given above</nowiki> | <font color=#99CCFF>'''<nowiki>#Define the differential equations in the format given above</nowiki></font> | ||
res<-c(dmRNA, dprotein) | res<-c(dmRNA, dprotein) | ||
Line 78: | Line 78: | ||
})} | })} | ||
'''<nowiki>#Define the species which will be solved, these are the species which have been defined previous as x[1][2][...] and combines these vectors into a list called res</nowiki>'''</nowiki> | <font color=#99CCFF>'''<nowiki>#Define the species which will be solved, these are the species which have been defined previous as x[1][2][...] and combines these vectors into a list called res</nowiki>'''</nowiki></font> | ||
times <-seq(0, 1000, length=1001) | times <-seq(0, 1000, length=1001) | ||
Line 84: | Line 84: | ||
parms <-c(k1=0.69 , k2=f ,d1=0.23 ,d2=0.012) | parms <-c(k1=0.69 , k2=f ,d1=0.23 ,d2=0.012) | ||
'''<nowiki>#Generate a time series over which to solve the equations (1000 in steps of 1)</nowiki>''' | <font color=#99CCFF>'''<nowiki>#Generate a time series over which to solve the equations (1000 in steps of 1)</nowiki>'''</font> | ||
'''<nowiki>#Set the parameter values in parms</nowiki>''' | <font color=#99CCFF>'''<nowiki>#Set the parameter values in parms</nowiki>'''</font> | ||
y <- xstart <-c (mRNA=1, protein=1) | y <- xstart <-c (mRNA=1, protein=1) | ||
'''<nowiki>#Set the starting value for response variables</nowiki>''' | <font color=#99CCFF>'''<nowiki>#Set the starting value for response variables</nowiki>'''</font> | ||
output <- as.data.frame(rk4(xstart, times, constitutiveexpression, parms)) | output <- as.data.frame(rk4(xstart, times, constitutiveexpression, parms)) |
Revision as of 14:12, 13 July 2009
<html> <style type="text/css"> .firstHeading {display: none;} </style> </html>
James Chappell
Imperial College London Synthetic Biology Lab
Modelling With ODEs
RK4
WORK IN PROGRESS!!!!!
The RK4 tool is a tool that can be used to model ordinary differential equations (ODE). Like other ODE solvers you can output the results of a simulation into graph or tables.
Example 1 : Simple Constitutive Expression
Ordinary Differential Equations of constitutive gene expression
[math]\displaystyle{
\begin{alignat}{1}
\frac{d[mRNA]}{dt} & = k_{1} - d_{1}[mRNA] \\
\frac{d[Protein]}{dt} & = k_{2}[mRNA] - d_{2}[Protein] \\
\end{alignat}
}[/math]
- mRNA = mRNA species
- Protein = Protein species
- k1 = Rate of transcription
- k2 = Rate of translation
- d1 = Rate of mRNA degradation
- d2 = Rate of Protein degradation
(Images taken fromImperial College Synthetic Biology Course)
R CODE
library(odesolve)
#recalls the rk4 allgorithm - need to have install packages to be able to recall and use this function
rm(list=objects())
#Function removes any previous objects from previous simulations using this or other functions, means always need to define any objects for each simulation
(constitutiveexpression <- function(t, x, parms) {
#Define the name of the model, in this case "constitutiveexpression"
mRNA <- x[1]
protein <- x[2]
#Name the response variables, which are the outputs of the model. So in this case the two outputs of this model are the mRNA and protein species, which will both be solved over time given the parameters defined below
with(as.list(parms),{
dmRNA <- k1 - d1*mRNA
dprotein <- k2*mRNA - d2*protein
#Define the differential equations in the format given above
res<-c(dmRNA, dprotein)
list(res)
})}
#Define the species which will be solved, these are the species which have been defined previous as x[1][2][...] and combines these vectors into a list called res</nowiki>
times <-seq(0, 1000, length=1001)
parms <-c(k1=0.69 , k2=f ,d1=0.23 ,d2=0.012)
#Generate a time series over which to solve the equations (1000 in steps of 1)
#Set the parameter values in parms
y <- xstart <-c (mRNA=1, protein=1)
#Set the starting value for response variables
output <- as.data.frame(rk4(xstart, times, constitutiveexpression, parms))
plot(output$time, output$protein, ylim=c(0,2000), ylab="protein (molecules)",xlab="time (min)",type="n") }