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
|
library("edgeR")
target_list_file_to_DGEList = function(targetsFile, minSumTagCounts = 5) {
# format should be like so, including header:
# files group description
# fileA.txt grpA my grpA replicate
# fileB.txt grpB my grpB replicate
# ...
targets = read.delim(file=targetsFile, stringsAsFactors = FALSE)
d = readDGE(targets)
# only use those rows that have a minimum number of tags (min to be DE)
d = d[rowSums(d$counts) >= minSumTagCounts, ];
# reset library sizes
d$samples$lib.size = colSums(d$counts)
# run TMM normalization
d = calcNormFactors(d)
return(d)
}
edgeR_DE_analysis = function (DGEList, dispersion=0.1, FDR=0.05) {
de.tgw = exactTest(DGEList, dispersion=dispersion)
topTagCount = -1;
if (! is.null(de.tgw$table$p.value)) { # the old edgeR way (R-2.12 and earlier)
topTagCount = sum(de.tgw$table$p.value <= FDR);
}
else {
topTagCount = sum(de.tgw$table$PValue <= FDR); # the latest way of doing it.
}
toptgw = topTags(de.tgw, n = topTagCount);
detags_toptgw = toptgw$table[toptgw$table[,4] <= FDR,];
detags_names = rownames(detags_toptgw)
plotSmear(DGEList, de.tags=detags_names)
return(detags_toptgw); # table with entries of interest.
}
|