add_contrast: Create a contrast for differential expression analysis

View source: R/sample_metadata.R

add_contrastR Documentation

Create a contrast for differential expression analysis

Description

Note that a MS-DAP contrast for "A vs B" will return foldchanges for B/A in downstream output tables and data visualizations. For example, for the contrast "control vs disease" a positive log2 foldchange implies protein abundances are higher in the "disease" sample group.

Throughout this function, all samples where the column "exclude" is set to TRUE are disregarded.

Usage

add_contrast(
  dataset,
  colname_condition_variable,
  values_condition1,
  values_condition2,
  colname_additional_variables = NULL
)

Arguments

dataset

your dataset. Make sure you've already imported sample metadata

colname_condition_variable

sample metadata column name that should be used for the experimental condition. Typically, this is the "group" column. Should be any of the values in user_provided_metadata(dataset$samples)

values_condition1

array of values from column colname_condition_variable that are the first group in the contrast. Note that

values_condition2

analogous to values_condition1, but for the second group. Note that you can set this to NA to indicate "everything except values in values_condition1"

colname_additional_variables

optionally, sample metadata column names that should be used as additional regression variables (only the subset of user_provided_metadata(dataset$samples), NOT including the value provided as parameter colname_condition_variable)

See Also

print_contrasts() to print an overview of defined contrasts, remove_contrasts() to remove all current contrasts (and respective filtering and DEA results)

Examples

## Not run: 
  # first, remove all existing contrasts (and their respecive DEA results)
  dataset = remove_contrasts(dataset)

  # Assume that column "group" in your sample metadata table specifies sample groups
  # The following example will create the contrast "WT vs KO"
  dataset = add_contrast(dataset, "group", "WT", "KO")

  # If the sample metadata table contains a column "batch" that should be used as
  # a regression variable (works for ebayes/deqms/msqrob), we can add it as follows:
  dataset = add_contrast(dataset, "group", "WT", "KO", colname_additional_variables = "batch")

  # Elaborate example; create a contrast while matching multiple values per group.
  # Testing all motor- and visual-cortex samples (described in the "brain_region"
  # column) against prefrontal cortex samples, with additional regression variables
  # batch and age.
  # In this example, the sample metadata table must contain columns
  # "brain_region", "batch", "age"
  dataset = add_contrast(
    dataset,
    # this parameter describes 1 column name in `dataset$samples`
    colname_condition_variable = "brain_region",
    # values in "brain_region" that are the first group in A/B testing
    values_condition1 = c("motor_cortex", "visual_cortex"),
    # analogous, but for the second group in A/B testing.
    # note that you may alternatively this to `NA` to indicate
    # "everything except values in values_condition1"
    values_condition2 = c("prefrontal_cortex"),
    # a vector/array of 0 or more column names in dataset$samples
    # that should be used as additional regression variables
    colname_additional_variables = c("batch", "age")
  )

  # Assume that the sample metadata table contains a column "group" with values
  # "A", "B", "C", "D". The following code will create the contrast "A vs B,C,D"
  # by setting the second set of values to `NA`
  dataset = add_contrast(
    dataset,
    colname_condition_variable = "group",
    values_condition1 = "A",
    values_condition2 = NA
  )

  ## The "group" column in the sample table is used for group definitions in
  ## "all group" filtering. We here create two contrasts based on different
  ## regression variables in the sample tabel.
  dataset = remove_contrasts(dataset) # optionally, remove previously defined contrasts
  dataset = add_contrast(
    dataset,
    colname_condition_variable = "genotype",
    values_condition1 = "control",
    values_condition2 = "knockout",
    colname_additional_variables = "batch"
  )
  dataset = add_contrast(
    dataset,
    colname_condition_variable = "genotype",
    values_condition1 = "control",
    values_condition2 = c("knockout", "mutant1"),
    # note that we have the flexibility to add different regression variables per contrast
    colname_additional_variables = "batch"
  )
  # print an overview of all contrasts
  print_contrasts(dataset)
  # apply typical MS-DAP pipeline
  dataset = analysis_quickstart(
    dataset,
    filter_min_detect = 0, ## if DDA, we might not require minimum MS/MS counts
    filter_min_quant = 3,
    filter_fraction_detect = 0,
    filter_fraction_quant = 0.75,
    filter_by_contrast = FALSE,      ## we only want filtering across all groups
    filter_min_peptide_per_prot = 2, ## 2 peptides per protein
    dea_algorithm = "deqms",
    norm_algorithm = c("vwmb", "modebetween_protein"),
    output_qc_report = TRUE,
    output_abundance_tables = TRUE,
    output_dir = "C:/temp",         ## you may set this to NA to skip the QC report
    output_within_timestamped_subdirectory = TRUE
  )

## End(Not run)

ftwkoopmans/msdap documentation built on March 5, 2025, 12:15 a.m.