knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(bioassays)
The following packages will be useful. If they are not installed, please install them using install.packages().
library(tcltk)# for selecting the folder for analysis library(dplyr) library(ggplot2)# for plotting graphs library(reshape2) library(nplr)# for the standard curve fitting
In a cell culture lab various cellular assays are performed. The package
"bioassays" helps to analyse the results of these experiments performed in
multiwell plates. The functions in this package can be used to summarise data
from any multiwell plate, and by incorporating them in a loop several plates can
be analyzed automatically. Two examples are shown in this article. All the csv
files used for the examples are available in the exdata
folder.
To set up a folder as working directory
path1<-tk_choose.dir(getwd(), "Choose the folder for Analysis") # A window will popup and ask you to select the folder containg the data setwd(path1)
Files can be read using the code example below. The files need to be in .csv format. In this example file names reflect the type of the assay used. For example "L_DIFF_P3_72HRS.csv" :L is assay code (Lactate assay), DIFF differentiation (type of cells used), p3: Plate 3 (each plate represent specific compounds tested), 72HRS 72hrs treatment with compound. This information will help to summarise the results.
filelist <-list("L_HEPG2_P3_72HRS.csv","L_HEPG2_P3_24HRS.csv") # list of files fno<-1 # file number (in fileslist) that is going to be analyzed result <- data.frame(stringsAsFactors= FALSE) ## An empty dataframe to dump result zzz <- data.frame(stringsAsFactors= FALSE) ## An empty dataframe to dump result
To read the first file
filename<-extract_filename(filelist[fno])[1] filename nickname<-extract_filename(filelist[fno], split="_",end=".csv",remove="",sep="")[2] nickname
rawdata<-read.csv(filename,stringsAsFactors = FALSE, strip.white = TRUE, na.strings = c("NA",""),header = TRUE,skip=1) head(rawdata)
data(rawdata96) rawdata<-rawdata96 head(rawdata)
Reading the metadata file
metadata<-read.csv("metafile.csv",stringsAsFactors = FALSE,strip.white = TRUE, na.strings = c("NA",""),header = TRUE) head(metadata)
data(metafile96) metadata<-metafile96 head(metadata)
96 well plates were used for the assay, so it is assumed that data is arrayed in
rows A to G and columns 1 to 12 of a 96 well plate. The data2plateformat
function is used to label them correctly.
rawdata<-data2plateformat(rawdata,platetype = 96) head(rawdata)
The data2plateformat
function uses the column and row names of the rawdata
object to coerce it into a data.frame.
OD_df<- plate2df(rawdata) head(OD_df)
data<-matrix96(OD_df,"value",rm="TRUE") heatplate(data,"Plate 1", size=5)
The example function given below determines the compound, concentration,type and dilution from the file name.
plate_info<-function(file,i){ file<-file[1] plate<- extract_filename(file,split = "_",end = ".csv", remove = " ", sep=" ")[5] if(plate == "P2"){ compound<-"CyclosporinA" # Concentration of cyclosporinA used for experiment concentration<-c(0,1,5,10,15,20,25,50) # Concentration of cyclosporinA used for experiment type<-c("S1","S2","S3","S4","S5","S6","S7","S8") # sample names of corresponding concentration dilution<-5 plate_meta<-list(compound=compound,concentration=round(concentration,2), type=type,dilution=dilution) } if(plate == "P3"){ compound<-"Taxol" concentration<-c(0,0.0125,.025,.05,0.1,1,5,10) type<-c("S1","S2","S3","S4","S5","S6","S7","S8") dilution<-5 plate_meta<-list(compound=compound,concentration=round(concentration,2), type=type, dilution=dilution) } if(plate =="p4"){ compound<-c("Cisplatin") concentration<-c(0,0.5,2,4,8,16,64,"") type<-c("S1","S2","S3","S4","S5","S6","S7","") dilution <- 5 plate_meta<-list(compound=compound,concentration=round(concentration,2), type=type,dilution=dilution) } return(plate_meta) } plate_details<-plate_info(filelist,1) plate_details
These 'plate details' can be used to add the metadata with the plate_metadata
function.
metadata1<-plate_metadata(plate_details,metadata,mergeby="type") head(metadata1)
For joining the metadata and platelayout dplyr's inner_join
function can be
used:
data_DF<- dplyr::inner_join(OD_df,metadata1,by=c("row","col","position")) assign(paste("data",sep="_",nickname),data_DF) # create a copy of data with plate name head(data_DF)
Blank values can be subtracted from the measurements with the reduceblank
function.
data_DF<-reduceblank(data_DF, x_vector =c("All"), blank_vector = c("Blank"), "value") head(data_DF) assign(paste("Blkmin",sep="_",nickname),data_DF) # create a copy of data with plate name
To filter standards
std<- dplyr::filter(data_DF, data_DF$id=="STD") std<- aggregate(std$blankminus ~ std$concentration, FUN = mean ) colnames (std) <-c("con", "OD") head(std)
Calculations for standard curve : nonparametric logistic regression curve
fit1<-nplr::nplr(std$con,std$OD,npars=3,useLog = FALSE) #npars = 3 for 3 parametric regression curve #for graph x1 <- nplr::getX(fit1); y1 <- nplr::getY(fit1) x2 <- nplr::getXcurve(fit1); y2 <- nplr::getYcurve(fit1) plot(x1, y1, pch=15, cex=1, col="red", xlab="Concentration", ylab="Mean OD", main=paste("Standard Curve: ", nickname), cex.main=1) lines(x2, y2, lwd=3, col="seagreen4")
To evaluate nonparametric logistic regression fitting
params<-nplr::getPar(fit1)$params nplr::getGoodness(fit1)
To estimate the values based on logistic regression fitting
estimated_nplr<-estimate(data_DF,colname="blankminus",fitformula=fit1,method="nplr") head(estimated_nplr)
Calculations for standard curve : linear regression curve
fit2<-stats::lm(formula = con ~ OD,data = std) ggplot2::ggplot(std, ggplot2::aes(x=OD,y=con))+ ggplot2::ggtitle(paste("Std Curve:", nickname))+ ggplot2::geom_point(color="red",size=2)+ ggplot2::geom_line(data = ggplot2::fortify(fit2),ggplot2::aes(x=OD,y=.fitted), colour="seagreen4",size=1)+ ggplot2::theme_bw()
To evaluate the fit of the linear model
conpred<-estimate(std,colname="OD",fitformula=fit2,method="linear") compare<-conpred[,c(1,3)] corAccuracy<-cor(compare)[1,2] corAccuracy ## Correlation accuracy of regression line summary(fit2)
To estimate the values based on linear curve
estimated_lr<-estimate(data_DF,colname="blankminus",fitformula=fit2, method="linear") head(estimated_lr)
For multiply estimated by dilution
estimated_lr$estimated2 <- estimated_lr$estimated * estimated_lr$dilution head(estimated_lr)
For summarising the "estimated_lr" based on "id" and "type".
result<-dfsummary(estimated_lr,"estimated2",c("id","type"), c("STD","Blank"),"plate1", rm="FALSE", param=c(strict="FALSE",cutoff=40,n=12)) result
For the t test (S1 as control)
pval<-pvalue(result, control="S1", sigval=0.05) head(pval)
\newpage
This example data contain result of dose response of few drugs (drug1, drug2, drug3, drug4) at three concentrations (C1,C2,C3) from two different cell lines (hepg2 and huh7)
Reading the spectrophotometer readings from a csv file
rawdata2<-read.csv("384.csv",stringsAsFactors = FALSE,strip.white = TRUE, na.strings = c("NA",""),header = TRUE,skip=1) dim(rawdata2) head(rawdata2)
data(rawdata384) rawdata2<-rawdata384 dim(rawdata2) head(rawdata2)
Reading the metadata file
metadata2<-read.csv("metafile_384_plate.csv",stringsAsFactors = FALSE, strip.white = TRUE, na.strings = c("NA",""), header = TRUE) head(metadata2)
data(metafile384) metadata2<-metafile384 head(metadata2)
Renaming rows and columns of the rawdata2
object
rawdata2<-data2plateformat(rawdata2,platetype = 384) head(rawdata2)
Converting the data into a data.frame.
OD_df2 <- plate2df(rawdata2) head(OD_df2)
Create a graphical overview of the plate.
data2<-matrix96(OD_df2,"value",rm="TRUE") heatplate(data2,"Plate 384", size=1.5)
Joining the metadata2
and OD_df2
objects
data_DF2<- dplyr::inner_join(OD_df2,metadata2,by=c("row","col","position")) head(data_DF2)
Display the cell categories:
data3<-matrix96(data_DF2,"cell",rm="TRUE") heatplate(data3,"Plate 384", size=2)
Discplay the compounds
data4<-matrix96(data_DF2,"compound",rm="TRUE") heatplate(data4,"Plate 384", size=2)
The data contain separate blanks wells for drug1, drug2, drug3 and drug4 (blank1, blank2,blank3 and blank 4 respectively) that can be used for background correction.
data_blk<-reduceblank(data_DF2, x_vector=c("drug1","drug2","drug3","drug4"), blank_vector = c("blank1","blank2","blank3","blank4"), "value") dim(data_blk)
head(data_blk)
For summarising the result in the order cell, compound,concentration,type and by omitting blanks.
result2<-dfsummary(data_blk,"blankminus", c("cell","compound","concentration","type"), c("blank1","blank2","blank3","blank4"), nickname="384well", rm="FALSE",param=c(strict="FALSE",cutoff=40,n=12)) head (result2) dim (result2)
The following example summarises the results in the following order: cell, compound and concentration, and by omitting blanks (all blanks are marked as "B" in concentration), drug 2 and huh7.
result3<-dfsummary(data_blk,"blankminus", c("cell","compound","concentration"), c("B","drug2","huh7"), nickname="", rm="FALSE",param=c(strict="FALSE",cutoff=40,n=12)) head (result3) dim (result3)
The following command will perform a t-test:
pvalue<-pvalue(result3,"C3",sigval=0.05) pvalue
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.