knitr::opts_chunk$set(fig.path = "README_figs/README-")

Installation

Install following packages

if(!require(tidyverse)) install.packages("tidyverse")
if(!require(ggpubr)) install.packages("ggpubr") 
if(!require(lazyeval)) install.packages("lazyeval")
if(!require(WriteXLS)) install.packages("WriteXLS")
if(!require(devtools)) install.packages("devtools")
if(!require(qPCRanalysis)) devtools::install_github("SCIL-leuven/qPCRanalysis")

Load packages

library(tidyverse)
library(readxl)
library(qPCRanalysis)
library(ggpubr)
library(lazyeval)

Load data

We load the data with the read_excel() function of the readxl package. The data should consist of at least 4 columns:

qpcr <- read_excel("vignette/qPCR_data.xlsx", col_names = TRUE, sheet = 3, skip = 35)
head(qpcr)

Prepare data

Select columns

Now we need to clean the data frame. We will select only the columns that we need and change their names because R does not like spaces inside column names.

qpcr <- select(qpcr, c("Sample Name", "Target Name", "CT"))
colnames(qpcr) <- c("Sample", "Gene", "CT")
head(qpcr)

Switch CT column to numeric object

When we check the structure of the data frame we see that the CT column is not numeric, we will change this. In addition, all undetermined values are switched to NA. If desired, these values can be changed to 40.

#Change CT column to numeric values
qpcr$CT <- as.numeric(qpcr$CT)
#Change NA values in CT column to 40
qpcr[is.na(qpcr$CT), "CT"] <- 40
head(qpcr)

Create a grouping variable

In this example we want to see the difference between different genotypes. We will split the Sample Name column in two to create a sample column and a replicate column.

qpcr <- qpcr %>%
  #Copy Sample column
  mutate(temp = Sample) %>%
  #Split Sample column to create genotype column
  separate(col = temp, into = c("Genotype", "temp"), sep = "_") %>%
  #remove temp column
  select(-temp)
head(qpcr)

Calculate Delta CT

To calculate delta CT we use the calculate_DCT() function. This function requires four arguments:

It will pass a dataframe with three added columns:

qpcr <- calculate_DCT(df = qpcr, 
                      hkg = c("Rpl13a"), 
                      sample_col = "Sample", 
                      gene_col = "Gene")

Statistics

Perform statistical test between two groups and add information to qpcr data frame. We will do this with the ggpubr package. We want to perform a t-test between healthy and dystrophic samples. Therefore, we put DCT as our numeric variable and Genotype as our grouping variable. We Specify the method as t.test, specify that the data in unpaired and group by Gene.

stat <- compare_means(DCT ~ Genotype, qpcr, method = "t.test", paired = FALSE, group.by = "Gene")
head(stat)

Plot

ggplot(qpcr, aes(x = Genotype, y = DCT, col = Genotype)) +
  geom_boxplot() +
  facet_wrap(~Gene, scales = "free_y") +
  stat_compare_means(method = "t.test", label = "p.signif", label.x = 1.5)

Calculate Delta Delta CT

If you have unpaired data, the only way to calculate a delta delta CT or fold change is to take an average of your sample and compate the fold change to another group that you are referring to, plus also correctly propagate your error.

To calculate Delta Delta CT use the calculate_DDCT() function. This function can only be run after the calculate_DCT() function is used and requires five argeuments:

It will pass a dataframe with seven added columns

ddct <- calculate_DDCT(df = qpcr, 
                       gene_col = "Gene", 
                       sample_col = "Sample", 
                       var_col = "Genotype", 
                       control = "WT")
head(ddct)

Plot

ggplot(ddct, aes(x = Genotype, y = DDCTavg, fill = Genotype)) +
  geom_col() +
  geom_errorbar(aes(ymin = DDCTmin, ymax = DDCTmax), width = 0.1, data = ddct) +
  facet_wrap(~Gene, scales = "free_y")

Export

At any given point you can export the data frame to an excel file with this function. Here we will export the data in an excel with three sheets. The first sheet will contain your raw values and normalized delta CT values. The second sheet will contain your statistics. The third sheet will contain all the values normalized to your control group.

library(WriteXLS)
WriteXLS(c("qpcr", "stat", "ddct"), "vignette/qpcr.xlsx")


SCIL-leuven/qPCRanalysis documentation built on May 11, 2019, 3:03 p.m.