Skip to content

Differential expression analysis

Usage

diff_counts(
  moo,
  count_type = "filt",
  sub_count_type = NULL,
  sample_id_colname = NULL,
  feature_id_colname = NULL,
  samples_to_include = NULL,
  covariates_colnames = c("Group", "Batch"),
  contrast_colname = c("Group"),
  contrasts = c("B-A", "C-A", "B-C"),
  input_in_log_counts = FALSE,
  return_mean_and_sd = FALSE,
  return_normalized_counts = TRUE,
  voom_normalization_method = "quantile",
  print_plots = options::opt("print_plots"),
  save_plots = options::opt("save_plots"),
  plots_subdir = "diff"
)

Arguments

moo

multiOmicDataSet object (see create_multiOmicDataSet_from_dataframes())

count_type

the type of counts to use – must be a name in the counts slot (moo@counts)

sub_count_type

if count_type is a list, specify the sub count type within the list. (Default: NULL)

sample_id_colname

The column from the sample metadata containing the sample names. The names in this column must exactly match the names used as the sample column names of your input Counts Matrix. (Default: NULL - first column in the sample metadata will be used.)

feature_id_colname

The column from the counts dataa containing the Feature IDs (Usually Gene or Protein ID). This is usually the first column of your input Counts Matrix. Only columns of Text type from your input Counts Matrix will be available to select for this parameter. (Default: NULL - first column in the counts matrix will be used.)

samples_to_include

Which samples would you like to include? Usually, you will choose all sample columns, or you could choose to remove certain samples. Samples excluded here will be removed in this step and from further analysis downstream of this step. (Default: NULL - all sample IDs in moo@sample_meta will be used.)

covariates_colnames

Columns to be used as covariates in linear modeling. Must include column from "Contrast Variable". Most commonly your covariate will be group and batch (if you have different batches in your data).

contrast_colname

The column in the metadata that contains the group variables you wish to find differential expression between. Up to 2 columns (2-factor analysis) can be used.

contrasts

Specify each contrast in the format group1-group2, e.g. treated-control

input_in_log_counts

set this to TRUE if counts are already log2-transformed

return_mean_and_sd

if TRUE, return Mean and Standard Deviation of groups in addition to DEG estimates for contrast(s)

return_normalized_counts

if TRUE, return normalized counts for samples included in the limma model

voom_normalization_method

Normalization method to be applied to the logCPM values when using limma::voom

print_plots

Whether to print plots during analysis (Defaults to FALSE, overwritable using option 'moo_print_plots' or environment variable 'MOO_PRINT_PLOTS')

save_plots

Whether to save plots to files during analysis (Defaults to FALSE, overwritable using option 'moo_save_plots' or environment variable 'MOO_SAVE_PLOTS')

plots_subdir

subdirectory in where plots will be saved if save_plots is TRUE

Value

multiOmicDataSet with diff added to the analyses slot (i.e. moo@analyses$diff)

Examples

moo <- multiOmicDataSet(
  sample_metadata = as.data.frame(nidap_sample_metadata),
  anno_dat = data.frame(),
  counts_lst = list(
    "raw" = as.data.frame(nidap_raw_counts),
    "clean" = as.data.frame(nidap_clean_raw_counts),
    "filt" = as.data.frame(nidap_filtered_counts)
  )
) %>%
  diff_counts(
    count_type = "filt",
    sub_count_type = NULL,
    sample_id_colname = "Sample",
    feature_id_colname = "Gene",
    covariates_colnames = c("Group", "Batch"),
    contrast_colname = c("Group"),
    contrasts = c("B-A", "C-A", "B-C"),
    voom_normalization_method = "quantile",
  )
#> * differential counts
#> Setting first column of `counts` as gene annotation.
#> Total number of genes included: 7943
head(moo@analyses$diff)
#>            Gene    B-A_FC    C-A_FC    B-C_FC   B-A_logFC   C-A_logFC
#> 1 0610007P14Rik -1.026892  1.106240 -1.135989 -0.03828439  0.14566407
#> 2 0610009B22Rik -1.009168 -1.267764  1.256247 -0.01316628 -0.34228628
#> 3 0610010F05Rik  1.122161 -6.063562  6.804293  0.16627966 -2.60016562
#> 4 0610011F06Rik  1.179418  1.357548 -1.151032  0.23807481  0.44100333
#> 5 0610012G03Rik -1.180719  1.051413 -1.241423 -0.23966515  0.07232912
#> 6 0610037L13Rik -1.422360 -1.429566  1.005067 -0.50828657 -0.51557755
#>      B-C_logFC   B-A_tstat  C-A_tstat   B-C_tstat  B-A_pval    C-A_pval
#> 1 -0.183948458 -0.11239064  0.4619930 -0.58386927 0.9124155 0.652543422
#> 2  0.329120003 -0.01744031 -0.4779059  0.42923631 0.9863787 0.641505931
#> 3  2.766445272  0.29807039 -3.0878622  3.11529979 0.7708668 0.009637891
#> 4 -0.202928519  0.43922204  0.8994597 -0.42166164 0.6684882 0.386513298
#> 5 -0.311994268 -0.37124882  0.1260545 -0.52269647 0.7170755 0.901825097
#> 6  0.007290977 -0.73372174 -0.7907409  0.01033402 0.4775382 0.444800236
#>      B-C_pval B-A_adjpval C-A_adjpval B-C_adjpval       A1       A2       A3
#> 1 0.570373641   0.9822240  0.82272260   0.8159825 6.532994 6.192871 5.954869
#> 2 0.675534876   0.9973532  0.81775923   0.8721628 4.484983 5.448875 5.286875
#> 3 0.009163897   0.9577678  0.07958189   0.1269944 4.883688 5.668494 6.537590
#> 4 0.680901716   0.9286117  0.62868219   0.8742464 5.199684 5.374085 5.112952
#> 5 0.610922936   0.9499111  0.95865237   0.8370657 5.368118 5.445918 5.456511
#> 6 0.991928593   0.8709056  0.67812827   0.9966969 5.327987 5.388747 5.233520
#>         B1       B2       B3       C1       C2       C3
#> 1 6.375896 6.275880 6.119449 6.419913 6.172204 6.497050
#> 2 3.445612 4.451347 5.473886 3.500359 4.709254 5.471951
#> 3 6.216408 5.893089 5.498884 3.845207 2.685177 2.805426
#> 4 5.155558 5.163359 5.650929 5.441965 6.043492 5.490958
#> 5 4.567138 5.274928 5.625039 5.787457 6.214163 4.682896
#> 6 5.450169 3.656585 4.929386 4.274944 4.744405 5.173531