knitr::opts_chunk$set(echo = TRUE, fig$path = "README_figs/README-")

Load packages

library(readxl)
library(tidyr)
library(dplyr)
library(ggplot2)
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("qPCR_data.xlsx", col_names = TRUE, sheet = 3, skip = 35)
head(qpcr)

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)

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

qpcr <- separate(qpcr, col = Sample, into = c("Sample", "Replicate"), sep = "_")
qpcr <- filter(qpcr, Sample != "Blanc")
head(qpcr)

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.

qpcr$CT <- as.numeric(qpcr$CT)
str(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("Rab35", "Rpl13a", "PSma3"), sample_col = "Sample", gene_col = "Gene")
head(qpcr)

Statistics

Perform statistical test between two groups and add information to qpcr data frame. We will do this with the ggpubr package.

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

Plot

ggplot(qpcr, aes(x = Sample, y = DCT, col = Sample)) +
  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

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 = "Sample", control = "WT")
head(ddct)

Plot

ggplot(ddct, aes(x = Sample, y = DDCTavg, fill = Sample)) +
  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"), "qpcr.xlsx")


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