Cellular assays using ‘bioassays’ package in R

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(bioassays)

Libraries

Following libraries will be useful. If the libraries 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

Introduction

In a cell culture lab various cellular assays are performed. The package "bioassays" will help 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 availble in the folder exdata (inst/exdata).

Example 1: Analysing result from a 96 well plate

Input data

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)

Read files

Files can be read using the codes below. Files need to be in .csv format. In this examples file names reflect the type of 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. These 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 1st 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 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)

Rearranging the data

96 well plates were used for the assay, so it is assumed that in data the rows being from A to G and columns 1 to 12 of a 96 well plate. data2plateformat function is used to label them correctly.

rawdata<-data2plateformat(rawdata,platetype = 96)
head(rawdata)

To convert data into a dataframe.

data2plateformat function uses the column name and row name of the above rawdata to format it as a data frame. So the data should be well formatted before using this function.

OD_df<- plate2df(rawdata)
head(OD_df)

For an overview of the plate

data<-matrix96(OD_df,"value",rm="TRUE")
heatplate(data,"Plate 1", size=5)

Filling metadata file using plate specific details

An example function is given below which will determine 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 fill metadata using plate_metadata function

metadata1<-plate_metadata(plate_details,metadata,mergeby="type")
head(metadata1)

For joining metadata and platelayout 'inner_join' function is 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 platename
head(data_DF)

Sorting blank wells and reducing blanks

Blank can be reduced using '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 platename

Plotting standard curve

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 linear fitting

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)

Summarise the data

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

Statistical test

For the t test (S1 as control)

pval<-pvalue(result, control="S1", sigval=0.05)
head(pval)

\newpage

Example 2: Analysing result from a 384 well plate.

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)

Input data.

Reading the spectrophotometer readings in 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 metadata

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)

Rearranging the data.

For appropriate naming of rows and column of rawdata2

rawdata2<-data2plateformat(rawdata2,platetype = 384)
head(rawdata2)

To convert data into a dataframe.

OD_df2 <- plate2df(rawdata2)
head(OD_df2)

For an overview of the plate.

For heat map

data2<-matrix96(OD_df2,"value",rm="TRUE")
heatplate(data2,"Plate 384", size=1.5)

For joining metadata2 and OD_df2.

data_DF2<- dplyr::inner_join(OD_df2,metadata2,by=c("row","col","position"))
head(data_DF2)

For categorical view of cells

data3<-matrix96(data_DF2,"cell",rm="TRUE")
heatplate(data3,"Plate 384", size=2)

For categorical view of compound

data4<-matrix96(data_DF2,"compound",rm="TRUE")
heatplate(data4,"Plate 384", size=2)

Sorting blank wells and reducing blanks.

The data contain separate blanks for drug1, drug2, drug3 and drug4 (blank1, blank2,blank3 and blank 4 respectively)

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)

To summarise the result from a plate.

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)

For summarising the result in the 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)

Statistical test.

For t-test

pvalue<-pvalue(result3,"C3",sigval=0.05)
pvalue


Try the bioassays package in your browser

Any scripts or data that you put into this service are public.

bioassays documentation built on Oct. 23, 2020, 6:48 p.m.