Mercurial > repos > shians > shrnaseq
annotate hairpinTool.R @ 7:91e411fcdecc
Version 1.0.8
- Added differential representation counts table
author | shian_su <registertonysu@gmail.com> |
---|---|
date | Wed, 23 Apr 2014 14:05:26 +1000 |
parents | 3d04308a99f9 |
children | 548802b3492f |
rev | line source |
---|---|
6
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
1 # ARGS: 1.inputType -String specifying format of input (fastq or table) |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
2 # IF inputType is "fastQ": |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
3 # 2*.fastqPath -One or more strings specifying path to fastq files |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
4 # 2.annoPath -String specifying path to hairpin annotation table |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
5 # 3.samplePath -String specifying path to sample annotation table |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
6 # 4.barStart -Integer specifying starting position of barcode |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
7 # 5.barEnd -Integer specifying ending position of barcode |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
8 # 6.hpStart -Integer specifying startins position of hairpin |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
9 # unique region |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
10 # 7.hpEnd -Integer specifying ending position of hairpin |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
11 # unique region |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
12 # ### |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
13 # IF inputType is "counts": |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
14 # 2.countPath -String specifying path to count table |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
15 # 3.annoPath -String specifying path to hairpin annotation table |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
16 # 4.samplePath -String specifying path to sample annotation table |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
17 # ### |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
18 # 8.cpmReq -Float specifying cpm requirement |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
19 # 9.sampleReq -Integer specifying cpm requirement |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
20 # 10.fdrThresh -Float specifying the FDR requirement |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
21 # 11.lfcThresh -Float specifying the log-fold-change requirement |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
22 # 12.workMode -String specifying exact test or GLM usage |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
23 # 13.htmlPath -String specifying path to HTML file |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
24 # 14.folderPath -STring specifying path to folder for output |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
25 # IF workMode is "classic" (exact test) |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
26 # 15.pairData[2] -String specifying first group for exact test |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
27 # 16.pairData[1] -String specifying second group for exact test |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
28 # ### |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
29 # IF workMode is "glm" |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
30 # 15.contrastData -String specifying contrasts to be made |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
31 # 16.roastOpt -String specifying usage of gene-wise tests |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
32 # 17.hairpinReq -String specifying hairpin requirement for gene- |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
33 # wise test |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
34 # 18.selectOpt -String specifying type of selection for barcode |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
35 # plots |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
36 # 19.selectVals -String specifying members selected for barcode |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
37 # plots |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
38 # |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
39 # OUT: Bar Plot of Counts Per Index |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
40 # Bar Plot of Counts Per Hairpin |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
41 # MDS Plot |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
42 # Smear Plot |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
43 # Barcode Plots (If Genewise testing was selected) |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
44 # Top Expression Table |
7 | 45 # Feature Counts Table |
6
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
46 # HTML file linking to the ouputs |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
47 # |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
48 # Author: Shian Su - registertonysu@gmail.com - Jan 2014 |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
49 |
2 | 50 # Record starting time |
51 timeStart <- as.character(Sys.time()) | |
52 | |
53 # Loading and checking required packages | |
54 library(methods, quietly=TRUE, warn.conflicts=FALSE) | |
55 library(statmod, quietly=TRUE, warn.conflicts=FALSE) | |
56 library(splines, quietly=TRUE, warn.conflicts=FALSE) | |
57 library(edgeR, quietly=TRUE, warn.conflicts=FALSE) | |
58 library(limma, quietly=TRUE, warn.conflicts=FALSE) | |
59 | |
60 if (packageVersion("edgeR") < "3.5.23") { | |
61 message("Please update 'edgeR' to version >= 3.5.23 to run this script") | |
62 } | |
63 | |
64 ################################################################################ | |
65 ### Function declarations | |
66 ################################################################################ | |
67 | |
7 | 68 # Function to load libaries without messages |
69 silentLibrary <- function(...) { | |
70 list <- c(...) | |
71 for (package in list){ | |
72 suppressPackageStartupMessages(library(package, character.only=TRUE)) | |
73 } | |
74 } | |
75 | |
2 | 76 # Function to sanitise contrast equations so there are no whitespaces |
77 # surrounding the arithmetic operators, leading or trailing whitespace | |
78 sanitiseEquation <- function(equation) { | |
79 equation <- gsub(" *[+] *", "+", equation) | |
80 equation <- gsub(" *[-] *", "-", equation) | |
81 equation <- gsub(" *[/] *", "/", equation) | |
82 equation <- gsub(" *[*] *", "*", equation) | |
83 equation <- gsub("^\\s+|\\s+$", "", equation) | |
84 return(equation) | |
85 } | |
86 | |
87 # Function to sanitise group information | |
88 sanitiseGroups <- function(string) { | |
89 string <- gsub(" *[,] *", ",", string) | |
90 string <- gsub("^\\s+|\\s+$", "", string) | |
91 return(string) | |
92 } | |
93 | |
94 # Function to change periods to whitespace in a string | |
95 unmake.names <- function(string) { | |
96 string <- gsub(".", " ", string, fixed=TRUE) | |
97 return(string) | |
98 } | |
99 | |
100 # Function has string input and generates an output path string | |
101 makeOut <- function(filename) { | |
102 return(paste0(folderPath, "/", filename)) | |
103 } | |
104 | |
105 # Function has string input and generates both a pdf and png output strings | |
106 imgOut <- function(filename) { | |
107 assign(paste0(filename, "Png"), makeOut(paste0(filename,".png")), | |
7 | 108 envir=.GlobalEnv) |
2 | 109 assign(paste0(filename, "Pdf"), makeOut(paste0(filename,".pdf")), |
7 | 110 envir=.GlobalEnv) |
2 | 111 } |
112 | |
113 # Create cat function default path set, default seperator empty and appending | |
114 # true by default (Ripped straight from the cat function with altered argument | |
115 # defaults) | |
7 | 116 cata <- function(..., file=htmlPath, sep="", fill=FALSE, labels=NULL, |
117 append=TRUE) { | |
2 | 118 if (is.character(file)) |
119 if (file == "") | |
120 file <- stdout() | |
121 else if (substring(file, 1L, 1L) == "|") { | |
122 file <- pipe(substring(file, 2L), "w") | |
123 on.exit(close(file)) | |
124 } | |
125 else { | |
126 file <- file(file, ifelse(append, "a", "w")) | |
127 on.exit(close(file)) | |
128 } | |
129 .Internal(cat(list(...), file, sep, fill, labels, append)) | |
130 } | |
131 | |
132 # Function to write code for html head and title | |
133 HtmlHead <- function(title) { | |
134 cata("<head>\n") | |
135 cata("<title>", title, "</title>\n") | |
136 cata("</head>\n") | |
137 } | |
138 | |
139 # Function to write code for html links | |
140 HtmlLink <- function(address, label=address) { | |
141 cata("<a href=\"", address, "\" target=\"_blank\">", label, "</a><br />\n") | |
142 } | |
143 | |
144 # Function to write code for html images | |
145 HtmlImage <- function(source, label=source, height=600, width=600) { | |
146 cata("<img src=\"", source, "\" alt=\"", label, "\" height=\"", height) | |
147 cata("\" width=\"", width, "\"/>\n") | |
148 } | |
149 | |
150 # Function to write code for html list items | |
151 ListItem <- function(...) { | |
152 cata("<li>", ..., "</li>\n") | |
153 } | |
154 | |
155 TableItem <- function(...) { | |
156 cata("<td>", ..., "</td>\n") | |
157 } | |
158 | |
159 TableHeadItem <- function(...) { | |
160 cata("<th>", ..., "</th>\n") | |
161 } | |
162 ################################################################################ | |
163 ### Input Processing | |
164 ################################################################################ | |
165 | |
166 # Grabbing arguments from command line | |
167 argv <- commandArgs(TRUE) | |
168 | |
169 # Remove fastq file paths after collecting from argument vector | |
170 inputType <- as.character(argv[1]) | |
171 if (inputType=="fastq") { | |
172 fastqPath <- as.character(gsub("fastq::", "", argv[grepl("fastq::", argv)], | |
173 fixed=TRUE)) | |
174 argv <- argv[!grepl("fastq::", argv, fixed=TRUE)] | |
6
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
175 annoPath <- as.character(argv[2]) |
2 | 176 samplePath <- as.character(argv[3]) |
177 barStart <- as.numeric(argv[4]) | |
178 barEnd <- as.numeric(argv[5]) | |
179 hpStart <- as.numeric(argv[6]) | |
180 hpEnd <- as.numeric(argv[7]) | |
181 } else if (inputType=="counts") { | |
182 countPath <- as.character(argv[2]) | |
183 annoPath <- as.character(argv[3]) | |
184 samplePath <- as.character(argv[4]) | |
185 } | |
186 | |
187 cpmReq <- as.numeric(argv[8]) | |
188 sampleReq <- as.numeric(argv[9]) | |
189 fdrThresh <- as.numeric(argv[10]) | |
190 lfcThresh <- as.numeric(argv[11]) | |
191 workMode <- as.character(argv[12]) | |
192 htmlPath <- as.character(argv[13]) | |
193 folderPath <- as.character(argv[14]) | |
6
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
194 |
2 | 195 if (workMode=="classic") { |
196 pairData <- character() | |
197 pairData[2] <- as.character(argv[15]) | |
198 pairData[1] <- as.character(argv[16]) | |
199 } else if (workMode=="glm") { | |
200 contrastData <- as.character(argv[15]) | |
201 roastOpt <- as.character(argv[16]) | |
202 hairpinReq <- as.numeric(argv[17]) | |
203 selectOpt <- as.character(argv[18]) | |
204 selectVals <- as.character(argv[19]) | |
205 } | |
206 | |
207 # Read in inputs | |
6
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
208 |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
209 samples <- read.table(samplePath, header=TRUE, sep="\t") |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
210 anno <- read.table(annoPath, header=TRUE, sep="\t") |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
211 if (inputType=="counts") { |
2 | 212 counts <- read.table(countPath, header=TRUE, sep="\t") |
213 } | |
6
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
214 |
2 | 215 ###################### Check inputs for correctness ############################ |
216 samples$ID <- make.names(samples$ID) | |
217 | |
218 if (!any(grepl("group", names(samples)))) { | |
219 stop("'group' column not specified in sample annotation file") | |
220 } # Check if grouping variable has been specified | |
221 | |
222 if (any(table(samples$ID)>1)){ | |
223 tab <- table(samples$ID) | |
224 offenders <- paste(names(tab[tab>1]), collapse=", ") | |
225 offenders <- unmake.names(offenders) | |
6
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
226 stop("'ID' column of sample annotation must have unique values, values ", |
2 | 227 offenders, " are repeated") |
228 } # Check that IDs in sample annotation are unique | |
229 | |
230 if (inputType=="fastq") { | |
6
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
231 |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
232 if (any(table(anno$ID)>1)){ |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
233 tab <- table(anno$ID) |
2 | 234 offenders <- paste(names(tab[tab>1]), collapse=", ") |
6
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
235 stop("'ID' column of hairpin annotation must have unique values, values ", |
2 | 236 offenders, " are repeated") |
237 } # Check that IDs in hairpin annotation are unique | |
4
f8af57d6f60b
Fixed bug causing fastq input to break
shian_su <registertonysu@gmail.com>
parents:
2
diff
changeset
|
238 |
2 | 239 } else if (inputType=="counts") { |
4
f8af57d6f60b
Fixed bug causing fastq input to break
shian_su <registertonysu@gmail.com>
parents:
2
diff
changeset
|
240 if (any(is.na(match(samples$ID, colnames(counts))))) { |
f8af57d6f60b
Fixed bug causing fastq input to break
shian_su <registertonysu@gmail.com>
parents:
2
diff
changeset
|
241 stop("not all samples have groups specified") |
f8af57d6f60b
Fixed bug causing fastq input to break
shian_su <registertonysu@gmail.com>
parents:
2
diff
changeset
|
242 } # Check that a group has be specifed for each sample |
2 | 243 |
244 if (any(table(counts$ID)>1)){ | |
245 tab <- table(counts$ID) | |
246 offenders <- paste(names(tab[tab>1]), collapse=", ") | |
6
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
247 stop("'ID' column of count table must have unique values, values ", |
2 | 248 offenders, " are repeated") |
249 } # Check that IDs in count table are unique | |
250 } | |
6
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
251 if (workMode=="glm") { |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
252 if (roastOpt == "yes") { |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
253 if (is.na(match("Gene", colnames(anno)))) { |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
254 tempStr <- paste("Gene-wise tests selected but'Gene' column not", |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
255 "specified in hairpin annotation file") |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
256 stop(tempStr) |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
257 } |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
258 } |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
259 } |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
260 |
2 | 261 ################################################################################ |
262 | |
263 # Process arguments | |
264 if (workMode=="glm") { | |
265 if (roastOpt=="yes") { | |
266 wantRoast <- TRUE | |
267 } else { | |
268 wantRoast <- FALSE | |
269 } | |
270 } | |
271 | |
272 # Split up contrasts seperated by comma into a vector and replace spaces with | |
273 # periods | |
274 if (exists("contrastData")) { | |
275 contrastData <- unlist(strsplit(contrastData, split=",")) | |
276 contrastData <- sanitiseEquation(contrastData) | |
277 contrastData <- gsub(" ", ".", contrastData, fixed=TRUE) | |
278 } | |
279 | |
280 # Replace spaces with periods in pair data | |
281 if (exists("pairData")) { | |
282 pairData <- make.names(pairData) | |
283 } | |
284 | |
285 # Generate output folder and paths | |
6
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
286 dir.create(folderPath, showWarnings=FALSE) |
2 | 287 |
288 # Generate links for outputs | |
289 imgOut("barHairpin") | |
290 imgOut("barIndex") | |
291 imgOut("mds") | |
292 imgOut("bcv") | |
293 if (workMode == "classic") { | |
294 smearPng <- makeOut(paste0("smear(", pairData[2], "-", pairData[1],").png")) | |
295 smearPdf <- makeOut(paste0("smear(", pairData[2], "-", pairData[1],").pdf")) | |
296 topOut <- makeOut(paste0("toptag(", pairData[2], "-", pairData[1],").tsv")) | |
297 } else if (workMode=="glm") { | |
298 smearPng <- character() | |
299 smearPdf <- character() | |
300 topOut <- character() | |
301 roastOut <- character() | |
302 barcodePng <- character() | |
303 barcodePdf <- character() | |
304 for (i in 1:length(contrastData)) { | |
305 smearPng[i] <- makeOut(paste0("smear(", contrastData[i], ").png")) | |
306 smearPdf[i] <- makeOut(paste0("smear(", contrastData[i], ").pdf")) | |
307 topOut[i] <- makeOut(paste0("toptag(", contrastData[i], ").tsv")) | |
308 roastOut[i] <- makeOut(paste0("roast(", contrastData[i], ").tsv")) | |
309 barcodePng[i] <- makeOut(paste0("barcode(", contrastData[i], ").png")) | |
310 barcodePdf[i] <- makeOut(paste0("barcode(", contrastData[i], ").pdf")) | |
311 } | |
312 } | |
6
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
313 countsOut <- makeOut("counts.tsv") |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
314 |
2 | 315 # Initialise data for html links and images, table with the link label and |
316 # link address | |
317 linkData <- data.frame(Label=character(), Link=character(), | |
318 stringsAsFactors=FALSE) | |
319 imageData <- data.frame(Label=character(), Link=character(), | |
320 stringsAsFactors=FALSE) | |
7 | 321 |
322 # Initialise vectors for storage of up/down/neutral regulated counts | |
323 upCount <- numeric() | |
324 downCount <- numeric() | |
325 flatCount <- numeric() | |
326 | |
2 | 327 ################################################################################ |
328 ### Data Processing | |
329 ################################################################################ | |
330 | |
331 # Transform gene selection from string into index values for mroast | |
332 if (workMode=="glm") { | |
333 if (selectOpt=="rank") { | |
334 selectVals <- gsub(" ", "", selectVals, fixed=TRUE) | |
335 selectVals <- unlist(strsplit(selectVals, ",")) | |
336 | |
337 for (i in 1:length(selectVals)) { | |
338 if (grepl(":", selectVals[i], fixed=TRUE)) { | |
339 temp <- unlist(strsplit(selectVals[i], ":")) | |
340 selectVals <- selectVals[-i] | |
341 a <- as.numeric(temp[1]) | |
342 b <- as.numeric(temp[2]) | |
343 selectVals <- c(selectVals, a:b) | |
344 } | |
345 } | |
346 selectVals <- as.numeric(unique(selectVals)) | |
347 } else { | |
348 selectVals <- gsub(" ", "", selectVals, fixed=TRUE) | |
349 selectVals <- unlist(strsplit(selectVals, " ")) | |
350 } | |
351 } | |
352 | |
353 if (inputType=="fastq") { | |
6
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
354 # Use EdgeR hairpin process and capture outputs |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
355 hpReadout <- capture.output( |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
356 data <- processHairpinReads(fastqPath, samplePath, annoPath, |
2 | 357 hairpinStart=hpStart, hairpinEnd=hpEnd, |
358 verbose=TRUE) | |
6
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
359 ) |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
360 |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
361 # Remove function output entries that show processing data or is empty |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
362 hpReadout <- hpReadout[hpReadout!=""] |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
363 hpReadout <- hpReadout[!grepl("Processing", hpReadout)] |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
364 hpReadout <- hpReadout[!grepl("in file", hpReadout)] |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
365 hpReadout <- gsub(" -- ", "", hpReadout, fixed=TRUE) |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
366 |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
367 # Make the names of groups syntactically valid (replace spaces with periods) |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
368 data$samples$group <- make.names(data$samples$group) |
4
f8af57d6f60b
Fixed bug causing fastq input to break
shian_su <registertonysu@gmail.com>
parents:
2
diff
changeset
|
369 } else if (inputType=="counts") { |
2 | 370 # Process counts information, set ID column to be row names |
371 rownames(counts) <- counts$ID | |
372 counts <- counts[ , !(colnames(counts)=="ID")] | |
373 countsRows <- nrow(counts) | |
374 | |
375 # Process group information | |
376 factors <- samples$group[match(samples$ID, colnames(counts))] | |
377 annoRows <- nrow(anno) | |
378 anno <- anno[match(rownames(counts), anno$ID), ] | |
379 annoMatched <- sum(!is.na(anno$ID)) | |
380 | |
381 if (any(is.na(anno$ID))) { | |
382 warningStr <- paste("count table contained more hairpins than", | |
383 "specified in hairpin annotation file") | |
384 warning(warningStr) | |
385 } | |
386 | |
387 # Filter out rows with zero counts | |
388 sel <- rowSums(counts)!=0 | |
389 counts <- counts[sel, ] | |
390 anno <- anno[sel, ] | |
391 | |
392 # Create DGEList | |
393 data <- DGEList(counts=counts, lib.size=colSums(counts), | |
394 norm.factors=rep(1,ncol(counts)), genes=anno, group=factors) | |
6
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
395 |
2 | 396 # Make the names of groups syntactically valid (replace spaces with periods) |
397 data$samples$group <- make.names(data$samples$group) | |
398 } | |
399 | |
400 # Filter hairpins with low counts | |
6
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
401 preFilterCount <- nrow(data) |
2 | 402 sel <- rowSums(cpm(data$counts) > cpmReq) >= sampleReq |
403 data <- data[sel, ] | |
6
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
404 postFilterCount <- nrow(data) |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
405 filteredCount <- preFilterCount-postFilterCount |
2 | 406 |
407 # Estimate dispersions | |
408 data <- estimateDisp(data) | |
409 commonBCV <- sqrt(data$common.dispersion) | |
410 | |
411 ################################################################################ | |
412 ### Output Processing | |
413 ################################################################################ | |
414 | |
415 # Plot number of hairpins that could be matched per sample | |
416 png(barIndexPng, width=600, height=600) | |
417 barplot(height<-colSums(data$counts), las=2, main="Counts per index", | |
418 cex.names=1.0, cex.axis=0.8, ylim=c(0, max(height)*1.2)) | |
419 imageData[1, ] <- c("Counts per Index", "barIndex.png") | |
420 invisible(dev.off()) | |
421 | |
422 pdf(barIndexPdf) | |
423 barplot(height<-colSums(data$counts), las=2, main="Counts per index", | |
424 cex.names=1.0, cex.axis=0.8, ylim=c(0, max(height)*1.2)) | |
425 linkData[1, ] <- c("Counts per Index Barplot (.pdf)", "barIndex.pdf") | |
426 invisible(dev.off()) | |
427 | |
428 # Plot per hairpin totals across all samples | |
429 png(barHairpinPng, width=600, height=600) | |
430 if (nrow(data$counts)<50) { | |
431 barplot(height<-rowSums(data$counts), las=2, main="Counts per hairpin", | |
432 cex.names=0.8, cex.axis=0.8, ylim=c(0, max(height)*1.2)) | |
433 } else { | |
434 barplot(height<-rowSums(data$counts), las=2, main="Counts per hairpin", | |
435 cex.names=0.8, cex.axis=0.8, ylim=c(0, max(height)*1.2), | |
436 names.arg=FALSE) | |
437 } | |
438 imageData <- rbind(imageData, c("Counts per Hairpin", "barHairpin.png")) | |
439 invisible(dev.off()) | |
440 | |
441 pdf(barHairpinPdf) | |
442 if (nrow(data$counts)<50) { | |
443 barplot(height<-rowSums(data$counts), las=2, main="Counts per hairpin", | |
444 cex.names=0.8, cex.axis=0.8, ylim=c(0, max(height)*1.2)) | |
445 } else { | |
446 barplot(height<-rowSums(data$counts), las=2, main="Counts per hairpin", | |
447 cex.names=0.8, cex.axis=0.8, ylim=c(0, max(height)*1.2), | |
448 names.arg=FALSE) | |
449 } | |
450 newEntry <- c("Counts per Hairpin Barplot (.pdf)", "barHairpin.pdf") | |
451 linkData <- rbind(linkData, newEntry) | |
452 invisible(dev.off()) | |
453 | |
454 # Make an MDS plot to visualise relationships between replicate samples | |
455 png(mdsPng, width=600, height=600) | |
456 plotMDS(data, labels=data$samples$group, col=as.numeric(data$samples$group), | |
457 main="MDS Plot") | |
458 imageData <- rbind(imageData, c("MDS Plot", "mds.png")) | |
459 invisible(dev.off()) | |
460 | |
461 pdf(mdsPdf) | |
462 plotMDS(data, labels=data$samples$group, col=as.numeric(data$samples$group), | |
463 main="MDS Plot") | |
464 newEntry <- c("MDS Plot (.pdf)", "mds.pdf") | |
465 linkData <- rbind(linkData, newEntry) | |
466 invisible(dev.off()) | |
467 | |
468 if (workMode=="classic") { | |
469 # Assess differential representation using classic exact testing methodology | |
470 # in edgeR | |
471 testData <- exactTest(data, pair=pairData) | |
472 | |
473 top <- topTags(testData, n=Inf) | |
474 topIDs <- top$table[(top$table$FDR < fdrThresh) & | |
475 (abs(top$table$logFC) > lfcThresh), 1] | |
7 | 476 |
2 | 477 write.table(top, file=topOut, row.names=FALSE, sep="\t") |
7 | 478 |
2 | 479 linkName <- paste0("Top Tags Table(", pairData[2], "-", pairData[1], |
480 ") (.tsv)") | |
481 linkAddr <- paste0("toptag(", pairData[2], "-", pairData[1], ").tsv") | |
482 linkData <- rbind(linkData, c(linkName, linkAddr)) | |
483 | |
7 | 484 upCount[1] <- sum(top$table$FDR < fdrThresh & top$table$logFC > lfcThresh) |
485 downCount[1] <- sum(top$table$FDR < fdrThresh & | |
486 top$table$logFC < -lfcThresh) | |
487 flatCount[1] <- sum(top$table$FDR > fdrThresh | | |
488 abs(top$table$logFC) < lfcThresh) | |
489 | |
490 | |
491 | |
2 | 492 # Select hairpins with FDR < 0.05 to highlight on plot |
493 png(smearPng, width=600, height=600) | |
494 plotTitle <- gsub(".", " ", | |
495 paste0("Smear Plot: ", pairData[2], "-", pairData[1]), | |
7 | 496 fixed=TRUE) |
2 | 497 plotSmear(testData, de.tags=topIDs, |
498 pch=20, cex=1.0, main=plotTitle) | |
7 | 499 abline(h=c(-1, 0, 1), col=c("dodgerblue", "yellow", "dodgerblue"), lty=2) |
2 | 500 imgName <- paste0("Smear Plot(", pairData[2], "-", pairData[1], ")") |
501 imgAddr <- paste0("smear(", pairData[2], "-", pairData[1],").png") | |
502 imageData <- rbind(imageData, c(imgName, imgAddr)) | |
503 invisible(dev.off()) | |
504 | |
505 pdf(smearPdf) | |
506 plotTitle <- gsub(".", " ", | |
507 paste0("Smear Plot: ", pairData[2], "-", pairData[1]), | |
7 | 508 fixed=TRUE) |
2 | 509 plotSmear(testData, de.tags=topIDs, |
510 pch=20, cex=1.0, main=plotTitle) | |
7 | 511 abline(h=c(-1, 0, 1), col=c("dodgerblue", "yellow", "dodgerblue"), lty=2) |
2 | 512 imgName <- paste0("Smear Plot(", pairData[2], "-", pairData[1], ") (.pdf)") |
513 imgAddr <- paste0("smear(", pairData[2], "-", pairData[1], ").pdf") | |
514 linkData <- rbind(linkData, c(imgName, imgAddr)) | |
515 invisible(dev.off()) | |
7 | 516 |
2 | 517 } else if (workMode=="glm") { |
518 # Generating design information | |
519 factors <- factor(data$sample$group) | |
520 design <- model.matrix(~0+factors) | |
521 | |
522 colnames(design) <- gsub("factors", "", colnames(design), fixed=TRUE) | |
523 | |
524 # Split up contrasts seperated by comma into a vector | |
525 contrastData <- unlist(strsplit(contrastData, split=",")) | |
7 | 526 |
2 | 527 for (i in 1:length(contrastData)) { |
528 # Generate contrasts information | |
529 contrasts <- makeContrasts(contrasts=contrastData[i], levels=design) | |
530 | |
531 # Fit negative bionomial GLM | |
7 | 532 fit <- glmFit(data, design) |
2 | 533 # Carry out Likelihood ratio test |
7 | 534 testData <- glmLRT(fit, contrast=contrasts) |
2 | 535 |
536 # Select hairpins with FDR < 0.05 to highlight on plot | |
537 top <- topTags(testData, n=Inf) | |
538 topIDs <- top$table[(top$table$FDR < fdrThresh) & | |
539 (abs(top$table$logFC) > lfcThresh), 1] | |
540 write.table(top, file=topOut[i], row.names=FALSE, sep="\t") | |
541 | |
542 linkName <- paste0("Top Tags Table(", contrastData[i], ") (.tsv)") | |
543 linkAddr <- paste0("toptag(", contrastData[i], ").tsv") | |
544 linkData <- rbind(linkData, c(linkName, linkAddr)) | |
545 | |
7 | 546 # Collect counts for differential representation |
547 upCount[i] <- sum(top$table$FDR < fdrThresh & top$table$logFC > lfcThresh) | |
548 downCount[i] <- sum(top$table$FDR < fdrThresh & | |
549 top$table$logFC < -lfcThresh) | |
550 flatCount[i] <- sum(top$table$FDR > fdrThresh | | |
551 abs(top$table$logFC) < lfcThresh) | |
552 | |
2 | 553 # Make a plot of logFC versus logCPM |
554 png(smearPng[i], height=600, width=600) | |
555 plotTitle <- paste("Smear Plot:", gsub(".", " ", contrastData[i], | |
556 fixed=TRUE)) | |
557 plotSmear(testData, de.tags=topIDs, pch=20, cex=0.8, main=plotTitle) | |
558 abline(h=c(-1, 0, 1), col=c("dodgerblue", "yellow", "dodgerblue"), lty=2) | |
559 | |
560 imgName <- paste0("Smear Plot(", contrastData[i], ")") | |
561 imgAddr <- paste0("smear(", contrastData[i], ").png") | |
562 imageData <- rbind(imageData, c(imgName, imgAddr)) | |
563 invisible(dev.off()) | |
564 | |
565 pdf(smearPdf[i]) | |
566 plotTitle <- paste("Smear Plot:", gsub(".", " ", contrastData[i], | |
567 fixed=TRUE)) | |
568 plotSmear(testData, de.tags=topIDs, pch=20, cex=0.8, main=plotTitle) | |
569 abline(h=c(-1, 0, 1), col=c("dodgerblue", "yellow", "dodgerblue"), lty=2) | |
570 | |
571 linkName <- paste0("Smear Plot(", contrastData[i], ") (.pdf)") | |
572 linkAddr <- paste0("smear(", contrastData[i], ").pdf") | |
573 linkData <- rbind(linkData, c(linkName, linkAddr)) | |
574 invisible(dev.off()) | |
575 | |
576 genes <- as.character(data$genes$Gene) | |
577 unq <- unique(genes) | |
578 unq <- unq[!is.na(unq)] | |
579 geneList <- list() | |
580 for (gene in unq) { | |
581 if (length(which(genes==gene)) >= hairpinReq) { | |
582 geneList[[gene]] <- which(genes==gene) | |
583 } | |
584 } | |
585 | |
586 if (wantRoast) { | |
587 # Input preparaton for roast | |
7 | 588 nrot <- 9999 |
2 | 589 set.seed(602214129) |
590 roastData <- mroast(data, index=geneList, design=design, | |
591 contrast=contrasts, nrot=nrot) | |
592 roastData <- cbind(GeneID=rownames(roastData), roastData) | |
593 write.table(roastData, file=roastOut[i], row.names=FALSE, sep="\t") | |
594 linkName <- paste0("Gene Level Analysis Table(", contrastData[i], | |
595 ") (.tsv)") | |
596 linkAddr <- paste0("roast(", contrastData[i], ").tsv") | |
597 linkData <- rbind(linkData, c(linkName, linkAddr)) | |
598 if (selectOpt=="rank") { | |
599 selectedGenes <- rownames(roastData)[selectVals] | |
600 } else { | |
601 selectedGenes <- selectVals | |
602 } | |
603 | |
604 if (packageVersion("limma")<"3.19.19") { | |
605 png(barcodePng[i], width=600, height=length(selectedGenes)*150) | |
606 } else { | |
607 png(barcodePng[i], width=600, height=length(selectedGenes)*300) | |
608 } | |
609 par(mfrow=c(length(selectedGenes), 1)) | |
610 for (gene in selectedGenes) { | |
611 barcodeplot(testData$table$logFC, index=geneList[[gene]], | |
612 main=paste("Barcode Plot for", gene, "(logFCs)", | |
613 gsub(".", " ", contrastData[i])), | |
614 labels=c("Positive logFC", "Negative logFC")) | |
615 } | |
616 imgName <- paste0("Barcode Plot(", contrastData[i], ")") | |
617 imgAddr <- paste0("barcode(", contrastData[i], ").png") | |
618 imageData <- rbind(imageData, c(imgName, imgAddr)) | |
619 dev.off() | |
620 if (packageVersion("limma")<"3.19.19") { | |
621 pdf(barcodePdf[i], width=8, height=2) | |
622 } else { | |
623 pdf(barcodePdf[i], width=8, height=4) | |
624 } | |
625 for (gene in selectedGenes) { | |
626 barcodeplot(testData$table$logFC, index=geneList[[gene]], | |
627 main=paste("Barcode Plot for", gene, "(logFCs)", | |
628 gsub(".", " ", contrastData[i])), | |
629 labels=c("Positive logFC", "Negative logFC")) | |
630 } | |
631 linkName <- paste0("Barcode Plot(", contrastData[i], ") (.pdf)") | |
632 linkAddr <- paste0("barcode(", contrastData[i], ").pdf") | |
633 linkData <- rbind(linkData, c(linkName, linkAddr)) | |
634 dev.off() | |
635 } | |
636 } | |
637 } | |
638 | |
7 | 639 sigDiff <- data.frame(Up=upCount, Flat=flatCount, Down=downCount) |
640 if (workMode == "glm") { | |
641 row.names(sigDiff) <- contrastData | |
642 } else if (workMode == "classic") { | |
643 row.names(sigDiff) <- paste0(pairData[2], "-", pairData[1]) | |
644 } | |
645 | |
6
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
646 ID <- rownames(data$counts) |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
647 outputCounts <- cbind(ID, data$counts) |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
648 write.table(outputCounts, file=countsOut, row.names=FALSE, sep="\t") |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
649 linkName <- "Counts table (.tsv)" |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
650 linkAddr <- "counts.tsv" |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
651 linkData <- rbind(linkData, c(linkName, linkAddr)) |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
652 |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
653 # Record ending time and calculate total run time |
2 | 654 timeEnd <- as.character(Sys.time()) |
6
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
655 timeTaken <- capture.output(round(difftime(timeEnd,timeStart), digits=3)) |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
656 timeTaken <- gsub("Time difference of ", "", timeTaken, fixed=TRUE) |
2 | 657 ################################################################################ |
658 ### HTML Generation | |
659 ################################################################################ | |
660 # Clear file | |
661 cat("", file=htmlPath) | |
662 | |
663 cata("<html>\n") | |
664 HtmlHead("EdgeR Output") | |
665 | |
666 cata("<body>\n") | |
667 cata("<h3>EdgeR Analysis Output:</h3>\n") | |
668 cata("<h4>Input Summary:</h4>\n") | |
669 if (inputType=="fastq") { | |
670 cata("<ul>\n") | |
671 ListItem(hpReadout[1]) | |
672 ListItem(hpReadout[2]) | |
673 cata("</ul>\n") | |
6
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
674 cata(hpReadout[3], "<br />\n") |
2 | 675 cata("<ul>\n") |
676 ListItem(hpReadout[4]) | |
677 ListItem(hpReadout[7]) | |
678 cata("</ul>\n") | |
6
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
679 cata(hpReadout[8:11], sep="<br />\n") |
2 | 680 cata("<br />\n") |
681 cata("<b>Please check that read percentages are consistent with ") | |
682 cata("expectations.</b><br >\n") | |
683 } else if (inputType=="counts") { | |
684 cata("<ul>\n") | |
685 ListItem("Number of Samples: ", ncol(data$counts)) | |
686 ListItem("Number of Hairpins: ", countsRows) | |
687 ListItem("Number of annotations provided: ", annoRows) | |
688 ListItem("Number of annotations matched to hairpin: ", annoMatched) | |
689 cata("</ul>\n") | |
690 } | |
691 | |
692 cata("The estimated common biological coefficient of variation (BCV) is: ", | |
693 commonBCV, "<br />\n") | |
694 | |
695 cata("<h4>Output:</h4>\n") | |
7 | 696 cata("PDF copies of JPEGS available in 'Plots' section.<br />\n") |
2 | 697 for (i in 1:nrow(imageData)) { |
698 if (grepl("barcode", imageData$Link[i])) { | |
699 if (packageVersion("limma")<"3.19.19") { | |
700 HtmlImage(imageData$Link[i], imageData$Label[i], | |
701 height=length(selectedGenes)*150) | |
702 } else { | |
703 HtmlImage(imageData$Link[i], imageData$Label[i], | |
704 height=length(selectedGenes)*300) | |
705 } | |
706 } else { | |
707 HtmlImage(imageData$Link[i], imageData$Label[i]) | |
708 } | |
709 } | |
6
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
710 cata("<br />\n") |
2 | 711 |
7 | 712 cata("<h4>Differential Representation Counts:</h4>\n") |
713 | |
714 cata("<table border=\"1\" cellpadding=\"4\">\n") | |
715 cata("<tr>\n") | |
716 TableItem() | |
717 for (i in colnames(sigDiff)) { | |
718 TableHeadItem(i) | |
719 } | |
720 cata("</tr>\n") | |
721 for (i in 1:nrow(sigDiff)) { | |
722 cata("<tr>\n") | |
723 TableHeadItem(unmake.names(row.names(sigDiff)[i])) | |
724 for (j in 1:ncol(sigDiff)) { | |
725 TableItem(as.character(sigDiff[i, j])) | |
726 } | |
727 cata("</tr>\n") | |
728 } | |
729 cata("</table>") | |
730 | |
2 | 731 cata("<h4>Plots:</h4>\n") |
732 for (i in 1:nrow(linkData)) { | |
733 if (!grepl(".tsv", linkData$Link[i])) { | |
734 HtmlLink(linkData$Link[i], linkData$Label[i]) | |
735 } | |
736 } | |
737 | |
738 cata("<h4>Tables:</h4>\n") | |
739 for (i in 1:nrow(linkData)) { | |
740 if (grepl(".tsv", linkData$Link[i])) { | |
741 HtmlLink(linkData$Link[i], linkData$Label[i]) | |
742 } | |
743 } | |
744 | |
7 | 745 cata("<p>Alt-click links to download file.</p>\n") |
746 cata("<p>Click floppy disc icon associated history item to download ") | |
747 cata("all files.</p>\n") | |
748 cata("<p>.tsv files can be viewed in Excel or any spreadsheet program.</p>\n") | |
6
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
749 |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
750 cata("<h4>Additional Information:</h4>\n") |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
751 |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
752 if (inputType == "fastq") { |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
753 ListItem("Data was gathered from fastq raw read file(s).") |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
754 } else if (inputType == "counts") { |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
755 ListItem("Data was gathered from a table of counts.") |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
756 } |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
757 |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
758 if (cpmReq!=0 && sampleReq!=0) { |
7 | 759 tempStr <- paste("Hairpins with less than", cpmReq, |
760 "CPM in at least", sampleReq, "samples are insignificant", | |
761 "and filtered out.") | |
6
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
762 ListItem(tempStr) |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
763 filterProp <- round(filteredCount/preFilterCount*100, digits=2) |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
764 tempStr <- paste0(filteredCount, " of ", preFilterCount," (", filterProp, |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
765 "%) hairpins were filtered out for low count-per-million.") |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
766 ListItem(tempStr) |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
767 } |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
768 |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
769 if (workMode == "classic") { |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
770 ListItem("An exact test was performed on each hairpin.") |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
771 } else if (workMode == "glm") { |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
772 ListItem("A generalised linear model was fitted to each hairpin.") |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
773 } |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
774 |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
775 cit <- character() |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
776 link <-character() |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
777 link[1] <- paste0("<a href=\"", |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
778 "http://www.bioconductor.org/packages/release/bioc/", |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
779 "vignettes/limma/inst/doc/usersguide.pdf", |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
780 "\">", "limma User's Guide", "</a>.") |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
781 link[2] <- paste0("<a href=\"", |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
782 "http://www.bioconductor.org/packages/release/bioc/", |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
783 "vignettes/edgeR/inst/doc/edgeRUsersGuide.pdf", |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
784 "\">", "edgeR User's Guide", "</a>") |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
785 |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
786 cit[1] <- paste("Robinson MD, McCarthy DJ and Smyth GK (2010).", |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
787 "edgeR: a Bioconductor package for differential", |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
788 "expression analysis of digital gene expression", |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
789 "data. Bioinformatics 26, 139-140") |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
790 cit[2] <- paste("Robinson MD and Smyth GK (2007). Moderated statistical tests", |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
791 "for assessing differences in tag abundance. Bioinformatics", |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
792 "23, 2881-2887") |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
793 cit[3] <- paste("Robinson MD and Smyth GK (2008). Small-sample estimation of", |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
794 "negative binomial dispersion, with applications to SAGE data.", |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
795 "Biostatistics, 9, 321-332") |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
796 |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
797 cit[4] <- paste("McCarthy DJ, Chen Y and Smyth GK (2012). Differential", |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
798 "expression analysis of multifactor RNA-Seq experiments with", |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
799 "respect to biological variation. Nucleic Acids Research 40,", |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
800 "4288-4297") |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
801 |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
802 cata("<h4>Citations</h4>") |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
803 cata("<ol>\n") |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
804 ListItem(cit[1]) |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
805 ListItem(cit[2]) |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
806 ListItem(cit[3]) |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
807 ListItem(cit[4]) |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
808 cata("</ol>\n") |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
809 |
2 | 810 cata("<table border=\"0\">\n") |
811 cata("<tr>\n") | |
812 TableItem("Task started at:"); TableItem(timeStart) | |
813 cata("</tr>\n") | |
814 cata("<tr>\n") | |
815 TableItem("Task ended at:"); TableItem(timeEnd) | |
816 cata("</tr>\n") | |
6
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
817 cata("<tr>\n") |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
818 TableItem("Task run time:"); TableItem(timeTaken) |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
819 cata("<tr>\n") |
3d04308a99f9
- Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents:
4
diff
changeset
|
820 cata("</table>\n") |
2 | 821 |
822 cata("</body>\n") | |
823 cata("</html>") |