annotate hairpinTool.R @ 2:076ca575208f

First commit
author shian_su <registertonysu@gmail.com>
date Fri, 21 Feb 2014 12:52:56 +1100
parents
children f8af57d6f60b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
1 # Record starting time
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
2 timeStart <- as.character(Sys.time())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
3
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
4 # Loading and checking required packages
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
5 library(methods, quietly=TRUE, warn.conflicts=FALSE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
6 library(statmod, quietly=TRUE, warn.conflicts=FALSE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
7 library(splines, quietly=TRUE, warn.conflicts=FALSE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
8 library(edgeR, quietly=TRUE, warn.conflicts=FALSE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
9 library(limma, quietly=TRUE, warn.conflicts=FALSE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
10
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
11 if (packageVersion("edgeR") < "3.5.23") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
12 message("Please update 'edgeR' to version >= 3.5.23 to run this script")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
13 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
14
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
15 ################################################################################
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
16 ### Function declarations
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
17 ################################################################################
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
18
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
19 # Function to sanitise contrast equations so there are no whitespaces
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
20 # surrounding the arithmetic operators, leading or trailing whitespace
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
21 sanitiseEquation <- function(equation) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
22 equation <- gsub(" *[+] *", "+", equation)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
23 equation <- gsub(" *[-] *", "-", equation)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
24 equation <- gsub(" *[/] *", "/", equation)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
25 equation <- gsub(" *[*] *", "*", equation)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
26 equation <- gsub("^\\s+|\\s+$", "", equation)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
27 return(equation)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
28 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
29
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
30 # Function to sanitise group information
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
31 sanitiseGroups <- function(string) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
32 string <- gsub(" *[,] *", ",", string)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
33 string <- gsub("^\\s+|\\s+$", "", string)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
34 return(string)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
35 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
36
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
37 # Function to change periods to whitespace in a string
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
38 unmake.names <- function(string) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
39 string <- gsub(".", " ", string, fixed=TRUE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
40 return(string)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
41 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
42
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
43 # Function has string input and generates an output path string
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
44 makeOut <- function(filename) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
45 return(paste0(folderPath, "/", filename))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
46 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
47
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
48 # Function has string input and generates both a pdf and png output strings
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
49 imgOut <- function(filename) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
50 assign(paste0(filename, "Png"), makeOut(paste0(filename,".png")),
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
51 envir = .GlobalEnv)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
52 assign(paste0(filename, "Pdf"), makeOut(paste0(filename,".pdf")),
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
53 envir = .GlobalEnv)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
54 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
55
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
56 # Create cat function default path set, default seperator empty and appending
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
57 # true by default (Ripped straight from the cat function with altered argument
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
58 # defaults)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
59 cata <- function(..., file = htmlPath, sep = "", fill = FALSE, labels = NULL,
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
60 append = TRUE) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
61 if (is.character(file))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
62 if (file == "")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
63 file <- stdout()
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
64 else if (substring(file, 1L, 1L) == "|") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
65 file <- pipe(substring(file, 2L), "w")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
66 on.exit(close(file))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
67 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
68 else {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
69 file <- file(file, ifelse(append, "a", "w"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
70 on.exit(close(file))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
71 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
72 .Internal(cat(list(...), file, sep, fill, labels, append))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
73 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
74
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
75 # Function to write code for html head and title
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
76 HtmlHead <- function(title) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
77 cata("<head>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
78 cata("<title>", title, "</title>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
79 cata("</head>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
80 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
81
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
82 # Function to write code for html links
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
83 HtmlLink <- function(address, label=address) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
84 cata("<a href=\"", address, "\" target=\"_blank\">", label, "</a><br />\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
85 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
86
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
87 # Function to write code for html images
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
88 HtmlImage <- function(source, label=source, height=600, width=600) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
89 cata("<img src=\"", source, "\" alt=\"", label, "\" height=\"", height)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
90 cata("\" width=\"", width, "\"/>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
91 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
92
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
93 # Function to write code for html list items
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
94 ListItem <- function(...) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
95 cata("<li>", ..., "</li>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
96 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
97
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
98 TableItem <- function(...) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
99 cata("<td>", ..., "</td>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
100 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
101
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
102 TableHeadItem <- function(...) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
103 cata("<th>", ..., "</th>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
104 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
105 ################################################################################
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
106 ### Input Processing
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
107 ################################################################################
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
108
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
109 # Grabbing arguments from command line
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
110 argv <- commandArgs(TRUE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
111
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
112 # Remove fastq file paths after collecting from argument vector
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
113 inputType <- as.character(argv[1])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
114 if (inputType=="fastq") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
115 fastqPath <- as.character(gsub("fastq::", "", argv[grepl("fastq::", argv)],
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
116 fixed=TRUE))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
117 argv <- argv[!grepl("fastq::", argv, fixed=TRUE)]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
118 hairpinPath <- as.character(argv[2])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
119 samplePath <- as.character(argv[3])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
120 barStart <- as.numeric(argv[4])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
121 barEnd <- as.numeric(argv[5])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
122 hpStart <- as.numeric(argv[6])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
123 hpEnd <- as.numeric(argv[7])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
124 } else if (inputType=="counts") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
125 countPath <- as.character(argv[2])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
126 annoPath <- as.character(argv[3])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
127 samplePath <- as.character(argv[4])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
128 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
129
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
130 cpmReq <- as.numeric(argv[8])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
131 sampleReq <- as.numeric(argv[9])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
132 fdrThresh <- as.numeric(argv[10])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
133 lfcThresh <- as.numeric(argv[11])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
134 workMode <- as.character(argv[12])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
135 htmlPath <- as.character(argv[13])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
136 folderPath <- as.character(argv[14])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
137 if (workMode=="classic") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
138 pairData <- character()
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
139 pairData[2] <- as.character(argv[15])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
140 pairData[1] <- as.character(argv[16])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
141 } else if (workMode=="glm") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
142 contrastData <- as.character(argv[15])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
143 roastOpt <- as.character(argv[16])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
144 hairpinReq <- as.numeric(argv[17])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
145 selectOpt <- as.character(argv[18])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
146 selectVals <- as.character(argv[19])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
147 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
148
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
149 # Read in inputs
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
150 if (inputType=="fastq") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
151 samples <- read.table(samplePath, header=TRUE, sep="\t")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
152 hairpins <- read.table(hairpinPath, header=TRUE, sep="\t")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
153 } else if (inputType=="counts") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
154 samples <- read.table(samplePath, header=TRUE, sep="\t")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
155 counts <- read.table(countPath, header=TRUE, sep="\t")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
156 anno <- read.table(annoPath, header=TRUE, sep="\t")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
157 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
158 ###################### Check inputs for correctness ############################
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
159 samples$ID <- make.names(samples$ID)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
160
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
161 if (!any(grepl("group", names(samples)))) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
162 stop("'group' column not specified in sample annotation file")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
163 } # Check if grouping variable has been specified
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
164
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
165 if (any(table(samples$ID)>1)){
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
166 tab <- table(samples$ID)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
167 offenders <- paste(names(tab[tab>1]), collapse=", ")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
168 offenders <- unmake.names(offenders)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
169 stop("ID column of sample annotation must have unique values, values ",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
170 offenders, " are repeated")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
171 } # Check that IDs in sample annotation are unique
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
172
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
173 if (any(is.na(match(samples$ID, colnames(counts))))) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
174 stop("not all samples have groups specified")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
175 } # Check that a group has be specifed for each sample
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
176
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
177 if (inputType=="fastq") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
178
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
179 if (any(table(hairpins$ID)>1)){
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
180 tab <- table(hairpins$ID)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
181 offenders <- paste(names(tab[tab>1]), collapse=", ")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
182 stop("ID column of hairpin annotation must have unique values, values ",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
183 offenders, " are repeated")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
184 } # Check that IDs in hairpin annotation are unique
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
185
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
186 } else if (inputType=="counts") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
187
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
188 if (any(table(counts$ID)>1)){
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
189 tab <- table(counts$ID)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
190 offenders <- paste(names(tab[tab>1]), collapse=", ")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
191 stop("ID column of count table must have unique values, values ",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
192 offenders, " are repeated")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
193 } # Check that IDs in count table are unique
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
194 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
195 ################################################################################
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
196
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
197 # Process arguments
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
198 if (workMode=="glm") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
199 if (roastOpt=="yes") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
200 wantRoast <- TRUE
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
201 } else {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
202 wantRoast <- FALSE
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
203 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
204 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
205
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
206 # Split up contrasts seperated by comma into a vector and replace spaces with
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
207 # periods
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
208 if (exists("contrastData")) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
209 contrastData <- unlist(strsplit(contrastData, split=","))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
210 contrastData <- sanitiseEquation(contrastData)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
211 contrastData <- gsub(" ", ".", contrastData, fixed=TRUE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
212 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
213
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
214 # Replace spaces with periods in pair data
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
215 if (exists("pairData")) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
216 pairData <- make.names(pairData)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
217 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
218
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
219 # Generate output folder and paths
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
220 dir.create(folderPath)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
221
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
222 # Generate links for outputs
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
223 imgOut("barHairpin")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
224 imgOut("barIndex")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
225 imgOut("mds")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
226 imgOut("bcv")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
227 if (workMode == "classic") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
228 smearPng <- makeOut(paste0("smear(", pairData[2], "-", pairData[1],").png"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
229 smearPdf <- makeOut(paste0("smear(", pairData[2], "-", pairData[1],").pdf"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
230 topOut <- makeOut(paste0("toptag(", pairData[2], "-", pairData[1],").tsv"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
231 } else if (workMode=="glm") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
232 smearPng <- character()
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
233 smearPdf <- character()
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
234 topOut <- character()
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
235 roastOut <- character()
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
236 barcodePng <- character()
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
237 barcodePdf <- character()
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
238 for (i in 1:length(contrastData)) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
239 smearPng[i] <- makeOut(paste0("smear(", contrastData[i], ").png"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
240 smearPdf[i] <- makeOut(paste0("smear(", contrastData[i], ").pdf"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
241 topOut[i] <- makeOut(paste0("toptag(", contrastData[i], ").tsv"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
242 roastOut[i] <- makeOut(paste0("roast(", contrastData[i], ").tsv"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
243 barcodePng[i] <- makeOut(paste0("barcode(", contrastData[i], ").png"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
244 barcodePdf[i] <- makeOut(paste0("barcode(", contrastData[i], ").pdf"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
245 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
246 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
247 # Initialise data for html links and images, table with the link label and
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
248 # link address
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
249 linkData <- data.frame(Label=character(), Link=character(),
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
250 stringsAsFactors=FALSE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
251 imageData <- data.frame(Label=character(), Link=character(),
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
252 stringsAsFactors=FALSE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
253 ################################################################################
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
254 ### Data Processing
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
255 ################################################################################
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
256
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
257 # Transform gene selection from string into index values for mroast
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
258 if (workMode=="glm") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
259 if (selectOpt=="rank") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
260 selectVals <- gsub(" ", "", selectVals, fixed=TRUE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
261 selectVals <- unlist(strsplit(selectVals, ","))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
262
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
263 for (i in 1:length(selectVals)) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
264 if (grepl(":", selectVals[i], fixed=TRUE)) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
265 temp <- unlist(strsplit(selectVals[i], ":"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
266 selectVals <- selectVals[-i]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
267 a <- as.numeric(temp[1])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
268 b <- as.numeric(temp[2])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
269 selectVals <- c(selectVals, a:b)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
270 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
271 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
272 selectVals <- as.numeric(unique(selectVals))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
273 } else {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
274 selectVals <- gsub(" ", "", selectVals, fixed=TRUE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
275 selectVals <- unlist(strsplit(selectVals, " "))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
276 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
277 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
278
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
279 if (inputType=="fastq") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
280 # Use EdgeR hairpin process and capture outputs
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
281 hpReadout <- capture.output(
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
282 data <- processHairpinReads(fastqPath, samplePath, hairpinPath,
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
283 hairpinStart=hpStart, hairpinEnd=hpEnd,
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
284 verbose=TRUE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
285 )
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
286
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
287 # Remove function output entries that show processing data or is empty
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
288 hpReadout <- hpReadout[hpReadout!=""]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
289 hpReadout <- hpReadout[!grepl("Processing", hpReadout)]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
290 hpReadout <- hpReadout[!grepl("in file", hpReadout)]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
291 hpReadout <- gsub(" -- ", "", hpReadout, fixed=TRUE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
292
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
293
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
294 # Make the names of groups syntactically valid (replace spaces with periods)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
295 data$samples$group <- make.names(data$samples$group)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
296 } else {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
297 # Process counts information, set ID column to be row names
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
298 rownames(counts) <- counts$ID
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
299 counts <- counts[ , !(colnames(counts)=="ID")]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
300 countsRows <- nrow(counts)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
301
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
302 # Process group information
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
303 factors <- samples$group[match(samples$ID, colnames(counts))]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
304 annoRows <- nrow(anno)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
305 anno <- anno[match(rownames(counts), anno$ID), ]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
306 annoMatched <- sum(!is.na(anno$ID))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
307
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
308 if (any(is.na(anno$ID))) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
309 warningStr <- paste("count table contained more hairpins than",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
310 "specified in hairpin annotation file")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
311 warning(warningStr)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
312 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
313
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
314 # Filter out rows with zero counts
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
315 sel <- rowSums(counts)!=0
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
316 counts <- counts[sel, ]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
317 anno <- anno[sel, ]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
318
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
319 # Create DGEList
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
320 data <- DGEList(counts=counts, lib.size=colSums(counts),
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
321 norm.factors=rep(1,ncol(counts)), genes=anno, group=factors)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
322
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
323 # Make the names of groups syntactically valid (replace spaces with periods)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
324 data$samples$group <- make.names(data$samples$group)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
325 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
326
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
327 # Filter hairpins with low counts
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
328 sel <- rowSums(cpm(data$counts) > cpmReq) >= sampleReq
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
329 data <- data[sel, ]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
330
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
331 # Estimate dispersions
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
332 data <- estimateDisp(data)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
333 commonBCV <- sqrt(data$common.dispersion)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
334
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
335 ################################################################################
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
336 ### Output Processing
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
337 ################################################################################
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
338
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
339 # Plot number of hairpins that could be matched per sample
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
340 png(barIndexPng, width=600, height=600)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
341 barplot(height<-colSums(data$counts), las=2, main="Counts per index",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
342 cex.names=1.0, cex.axis=0.8, ylim=c(0, max(height)*1.2))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
343 imageData[1, ] <- c("Counts per Index", "barIndex.png")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
344 invisible(dev.off())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
345
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
346 pdf(barIndexPdf)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
347 barplot(height<-colSums(data$counts), las=2, main="Counts per index",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
348 cex.names=1.0, cex.axis=0.8, ylim=c(0, max(height)*1.2))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
349 linkData[1, ] <- c("Counts per Index Barplot (.pdf)", "barIndex.pdf")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
350 invisible(dev.off())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
351
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
352 # Plot per hairpin totals across all samples
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
353 png(barHairpinPng, width=600, height=600)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
354 if (nrow(data$counts)<50) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
355 barplot(height<-rowSums(data$counts), las=2, main="Counts per hairpin",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
356 cex.names=0.8, cex.axis=0.8, ylim=c(0, max(height)*1.2))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
357 } else {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
358 barplot(height<-rowSums(data$counts), las=2, main="Counts per hairpin",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
359 cex.names=0.8, cex.axis=0.8, ylim=c(0, max(height)*1.2),
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
360 names.arg=FALSE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
361 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
362 imageData <- rbind(imageData, c("Counts per Hairpin", "barHairpin.png"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
363 invisible(dev.off())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
364
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
365 pdf(barHairpinPdf)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
366 if (nrow(data$counts)<50) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
367 barplot(height<-rowSums(data$counts), las=2, main="Counts per hairpin",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
368 cex.names=0.8, cex.axis=0.8, ylim=c(0, max(height)*1.2))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
369 } else {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
370 barplot(height<-rowSums(data$counts), las=2, main="Counts per hairpin",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
371 cex.names=0.8, cex.axis=0.8, ylim=c(0, max(height)*1.2),
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
372 names.arg=FALSE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
373 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
374 newEntry <- c("Counts per Hairpin Barplot (.pdf)", "barHairpin.pdf")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
375 linkData <- rbind(linkData, newEntry)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
376 invisible(dev.off())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
377
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
378 # Make an MDS plot to visualise relationships between replicate samples
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
379 png(mdsPng, width=600, height=600)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
380 plotMDS(data, labels=data$samples$group, col=as.numeric(data$samples$group),
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
381 main="MDS Plot")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
382 imageData <- rbind(imageData, c("MDS Plot", "mds.png"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
383 invisible(dev.off())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
384
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
385 pdf(mdsPdf)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
386 plotMDS(data, labels=data$samples$group, col=as.numeric(data$samples$group),
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
387 main="MDS Plot")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
388 newEntry <- c("MDS Plot (.pdf)", "mds.pdf")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
389 linkData <- rbind(linkData, newEntry)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
390 invisible(dev.off())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
391
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
392 if (workMode=="classic") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
393 # Assess differential representation using classic exact testing methodology
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
394 # in edgeR
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
395 testData <- exactTest(data, pair=pairData)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
396
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
397 top <- topTags(testData, n=Inf)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
398 topIDs <- top$table[(top$table$FDR < fdrThresh) &
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
399 (abs(top$table$logFC) > lfcThresh), 1]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
400 write.table(top, file=topOut, row.names=FALSE, sep="\t")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
401 linkName <- paste0("Top Tags Table(", pairData[2], "-", pairData[1],
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
402 ") (.tsv)")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
403 linkAddr <- paste0("toptag(", pairData[2], "-", pairData[1], ").tsv")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
404 linkData <- rbind(linkData, c(linkName, linkAddr))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
405
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
406 # Select hairpins with FDR < 0.05 to highlight on plot
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
407 png(smearPng, width=600, height=600)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
408 plotTitle <- gsub(".", " ",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
409 paste0("Smear Plot: ", pairData[2], "-", pairData[1]),
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
410 fixed = TRUE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
411 plotSmear(testData, de.tags=topIDs,
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
412 pch=20, cex=1.0, main=plotTitle)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
413 abline(h = c(-1, 0, 1), col = c("dodgerblue", "yellow", "dodgerblue"), lty=2)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
414 imgName <- paste0("Smear Plot(", pairData[2], "-", pairData[1], ")")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
415 imgAddr <- paste0("smear(", pairData[2], "-", pairData[1],").png")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
416 imageData <- rbind(imageData, c(imgName, imgAddr))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
417 invisible(dev.off())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
418
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
419 pdf(smearPdf)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
420 plotTitle <- gsub(".", " ",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
421 paste0("Smear Plot: ", pairData[2], "-", pairData[1]),
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
422 fixed = TRUE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
423 plotSmear(testData, de.tags=topIDs,
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
424 pch=20, cex=1.0, main=plotTitle)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
425 abline(h = c(-1, 0, 1), col = c("dodgerblue", "yellow", "dodgerblue"), lty=2)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
426 imgName <- paste0("Smear Plot(", pairData[2], "-", pairData[1], ") (.pdf)")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
427 imgAddr <- paste0("smear(", pairData[2], "-", pairData[1], ").pdf")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
428 linkData <- rbind(linkData, c(imgName, imgAddr))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
429 invisible(dev.off())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
430 } else if (workMode=="glm") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
431 # Generating design information
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
432 factors <- factor(data$sample$group)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
433 design <- model.matrix(~0+factors)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
434
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
435 colnames(design) <- gsub("factors", "", colnames(design), fixed=TRUE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
436
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
437 # Split up contrasts seperated by comma into a vector
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
438 contrastData <- unlist(strsplit(contrastData, split=","))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
439 for (i in 1:length(contrastData)) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
440 # Generate contrasts information
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
441 contrasts <- makeContrasts(contrasts=contrastData[i], levels=design)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
442
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
443 # Fit negative bionomial GLM
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
444 fit = glmFit(data, design)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
445 # Carry out Likelihood ratio test
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
446 testData = glmLRT(fit, contrast=contrasts)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
447
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
448 # Select hairpins with FDR < 0.05 to highlight on plot
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
449 top <- topTags(testData, n=Inf)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
450 topIDs <- top$table[(top$table$FDR < fdrThresh) &
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
451 (abs(top$table$logFC) > lfcThresh), 1]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
452 write.table(top, file=topOut[i], row.names=FALSE, sep="\t")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
453
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
454 linkName <- paste0("Top Tags Table(", contrastData[i], ") (.tsv)")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
455 linkAddr <- paste0("toptag(", contrastData[i], ").tsv")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
456 linkData <- rbind(linkData, c(linkName, linkAddr))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
457
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
458 # Make a plot of logFC versus logCPM
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
459 png(smearPng[i], height=600, width=600)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
460 plotTitle <- paste("Smear Plot:", gsub(".", " ", contrastData[i],
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
461 fixed=TRUE))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
462 plotSmear(testData, de.tags=topIDs, pch=20, cex=0.8, main=plotTitle)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
463 abline(h=c(-1, 0, 1), col=c("dodgerblue", "yellow", "dodgerblue"), lty=2)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
464
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
465 imgName <- paste0("Smear Plot(", contrastData[i], ")")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
466 imgAddr <- paste0("smear(", contrastData[i], ").png")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
467 imageData <- rbind(imageData, c(imgName, imgAddr))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
468 invisible(dev.off())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
469
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
470 pdf(smearPdf[i])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
471 plotTitle <- paste("Smear Plot:", gsub(".", " ", contrastData[i],
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
472 fixed=TRUE))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
473 plotSmear(testData, de.tags=topIDs, pch=20, cex=0.8, main=plotTitle)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
474 abline(h=c(-1, 0, 1), col=c("dodgerblue", "yellow", "dodgerblue"), lty=2)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
475
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
476 linkName <- paste0("Smear Plot(", contrastData[i], ") (.pdf)")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
477 linkAddr <- paste0("smear(", contrastData[i], ").pdf")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
478 linkData <- rbind(linkData, c(linkName, linkAddr))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
479 invisible(dev.off())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
480
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
481 genes <- as.character(data$genes$Gene)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
482 unq <- unique(genes)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
483 unq <- unq[!is.na(unq)]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
484 geneList <- list()
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
485 for (gene in unq) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
486 if (length(which(genes==gene)) >= hairpinReq) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
487 geneList[[gene]] <- which(genes==gene)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
488 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
489 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
490
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
491 if (wantRoast) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
492 # Input preparaton for roast
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
493 nrot = 9999
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
494 set.seed(602214129)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
495 roastData <- mroast(data, index=geneList, design=design,
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
496 contrast=contrasts, nrot=nrot)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
497 roastData <- cbind(GeneID=rownames(roastData), roastData)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
498 write.table(roastData, file=roastOut[i], row.names=FALSE, sep="\t")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
499 linkName <- paste0("Gene Level Analysis Table(", contrastData[i],
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
500 ") (.tsv)")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
501 linkAddr <- paste0("roast(", contrastData[i], ").tsv")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
502 linkData <- rbind(linkData, c(linkName, linkAddr))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
503 if (selectOpt=="rank") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
504 selectedGenes <- rownames(roastData)[selectVals]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
505 } else {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
506 selectedGenes <- selectVals
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
507 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
508
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
509 if (packageVersion("limma")<"3.19.19") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
510 png(barcodePng[i], width=600, height=length(selectedGenes)*150)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
511 } else {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
512 png(barcodePng[i], width=600, height=length(selectedGenes)*300)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
513 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
514 par(mfrow=c(length(selectedGenes), 1))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
515 for (gene in selectedGenes) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
516 barcodeplot(testData$table$logFC, index=geneList[[gene]],
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
517 main=paste("Barcode Plot for", gene, "(logFCs)",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
518 gsub(".", " ", contrastData[i])),
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
519 labels=c("Positive logFC", "Negative logFC"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
520 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
521 imgName <- paste0("Barcode Plot(", contrastData[i], ")")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
522 imgAddr <- paste0("barcode(", contrastData[i], ").png")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
523 imageData <- rbind(imageData, c(imgName, imgAddr))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
524 dev.off()
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
525 if (packageVersion("limma")<"3.19.19") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
526 pdf(barcodePdf[i], width=8, height=2)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
527 } else {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
528 pdf(barcodePdf[i], width=8, height=4)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
529 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
530 for (gene in selectedGenes) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
531 barcodeplot(testData$table$logFC, index=geneList[[gene]],
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
532 main=paste("Barcode Plot for", gene, "(logFCs)",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
533 gsub(".", " ", contrastData[i])),
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
534 labels=c("Positive logFC", "Negative logFC"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
535 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
536 linkName <- paste0("Barcode Plot(", contrastData[i], ") (.pdf)")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
537 linkAddr <- paste0("barcode(", contrastData[i], ").pdf")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
538 linkData <- rbind(linkData, c(linkName, linkAddr))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
539 dev.off()
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
540 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
541 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
542 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
543
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
544 # Record ending time
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
545 timeEnd <- as.character(Sys.time())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
546 ################################################################################
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
547 ### HTML Generation
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
548 ################################################################################
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
549 # Clear file
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
550 cat("", file=htmlPath)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
551
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
552 cata("<html>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
553 HtmlHead("EdgeR Output")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
554
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
555 cata("<body>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
556 cata("<h3>EdgeR Analysis Output:</h3>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
557 cata("<h4>Input Summary:</h4>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
558 if (inputType=="fastq") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
559 cata("<ul>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
560 ListItem(hpReadout[1])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
561 ListItem(hpReadout[2])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
562 cata("</ul>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
563 cata(hpReadout[3], "<br/>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
564 cata("<ul>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
565 ListItem(hpReadout[4])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
566 ListItem(hpReadout[7])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
567 cata("</ul>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
568 cata(hpReadout[8:11], sep="<br/>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
569 cata("<br />\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
570 cata("<b>Please check that read percentages are consistent with ")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
571 cata("expectations.</b><br >\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
572 } else if (inputType=="counts") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
573 cata("<ul>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
574 ListItem("Number of Samples: ", ncol(data$counts))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
575 ListItem("Number of Hairpins: ", countsRows)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
576 ListItem("Number of annotations provided: ", annoRows)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
577 ListItem("Number of annotations matched to hairpin: ", annoMatched)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
578 cata("</ul>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
579 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
580
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
581 cata("The estimated common biological coefficient of variation (BCV) is: ",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
582 commonBCV, "<br />\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
583
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
584 cata("<h4>Output:</h4>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
585 cata("All images displayed have PDF copy at the bottom of the page, these can ")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
586 cata("exported in a pdf viewer to high resolution image format. <br/>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
587 for (i in 1:nrow(imageData)) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
588 if (grepl("barcode", imageData$Link[i])) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
589 if (packageVersion("limma")<"3.19.19") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
590 HtmlImage(imageData$Link[i], imageData$Label[i],
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
591 height=length(selectedGenes)*150)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
592 } else {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
593 HtmlImage(imageData$Link[i], imageData$Label[i],
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
594 height=length(selectedGenes)*300)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
595 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
596 } else {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
597 HtmlImage(imageData$Link[i], imageData$Label[i])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
598 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
599 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
600 cata("<br/>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
601
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
602 cata("<h4>Plots:</h4>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
603 for (i in 1:nrow(linkData)) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
604 if (!grepl(".tsv", linkData$Link[i])) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
605 HtmlLink(linkData$Link[i], linkData$Label[i])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
606 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
607 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
608
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
609 cata("<h4>Tables:</h4>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
610 for (i in 1:nrow(linkData)) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
611 if (grepl(".tsv", linkData$Link[i])) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
612 HtmlLink(linkData$Link[i], linkData$Label[i])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
613 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
614 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
615
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
616 cata("<p>alt-click any of the links to download the file, or click the name ")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
617 cata("of this task in the galaxy history panel and click on the floppy ")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
618 cata("disk icon to download all files in a zip archive.</p>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
619 cata("<p>.tsv files are tab seperated files that can be viewed using Excel ")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
620 cata("or other spreadsheet programs</p>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
621 cata("<table border=\"0\">\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
622
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
623 cata("<tr>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
624 TableItem("Task started at:"); TableItem(timeStart)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
625 cata("</tr>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
626 cata("<tr>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
627 TableItem("Task ended at:"); TableItem(timeEnd)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
628 cata("</tr>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
629
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
630 cata("</body>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
631 cata("</html>")