Imperial College/Courses/Fall2009/Synthetic Biology (MRes class)/'R' Tutorial/Practical: Difference between revisions
m (→Questions) |
|||
Line 86: | Line 86: | ||
==Part 2: Enzymatic reaction analysis== | ==Part 2: Enzymatic reaction analysis== | ||
In this section, we will be looking at enzymatic reaction data, using a Michaelis-Menten model. | |||
The purpose of the 'R' script is to automatise enzyme characterisation from experimental data. | |||
* Copy this script and run it. | |||
<syntax type='R'> | <syntax type='R'> | ||
Line 99: | Line 104: | ||
concentration <- c(0.3330, 0.1670, 0.0833, 0.0416, 0.0208, 0.0104, 0.0052) | concentration <- c(0.3330, 0.1670, 0.0833, 0.0416, 0.0208, 0.0104, 0.0052) | ||
velocity <- c(3.636, 3.636, 3.236, 2. | velocity <- c(3.636, 3.636, 3.236, 2.666, 2.114, 1.466, 0.866) | ||
df <- data.frame(concentration, velocity) | df <- data.frame(concentration, velocity) | ||
plot(df$concentration, df$velocity) | plot(df$concentration, df$velocity) | ||
df$ytrans <- df$conc/df$vel | df$ytrans <- df$conc/df$vel | ||
plot(df$conc, df$ytrans) | plot(df$conc, df$ytrans) | ||
lmfit <- lm(ytrans~conc, data=df) | lmfit <- lm(ytrans~conc, data=df) | ||
summary(lmfit) | summary(lmfit) | ||
plot(lmfit) | plot(lmfit) | ||
coef(lmfit) | coef(lmfit) | ||
Line 145: | Line 128: | ||
</syntax> | </syntax> | ||
===Questions=== | |||
* Using the help functions in 'R', add comment to the script to detail each command. | |||
* Modify the script so that experimental data can be read from a file, and analytical results can be exported into a file. | |||
* Basic intro to 'R' language | * Basic intro to 'R' language | ||
** types: vector, string, factor, data_frame | ** types: vector, string, factor, data_frame |
Revision as of 03:50, 9 October 2009
<html> <body> <!-- Start of StatCounter Code --> <script type="text/javascript"> var sc_project=3315864; var sc_invisible=0; var sc_partition=36; var sc_security="8bb2efcd"; </script>
<script type="text/javascript" src="http://www.statcounter.com/counter/counter_xhtml.js"></script><noscript><div class="statcounter"><a class="statcounter" href="http://www.statcounter.com/"><img class="statcounter" src="http://c37.statcounter.com/3315864/0/8bb2efcd/0/" alt="blog stats" /></a></div></noscript> <!-- End of StatCounter Code -->
</body> </html>
Introduction to 'R'
Part 1: Random Walks
Below is a basic 'R' script to simulate a random walk along the X axis. Random walks are important to model as they relate for example to the phenomenon of diffusion.
- Copy and save the script into a file.
- Run this script within 'R'
<syntax type='R'>
- Random Walk 1D / 1 Trace
-
- number of steps
nbSteps <- 1000
- sampling and path construction
- First method: Looping
- draw from uniform distribtion between [0,1]
x <- runif(n = nbSteps)
- initialise path variable
xSteps <- rep(0, nbSteps) #as opposed to x1Steps <-0
- build independent steps series
for(i in 1:nbSteps){ if(x[i]>0.5){ xSteps[i] <- 1} else{ xSteps[i] <- -1 } }
- build path from independent steps
xPath <- cumsum(xSteps)
- Second method: vectorisation (faster)
- x <- runif(n = nbSteps)
- xSteps <- ifelse(x>0.5, 1, -1)
- xPath <- cumsum(xSteps)
- plot path
plot(xPath, 1:nbSteps, type='l', col='red', lwd =2,
main = 'Random Walk 1D', xlab = "X coordinate", ylab = "Steps")
</syntax>
Questions
- Modify this script so that you can overlay as many independent paths as you want (Tip = use the function capability from 'R').
- Write a function to only return the last X coordinate after nbSteps.
- Use the previous function to build the distribution of X coordinates from 1000 independent simulations, after nbSteps.
- Extend the first script to be able to simulate 2D random walks.
Part 2: Enzymatic reaction analysis
In this section, we will be looking at enzymatic reaction data, using a Michaelis-Menten model. The purpose of the 'R' script is to automatise enzyme characterisation from experimental data.
- Copy this script and run it.
<syntax type='R'>
- R Example, inspired by
- Enzymatic analysis
concentration <- c(0.3330, 0.1670, 0.0833, 0.0416, 0.0208, 0.0104, 0.0052) velocity <- c(3.636, 3.636, 3.236, 2.666, 2.114, 1.466, 0.866)
df <- data.frame(concentration, velocity) plot(df$concentration, df$velocity)
df$ytrans <- df$conc/df$vel
plot(df$conc, df$ytrans)
lmfit <- lm(ytrans~conc, data=df)
summary(lmfit)
plot(lmfit)
coef(lmfit)
plot(df$conc, df$ytrans) abline(coef(lmfit))
Vm <- 1/coef(lmfit)[2] K <- Vm*coef(lmfit)[1]
</syntax>
Questions
- Using the help functions in 'R', add comment to the script to detail each command.
- Modify the script so that experimental data can be read from a file, and analytical results can be exported into a file.
- Basic intro to 'R' language
- types: vector, string, factor, data_frame
- functions for basic stats
- Exercises:
- ...
- Import / Export CSV files (other file formats ?)
- Exercises:
- ...
- Exercises:
- Fitting (least square method)
- Exercises:
- ...
- Exercises:
- Plotting (scatter plots, histograms, time series)
- Exercises:
- ...
- Exercises:
- ODE simulations (based on basic gene expression models)
- Exercises:
- ...
- Exercises: