GetContrasts {grandR}R Documentation

Create a contrast matrix

Description

Each column of a contrast matrix represents a pairwise comparison of all samples or cells of a grandR object (or a column annotation table). Elements being 1 are contrasted vs. elements being -1 (and all 0 are irrelevant for this comparison).

Usage

GetContrasts(x, ...)

## S3 method for class 'grandR'
GetContrasts(
  x,
  contrast = "Condition",
  no4sU = FALSE,
  columns = NULL,
  group = NULL,
  name.format = NULL,
  ...
)

## Default S3 method:
GetContrasts(
  x,
  contrast,
  columns = NULL,
  group = NULL,
  name.format = NULL,
  ...
)

Arguments

x

A grandR object or a column annotation table

...

further arguments to be passed to or from other methods.

contrast

A vector describing what should be contrasted

no4sU

Use no4sU columns (TRUE) or not (FALSE)

columns

logical vector of which columns (samples or cells) to use (or NULL: use all); for grandR objects, see details

group

Split the samples or cells according to this column of the column annotation table (and adapt the of the output table)

name.format

Format string for generating the column from the contrast vector (see details)

Details

To compare one specific factor level A against another level B in a particular column COL of the column annotation table, specify contrast=c("COL","A","B")

To compare all levels against a specific level A in a particular column COL of the column annotation table, specify contrast=c("COL","A")

To perform all pairwise comparisons of all levels from a particular column COL of the column annotation table, specify contrast=c("COL")

If the column COL only has two levels, all three are equivalent.

In all cases, if groups is not NULL, the columns annotation table is first split and contrasts are applied within all samples or cells with the same group factor level.

The format string specifies the column name in the generated contrast matrix (which is used as the Analysis name when calling ApplyContrasts, LFC, PairwiseDESeq2, etc.). The keywords $GRP, $COL, $A and $B are substituted by the respective elements of the contrast vector or the group this comparison refers to. By default, it is "$A vs $B" if group is NULL, and "$A vs $B.$GRP" otherwise.

The method for grandR objects simply calls the general method

For grandR objects, columns can be given as a logical, integer or character vector representing a selection of the columns (samples or cells). The expression is evaluated in an environment having the Coldata, i.e. you can use names of Coldata as variables to conveniently build a logical vector (e.g., columns=Condition="x").

Value

A data frame representig a contrast matrix to be used in ApplyContrasts, LFC, PairwiseDESeq2

See Also

ApplyContrasts, LFC, PairwiseDESeq2

Examples

sars <- ReadGRAND(system.file("extdata", "sars.tsv.gz", package = "grandR"),
                  design=c("Condition","Time",Design$Replicate))

GetContrasts(sars,contrast="Condition")
# Compare all Mock vs. all SARS
GetContrasts(sars,contrast=c("Condition","SARS","Mock"))
# This direction of the comparison is more reasonable
GetContrasts(sars,contrast=c("Condition","SARS","Mock"),group="Time")
# Compare SARS vs Mock per time point
GetContrasts(sars,contrast=c("Time.original","no4sU"), group="Condition",no4sU=TRUE,
                                                name.format="$A vs $B ($GRP)")
# Compare each sample against the respective no4sU sample

# See the differential-expression vignette for more examples!

[Package grandR version 0.2.5 Index]