DE_timepoints: Fit weekly differential expression analysis

Description Usage Arguments Details Value See Also Examples

Description

Fit weekly differential expression analysis

Creates pairwise contrasts for all timepoints

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
## S4 method for signature 'Moanin'
DE_timepoints(object, contrasts, add_factors = NULL, use_voom_weights = TRUE)

## S4 method for signature 'Moanin'
create_timepoints_contrasts(
  object,
  group1,
  group2 = NULL,
  type = c("per_timepoint_group_diff", "per_group_timepoint_diff",
    "group_and_timepoint_diff"),
  timepoints = sort(unique(time_variable(object))),
  timepoints_before = head(sort(timepoints), -1),
  timepoints_after = tail(sort(timepoints), -1),
  format = c("vector", "data.frame")
)

Arguments

object

An object of class Moanin, an object containing all related information for time course data and the splines model that will be used (if applicable). See create_moanin_model for more details.

contrasts

Contrasts, either provided as a vector of strings, or a matrix of contrasts coefficients obtained using makeContrasts from the package limma. If given as a character string, will be passed to makeContrasts to be converted into such a matrix.

add_factors

A character vector of additional variables to add to the design. See details.

use_voom_weights

boolean, optional, default: TRUE. Whether to use voom weights. See details.

group1

First group to consider in making contrasts, character value that must match a value of the grouping variable contained in moanin_model.

group2

Second group to consider in making contrasts, character value that must match a value of the grouping variable contained in moanin_model, unless type=="per_group_timepoint_diff", in which case should be NULL (only group1 is used in comparison)

type

the type of contrasts that should be created. See details.

timepoints

vector of timepoints to compare. Must be contained in the time_variable of the moanin object.

timepoints_before

for type equal to "per_group_timepoint_diff" or, "group_and_timepoint_diff", the set of timepoints to compare, see details. By default, taken from the timepoints variable.

timepoints_after

for type equal to "per_group_timepoint_diff" or, "group_and_timepoint_diff", the set of timepoints to compare, see details. By default, taken from the timepoints variable.

format

the choice of "vector" (the default) for create_timepoints_contrasts returns just the character vector of contrasts. If instead format="data.frame" then a data.frame is return that identifies the timepoint and group comparisons involved in each contrast. If this is the desired output, then the input to DE_timepoints should be the column corresponding to the contrast. See examples.

Details

By default the formula fitted for each gene is

1
2
   
   ~ Group*Timepoint +0

If the user gives values to add_factors, then the vector of character values given in add_factors will be added to the default formula. So that add_factors="Replicate" will change the formula to

1
2
   
   ~ Group*Timepoint +0 + Replicate

This allows for a small amount of additional complexity to control for other variables. Users should work directly with limma for more complex models.

If use_voom_weights=TRUE, the data is given directly to limma via assay(object). The specific series of calls is:

1
2
3
4
5
6
   
   y <- edgeR::DGEList(counts=assay(object))
   y <- edgeR::calcNormFactors(y, method="upperquartile")
   v <- limma::voom(y, design, plot=FALSE)
   v <- limma::lmFit(v) 
   

If the user set log_transform=TRUE in the creation of the Moanin object, this will not have an impact in the analysis if use_voom_weights=TRUE. Only if use_voom_weights=FALSE will this matter, in which case the log of the input data will be given to a regular call to limma:

1
2
   y<-get_log_data(object)
   v <- limma::lmFit(y, design)

create_timepoints_contrasts creates the needed contrasts for comparing groups or timepoints in the format needed for DE_timepoints (i.e. makeContrasts), to which the contrasts are ultimately passed. The time points and groups are determined by the levels of the grouping_variable and the values of time_variable in the moanin_object provided by the user.

Three different types of contrasts are created:

Value

create_timepoints_contrasts: a character vector with each element of the vector corresponding to a contrast to be compared.

See Also

makeContrasts

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
data(exampleData)
moanin <- create_moanin_model(data=testData, meta=testMeta)
# compare groups within each timepoint
contrasts <- create_timepoints_contrasts(moanin,"C", "K",
   type="per_timepoint_group_diff")
head(contrasts)
deTimepoints=DE_timepoints(moanin, 
    contrasts=contrasts, use_voom_weights=FALSE)
head(deTimepoints)
# Control for replicate variable:
deTimepoints=DE_timepoints(moanin, 
    contrasts=contrasts, add_factors="Replicate",
    use_voom_weights=FALSE)
head(deTimepoints)

# compare adjacent timepoints within each group
contrastsDiff <- create_timepoints_contrasts(moanin,"C",
   type="per_group_timepoint_diff")
deDiffTimepoints=DE_timepoints(moanin, 
    contrasts=contrastsDiff,
    use_voom_weights=FALSE)
# provide the sets of timepoints to compare:
contrastsDiff2<-create_timepoints_contrasts(moanin,"C",
   timepoints_before=c(72,120),timepoints_after=c(168,168),
   type="per_group_timepoint_diff")
deDiffTimepoints2=DE_timepoints(moanin, 
    contrasts=contrastsDiff2,
    use_voom_weights=FALSE)

# Compare selected timepoints across groups. 
# This time we also return format="data.frame" which helps us keep track of
# the meaning of each contrast. 
contrastsGroupDiff<-create_timepoints_contrasts(moanin,"C", "K",
   timepoints_before=c(72,120),timepoints_after=c(168,168),
   type="group_and_timepoint_diff",format="data.frame")
head(contrastsGroupDiff)
deGroupDiffTimepoints=DE_timepoints(moanin, 
    contrasts=contrastsGroupDiff$contrasts,
    use_voom_weights=FALSE)

NelleV/moanin documentation built on July 28, 2021, 7:34 p.m.