Imperial College/Courses/Fall2009/Synthetic Biology (MRes class)/'R' Tutorial/Practical: Difference between revisions

From OpenWetWare
Jump to navigationJump to search
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.660, 2.114, 1.466, 0.866)
velocity <- c(3.636, 3.636, 3.236, 2.666, 2.114, 1.466, 0.866)
 


# create data frame by combining data
df <- data.frame(concentration, velocity)
df <- data.frame(concentration, velocity)
# print 'df'
df
# Correct one value from 'velocity'
velocity[4] <- 2.666
# Check that data frame 'df' has also been updated
df$velocity[4] # or df[4,2]
# Visualise data
plot(df$concentration, df$velocity)
plot(df$concentration, df$velocity)


# Linear regression
# create new variable to linearise plot
df$ytrans <- df$conc/df$vel
df$ytrans <- df$conc/df$vel


# plot new relationship
plot(df$conc, df$ytrans)
plot(df$conc, df$ytrans)


# compute linear regression
lmfit <- lm(ytrans~conc, data=df)
lmfit <- lm(ytrans~conc, data=df)
names(lmfit)


summary(lmfit)
summary(lmfit)


plot(lmfit)
plot(lmfit)
class(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

Fall 2009 - Synthetic Biology (MRes class)

Home        Lecture        'R' Tutorial        Resources        Literature

<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'>

  1. Random Walk 1D / 1 Trace
  1. number of steps

nbSteps <- 1000

  1. sampling and path construction
  1. First method: Looping
  1. draw from uniform distribtion between [0,1]

x <- runif(n = nbSteps)

  1. initialise path variable

xSteps <- rep(0, nbSteps) #as opposed to x1Steps <-0

  1. build independent steps series

for(i in 1:nbSteps){ if(x[i]>0.5){ xSteps[i] <- 1} else{ xSteps[i] <- -1 } }

  1. build path from independent steps

xPath <- cumsum(xSteps)

  1. Second method: vectorisation (faster)
  2. x <- runif(n = nbSteps)
  3. xSteps <- ifelse(x>0.5, 1, -1)
  4. xPath <- cumsum(xSteps)
  1. 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'>

  1. R Example, inspired by
  1. 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:
      • ...
  • Fitting (least square method)
    • Exercises:
      • ...
  • Plotting (scatter plots, histograms, time series)
    • Exercises:
      • ...
  • ODE simulations (based on basic gene expression models)
    • Exercises:
      • ...