Introduction

renderAmpCurves and renderMeltCurves function represents amplification and melting data from real-time PCR experiments as curves based on plotly package. Main advantage of using this functions instead of regular plot renders is that it glued with RDML package. Minimal usage recures only GetFData(long.table = TRUE) function output. Also it has interactive feature - fast curves hiding without total plot redraw.

library(shinyMolBio)
library(tidyverse)
library(RDML)
library(chipPCR)
# load RDML file
rdml <- RDML$new(system.file("/extdata/stepone_std.rdml", package = "RDML"))
renderAmpCurves(inputId = "firstLook", # Shiny input ID
              label = "First Look", # optional plot label 
              ampCurves = rdml$GetFData(long.table = TRUE), # Amplification curves
              interactive = FALSE
)

Curves customization

Color

Curve color can be directly provided by adding column color to ampCurves table or by choosing column that defines color with colorBy param.

renderAmpCurves(inputId = "color1",
                "Color by Sample Name",
              ampCurves = rdml$GetFData(long.table = TRUE),
              colorBy = "sample", # sample name will define color
              interactive = FALSE
)
renderAmpCurves(inputId = "color2",
                "All 'red'",
              ampCurves = rdml$GetFData(long.table = TRUE) %>%
                mutate(color = "red"), # All curves will be red
              interactive = FALSE
)

Linetype

Curve linetype can be setted by choosing column that defines linetype with linetypeBy param.

renderAmpCurves(inputId = "linetype",
                "Different Linetypes",
              ampCurves = rdml$GetFData(long.table = TRUE),
              linetypeBy = "sample.type", # sample.type will define color
              interactive = FALSE
)

Show Markers

You can show Cq or Tm values on curves as markers setting showCq = TRUE or showTm = TRUE. Then input table have to contain cq or tm column.

renderAmpCurves(inputId = "cq",
                "Show Cq Values",
              ampCurves = rdml$GetFData(
                rdml$AsTable(cq = data$cq), # Get Cq values from file
                long.table = TRUE),
              showCq = TRUE, # Add Cq markers to curves
              colorBy = "sample",
              interactive = FALSE
)

Show Cq Threshold Line

Threshold lines can be shown by choosing column that splits different threshold values with thBy param. Then input table have to contain quantFluor column.

# Create function for curves preprocessing
dataType$set("public", "Process",
             function(thValue) {
               # Subtract background
               private$.adp$fpoints$fluor <-
                 CPP(self$adp$fpoints$cyc,
                     self$adp$fpoints$fluor,
                     bg.range = c(10,20))$y.norm
               # Calc Cq by threshold method
               self$cq <- th.cyc(self$adp$fpoints$cyc, self$adp$fpoints$fluor, r = thValue)[1, 1]
               # Write threshold value
               self$quantFluor <- thValue
             },
             overwrite = TRUE)

rdml <- RDML$new(system.file("/extdata/lc96_bACTXY.rdml", package = "RDML"))

Loading experiment: ca1eb225-ecea-4793-9804-87bfbb45f81d run: 65aeb1ec-b377-4ef6-b03f-92898d47488b

# Manual threshold values for different targets
thValues <- c("bACT" = 0.03, "X" = 0.05, "Y" = 0.04, "IPC" = 0.01)

# Preprocess every curve
for (react in rdml$experiment[[1]]$run[[1]]$react) {
  for (fdata in react$data) {
    fdata$Process(thValues[fdata$tar$id])
  }
}


tbl <- rdml$AsTable(quantFluor = data$quantFluor, # Add threshold values to table
                    cq = data$cq)
renderAmpCurves("th",
                "Show Thershold Lines",
                rdml$GetFData(tbl, long.table = TRUE),
                colorBy = "target",
                thBy = "target", # Add threshold lines (separated by targets)
                interactive = FALSE)

Custom Plotly Code

You can add custom qouted plotly code by plotlyCode parameter. Note that you have to add value p inside your quoted code to link it with render output.

markTbl <- tbl %>%
  filter(position %in% c("D03", "D07"),
         target == "bACT")

renderAmpCurves("th",
                "Show Thershold Lines",
                rdml$GetFData(tbl, long.table = TRUE),
                colorBy = "target",
                plotlyCode = quote(
                  # Add Cq values for tubes D03 and D07 for target bACT as blue points
                  add_markers(p,
                              data = markTbl,
                              name = ~sample,
                              x = ~cq,
                              y = ~quantFluor,
                              marker = list(color = "blue",
                                            size = 15)) %>%
                    # Set background color to light yellow
                    layout(paper_bgcolor = '#ffffe0',
                           plot_bgcolor = '#ffffe0')
                ),
                interactive = FALSE)

Melting curves

renderMeltCurves function provides all functionality described previosly in renderAmpCurves examples. Differences are showTm param instead of showCq and there is no thBy param.

# load RDML file
rdml <- RDML$new(system.file("/extdata/BioRad_qPCR_melt.rdml",
                             package = "RDML"))

Loading experiment: All Wells run: Amp Step 3_FAM

run: Amp Step 3_Cy5

Combining Bio-Rad runs

mdps <- rdml$GetFData(dp.type = "mdp", long.table = TRUE)
mdps[, diffFluor := c(0, diff(fluor)) * -1, by = fdata.name]

renderMeltCurves("melt",
                "Show melting curves",
                mdps,
                fluorColumn = "diffFluor",
                colorBy = "target",
                interactive = FALSE)

Hiding and highlighting curves

Individual curves can be hidden without plot redraw. Use updateCurves function with fdata.name as hideCurves param. Or highlighted with fdata.name as highlightCurves param. Run shinyMolBio::runExample("pcrPlateInput") to see this in action. Curves hiding occures after wells selection at PCR plate and higlighting after mouse hovering above PCR plate or details table.