gridClassify {twoddpcr} | R Documentation

## Use a 'grid' to create training data for classification algorithms.

### Description

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".

### Usage

    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)

### Arguments

`droplets` | A `ddpcrWell` object or a data frame of droplet amplitudes with columns `Ch1.Amplitude` and `Ch2.Amplitude`.
`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 `droplets`.
`trainingData` | Whether to use the output as training data. If `TRUE`, returns the _full table_ with the "N/A" entries removed; if `FALSE`, the "N/A" entries are retained. Taken to be `FALSE` if `fullTable` is set to `FALSE`. Defaults to `TRUE`. Ignored if `droplets` is not a data frame.
`fullTable` | Whether to return a data frame including amplitude figures. If `TRUE`, a data frame with columns `Ch1.Amplitude`, `Ch1.Amplitude` and `class` is returned. If `FALSE`, a factor with levels in `ddpcr$classesRain` is returned, where each entry corresponds to each row in `droplets` (and `trainingData` is automatically set to `FALSE`). Defaults to `TRUE`. Ignored if `droplets` is not a data frame.
`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".

### Details

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:

a:

  `ch1NNThreshold`,

b:

  `ch2NNThreshold`,

c:

  `ch1PNThreshold`,

d:

  `ch2PNThreshold`,

e:

  `ch1NPThreshold`,

f:

  `ch2NPThreshold`,

g:

  `ch1PPThreshold`,

h:

  `ch2PPThreshold`.

### Value

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.

### Author(s)

Anthony Chiu, anthony.chiu@cruk.manchester.ac.uk

### See Also

`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.

### Examples

    ## 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)

[Package twoddpcr version 1.6.0 Index]