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 )
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 )
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 )
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 cq <- th.cyc(self$adp$fpoints$cyc, self$adp$fpoints$fluor, r = thValue)[1, 1] self$cq <- if(!is.na(cq)) cq else NULL # Write threshold value self$quantFluor <- thValue }, overwrite = TRUE) rdml <- RDML$new(system.file("/extdata/lc96_bACTXY.rdml", package = "RDML")) # 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", showCq = TRUE, thBy = "target", # Add threshold lines (separated by targets) interactive = FALSE)
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, and quantFluor for y values.
renderAmpCurves(inputId = "cq", "Show Cq Values", ampCurves = rdml$GetFData(tbl, # Cq and quantFluor values are obtained # from file on previous step long.table = TRUE), showCq = TRUE, # Add Cq markers to curves colorBy = "sample", interactive = FALSE )
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)
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")) 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)
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.
Also curves can be hided or highlighted at the plot creation passing table with columns hideCurve and highlightCurve respectively.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.