subset {opm}R Documentation

Select a subset of the plates (or time points)

Description

Select a subset of the plates in an OPMS object based on the content of the metadata. Alternatively, select a common subset of time points from all plates. thin_out keeps only a regular subset of the time points from OPM measurements. This is a mainly experimental function that might be of use in testing.

Usage

  ## S4 method for signature 'MOPMX'
subset(x, query, values = TRUE,
    invert = FALSE, exact = FALSE, time = FALSE, positive = "ignore",
    negative = "ignore", common = FALSE, use = "i", ...) 
  ## S4 method for signature 'OPMX'
subset(x, query, values = TRUE,
    invert = FALSE, exact = FALSE, time = FALSE,
    positive = c("ignore", "any", "all"),
    negative = c("ignore", "any", "all"),
    common = FALSE,
    use = c("i", "I", "k", "K", "n", "N", "p", "P", "q", "Q", "t", "T",
      "c", "C")) 

  ## S4 method for signature 'MOPMX'
thin_out(object, ...) 
  ## S4 method for signature 'OPM'
thin_out(object, factor, drop = FALSE) 
  ## S4 method for signature 'OPMS'
thin_out(object, ...) 

Arguments

x

OPMX or MOPMX object.

query

Logical or numeric vector or object accepted as query by the infix operators. If a logical or numeric vector, query is directly used as the first argument of [, and all following arguments, if any, are ignored. If otherwise, it is used for conducting a query based on one of the infix operators as described below.

values

Logical scalar. If TRUE, the values of query are also considered (by using infix.q or infix.largeq). If FALSE only the keys are considered (by using infix.k).

That is, choose either the plates for which certain metadata entries contain certain values, or choose the plates for which these metadata have been set at all (to some arbitrary value). See the mentioned functions for details, and note the special behaviour if query is a character vector and values is FALSE.

invert

Logical scalar. If TRUE, return the plates for which the condition is not TRUE.

exact

Logical scalar. If the values of query are considered, should this be done using infix.q (when FALSE) or infix.largeq (when TRUE)? See these functions and contains for details.

time

Logical scalar. If TRUE, all other arguments are ignored and the object is reduced to the common subset of time points (usually measurement hours and minutes).

positive

Character scalar. If ‘ignore’, not used. Otherwise all previous arguments except object are ignored, and the function yields an error unless object has been discretised throughout, i.e. either it is an OPMD object or all elements of object have discretised values.

If object has the necessary discretised values, if ‘any’, wells are selected that contain positive reactions in at least one plate. If ‘all’, wells are selected that contain positive reactions in all plates. Using invert means selecting all negative or weak reactions.

negative

Character scalar. Like positive, but returns the negative reactions. Using invert means selecting all positive or weak reactions.

common

Logical scalar. If TRUE, this causes query to be used to construct plate identifiers from the metadata; these plate identifiers are used to reduce a MOPMX object to the plates whose identifiers occur throughout all plate types. If applied to an OPMX object this means returning x unmodified.

use

Character scalar. An alternative way to specify the settings.

If ‘i’ or ‘I’, ignored. If ‘t’ or ‘T’, time is set to TRUE. If ‘p’ or ‘P’, positive is set to ‘any’ or ‘all’, respectively. If ‘n’ or ‘N’, negative is set to ‘any’ or ‘all’, respectively. If ‘c’ or ‘C’, common is set to TRUE.

Otherwise, use is taken directly as the one-latter name of the infix operators to use for plate selection, overriding values and exact.

object

OPMX object.

factor

Numeric scalar >= 1 indicating how much the data set shall be thinned out.

drop

Logical scalar. See [.

...

Optional arguments passed between the methods.

Details

The MOPMX method creates subsets of all contained OPMX objects (if any) in turn and then removes those that yielded NULL. Thus subset is not intended for directly creating subsets of MOPMX but of their elements to yield, e.g., elements that have a common set of metadata entries, as required under most circumstances by some other MOPMX methods such as extract.

Thinning the plates out is experimental insofar as it has not been tested whether and how this could sensibly be applied before aggregating the data.

Value

NULL or OPM or OPMS object. This depends on how many plates are selected; see [ for details. The MOPMX method always returns a MOPMX object.

See Also

base::'[' base::'[[' base::subset

Other getter-functions: aggr_settings, aggregated, anyDuplicated, anyNA, contains, csv_data, dim, disc_settings, discretized, duplicated, has_aggr, has_disc, hours, max, measurements, minmax, seq, well

Examples

# simple object comparison function
mustbe <- function(a, b) stopifnot(identical(a, b))

# all plates have that entry: selection identical to original object
mustbe(vaas_4, vaas_4["Species" %k% vaas_4, ])
mustbe(vaas_4, subset(vaas_4, list(Species = "Escherichia coli"),
  values = FALSE)) # equivalent
mustbe(vaas_4, subset(vaas_4, ~ Species == "Escherichia coli",
  values = FALSE)) # also equivalent

# two plates also have that value: yielding OPMS object with only two plates
mustbe(vaas_4[1:2], vaas_4[list(Species = "Escherichia coli") %q% vaas_4, ])
mustbe(vaas_4[1:2], subset(vaas_4, list(Species = "Escherichia coli")))
mustbe(vaas_4[1:2], subset(vaas_4, ~ Species == "Escherichia coli"))

# these are also equivalent
mustbe(vaas_4[c(1, 3)],
  vaas_4[list(Strain = c("DSM18039", "DSM1707")) %q% vaas_4])
mustbe(vaas_4[c(1, 3)],
  subset(vaas_4, list(Strain = c("DSM18039", "DSM1707"))))
mustbe(vaas_4[c(1, 3)],
  subset(vaas_4, ~ Strain %in% c("DSM18039", "DSM1707")))
mustbe(vaas_4[c(1, 3)],
  subset(vaas_4, ~ Strain == "DSM18039" || Strain == "DSM1707"))
# note that particularly formulae can be used to set up very complex queries

# select all plates that have aggregated values
dim(x <- subset(vaas_4, has_aggr(vaas_4)))
## [1]   4 384  96
mustbe(x, vaas_4) # all have such values

# select a common set of time points
dim(x <- subset(vaas_4, time = TRUE))
## [1]   4 384  96
mustbe(x, vaas_4) # the time points had already been identical
# create unequal time points
dim(copy <- vaas_4[, list(1:10, 1:20, 1:15, 1:10)])
## [1]  4 10 96
mustbe(hours(copy), c(2.25, 4.75, 3.50, 2.25))
# now restrict to common subset
dim(x <- subset(copy, time = TRUE))
## [1]  4 10 96
mustbe(hours(x), rep(2.25, 4))
# see also the example with split() given under "["

# select all wells that have positive reactions
dim(x <- subset(vaas_4, use = "p")) # in at least one plate
## [1]   4 384  77
stopifnot(dim(x)[3] < dim(vaas_4)[3])
dim(y <- subset(vaas_4, use = "P")) # in all plates
## [1]   4 384  27
stopifnot(dim(y)[3] < dim(x)[3])

# select all wells that have non-negative reactions in at least one plate
dim(y <- subset(vaas_4, use = "N", invert = TRUE))
## [1]   4 384  92
stopifnot(dim(y)[3] > dim(x)[3])

## thin_out()

# 'OPM' method
(x <- dim(vaas_1))
## [1] 384  96
stopifnot(identical(x, c(384L, 96L)))
copy <- thin_out(vaas_1, 10) # keep every 10th time point and measurement
(x <- dim(copy))
## [1] 38 96
stopifnot(identical(x, c(38L, 96L)), has_aggr(copy))
copy <- thin_out(vaas_1, 10, drop = TRUE) # also remove the parameters
(x <- dim(copy))
## [1] 38 96
stopifnot(identical(x, c(38L, 96L)), !has_aggr(copy))

# 'OPMS' method
(x <- dim(vaas_4))
## [1]   4 384  96
stopifnot(identical(x, c(4L, 384L, 96L)))
copy <- thin_out(vaas_4, 10)
(x <- dim(copy))
## [1]  4 38 96
stopifnot(identical(x, c(4L, 38L, 96L)))

[Package opm version 1.3.63 Index]