annotate diffexp.R @ 1:b2fe55fd0651 default tip

- Initial commit
author shian_su <registertonysu@gmail.com>
date Tue, 16 Dec 2014 14:41:34 +1100
parents 7a80e9ec63cb
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
1 # This tool takes in a matrix of feature counts as well as gene annotations and
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
2 # outputs a table of top expressions as well as various plots for differential
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
3 # expression analysis
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
4 #
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
5 # ARGS: 1.countPath -Path to RData input containing counts
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
6 # 2.annoPath -Path to RData input containing gene annotations
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
7 # 3.htmlPath -Path to html file linking to other outputs
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
8 # 4.outPath -Path to folder to write all output to
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
9 # 5.rdaOpt -String specifying if RData should be saved
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
10 # 6.normOpt -String specifying type of normalisation used
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
11 # 7.weightOpt -String specifying usage of weights
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
12 # 8.contrastData -String containing contrasts of interest
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
13 # 9.cpmReq -Float specifying cpm requirement
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
14 # 10.sampleReq -Integer specifying cpm requirement
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
15 # 11.pAdjOpt -String specifying the p-value adjustment method
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
16 # 12.pValReq -Float specifying the p-value requirement
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
17 # 13.lfcReq -Float specifying the log-fold-change requirement
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
18 # 14.factorData -String containing factor names and values
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
19 #
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
20 # OUT: Voom Plot
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
21 # BCV Plot
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
22 # MA Plot
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
23 # Top Expression Table
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
24 # HTML file linking to the ouputs
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
25 #
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
26 # Author: Shian Su - registertonysu@gmail.com - Jan 2014
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
27
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
28 # Record starting time
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
29 timeStart <- as.character(Sys.time())
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
30
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
31 # Load all required libraries
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
32 library(methods, quietly=TRUE, warn.conflicts=FALSE)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
33 library(statmod, quietly=TRUE, warn.conflicts=FALSE)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
34 library(splines, quietly=TRUE, warn.conflicts=FALSE)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
35 library(edgeR, quietly=TRUE, warn.conflicts=FALSE)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
36 library(limma, quietly=TRUE, warn.conflicts=FALSE)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
37 library(scales, quietly=TRUE, warn.conflicts=FALSE)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
38
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
39 if (packageVersion("limma") < "3.20.1") {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
40 stop("Please update 'limma' to version >= 3.20.1 to run this tool")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
41 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
42
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
43 ################################################################################
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
44 ### Function Delcaration
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
45 ################################################################################
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
46 # Function to sanitise contrast equations so there are no whitespaces
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
47 # surrounding the arithmetic operators, leading or trailing whitespace
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
48 sanitiseEquation <- function(equation) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
49 equation <- gsub(" *[+] *", "+", equation)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
50 equation <- gsub(" *[-] *", "-", equation)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
51 equation <- gsub(" *[/] *", "/", equation)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
52 equation <- gsub(" *[*] *", "*", equation)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
53 equation <- gsub("^\\s+|\\s+$", "", equation)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
54 return(equation)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
55 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
56
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
57 # Function to sanitise group information
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
58 sanitiseGroups <- function(string) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
59 string <- gsub(" *[,] *", ",", string)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
60 string <- gsub("^\\s+|\\s+$", "", string)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
61 return(string)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
62 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
63
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
64 # Function to change periods to whitespace in a string
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
65 unmake.names <- function(string) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
66 string <- gsub(".", " ", string, fixed=TRUE)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
67 return(string)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
68 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
69
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
70 # Generate output folder and paths
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
71 makeOut <- function(filename) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
72 return(paste0(outPath, "/", filename))
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
73 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
74
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
75 # Generating design information
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
76 pasteListName <- function(string) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
77 return(paste0("factors$", string))
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
78 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
79
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
80 # Create cata function: default path set, default seperator empty and appending
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
81 # true by default (Ripped straight from the cat function with altered argument
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
82 # defaults)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
83 cata <- function(..., file = htmlPath, sep = "", fill = FALSE, labels = NULL,
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
84 append = TRUE) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
85 if (is.character(file))
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
86 if (file == "")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
87 file <- stdout()
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
88 else if (substring(file, 1L, 1L) == "|") {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
89 file <- pipe(substring(file, 2L), "w")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
90 on.exit(close(file))
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
91 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
92 else {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
93 file <- file(file, ifelse(append, "a", "w"))
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
94 on.exit(close(file))
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
95 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
96 .Internal(cat(list(...), file, sep, fill, labels, append))
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
97 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
98
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
99 # Function to write code for html head and title
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
100 HtmlHead <- function(title) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
101 cata("<head>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
102 cata("<title>", title, "</title>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
103 cata("</head>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
104 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
105
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
106 # Function to write code for html links
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
107 HtmlLink <- function(address, label=address) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
108 cata("<a href=\"", address, "\" target=\"_blank\">", label, "</a><br />\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
109 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
110
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
111 # Function to write code for html images
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
112 HtmlImage <- function(source, label=source, height=600, width=600) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
113 cata("<img src=\"", source, "\" alt=\"", label, "\" height=\"", height)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
114 cata("\" width=\"", width, "\"/>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
115 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
116
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
117 # Function to write code for html list items
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
118 ListItem <- function(...) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
119 cata("<li>", ..., "</li>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
120 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
121
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
122 TableItem <- function(...) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
123 cata("<td>", ..., "</td>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
124 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
125
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
126 TableHeadItem <- function(...) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
127 cata("<th>", ..., "</th>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
128 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
129
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
130 ################################################################################
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
131 ### Input Processing
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
132 ################################################################################
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
133
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
134 # Collects arguments from command line
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
135 argv <- commandArgs(TRUE)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
136
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
137 # Grab arguments
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
138 countPath <- as.character(argv[1])
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
139 annoPath <- as.character(argv[2])
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
140 htmlPath <- as.character(argv[3])
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
141 outPath <- as.character(argv[4])
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
142 rdaOpt <- as.character(argv[5])
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
143 normOpt <- as.character(argv[6])
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
144 weightOpt <- as.character(argv[7])
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
145 contrastData <- as.character(argv[8])
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
146 cpmReq <- as.numeric(argv[9])
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
147 sampleReq <- as.numeric(argv[10])
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
148 pAdjOpt <- as.character(argv[11])
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
149 pValReq <- as.numeric(argv[12])
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
150 lfcReq <- as.numeric(argv[13])
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
151 factorData <- list()
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
152 for (i in 14:length(argv)) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
153 newFact <- unlist(strsplit(as.character(argv[i]), split="::"))
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
154 factorData <- rbind(factorData, newFact)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
155 } # Factors have the form: FACT_NAME::LEVEL,LEVEL,LEVEL,LEVEL,...
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
156
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
157 # Process arguments
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
158 if (weightOpt=="yes") {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
159 wantWeight <- TRUE
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
160 } else {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
161 wantWeight <- FALSE
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
162 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
163
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
164 if (rdaOpt=="yes") {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
165 wantRda <- TRUE
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
166 } else {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
167 wantRda <- FALSE
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
168 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
169
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
170 if (annoPath=="None") {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
171 haveAnno <- FALSE
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
172 } else {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
173 haveAnno <- TRUE
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
174 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
175
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
176 # Set the row names to be the name of the factor and delete first row
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
177 row.names(factorData) <- factorData[, 1]
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
178 factorData <- factorData[, -1]
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
179 factorData <- sapply(factorData, sanitiseGroups)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
180 factorData <- sapply(factorData, strsplit, split=",")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
181 factorData <- sapply(factorData, make.names)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
182
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
183 # Transform factor data into data frame of R factor objects
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
184 factors <- data.frame(factorData)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
185
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
186 #Create output directory
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
187 dir.create(outPath, showWarnings=FALSE)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
188
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
189 # Split up contrasts seperated by comma into a vector then sanitise
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
190 contrastData <- unlist(strsplit(contrastData, split=","))
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
191 contrastData <- sanitiseEquation(contrastData)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
192 contrastData <- gsub(" ", ".", contrastData, fixed=TRUE)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
193
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
194 bcvOutPdf <- makeOut("bcvplot.pdf")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
195 bcvOutPng <- makeOut("bcvplot.png")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
196 mdsOutPdf <- makeOut("mdsplot.pdf")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
197 mdsOutPng <- makeOut("mdsplot.png")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
198 voomOutPdf <- makeOut("voomplot.pdf")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
199 voomOutPng <- makeOut("voomplot.png")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
200 maOutPdf <- character() # Initialise character vector
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
201 maOutPng <- character()
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
202 topOut <- character()
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
203 for (i in 1:length(contrastData)) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
204 maOutPdf[i] <- makeOut(paste0("maplot(", contrastData[i], ").pdf"))
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
205 maOutPng[i] <- makeOut(paste0("maplot(", contrastData[i], ").png"))
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
206 topOut[i] <- makeOut(paste0("toptab(", contrastData[i], ").tsv"))
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
207 } # Save output paths for each contrast as vectors
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
208 rdaOut <- makeOut("RData.rda")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
209 sessionOut <- makeOut("session_info.txt")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
210
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
211 # Initialise data for html links and images, data frame with columns Label and
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
212 # Link
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
213 linkData <- data.frame(Label=character(), Link=character(),
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
214 stringsAsFactors=FALSE)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
215 imageData <- data.frame(Label=character(), Link=character(),
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
216 stringsAsFactors=FALSE)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
217
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
218 # Initialise vectors for storage of up/down/neutral regulated counts
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
219 upCount <- numeric()
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
220 downCount <- numeric()
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
221 flatCount <- numeric()
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
222
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
223 # Read in counts and geneanno data
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
224 counts <- read.table(countPath, header=TRUE, sep="\t")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
225 row.names(counts) <- counts$GeneID
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
226 counts <- counts[ , !(colnames(counts)=="GeneID")]
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
227 countsRows <- nrow(counts)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
228 if (haveAnno) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
229 geneanno <- read.table(annoPath, header=TRUE, sep="\t")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
230 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
231
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
232 ################################################################################
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
233 ### Data Processing
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
234 ################################################################################
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
235
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
236 # Extract counts and annotation data
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
237 data <- list()
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
238 data$counts <- counts
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
239 if (haveAnno) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
240 data$genes <- geneanno
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
241 } else {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
242 data$genes <- data.frame(GeneID=row.names(counts))
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
243 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
244
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
245 # Filter out genes that do not have a required cpm in a required number of
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
246 # samples
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
247 preFilterCount <- nrow(data$counts)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
248 sel <- rowSums(cpm(data$counts) > cpmReq) >= sampleReq
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
249 data$counts <- data$counts[sel, ]
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
250 data$genes <- data$genes[sel, ]
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
251 postFilterCount <- nrow(data$counts)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
252 filteredCount <- preFilterCount-postFilterCount
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
253
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
254 # Creating naming data
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
255 samplenames <- colnames(data$counts)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
256 sampleanno <- data.frame("sampleID"=samplenames, factors)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
257
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
258 # Generating the DGEList object "data"
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
259 data$samples <- sampleanno
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
260 data$samples$lib.size <- colSums(data$counts)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
261 data$samples$norm.factors <- 1
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
262 row.names(data$samples) <- colnames(data$counts)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
263 data <- new("DGEList", data)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
264
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
265 factorList <- sapply(names(factors), pasteListName)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
266 formula <- "~0"
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
267 for (i in 1:length(factorList)) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
268 formula <- paste(formula, factorList[i], sep="+")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
269 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
270 formula <- formula(formula)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
271 design <- model.matrix(formula)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
272 for (i in 1:length(factorList)) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
273 colnames(design) <- gsub(factorList[i], "", colnames(design), fixed=TRUE)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
274 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
275
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
276 # Calculating normalising factor, estimating dispersion
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
277 data <- calcNormFactors(data, method=normOpt)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
278 #data <- estimateDisp(data, design=design, robust=TRUE)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
279
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
280 # Generate contrasts information
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
281 contrasts <- makeContrasts(contrasts=contrastData, levels=design)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
282
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
283 # Name rows of factors according to their sample
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
284 row.names(factors) <- names(data$counts)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
285
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
286 ################################################################################
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
287 ### Data Output
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
288 ################################################################################
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
289
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
290 # BCV Plot
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
291 #png(bcvOutPng, width=600, height=600)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
292 #plotBCV(data, main="BCV Plot")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
293 #imageData[1, ] <- c("BCV Plot", "bcvplot.png")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
294 #invisible(dev.off())
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
295
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
296 #pdf(bcvOutPdf)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
297 #plotBCV(data, main="BCV Plot")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
298 #invisible(dev.off())
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
299
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
300 if (wantWeight) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
301 # Creating voom data object and plot
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
302 png(voomOutPng, width=1000, height=600)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
303 vData <- voomWithQualityWeights(data, design=design, plot=TRUE)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
304 imageData[1, ] <- c("Voom Plot", "voomplot.png")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
305 invisible(dev.off())
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
306
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
307 pdf(voomOutPdf, width=14)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
308 vData <- voomWithQualityWeights(data, design=design, plot=TRUE)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
309 linkData[1, ] <- c("Voom Plot (.pdf)", "voomplot.pdf")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
310 invisible(dev.off())
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
311
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
312 # Generating fit data and top table with weights
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
313 wts <- vData$weights
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
314 voomFit <- lmFit(vData, design, weights=wts)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
315
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
316 } else {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
317 # Creating voom data object and plot
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
318 png(voomOutPng, width=600, height=600)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
319 vData <- voom(data, design=design, plot=TRUE)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
320 imageData[1, ] <- c("Voom Plot", "voomplot.png")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
321 invisible(dev.off())
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
322
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
323 pdf(voomOutPdf)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
324 vData <- voom(data, design=design, plot=TRUE)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
325 linkData[1, ] <- c("Voom Plot (.pdf)", "voomplot.pdf")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
326 invisible(dev.off())
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
327
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
328 # Generate voom fit
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
329 voomFit <- lmFit(vData, design)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
330
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
331 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
332
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
333 # Fit linear model and estimate dispersion with eBayes
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
334 voomFit <- contrasts.fit(voomFit, contrasts)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
335 voomFit <- eBayes(voomFit)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
336
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
337 # Plot MDS
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
338 labels <- names(counts)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
339 png(mdsOutPng, width=600, height=600)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
340 # Currently only using a single factor
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
341 plotMDS(vData, labels=labels, col=as.numeric(factors[, 1]), cex=0.8)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
342 imgName <- "Voom Plot"
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
343 imgAddr <- "mdsplot.png"
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
344 imageData <- rbind(imageData, c(imgName, imgAddr))
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
345 invisible(dev.off())
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
346
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
347 pdf(mdsOutPdf)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
348 plotMDS(vData, labels=labels, cex=0.5)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
349 linkName <- paste0("MDS Plot (.pdf)")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
350 linkAddr <- paste0("mdsplot.pdf")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
351 linkData <- rbind(linkData, c(linkName, linkAddr))
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
352 invisible(dev.off())
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
353
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
354
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
355 for (i in 1:length(contrastData)) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
356
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
357 status = decideTests(voomFit[, i], adjust.method=pAdjOpt, p.value=pValReq,
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
358 lfc=lfcReq)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
359
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
360 sumStatus <- summary(status)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
361
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
362 # Collect counts for differential expression
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
363 upCount[i] <- sumStatus["1",]
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
364 downCount[i] <- sumStatus["-1",]
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
365 flatCount[i] <- sumStatus["0",]
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
366
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
367 # Write top expressions table
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
368 top <- topTable(voomFit, coef=i, number=Inf, sort.by="P")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
369 write.table(top, file=topOut[i], row.names=FALSE, sep="\t")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
370
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
371 linkName <- paste0("Top Differential Expressions(", contrastData[i],
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
372 ") (.tsv)")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
373 linkAddr <- paste0("toptab(", contrastData[i], ").tsv")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
374 linkData <- rbind(linkData, c(linkName, linkAddr))
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
375
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
376 # Plot MA (log ratios vs mean average) using limma package on weighted data
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
377 pdf(maOutPdf[i])
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
378 limma::plotMA(voomFit, status=status, coef=i,
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
379 main=paste("MA Plot:", unmake.names(contrastData[i])),
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
380 col=alpha(c("firebrick", "blue"), 0.4), values=c("1", "-1"),
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
381 xlab="Average Expression", ylab="logFC")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
382
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
383 abline(h=0, col="grey", lty=2)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
384
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
385 linkName <- paste0("MA Plot(", contrastData[i], ")", " (.pdf)")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
386 linkAddr <- paste0("maplot(", contrastData[i], ").pdf")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
387 linkData <- rbind(linkData, c(linkName, linkAddr))
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
388 invisible(dev.off())
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
389
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
390 png(maOutPng[i], height=600, width=600)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
391 limma::plotMA(voomFit, status=status, coef=i,
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
392 main=paste("MA Plot:", unmake.names(contrastData[i])),
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
393 col=alpha(c("firebrick", "blue"), 0.4), values=c("1", "-1"),
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
394 xlab="Average Expression", ylab="logFC")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
395
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
396 abline(h=0, col="grey", lty=2)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
397
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
398 imgName <- paste0("MA Plot(", contrastData[i], ")")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
399 imgAddr <- paste0("maplot(", contrastData[i], ").png")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
400 imageData <- rbind(imageData, c(imgName, imgAddr))
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
401 invisible(dev.off())
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
402 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
403 sigDiff <- data.frame(Up=upCount, Flat=flatCount, Down=downCount)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
404 row.names(sigDiff) <- contrastData
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
405
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
406 # Save relevant items as rda object
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
407 if (wantRda) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
408 if (wantWeight) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
409 save(data, status, vData, labels, factors, wts, voomFit, top, contrasts,
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
410 design,
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
411 file=rdaOut, ascii=TRUE)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
412 } else {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
413 save(data, status, vData, labels, factors, voomFit, top, contrasts, design,
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
414 file=rdaOut, ascii=TRUE)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
415 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
416 linkData <- rbind(linkData, c("RData (.rda)", "RData.rda"))
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
417 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
418
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
419 # Record session info
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
420 writeLines(capture.output(sessionInfo()), sessionOut)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
421 linkData <- rbind(linkData, c("Session Info", "session_info.txt"))
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
422
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
423 # Record ending time and calculate total run time
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
424 timeEnd <- as.character(Sys.time())
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
425 timeTaken <- capture.output(round(difftime(timeEnd,timeStart), digits=3))
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
426 timeTaken <- gsub("Time difference of ", "", timeTaken, fixed=TRUE)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
427 ################################################################################
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
428 ### HTML Generation
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
429 ################################################################################
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
430
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
431 # Clear file
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
432 cat("", file=htmlPath)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
433
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
434 cata("<html>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
435
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
436 cata("<body>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
437 cata("<h3>Limma Voom Analysis Output:</h3>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
438 cata("PDF copies of JPEGS available in 'Plots' section.<br />\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
439 if (wantWeight) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
440 HtmlImage(imageData$Link[1], imageData$Label[1], width=1000)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
441 } else {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
442 HtmlImage(imageData$Link[1], imageData$Label[1])
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
443 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
444
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
445 for (i in 2:nrow(imageData)) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
446 HtmlImage(imageData$Link[i], imageData$Label[i])
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
447 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
448
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
449 cata("<h4>Differential Expression Counts:</h4>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
450
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
451 cata("<table border=\"1\" cellpadding=\"4\">\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
452 cata("<tr>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
453 TableItem()
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
454 for (i in colnames(sigDiff)) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
455 TableHeadItem(i)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
456 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
457 cata("</tr>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
458 for (i in 1:nrow(sigDiff)) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
459 cata("<tr>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
460 TableHeadItem(unmake.names(row.names(sigDiff)[i]))
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
461 for (j in 1:ncol(sigDiff)) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
462 TableItem(as.character(sigDiff[i, j]))
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
463 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
464 cata("</tr>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
465 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
466 cata("</table>")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
467
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
468 cata("<h4>Plots:</h4>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
469 for (i in 1:nrow(linkData)) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
470 if (grepl(".pdf", linkData$Link[i])) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
471 HtmlLink(linkData$Link[i], linkData$Label[i])
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
472 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
473 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
474
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
475 cata("<h4>Tables:</h4>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
476 for (i in 1:nrow(linkData)) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
477 if (grepl(".tsv", linkData$Link[i])) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
478 HtmlLink(linkData$Link[i], linkData$Label[i])
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
479 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
480 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
481
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
482 if (wantRda) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
483 cata("<h4>R Data Object:</h4>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
484 for (i in 1:nrow(linkData)) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
485 if (grepl(".rda", linkData$Link[i])) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
486 HtmlLink(linkData$Link[i], linkData$Label[i])
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
487 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
488 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
489 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
490
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
491 cata("<p>Alt-click links to download file.</p>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
492 cata("<p>Click floppy disc icon associated history item to download ")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
493 cata("all files.</p>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
494 cata("<p>.tsv files can be viewed in Excel or any spreadsheet program.</p>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
495
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
496 cata("<h4>Additional Information</h4>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
497 cata("<ul>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
498 if (cpmReq!=0 && sampleReq!=0) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
499 tempStr <- paste("Genes without more than", cpmReq,
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
500 "CPM in at least", sampleReq, "samples are insignificant",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
501 "and filtered out.")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
502 ListItem(tempStr)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
503 filterProp <- round(filteredCount/preFilterCount*100, digits=2)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
504 tempStr <- paste0(filteredCount, " of ", preFilterCount," (", filterProp,
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
505 "%) genes were filtered out for low expression.")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
506 ListItem(tempStr)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
507 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
508 ListItem(normOpt, " was the method used to normalise library sizes.")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
509 if (wantWeight) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
510 ListItem("Weights were applied to samples.")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
511 } else {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
512 ListItem("Weights were not applied to samples.")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
513 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
514 if (pAdjOpt!="none") {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
515 if (pAdjOpt=="BH" || pAdjOpt=="BY") {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
516 tempStr <- paste0("MA-Plot highlighted genes are significant at FDR ",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
517 "of ", pValReq," and exhibit log2-fold-change of at ",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
518 "least ", lfcReq, ".")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
519 ListItem(tempStr)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
520 } else if (pAdjOpt=="holm") {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
521 tempStr <- paste0("MA-Plot highlighted genes are significant at adjusted ",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
522 "p-value of ", pValReq," by the Holm(1979) ",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
523 "method, and exhibit log2-fold-change of at least ",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
524 lfcReq, ".")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
525 ListItem(tempStr)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
526 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
527 } else {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
528 tempStr <- paste0("MA-Plot highlighted genes are significant at p-value ",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
529 "of ", pValReq," and exhibit log2-fold-change of at ",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
530 "least ", lfcReq, ".")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
531 ListItem(tempStr)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
532 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
533 cata("</ul>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
534
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
535 cata("<h4>Summary of experimental data:</h4>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
536
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
537 cata("<p>*CHECK THAT SAMPLES ARE ASSOCIATED WITH CORRECT GROUP*</p>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
538
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
539 cata("<table border=\"1\" cellpadding=\"3\">\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
540 cata("<tr>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
541 TableItem()
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
542 for (i in names(factors)) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
543 TableHeadItem(i)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
544 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
545 cata("</tr>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
546
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
547 for (i in 1:nrow(factors)) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
548 cata("<tr>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
549 TableHeadItem(row.names(factors)[i])
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
550 for (j in ncol(factors)) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
551 TableItem(as.character(unmake.names(factors[i, j])))
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
552 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
553 cata("</tr>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
554 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
555 cata("</table>")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
556
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
557 cit <- character()
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
558 link <- character()
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
559 link[1] <- paste0("<a href=\"",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
560 "http://www.bioconductor.org/packages/release/bioc/",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
561 "vignettes/limma/inst/doc/usersguide.pdf",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
562 "\">", "limma User's Guide", "</a>.")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
563
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
564 link[2] <- paste0("<a href=\"",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
565 "http://www.bioconductor.org/packages/release/bioc/",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
566 "vignettes/edgeR/inst/doc/edgeRUsersGuide.pdf",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
567 "\">", "edgeR User's Guide", "</a>")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
568
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
569 cit[1] <- paste("Please cite the paper below for the limma software itself.",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
570 "Please also try to cite the appropriate methodology articles",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
571 "that describe the statistical methods implemented in limma,",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
572 "depending on which limma functions you are using. The",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
573 "methodology articles are listed in Section 2.1 of the",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
574 link[1],
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
575 "Cite no. 3 only if sample weights were used.")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
576 cit[2] <- paste("Smyth, GK (2005). Limma: linear models for microarray data.",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
577 "In: 'Bioinformatics and Computational Biology Solutions using",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
578 "R and Bioconductor'. R. Gentleman, V. Carey, S. doit,.",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
579 "Irizarry, W. Huber (eds), Springer, New York, pages 397-420.")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
580 cit[3] <- paste("Please cite the first paper for the software itself and the",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
581 "other papers for the various original statistical methods",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
582 "implemented in edgeR. See Section 1.2 in the", link[2],
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
583 "for more detail.")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
584 cit[4] <- paste("Robinson MD, McCarthy DJ and Smyth GK (2010). edgeR: a",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
585 "Bioconductor package for differential expression analysis",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
586 "of digital gene expression data. Bioinformatics 26, 139-140")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
587 cit[5] <- paste("Robinson MD and Smyth GK (2007). Moderated statistical tests",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
588 "for assessing differences in tag abundance. Bioinformatics",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
589 "23, 2881-2887")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
590 cit[6] <- paste("Robinson MD and Smyth GK (2008). Small-sample estimation of",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
591 "negative binomial dispersion, with applications to SAGE data.",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
592 "Biostatistics, 9, 321-332")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
593 cit[7] <- paste("McCarthy DJ, Chen Y and Smyth GK (2012). Differential",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
594 "expression analysis of multifactor RNA-Seq experiments with",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
595 "respect to biological variation. Nucleic Acids Research 40,",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
596 "4288-4297")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
597 cit[8] <- paste("Law, CW, Chen, Y, Shi, W, and Smyth, GK (2014). Voom:",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
598 "precision weights unlock linear model analysis tools for",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
599 "RNA-seq read counts. Genome Biology 15, R29.")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
600 cit[9] <- paste("Ritchie, M. E., Diyagama, D., Neilson, J., van Laar,",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
601 "R., Dobrovic, A., Holloway, A., and Smyth, G. K. (2006).",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
602 "Empirical array quality weights for microarray data.",
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
603 "BMC Bioinformatics 7, Article 261.")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
604 cata("<h3>Citations</h3>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
605
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
606 cata("<h4>limma</h4>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
607 cata(cit[1], "\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
608 cata("<ol>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
609 ListItem(cit[2])
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
610 ListItem(cit[8])
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
611 ListItem(cit[9])
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
612 cata("</ol>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
613
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
614 cata("<h4>edgeR</h4>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
615 cata(cit[3], "\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
616 cata("<ol>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
617 ListItem(cit[4])
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
618 ListItem(cit[5])
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
619 ListItem(cit[6])
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
620 ListItem(cit[7])
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
621 cata("</ol>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
622
1
b2fe55fd0651 - Initial commit
shian_su <registertonysu@gmail.com>
parents: 0
diff changeset
623 cata("<p>Please report problems or suggestions to: su.s@wehi.edu.au</p>\n")
0
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
624
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
625 for (i in 1:nrow(linkData)) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
626 if (grepl("session_info", linkData$Link[i])) {
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
627 HtmlLink(linkData$Link[i], linkData$Label[i])
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
628 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
629 }
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
630
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
631 cata("<table border=\"0\">\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
632 cata("<tr>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
633 TableItem("Task started at:"); TableItem(timeStart)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
634 cata("</tr>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
635 cata("<tr>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
636 TableItem("Task ended at:"); TableItem(timeEnd)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
637 cata("</tr>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
638 cata("<tr>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
639 TableItem("Task run time:"); TableItem(timeTaken)
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
640 cata("<tr>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
641 cata("</table>\n")
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
642
7a80e9ec63cb - Initial commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
643 cata("</body>\n")
1
b2fe55fd0651 - Initial commit
shian_su <registertonysu@gmail.com>
parents: 0
diff changeset
644 cata("</html>")