annotate hairpinTool.R @ 4:f8af57d6f60b

Fixed bug causing fastq input to break - Moved misplaced error check causing fastq inputs to not function
author shian_su <registertonysu@gmail.com>
date Mon, 24 Feb 2014 14:41:39 +1100
parents 076ca575208f
children 3d04308a99f9
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 (inputType=="fastq") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
174
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
175 if (any(table(hairpins$ID)>1)){
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
176 tab <- table(hairpins$ID)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
177 offenders <- paste(names(tab[tab>1]), collapse=", ")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
178 stop("ID column of hairpin annotation must have unique values, values ",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
179 offenders, " are repeated")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
180 } # 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
181
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
182 } else if (inputType=="counts") {
4
f8af57d6f60b Fixed bug causing fastq input to break
shian_su <registertonysu@gmail.com>
parents: 2
diff changeset
183 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
184 stop("not all samples have groups specified")
f8af57d6f60b Fixed bug causing fastq input to break
shian_su <registertonysu@gmail.com>
parents: 2
diff changeset
185 } # Check that a group has be specifed for each sample
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
186
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
187 if (any(table(counts$ID)>1)){
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
188 tab <- table(counts$ID)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
189 offenders <- paste(names(tab[tab>1]), collapse=", ")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
190 stop("ID column of count table must have unique values, values ",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
191 offenders, " are repeated")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
192 } # Check that IDs in count table are unique
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
193 }
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 # Process arguments
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
197 if (workMode=="glm") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
198 if (roastOpt=="yes") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
199 wantRoast <- TRUE
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
200 } else {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
201 wantRoast <- FALSE
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
202 }
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 # Split up contrasts seperated by comma into a vector and replace spaces with
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
206 # periods
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
207 if (exists("contrastData")) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
208 contrastData <- unlist(strsplit(contrastData, split=","))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
209 contrastData <- sanitiseEquation(contrastData)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
210 contrastData <- gsub(" ", ".", contrastData, fixed=TRUE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
211 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
212
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
213 # Replace spaces with periods in pair data
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
214 if (exists("pairData")) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
215 pairData <- make.names(pairData)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
216 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
217
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
218 # Generate output folder and paths
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
219 dir.create(folderPath)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
220
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
221 # Generate links for outputs
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
222 imgOut("barHairpin")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
223 imgOut("barIndex")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
224 imgOut("mds")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
225 imgOut("bcv")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
226 if (workMode == "classic") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
227 smearPng <- makeOut(paste0("smear(", pairData[2], "-", pairData[1],").png"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
228 smearPdf <- makeOut(paste0("smear(", pairData[2], "-", pairData[1],").pdf"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
229 topOut <- makeOut(paste0("toptag(", pairData[2], "-", pairData[1],").tsv"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
230 } else if (workMode=="glm") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
231 smearPng <- character()
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
232 smearPdf <- character()
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
233 topOut <- character()
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
234 roastOut <- character()
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
235 barcodePng <- character()
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
236 barcodePdf <- character()
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
237 for (i in 1:length(contrastData)) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
238 smearPng[i] <- makeOut(paste0("smear(", contrastData[i], ").png"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
239 smearPdf[i] <- makeOut(paste0("smear(", contrastData[i], ").pdf"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
240 topOut[i] <- makeOut(paste0("toptag(", contrastData[i], ").tsv"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
241 roastOut[i] <- makeOut(paste0("roast(", contrastData[i], ").tsv"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
242 barcodePng[i] <- makeOut(paste0("barcode(", contrastData[i], ").png"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
243 barcodePdf[i] <- makeOut(paste0("barcode(", contrastData[i], ").pdf"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
244 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
245 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
246 # Initialise data for html links and images, table with the link label and
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
247 # link address
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
248 linkData <- data.frame(Label=character(), Link=character(),
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
249 stringsAsFactors=FALSE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
250 imageData <- data.frame(Label=character(), Link=character(),
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
251 stringsAsFactors=FALSE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
252 ################################################################################
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
253 ### Data Processing
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
254 ################################################################################
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
255
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
256 # Transform gene selection from string into index values for mroast
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
257 if (workMode=="glm") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
258 if (selectOpt=="rank") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
259 selectVals <- gsub(" ", "", selectVals, fixed=TRUE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
260 selectVals <- unlist(strsplit(selectVals, ","))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
261
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
262 for (i in 1:length(selectVals)) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
263 if (grepl(":", selectVals[i], fixed=TRUE)) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
264 temp <- unlist(strsplit(selectVals[i], ":"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
265 selectVals <- selectVals[-i]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
266 a <- as.numeric(temp[1])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
267 b <- as.numeric(temp[2])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
268 selectVals <- c(selectVals, a:b)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
269 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
270 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
271 selectVals <- as.numeric(unique(selectVals))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
272 } else {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
273 selectVals <- gsub(" ", "", selectVals, fixed=TRUE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
274 selectVals <- unlist(strsplit(selectVals, " "))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
275 }
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 if (inputType=="fastq") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
279 # Use EdgeR hairpin process and capture outputs
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
280 hpReadout <- capture.output(
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
281 data <- processHairpinReads(fastqPath, samplePath, hairpinPath,
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
282 hairpinStart=hpStart, hairpinEnd=hpEnd,
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
283 verbose=TRUE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
284 )
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
285
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
286 # Remove function output entries that show processing data or is empty
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
287 hpReadout <- hpReadout[hpReadout!=""]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
288 hpReadout <- hpReadout[!grepl("Processing", hpReadout)]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
289 hpReadout <- hpReadout[!grepl("in file", hpReadout)]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
290 hpReadout <- gsub(" -- ", "", hpReadout, fixed=TRUE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
291
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
292
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
293 # Make the names of groups syntactically valid (replace spaces with periods)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
294 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
295 } else if (inputType=="counts") {
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
296 # Process counts information, set ID column to be row names
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
297 rownames(counts) <- counts$ID
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
298 counts <- counts[ , !(colnames(counts)=="ID")]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
299 countsRows <- nrow(counts)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
300
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
301 # Process group information
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
302 factors <- samples$group[match(samples$ID, colnames(counts))]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
303 annoRows <- nrow(anno)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
304 anno <- anno[match(rownames(counts), anno$ID), ]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
305 annoMatched <- sum(!is.na(anno$ID))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
306
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
307 if (any(is.na(anno$ID))) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
308 warningStr <- paste("count table contained more hairpins than",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
309 "specified in hairpin annotation file")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
310 warning(warningStr)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
311 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
312
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
313 # Filter out rows with zero counts
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
314 sel <- rowSums(counts)!=0
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
315 counts <- counts[sel, ]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
316 anno <- anno[sel, ]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
317
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
318 # Create DGEList
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
319 data <- DGEList(counts=counts, lib.size=colSums(counts),
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
320 norm.factors=rep(1,ncol(counts)), genes=anno, group=factors)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
321
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
322 # Make the names of groups syntactically valid (replace spaces with periods)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
323 data$samples$group <- make.names(data$samples$group)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
324 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
325
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
326 # Filter hairpins with low counts
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
327 sel <- rowSums(cpm(data$counts) > cpmReq) >= sampleReq
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
328 data <- data[sel, ]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
329
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
330 # Estimate dispersions
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
331 data <- estimateDisp(data)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
332 commonBCV <- sqrt(data$common.dispersion)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
333
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
334 ################################################################################
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
335 ### Output Processing
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
336 ################################################################################
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
337
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
338 # Plot number of hairpins that could be matched per sample
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
339 png(barIndexPng, width=600, height=600)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
340 barplot(height<-colSums(data$counts), las=2, main="Counts per index",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
341 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
342 imageData[1, ] <- c("Counts per Index", "barIndex.png")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
343 invisible(dev.off())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
344
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
345 pdf(barIndexPdf)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
346 barplot(height<-colSums(data$counts), las=2, main="Counts per index",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
347 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
348 linkData[1, ] <- c("Counts per Index Barplot (.pdf)", "barIndex.pdf")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
349 invisible(dev.off())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
350
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
351 # Plot per hairpin totals across all samples
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
352 png(barHairpinPng, width=600, height=600)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
353 if (nrow(data$counts)<50) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
354 barplot(height<-rowSums(data$counts), las=2, main="Counts per hairpin",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
355 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
356 } else {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
357 barplot(height<-rowSums(data$counts), las=2, main="Counts per hairpin",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
358 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
359 names.arg=FALSE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
360 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
361 imageData <- rbind(imageData, c("Counts per Hairpin", "barHairpin.png"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
362 invisible(dev.off())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
363
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
364 pdf(barHairpinPdf)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
365 if (nrow(data$counts)<50) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
366 barplot(height<-rowSums(data$counts), las=2, main="Counts per hairpin",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
367 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
368 } else {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
369 barplot(height<-rowSums(data$counts), las=2, main="Counts per hairpin",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
370 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
371 names.arg=FALSE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
372 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
373 newEntry <- c("Counts per Hairpin Barplot (.pdf)", "barHairpin.pdf")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
374 linkData <- rbind(linkData, newEntry)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
375 invisible(dev.off())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
376
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
377 # Make an MDS plot to visualise relationships between replicate samples
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
378 png(mdsPng, width=600, height=600)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
379 plotMDS(data, labels=data$samples$group, col=as.numeric(data$samples$group),
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
380 main="MDS Plot")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
381 imageData <- rbind(imageData, c("MDS Plot", "mds.png"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
382 invisible(dev.off())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
383
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
384 pdf(mdsPdf)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
385 plotMDS(data, labels=data$samples$group, col=as.numeric(data$samples$group),
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
386 main="MDS Plot")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
387 newEntry <- c("MDS Plot (.pdf)", "mds.pdf")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
388 linkData <- rbind(linkData, newEntry)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
389 invisible(dev.off())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
390
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
391 if (workMode=="classic") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
392 # Assess differential representation using classic exact testing methodology
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
393 # in edgeR
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
394 testData <- exactTest(data, pair=pairData)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
395
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
396 top <- topTags(testData, n=Inf)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
397 topIDs <- top$table[(top$table$FDR < fdrThresh) &
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
398 (abs(top$table$logFC) > lfcThresh), 1]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
399 write.table(top, file=topOut, row.names=FALSE, sep="\t")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
400 linkName <- paste0("Top Tags Table(", pairData[2], "-", pairData[1],
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
401 ") (.tsv)")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
402 linkAddr <- paste0("toptag(", pairData[2], "-", pairData[1], ").tsv")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
403 linkData <- rbind(linkData, c(linkName, linkAddr))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
404
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
405 # Select hairpins with FDR < 0.05 to highlight on plot
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
406 png(smearPng, width=600, height=600)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
407 plotTitle <- gsub(".", " ",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
408 paste0("Smear Plot: ", pairData[2], "-", pairData[1]),
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
409 fixed = TRUE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
410 plotSmear(testData, de.tags=topIDs,
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
411 pch=20, cex=1.0, main=plotTitle)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
412 abline(h = c(-1, 0, 1), col = c("dodgerblue", "yellow", "dodgerblue"), lty=2)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
413 imgName <- paste0("Smear Plot(", pairData[2], "-", pairData[1], ")")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
414 imgAddr <- paste0("smear(", pairData[2], "-", pairData[1],").png")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
415 imageData <- rbind(imageData, c(imgName, imgAddr))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
416 invisible(dev.off())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
417
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
418 pdf(smearPdf)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
419 plotTitle <- gsub(".", " ",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
420 paste0("Smear Plot: ", pairData[2], "-", pairData[1]),
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
421 fixed = TRUE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
422 plotSmear(testData, de.tags=topIDs,
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
423 pch=20, cex=1.0, main=plotTitle)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
424 abline(h = c(-1, 0, 1), col = c("dodgerblue", "yellow", "dodgerblue"), lty=2)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
425 imgName <- paste0("Smear Plot(", pairData[2], "-", pairData[1], ") (.pdf)")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
426 imgAddr <- paste0("smear(", pairData[2], "-", pairData[1], ").pdf")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
427 linkData <- rbind(linkData, c(imgName, imgAddr))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
428 invisible(dev.off())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
429 } else if (workMode=="glm") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
430 # Generating design information
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
431 factors <- factor(data$sample$group)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
432 design <- model.matrix(~0+factors)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
433
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
434 colnames(design) <- gsub("factors", "", colnames(design), fixed=TRUE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
435
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
436 # Split up contrasts seperated by comma into a vector
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
437 contrastData <- unlist(strsplit(contrastData, split=","))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
438 for (i in 1:length(contrastData)) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
439 # Generate contrasts information
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
440 contrasts <- makeContrasts(contrasts=contrastData[i], levels=design)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
441
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
442 # Fit negative bionomial GLM
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
443 fit = glmFit(data, design)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
444 # Carry out Likelihood ratio test
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
445 testData = glmLRT(fit, contrast=contrasts)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
446
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
447 # Select hairpins with FDR < 0.05 to highlight on plot
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
448 top <- topTags(testData, n=Inf)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
449 topIDs <- top$table[(top$table$FDR < fdrThresh) &
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
450 (abs(top$table$logFC) > lfcThresh), 1]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
451 write.table(top, file=topOut[i], row.names=FALSE, sep="\t")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
452
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
453 linkName <- paste0("Top Tags Table(", contrastData[i], ") (.tsv)")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
454 linkAddr <- paste0("toptag(", contrastData[i], ").tsv")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
455 linkData <- rbind(linkData, c(linkName, linkAddr))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
456
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
457 # Make a plot of logFC versus logCPM
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
458 png(smearPng[i], height=600, width=600)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
459 plotTitle <- paste("Smear Plot:", gsub(".", " ", contrastData[i],
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
460 fixed=TRUE))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
461 plotSmear(testData, de.tags=topIDs, pch=20, cex=0.8, main=plotTitle)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
462 abline(h=c(-1, 0, 1), col=c("dodgerblue", "yellow", "dodgerblue"), lty=2)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
463
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
464 imgName <- paste0("Smear Plot(", contrastData[i], ")")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
465 imgAddr <- paste0("smear(", contrastData[i], ").png")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
466 imageData <- rbind(imageData, c(imgName, imgAddr))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
467 invisible(dev.off())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
468
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
469 pdf(smearPdf[i])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
470 plotTitle <- paste("Smear Plot:", gsub(".", " ", contrastData[i],
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
471 fixed=TRUE))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
472 plotSmear(testData, de.tags=topIDs, pch=20, cex=0.8, main=plotTitle)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
473 abline(h=c(-1, 0, 1), col=c("dodgerblue", "yellow", "dodgerblue"), lty=2)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
474
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
475 linkName <- paste0("Smear Plot(", contrastData[i], ") (.pdf)")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
476 linkAddr <- paste0("smear(", contrastData[i], ").pdf")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
477 linkData <- rbind(linkData, c(linkName, linkAddr))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
478 invisible(dev.off())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
479
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
480 genes <- as.character(data$genes$Gene)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
481 unq <- unique(genes)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
482 unq <- unq[!is.na(unq)]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
483 geneList <- list()
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
484 for (gene in unq) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
485 if (length(which(genes==gene)) >= hairpinReq) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
486 geneList[[gene]] <- which(genes==gene)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
487 }
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 if (wantRoast) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
491 # Input preparaton for roast
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
492 nrot = 9999
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
493 set.seed(602214129)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
494 roastData <- mroast(data, index=geneList, design=design,
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
495 contrast=contrasts, nrot=nrot)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
496 roastData <- cbind(GeneID=rownames(roastData), roastData)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
497 write.table(roastData, file=roastOut[i], row.names=FALSE, sep="\t")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
498 linkName <- paste0("Gene Level Analysis Table(", contrastData[i],
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
499 ") (.tsv)")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
500 linkAddr <- paste0("roast(", contrastData[i], ").tsv")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
501 linkData <- rbind(linkData, c(linkName, linkAddr))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
502 if (selectOpt=="rank") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
503 selectedGenes <- rownames(roastData)[selectVals]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
504 } else {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
505 selectedGenes <- selectVals
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
506 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
507
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
508 if (packageVersion("limma")<"3.19.19") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
509 png(barcodePng[i], width=600, height=length(selectedGenes)*150)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
510 } else {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
511 png(barcodePng[i], width=600, height=length(selectedGenes)*300)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
512 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
513 par(mfrow=c(length(selectedGenes), 1))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
514 for (gene in selectedGenes) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
515 barcodeplot(testData$table$logFC, index=geneList[[gene]],
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
516 main=paste("Barcode Plot for", gene, "(logFCs)",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
517 gsub(".", " ", contrastData[i])),
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
518 labels=c("Positive logFC", "Negative logFC"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
519 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
520 imgName <- paste0("Barcode Plot(", contrastData[i], ")")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
521 imgAddr <- paste0("barcode(", contrastData[i], ").png")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
522 imageData <- rbind(imageData, c(imgName, imgAddr))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
523 dev.off()
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
524 if (packageVersion("limma")<"3.19.19") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
525 pdf(barcodePdf[i], width=8, height=2)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
526 } else {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
527 pdf(barcodePdf[i], width=8, height=4)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
528 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
529 for (gene in selectedGenes) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
530 barcodeplot(testData$table$logFC, index=geneList[[gene]],
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
531 main=paste("Barcode Plot for", gene, "(logFCs)",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
532 gsub(".", " ", contrastData[i])),
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
533 labels=c("Positive logFC", "Negative logFC"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
534 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
535 linkName <- paste0("Barcode Plot(", contrastData[i], ") (.pdf)")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
536 linkAddr <- paste0("barcode(", contrastData[i], ").pdf")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
537 linkData <- rbind(linkData, c(linkName, linkAddr))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
538 dev.off()
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
539 }
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 # Record ending time
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
544 timeEnd <- as.character(Sys.time())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
545 ################################################################################
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
546 ### HTML Generation
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
547 ################################################################################
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
548 # Clear file
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
549 cat("", file=htmlPath)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
550
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
551 cata("<html>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
552 HtmlHead("EdgeR Output")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
553
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
554 cata("<body>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
555 cata("<h3>EdgeR Analysis Output:</h3>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
556 cata("<h4>Input Summary:</h4>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
557 if (inputType=="fastq") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
558 cata("<ul>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
559 ListItem(hpReadout[1])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
560 ListItem(hpReadout[2])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
561 cata("</ul>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
562 cata(hpReadout[3], "<br/>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
563 cata("<ul>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
564 ListItem(hpReadout[4])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
565 ListItem(hpReadout[7])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
566 cata("</ul>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
567 cata(hpReadout[8:11], sep="<br/>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
568 cata("<br />\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
569 cata("<b>Please check that read percentages are consistent with ")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
570 cata("expectations.</b><br >\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
571 } else if (inputType=="counts") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
572 cata("<ul>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
573 ListItem("Number of Samples: ", ncol(data$counts))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
574 ListItem("Number of Hairpins: ", countsRows)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
575 ListItem("Number of annotations provided: ", annoRows)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
576 ListItem("Number of annotations matched to hairpin: ", annoMatched)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
577 cata("</ul>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
578 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
579
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
580 cata("The estimated common biological coefficient of variation (BCV) is: ",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
581 commonBCV, "<br />\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
582
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
583 cata("<h4>Output:</h4>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
584 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
585 cata("exported in a pdf viewer to high resolution image format. <br/>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
586 for (i in 1:nrow(imageData)) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
587 if (grepl("barcode", imageData$Link[i])) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
588 if (packageVersion("limma")<"3.19.19") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
589 HtmlImage(imageData$Link[i], imageData$Label[i],
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
590 height=length(selectedGenes)*150)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
591 } else {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
592 HtmlImage(imageData$Link[i], imageData$Label[i],
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
593 height=length(selectedGenes)*300)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
594 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
595 } else {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
596 HtmlImage(imageData$Link[i], imageData$Label[i])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
597 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
598 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
599 cata("<br/>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
600
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
601 cata("<h4>Plots:</h4>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
602 for (i in 1:nrow(linkData)) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
603 if (!grepl(".tsv", linkData$Link[i])) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
604 HtmlLink(linkData$Link[i], linkData$Label[i])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
605 }
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 cata("<h4>Tables:</h4>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
609 for (i in 1:nrow(linkData)) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
610 if (grepl(".tsv", linkData$Link[i])) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
611 HtmlLink(linkData$Link[i], linkData$Label[i])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
612 }
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 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
616 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
617 cata("disk icon to download all files in a zip archive.</p>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
618 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
619 cata("or other spreadsheet programs</p>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
620 cata("<table border=\"0\">\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
621
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
622 cata("<tr>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
623 TableItem("Task started at:"); TableItem(timeStart)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
624 cata("</tr>\n")
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 TableItem("Task ended at:"); TableItem(timeEnd)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
627 cata("</tr>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
628
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
629 cata("</body>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
630 cata("</html>")