groups_to_sedesign | R Documentation |
Create SEDesign from experimental groups
groups_to_sedesign(
ifactors,
group_colnames = NULL,
isamples = NULL,
idesign = NULL,
factor_order = NULL,
omit_grep = "[-,]",
max_depth = 2,
factor_sep = "_",
contrast_sep = "-",
remove_pairs = NULL,
pre_control_terms = NULL,
add_contrastdf = NULL,
contrast_names = NULL,
current_depth = 1,
rename_first_depth = TRUE,
return_sedesign = TRUE,
default_order = c("asis", "sort_samples", "mixedSort"),
verbose = FALSE,
...
)
ifactors |
|
group_colnames |
|
isamples |
|
idesign |
|
factor_order |
|
omit_grep |
|
max_depth |
|
factor_sep |
|
contrast_sep |
|
remove_pairs |
|
pre_control_terms |
|
add_contrastdf |
|
contrast_names |
|
current_depth |
|
rename_first_depth |
|
return_sedesign |
|
verbose |
|
... |
additional arguments are ignored. |
make_unique |
|
This function creates SEDesign
with appropriate design
and contrasts, based upon experimental groups.
This approach will use multiple experimental factors
to create appropriate one-way and n-way contrasts,
where each contrast represents a symmetric comparison
of each independent factor.
Input can be provided in one of two ways:
SummarizedExperiment
where experiment design is derived from
SummarizedExperiment::colData()
of the se
object, and
uses columns defined by group_colnames
. This input should be
equivalent to providing a data.frame
whose rownames()
are
equal to colnames(se)
.
data.frame
where each column represents a design factor.
An example of data.frame
input:
ifactors <- data.frame( treatment=c("Control", "Control", "Treated", "Treated"), genotype=c("Wildtype", "Knockout", "Wildtype", "Knockout"))
character
vector, where design factor levels are separated
by a delimiter such as underscore "_"
. This input will be
converted to data.frame
before processing.
An example of character
input:
ifactors <- c( "Control_Wildtype", "Control_Knockout", "Treated_Wildtype", "Treated_Knockout")
When rownames are provided in the data.frame
, or names
are provided with a character
vector, they are retained
and used as sample identifiers.
Note:
This function will change any "-"
in a factor name to
"."
prior to detecting valid contrasts, in order to
prevent confusion and potential problems using the
contrast names in downstream analyses.
This step does not call base::make.names()
, so that
step should be run beforehand if required.
When this function returns no contrasts, or returns an unexpected
error during processing, it is most likely due to the limitation
of comparing one factor at a time. For example, the logic will
not define contrast time1_treatment1-time2_treatment2
, because
this contrast changes two factors, it will only permit either
time1_treatment1-time1_treatment2
or time1_treatment1-time2_treatment1
.
max_depth
and factor_order
are used to define the order in
which factors are compared, but do not affect the order of factors
used for things like group names.
SEDesign
object with the following slots:
design
: numeric
matrix with sample-to-group association
contrasts
: numeric
matrix with group-to-contrast association
samples
: character
vector that represents individual sample
replicates, equivalent to rownames()
of the design
matrix.
Other jam experiment design:
check_sedesign()
,
contrast2comp()
,
contrast_colors_by_group()
,
contrast_names_to_sedesign()
,
contrasts_to_factors()
,
contrasts_to_venn_setlists()
,
draw_oneway_contrast()
,
draw_twoway_contrast()
,
filter_contrast_names()
,
plot_sedesign()
,
sedesign_to_factors()
,
validate_sedesign()
# first define a vector of sample groups
igroups <- jamba::nameVector(paste(rep(c("WT", "KO"), each=6),
rep(c("Control", "Treated"), each=3),
sep="_"),
suffix="_rep");
igroups <- factor(igroups, levels=unique(igroups));
igroups;
sedesign <- groups_to_sedesign(igroups);
design(sedesign);
contrasts(sedesign);
# plot the design and contrasts
plot_sedesign(sedesign)
# the two-way contrasts can be visibly flipped, since they are equivalent
plot_sedesign(sedesign, flip_twoway=TRUE)
# the design can be subset by sample
all_samples <- samples(sedesign)
subset_samples1 <- all_samples[-1:-3];
plot_sedesign(sedesign[subset_samples1, ])
# the group n=# replicates are updated
subset_samples2 <- all_samples[c(-1, -6, -11)];
plot_sedesign(sedesign[subset_samples2, ])
# The design * contrast matrix can be displayed in full
design(sedesign) %*% contrasts(sedesign);
# make "KO" the control term instead of "WT"
contrast_names(groups_to_sedesign(igroups, pre_control_terms=c("KO")))
# change the order of factors compared
contrast_names(groups_to_sedesign(igroups, factor_order=2:1))
# prevent comparisons of WT to WT, or KO to KO
sedesign_2 <- groups_to_sedesign(as.character(igroups),
remove_pairs=list(c("WT"), c("KO")))
contrast_names(sedesign_2)
plot_sedesign(sedesign_2)
# prevent comparisons of Treated to Treated, or Control to Control
sedesign_3 <- groups_to_sedesign(as.character(igroups),
remove_pairs=list(c("Treated"), c("Control")))
contrast_names(sedesign_3)
plot_sedesign(sedesign_3)
# input as a data.frame with ordered factor levels
ifactors <- data.frame(Genotype=factor(c("WT","WT","KO","KO"),
levels=c("WT","KO")),
Treatment=factor(c("Treated","Control"),
levels=c("Control","Treated")))
# not necessary, but define rownames
rownames(ifactors) <- jamba::pasteByRow(ifactors);
ifactors;
contrast_names(groups_to_sedesign(ifactors))
plot_sedesign(groups_to_sedesign(ifactors))
# you can still override factor levels with pre_control_terms
plot_sedesign(groups_to_sedesign(ifactors, pre_control_terms=c("KO")))
# input as design matrix
design_matrix <- design(groups_to_sedesign(ifactors))
design_matrix
contrast_names(groups_to_sedesign(design_matrix))
# again the "KO" group can be the control by using pre_control_terms
contrast_names(groups_to_sedesign(design_matrix, pre_control_terms="KO"))
# default_order="asis"
# contrasts show A-B, because B appears fist
# contrasts show Untreated-Treated because Treated appears first
df_test <- data.frame(
set=c("B", "B", "A", "A"),
treat=c("Treated", "Untreated"))
plot_sedesign(groups_to_sedesign(df_test))
plot_sedesign(groups_to_sedesign(jamba::pasteByRow(df_test)))
# default_order="sort_samples"
# contrasts show B-A, because A is sorted first
# contrasts show Treated-Untreated because sort_samples()
# determines "Untreated" is a preferred control term
plot_sedesign(groups_to_sedesign(df_test,
default_order="sort_samples"))
# default_order="mixedSort"
# contrasts show B-A, because A is sorted first
# contrasts show Untreated-Treated because Treated is sorted first
plot_sedesign(groups_to_sedesign(df_test,
default_order="mixedSort"))
plot_sedesign(groups_to_sedesign(df_test,
default_order="mixedSort",
pre_control_terms=c("Untreated")))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.