updateTSE: update the treeSummarizedExperiment object

Description Usage Arguments Value Author(s) Examples

Description

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.

Usage

1
updateTSE(result, tse, use.assays, design, contrast, fit = NULL)

Arguments

result

A list has the structure as list(A = list(a1, a2, ...), B = list(b1, b2, ...)). The sub-elements, e.g., a1, is a data frame that is output from the data analysis. The sub-elements,a1, a2, ..., are obtained by performing analysis on the same matrix-like element of assays with different contrasts. b1 and a1 are obtained by perfoming analysis on different matrix-like element (A and B, respectively) of assays with the same contrast. In summary, results from the same assay element with different contrasts are stored in a list. They are named according to their contrasts; Results from different assay elements are further organized in a list. They are named with “assay” followed by the number that the element is in the assays

tse

A treeSummarizedExperiment object to be updated.

use.assays

A numeric vector. It specifies which matrix-like elements in assays have been used for the analysis to get result. The order should match with the order of results (A and B in the example structure)

design

A design matrix that is used in the analysis to get result.

contrast

A list of contrast vectors that are used in the analysis to get result. The order should match with the subelements of the results, like a1, a2, ..., in the example structure.

fit

An optional argument. A object of DGEGLM-class that is the output of glmFit. Default is NULL.

Value

A treeSummarizedExperiment object.

assays

A list of tables

rowData

It stores the information of rows in assays, and the result tables obtained in the data analysis. The later is stored as the internal part of the rowData. More details or example could be found in the vignette Example of data analysis

colData

NULL

metadata
  • use.assays which elements in the assays have been used to run differential abundance analysis.

  • design the design matrix as input.

  • contrast the contrast vector as input.

Author(s)

Ruizhu HUANG

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
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)

markrobinsonuzh/treeAGG documentation built on May 26, 2019, 9:32 a.m.