Title: | Classify 2-d Droplet Digital PCR (ddPCR) data and quantify the number of starting molecules |
---|---|
Description: | The twoddpcr package takes Droplet Digital PCR (ddPCR) droplet amplitude data from Bio-Rad's QuantaSoft and can classify the droplets. A summary of the positive/negative droplet counts can be generated, which can then be used to estimate the number of molecules using the Poisson distribution. This is the first open source package that facilitates the automatic classification of general two channel ddPCR data. Previous work includes 'definetherain' (Jones et al., 2014) and 'ddpcRquant' (Trypsteen et al., 2015) which both handle one channel ddPCR experiments only. The 'ddpcr' package available on CRAN (Attali et al., 2016) supports automatic gating of a specific class of two channel ddPCR experiments only. |
Authors: | Anthony Chiu [aut, cre] |
Maintainer: | Anthony Chiu <[email protected]> |
License: | GPL-3 |
Version: | 1.31.0 |
Built: | 2024-12-19 04:24:35 UTC |
Source: | https://github.com/bioc/twoddpcr |
The twoddpcr
package takes droplet amplitude data from
Bio-Rad's QuantaSoft and can classify the droplets. A summary of the
positive/negative droplet counts can be generated, which can then be used to
estimate the number of molecules using the Poisson distribution.
Anthony Chiu, [email protected]
Useful links:
K-means classify a data frame where the droplets are negative in the same channels only.
.classifyDfOnChannel( df, channel, centres = NULL, minSeparation = 2000, fullTable = TRUE )
.classifyDfOnChannel( df, channel, centres = NULL, minSeparation = 2000, fullTable = TRUE )
df |
A data frame corresponding to a well with droplets corresponding only to "NN" and "NP" or "NN" and "PN". |
channel |
The channel on which to classify (1 or 2). |
centres |
A data frame of centres. The data frame should have columns
|
minSeparation |
The minimum distance required between two cluster centres in order for us to assume that k-means found two distinct clusters. Defaults to 2000. |
fullTable |
Whether to return a full table or just a vector. Defaults to 'TRUE' |
A classification for df
.
Anthony Chiu, [email protected]
K-means classify a list of data frames individually, where each data frame comprises droplets that are negative in the same channels only.
.classifyOnChannel( cl, channel, centres = NULL, minSeparation = 2000, fullTable = TRUE )
.classifyOnChannel( cl, channel, centres = NULL, minSeparation = 2000, fullTable = TRUE )
cl |
List of data frames, where each data frame corresponds to a well with droplets corresponding only to "NN" and "NP" or "NN" and "PN". |
channel |
The channel on which to classify (1 or 2). |
centres |
A data frame of centres. The data frame should have columns
|
minSeparation |
The minimum distance required between two cluster centres in order for us to assume that k-means found two distinct clusters. Defaults to 2000. |
fullTable |
Whether to return a full table or just a vector. Defaults to 'TRUE' |
A classification for cl
.
Anthony Chiu, [email protected]
Assume that the class cl
is bivariate normally distributed. This
method adds fuzziness to the class. Other classes are not changed.
.classwiseMahalanobisRain(droplets, cl, maxDistance = 30, classCol = "class")
.classwiseMahalanobisRain(droplets, cl, maxDistance = 30, classCol = "class")
droplets |
A data frame of droplets with |
cl |
The class to focus on. This should be either "NN", "NP", "PN" or "PP". |
maxDistance |
An integer corresponding to the maximum Mahalanobis distance for which we will consider points to be members of the class, i.e. this is the level outside of which we consider droplets to be too far from the cluster. |
classCol |
The column (name or number) from |
A factor corresponding to the class column with Rain
entries
added for the class cl
.
Anthony Chiu, [email protected]
Get the covariance of a single cluster.
.cov(cl, droplets, classCol)
.cov(cl, droplets, classCol)
cl |
The cluster of which to find the covariance. |
droplets |
A data frame of droplets with |
classCol |
The column (name or number) from |
The covariance matrix of the chosen cluster. If not defined, return
NULL
.
Anthony Chiu, [email protected]
Get a list of the columns in the ddPCR data that depend on the target (e.g. mutant or wild type). This includes columns that cannot be calculated from the very basic droplet counts.
.dependentCols(prefix = "")
.dependentCols(prefix = "")
prefix |
A string to prepend to each of the column names. Defaults to
|
A vector of column names with an optional prefix.
Anthony Chiu, [email protected]
Get a list of the essential columns in the ddPCR data that depend on the target (e.g. mutant or wild type).
.essentialDependentCols(prefix = "")
.essentialDependentCols(prefix = "")
prefix |
A string to prepend to each of the essential column names.
Defaults to |
A vector of essential column names with an optional prefix.
Anthony Chiu, [email protected]
We simply retrieve the names
from a given list, but also perform some
checks to make sure that the names are consistent with a given
ddpcrPlate
object.
.extractWellNames(theObject, aList)
.extractWellNames(theObject, aList)
theObject |
A |
aList |
A list from which we wish to extract well names. |
The names of aList
.
Anthony Chiu, [email protected]
Returns a data frame with a summary of the number of mutant and wild type copies per 20ul.
.getAllSummary(df)
.getAllSummary(df)
df |
A data frame generated by |
A data frame with mutant and wild type copies per 20ul, the total number of copies per 20ul, and a flag indicating if there are more than 2 mutant copies per 20ul.
Anthony Chiu, [email protected]
The plate should have been classified by k-means clustering.
.getChannelCentres(plate, cMethod, channel, minSeparation = 2000)
.getChannelCentres(plate, cMethod, channel, minSeparation = 2000)
plate |
A |
cMethod |
The classification method to use (in the form of a character string). |
channel |
An integer 1 or 2 corresponding to the channel of interest. |
minSeparation |
The minimum distance required between two cluster centres in order for us to assume that k-means found two distinct clusters. Defaults to 2000. |
A list of data frames, where each data frame has information about the centres in the channel of interest.
Anthony Chiu, [email protected]
Check that non-Ch*Amplitude columns are in a known classification format and coerce it to a factor.
.getClassificationData(colName, well)
.getClassificationData(colName, well)
colName |
The name of the column to focus on. |
well |
The data frame from which to extract the classifications. |
A factor with levels in ddpcr$classesRain
.
Anthony Chiu, [email protected]
Returns a data frame with the number of mutant copies per 20ul.
.getMutCopies(df)
.getMutCopies(df)
df |
A data frame generated by |
A data frame with the basic columns and mutant copies per 20ul.
Anthony Chiu, [email protected]
Get the well names from a data frame, checking if there is a Well
column or by using the row numbering.
.getWellNames(df)
.getWellNames(df)
df |
A data frame. |
A factor of row names.
Anthony Chiu, [email protected]
Returns a data frame with the number of wild type copies per 20ul.
.getWtCopies(df)
.getWtCopies(df)
df |
A data frame generated by |
A data frame with the basic columns and wild type copies per 20ul.
Anthony Chiu, [email protected]
Checks whether an object is a data frame with two leading double columns.
.isTwoDimDataFrame(df)
.isTwoDimDataFrame(df)
df |
A data frame. |
A logical value: whether the data frame meets the criteria.
Our preferred data frame format is to have things in a wide-form data frame, i.e. to have channel 1 and channel 2 data both in the same row.
.isWideForm(df, ch1Label = "Mt", ch2Label = "Wt")
.isWideForm(df, ch1Label = "Mt", ch2Label = "Wt")
df |
A data frame. |
ch1Label |
The prefix to use for the channel 1 target. Defaults to "Mt". |
ch2Label |
The prefix to use for the channel 2 target. Defaults to "Wt". |
TRUE
if df
is considered to be of the correct format
and FALSE
otherwise.
Anthony Chiu, [email protected]
Find the Mahalanobis distance of all droplets from a given distribution.
.mahDist(droplets, clusStats)
.mahDist(droplets, clusStats)
droplets |
A data frame of droplets with |
clusStats |
A list of statistics for a cluster generated by
|
A vector of numbers, where each one corresponds to the distance of that droplet from the given distribution.
Anthony Chiu, [email protected]
Get the inverse of a matrix
.matrixInverse(s)
.matrixInverse(s)
s |
A 2x2 matrix. |
The inverse of 's', or NULL if the matrix is singular
Given a matrix, compute the inverse or return NULL
if it is singular.
Auxiliary function to find the number of wells that appear in the data frame, each with the same frequency (almost certainly once or twice). If some wells appear more than others, the function stops because the data is in an unknown format.
.numberOfWells(df)
.numberOfWells(df)
df |
A data frame of droplet counts with a |
Bio-Rad's QuantaSoft produces data in long form tables, i.e. for each well there is a row for each target such as mutant and wild type. In this package, we prefer to work with wide form tables that combine the mutant and wild type parts.
An integer giving the number of wells.
Anthony Chiu, [email protected]
Normalise a well on one channel only and then transform it back to the original (combined) scale.
.renormaliseByChannel(wellDf, combinedCentres, wellCentres, channel)
.renormaliseByChannel(wellDf, combinedCentres, wellCentres, channel)
wellDf |
A data frame of the well's droplet amplitudes. |
combinedCentres |
A data frame of the combined (average) centres of the non-normalised wells. |
wellCentres |
A data frame of centres corresponding to the given
|
channel |
An integer 1 or 2 corresponding to the channel that we are interested in. |
A data frame with the rescaled amplitudes in the chosen channel.
Anthony Chiu, [email protected]
Normalise a well in both channels and then transform it back to the original (combined) scale.
.renormaliseWell(allDf, well, combinedCentres, indivCentres1, indivCentres2)
.renormaliseWell(allDf, well, combinedCentres, indivCentres1, indivCentres2)
allDf |
A list of data frames, where each one corresponds to a well's droplet amplitudes. |
well |
The name or number of the well to normalise. |
combinedCentres |
A data frame of the combined (average) centres of the non-normalised wells. |
indivCentres1 |
A data frame of centres corresponding to channel 1. |
indivCentres2 |
A data frame of centres corresponding to channel 2. |
A list of data frames with the rescaled amplitudes in both channels.
Anthony Chiu, [email protected]
For a data frame, if an extry is < 1, then round it to n significant figures. If it is >= 1, then round it to n decimal places.
.roundIt(df, n = 3)
.roundIt(df, n = 3)
df |
A data frame. |
n |
How many decimal places/significant figures to round to. |
The data frame x
with rounded entries.
Takes one long vector/factor and splits it into a list of vectors, where the lengths are given by a vector of sizes. This may be the same as another given list of vectors. Particularly useful if we want to combine a list of data, do some analysis on the combined data, then split the analysis.
.slice(vec, wellSizes, wellNames)
.slice(vec, wellSizes, wellNames)
vec |
The vector to split. |
wellSizes |
A numeric vector corresponding to sizes of the wells. |
wellNames |
A character vector corresponding to the names of the wells. |
A list of vectors split into the given lengths.
Anthony Chiu, [email protected]
Get the total number of copies of mutant and wild type molecules in a 20ul well.
.totalCopies(df)
.totalCopies(df)
df |
An input data frame with copies per 20ul figures. |
A vector listing the total numbers of copies per 20ul well.
Anthony Chiu, [email protected]
Retrieve the droplet amplitudes from an object.
amplitudes(theObject) ## S4 method for signature 'ddpcrWell' amplitudes(theObject) ## S4 method for signature 'ddpcrPlate' amplitudes(theObject)
amplitudes(theObject) ## S4 method for signature 'ddpcrWell' amplitudes(theObject) ## S4 method for signature 'ddpcrPlate' amplitudes(theObject)
theObject |
A |
If theObject
is a ddpcrWell
object, return
a data frame of droplet amplitudes with columns "Ch1.Amplitude" and
"Ch2.Amplitude". If theObject
is a ddpcrPlate
object,
return a list of data frames.
Anthony Chiu, [email protected]
wellClassification
for the classification of the
droplets.
## Set a ddpcrWell object with no data. aWell <- ddpcrWell(well=data.frame("Ch1.Amplitude"=double(), "Ch2.Amplitude"=double())) ## This can be checked to be empty. amplitudes(aWell) ## Alternatively, load some data. aWell <- ddpcrWell(well=KRASdata[["E03"]]) ## We check again and see that it has been populated. head(amplitudes(aWell)) # Get all of the KRASdata droplet amplitudes. krasPlate <- ddpcrPlate(wells=KRASdata) allDroplets <- amplitudes(krasPlate) str(allDroplets)
## Set a ddpcrWell object with no data. aWell <- ddpcrWell(well=data.frame("Ch1.Amplitude"=double(), "Ch2.Amplitude"=double())) ## This can be checked to be empty. amplitudes(aWell) ## Alternatively, load some data. aWell <- ddpcrWell(well=KRASdata[["E03"]]) ## We check again and see that it has been populated. head(amplitudes(aWell)) # Get all of the KRASdata droplet amplitudes. krasPlate <- ddpcrPlate(wells=KRASdata) allDroplets <- amplitudes(krasPlate) str(allDroplets)
It is useful to see the droplet counts for each class in addition to the overall droplet count at a glance.
basicsSummary(df)
basicsSummary(df)
df |
A data frame generated by |
A data frame with the PP
, PN
, NP
, NN
and
AcceptedDroplets
figures.
Anthony Chiu, [email protected]
df <- fullCountsSummary(KRAScountsQS) basicsSummary(df)
df <- fullCountsSummary(KRAScountsQS) basicsSummary(df)
Returns a data frame with the dependent columns prefixed with given labels (depending on the targets). All relevant columns are retained.
castSummary(df, ch1Label = "Mt", ch2Label = "Wt", rows = NULL)
castSummary(df, ch1Label = "Mt", ch2Label = "Wt", rows = NULL)
df |
A data frame created by calling |
ch1Label |
The prefix to use for the channel 1 target. Defaults to "Mt". |
ch2Label |
The prefix to use for the channel 2 target. Defaults to "Wt". |
rows |
The number of rows to retain from the original data frame. If
|
A data frame with the target rows merged.
Anthony Chiu, [email protected]
## Cast output from Bio-Rad's QuantaSoft into wide form. castSummary(KRAScountsQS) ## Only retain selected rows. castSummary(KRAScountsQS, rows=c(1,4:6))
## Cast output from Bio-Rad's QuantaSoft into wide form. castSummary(KRAScountsQS) ## Only retain selected rows. castSummary(KRAScountsQS, rows=c(1,4:6))
After classifying droplets, we can compute the covariance for each class.
classCov(droplets, classCol = "class")
classCov(droplets, classCol = "class")
droplets |
A data frame of droplets with |
classCol |
The column (name or number) from |
A list of covariance matrices of each cluster.
Anthony Chiu, [email protected]
## Get the covariance matrix of the clusters. aWell<- KRASdata[["E03"]] aWell$Cluster <- relabelClasses(aWell, classCol="Cluster") classCov(aWell, classCol="Cluster") ## We repeat the above but with a sample with no "PP" cluster. aWell <- KRASdata[["H04"]] aWell$Cluster <- relabelClasses(aWell, classCol="Cluster") classCov(aWell, classCol="Cluster")
## Get the covariance matrix of the clusters. aWell<- KRASdata[["E03"]] aWell$Cluster <- relabelClasses(aWell, classCol="Cluster") classCov(aWell, classCol="Cluster") ## We repeat the above but with a sample with no "PP" cluster. aWell <- KRASdata[["H04"]] aWell$Cluster <- relabelClasses(aWell, classCol="Cluster") classCov(aWell, classCol="Cluster")
After classifying droplets, we can compute the mean for each class.
classMeans(droplets, classCol = "class")
classMeans(droplets, classCol = "class")
droplets |
A data frame of droplets with |
classCol |
The column (name or number) from |
A list or data frame of means of each class.
Anthony Chiu, [email protected]
## Get the means of the clusters. aWell <- KRASdata[["E03"]] aWell$Cluster <- relabelClasses(aWell, classCol="Cluster") classMeans(aWell, classCol="Cluster") ## We repeat the above but with a sample with no "PP" cluster. aWell <- KRASdata[["H04"]] aWell$Cluster <- relabelClasses(aWell, classCol="Cluster") classMeans(aWell, classCol="Cluster")
## Get the means of the clusters. aWell <- KRASdata[["E03"]] aWell$Cluster <- relabelClasses(aWell, classCol="Cluster") classMeans(aWell, classCol="Cluster") ## We repeat the above but with a sample with no "PP" cluster. aWell <- KRASdata[["H04"]] aWell$Cluster <- relabelClasses(aWell, classCol="Cluster") classMeans(aWell, classCol="Cluster")
This function gives the mean, covariance and inverse of the covariance for each of the classes.
classStats(droplets, classCol = "class")
classStats(droplets, classCol = "class")
droplets |
A data frame of droplets with |
classCol |
The column (name or number) from |
A list (grouped by class name) of lists with keys mean
,
cov
and cov.inv
. If cov
is a singular matrix, then
cov.inv
will be NULL
.
Anthony Chiu, [email protected]
## Get some basic statistical properties of the clusters. aWell <- KRASdata[["E03"]] aWell$Cluster <- relabelClasses(aWell, classCol="Cluster") classStats(aWell, classCol="Cluster") ## We repeat the above but with a sample with no "PP" cluster. aWell <- KRASdata[["H04"]] aWell$Cluster <- relabelClasses(aWell, classCol="Cluster") classStats(aWell, classCol="Cluster")
## Get some basic statistical properties of the clusters. aWell <- KRASdata[["E03"]] aWell$Cluster <- relabelClasses(aWell, classCol="Cluster") classStats(aWell, classCol="Cluster") ## We repeat the above but with a sample with no "PP" cluster. aWell <- KRASdata[["H04"]] aWell$Cluster <- relabelClasses(aWell, classCol="Cluster") classStats(aWell, classCol="Cluster")
clusterCentres
retrieves the cluster centres for
a ddpcrWell
object or the centres for each well in
a ddpcrPlate
object.
combinedCentres
retrieves the cluster centres for all of
the wells together.
clusterCentres(theObject, cMethod) ## S4 method for signature 'ddpcrWell' clusterCentres(theObject, cMethod) ## S4 method for signature 'ddpcrPlate' clusterCentres(theObject, cMethod) combinedCentres(theObject, cMethod) ## S4 method for signature 'ddpcrPlate' combinedCentres(theObject, cMethod)
clusterCentres(theObject, cMethod) ## S4 method for signature 'ddpcrWell' clusterCentres(theObject, cMethod) ## S4 method for signature 'ddpcrPlate' clusterCentres(theObject, cMethod) combinedCentres(theObject, cMethod) ## S4 method for signature 'ddpcrPlate' combinedCentres(theObject, cMethod)
theObject |
A |
cMethod |
The classification method for which to obtain the centres. |
If a ddpcrWell
object is given, clusterCentres
returns
the cluster centres as a data frame.
If a ddpcrPlate
object is given, clusterCentres
return
a list of data frames, where each data frame corresponds to the cluster
centres of a well.
combinedCentres
returns a data frame of the centres of all of
the wells combined.
Anthony Chiu, [email protected]
## Get the centres of a sample with 4 clusters. aWell <- ddpcrWell(well=KRASdata[["E03"]]) clusterCentres(aWell, "Cluster") ## Get the centres of a sample with 3 clusters. aWell <- ddpcrWell(well=KRASdata[["H04"]]) clusterCentres(aWell, "Cluster") ## Retrieve the cluster centres of each of the wells in a \code{ddpcrPlate} ## object. krasPlate <- ddpcrPlate(wells=KRASdata) clusterCentres(krasPlate, cMethod="Cluster") ## Retrieve the cluster centres of all wells combined. combinedCentres(krasPlate, cMethod="Cluster")
## Get the centres of a sample with 4 clusters. aWell <- ddpcrWell(well=KRASdata[["E03"]]) clusterCentres(aWell, "Cluster") ## Get the centres of a sample with 3 clusters. aWell <- ddpcrWell(well=KRASdata[["H04"]]) clusterCentres(aWell, "Cluster") ## Retrieve the cluster centres of each of the wells in a \code{ddpcrPlate} ## object. krasPlate <- ddpcrPlate(wells=KRASdata) clusterCentres(krasPlate, cMethod="Cluster") ## Retrieve the cluster centres of all wells combined. combinedCentres(krasPlate, cMethod="Cluster")
Returns a data frame with the basic figures and a summary of the number of copies per 20ul.
copiesSummary(df)
copiesSummary(df)
df |
A data frame generated by |
A data frame with the basic data columns, mutant and wild type copies per 20ul, the total number of copies per 20ul, and a flag indicating if there are more than 2 mutant copies per 20ul.
Anthony Chiu, [email protected]
df <- fullCountsSummary(KRAScountsQS) copiesSummary(df)
df <- fullCountsSummary(KRAScountsQS) copiesSummary(df)
Stores default variables used in the package.
ddpcr
ddpcr
An object of class environment
of length 10.
An environment for storing package variables.
An S4 class for multiple wells in a ddPCR experiment.
The constructor for the ddpcrPlate
class.
ddpcrPlate(wells) ## S4 method for signature 'list' ddpcrPlate(wells) ## S4 method for signature 'ddpcrPlate' ddpcrPlate(wells) ## S4 method for signature 'character' ddpcrPlate(wells) ## S4 method for signature 'missing' ddpcrPlate(wells) ## S4 method for signature 'ddpcrPlate' show(object)
ddpcrPlate(wells) ## S4 method for signature 'list' ddpcrPlate(wells) ## S4 method for signature 'ddpcrPlate' ddpcrPlate(wells) ## S4 method for signature 'character' ddpcrPlate(wells) ## S4 method for signature 'missing' ddpcrPlate(wells) ## S4 method for signature 'ddpcrPlate' show(object)
wells |
Either:
|
object |
Any R object |
A ddpcrPlate
object with the given wells.
Anthony Chiu, [email protected]
Anthony Chiu, [email protected]
## A \code{ddpcrPlate} object can be created from data from a list of data ## frames. ddpcrPlate(KRASdata) ## A directory (or individual files) of droplet amplitude CSVs can also be ## loaded. moreAmpsDir <- system.file("extdata", "more-amplitudes", package="twoddpcr") ddpcrPlate(moreAmpsDir)
## A \code{ddpcrPlate} object can be created from data from a list of data ## frames. ddpcrPlate(KRASdata) ## A directory (or individual files) of droplet amplitude CSVs can also be ## loaded. moreAmpsDir <- system.file("extdata", "more-amplitudes", package="twoddpcr") ddpcrPlate(moreAmpsDir)
An S4 class for the classification of a single well in a ddPCR experiment.
The constructor for the ddpcrWell
class.
ddpcrWell(well) ## S4 method for signature 'data.frame' ddpcrWell(well) ## S4 method for signature 'character' ddpcrWell(well) ## S4 method for signature 'missing' ddpcrWell(well) ## S4 method for signature 'ddpcrWell' ddpcrWell(well) ## S4 method for signature 'ddpcrWell' show(object)
ddpcrWell(well) ## S4 method for signature 'data.frame' ddpcrWell(well) ## S4 method for signature 'character' ddpcrWell(well) ## S4 method for signature 'missing' ddpcrWell(well) ## S4 method for signature 'ddpcrWell' ddpcrWell(well) ## S4 method for signature 'ddpcrWell' show(object)
well |
A well with columns |
object |
Any R object |
A ddpcrWell
object with the given droplets in the well.
dropletAmplitudes
A data frame with columns Ch1.Amplitude
and Ch2.Amplitude
corresponding to all the droplets in the ddPCR
well.
classification
A vector of factors, where the levels are given by
ddpcr$classesRain
.
Anthony Chiu, [email protected]
Anthony Chiu, [email protected]
## A \code{ddpcrWell} object can be created from data from a list of data ## frames. ddpcrWell(KRASdata[[1]]) ## An CSV file of droplet amplitudes can also be loaded. ampFile <- system.file("extdata/amplitudes/sample_B03_Amplitude.csv", package="twoddpcr") ddpcrWell(ampFile)
## A \code{ddpcrWell} object can be created from data from a list of data ## frames. ddpcrWell(KRASdata[[1]]) ## An CSV file of droplet amplitudes can also be loaded. ampFile <- system.file("extdata/amplitudes/sample_B03_Amplitude.csv", package="twoddpcr") ddpcrWell(ampFile)
We may sometimes request that the dropletPlot
method takes an
empty data frame as its argument, e.g. an empty CSV file is loaded. This
normally presents an error, which is not the desired output. This function
plots nothing to show that there was no data to plot.
drawBlank()
drawBlank()
A blank ggplot
object.
ggplot.well
and
ggplot.plate
are wrappers for plotting
ddpcrWell
and ddpcrPlate
objects.
If there is at least one droplet, the dropletPlot
method plots droplet amplitude classifications.
Plot an object comprising droplet amplitudes and their classification. If specified, centres of clusters can be marked, e.g. k-means clustering can take a set of centres as the initial centres of the algorithm, and the algorithm also outputs the final cluster centres. Limits to the axes can also be set for ease of comparison and consistency.
If a ggplot
object is given as a parameter, this method will simply
plot it with the pretty colours, centres and restrictions on the axes.
If a data.frame
is given as a parameter, it should
correspond to droplets with their classification.
If a ddpcrWell
object is given as a parameter, plot the
droplets in the well with its classification.
If a ddpcrPlate
object is given as a parameter, plot the
droplets from all wells with their classifications.
dropletPlot( droplets, ch1Label = "Ch1 Amplitude", ch2Label = "Ch2 Amplitude", ... ) ## S4 method for signature 'data.frame' dropletPlot( droplets, ch1Label = "Ch1 Amplitude", ch2Label = "Ch2 Amplitude", cMethod = "None", mapping = aes_string(x = "Ch2.Amplitude", y = "Ch1.Amplitude", colour = cMethod), finalCentres = NULL, initialCentres = NULL, selectedCentre = NULL, pointSize = 1, plotLimits = list(x = c(1000, 9000), y = c(3000, 13500)), legendLabels = ddpcr$classesRain ) ## S4 method for signature 'ddpcrWell' dropletPlot( droplets, ch1Label = "Ch1 Amplitude", ch2Label = "Ch2 Amplitude", cMethod = "None", mapping = aes_string(x = "Ch2.Amplitude", y = "Ch1.Amplitude", colour = cMethod), finalCentres = NULL, initialCentres = NULL, selectedCentre = NULL, pointSize = 1, plotLimits = list(x = c(1000, 9000), y = c(3000, 13500)), legendLabels = ddpcr$classesRain ) ## S4 method for signature 'ddpcrPlate' dropletPlot( droplets, ch1Label = "Ch1 Amplitude", ch2Label = "Ch2 Amplitude", cMethod = "None", mapping = aes_string(x = "Ch2.Amplitude", y = "Ch1.Amplitude", colour = cMethod), finalCentres = NULL, initialCentres = NULL, selectedCentre = NULL, pointSize = 1, plotLimits = list(x = c(1000, 9000), y = c(3000, 13500)), legendLabels = ddpcr$classesRain )
dropletPlot( droplets, ch1Label = "Ch1 Amplitude", ch2Label = "Ch2 Amplitude", ... ) ## S4 method for signature 'data.frame' dropletPlot( droplets, ch1Label = "Ch1 Amplitude", ch2Label = "Ch2 Amplitude", cMethod = "None", mapping = aes_string(x = "Ch2.Amplitude", y = "Ch1.Amplitude", colour = cMethod), finalCentres = NULL, initialCentres = NULL, selectedCentre = NULL, pointSize = 1, plotLimits = list(x = c(1000, 9000), y = c(3000, 13500)), legendLabels = ddpcr$classesRain ) ## S4 method for signature 'ddpcrWell' dropletPlot( droplets, ch1Label = "Ch1 Amplitude", ch2Label = "Ch2 Amplitude", cMethod = "None", mapping = aes_string(x = "Ch2.Amplitude", y = "Ch1.Amplitude", colour = cMethod), finalCentres = NULL, initialCentres = NULL, selectedCentre = NULL, pointSize = 1, plotLimits = list(x = c(1000, 9000), y = c(3000, 13500)), legendLabels = ddpcr$classesRain ) ## S4 method for signature 'ddpcrPlate' dropletPlot( droplets, ch1Label = "Ch1 Amplitude", ch2Label = "Ch2 Amplitude", cMethod = "None", mapping = aes_string(x = "Ch2.Amplitude", y = "Ch1.Amplitude", colour = cMethod), finalCentres = NULL, initialCentres = NULL, selectedCentre = NULL, pointSize = 1, plotLimits = list(x = c(1000, 9000), y = c(3000, 13500)), legendLabels = ddpcr$classesRain )
droplets |
An object corresponding to droplet amplitudes and their classifications. This can be in the form of:
|
ch1Label |
The label for the channel 1 target. Defaults to "Ch1 Amplitude". |
ch2Label |
The label for the channel 2 target. Defaults to "Ch2 Amplitude". |
... |
Other plotting parameters that depend on the object type of
|
cMethod |
This should be the name or column number of |
mapping |
A list of aesthetic mappings to use for the plot. Defaults to
|
finalCentres |
A data frmae of final centres to plot (e.g. those
returned by the k-means or c-means algorithms). If |
initialCentres |
A data frame of initial centres to plot (e.g. initial
cluster centres used in the k-means). If |
selectedCentre |
An initial centre to highlight. This should be either
"NN", "NP", "PN" or "PP". If |
pointSize |
The size to draw each droplet. Defaults to 1. |
plotLimits |
A list of 2-element vectors with names |
legendLabels |
The character vector corresponding to the labels for the
legend. The elements of the vector should correspond to the NN, NP, PN, PP,
Rain and N/A classes, respectively. Defaults to |
A ggplot
object with all of the given information above.
Anthony Chiu, [email protected]
## Get a data frame and relabel the "Cluster" column to the right form. aWell <- KRASdata[["E03"]] aWell$Cluster <- relabelClasses(aWell, classCol="Cluster") ## Plot the data frame. dropletPlot(aWell, cMethod="Cluster") ## Plot a ddpcrWell object. aWell <- ddpcrWell(well=KRASdata[["E03"]]) dropletPlot(aWell, cMethod="Cluster") ## Plot a ddpcrPlate object. krasPlate <- ddpcrPlate(wells=KRASdata[c("E03", "H03", "C04", "F04")]) dropletPlot(krasPlate, cMethod="Cluster") ## Use K-means clustering to classify a single sample. Then plot the ## classification and final cluster centres. aWell <- kmeansClassify(aWell) centres <- clusterCentres(aWell, cMethod="kmeans") dropletPlot(aWell, cMethod="kmeans", finalCentres=centres)
## Get a data frame and relabel the "Cluster" column to the right form. aWell <- KRASdata[["E03"]] aWell$Cluster <- relabelClasses(aWell, classCol="Cluster") ## Plot the data frame. dropletPlot(aWell, cMethod="Cluster") ## Plot a ddpcrWell object. aWell <- ddpcrWell(well=KRASdata[["E03"]]) dropletPlot(aWell, cMethod="Cluster") ## Plot a ddpcrPlate object. krasPlate <- ddpcrPlate(wells=KRASdata[c("E03", "H03", "C04", "F04")]) dropletPlot(krasPlate, cMethod="Cluster") ## Use K-means clustering to classify a single sample. Then plot the ## classification and final cluster centres. aWell <- kmeansClassify(aWell) centres <- clusterCentres(aWell, cMethod="kmeans") dropletPlot(aWell, cMethod="kmeans", finalCentres=centres)
SimpleList
.Check the types of the elements in a SimpleList
.
## S4 method for signature 'SimpleList' elementType(x)
## S4 method for signature 'SimpleList' elementType(x)
x |
An object. |
The types of objects in the SimpleList
object.
If given a data frame, exportTable
exports the whole
data frame to file. This could be a data frame of any form. A few options
are available that can be used to determine the format of the file that is
exported, e.g. using a heading for the row names 'column', or omitting row
names altogether.
If a ddpcrWell
is given, exportTable
exports to
a single file with specified/all classification methods.
If a ddpcrPlate
is given, exportTable
exports to a directory in the given location
, where one file is
created for each of the wells. If it does not exist, the directory
location
will be created as long as all other parent directories
exist.
exportZip
takes a ddpcrPlate
object and
exports it as a zip file.
exportTable(theObject, location, delim = ",", ...) ## S4 method for signature 'data.frame' exportTable( theObject, location, delim = ",", leadingColName = NULL, row.names = TRUE ) ## S4 method for signature 'ddpcrWell' exportTable(theObject, location, delim = ",", cMethod = NULL) ## S4 method for signature 'ddpcrPlate' exportTable( theObject, location, delim = ",", cMethod = NULL, prefix = "", suffix = "_Amplitude.csv" ) exportZip( theObject, location, delim = ",", cMethod = NULL, prefix = "", suffix = "_Amplitude.csv" ) ## S4 method for signature 'ddpcrPlate' exportZip( theObject, location, delim = ",", cMethod = NULL, prefix = "", suffix = "_Amplitude.csv" )
exportTable(theObject, location, delim = ",", ...) ## S4 method for signature 'data.frame' exportTable( theObject, location, delim = ",", leadingColName = NULL, row.names = TRUE ) ## S4 method for signature 'ddpcrWell' exportTable(theObject, location, delim = ",", cMethod = NULL) ## S4 method for signature 'ddpcrPlate' exportTable( theObject, location, delim = ",", cMethod = NULL, prefix = "", suffix = "_Amplitude.csv" ) exportZip( theObject, location, delim = ",", cMethod = NULL, prefix = "", suffix = "_Amplitude.csv" ) ## S4 method for signature 'ddpcrPlate' exportZip( theObject, location, delim = ",", cMethod = NULL, prefix = "", suffix = "_Amplitude.csv" )
theObject |
The dataframe to export. |
location |
The location to export to. This should be a filename if we
are using |
delim |
The character to use as a field separator. Defaults to ",", i.e. export a CSV. |
... |
Other options depending on the type of |
leadingColName |
The name of the leading column, i.e. the 'row names'
of the dataframe. This could be a patient identifier or the well used in the
ddPCR experiment. If |
row.names |
If |
cMethod |
The name or column number of the classification methods in
a |
prefix |
For |
suffix |
For |
Note that filenames of the form Anything_A01_Amplitude.csv
can be read by readCSVDataFrame
so that the well name can be
extracted successfully (in this case A01
). Where it is used, see the
default value of the parameter suffix
.
Exports a file.
Anthony Chiu, [email protected]
## Output to a temporary directory. tmpOut <- file.path(normalizePath(tempdir())) ## Read some counts data and generate a summary data frame. df <- fullCountsSummary(KRAScountsQS) summaryDf <- fullCopiesSummary(df) ## Write the summary to a CSV file. exportTable(summaryDf, file.path(tmpOut, "summary-table.csv")) ## Write the summary to a tab-separated text file. exportTable(summaryDf, file.path(tmpOut, "summary-table.txt"), delim="\t") ## Write the summary to a CSV file with leading column labelled "Patient". exportTable(summaryDf, file.path(tmpOut, "summary-table.csv"), leadingColName="Patient") ## Read a droplet amplitude CSV file to a ddpcrWell object. ampFile <- system.file("extdata", "amplitudes", "sample_B03_Amplitude.csv", package="twoddpcr") aWell <- ddpcrWell(well=ampFile) ## Classify the droplets into 4 clusters. aWell <- kmeansClassify(aWell, centres=4) ## Write the amplitudes to a CSV file with the old and new classifications. exportTable(aWell, location=file.path(tmpOut, "With_Kmeans_B03_Amplitude.csv")) ## Write the amplitudes to a CSV file with the new classification only. exportTable(aWell, location=file.path(tmpOut, "With_Kmeans_B03_Amplitude.csv"), cMethod="kmeans") ## Read all amplitude files in a directory to a ddpcrPlate object. moreAmpsDir <- system.file("extdata", "more-amplitudes", package="twoddpcr") krasPlate <- ddpcrPlate(wells=moreAmpsDir) ## Classify the droplets into 4 clusters. krasPlate <- kmeansClassify(krasPlate, centres=4) ## Write the amplitudes to multiple files in a directory with the old and ## new classifications. exportTable(krasPlate, location=file.path(tmpOut, "amplitudes-classified")) ## Write the amplitudes to multiple files with the new classification only ## and a custom prefix for the filenames. exportTable(krasPlate, location=file.path(tmpOut, "amplitudes-classified"), cMethod="kmeans", prefix="Kmeans_Only_") ## Export to a zip file. exportZip(krasPlate, location=file.path(tmpOut, "amplitudes-classified/all.zip"), cMethod="kmeans", prefix="Kmeans_Only_")
## Output to a temporary directory. tmpOut <- file.path(normalizePath(tempdir())) ## Read some counts data and generate a summary data frame. df <- fullCountsSummary(KRAScountsQS) summaryDf <- fullCopiesSummary(df) ## Write the summary to a CSV file. exportTable(summaryDf, file.path(tmpOut, "summary-table.csv")) ## Write the summary to a tab-separated text file. exportTable(summaryDf, file.path(tmpOut, "summary-table.txt"), delim="\t") ## Write the summary to a CSV file with leading column labelled "Patient". exportTable(summaryDf, file.path(tmpOut, "summary-table.csv"), leadingColName="Patient") ## Read a droplet amplitude CSV file to a ddpcrWell object. ampFile <- system.file("extdata", "amplitudes", "sample_B03_Amplitude.csv", package="twoddpcr") aWell <- ddpcrWell(well=ampFile) ## Classify the droplets into 4 clusters. aWell <- kmeansClassify(aWell, centres=4) ## Write the amplitudes to a CSV file with the old and new classifications. exportTable(aWell, location=file.path(tmpOut, "With_Kmeans_B03_Amplitude.csv")) ## Write the amplitudes to a CSV file with the new classification only. exportTable(aWell, location=file.path(tmpOut, "With_Kmeans_B03_Amplitude.csv"), cMethod="kmeans") ## Read all amplitude files in a directory to a ddpcrPlate object. moreAmpsDir <- system.file("extdata", "more-amplitudes", package="twoddpcr") krasPlate <- ddpcrPlate(wells=moreAmpsDir) ## Classify the droplets into 4 clusters. krasPlate <- kmeansClassify(krasPlate, centres=4) ## Write the amplitudes to multiple files in a directory with the old and ## new classifications. exportTable(krasPlate, location=file.path(tmpOut, "amplitudes-classified")) ## Write the amplitudes to multiple files with the new classification only ## and a custom prefix for the filenames. exportTable(krasPlate, location=file.path(tmpOut, "amplitudes-classified"), cMethod="kmeans", prefix="Kmeans_Only_") ## Export to a zip file. exportZip(krasPlate, location=file.path(tmpOut, "amplitudes-classified/all.zip"), cMethod="kmeans", prefix="Kmeans_Only_")
If the given filename is of the form "<PlateName>_<WellName>_Amplitude.csv", where <WellName> is of the form A01, B01, etc., then this function can extract the <PlateName> component. Otherwise, an empty string is returned.
extractPlateName(filename)
extractPlateName(filename)
filename |
A character string corresponding to a filename with .csv extension. |
A character string corresponding to the plate name. This is "" if filename is not in a known format.
Anthony Chiu, [email protected]
## Get the plate name (recognised format). extractPlateName(c("Sample_Plate_Name_G02_Amplitude.csv")) ## Get the plate name (unrecognised format). extractPlateName(c("Sample_G02.csv"))
## Get the plate name (recognised format). extractPlateName(c("Sample_Plate_Name_G02_Amplitude.csv")) ## Get the plate name (unrecognised format). extractPlateName(c("Sample_G02.csv"))
If each of the given filenames are of the form "<PlateName>_<WellName>_Amplitude.csv", where <WellName> is of the form A01, B01, etc., then this function can extract the <WellName> component. Otherwise, the whole file name is assumed to be the well name.
extractWellNames(filenames)
extractWellNames(filenames)
filenames |
A character vector of filenames with .csv extension. |
A character vector of well names.
Anthony Chiu, [email protected]
## Get the well names (recognised format). extractWellNames(c("Sample_Plate_Name_G02_Amplitude.csv", "Sample_Plate_Name_H02_Amplitude.csv", "Sample_Plate_Name_A03_Amplitude.csv", "Sample_Plate_Name_B03_Amplitude.csv")) ## Get the well names (unrecognised format). extractWellNames(c("Sample_G02.csv", "Sample_H02.csv", "Sample_A03.csv", "Sample_B03.csv"))
## Get the well names (recognised format). extractWellNames(c("Sample_Plate_Name_G02_Amplitude.csv", "Sample_Plate_Name_H02_Amplitude.csv", "Sample_Plate_Name_A03_Amplitude.csv", "Sample_Plate_Name_B03_Amplitude.csv")) ## Get the well names (unrecognised format). extractWellNames(c("Sample_G02.csv", "Sample_H02.csv", "Sample_A03.csv", "Sample_B03.csv"))
Plot each of the wells in a ddpcrPlate
object or
a large data frame of droplets. By default, a density plot is returned for
speed purposes.
facetPlot( droplets, ch1Label = "Ch1 Amplitude", ch2Label = "Ch2 Amplitude", cMethod = NULL, binwidth = 100, pointSize = 0.1, plotLimits = list(x = c(1000, 9000), y = c(3000, 13500)), showEmptyWells = FALSE ) ## S4 method for signature 'data.frame' facetPlot( droplets, ch1Label = "Ch1 Amplitude", ch2Label = "Ch2 Amplitude", cMethod = NULL, binwidth = 100, pointSize = 0.1, plotLimits = list(x = c(1000, 9000), y = c(3000, 13500)), showEmptyWells = FALSE ) ## S4 method for signature 'ddpcrPlate' facetPlot( droplets, ch1Label = "Ch1 Amplitude", ch2Label = "Ch2 Amplitude", cMethod = NULL, binwidth = 100, pointSize = 0.1, plotLimits = list(x = c(1000, 9000), y = c(3000, 13500)), showEmptyWells = FALSE )
facetPlot( droplets, ch1Label = "Ch1 Amplitude", ch2Label = "Ch2 Amplitude", cMethod = NULL, binwidth = 100, pointSize = 0.1, plotLimits = list(x = c(1000, 9000), y = c(3000, 13500)), showEmptyWells = FALSE ) ## S4 method for signature 'data.frame' facetPlot( droplets, ch1Label = "Ch1 Amplitude", ch2Label = "Ch2 Amplitude", cMethod = NULL, binwidth = 100, pointSize = 0.1, plotLimits = list(x = c(1000, 9000), y = c(3000, 13500)), showEmptyWells = FALSE ) ## S4 method for signature 'ddpcrPlate' facetPlot( droplets, ch1Label = "Ch1 Amplitude", ch2Label = "Ch2 Amplitude", cMethod = NULL, binwidth = 100, pointSize = 0.1, plotLimits = list(x = c(1000, 9000), y = c(3000, 13500)), showEmptyWells = FALSE )
droplets |
A |
ch1Label |
The label for the channel 1 target. Defaults to "Ch1 Amplitude". |
ch2Label |
The label for the channel 2 target. Defaults to "Ch2 Amplitude". |
cMethod |
This should be the name or column number of |
binwidth |
The width of each hexagonal bin in the density plot. Ignored
if |
pointSize |
If |
plotLimits |
A list of 2-element vectors with names |
showEmptyWells |
If |
A collection of plots as a ggplot
object.
Anthony Chiu, [email protected]
The nice log-scaled palette was achieved using http://www.everydayanalytics.ca/2014/09/5-ways-to-do-2d-histograms-in-r.html
By default, each subplot uses the same plotting style as
heatPlot
.
## Plot a facet wrap of density plots of each well. krasPlate <- ddpcrPlate(wells=KRASdata) facetPlot(krasPlate)
## Plot a facet wrap of density plots of each well. krasPlate <- ddpcrPlate(wells=KRASdata) facetPlot(krasPlate)
There are occasions where classification algorithms fail for various reasons (such as poor choice/number of centres in k-means clustering). In these cases, it may be helpful to the user if an app draws a 'flat' plot with just one colour rather than nothing at all.
If a ddpcrWell
object is given as a parameter, plot the
droplets in the well and colour them according to a given class.
If a ddpcrPlate
object is given as a parameter,
plot the droplets in all wells and colour them according to a given class.
flatPlot( droplets, ch1Label = "Ch1 Amplitude", ch2Label = "Ch2 Amplitude", classString = ddpcr$na, initialCentres = NULL, selectedCentre = NULL, plotLimits = list(x = c(1000, 9000), y = c(3000, 13500)) ) ## S4 method for signature 'data.frame' flatPlot( droplets, ch1Label = "Ch1 Amplitude", ch2Label = "Ch2 Amplitude", classString = ddpcr$na, initialCentres = NULL, selectedCentre = NULL, plotLimits = list(x = c(1000, 9000), y = c(3000, 13500)) ) ## S4 method for signature 'ddpcrWell' flatPlot( droplets, ch1Label = "Ch1 Amplitude", ch2Label = "Ch2 Amplitude", classString = ddpcr$na, initialCentres = NULL, selectedCentre = NULL, plotLimits = list(x = c(1000, 9000), y = c(3000, 13500)) ) ## S4 method for signature 'ddpcrPlate' flatPlot( droplets, ch1Label = "Ch1 Amplitude", ch2Label = "Ch2 Amplitude", classString = ddpcr$na, initialCentres = NULL, selectedCentre = NULL, plotLimits = list(x = c(1000, 9000), y = c(3000, 13500)) )
flatPlot( droplets, ch1Label = "Ch1 Amplitude", ch2Label = "Ch2 Amplitude", classString = ddpcr$na, initialCentres = NULL, selectedCentre = NULL, plotLimits = list(x = c(1000, 9000), y = c(3000, 13500)) ) ## S4 method for signature 'data.frame' flatPlot( droplets, ch1Label = "Ch1 Amplitude", ch2Label = "Ch2 Amplitude", classString = ddpcr$na, initialCentres = NULL, selectedCentre = NULL, plotLimits = list(x = c(1000, 9000), y = c(3000, 13500)) ) ## S4 method for signature 'ddpcrWell' flatPlot( droplets, ch1Label = "Ch1 Amplitude", ch2Label = "Ch2 Amplitude", classString = ddpcr$na, initialCentres = NULL, selectedCentre = NULL, plotLimits = list(x = c(1000, 9000), y = c(3000, 13500)) ) ## S4 method for signature 'ddpcrPlate' flatPlot( droplets, ch1Label = "Ch1 Amplitude", ch2Label = "Ch2 Amplitude", classString = ddpcr$na, initialCentres = NULL, selectedCentre = NULL, plotLimits = list(x = c(1000, 9000), y = c(3000, 13500)) )
droplets |
A data frame of droplet amplitudes, or
a |
ch1Label |
The label for the channel 1 target. Defaults to "Ch1 Amplitude". |
ch2Label |
The label for the channel 2 target. Defaults to "Ch2 Amplitude". |
classString |
The class that all droplets should be classified as.
Defaults to the |
initialCentres |
A data frame of initial centres to plot (e.g. initial
cluster centres used in the k-means). This is _not_ restricted to the class
|
selectedCentre |
An initial centre to highlight. This should be either
"NN", "PN", "NP" or "PP", but is _not_ restricted to the class 'classString'
only. If |
plotLimits |
A list of 2-element vectors with names |
A ggplot object in just one colour corresponding to
classString
.
Anthony Chiu, [email protected]
## Plot the data frame with no classification. aWell <- KRASdata[["E03"]] flatPlot(aWell) ## Take a ddpcrWell object that is mostly classified as "NN" and colour it ## as such. aWell <- KRASdata[["H04"]] emptiedWell <- aWell[aWell$Cluster == 1, ] emptiedWell <- ddpcrWell(well=emptiedWell) flatPlot(emptiedWell, classString="NN") ## Plotting all of a ddpcrPlate object works the same way. krasPlate <- ddpcrPlate(wells=KRASdata) flatPlot(krasPlate)
## Plot the data frame with no classification. aWell <- KRASdata[["E03"]] flatPlot(aWell) ## Take a ddpcrWell object that is mostly classified as "NN" and colour it ## as such. aWell <- KRASdata[["H04"]] emptiedWell <- aWell[aWell$Cluster == 1, ] emptiedWell <- ddpcrWell(well=emptiedWell) flatPlot(emptiedWell, classString="NN") ## Plotting all of a ddpcrPlate object works the same way. krasPlate <- ddpcrPlate(wells=KRASdata) flatPlot(krasPlate)
Returns a data frame with all the copies information, plus any optional columns. This function is intended to be used as a final summary of the molecule counts.
fullCopiesSummary(df, extraCols = NULL)
fullCopiesSummary(df, extraCols = NULL)
df |
A data frame generated by |
extraCols |
A vector of column names from |
A data frame with the basic figures, the mutant counts, the wild type counts, the summarised counts, and extraCols if specified. Prints an additional column for notes, indicating whether this run failed or if there were fewer than 8000 accepted droplets.
Anthony Chiu, [email protected]
df <- fullCountsSummary(KRAScountsQS) fullCopiesSummary(df)
df <- fullCountsSummary(KRAScountsQS) fullCopiesSummary(df)
Returns a data frame with basic counts, the concentration of each kind of target molecule, the ratio ch1:ch2 molecules, and the fractional abundance of ch1 molecules in the overall count.
fullCountsSummary( df, ch1Label = "Mt", ch2Label = "Wt", rows = NULL, rowID = NULL, keepCols = NULL, keepColNames = NULL )
fullCountsSummary( df, ch1Label = "Mt", ch2Label = "Wt", rows = NULL, rowID = NULL, keepCols = NULL, keepColNames = NULL )
df |
A data frame with droplet count columns in one of the following formats:
|
ch1Label |
The prefix to use for the channel 1 target. Defaults to "Mt". |
ch2Label |
The prefix to use for the channel 2 target. Defaults to "Wt". |
rows |
A vector of rows (numbers or well names) to keep from the
original data frame. If set to |
rowID |
If set, this field is used as the row names. If |
keepCols |
A vector of columns to keep from |
keepColNames |
A vector of new column names for |
A data frame with
rowID
as the row names (if given);
the droplet counts per channel;
the number of ch1 and ch2 positive and negative readings;
the ch1 and ch2 concentration, copies per 20ul, and total copies per 20ul;
the ratio of ch1 to ch2 molecules; and
the fractional abundance of ch1 molecules in the overall molecule count (as a percentage).
Anthony Chiu, [email protected]
## Take a data frame with row names given by the well names. Get estimates ## for the numbers of molecules in each sample.. fullCountsSummary(KRAScounts) ## Keep only the row numbers 3, 6 and 9. fullCountsSummary(KRAScounts, rows=c(3, 6, 9)) ## Keep only the rows labelled "F03", "A04", "D04". fullCountsSummary(KRAScounts, rows=c("F03", "A04", "D04")) ## Take a data frame with a 'Well' column and do the same as above. fullCountsSummary(KRAScountsWellCol, rowID="Well") ## Keep the 'InputAmount' column. fullCountsSummary(KRAScounts, keepCols=c("InputAmount")) ## Keep the 'InputAmount' column and rename it. fullCountsSummary(KRAScounts, keepCols=c("InputAmount"), keepColNames=c("NanogramsIn"))
## Take a data frame with row names given by the well names. Get estimates ## for the numbers of molecules in each sample.. fullCountsSummary(KRAScounts) ## Keep only the row numbers 3, 6 and 9. fullCountsSummary(KRAScounts, rows=c(3, 6, 9)) ## Keep only the rows labelled "F03", "A04", "D04". fullCountsSummary(KRAScounts, rows=c("F03", "A04", "D04")) ## Take a data frame with a 'Well' column and do the same as above. fullCountsSummary(KRAScountsWellCol, rowID="Well") ## Keep the 'InputAmount' column. fullCountsSummary(KRAScounts, keepCols=c("InputAmount")) ## Keep the 'InputAmount' column and rename it. fullCountsSummary(KRAScounts, keepCols=c("InputAmount"), keepColNames=c("NanogramsIn"))
For a specified class, take a data frame of droplet amplitudes and compute the standard deviation multiplied by a level of accuracy.
getCutOff(droplets, cl, level = 3, classCol = "class")
getCutOff(droplets, cl, level = 3, classCol = "class")
droplets |
A data frame of droplets with "Ch1.Amplitude" and "Ch2.Amplitude" columns, as well as a class column (see classCol). |
cl |
The class to focus on. Typically one of "NN", "PN", "NP" and "PP". |
level |
A constant by which we will multiply the standard deviation. Defaults to 5. |
classCol |
The column (name or number) from 'droplets' representing the class. |
A list with named elements 'ch1' and 'ch2', each giving the error bound for the corresponding channel. If the number of droplets is either 0 or 1, return list(ch1=0, ch2=0) to avoid any errors. Otherwise, return level * (sd of the droplets in each channel).
Anthony Chiu, [email protected]
ddpcrWell
and
ddpcrPlate
classes.These functions work in the same way as the original
ggplot
method, but handles the coercion of the object
into a data frame.
ggplot.well
is a ggplot
method
for the ddpcrWell
class.
ggplot.multiwell
is a ggplot
method for the ddpcrPlate
class.
ggplot.well( data, mapping = aes_string(x = "Ch2.Amplitude", y = "Ch1.Amplitude", colour = cMethod), cMethod = NULL, ..., environment = parent.frame() ) ## S4 method for signature 'ddpcrWell' ggplot.well( data, mapping = aes_string(x = "Ch2.Amplitude", y = "Ch1.Amplitude", colour = cMethod), cMethod = "None", ..., environment = parent.frame() ) ggplot.plate( data, mapping = aes_string(x = "Ch2.Amplitude", y = "Ch1.Amplitude", colour = class), cMethod = "None", ..., environment = parent.frame() ) ## S4 method for signature 'ddpcrPlate' ggplot.plate( data, mapping = aes_string(x = "Ch2.Amplitude", y = "Ch1.Amplitude", colour = cMethod), cMethod = "None", ..., environment = parent.frame() )
ggplot.well( data, mapping = aes_string(x = "Ch2.Amplitude", y = "Ch1.Amplitude", colour = cMethod), cMethod = NULL, ..., environment = parent.frame() ) ## S4 method for signature 'ddpcrWell' ggplot.well( data, mapping = aes_string(x = "Ch2.Amplitude", y = "Ch1.Amplitude", colour = cMethod), cMethod = "None", ..., environment = parent.frame() ) ggplot.plate( data, mapping = aes_string(x = "Ch2.Amplitude", y = "Ch1.Amplitude", colour = class), cMethod = "None", ..., environment = parent.frame() ) ## S4 method for signature 'ddpcrPlate' ggplot.plate( data, mapping = aes_string(x = "Ch2.Amplitude", y = "Ch1.Amplitude", colour = cMethod), cMethod = "None", ..., environment = parent.frame() )
data |
A |
mapping |
A list of aesthetic mappings to use for the plot. Defaults to
|
cMethod |
The name or column number of the classification to use. This
is renamed internally to "class" for use with |
... |
Other arguments passed onto |
environment |
Where to look if a mapping variable is not defined.
Defaults to |
A ggplot
object using the slots in the given
object.
Anthony Chiu, [email protected]
dropletPlot
builds upon these ggplot
methods
to plot droplet amplitude plots with a colour-blind friendly palette.
The original ggplot
method in the
ggplot2
package is used internally.
## Plot the droplets in one well. library(ggplot2) aWell <- ddpcrWell(KRASdata[["E03"]]) ggplot.well(aWell, cMethod="Cluster") + geom_point() ## Plot the droplets in all of the wells in a single plot. krasPlate <- ddpcrPlate(KRASdata) ggplot.plate(krasPlate, cMethod="Cluster") + geom_point()
## Plot the droplets in one well. library(ggplot2) aWell <- ddpcrWell(KRASdata[["E03"]]) ggplot.well(aWell, cMethod="Cluster") + geom_point() ## Plot the droplets in all of the wells in a single plot. krasPlate <- ddpcrPlate(KRASdata) ggplot.plate(krasPlate, cMethod="Cluster") + geom_point()
Classify droplets as "NN", "NP", "PN" or "PP". The
classification is based on upper bounds for negative readings and lower
bounds for positive readings; see the details and parameters for more
detail. If required (see the trainingData
parameter), droplets that
are not classified will be given the label "N/A".
gridClassify( droplets, ch1NNThreshold = 6500, ch2NNThreshold = 1900, ch1NPThreshold = 6500, ch2NPThreshold = 5000, ch1PNThreshold = 10000, ch2PNThreshold = 2900, ch1PPThreshold = 7500, ch2PPThreshold = 5000, ... ) ## S4 method for signature 'data.frame' gridClassify( droplets, ch1NNThreshold = 6500, ch2NNThreshold = 1900, ch1NPThreshold = 6500, ch2NPThreshold = 5000, ch1PNThreshold = 10000, ch2PNThreshold = 2900, ch1PPThreshold = 7500, ch2PPThreshold = 5000, trainingData = TRUE, fullTable = TRUE, naLabel = ddpcr$rain ) ## S4 method for signature 'ddpcrWell' gridClassify( droplets, ch1NNThreshold = 6500, ch2NNThreshold = 1900, ch1NPThreshold = 6500, ch2NPThreshold = 5000, ch1PNThreshold = 10000, ch2PNThreshold = 2900, ch1PPThreshold = 7500, ch2PPThreshold = 5000, classMethodLabel = "grid", naLabel = ddpcr$rain ) ## S4 method for signature 'ddpcrPlate' gridClassify( droplets, ch1NNThreshold = 6500, ch2NNThreshold = 1900, ch1NPThreshold = 6500, ch2NPThreshold = 5000, ch1PNThreshold = 10000, ch2PNThreshold = 2900, ch1PPThreshold = 7500, ch2PPThreshold = 5000, classMethodLabel = "grid", naLabel = ddpcr$rain )
gridClassify( droplets, ch1NNThreshold = 6500, ch2NNThreshold = 1900, ch1NPThreshold = 6500, ch2NPThreshold = 5000, ch1PNThreshold = 10000, ch2PNThreshold = 2900, ch1PPThreshold = 7500, ch2PPThreshold = 5000, ... ) ## S4 method for signature 'data.frame' gridClassify( droplets, ch1NNThreshold = 6500, ch2NNThreshold = 1900, ch1NPThreshold = 6500, ch2NPThreshold = 5000, ch1PNThreshold = 10000, ch2PNThreshold = 2900, ch1PPThreshold = 7500, ch2PPThreshold = 5000, trainingData = TRUE, fullTable = TRUE, naLabel = ddpcr$rain ) ## S4 method for signature 'ddpcrWell' gridClassify( droplets, ch1NNThreshold = 6500, ch2NNThreshold = 1900, ch1NPThreshold = 6500, ch2NPThreshold = 5000, ch1PNThreshold = 10000, ch2PNThreshold = 2900, ch1PPThreshold = 7500, ch2PPThreshold = 5000, classMethodLabel = "grid", naLabel = ddpcr$rain ) ## S4 method for signature 'ddpcrPlate' gridClassify( droplets, ch1NNThreshold = 6500, ch2NNThreshold = 1900, ch1NPThreshold = 6500, ch2NPThreshold = 5000, ch1PNThreshold = 10000, ch2PNThreshold = 2900, ch1PPThreshold = 7500, ch2PPThreshold = 5000, classMethodLabel = "grid", naLabel = ddpcr$rain )
droplets |
A |
ch1NNThreshold |
The channel 1 upper bound for the NN class. Defaults to 6500. |
ch2NNThreshold |
The channel 2 upper bound for the NN class. Defaults to 1900. |
ch1NPThreshold |
The channel 1 upper bound for the NP class. Defaults to 6500. |
ch2NPThreshold |
The channel 2 lower bound for the NP class. Defaults to 5000. |
ch1PNThreshold |
The channel 1 lower bound for the PN class. Defaults to 10000. |
ch2PNThreshold |
The channel 2 upper bound for the PN class. Defaults to 2900. |
ch1PPThreshold |
The channel 1 lower bound for the PP class. Defaults to 7500. |
ch2PPThreshold |
The channel 2 lower bound for the PP class. Defaults to 5000. |
... |
Other options depending on the type of |
trainingData |
Whether to use the output as training data. If
|
fullTable |
Whether to return a data frame including amplitude
figures. If |
naLabel |
The label to use for unclassified droplets. Should be either ddpcr$na ("N/A") or ddpcr$rain ("Rain"). Defaults to ddpcr$rain. |
classMethodLabel |
A name (as a character string) of the classification method. Defaults to "grid". |
The threshold
parameters correspond to those in the
following diagram:
Ch1 ^ | | | | | | PN | | | | | PP e|________| | g|........:..|_________ | : : c|.............._______ a|______ : : | | | : : | NP | NN | : : | | | : : | ---------------------> b f h d Ch2
Specifically:
ch1NNThreshold
,
ch2NNThreshold
,
ch1PNThreshold
,
ch2PNThreshold
,
ch1NPThreshold
,
ch2NPThreshold
,
ch1PPThreshold
,
ch2PPThreshold
.
If droplets
is a data frame, return a data frame or factor
(depending on the trainingData
and fullTable
parameters) with
a classification for droplets in the chosen regions.
If droplets
is a ddpcrWell
object, return
a ddpcrWell
object with the appropriate classification.
If droplets
is a ddpcrPlate
object, return
a ddpcrPlate
object with the appropriate classification.
Anthony Chiu, [email protected]
thresholdClassify
is a special case of this
function.
removeDropletClasses
retrieves a data frame with the
"N/A" (and "Rain") droplets removed. This can used for transforming
a grid-like classification into usable training data.
## Use a grid to set training data for a data frame. sgCl <- gridClassify(KRASdata[["E03"]], ch1NNThreshold=5700, ch2NNThreshold=1700, ch1NPThreshold=5400, ch2NPThreshold=5700, ch1PNThreshold=9700, ch2PNThreshold=2050, ch1PPThreshold=7200, ch2PPThreshold=4800) str(sgCl) ## For data frame only, we can set the trainingData flag to FALSE so that ## the unclassified droplets are retained but labelled as "N/A" sgCl <- gridClassify(KRASdata[["E03"]], ch1NNThreshold=5700, ch2NNThreshold=1700, ch1NPThreshold=5400, ch2NPThreshold=5700, ch1PNThreshold=9700, ch2PNThreshold=2050, ch1PPThreshold=7200, ch2PPThreshold=4800, trainingData=FALSE) dropletPlot(sgCl, cMethod="class") ## The same works for ddpcrWell objects. aWell <- ddpcrWell(well=KRASdata[["E03"]]) aWell <- gridClassify(aWell, ch1NNThreshold=5700, ch2NNThreshold=1700, ch1NPThreshold=5400, ch2NPThreshold=5700, ch1PNThreshold=9700, ch2PNThreshold=2050, ch1PPThreshold=7200, ch2PPThreshold=4800) str(aWell) ## ddpcrPlate objects work in exactly the same way. krasPlate <- ddpcrPlate(wells=KRASdata) krasPlate <- gridClassify(krasPlate) lapply(plateClassification(krasPlate, withAmplitudes=TRUE), head, n=1) ## The default classification method (column name) is 'gridClassify', ## which may be a bit long. It can be changed. krasPlate <- gridClassify(krasPlate, classMethodLabel="training") lapply(plateClassification(krasPlate, withAmplitudes=TRUE), head, n=1)
## Use a grid to set training data for a data frame. sgCl <- gridClassify(KRASdata[["E03"]], ch1NNThreshold=5700, ch2NNThreshold=1700, ch1NPThreshold=5400, ch2NPThreshold=5700, ch1PNThreshold=9700, ch2PNThreshold=2050, ch1PPThreshold=7200, ch2PPThreshold=4800) str(sgCl) ## For data frame only, we can set the trainingData flag to FALSE so that ## the unclassified droplets are retained but labelled as "N/A" sgCl <- gridClassify(KRASdata[["E03"]], ch1NNThreshold=5700, ch2NNThreshold=1700, ch1NPThreshold=5400, ch2NPThreshold=5700, ch1PNThreshold=9700, ch2PNThreshold=2050, ch1PPThreshold=7200, ch2PPThreshold=4800, trainingData=FALSE) dropletPlot(sgCl, cMethod="class") ## The same works for ddpcrWell objects. aWell <- ddpcrWell(well=KRASdata[["E03"]]) aWell <- gridClassify(aWell, ch1NNThreshold=5700, ch2NNThreshold=1700, ch1NPThreshold=5400, ch2NPThreshold=5700, ch1PNThreshold=9700, ch2PNThreshold=2050, ch1PPThreshold=7200, ch2PPThreshold=4800) str(aWell) ## ddpcrPlate objects work in exactly the same way. krasPlate <- ddpcrPlate(wells=KRASdata) krasPlate <- gridClassify(krasPlate) lapply(plateClassification(krasPlate, withAmplitudes=TRUE), head, n=1) ## The default classification method (column name) is 'gridClassify', ## which may be a bit long. It can be changed. krasPlate <- gridClassify(krasPlate, classMethodLabel="training") lapply(plateClassification(krasPlate, withAmplitudes=TRUE), head, n=1)
Using alpha transparency only, it is generally difficult to see where droplets are truly distributed and concentrated. A heat (density) plot gives a better illustration of this.
heatPlot( droplets, ch1Label = "Ch1 Amplitude", ch2Label = "Ch2 Amplitude", binwidth = 100, plotLimits = list(x = c(1000, 9000), y = c(3000, 13500)) ) heatPlot( droplets, ch1Label = "Ch1 Amplitude", ch2Label = "Ch2 Amplitude", binwidth = 100, plotLimits = list(x = c(1000, 9000), y = c(3000, 13500)) ) ## S4 method for signature 'data.frame' heatPlot( droplets, ch1Label = "Ch1 Amplitude", ch2Label = "Ch2 Amplitude", binwidth = 100, plotLimits = list(x = c(1000, 9000), y = c(3000, 13500)) ) ## S4 method for signature 'ddpcrWell' heatPlot( droplets, ch1Label = "Ch1 Amplitude", ch2Label = "Ch2 Amplitude", binwidth = 100, plotLimits = list(x = c(1000, 9000), y = c(3000, 13500)) ) ## S4 method for signature 'ddpcrPlate' heatPlot( droplets, ch1Label = "Ch1 Amplitude", ch2Label = "Ch2 Amplitude", binwidth = 100, plotLimits = list(x = c(1000, 9000), y = c(3000, 13500)) )
heatPlot( droplets, ch1Label = "Ch1 Amplitude", ch2Label = "Ch2 Amplitude", binwidth = 100, plotLimits = list(x = c(1000, 9000), y = c(3000, 13500)) ) heatPlot( droplets, ch1Label = "Ch1 Amplitude", ch2Label = "Ch2 Amplitude", binwidth = 100, plotLimits = list(x = c(1000, 9000), y = c(3000, 13500)) ) ## S4 method for signature 'data.frame' heatPlot( droplets, ch1Label = "Ch1 Amplitude", ch2Label = "Ch2 Amplitude", binwidth = 100, plotLimits = list(x = c(1000, 9000), y = c(3000, 13500)) ) ## S4 method for signature 'ddpcrWell' heatPlot( droplets, ch1Label = "Ch1 Amplitude", ch2Label = "Ch2 Amplitude", binwidth = 100, plotLimits = list(x = c(1000, 9000), y = c(3000, 13500)) ) ## S4 method for signature 'ddpcrPlate' heatPlot( droplets, ch1Label = "Ch1 Amplitude", ch2Label = "Ch2 Amplitude", binwidth = 100, plotLimits = list(x = c(1000, 9000), y = c(3000, 13500)) )
droplets |
A data frame of droplet amplitudes, a |
ch1Label |
The label for the channel 1 target. Defaults to "Ch1 Amplitude". |
ch2Label |
The label for the channel 2 target. Defaults to "Ch2 Amplitude". |
binwidth |
The width of each hexagonal bin in the 2d heat (density) plot. Defaults to 100. |
plotLimits |
A list of 2-element vectors with names |
A heat plot as a ggplot
object.
Anthony Chiu, [email protected]
The nice log-scaled palette was achieved using http://www.everydayanalytics.ca/2014/09/5-ways-to-do-2d-histograms-in-r.html
## Density plot of a data frame. heatPlot(KRASdata[["E03"]]) ## Density plot of a ddpcrWell object. aWell <- ddpcrWell(well=KRASdata[["E03"]]) heatPlot(aWell) ## Density plot of a ddpcrPlate object with an adjusted bin size. krasPlate <- ddpcrPlate(wells=KRASdata) heatPlot(krasPlate, binwidth=50)
## Density plot of a data frame. heatPlot(KRASdata[["E03"]]) ## Density plot of a ddpcrWell object. aWell <- ddpcrWell(well=KRASdata[["E03"]]) heatPlot(aWell) ## Density plot of a ddpcrPlate object with an adjusted bin size. krasPlate <- ddpcrPlate(wells=KRASdata) heatPlot(krasPlate, binwidth=50)
ddpcrWell
object empty?Returns a logical value as to whether the given object has no droplets/wells.
## S4 method for signature 'ddpcrWell' isEmpty(x) ## S4 method for signature 'ddpcrPlate' isEmpty(x)
## S4 method for signature 'ddpcrWell' isEmpty(x) ## S4 method for signature 'ddpcrPlate' isEmpty(x)
x |
An object to test for emptiness. |
A logical value.
Anthony Chiu, [email protected]
## Check that an empty ddpcrPlate object is in fact empty. krasPlate <- ddpcrPlate(wells=list()) isEmpty(krasPlate) ## Now add some amplitude data and check that is not empty. krasPlate <- ddpcrPlate(wells=KRASdata) isEmpty(krasPlate)
## Check that an empty ddpcrPlate object is in fact empty. krasPlate <- ddpcrPlate(wells=list()) isEmpty(krasPlate) ## Now add some amplitude data and check that is not empty. krasPlate <- ddpcrPlate(wells=KRASdata) isEmpty(krasPlate)
ddpcrWell
or
ddpcrPlate
object, or in a data frame.If droplets
is a data frame, the droplets are classified
using the k-means clustering algorithm.
For ddpcrWell
, the droplets are classified by using the
k-means clustering algorithm.
For ddpcrPlate
, all of the wells are combined and
classified, with this new classification assigned to the
ddpcrPlate
object.
kmeansClassify( droplets, centres = matrix(c(0, 0, 10000, 0, 0, 7000, 10000, 7000), ncol = 2, byrow = TRUE), ... ) ## S4 method for signature 'data.frame' kmeansClassify( droplets, centres = matrix(c(0, 0, 10000, 0, 0, 7000, 10000, 7000), ncol = 2, byrow = TRUE), fullTable = TRUE ) ## S4 method for signature 'ddpcrWell' kmeansClassify( droplets, centres = matrix(c(0, 0, 10000, 0, 0, 7000, 10000, 7000), ncol = 2, byrow = TRUE) ) ## S4 method for signature 'ddpcrPlate' kmeansClassify( droplets, centres = matrix(c(0, 0, 10000, 0, 0, 7000, 10000, 7000), ncol = 2, byrow = TRUE) )
kmeansClassify( droplets, centres = matrix(c(0, 0, 10000, 0, 0, 7000, 10000, 7000), ncol = 2, byrow = TRUE), ... ) ## S4 method for signature 'data.frame' kmeansClassify( droplets, centres = matrix(c(0, 0, 10000, 0, 0, 7000, 10000, 7000), ncol = 2, byrow = TRUE), fullTable = TRUE ) ## S4 method for signature 'ddpcrWell' kmeansClassify( droplets, centres = matrix(c(0, 0, 10000, 0, 0, 7000, 10000, 7000), ncol = 2, byrow = TRUE) ) ## S4 method for signature 'ddpcrPlate' kmeansClassify( droplets, centres = matrix(c(0, 0, 10000, 0, 0, 7000, 10000, 7000), ncol = 2, byrow = TRUE) )
droplets |
A |
centres |
Either:
Defaults to |
... |
Other options depending on the type of |
fullTable |
If |
An object with the new classification.
If droplets
is a data frame, a list is returned with the
following components:
data |
A data frame or vector corresponding to the classification. |
centres |
A data frame listing the final centre points from the k-means algorithm with the corresponding cluster labels. |
Anthony Chiu, [email protected]
This method uses the kmeans
function.
To manually set and retrieve classifications, use the
wellClassification
, plateClassification
and
plateClassificationMethod
methods.
For a supervised classification approach, one may want to consider
knnClassify
.
### Use the KRASdata dataset for all of these examples. ## Use K-means clustering to classify droplets into four (the default ## number) classes. aWell <- kmeansClassify(KRASdata[["E03"]]) ## We can look the the classification or the centres. head(aWell$data) aWell$centres ## Specify 3 centres for a different sample in KRASdata. aWell <- kmeansClassify(KRASdata[["H04"]], centres=3) head(aWell$data) ## We can be more specific with the choice of centres. aWell <- kmeansClassify(KRASdata[["H04"]], centres=matrix(c(5000, 1500, 5500, 7000, 10000, 2000), ncol=2, byrow=TRUE)) ## We can use \code{ddpcrWell} objects directly as a parameter. aWell <- ddpcrWell(well=KRASdata[["E03"]]) kmeansClassify(aWell) ## We can take multiple samples in a \code{ddpcrPlate} object and ## classify everything together. krasPlate <- ddpcrPlate(wells=KRASdata) kmeansClassify(krasPlate)
### Use the KRASdata dataset for all of these examples. ## Use K-means clustering to classify droplets into four (the default ## number) classes. aWell <- kmeansClassify(KRASdata[["E03"]]) ## We can look the the classification or the centres. head(aWell$data) aWell$centres ## Specify 3 centres for a different sample in KRASdata. aWell <- kmeansClassify(KRASdata[["H04"]], centres=3) head(aWell$data) ## We can be more specific with the choice of centres. aWell <- kmeansClassify(KRASdata[["H04"]], centres=matrix(c(5000, 1500, 5500, 7000, 10000, 2000), ncol=2, byrow=TRUE)) ## We can use \code{ddpcrWell} objects directly as a parameter. aWell <- ddpcrWell(well=KRASdata[["E03"]]) kmeansClassify(aWell) ## We can take multiple samples in a \code{ddpcrPlate} object and ## classify everything together. krasPlate <- ddpcrPlate(wells=KRASdata) kmeansClassify(krasPlate)
ddpcrWell
or ddpcrPlate
object, or in a data frame.If droplets
is a data frame, the droplets are classified
using the k-nearest neighbour algorithm against a training data set.
If droplets
is a ddpcrWell
object, the droplets
in the well are classified and returned in another ddpcrWell
object.
If droplets
is a ddpcrPlate
object, the
wells are combined and classified together, with the resulting
classification assigned to the ddpcrPlate
object.
knnClassify(droplets, trainData, cl, k, prob = 0, ...) ## S4 method for signature 'data.frame' knnClassify(droplets, trainData, cl, k, prob = 0, fullTable = TRUE) ## S4 method for signature 'ddpcrWell' knnClassify(droplets, trainData, cl, k, prob = 0) ## S4 method for signature 'ddpcrPlate' knnClassify(droplets, trainData, cl, k, prob = 0)
knnClassify(droplets, trainData, cl, k, prob = 0, ...) ## S4 method for signature 'data.frame' knnClassify(droplets, trainData, cl, k, prob = 0, fullTable = TRUE) ## S4 method for signature 'ddpcrWell' knnClassify(droplets, trainData, cl, k, prob = 0) ## S4 method for signature 'ddpcrPlate' knnClassify(droplets, trainData, cl, k, prob = 0)
droplets |
A |
trainData |
A data frame of training data with columns
|
cl |
A vector of classes corresponding to |
k |
The number of nearest neighbours to use in the algorithm. |
prob |
The minimal proportion of votes for the winning class needed to assert that a droplet belongs to the class. This figure should be a float between 0 and 1. For example, if 0.6 then at least 60 k-nearest neighbours need to be of one class, otherwise it is classified as "Rain". Defaults to 0, i.e. we do not use "Rain". |
... |
Other options depending on the type of |
fullTable |
If |
An object with the new classification.
If droplets
is a data frame, return data frame or factor
(depending on the value of fullTable
) of the droplet classification
under the k-NN algorithm.
Anthony Chiu, [email protected]
This method uses the knn
function.
To manually set and retrieve classifications, use the
wellClassification
, plateClassification
and
plateClassificationMethod
methods.
kmeansClassify
provides a wrapper for the k-means clustering
algorithm.
### Use the KRASdata dataset for all of these examples. ## Use k-means clustering to classify one sample. Use this as training ## data for the K-Nearest Neighbour algorithm. trainingData <- KRASdata[["E03"]] trainingData <- kmeansClassify(trainingData)$data ## Classify a dataframe using k-NN with k = 1 and the above training data. aWell <- knnClassify( KRASdata[["F03"]], trainData=trainingData[, c("Ch1.Amplitude", "Ch2.Amplitude")], cl=trainingData$class, k=1) dropletPlot(aWell, cMethod="class") # visualising the classification ## We can change k to a larger number, here with a ddpcrWell object. aWell <- ddpcrWell(well=KRASdata[["E03"]]) aWell <- knnClassify( aWell, trainData=trainingData[, c("Ch1.Amplitude", "Ch2.Amplitude")], cl=trainingData$class, k=3) dropletPlot(aWell, cMethod="knn") # visualising the classification ## Changing the 'prob' parameter means that droplets with less than 'prob' ## of the votes will not be classified. We do this for a ddpcrPlate ## object. krasPlate <- ddpcrPlate(wells=KRASdata[c("E03", "H03", "C04", "F04")]) krasPlate <- knnClassify( krasPlate, trainData=trainingData[, c("Ch1.Amplitude", "Ch2.Amplitude")], cl=trainingData$class, k=3, prob=0.6) dropletPlot(krasPlate, cMethod="knn") # visualising the classification
### Use the KRASdata dataset for all of these examples. ## Use k-means clustering to classify one sample. Use this as training ## data for the K-Nearest Neighbour algorithm. trainingData <- KRASdata[["E03"]] trainingData <- kmeansClassify(trainingData)$data ## Classify a dataframe using k-NN with k = 1 and the above training data. aWell <- knnClassify( KRASdata[["F03"]], trainData=trainingData[, c("Ch1.Amplitude", "Ch2.Amplitude")], cl=trainingData$class, k=1) dropletPlot(aWell, cMethod="class") # visualising the classification ## We can change k to a larger number, here with a ddpcrWell object. aWell <- ddpcrWell(well=KRASdata[["E03"]]) aWell <- knnClassify( aWell, trainData=trainingData[, c("Ch1.Amplitude", "Ch2.Amplitude")], cl=trainingData$class, k=3) dropletPlot(aWell, cMethod="knn") # visualising the classification ## Changing the 'prob' parameter means that droplets with less than 'prob' ## of the votes will not be classified. We do this for a ddpcrPlate ## object. krasPlate <- ddpcrPlate(wells=KRASdata[c("E03", "H03", "C04", "F04")]) krasPlate <- knnClassify( krasPlate, trainData=trainingData[, c("Ch1.Amplitude", "Ch2.Amplitude")], cl=trainingData$class, k=3, prob=0.6) dropletPlot(krasPlate, cMethod="knn") # visualising the classification
A data frame of droplet counts using the standard
Cluster
classification from KRASdata
. Each row
corresponds to a well/sample and the columns PP
, PN
, NP
and NN
show how many droplets were in each cluster. The remaining
rows were calculated from the counts figures except for the
InputAmount
column.
KRAScountsWellCol
is the same data frame but has
a Well
column instead of named rows.
KRAScountsQS
is a data frame imported from a CSV created
by Bio-Rad's QuantaSoft.
data(KRAScounts) data(KRAScountsWellCol) data(KRAScountsQS)
data(KRAScounts) data(KRAScountsWellCol) data(KRAScountsQS)
A data frame where each row corresponds to a well/sample.
An object of class data.frame
with 12 rows and 18 columns.
An object of class data.frame
with 24 rows and 63 columns.
The data frame was created by:
krasPlate <- ddpcrPlate(wells=KRASdata) KRAScounts <- plateSummary(krasPlate, cMethod="Cluster") onesVector <- c(1, 1, 1) runAmount <- c(64 * onesVector, 16 * onesVector, 4 * onesVector, onesVector) KRAScounts$InputAmount <- runAmount KRAScountsWellCol <- KRAScounts KRAScountsWellCol$Well <- rownames(KRAScounts) KRAScountsWellCol <- KRAScountsWellCol[, c(18,1:17)] rownames(KRAScountsWellCol) <- NULL
A data frame.
From the KRASdata
dataset created by Mahmood Ayub,
[email protected]
A data frame of ddPCR droplet amplitudes using KRAS cell lines
and pre-defined mutant/wild type ratios. The existing classification under
the column name Cluster
was obtained from Bio-Rad's QuantaSoft by
setting the Ch1.Amplitude
threshold to 6789
and the
Ch2.Amplitude
threshold to 3000
.
data(KRASdata)
data(KRASdata)
A list of data frames, each of which has columns
Ch1.Amplitude
, Ch2.Amplitude
and Cluster
.
A data frame.
From ddPCR experiments run by Mahmood Ayub, [email protected]
Assume that each of the classified clusters are bivariate normally distributed. We add fuzziness to the classifications by assigning droplets far away from the centres as "Rain". We use the Mahalanobis distance for each cluster to determine whether a droplet is 'too far away'.
mahalanobisRain(droplets, cMethod, maxDistances = 30, ...) ## S4 method for signature 'data.frame' mahalanobisRain(droplets, cMethod, maxDistances = 30, fullTable = TRUE) ## S4 method for signature 'ddpcrWell' mahalanobisRain(droplets, cMethod, maxDistances = 30) ## S4 method for signature 'ddpcrPlate' mahalanobisRain(droplets, cMethod, maxDistances = 30)
mahalanobisRain(droplets, cMethod, maxDistances = 30, ...) ## S4 method for signature 'data.frame' mahalanobisRain(droplets, cMethod, maxDistances = 30, fullTable = TRUE) ## S4 method for signature 'ddpcrWell' mahalanobisRain(droplets, cMethod, maxDistances = 30) ## S4 method for signature 'ddpcrPlate' mahalanobisRain(droplets, cMethod, maxDistances = 30)
droplets |
A |
cMethod |
The name or column number of the classification for which we want to add rain to. |
maxDistances |
A list of (levels) with keys in |
... |
Other options depending on the type of |
fullTable |
If |
An object where the specified class has "Rain" entries added.
Anthony Chiu, [email protected]
## Take a data frame of droplets of transform it into the rigth format. droplets <- KRASdata[["E03"]] droplets$Cluster <- relabelClasses(droplets, classCol="Cluster") ## Add rain as a new column. droplets$ClusterMahRain <- mahalanobisRain(droplets, cMethod="Cluster", fullTable=FALSE) table(droplets$ClusterMahRain) ## The maximum distance around each mean can be changed uniformly. droplets$ClusterMahRain <- mahalanobisRain(droplets, cMethod="Cluster", maxDistances=35, fullTable=FALSE) table(droplets$ClusterMahRain) ## Or we can change the maximum distances for each individual cluster. droplets$ClusterMahRain <- mahalanobisRain(droplets, cMethod="Cluster", maxDistances=list(NN=35, NP=30, PN=30, PP=30), fullTable=FALSE) table(droplets$ClusterMahRain) # This method works the same for ddpcrWell objects. aWell <- ddpcrWell(well=KRASdata[["E03"]]) aWell <- mahalanobisRain(aWell, cMethod="Cluster") table(wellClassification(aWell, cMethod="ClusterMahRain")) # Likewise for ddpcrPlate objects. krasPlate <- ddpcrPlate(wells=KRASdata[c("E03", "H03", "C04", "F04")]) krasPlate <- mahalanobisRain(krasPlate, cMethod="Cluster") lapply(plateClassification(krasPlate, cMethod="ClusterMahRain"), table)
## Take a data frame of droplets of transform it into the rigth format. droplets <- KRASdata[["E03"]] droplets$Cluster <- relabelClasses(droplets, classCol="Cluster") ## Add rain as a new column. droplets$ClusterMahRain <- mahalanobisRain(droplets, cMethod="Cluster", fullTable=FALSE) table(droplets$ClusterMahRain) ## The maximum distance around each mean can be changed uniformly. droplets$ClusterMahRain <- mahalanobisRain(droplets, cMethod="Cluster", maxDistances=35, fullTable=FALSE) table(droplets$ClusterMahRain) ## Or we can change the maximum distances for each individual cluster. droplets$ClusterMahRain <- mahalanobisRain(droplets, cMethod="Cluster", maxDistances=list(NN=35, NP=30, PN=30, PP=30), fullTable=FALSE) table(droplets$ClusterMahRain) # This method works the same for ddpcrWell objects. aWell <- ddpcrWell(well=KRASdata[["E03"]]) aWell <- mahalanobisRain(aWell, cMethod="Cluster") table(wellClassification(aWell, cMethod="ClusterMahRain")) # Likewise for ddpcrPlate objects. krasPlate <- ddpcrPlate(wells=KRASdata[c("E03", "H03", "C04", "F04")]) krasPlate <- mahalanobisRain(krasPlate, cMethod="Cluster") lapply(plateClassification(krasPlate, cMethod="ClusterMahRain"), table)
Returns a data frame with the basic figures and the number of mutant copies per 20ul.
mutantCopiesSummary(df)
mutantCopiesSummary(df)
df |
A data frame generated by |
A data frame with the basic columns and mutant copies per 20ul.
Anthony Chiu, [email protected]
df <- fullCountsSummary(KRAScountsQS) mutantCopiesSummary(df)
df <- fullCountsSummary(KRAScountsQS) mutantCopiesSummary(df)
Retrieves the number of droplets in a ddpcrWell
or
ddpcrPlate
object.
numDroplets(theObject, ...) ## S4 method for signature 'ddpcrWell' numDroplets(theObject) ## S4 method for signature 'ddpcrPlate' numDroplets(theObject)
numDroplets(theObject, ...) ## S4 method for signature 'ddpcrWell' numDroplets(theObject) ## S4 method for signature 'ddpcrPlate' numDroplets(theObject)
theObject |
A |
... |
Other parameters depending on the type of |
For ddpcrWell
objects, return the number of droplets as an
integer.
For ddpcrPlate
objects, return a named vector. The names
correspond to a well name and each item corresponding to the number of
droplets in that well.
Anthony Chiu, [email protected]
## Count the number of droplets in a well. aWell <- ddpcrWell(well=KRASdata[["E03"]]) numDroplets(aWell) ## Get all of the wells in a named vector. krasPlate <- ddpcrPlate(wells=KRASdata) (numberDroplets <- numDroplets(krasPlate)) sum(numberDroplets) ## We can choose to get a subset of the wells. (numberDroplets <- numDroplets(krasPlate[c("H03", "A04")])) sum(numberDroplets)
## Count the number of droplets in a well. aWell <- ddpcrWell(well=KRASdata[["E03"]]) numDroplets(aWell) ## Get all of the wells in a named vector. krasPlate <- ddpcrPlate(wells=KRASdata) (numberDroplets <- numDroplets(krasPlate)) sum(numberDroplets) ## We can choose to get a subset of the wells. (numberDroplets <- numDroplets(krasPlate[c("H03", "A04")])) sum(numberDroplets)
numericInputs
.By default, numericInput
objects are added to the page
below each other. This function allows for inline numericInput
fields.
numericInputRow(inputId, label, value = "", size = NULL)
numericInputRow(inputId, label, value = "", size = NULL)
inputId |
The identifier for the numericInput object. |
label |
The text label to display alongside. |
value |
The default value of the numericInput. |
size |
The size (width) and maxlength. |
A div
with the appropriate label and input field.
Adapted from: http://stackoverflow.com/a/21132918/1262569
Take a data frame of droplet counts and returns only the raw "PP", "PN", "NP" and "NN" counts, plus any additional columns specified.
parseClusterCounts( df, rows = NULL, rowID = NULL, keepCols = NULL, keepColNames = NULL )
parseClusterCounts( df, rows = NULL, rowID = NULL, keepCols = NULL, keepColNames = NULL )
df |
A data frame with droplet count columns in one of the following formats:
|
rows |
A vector of rows (numbers or well names) to keep from the
original data frame. If set to |
rowID |
If set, this field is used as the row names. If |
keepCols |
A vector of columns to keep from |
keepColNames |
A vector of new column names for |
A data frame with the counts in the PP
, PN
, PN
and PN
convention.
Anthony Chiu, [email protected]
## Take a data frame with row names given by the well names. Get a simple ## count of droplets in each cluster. parseClusterCounts(KRAScounts) ## Keep only the row numbers 3, 6 and 9. parseClusterCounts(KRAScounts, rows=c(3, 6, 9)) ## Keep only the rows labelled "F03", "A04", "D04". parseClusterCounts(KRAScounts, rows=c("F03", "A04", "D04")) ## Take a data frame with a 'Well' column and do the same as above. parseClusterCounts(KRAScountsWellCol, rowID="Well") ## Keep the 'InputAmount' column. parseClusterCounts(KRAScounts, keepCols=c("InputAmount")) ## Keep the 'InputAmount' column and rename it. parseClusterCounts(KRAScounts, keepCols=c("InputAmount"), keepColNames=c("NanogramsIn"))
## Take a data frame with row names given by the well names. Get a simple ## count of droplets in each cluster. parseClusterCounts(KRAScounts) ## Keep only the row numbers 3, 6 and 9. parseClusterCounts(KRAScounts, rows=c(3, 6, 9)) ## Keep only the rows labelled "F03", "A04", "D04". parseClusterCounts(KRAScounts, rows=c("F03", "A04", "D04")) ## Take a data frame with a 'Well' column and do the same as above. parseClusterCounts(KRAScountsWellCol, rowID="Well") ## Keep the 'InputAmount' column. parseClusterCounts(KRAScounts, keepCols=c("InputAmount")) ## Keep the 'InputAmount' column and rename it. parseClusterCounts(KRAScounts, keepCols=c("InputAmount"), keepColNames=c("NanogramsIn"))
Retrieve multiple classification factors that have been assigned to
a ddpcrPlate
object.
plateClassification( theObject, cMethod = NULL, withAmplitudes = FALSE, wellCol = FALSE ) ## S4 method for signature 'ddpcrPlate' plateClassification( theObject, cMethod = NULL, withAmplitudes = FALSE, wellCol = FALSE ) plateClassification(theObject, cMethod) <- value ## S4 replacement method for signature 'ddpcrPlate,character,list' plateClassification(theObject, cMethod) <- value ## S4 replacement method for signature 'ddpcrPlate,character,factor' plateClassification(theObject, cMethod) <- value
plateClassification( theObject, cMethod = NULL, withAmplitudes = FALSE, wellCol = FALSE ) ## S4 method for signature 'ddpcrPlate' plateClassification( theObject, cMethod = NULL, withAmplitudes = FALSE, wellCol = FALSE ) plateClassification(theObject, cMethod) <- value ## S4 replacement method for signature 'ddpcrPlate,character,list' plateClassification(theObject, cMethod) <- value ## S4 replacement method for signature 'ddpcrPlate,character,factor' plateClassification(theObject, cMethod) <- value
theObject |
A |
cMethod |
This is the name of the classification to retrieve and should
be a character vector. If |
withAmplitudes |
If |
wellCol |
If |
value |
Either:
|
If requesting one classification without the amplitudes, a list of factors corresponding to the classifications is returned. Otherwise, a list of data frames is returned where each row corresponds to a droplet in the corresponding well.
Anthony Chiu, [email protected]
### The examples here show how this method works by setting classifications ### using data frames. To do this, we use the ### \code{\link{thresholdClassify}} method on _data frames_. Note that ### \code{thresholdClassify} also works directly on \code{ddpcrWell} and ### \code{ddpcrPlate} objects; this is simply an illustration of ### how to use the \code{plateClassification} method directly. In general, ### it is recommended to use \code{thresholdClassify} directly on ### \code{ddpcrPlate} objects. ## Create a ddpcrPlate object. krasPlate <- ddpcrPlate(wells=KRASdata) ## Classify a data frame of droplets and keep it in a _single_ data frame. ## Set the new classification from this. droplets <- do.call(rbind, amplitudes(krasPlate)) clSingle <- thresholdClassify(droplets, ch1Threshold=7000, ch2Threshold=3500, fullTable=FALSE) plateClassification(krasPlate, "thresholdSing") <- clSingle ## We can also set the new classification from a list of factors. clList <- lapply(KRASdata, thresholdClassify, ch1Threshold=7000, ch2Threshold=3500, fullTable=FALSE) plateClassification(krasPlate, "thresholdList") <- clList ## We can get all of the classifications as a list of data frames. plate <- plateClassification(krasPlate) lapply(plate, head, n=1) ## We can include the droplet amplitudes columns. plate <- plateClassification(krasPlate, withAmplitudes=TRUE) lapply(plate, head, n=1) ## We can focus on specific classifications. plate <- plateClassification(krasPlate, cMethod=c("thresholdSing", "thresholdList")) lapply(plate, head, n=1) ## The wellCol option adds an extra column showing which well the droplet ## came from. plate <- plateClassification(krasPlate, withAmplitudes=TRUE, wellCol=TRUE) lapply(plate, head, n=1)
### The examples here show how this method works by setting classifications ### using data frames. To do this, we use the ### \code{\link{thresholdClassify}} method on _data frames_. Note that ### \code{thresholdClassify} also works directly on \code{ddpcrWell} and ### \code{ddpcrPlate} objects; this is simply an illustration of ### how to use the \code{plateClassification} method directly. In general, ### it is recommended to use \code{thresholdClassify} directly on ### \code{ddpcrPlate} objects. ## Create a ddpcrPlate object. krasPlate <- ddpcrPlate(wells=KRASdata) ## Classify a data frame of droplets and keep it in a _single_ data frame. ## Set the new classification from this. droplets <- do.call(rbind, amplitudes(krasPlate)) clSingle <- thresholdClassify(droplets, ch1Threshold=7000, ch2Threshold=3500, fullTable=FALSE) plateClassification(krasPlate, "thresholdSing") <- clSingle ## We can also set the new classification from a list of factors. clList <- lapply(KRASdata, thresholdClassify, ch1Threshold=7000, ch2Threshold=3500, fullTable=FALSE) plateClassification(krasPlate, "thresholdList") <- clList ## We can get all of the classifications as a list of data frames. plate <- plateClassification(krasPlate) lapply(plate, head, n=1) ## We can include the droplet amplitudes columns. plate <- plateClassification(krasPlate, withAmplitudes=TRUE) lapply(plate, head, n=1) ## We can focus on specific classifications. plate <- plateClassification(krasPlate, cMethod=c("thresholdSing", "thresholdList")) lapply(plate, head, n=1) ## The wellCol option adds an extra column showing which well the droplet ## came from. plate <- plateClassification(krasPlate, withAmplitudes=TRUE, wellCol=TRUE) lapply(plate, head, n=1)
plateClassificationMethod
retrieves multiple classification methods
that have been assigned to a ddpcrPlate
object.
commonClassificationMethod
retrieves the classification
methods common to all the wells in the given ddpcrPlate
object.
plateClassificationMethod(theObject) ## S4 method for signature 'ddpcrPlate' plateClassificationMethod(theObject) plateClassificationMethod(theObject, cMethod) <- value ## S4 replacement method for signature 'ddpcrPlate' plateClassificationMethod(theObject, cMethod) <- value commonClassificationMethod(theObject) ## S4 method for signature 'ddpcrPlate' commonClassificationMethod(theObject)
plateClassificationMethod(theObject) ## S4 method for signature 'ddpcrPlate' plateClassificationMethod(theObject) plateClassificationMethod(theObject, cMethod) <- value ## S4 replacement method for signature 'ddpcrPlate' plateClassificationMethod(theObject, cMethod) <- value commonClassificationMethod(theObject) ## S4 method for signature 'ddpcrPlate' commonClassificationMethod(theObject)
theObject |
A |
cMethod |
This should represent existing classification method(s) for
all wells in
|
value |
New classification method(s) in the same form as
|
plateClassificationMethod
returns a list of character strings
corresponding to the classification methods.
commonClassificationMethod
returns a vector of character
strings indicating which classification methods appear in all wells.
Anthony Chiu, [email protected]
plateClassification
for the classifications.
## Get the classification methods for the KRASdata dataset. krasPlate <- ddpcrPlate(wells=KRASdata) plateClassificationMethod(krasPlate) ## Change the "Cluster" column to "QS". plateClassificationMethod(krasPlate, "Cluster") <- "QS" plateClassificationMethod(krasPlate) ## Usually, all of the classification names are the same for all wells. We ## use the \code{commonClassificationMethod} method to retrieve the ones ## common to all wells. commonClassificationMethod(krasPlate)
## Get the classification methods for the KRASdata dataset. krasPlate <- ddpcrPlate(wells=KRASdata) plateClassificationMethod(krasPlate) ## Change the "Cluster" column to "QS". plateClassificationMethod(krasPlate, "Cluster") <- "QS" plateClassificationMethod(krasPlate) ## Usually, all of the classification names are the same for all wells. We ## use the \code{commonClassificationMethod} method to retrieve the ones ## common to all wells. commonClassificationMethod(krasPlate)
Takes a collection of classified droplets, each corresponding to a well, and produces a list of positive/negative counts and estimates of how many molecules are in each well.
plateSummary( wells, ..., ch1Label = "Mt", ch2Label = "Wt", sortByLetter = FALSE ) ## S4 method for signature 'list' plateSummary(wells, ch1Label = "Mt", ch2Label = "Wt", sortByLetter = FALSE) ## S4 method for signature 'ddpcrPlate' plateSummary( wells, cMethod, ch1Label = "Mt", ch2Label = "Wt", sortByLetter = FALSE )
plateSummary( wells, ..., ch1Label = "Mt", ch2Label = "Wt", sortByLetter = FALSE ) ## S4 method for signature 'list' plateSummary(wells, ch1Label = "Mt", ch2Label = "Wt", sortByLetter = FALSE) ## S4 method for signature 'ddpcrPlate' plateSummary( wells, cMethod, ch1Label = "Mt", ch2Label = "Wt", sortByLetter = FALSE )
wells |
Either a |
... |
Other options depending on the type of |
ch1Label |
The prefix to use for the channel 1 target. Defaults to "Mt". |
ch2Label |
The prefix to use for the channel 2 target. Defaults to "Wt". |
sortByLetter |
If |
cMethod |
The classification method to create a summary for. |
A data frame with droplet counts and molecules number estimates for each well.
Anthony Chiu, [email protected]
## Take a ddpcrPlate object and summarise its wells. krasPlate <- ddpcrPlate(KRASdata) plateSummary(krasPlate, cMethod="Cluster")
## Take a ddpcrPlate object and summarise its wells. krasPlate <- ddpcrPlate(KRASdata) plateSummary(krasPlate, cMethod="Cluster")
Take a vector of classes and return a vector of positive and negative counts that is compatible with ddPCR analysis.
positiveCounts(cl)
positiveCounts(cl)
cl |
A vector of classes that correspond to droplet amplitude data. The vector should only contain the values "PP", "PN", "NP" or "NN". |
A vector corresponding to "PP", "PN", "NP" and "NN".
Anthony Chiu, [email protected]
## Take a data frame and make it into the right format. aWell <- KRASdata[["E03"]] aWell$Cluster <- relabelClasses(aWell, classCol="Cluster") ## Count the number of droplets in each cluster. positiveCounts(aWell$Cluster)
## Take a data frame and make it into the right format. aWell <- KRASdata[["E03"]] aWell$Cluster <- relabelClasses(aWell, classCol="Cluster") ## Count the number of droplets in each cluster. positiveCounts(aWell$Cluster)
Bio-Rad's QuantaSoft can export droplet amplitude data from multiple wells into CSV files for each well. This function can read these CSV files into a list. Note that empty wells will be ignored.
readCSVDataFrame(path, wellCol = FALSE, sortByLetter = FALSE)
readCSVDataFrame(path, wellCol = FALSE, sortByLetter = FALSE)
path |
The path containing the CSV files (can be a combination of
directories and individual CSV file paths). Each file will have
a |
wellCol |
If |
sortByLetter |
If |
A list of data frames, each containing the data from a CSV file with the corresponding well name.
Anthony Chiu, [email protected]
## Read all of the droplet amplitudes from CSV files in a directory. moreAmpsDir <- system.file("extdata", "more-amplitudes", package="twoddpcr") someWells <- readCSVDataFrame(moreAmpsDir) ## We can read files from directories and files at the same time. ampFile <- system.file("extdata", "amplitudes", "sample_B03_Amplitude.csv", package="twoddpcr") someWells <- readCSVDataFrame(c(moreAmpsDir, ampFile)) ## If samples have been ordered by "A01", "A02", "A03", etc. instead of ## "A01", "B01", "C01", etc., we can set the sortByLetter flag to TRUE. someWells <- readCSVDataFrame(moreAmpsDir, sortByLetter=TRUE) ## Setting wellCol to TRUE adds an extra column with the well name. If we ## bind the data frames together, we can track where the droplets came from. someWells <- readCSVDataFrame(moreAmpsDir, wellCol=TRUE) someWells <- do.call(rbind, someWells) head(someWells) tail(someWells)
## Read all of the droplet amplitudes from CSV files in a directory. moreAmpsDir <- system.file("extdata", "more-amplitudes", package="twoddpcr") someWells <- readCSVDataFrame(moreAmpsDir) ## We can read files from directories and files at the same time. ampFile <- system.file("extdata", "amplitudes", "sample_B03_Amplitude.csv", package="twoddpcr") someWells <- readCSVDataFrame(c(moreAmpsDir, ampFile)) ## If samples have been ordered by "A01", "A02", "A03", etc. instead of ## "A01", "B01", "C01", etc., we can set the sortByLetter flag to TRUE. someWells <- readCSVDataFrame(moreAmpsDir, sortByLetter=TRUE) ## Setting wellCol to TRUE adds an extra column with the well name. If we ## bind the data frames together, we can track where the droplets came from. someWells <- readCSVDataFrame(moreAmpsDir, wellCol=TRUE) someWells <- do.call(rbind, someWells) head(someWells) tail(someWells)
An attempt to label clusters with "NN", "NP", "PN" or "PP" automatically. (This will not generalise to amplitudes in only a single channel.)
relabelClasses(droplets, classCol = "class", presentClasses = ddpcr$classes)
relabelClasses(droplets, classCol = "class", presentClasses = ddpcr$classes)
droplets |
A data frame of droplet amplitudes with a classification. |
classCol |
The column (name or number) from 'droplets' representing the class. |
presentClasses |
A vector of classes that we want to label. Must be a subset of c("NN", "NP", "PN", "PP") and must have the same number of classes as the number of unique classes in the class column. |
The classification column relabelled with "NN", "NP", "PN" and "PP".
Anthony Chiu, [email protected]
## Look at the "Cluster" column that was created by Bio-Rad's QuantaSoft. aWell <- KRASdata[["E03"]] str(aWell$Cluster) ## Relabel the classes to see the difference. relabelled <- relabelClasses(aWell, classCol="Cluster") str(relabelled) levels(relabelled) ## We choose a sample with 3 clusters. unique(KRASdata[["H04"]]$Cluster) ## We can check that there is no "PP" class, so specify the others only. relabelled <- relabelClasses(KRASdata[["H04"]], classCol="Cluster", presentClasses=c("NN", "PN", "NP")) table(relabelled)
## Look at the "Cluster" column that was created by Bio-Rad's QuantaSoft. aWell <- KRASdata[["E03"]] str(aWell$Cluster) ## Relabel the classes to see the difference. relabelled <- relabelClasses(aWell, classCol="Cluster") str(relabelled) levels(relabelled) ## We choose a sample with 3 clusters. unique(KRASdata[["H04"]]$Cluster) ## We can check that there is no "PP" class, so specify the others only. relabelled <- relabelClasses(KRASdata[["H04"]], classCol="Cluster", presentClasses=c("NN", "PN", "NP")) table(relabelled)
By default, all droplets classified as "N/A" or "Rain" will be removed. Including these droplets is useful for visualisation purposes, but they could be a problem in some scenarios, e.g. if we wish to use the classification as a training data set.
removeDropletClasses( droplets, ..., classesToRemove = NULL, keepUnclassified = FALSE ) ## S4 method for signature 'data.frame' removeDropletClasses( droplets, cMethod = "class", classesToRemove = NULL, keepUnclassified = FALSE ) ## S4 method for signature 'ddpcrWell' removeDropletClasses( droplets, cMethod, classesToRemove = NULL, keepUnclassified = FALSE ) ## S4 method for signature 'ddpcrPlate' removeDropletClasses( droplets, cMethod, classesToRemove = NULL, keepUnclassified = FALSE )
removeDropletClasses( droplets, ..., classesToRemove = NULL, keepUnclassified = FALSE ) ## S4 method for signature 'data.frame' removeDropletClasses( droplets, cMethod = "class", classesToRemove = NULL, keepUnclassified = FALSE ) ## S4 method for signature 'ddpcrWell' removeDropletClasses( droplets, cMethod, classesToRemove = NULL, keepUnclassified = FALSE ) ## S4 method for signature 'ddpcrPlate' removeDropletClasses( droplets, cMethod, classesToRemove = NULL, keepUnclassified = FALSE )
droplets |
A |
... |
Other parameters depending on the type of |
classesToRemove |
A vector of character strings corresponding to the
classes that should be removed. Defaults to |
keepUnclassified |
A logical flag determining whether unclassified
droplets (i.e. "Rain" or "N/A") should be kept. Defaults to |
cMethod |
This is the name or column number corresponding to the
classification in |
If a ddpcrWell
object is given, return a data frame
corresponding to droplets
with the given droplet classes removed.
If a ddpcrPlate
object is given, return a list of data frames
instead.
Anthony Chiu, [email protected]
This function can remove "N/A" droplets from classifications
produced by gridClassify
.
## Take a data frame and transform it into the right format. aWell <- KRASdata[["E03"]] aWell$Cluster <- relabelClasses(aWell, classCol="Cluster") ## Add rain using the Mahalanobis distance. aWell$ClusterMahRain <- mahalanobisRain(aWell, cMethod="Cluster", fullTable=FALSE) table(aWell$ClusterMahRain) ## Suppose we want to use this for training. Remove the "Rain" droplets. aWellCleaned <- removeDropletClasses(aWell, cMethod="ClusterMahRain") table(aWellCleaned$ClusterMahRain) ## All of the above works with ddpcrWell objects. aWell <- ddpcrWell(well=KRASdata[["E03"]]) aWell <- mahalanobisRain(aWell, cMethod="Cluster") trainingData <- removeDropletClasses(aWell, cMethod="ClusterMahRain") table(wellClassification(aWell, "ClusterMahRain")) table(trainingData$ClusterMahRain) ## Likewise for ddpcrPlate objects we can create the training data. krasPlate <- ddpcrPlate(wells=KRASdata[c("E03", "F03", "G03")]) krasPlate <- mahalanobisRain(krasPlate, cMethod="Cluster") trainingData <- removeDropletClasses(krasPlate, cMethod="ClusterMahRain") cl <- plateClassification(krasPlate, cMethod="ClusterMahRain") cl <- unlist(cl) table(cl) td <- do.call(rbind, trainingData) table(td$ClusterMahRain) ## We could also remove other droplet classes, such as the "PN" and "PP" ## clusters. noPNPP <- removeDropletClasses(krasPlate, cMethod="ClusterMahRain", classesToRemove=c("PN", "PP")) td <- do.call(rbind, noPNPP) table(td$ClusterMahRain) ## The same could be done, but with the "Rain" retained. noPNPPWithRain <- removeDropletClasses(krasPlate, cMethod="ClusterMahRain", classesToRemove=c("PN", "PP"), keepUnclassified=TRUE) td <- do.call(rbind, noPNPPWithRain) table(td$ClusterMahRain)
## Take a data frame and transform it into the right format. aWell <- KRASdata[["E03"]] aWell$Cluster <- relabelClasses(aWell, classCol="Cluster") ## Add rain using the Mahalanobis distance. aWell$ClusterMahRain <- mahalanobisRain(aWell, cMethod="Cluster", fullTable=FALSE) table(aWell$ClusterMahRain) ## Suppose we want to use this for training. Remove the "Rain" droplets. aWellCleaned <- removeDropletClasses(aWell, cMethod="ClusterMahRain") table(aWellCleaned$ClusterMahRain) ## All of the above works with ddpcrWell objects. aWell <- ddpcrWell(well=KRASdata[["E03"]]) aWell <- mahalanobisRain(aWell, cMethod="Cluster") trainingData <- removeDropletClasses(aWell, cMethod="ClusterMahRain") table(wellClassification(aWell, "ClusterMahRain")) table(trainingData$ClusterMahRain) ## Likewise for ddpcrPlate objects we can create the training data. krasPlate <- ddpcrPlate(wells=KRASdata[c("E03", "F03", "G03")]) krasPlate <- mahalanobisRain(krasPlate, cMethod="Cluster") trainingData <- removeDropletClasses(krasPlate, cMethod="ClusterMahRain") cl <- plateClassification(krasPlate, cMethod="ClusterMahRain") cl <- unlist(cl) table(cl) td <- do.call(rbind, trainingData) table(td$ClusterMahRain) ## We could also remove other droplet classes, such as the "PN" and "PP" ## clusters. noPNPP <- removeDropletClasses(krasPlate, cMethod="ClusterMahRain", classesToRemove=c("PN", "PP")) td <- do.call(rbind, noPNPP) table(td$ClusterMahRain) ## The same could be done, but with the "Rain" retained. noPNPPWithRain <- removeDropletClasses(krasPlate, cMethod="ClusterMahRain", classesToRemove=c("PN", "PP"), keepUnclassified=TRUE) td <- do.call(rbind, noPNPPWithRain) table(td$ClusterMahRain)
Each well is scaled in the direction of the two axes independently. The algorithm works as follows:
Classify the entire plate using k-means clustering in order to roughly identify clusters.
For each channel and each well:
Remove the positive clusters in the other channel.
Re-run k-means clustering with to obtain new
cluster centres. If the centres are too close (default distance
2000), reject these new cluster centres and use the old centres.
Use the new centres for each well to rescale to the same scale as the average/overall scale.
renormalisePlate( plate, initialCentres = matrix(c(0, 0, 10000, 0, 0, 7000, 10000, 7000), ncol = 2, byrow = TRUE), minSeparation = 2000 )
renormalisePlate( plate, initialCentres = matrix(c(0, 0, 10000, 0, 0, 7000, 10000, 7000), ncol = 2, byrow = TRUE), minSeparation = 2000 )
plate |
A |
initialCentres |
A matrix or data frame of (rough estimates) of centres of each of the clusters in the combined data. This will be used for an initial run of k-means clustering. |
minSeparation |
The minimum distance required between two cluster centres in order for us to assume that k-means clustering found two distinct clusters. This is used when classifying droplets along a single channel and helps to reject classifications where there is only one cluster, e.g. when there are no mutants in a well. Defaults to 2000. |
A list of data frames with the rescaled amplitudes in both channels.
Anthony Chiu, [email protected]
## Normalise the KRAS data. plate <- ddpcrPlate(wells=KRASdata) normPlate <- renormalisePlate(plate)
## Normalise the KRAS data. plate <- ddpcrPlate(wells=KRASdata) normPlate <- renormalisePlate(plate)
Although we can use various algorithms to classify all droplets in a ddPCR experiment, there will be some variation between the classifications. We can perhaps have a relatively high confidence that droplets near the centres of clusters do indeed belong to that cluster, whereas we probably have a lower confidence in the classification of those further away, say, near the 'boundary' of two clusters. We may view these droplets (or a subset of them) as having an ambiguous class. This function allows us to only consider droplets classified within a certain distance of the means of each cluster and label the rest as "Rain".
sdRain(droplets, cMethod, errorLevel = 5, ...) ## S4 method for signature 'data.frame' sdRain(droplets, cMethod, errorLevel = 5, fullTable = TRUE) ## S4 method for signature 'ddpcrWell' sdRain(droplets, cMethod, errorLevel = 5) ## S4 method for signature 'ddpcrPlate' sdRain(droplets, cMethod, errorLevel = 5)
sdRain(droplets, cMethod, errorLevel = 5, ...) ## S4 method for signature 'data.frame' sdRain(droplets, cMethod, errorLevel = 5, fullTable = TRUE) ## S4 method for signature 'ddpcrWell' sdRain(droplets, cMethod, errorLevel = 5) ## S4 method for signature 'ddpcrPlate' sdRain(droplets, cMethod, errorLevel = 5)
droplets |
A |
cMethod |
The name or column number of the classification for which we want to add rain to. |
errorLevel |
How many multiples of standard deviation from the mean of each cluster to retain. Can be a list where each item corresponds to a class name and the multiple for that class. Can also be a numeric vector of length 1, which is equivalent to a list with all the same entries. Defaults to 5. |
... |
Other options depending on the type of |
fullTable |
If |
If droplets
is a data frame, return a data frame or factor
(depending on fullTable
) where droplets with ambiguous
classifications are labelled as "Rain".
If droplets
is a ddpcrWell
object, return
a ddpcrWell
object with a rainy classification.
If droplets
is a ddpcrPlate
object, return
a ddpcrPlate
object with a rainy classifications.
Anthony Chiu, [email protected]
This approach was described in Jones, M., Williams, J., Gaertner, K., Phillips, R., Hurst, J., & Frater, J. (2014). Low copy target detection by Droplet Digital PCR through application of a novel open access bioinformatic pipeline, "definetherain." Journal of Virological Methods, 202(100), 46–53. http://doi.org/10.1016/j.jviromet.2014.02.020
## Compare the types of droplets in a single well for the "Cluster" class ## and then with rain. aWell <- ddpcrWell(well=KRASdata[["E03"]]) aWell <- sdRain(aWell, cMethod="Cluster") cl <- wellClassification(aWell) table(cl$Cluster) table(cl$ClusterSdRain) ## Compare the types of droplets in multiple wells for the "Cluster" class ## and then with rain. krasPlate <- ddpcrPlate(wells=KRASdata[c("E03", "H03", "C04", "F04")]) krasPlate <- sdRain(krasPlate, cMethod="Cluster") plateSummary(krasPlate, cMethod="Cluster")[, c(1:5)] plateSummary(krasPlate, cMethod="ClusterSdRain")[, c(1:5)] ## The 'errorLevel' parameter can changed. krasPlate <- sdRain(krasPlate, cMethod="Cluster", errorLevel=4) plateSummary(krasPlate, cMethod="ClusterSdRain")[, c(1:5)] ## The 'errorLevel' parameter can also be changed for each cluster. krasPlate <- sdRain(krasPlate, cMethod="Cluster", errorLevel=list(NN=5, NP=5, PN=4, PP=3)) plateSummary(krasPlate, cMethod="ClusterSdRain")[, c(1:5)]
## Compare the types of droplets in a single well for the "Cluster" class ## and then with rain. aWell <- ddpcrWell(well=KRASdata[["E03"]]) aWell <- sdRain(aWell, cMethod="Cluster") cl <- wellClassification(aWell) table(cl$Cluster) table(cl$ClusterSdRain) ## Compare the types of droplets in multiple wells for the "Cluster" class ## and then with rain. krasPlate <- ddpcrPlate(wells=KRASdata[c("E03", "H03", "C04", "F04")]) krasPlate <- sdRain(krasPlate, cMethod="Cluster") plateSummary(krasPlate, cMethod="Cluster")[, c(1:5)] plateSummary(krasPlate, cMethod="ClusterSdRain")[, c(1:5)] ## The 'errorLevel' parameter can changed. krasPlate <- sdRain(krasPlate, cMethod="Cluster", errorLevel=4) plateSummary(krasPlate, cMethod="ClusterSdRain")[, c(1:5)] ## The 'errorLevel' parameter can also be changed for each cluster. krasPlate <- sdRain(krasPlate, cMethod="Cluster", errorLevel=list(NN=5, NP=5, PN=4, PP=3)) plateSummary(krasPlate, cMethod="ClusterSdRain")[, c(1:5)]
We use the channel names "Ch1.Amplitude" and "Ch2.Amplitude" by default. This method allows us to change it at will.
setChannelNames(droplets, ch1 = "Ch1.Amplitude", ch2 = "Ch2.Amplitude") ## S4 method for signature 'data.frame' setChannelNames(droplets, ch1 = "Ch1.Amplitude", ch2 = "Ch2.Amplitude") ## S4 method for signature 'list' setChannelNames(droplets, ch1 = "Ch1.Amplitude", ch2 = "Ch2.Amplitude")
setChannelNames(droplets, ch1 = "Ch1.Amplitude", ch2 = "Ch2.Amplitude") ## S4 method for signature 'data.frame' setChannelNames(droplets, ch1 = "Ch1.Amplitude", ch2 = "Ch2.Amplitude") ## S4 method for signature 'list' setChannelNames(droplets, ch1 = "Ch1.Amplitude", ch2 = "Ch2.Amplitude")
droplets |
A data frame or list of data frames. Each data frame should have at least two columns, where the first two columns should be vectors of doubles. |
ch1 |
The channel 1 label. |
ch2 |
The channel 2 label. |
The object droplets
with the channels renamed.
## Ensure that a data frame has channels named "Ch1.Amplitude" and ## "Ch2.Amplitude". aWell <- KRASdata[["E03"]] aWell <- setChannelNames(aWell) colnames(aWell) ## Perhaps we want to abbreviate the channel names. aWell <- setChannelNames(aWell, "Ch1", "Ch2") colnames(aWell) ## The same operator works for a list of data frames. krasWells <- KRASdata krasWells <- setChannelNames(krasWells, "Ch1", "Ch2") lapply(krasWells, colnames)[1:3]
## Ensure that a data frame has channels named "Ch1.Amplitude" and ## "Ch2.Amplitude". aWell <- KRASdata[["E03"]] aWell <- setChannelNames(aWell) colnames(aWell) ## Perhaps we want to abbreviate the channel names. aWell <- setChannelNames(aWell, "Ch1", "Ch2") colnames(aWell) ## The same operator works for a list of data frames. krasWells <- KRASdata krasWells <- setChannelNames(krasWells, "Ch1", "Ch2") lapply(krasWells, colnames)[1:3]
Change the volume of droplets used in the ddPCR experiment.
setDropletVolume(volume = 0.00085)
setDropletVolume(volume = 0.00085)
volume |
The new volume of each droplet. Defaults to 0.00085, which is the default given by Bio-Rad. |
Sets the internal droplet volume.
Anthony Chiu, [email protected]
## Change the droplet volume. ddpcr$dropletVolume setDropletVolume(0.00091) ddpcr$dropletVolume
## Change the droplet volume. ddpcr$dropletVolume setDropletVolume(0.00091) ddpcr$dropletVolume
Stores modes used the in Shiny UI and internal defaults.
shinyVis
shinyVis
An object of class environment
of length 3.
An environment for storing Shiny variables.
A shiny app for interactive ddPCR droplet classification.
shinyVisApp()
shinyVisApp()
A Shiny application
Anthony Chiu, [email protected]
A Shiny server for interactive ddPCR droplet classification.
shinyVisServer(input, output, session)
shinyVisServer(input, output, session)
input |
Shiny input list. |
output |
Shiny output list. |
session |
Shiny session. |
A Shiny server.
Anthony Chiu, [email protected]
A Shiny UI for interactive ddPCR droplet classification.
shinyVisUI()
shinyVisUI()
A Shiny UI.
Anthony Chiu, [email protected]
Well names can be sorted according to the leading letter or the trailing digit.
sortDataFrame(df, sortByLetter = FALSE)
sortDataFrame(df, sortByLetter = FALSE)
df |
A data frame with row names of the form A01, A02, B01, etc. |
sortByLetter |
If |
The data frame df
with the rows sorted.
Anthony Chiu, [email protected]
## Sort a subset of the KRAScounts data frame. df <- KRAScounts[, c("Ratio", "FracAbun")] sortDataFrame(df=df, sortByLetter=FALSE) sortDataFrame(df=df, sortByLetter=TRUE)
## Sort a subset of the KRAScounts data frame. df <- KRAScounts[, c("Ratio", "FracAbun")] sortDataFrame(df=df, sortByLetter=FALSE) sortDataFrame(df=df, sortByLetter=TRUE)
Well names can be sorted according to the leading letter or the trailing digit.
sortWells(wellNames, sortByLetter)
sortWells(wellNames, sortByLetter)
wellNames |
The well names to sort. |
sortByLetter |
If |
The well names sorted.
Anthony Chiu, [email protected]
## Use the KRASdata dataset as an example. plate <- ddpcrPlate(wells=KRASdata) wellNames <- names(plate) ## Sample sorting. sortWells(wellNames=wellNames, sortByLetter=FALSE) sortWells(wellNames=wellNames, sortByLetter=TRUE)
## Use the KRASdata dataset as an example. plate <- ddpcrPlate(wells=KRASdata) wellNames <- names(plate) ## Sample sorting. sortWells(wellNames=wellNames, sortByLetter=FALSE) sortWells(wellNames=wellNames, sortByLetter=TRUE)
textInputs
.By default, textInput
objects are added to the page
below each other. This function allows for inline textInput
fields.
textInputRow(inputId, label, value = "", size = NULL)
textInputRow(inputId, label, value = "", size = NULL)
inputId |
The identifier for the textInput object. |
label |
The text label to display alongside. |
value |
The default value of the textInput. |
size |
The size (width) and maxlength. |
A div
with the appropriate label and input field.
Adapted from: http://stackoverflow.com/a/21132918/1262569
Classify droplets as "NN", "NP", "PN" or "PP" depending on whether they lie above or below given thresholds. This is illustrated in the details and parameters for more detail.
thresholdClassify(droplets, ch1Threshold = 6500, ch2Threshold = 2900, ...) ## S4 method for signature 'data.frame' thresholdClassify( droplets, ch1Threshold = 6500, ch2Threshold = 2900, fullTable = TRUE ) ## S4 method for signature 'ddpcrWell' thresholdClassify( droplets, ch1Threshold = 6500, ch2Threshold = 2900, classMethodLabel = "thresholds" ) ## S4 method for signature 'ddpcrPlate' thresholdClassify( droplets, ch1Threshold = 6500, ch2Threshold = 2900, classMethodLabel = "thresholds" )
thresholdClassify(droplets, ch1Threshold = 6500, ch2Threshold = 2900, ...) ## S4 method for signature 'data.frame' thresholdClassify( droplets, ch1Threshold = 6500, ch2Threshold = 2900, fullTable = TRUE ) ## S4 method for signature 'ddpcrWell' thresholdClassify( droplets, ch1Threshold = 6500, ch2Threshold = 2900, classMethodLabel = "thresholds" ) ## S4 method for signature 'ddpcrPlate' thresholdClassify( droplets, ch1Threshold = 6500, ch2Threshold = 2900, classMethodLabel = "thresholds" )
droplets |
A |
ch1Threshold |
The channel 1 upper bound for the NN and NP classes. Defaults to 8000 |
ch2Threshold |
The channel 2 upper bound for the NN and PN classes. Defaults to 3000. |
... |
Other options depending on the type of |
fullTable |
Whether to return a data frame including amplitude figures.
If |
classMethodLabel |
A name (as a character string) of the classification method. Defaults to "thresholds". |
The threshold
parameters correspond to those in the
following diagram:
Ch1 ^ | | | | | | PN | PP | | | | a|__________|__________ | | | | | NN | NP | | | | ---------------------> b Ch2
Specifically:
ch1Threshold
,
ch2Threshold
.
If droplets
is a data frame, return a data frame or factor
(depending on the trainingData
and fullTable
parameters) with
a classification for droplets in the chosen regions.
If droplets
is a ddpcrWell
object, return
a ddpcrWell
object with the appropriate classification.
If droplets
is a ddpcrPlate
object, return
a ddpcrPlate
object with the appropriate classification.
Anthony Chiu, [email protected]
This function is a special case of gridClassify
.
## Use thresholds to set a classification for a data frame. gCl <- thresholdClassify(KRASdata[["E03"]], ch1Threshold=6789, ch2Threshold=3000) str(gCl) ## The same works for ddpcrWell objects. aWell <- ddpcrWell(well=KRASdata[["E03"]]) aWell <- thresholdClassify(aWell, ch1Threshold=6789, ch2Threshold=3000) str(aWell) ## ddpcrPlate objects work in exactly the same way. krasPlate <- ddpcrPlate(wells=KRASdata) krasPlate <- thresholdClassify(krasPlate, ch1Threshold=6789, ch2Threshold=3000) lapply(plateClassification(krasPlate, withAmplitudes=TRUE), head, n=1) ## The default classification method (column name) is 'threshold'. It can be ## changed by providing a label. krasPlate <- ddpcrPlate(wells=KRASdata) krasPlate <- thresholdClassify(krasPlate, ch1Threshold=6789, ch2Threshold=3000, classMethodLabel="manual") lapply(plateClassification(krasPlate, withAmplitudes=TRUE), head, n=1)
## Use thresholds to set a classification for a data frame. gCl <- thresholdClassify(KRASdata[["E03"]], ch1Threshold=6789, ch2Threshold=3000) str(gCl) ## The same works for ddpcrWell objects. aWell <- ddpcrWell(well=KRASdata[["E03"]]) aWell <- thresholdClassify(aWell, ch1Threshold=6789, ch2Threshold=3000) str(aWell) ## ddpcrPlate objects work in exactly the same way. krasPlate <- ddpcrPlate(wells=KRASdata) krasPlate <- thresholdClassify(krasPlate, ch1Threshold=6789, ch2Threshold=3000) lapply(plateClassification(krasPlate, withAmplitudes=TRUE), head, n=1) ## The default classification method (column name) is 'threshold'. It can be ## changed by providing a label. krasPlate <- ddpcrPlate(wells=KRASdata) krasPlate <- thresholdClassify(krasPlate, ch1Threshold=6789, ch2Threshold=3000, classMethodLabel="manual") lapply(plateClassification(krasPlate, withAmplitudes=TRUE), head, n=1)
Retrieve the classification from a ddpcrWell
object.
wellClassification(theObject, cMethod = NULL, withAmplitudes = FALSE) ## S4 method for signature 'ddpcrWell' wellClassification(theObject, cMethod = NULL, withAmplitudes = FALSE) wellClassification(theObject, cMethod) <- value ## S4 replacement method for signature 'ddpcrWell' wellClassification(theObject, cMethod) <- value
wellClassification(theObject, cMethod = NULL, withAmplitudes = FALSE) ## S4 method for signature 'ddpcrWell' wellClassification(theObject, cMethod = NULL, withAmplitudes = FALSE) wellClassification(theObject, cMethod) <- value ## S4 replacement method for signature 'ddpcrWell' wellClassification(theObject, cMethod) <- value
theObject |
A |
cMethod |
The names (or column numbers) of the classification to
retrieve. If |
withAmplitudes |
Logical value. If |
value |
A factor with the same length as the number of droplets in
|
A factor or data frame corresponding to the requested classification(s).
Anthony Chiu, [email protected]
wellClassificationMethod
for the name of the
classification method.
## Take some droplets with a given classification. amplitudes <- KRASdata[["E03"]][, c("Ch1.Amplitude", "Ch2.Amplitude")] ## Create a ddpcrWell object with the amplitudes only. aWell <- ddpcrWell(well=amplitudes) ## This has no classification yet. head(wellClassification(aWell)) ## We check the classification now, showing the amplitudes as well. head(wellClassification(aWell, withAmplitudes=TRUE)) ## Now set a sample classification. wellClassification(aWell, cMethod="Sample") <- rep(c("NN", "NP", "PN", "PP"), numDroplets(aWell) / 4) head(wellClassification(aWell, withAmplitudes=TRUE))
## Take some droplets with a given classification. amplitudes <- KRASdata[["E03"]][, c("Ch1.Amplitude", "Ch2.Amplitude")] ## Create a ddpcrWell object with the amplitudes only. aWell <- ddpcrWell(well=amplitudes) ## This has no classification yet. head(wellClassification(aWell)) ## We check the classification now, showing the amplitudes as well. head(wellClassification(aWell, withAmplitudes=TRUE)) ## Now set a sample classification. wellClassification(aWell, cMethod="Sample") <- rep(c("NN", "NP", "PN", "PP"), numDroplets(aWell) / 4) head(wellClassification(aWell, withAmplitudes=TRUE))
Retrieve the names of the classification methods for
a ddpcrWell
object.
wellClassificationMethod(theObject) ## S4 method for signature 'ddpcrWell' wellClassificationMethod(theObject) wellClassificationMethod(theObject, cMethod) <- value ## S4 replacement method for signature 'ddpcrWell' wellClassificationMethod(theObject, cMethod) <- value
wellClassificationMethod(theObject) ## S4 method for signature 'ddpcrWell' wellClassificationMethod(theObject) wellClassificationMethod(theObject, cMethod) <- value ## S4 replacement method for signature 'ddpcrWell' wellClassificationMethod(theObject, cMethod) <- value
theObject |
A |
cMethod |
If modifying the classification methods, this should be a vector of existing classification names or numbers. |
value |
A character vector (of the same length as |
The classification method names.
Anthony Chiu, [email protected]
wellClassification
for the classification of the
droplets.
## Create a ddpcrWell object with some data and classification. aWell <- ddpcrWell(well=KRASdata[["E03"]]) ## Retrieve the classification method names. head(wellClassificationMethod(aWell)) ## Set a classification method name to something new. wellClassificationMethod(aWell, cMethod="Cluster") <- "QuantaSoft" ## We check the classification now, showing the amplitudes as well. wellClassificationMethod(aWell)
## Create a ddpcrWell object with some data and classification. aWell <- ddpcrWell(well=KRASdata[["E03"]]) ## Retrieve the classification method names. head(wellClassificationMethod(aWell)) ## Set a classification method name to something new. wellClassificationMethod(aWell, cMethod="Cluster") <- "QuantaSoft" ## We check the classification now, showing the amplitudes as well. wellClassificationMethod(aWell)
The default ggplot
theme has a grey background. This
layer can be added to change the aesthetics.
whiteTheme(legendPosition = "right", legendJustification = "center")
whiteTheme(legendPosition = "right", legendJustification = "center")
legendPosition |
Where to position the legend. This can be "none",
"left", "right", "bottom", "top" or a numeric vector of length two. See the
documentation for |
legendJustification |
The justification to use for the legend positioning. This should be "center" or a two-element vector. Defaults to "center". |
A ggplot
theme layer.
Anthony Chiu, [email protected]
This function uses theme
.
## Get a data frame in the right format. aWell <- KRASdata[["E03"]] aWell$Cluster <- relabelClasses(aWell, classCol="Cluster") ## Plot it with the white theme. ggplot2::ggplot(aWell, ggplot2::aes(x=Ch2.Amplitude, y=Ch1.Amplitude)) + ggplot2::geom_point(ggplot2::aes(colour=Cluster)) + whiteTheme()
## Get a data frame in the right format. aWell <- KRASdata[["E03"]] aWell$Cluster <- relabelClasses(aWell, classCol="Cluster") ## Plot it with the white theme. ggplot2::ggplot(aWell, ggplot2::aes(x=Ch2.Amplitude, y=Ch1.Amplitude)) + ggplot2::geom_point(ggplot2::aes(colour=Cluster)) + whiteTheme()
Returns a data frame with the basic figures and the number of wild type copies per 20ul.
wildTypeCopiesSummary(df)
wildTypeCopiesSummary(df)
df |
A data frame generated by |
A data frame with the basic columns and wild type copies per 20ul.
Anthony Chiu, [email protected]
df <- fullCountsSummary(KRAScountsQS) wildTypeCopiesSummary(df)
df <- fullCountsSummary(KRAScountsQS) wildTypeCopiesSummary(df)