Skip to contents

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 grandR
GetContrasts(
  x,
  contrast = "Condition",
  no4sU = FALSE,
  columns = NULL,
  group = NULL,
  name.format = NULL,
  ...
)

# S3 method for default
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)

Value

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

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

Examples

sars <- ReadGRAND(system.file("extdata", "sars.tsv.gz", package = "grandR"),
                  design=c("Condition","Time",Design$Replicate))
#> Warning: Duplicate gene symbols (n=1, e.g. MATR3) present, making unique!

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

# See the differential-expression vignette for more examples!