|
a |
|
b/voomDDA.train.R |
|
|
1 |
voomDDA.train = function (counts, conditions, normalization = c("TMM", "deseq", "none"), pooled.var = TRUE) |
|
|
2 |
{ |
|
|
3 |
normalization = match.arg(normalization) |
|
|
4 |
counts = data.matrix(counts) |
|
|
5 |
p = nrow(counts) |
|
|
6 |
n = ncol(counts) |
|
|
7 |
|
|
|
8 |
nclass = length(unique(conditions)) |
|
|
9 |
n.class = table(conditions) |
|
|
10 |
|
|
|
11 |
if (min(n.class) == 1) { |
|
|
12 |
stop(warning("Warning: a class contains only 1 sample")) |
|
|
13 |
} |
|
|
14 |
|
|
|
15 |
#### voom transformation steps |
|
|
16 |
{ |
|
|
17 |
if (normalization == "TMM"){ |
|
|
18 |
design = model.matrix(~conditions) |
|
|
19 |
rownames(design) = colnames(counts) |
|
|
20 |
dge = DGEList(counts = counts) |
|
|
21 |
dge = calcNormFactors(dge, method = "TMM") |
|
|
22 |
vm = voom(dge, design, plot=F) |
|
|
23 |
x = vm $ E #pxn dim gene expression matrix |
|
|
24 |
w = vm $ weights #pxn dim weight matrix |
|
|
25 |
dimnames(w) = dimnames(x) |
|
|
26 |
} |
|
|
27 |
else if (normalization == "deseq"){ |
|
|
28 |
design = model.matrix(~conditions) |
|
|
29 |
rownames(design) = colnames(counts) |
|
|
30 |
dge = DGEList(counts = counts) |
|
|
31 |
dge = calcNormFactors(dge, method = "RLE") |
|
|
32 |
vm = voom(dge, design, plot=F) |
|
|
33 |
x = vm $ E #pxn dim gene expression matrix |
|
|
34 |
w = vm $ weights #pxn dim weight matrix |
|
|
35 |
dimnames(w) = dimnames(x) |
|
|
36 |
} |
|
|
37 |
else { |
|
|
38 |
design = model.matrix(~conditions) |
|
|
39 |
rownames(design) = colnames(counts) |
|
|
40 |
vm = voom(counts, design, plot=F) |
|
|
41 |
x = vm $ E #pxn dim gene expression matrix |
|
|
42 |
w = vm $ weights #pxn dim weight matrix |
|
|
43 |
dimnames(w) = dimnames(x) |
|
|
44 |
} |
|
|
45 |
} |
|
|
46 |
|
|
|
47 |
if(is.factor(conditions)) classNames = levels(conditions) |
|
|
48 |
|
|
|
49 |
wStats = weighted.stats(x, w, conditions) |
|
|
50 |
|
|
|
51 |
results = structure(list(counts = counts, conditions = factor(conditions), weightedStats = wStats, normalization = normalization, |
|
|
52 |
nclass = nclass, classNames = classNames, PooledVar = pooled.var), class = "voomDDA") |
|
|
53 |
|
|
|
54 |
return(results) |
|
|
55 |
} |