se_contrast_stats | R Documentation |
Compute contrast statistics on SummarizedExperiment data
se_contrast_stats(
se,
assay_names,
adjp_cutoff = 0.05,
p_cutoff = NULL,
fold_cutoff = 1.5,
int_adjp_cutoff = adjp_cutoff,
int_p_cutoff = p_cutoff,
int_fold_cutoff = fold_cutoff,
mgm_cutoff = NULL,
ave_cutoff = NULL,
confint = FALSE,
floor_min = NULL,
floor_value = NULL,
sedesign = NULL,
icontrasts = NULL,
idesign = NULL,
igenes = NULL,
isamples = NULL,
enforce_design = TRUE,
use_voom = FALSE,
voom_block_twostep = TRUE,
posthoc_test = c("none", "DEqMS"),
posthoc_args = list(DEqMS = list(PSM_counts = NULL, fit.method = "loess")),
weights = NULL,
robust = FALSE,
handle_na = c("full1", "full", "partial", "all", "none"),
na_value = 0,
rowData_colnames = c("SYMBOL"),
collapse_by_gene = FALSE,
block = NULL,
correlation = NULL,
max_correlation_rows = 10000,
normgroup = NULL,
do_normgroups = TRUE,
seed = 123,
verbose = FALSE,
...
)
se |
|
assay_names |
|
adjp_cutoff |
|
p_cutoff |
|
fold_cutoff |
|
int_adjp_cutoff , int_p_cutoff , int_fold_cutoff |
optional thresholds used only when a two-way interaction style contrast is detected. These optional thresholds may be useful to apply more lenient criteria to interaction contrasts, but in that event are cautioned to be used for data mining exercises. Ideally, the thresholds are identical between pairwise and interaction contrasts, and ideally there are enough replicates in the data to support the interaction contrasts with sufficient confidence to make those comparisons. |
mgm_cutoff |
|
ave_cutoff |
|
confint |
|
floor_min , floor_value |
|
sedesign |
|
icontrasts , idesign |
|
igenes |
|
isamples |
|
enforce_design |
|
use_voom |
|
voom_block_twostep |
|
posthoc_test |
|
posthoc_args |
|
weights |
|
robust |
|
handle_na |
|
na_value |
|
rowData_colnames |
|
collapse_by_gene |
|
block |
The argument can be supplied as one of the following:
|
correlation |
optional inter-duplicate or inter-technical
correlation matrix passed to |
max_correlation_rows |
|
normgroup |
The argument can be supplied as one of the following:
|
do_normgroups |
|
seed |
|
verbose |
|
... |
additional arguments are ignored. |
This function is essentially a wrapper around statistical methods
in the limma
package, with additional steps to apply statistical
thresholds to define "statistical hits" by three main criteria:
P-value or adjusted P-value
fold change
max group mean
This function is unique in that it applies the statistical methods
to one or more "signals" in the input SummarizedExperiment
assays,
specifically intended to compare things like normalization methods.
If multiple statistical thresholds are defined, each one is applied in order, which is specifically designed to compare the effect of applying different statistical thresholds. For example one may want to pre-compute "statistical hits" using adjusted P-value 0.05, and 0.01; or using fold change >= 1.5, or fold change >= 2.0. The underlying statistics are the same, but a column indicating hits is created for each set of thresholds.
Hits are annotated:
-1
for down-regulation
0
for un-changed (by the given criteria)
1
for up-regulation
The results are therefore intended to feed directional Venn diagrams, which display the overlapping gene hits, and whether the directions are shared or opposed.
This function can optionally apply the limma-voom workflow,
which involves calculating matrix weights using limma::voom()
,
then applying those weights during the model fit.
The output is intended to include several convenient formats:
stats_dfs
- list of data.frame
stats one per contrast
stats_df
- one data.frame
with all stats together
hit_array
- array
with three dimensions: signal; contrast; threshold
whose cells contain hit flags (-1, 0, 1) named by rownames(se)
.
Design and contrast matrices can be defined using the function
jamses::groups_to_sedesign()
. That function assigns each sample
to a sample group, then assembles all relevant group contrasts
which involve only one-factor contrast at a time. It optionally
defines two-factor contrasts (contrast of contrasts) where
applicable.
A subset of genes (rownames(se)
) or samples (colnames(se)
) can
be defined, to restrict calculations to use only the subset data.
Other jamses stats:
ebayes2dfs()
,
format_hits()
,
handle_na_values()
,
hit_array_to_list()
,
process_sestats_to_hitim()
,
run_limma_replicate()
,
save_sestats()
,
sestats_to_dfs()
,
sestats_to_df()
,
voom_jam()
set.seed(123)
expr <- rnorm(20) + 7;
noise <- rnorm(120) / 5;
fold <- rnorm(20) / 2.5;
m <- matrix(expr + noise, ncol=6);
for (i in 4:6) {
m[,i] <- m[,i] + fold;
}
# m <- matrix(rnorm(120)/2 + 5, ncol=6);
colnames(m) <- paste0(rep(c("Vehicle", "Treated"), each=3), 1:3)
rownames(m) <- paste0("row", seq_len(20))
# simulate some "hits"
m[1, 4:6] <- m[1, 4:6] + 2
m[2, 4:6] <- m[2, 4:6] + 1.5
m[3, 4:6] <- m[3, 4:6] - 1.3
# create SummarizedExperiment
se <- SummarizedExperiment::SummarizedExperiment(
assays=list(counts=m),
colData=data.frame(sample=colnames(m),
group=factor(rep(c("Vehicle", "Treated"), each=3),
c("Vehicle", "Treated"))),
rowData=data.frame(measurement=rownames(m)))
# assign colors
sample_color_list <- platjam::design2colors(se)
# heatmap
heatmap_se(se, sample_color_list=sample_color_list)
# create SEDesign
sedesign <- groups_to_sedesign(se, group_colnames="group")
# plot the design and contrasts
plot_sedesign(sedesign)
# limma contrasts
sestats <- se_contrast_stats(se=se,
sedesign=sedesign,
assay_names="counts")
# print data.frame summary of hits
sestats_to_df(sestats)
# plot the design with number of hits labeled
plot_sedesign(sedesign, sestats=sestats)
# heatmap with hits
heatmap_se(se,
sample_color_list=sample_color_list,
sestats=sestats)
# review stats table
stats_df <- sestats$stats_dfs$counts[["Treated-Vehicle"]]
head(stats_df)
# volcano plot for one contrast
jamma::volcano_plot(stats_df)
###############################
# simulate a two-way model
adjust <- rnorm(20);
new_fold <- rnorm(20);
se2 <- cbind(se, se)
groups2 <- paste0(rep(c("WT", "KO"), each=6),
"_",
SummarizedExperiment::colData(se)$group)
groups2 <- factor(groups2, levels=unique(groups2))
colnames(se2) <- paste0(groups2, 1:3)
SummarizedExperiment::colData(se2)$sample <- colnames(se2);
SummarizedExperiment::colData(se2)$group <- groups2;
SummarizedExperiment::colData(se2)$genotype <- jamba::gsubOrdered("_.+", "",
SummarizedExperiment::colData(se2)$group)
SummarizedExperiment::colData(se2)$treatment <- jamba::gsubOrdered("^.+_", "",
SummarizedExperiment::colData(se2)$group)
SummarizedExperiment::assays(se2)$counts[,7:12] <- (
SummarizedExperiment::assays(se2)$counts[,7:12] + adjust)
SummarizedExperiment::assays(se2)$counts[,10:12] <- (
SummarizedExperiment::assays(se2)$counts[,10:12] + new_fold)
# assign colors
sample_color_list2 <- platjam::design2colors(se2,
class_colnames="genotype",
color_sub=c(
Vehicle="palegoldenrod",
Treated="firebrick4"),
group_colnames="group")
# heatmap
hm2a <- heatmap_se(se2,
sample_color_list=sample_color_list2,
controlSamples=1:3,
center_label="versus WT_Vehicle",
column_title_rot=60,
row_cex=0.4,
column_cex=0.5,
column_title_gp=grid::gpar(fontsize=8),
column_split="group")
ComplexHeatmap::draw(hm2a, column_title=attr(hm2a, "hm_title"), merge_legends=TRUE)
# heatmap centered by genotype
hm2b <- heatmap_se(se2,
sample_color_list=sample_color_list2,
controlSamples=c(1:3, 7:9),
control_label="versus vehicle",
column_gap=grid::unit(c(1, 3, 1), "mm"),
centerby_colnames="genotype",
column_title_rot=60,
row_cex=0.4,
column_cex=0.5,
column_title_gp=grid::gpar(fontsize=8),
column_split="group")
ComplexHeatmap::draw(hm2b, column_title=attr(hm2b, "hm_title"), merge_legends=TRUE)
# create SEDesign
sedesign2 <- groups_to_sedesign(se2, group_colnames="group")
# plot the design and contrasts
plot_sedesign(sedesign2, label_cex=0.7)
# note the two-way contrast can be flipped
plot_sedesign(sedesign2, flip_twoway=TRUE, label_cex=0.7)
# limma contrasts
sestats2 <- se_contrast_stats(se=se2,
sedesign=sedesign2,
assay_names="counts")
# print data.frame summary of hits
sestats_to_df(sestats2)
# plot the design with number of hits labeled
plot_sedesign(sedesign2, sestats=sestats2, label_cex=0.7)
# heatmap with hits
hm2hits <- heatmap_se(se2,
sample_color_list=sample_color_list2,
sestats=sestats2,
controlSamples=c(1:3, 7:9),
column_gap=grid::unit(c(1, 3, 1), "mm"),
control_label="versus vehicle",
centerby_colnames="genotype",
row_split=3,
row_cex=0.4,
column_title_rot=60,
column_cex=0.5,
column_title_gp=grid::gpar(fontsize=8),
column_split="group")
ComplexHeatmap::draw(hm2hits,
column_title=attr(hm2hits, "hm_title"),
merge_legends=TRUE)
# venn diagram
hit_list <- hit_array_to_list(sestats2,
contrast_names=c(1:2))
jamba::sdim(hit_list);
# names(hit_list) <- gsub(":", ",<br>\n", contrast2comp(names(hit_list)))
# vo <- venndir::venndir(hit_list, expand_fraction=0.1)
# venndir::venndir_legender(venndir_out=vo, setlist=hit_list)
# vo <- venndir::venndir(hit_list, expand_fraction=0.1, proportional=TRUE)
# venndir::venndir_legender(venndir_out=vo, setlist=hit_list)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.