Needs to be updated!

Introduction

A work in progress. This is the alpha version of the package. It contains functions for reading, plotting, smoothing, differentiating, contrasting and extracting of feature points from individual wells in a mtp.

Future enhancements will include functions for differentiating and contrasting (subtracting) individual wells. In addition, functions for addding meta data such as experimental design and functions to plot and analyze them will also be added. Finally, it is my entention to include PCA and PLS and other routines enabling the entire analysis to be done in R.

Data from the package can be exported to csv files, that can be read and analyzed by e.g. simca.

This vignette aims to show a possible workflow using this package.

Libraries

Assuming you have installed R (3.2.1) and Rstudio (0.99.491+). Install and load into memory the following packages

library(tidyr) # data frame manipulation tools
library(dplyr) # data frame manipulation tools
library(purrr) # functional programming tools
library(ggplot2) # grammar of graphics plotting engine
library(knitr) # to create pretty tables
library(RAPr) # to manipulate RAP MTP data (in development) 

Getting Help

Getting help about the package and its functions type:

# Help about package
help(package = RAPr)

# Help about a particular function
?xls_read

Read Data

To read a single file type the line below and navigate to the folder containing the excel file.

xls_read()

Alternatively, run the following script to read all data in a folder (here the "RAPdata" folder in the working directory)

raw_data <- xls_folder_read("./myfolder")

This example does not work in this vignette, but the effect is similar to assigning the package data set to raw_data:

raw_data <- df_mtp

investigate the structure

# as a table
raw_data

# as list
glimpse(raw_data)

# mtp object as a table
raw_data$mtp[[1]]

Plot curves

Individual MTPs can be plotted:

plot_mtp(raw_data$mtp[[1]], title = "First MTP")

or all mtp curves can be plotted to a pdf file in the working directory:

dl <- raw_data$mtp
names(dl) <- with(raw_data, paste(file, sheet, Plate, sep="_"))

plot_to_pdf(dl, file_name = "raw_plots.pdf")

open the pdf curves to inspect the data

Smooth curves

The package uses LOcal regreESSion (LOESS) smoothing to smooth ou the noise.

To smooth all microtiter plates do the following:

smooth_data <- df_mtp
smooth_data$mtp <- smooth_mtp_list(smooth_data$mtp)

The smoothing functions have parameters that can be adjusted to suit your needs. See the help file.

Inspect smoothing

With the smoothed data, we can inspect the quality of the smoothing:

plot_mtp(smooth_data$mtp[[1]], y_name = "fit")
plot_mtp(smooth_data$mtp[[1]], y_name = "resid")
plot_mtp(smooth_data$mtp[[1]], x_name = "value", y_name = "resid")

To save all files as pdf do the following:

# first make a named list
dl <- smooth_data$mtp
names(dl) <- with(smooth_data, paste(file, sheet, Plate, sep = "_"))

# then plot
plot_to_pdf(dl, file_name = "smooth_plots.pdf", y_name = "fit")
plot_to_pdf(dl, file_name = "resid_plots.pdf", y_name = "resid")
plot_to_pdf(dl, file_name = "resid_plots2.pdf", x_name = "value", y_name = "resid")

Extract feature points

with the smooth data, we would like to extract feature points:

# calculate pH features: pH after 6 hours
pH_after_xhrs <- smooth_data %>%
  group_by(file, sheet, Plate) %>%
  do(mtp_pH_after_hours(.$mtp[[1]], x_out = c(6))) 

# look
pH_after_xhrs

#  calculate pH features: time to pH 5 and 6 (currently a little more elaborate)
time_to_pH <- smooth_data %>%
  group_by(file, sheet, Plate) %>%
  do(mtp_feature(.$mtp[[1]], x_out = c(5,6), x_name = "fit", y_name = "hours", feat_name = "t_pH"))

time_to_pH

# calculate the slopes
slopes <- smooth_data %>% 
  group_by(file, sheet, Plate) %>%
  do(mtp_slopes(.$mtp[[1]]))

slopes

Manipulate and export to csv

We can then reshape the data using the tidyr and dplyr packages and export to csv for further analysis in e.g. SIMCA

simca_01 <- pH_after_xhrs %>%
  spread(feature, value)

simca_02 <- time_to_pH %>%
  spread(feature, value)

simca <- left_join(simca_01, simca_02)

simca 

write.csv(simca, "simca.csv")

Adding additional information

The feature points can also be further analysed in R by e.g. adding information about the experimental setup on the MTP. Ideally, this could be supplied as a file, but in this example we will create the data ourselves.

In this particular experiment, "salt content" was varied with Ver. and "crystalban content" was varied with horizontal.

salt <- dplyr::data_frame(`Ver.` = as.factor(1:12),
                                salt = seq(0, 5.3, length.out = 12))

crystalban <- dplyr::data_frame(`Hor.` = as.factor(c("A", "B", "C", "D", "E", "F", "G", "H")),
                                crystalban = seq(0, 2, length.out = 8))

crystalban_salt <- dplyr::tbl_df(merge(crystalban, salt))

crystalban_salt

we also need to assign cultures and temperatures to the 10 MTP's tested

file = c("crystalban_salt_01.xls", "crystalban_salt_01.xls",
                  "crystalban_salt_02.xls", "crystalban_salt_02.xls",
                  "crystalban_salt_02.xls", "crystalban_salt_03_37.xls",
                  "crystalban_salt_03_37.xls", "crystalban_salt_03_37.xls",
                  "crystalban_salt_03_37.xls", "crystalban_salt_04_37.xls")

Plate <- as.character(c(1, 2, 1, 2, 3, 1, 2, 3, 4, 1))

culture <- rep(c("A3010", "A3020","A3030", "A3040", "A3050"),2)

temperature <- c(rep(30, 5), rep(37, 5))

experiment <- dplyr::data_frame(file,
                                Plate,
                                culture,
                                temperature)

experiment

We can now bind the experiment to the features:

setup <- pH_after_xhrs %>%
  left_join(crystalban_salt) %>%
  left_join(experiment) %>% 
  filter(feature == "hrs_fit6" )

setup

Analysis of experiment

if we plot a heat map as a function of culture and temperature, it appears that only the salt content is inhibitort, especially at 37C:

setup %>%
  ggplot(aes(x = salt, y = crystalban))+
  geom_raster(aes(fill = value))+
  facet_grid(temperature ~ culture)

we could also add a contour plot:

last_plot()+
  geom_contour(aes(z = value), colour = "white")

or a line plot

setup %>%
  ggplot(aes(x = salt, y = value))+
  geom_line(aes(colour = factor(round(crystalban,1))))+
  facet_grid(temperature ~ culture)+
  labs(colour = "crystalban %")
setup %>%
  ggplot(aes(x = crystalban, y = value))+
  geom_line(aes(colour = factor(round(salt,1))))+
  facet_grid(temperature ~ culture)+
  labs(colour = "salt %")

Or make a simple interaction model

model01 <- lm(value ~ 0 + culture+temperature*salt*crystalban + I(salt^2) + I(crystalban^2), data = setup)

summary(model01)

It appaers that salt:crystalban and temperature:salt:crystalban can be removed

model02 <- update(model01, . ~ . -salt:crystalban -temperature:salt:crystalban)
summary(model02)

it appears we can also remove the squared effect of crystalban

model03 <- update(model02, . ~ . -I(crystalban^2))
summary(model03)
anova(model01, model03)

lets look at the predictions:

setup$predictions <- predict(model03)

setup %>%
  ggplot(aes(x = salt, y = predictions))+
  geom_point(aes(y = value), size = 1)+
  geom_line(aes(colour = factor(round(crystalban,1))))+
  facet_grid(temperature ~ culture)+
  labs(colour = "crystalban %")

we see that there are some structural issues with this simple model but the conclusion appear sound: salt and crystal ban are inhibitory, especially at higher temperatures, salt more so than crystalban in the ranges tested



JannikVindeloev/RAPr documentation built on May 7, 2019, 10:21 a.m.