DE_timepoints {moanin} | R Documentation |
Fit weekly differential expression analysis
Creates pairwise contrasts for all timepoints
## 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") )
object |
An object of class |
contrasts |
Contrasts, either provided as a vector of strings, or a
matrix of contrasts coefficients obtained using
|
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
|
group2 |
Second group to consider in making contrasts, character value
that must match a value of the grouping variable contained in
|
type |
the type of contrasts that should be created. See details. |
timepoints |
vector of timepoints to compare. Must be contained in the
|
timepoints_before |
for |
timepoints_after |
for |
format |
the choice of "vector" (the default) for
|
By default the formula fitted for each gene is
~ 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
~ 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:
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
:
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:
"per_timepoint_group_diff"Contrasts that compare the groups within a timepoint
"per_group_timepoint_diff"Contrasts that compare two timepoints within a group
"group_and_timepoint_diff"Contrasts that compare the
difference between two timepoints between two levels of the
group_variable
of the Moanin
object. These are contrasts in
the form (TP i - TP (i-1))[Group1] - (TP i - TP (i-1))[Group2].
create_timepoints_contrasts
: a character vector with each
element of the vector corresponding to a contrast to be compared.
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)