Description Usage Arguments Value Author(s) Examples
updateTSE
includes the analysis results to the rowData
of the
treeSummarizedExperiment object. The matrix-like elements of the
assays
, which has been used to do data analysis, will be specified in
the use.assays
of metadata
. The design matrix and contrast
vectors are also included in the metadata
.
1 |
result |
A list has the structure as |
tse |
A treeSummarizedExperiment object to be updated. |
use.assays |
A numeric vector. It specifies which matrix-like elements
in |
design |
A design matrix that is used in the analysis to get
|
contrast |
A list of contrast vectors that are used in the analysis to
get |
fit |
An optional argument. A object of
|
A treeSummarizedExperiment object.
assays |
A list of tables |
rowData |
It stores the information of rows in |
colData |
NULL |
metadata |
|
Ruizhu HUANG
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | library(edgeR)
library(S4Vectors)
set.seed(1)
y <- matrix(rnbinom(300,size=1,mu=10),nrow=10)
colnames(y) <- paste(rep(LETTERS[1:3], each = 10), rep(1:10,3), sep = "_")
rownames(y) <- tinyTree$tip.label
rowInf <- DataFrame(nodeLab = rownames(y),
var1 = sample(letters[1:3], 10, replace = TRUE),
var2 = sample(c(TRUE, FALSE), 10, replace = TRUE))
colInf <- DataFrame(gg = factor(sample(1:3, 30, replace = TRUE)),
group = rep(LETTERS[1:3], each = 10))
toy_lse <- leafSummarizedExperiment(tree = tinyTree, rowData = rowInf,
colData = colInf,
assays = list(y, (2*y), 3*y))
toy_tse <- nodeValue(data = toy_lse, fun = sum, tree = tinyTree,
message = TRUE)
# extract the abundace table
count <- assays(toy_tse, use.nodeLab = TRUE)[[1]]
# The sample size is the sum of cell counts of clusters on the leaf
# level of the tree.
tipCount <- assays(toy_tse[linkData(toy_tse)$isLeaf,],
use.nodeLab = TRUE)[[1]]
libSize <- apply(tipCount, 2, sum)
# create DGEList
y <- DGEList(counts = count, lib.size = libSize,
remove.zeros = FALSE)
# calculate normalisation factors
y <- calcNormFactors(object = y, method = "TMM")
# construct design matrix
sample_inf <- colData(toy_tse)
design <- model.matrix(~ gg + group, data = sample_inf)
# estimate dispersion
y <- estimateGLMRobustDisp(y, design = design)
# fit the negative binomial GLMs
fit <- glmFit(y, design = design, prior.count = 0.125)
# run likelihood ratio tests
# contrast
contrast1 <- c(0, 0, 0, -1, 1)
contrast2 <- c(0, -1, 1, 0, 0)
# contrast is not specified here, so the last coefficient is tested.
lrt1 <- glmLRT(fit, contrast = contrast1)
lrt2 <- glmLRT(fit, contrast = c (0, 0, 1, 0, 0))
# matC <- cbind(c(0, 1, 0, 0, 0), c(0, 0, 1, 0, 0))
# lrt3 <- glmLRT(fit, contrast = matC)
# extract table
tab1 <- topTags(lrt1, n = Inf, adjust.method = "BH", sort.by = "none")$table
tab2 <- topTags(lrt2, n = Inf, adjust.method = "BH", sort.by = "none")$table
#tab3 <- topTags(lrt3, n = Inf, adjust.method = "BH", sort.by = "none")$table
# put the analysis result in the toy_tse
contrastList <- list(contrastG1 = contrast1, contrastG2 = contrast2)
#,contrastG3 = matC)
# the analaysis is performed on the first table of assays
# add more elements if there are results from more tables of assays
res <- list(assay1 = list(contrastG1 = tab1, contrastG2 = tab2))
#, contrastG3 = tab3))
new_tse <- updateTSE(result = res, tse = toy_tse,
use.assays = 1, design = design, contrast = contrastList,
fit = fit)
# the results is added to a column called result_assay1
rowData(toy_tse)
rowData(new_tse)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.