annotate hairpinTool.R @ 15:5a917ea5bed2

- Fixed read requirement report statistic.
author shian_su <registertonysu@gmail.com>
date Mon, 12 Jan 2015 16:31:48 +1100
parents 7aaa9bc23e3c
children 525bf4364896
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1 # ARGS: 1.inputType -String specifying format of input (fastq or table)
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
2 # IF inputType is "fastq" or "pairedFastq:
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
3 # 2*.fastqPath -One or more strings specifying path to fastq files
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
4 # 2.annoPath -String specifying path to hairpin annotation table
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
5 # 3.samplePath -String specifying path to sample annotation table
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
6 # 4.barStart -Integer specifying starting position of barcode
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
7 # 5.barEnd -Integer specifying ending position of barcode
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
8 # ###
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
9 # IF inputType is "pairedFastq":
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
10 # 6.barStartRev -Integer specifying starting position of barcode
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
11 # on reverse end
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
12 # 7.barEndRev -Integer specifying ending position of barcode
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
13 # on reverse end
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
14 # ###
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
15 # 8.hpStart -Integer specifying startins position of hairpin
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
16 # unique region
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
17 # 9.hpEnd -Integer specifying ending position of hairpin
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
18 # unique region
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
19 # IF inputType is "counts":
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
20 # 2.countPath -String specifying path to count table
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
21 # 3.annoPath -String specifying path to hairpin annotation table
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
22 # 4.samplePath -String specifying path to sample annotation table
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
23 # ###
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
24 # 10.secFactName -String specifying name of secondary factor
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
25 # 11.cpmReq -Float specifying cpm requirement
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
26 # 12.sampleReq -Integer specifying cpm requirement
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
27 # 13.readReq -Integer specifying read requirement
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
28 # 14.fdrThresh -Float specifying the FDR requirement
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
29 # 15.lfcThresh -Float specifying the log-fold-change requirement
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
30 # 16.workMode -String specifying exact test or GLM usage
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
31 # 17.htmlPath -String specifying path to HTML file
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
32 # 18.folderPath -String specifying path to folder for output
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
33 # IF workMode is "classic" (exact test)
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
34 # 19.pairData[2] -String specifying first group for exact test
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
35 # 20.pairData[1] -String specifying second group for exact test
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
36 # ###
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
37 # IF workMode is "glm"
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
38 # 19.contrastData -String specifying contrasts to be made
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
39 # 20.roastOpt -String specifying usage of gene-wise tests
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
40 # 21.hairpinReq -String specifying hairpin requirement for gene-
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
41 # wise test
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
42 # 22.selectOpt -String specifying type of selection for barcode
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
43 # plots
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
44 # 23.selectVals -String specifying members selected for barcode
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
45 # plots
9
f1076bfb0ed1 - Fixed tool to actually make use of barcode location options
shian_su <registertonysu@gmail.com>
parents: 8
diff changeset
46 # ###
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
47 #
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
48 # OUT: Bar Plot of Counts Per Index
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
49 # Bar Plot of Counts Per Hairpin
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
50 # MDS Plot
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
51 # BCV Plot
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
52 # Smear Plot
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
53 # Barcode Plots (If Genewise testing was selected)
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
54 # Top Expression Table
7
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
55 # Feature Counts Table
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
56 # HTML file linking to the ouputs
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
57 #
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
58 # Author: Shian Su - registertonysu@gmail.com - Jan 2014
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
59
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
60 # Record starting time
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
61 timeStart <- as.character(Sys.time())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
62
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
63 # Loading and checking required packages
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
64 library(methods, quietly=TRUE, warn.conflicts=FALSE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
65 library(statmod, quietly=TRUE, warn.conflicts=FALSE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
66 library(splines, quietly=TRUE, warn.conflicts=FALSE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
67 library(edgeR, quietly=TRUE, warn.conflicts=FALSE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
68 library(limma, quietly=TRUE, warn.conflicts=FALSE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
69
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
70 if (packageVersion("edgeR") < "3.7.17") {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
71 stop("Please update 'edgeR' to version >= 3.7.17 to run this tool")
8
548802b3492f Version 1.0.9
shian_su <registertonysu@gmail.com>
parents: 7
diff changeset
72 }
548802b3492f Version 1.0.9
shian_su <registertonysu@gmail.com>
parents: 7
diff changeset
73
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
74 if (packageVersion("limma")<"3.21.16") {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
75 message("Update 'limma' to version >= 3.21.16 to see updated barcode graphs")
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
76 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
77
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
78 ################################################################################
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
79 ### Function declarations
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
80 ################################################################################
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
81
7
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
82 # Function to load libaries without messages
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
83 silentLibrary <- function(...) {
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
84 list <- c(...)
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
85 for (package in list){
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
86 suppressPackageStartupMessages(library(package, character.only=TRUE))
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
87 }
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
88 }
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
89
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
90 # Function to sanitise contrast equations so there are no whitespaces
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
91 # surrounding the arithmetic operators, leading or trailing whitespace
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
92 sanitiseEquation <- function(equation) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
93 equation <- gsub(" *[+] *", "+", equation)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
94 equation <- gsub(" *[-] *", "-", equation)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
95 equation <- gsub(" *[/] *", "/", equation)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
96 equation <- gsub(" *[*] *", "*", equation)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
97 equation <- gsub("^\\s+|\\s+$", "", equation)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
98 return(equation)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
99 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
100
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
101 # Function to sanitise group information
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
102 sanitiseGroups <- function(string) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
103 string <- gsub(" *[,] *", ",", string)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
104 string <- gsub("^\\s+|\\s+$", "", string)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
105 return(string)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
106 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
107
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
108 # Function to change periods to whitespace in a string
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
109 unmake.names <- function(string) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
110 string <- gsub(".", " ", string, fixed=TRUE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
111 return(string)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
112 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
113
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
114 # Function has string input and generates an output path string
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
115 makeOut <- function(filename) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
116 return(paste0(folderPath, "/", filename))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
117 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
118
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
119 # Function has string input and generates both a pdf and png output strings
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
120 imgOut <- function(filename) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
121 assign(paste0(filename, "Png"), makeOut(paste0(filename,".png")),
7
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
122 envir=.GlobalEnv)
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
123 assign(paste0(filename, "Pdf"), makeOut(paste0(filename,".pdf")),
7
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
124 envir=.GlobalEnv)
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
125 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
126
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
127 # Create cat function default path set, default seperator empty and appending
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
128 # true by default (Ripped straight from the cat function with altered argument
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
129 # defaults)
7
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
130 cata <- function(..., file=htmlPath, sep="", fill=FALSE, labels=NULL,
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
131 append=TRUE) {
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
132 if (is.character(file))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
133 if (file == "")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
134 file <- stdout()
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
135 else if (substring(file, 1L, 1L) == "|") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
136 file <- pipe(substring(file, 2L), "w")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
137 on.exit(close(file))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
138 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
139 else {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
140 file <- file(file, ifelse(append, "a", "w"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
141 on.exit(close(file))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
142 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
143 .Internal(cat(list(...), file, sep, fill, labels, append))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
144 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
145
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
146 # Function to write code for html head and title
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
147 HtmlHead <- function(title) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
148 cata("<head>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
149 cata("<title>", title, "</title>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
150 cata("</head>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
151 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
152
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
153 # Function to write code for html links
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
154 HtmlLink <- function(address, label=address) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
155 cata("<a href=\"", address, "\" target=\"_blank\">", label, "</a><br />\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
156 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
157
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
158 # Function to write code for html images
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
159 HtmlImage <- function(source, label=source, height=600, width=600) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
160 cata("<img src=\"", source, "\" alt=\"", label, "\" height=\"", height)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
161 cata("\" width=\"", width, "\"/>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
162 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
163
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
164 # Function to write code for html list items
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
165 ListItem <- function(...) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
166 cata("<li>", ..., "</li>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
167 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
168
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
169 TableItem <- function(...) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
170 cata("<td>", ..., "</td>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
171 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
172
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
173 TableHeadItem <- function(...) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
174 cata("<th>", ..., "</th>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
175 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
176 ################################################################################
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
177 ### Input Processing
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
178 ################################################################################
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
179
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
180 # Grabbing arguments from command line
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
181 argv <- commandArgs(TRUE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
182
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
183 inputType <- as.character(argv[1])
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
184 if (inputType == "fastq") {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
185
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
186 fastqPath <- as.character(gsub("fastq::", "", argv[grepl("fastq::", argv)],
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
187 fixed=TRUE))
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
188
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
189 # Remove fastq paths
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
190 argv <- argv[!grepl("fastq::", argv, fixed=TRUE)]
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
191
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
192 fastqPathRev <- NULL
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
193 annoPath <- as.character(argv[2])
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
194 samplePath <- as.character(argv[3])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
195 barStart <- as.numeric(argv[4])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
196 barEnd <- as.numeric(argv[5])
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
197 barStartRev <- NULL
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
198 barStartRev <- NULL
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
199 hpStart <- as.numeric(argv[8])
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
200 hpEnd <- as.numeric(argv[9])
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
201 } else if (inputType=="pairedFastq") {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
202
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
203 fastqPath <- as.character(gsub("fastq::", "", argv[grepl("fastq::", argv)],
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
204 fixed=TRUE))
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
205
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
206 fastqPathRev <- as.character(gsub("fastqRev::", "",
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
207 argv[grepl("fastqRev::", argv)], fixed=TRUE))
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
208
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
209 # Remove fastq paths
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
210 argv <- argv[!grepl("fastq::", argv, fixed=TRUE)]
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
211 argv <- argv[!grepl("fastqRev::", argv, fixed=TRUE)]
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
212
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
213 annoPath <- as.character(argv[2])
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
214 samplePath <- as.character(argv[3])
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
215 barStart <- as.numeric(argv[4])
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
216 barEnd <- as.numeric(argv[5])
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
217 barStartRev <- as.numeric(argv[6])
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
218 barEndRev <- as.numeric(argv[7])
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
219 hpStart <- as.numeric(argv[8])
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
220 hpEnd <- as.numeric(argv[9])
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
221 } else if (inputType == "counts") {
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
222 countPath <- as.character(argv[2])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
223 annoPath <- as.character(argv[3])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
224 samplePath <- as.character(argv[4])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
225 }
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
226
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
227 secFactName <- as.character(argv[10])
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
228 cpmReq <- as.numeric(argv[11])
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
229 sampleReq <- as.numeric(argv[12])
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
230 readReq <- as.numeric(argv[13])
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
231 fdrThresh <- as.numeric(argv[14])
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
232 lfcThresh <- as.numeric(argv[15])
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
233 selectDirection <- as.character(argv[16])
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
234 workMode <- as.character(argv[17])
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
235 htmlPath <- as.character(argv[18])
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
236 folderPath <- as.character(argv[19])
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
237
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
238 if (workMode == "classic") {
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
239 pairData <- character()
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
240 pairData[2] <- as.character(argv[20])
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
241 pairData[1] <- as.character(argv[21])
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
242 } else if (workMode == "glm") {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
243 contrastData <- as.character(argv[20])
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
244 roastOpt <- as.character(argv[21])
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
245 hairpinReq <- as.numeric(argv[22])
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
246 selectOpt <- as.character(argv[23])
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
247 selectVals <- as.character(argv[24])
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
248 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
249
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
250 # Read in inputs
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
251
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
252 samples <- read.table(samplePath, header=TRUE, sep="\t")
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
253
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
254 anno <- read.table(annoPath, header=TRUE, sep="\t")
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
255
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
256 if (inputType == "counts") {
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
257 counts <- read.table(countPath, header=TRUE, sep="\t")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
258 }
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
259
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
260 ###################### Check inputs for correctness ############################
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
261 samples$ID <- make.names(samples$ID)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
262
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
263 if ( !any(grepl("group", names(samples))) ) {
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
264 stop("'group' column not specified in sample annotation file")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
265 } # Check if grouping variable has been specified
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
266
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
267 if (secFactName != "none") {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
268 if ( !any(grepl(secFactName, names(samples))) ) {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
269 tempStr <- paste0("Second factor specified as \"", secFactName, "\" but ",
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
270 "no such column name found in sample annotation file")
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
271 stop(tempStr)
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
272 } # Check if specified secondary factor is present
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
273 }
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
274
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
275
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
276 if ( any(table(samples$ID) > 1) ){
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
277 tab <- table(samples$ID)
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
278 offenders <- paste(names(tab[tab > 1]), collapse=", ")
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
279 offenders <- unmake.names(offenders)
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
280 stop("'ID' column of sample annotation must have unique values, values ",
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
281 offenders, " are repeated")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
282 } # Check that IDs in sample annotation are unique
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
283
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
284 if (inputType == "fastq" || inputType == "pairedFastq") {
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
285
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
286 if ( any(table(anno$ID) > 1) ){
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
287 tab <- table(anno$ID)
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
288 offenders <- paste(names(tab[tab>1]), collapse=", ")
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
289 stop("'ID' column of hairpin annotation must have unique values, values ",
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
290 offenders, " are repeated")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
291 } # 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
292
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
293 } else if (inputType == "counts") {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
294 # The first element of the colnames will be 'ID' and should not match
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
295 idFromSample <- samples$ID
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
296 idFromTable <- colnames(counts)[-1]
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
297 if (any(is.na(match(idFromTable, idFromSample)))) {
4
f8af57d6f60b Fixed bug causing fastq input to break
shian_su <registertonysu@gmail.com>
parents: 2
diff changeset
298 stop("not all samples have groups specified")
f8af57d6f60b Fixed bug causing fastq input to break
shian_su <registertonysu@gmail.com>
parents: 2
diff changeset
299 } # Check that a group has be specifed for each sample
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
300
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
301 if ( any(table(counts$ID) > 1) ){
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
302 tab <- table(counts$ID)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
303 offenders <- paste(names(tab[tab>1]), collapse=", ")
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
304 stop("'ID' column of count table must have unique values, values ",
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
305 offenders, " are repeated")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
306 } # Check that IDs in count table are unique
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
307 }
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
308 if (workMode == "glm") {
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
309 if (roastOpt == "yes") {
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
310 if (is.na(match("Gene", colnames(anno)))) {
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
311 tempStr <- paste("Gene-wise tests selected but'Gene' column not",
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
312 "specified in hairpin annotation file")
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
313 stop(tempStr)
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
314 }
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
315 }
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
316 }
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
317
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
318 if (secFactName != "none") {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
319 if (workMode != "glm") {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
320 tempStr <- paste("only glm analysis type possible when secondary factor",
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
321 "used, please change appropriate option.")
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
322 }
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
323 }
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
324
2
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 # Process arguments
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
328 if (workMode == "glm") {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
329 if (roastOpt == "yes") {
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
330 wantRoast <- TRUE
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
331 } else {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
332 wantRoast <- FALSE
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
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
336 # Split up contrasts seperated by comma into a vector and replace spaces with
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
337 # periods
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
338 if (exists("contrastData")) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
339 contrastData <- unlist(strsplit(contrastData, split=","))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
340 contrastData <- sanitiseEquation(contrastData)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
341 contrastData <- gsub(" ", ".", contrastData, fixed=TRUE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
342 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
343
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
344 # Replace spaces with periods in pair data
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
345 if (exists("pairData")) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
346 pairData <- make.names(pairData)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
347 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
348
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
349 # Generate output folder and paths
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
350 dir.create(folderPath, showWarnings=FALSE)
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
351
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
352 # Generate links for outputs
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
353 imgOut("barHairpin")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
354 imgOut("barIndex")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
355 imgOut("mds")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
356 imgOut("bcv")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
357 if (workMode == "classic") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
358 smearPng <- makeOut(paste0("smear(", pairData[2], "-", pairData[1],").png"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
359 smearPdf <- makeOut(paste0("smear(", pairData[2], "-", pairData[1],").pdf"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
360 topOut <- makeOut(paste0("toptag(", pairData[2], "-", pairData[1],").tsv"))
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
361 } else if (workMode == "glm") {
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
362 smearPng <- character()
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
363 smearPdf <- character()
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
364 topOut <- character()
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
365 roastOut <- character()
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
366 barcodePng <- character()
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
367 barcodePdf <- character()
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
368 for (i in 1:length(contrastData)) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
369 smearPng[i] <- makeOut(paste0("smear(", contrastData[i], ").png"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
370 smearPdf[i] <- makeOut(paste0("smear(", contrastData[i], ").pdf"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
371 topOut[i] <- makeOut(paste0("toptag(", contrastData[i], ").tsv"))
8
548802b3492f Version 1.0.9
shian_su <registertonysu@gmail.com>
parents: 7
diff changeset
372 roastOut[i] <- makeOut(paste0("gene_level(", contrastData[i], ").tsv"))
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
373 barcodePng[i] <- makeOut(paste0("barcode(", contrastData[i], ").png"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
374 barcodePdf[i] <- makeOut(paste0("barcode(", contrastData[i], ").pdf"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
375 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
376 }
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
377 countsOut <- makeOut("counts.tsv")
8
548802b3492f Version 1.0.9
shian_su <registertonysu@gmail.com>
parents: 7
diff changeset
378 sessionOut <- makeOut("session_info.txt")
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
379
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
380 # Initialise data for html links and images, table with the link label and
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
381 # link address
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
382 linkData <- data.frame(Label=character(), Link=character(),
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
383 stringsAsFactors=FALSE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
384 imageData <- data.frame(Label=character(), Link=character(),
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
385 stringsAsFactors=FALSE)
7
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
386
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
387 # Initialise vectors for storage of up/down/neutral regulated counts
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
388 upCount <- numeric()
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
389 downCount <- numeric()
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
390 flatCount <- numeric()
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
391
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
392 ################################################################################
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
393 ### Data Processing
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
394 ################################################################################
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
395
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
396 # Transform gene selection from string into index values for mroast
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
397 if (workMode == "glm") {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
398 if (selectOpt == "rank") {
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
399 selectVals <- gsub(" ", "", selectVals, fixed=TRUE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
400 selectVals <- unlist(strsplit(selectVals, ","))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
401
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
402 for (i in 1:length(selectVals)) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
403 if (grepl(":", selectVals[i], fixed=TRUE)) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
404 temp <- unlist(strsplit(selectVals[i], ":"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
405 selectVals <- selectVals[-i]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
406 a <- as.numeric(temp[1])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
407 b <- as.numeric(temp[2])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
408 selectVals <- c(selectVals, a:b)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
409 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
410 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
411 selectVals <- as.numeric(unique(selectVals))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
412 } else {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
413 selectVals <- gsub(" ", "", selectVals, fixed=TRUE)
8
548802b3492f Version 1.0.9
shian_su <registertonysu@gmail.com>
parents: 7
diff changeset
414 selectVals <- unlist(strsplit(selectVals, ","))
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
415 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
416 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
417
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
418 if (inputType == "fastq" || inputType == "pairedFastq") {
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
419 # Use EdgeR hairpin process and capture outputs
15
5a917ea5bed2 - Fixed read requirement report statistic.
shian_su <registertonysu@gmail.com>
parents: 13
diff changeset
420
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
421 hpReadout <- capture.output(
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
422 data <- processAmplicons(readfile=fastqPath, readfile2=fastqPathRev,
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
423 barcodefile=samplePath,
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
424 hairpinfile=annoPath,
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
425 barcodeStart=barStart, barcodeEnd=barEnd,
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
426 barcodeStartRev=barStartRev,
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
427 barcodeEndRev=barEndRev,
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
428 hairpinStart=hpStart, hairpinEnd=hpEnd,
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
429 verbose=TRUE)
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
430 )
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
431
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
432 # Remove function output entries that show processing data or is empty
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
433 hpReadout <- hpReadout[hpReadout!=""]
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
434 hpReadout <- hpReadout[!grepl("Processing", hpReadout)]
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
435 hpReadout <- hpReadout[!grepl("in file", hpReadout)]
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
436 hpReadout <- gsub(" -- ", "", hpReadout, fixed=TRUE)
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
437
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
438 # Make the names of groups syntactically valid (replace spaces with periods)
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
439 data$samples$group <- make.names(data$samples$group)
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
440 if (secFactName != "none") {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
441 data$samples[[secFactName]] <- make.names(data$samples[[secFactName]])
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
442 }
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
443 } else if (inputType == "counts") {
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
444 # Process counts information, set ID column to be row names
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
445 rownames(counts) <- counts$ID
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
446 counts <- counts[ , !(colnames(counts) == "ID")]
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
447 countsRows <- nrow(counts)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
448
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
449 # Process group information
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
450 sampleNames <- colnames(counts)
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
451 matchedIndex <- match(sampleNames, samples$ID)
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
452 factors <- samples$group[matchedIndex]
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
453
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
454 if (secFactName != "none") {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
455 secFactors <- samples[[secFactName]][matchedIndex]
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
456 }
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
457
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
458 annoRows <- nrow(anno)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
459 anno <- anno[match(rownames(counts), anno$ID), ]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
460 annoMatched <- sum(!is.na(anno$ID))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
461
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
462 if (any(is.na(anno$ID))) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
463 warningStr <- paste("count table contained more hairpins than",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
464 "specified in hairpin annotation file")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
465 warning(warningStr)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
466 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
467
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
468 # Filter out rows with zero counts
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
469 sel <- rowSums(counts)!=0
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
470 counts <- counts[sel, ]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
471 anno <- anno[sel, ]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
472
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
473 # Create DGEList
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
474 data <- DGEList(counts=counts, lib.size=colSums(counts),
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
475 norm.factors=rep(1,ncol(counts)), genes=anno, group=factors)
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
476
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
477 # Make the names of groups syntactically valid (replace spaces with periods)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
478 data$samples$group <- make.names(data$samples$group)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
479 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
480
10
8923d4ea858b - Added check for zero library size, will now filter out zero library size
shian_su <registertonysu@gmail.com>
parents: 9
diff changeset
481 # Filter out any samples with zero counts
8923d4ea858b - Added check for zero library size, will now filter out zero library size
shian_su <registertonysu@gmail.com>
parents: 9
diff changeset
482 if (any(data$samples$lib.size == 0)) {
8923d4ea858b - Added check for zero library size, will now filter out zero library size
shian_su <registertonysu@gmail.com>
parents: 9
diff changeset
483 sampleSel <- data$samples$lib.size != 0
8923d4ea858b - Added check for zero library size, will now filter out zero library size
shian_su <registertonysu@gmail.com>
parents: 9
diff changeset
484 filteredSamples <- paste(data$samples$ID[!sampleSel], collapse=", ")
8923d4ea858b - Added check for zero library size, will now filter out zero library size
shian_su <registertonysu@gmail.com>
parents: 9
diff changeset
485 data$counts <- data$counts[, sampleSel]
8923d4ea858b - Added check for zero library size, will now filter out zero library size
shian_su <registertonysu@gmail.com>
parents: 9
diff changeset
486 data$samples <- data$samples[sampleSel, ]
8923d4ea858b - Added check for zero library size, will now filter out zero library size
shian_su <registertonysu@gmail.com>
parents: 9
diff changeset
487 }
8923d4ea858b - Added check for zero library size, will now filter out zero library size
shian_su <registertonysu@gmail.com>
parents: 9
diff changeset
488
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
489 # Filter hairpins with low counts
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
490 preFilterCount <- nrow(data)
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
491 selRow <- rowSums(cpm(data$counts) > cpmReq) >= sampleReq
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
492 selCol <- colSums(data$counts) > readReq
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
493 data <- data[selRow, selCol]
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
494
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
495 # Check if any data survived filtering
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
496 if (length(data$counts) == 0) {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
497 stop("no data remains after filtering, consider relaxing filters")
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
498 }
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
499
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
500 # Count number of filtered tags and samples
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
501 postFilterCount <- nrow(data)
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
502 filteredCount <- preFilterCount - postFilterCount
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
503 sampleFilterCount <- sum(!selCol)
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
504
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
505 if (secFactName == "none") {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
506 # Estimate dispersions
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
507 data <- estimateDisp(data)
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
508 commonBCV <- round(sqrt(data$common.dispersion), 4)
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
509 } else {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
510 # Construct design
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
511 if (inputType == "counts") {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
512
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
513 sampleNames <- colnames(counts)
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
514 matchedIndex <- match(sampleNames, samples$ID)
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
515 factors <- factor(make.names(samples$group[matchedIndex]))
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
516
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
517 secFactors <- factor(make.names(samples[[secFactName]][matchedIndex]))
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
518
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
519 } else if (inputType == "fastq" || inputType == "pairedFastq") {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
520
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
521 factors <- factor(data$sample$group)
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
522 secFactors <- factor(data$sample[[secFactName]])
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
523
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
524 }
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
525
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
526 design <- model.matrix(~0 + factors + secFactors)
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
527
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
528 # Estimate dispersions
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
529 data <- estimateDisp(data, design=design)
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
530 commonBCV <- round(sqrt(data$common.dispersion), 4)
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
531 }
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
532
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
533
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
534 ################################################################################
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
535 ### Output Processing
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
536 ################################################################################
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
537
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
538 # Plot number of hairpins that could be matched per sample
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
539 png(barIndexPng, width=600, height=600)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
540 barplot(height<-colSums(data$counts), las=2, main="Counts per index",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
541 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
542 imageData[1, ] <- c("Counts per Index", "barIndex.png")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
543 invisible(dev.off())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
544
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
545 pdf(barIndexPdf)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
546 barplot(height<-colSums(data$counts), las=2, main="Counts per index",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
547 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
548 linkData[1, ] <- c("Counts per Index Barplot (.pdf)", "barIndex.pdf")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
549 invisible(dev.off())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
550
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
551 # Plot per hairpin totals across all samples
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
552 png(barHairpinPng, width=600, height=600)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
553 if (nrow(data$counts)<50) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
554 barplot(height<-rowSums(data$counts), las=2, main="Counts per hairpin",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
555 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
556 } else {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
557 barplot(height<-rowSums(data$counts), las=2, main="Counts per hairpin",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
558 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
559 names.arg=FALSE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
560 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
561 imageData <- rbind(imageData, c("Counts per Hairpin", "barHairpin.png"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
562 invisible(dev.off())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
563
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
564 pdf(barHairpinPdf)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
565 if (nrow(data$counts)<50) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
566 barplot(height<-rowSums(data$counts), las=2, main="Counts per hairpin",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
567 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
568 } else {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
569 barplot(height<-rowSums(data$counts), las=2, main="Counts per hairpin",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
570 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
571 names.arg=FALSE)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
572 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
573 newEntry <- c("Counts per Hairpin Barplot (.pdf)", "barHairpin.pdf")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
574 linkData <- rbind(linkData, newEntry)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
575 invisible(dev.off())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
576
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
577 # Make an MDS plot to visualise relationships between replicate samples
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
578 png(mdsPng, width=600, height=600)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
579 plotMDS(data, labels=data$samples$group, col=as.numeric(data$samples$group),
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
580 main="MDS Plot")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
581 imageData <- rbind(imageData, c("MDS Plot", "mds.png"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
582 invisible(dev.off())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
583
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
584 pdf(mdsPdf)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
585 plotMDS(data, labels=data$samples$group, col=as.numeric(data$samples$group),
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
586 main="MDS Plot")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
587 newEntry <- c("MDS Plot (.pdf)", "mds.pdf")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
588 linkData <- rbind(linkData, newEntry)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
589 invisible(dev.off())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
590
9
f1076bfb0ed1 - Fixed tool to actually make use of barcode location options
shian_su <registertonysu@gmail.com>
parents: 8
diff changeset
591 # BCV Plot
f1076bfb0ed1 - Fixed tool to actually make use of barcode location options
shian_su <registertonysu@gmail.com>
parents: 8
diff changeset
592 png(bcvPng, width=600, height=600)
f1076bfb0ed1 - Fixed tool to actually make use of barcode location options
shian_su <registertonysu@gmail.com>
parents: 8
diff changeset
593 plotBCV(data, main="BCV Plot")
f1076bfb0ed1 - Fixed tool to actually make use of barcode location options
shian_su <registertonysu@gmail.com>
parents: 8
diff changeset
594 imageData <- rbind(imageData, c("BCV Plot", "bcv.png"))
f1076bfb0ed1 - Fixed tool to actually make use of barcode location options
shian_su <registertonysu@gmail.com>
parents: 8
diff changeset
595 invisible(dev.off())
f1076bfb0ed1 - Fixed tool to actually make use of barcode location options
shian_su <registertonysu@gmail.com>
parents: 8
diff changeset
596
f1076bfb0ed1 - Fixed tool to actually make use of barcode location options
shian_su <registertonysu@gmail.com>
parents: 8
diff changeset
597 pdf(bcvPdf)
f1076bfb0ed1 - Fixed tool to actually make use of barcode location options
shian_su <registertonysu@gmail.com>
parents: 8
diff changeset
598 plotBCV(data, main="BCV Plot")
f1076bfb0ed1 - Fixed tool to actually make use of barcode location options
shian_su <registertonysu@gmail.com>
parents: 8
diff changeset
599 newEntry <- c("BCV Plot (.pdf)", "bcv.pdf")
12
ebb4cb1e8e35 - Fixed BCV plot pdf not showing in the html output
shian_su <registertonysu@gmail.com>
parents: 11
diff changeset
600 linkData <- rbind(linkData, newEntry)
9
f1076bfb0ed1 - Fixed tool to actually make use of barcode location options
shian_su <registertonysu@gmail.com>
parents: 8
diff changeset
601 invisible(dev.off())
f1076bfb0ed1 - Fixed tool to actually make use of barcode location options
shian_su <registertonysu@gmail.com>
parents: 8
diff changeset
602
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
603 if (workMode == "classic") {
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
604 # Assess differential representation using classic exact testing methodology
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
605 # in edgeR
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
606 testData <- exactTest(data, pair=pairData)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
607
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
608 top <- topTags(testData, n=Inf)
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
609
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
610 if (selectDirection == "all") {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
611 topIDs <- top$table[(top$table$FDR < fdrThresh) &
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
612 (abs(top$table$logFC) > lfcThresh), 1]
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
613 } else if (selectDirection == "up") {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
614 topIDs <- top$table[(top$table$FDR < fdrThresh) &
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
615 (top$table$logFC > lfcThresh), 1]
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
616 } else if (selectDirection == "down") {
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
617 topIDs <- top$table[(top$table$FDR < fdrThresh) &
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
618 (top$table$logFC < -lfcThresh), 1]
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
619 }
7
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
620
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
621 write.table(top, file=topOut, row.names=FALSE, sep="\t")
7
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
622
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
623 linkName <- paste0("Top Tags Table(", pairData[2], "-", pairData[1],
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
624 ") (.tsv)")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
625 linkAddr <- paste0("toptag(", pairData[2], "-", pairData[1], ").tsv")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
626 linkData <- rbind(linkData, c(linkName, linkAddr))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
627
7
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
628 upCount[1] <- sum(top$table$FDR < fdrThresh & top$table$logFC > lfcThresh)
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
629
7
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
630 downCount[1] <- sum(top$table$FDR < fdrThresh &
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
631 top$table$logFC < -lfcThresh)
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
632
7
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
633 flatCount[1] <- sum(top$table$FDR > fdrThresh |
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
634 abs(top$table$logFC) < lfcThresh)
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
635
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
636
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
637
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
638 # Select hairpins with FDR < 0.05 to highlight on plot
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
639 png(smearPng, width=600, height=600)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
640 plotTitle <- gsub(".", " ",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
641 paste0("Smear Plot: ", pairData[2], "-", pairData[1]),
7
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
642 fixed=TRUE)
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
643 plotSmear(testData, de.tags=topIDs,
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
644 pch=20, cex=1.0, main=plotTitle)
7
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
645 abline(h=c(-1, 0, 1), col=c("dodgerblue", "yellow", "dodgerblue"), lty=2)
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
646 imgName <- paste0("Smear Plot(", pairData[2], "-", pairData[1], ")")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
647 imgAddr <- paste0("smear(", pairData[2], "-", pairData[1],").png")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
648 imageData <- rbind(imageData, c(imgName, imgAddr))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
649 invisible(dev.off())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
650
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
651 pdf(smearPdf)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
652 plotTitle <- gsub(".", " ",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
653 paste0("Smear Plot: ", pairData[2], "-", pairData[1]),
7
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
654 fixed=TRUE)
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
655 plotSmear(testData, de.tags=topIDs,
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
656 pch=20, cex=1.0, main=plotTitle)
7
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
657 abline(h=c(-1, 0, 1), col=c("dodgerblue", "yellow", "dodgerblue"), lty=2)
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
658 imgName <- paste0("Smear Plot(", pairData[2], "-", pairData[1], ") (.pdf)")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
659 imgAddr <- paste0("smear(", pairData[2], "-", pairData[1], ").pdf")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
660 linkData <- rbind(linkData, c(imgName, imgAddr))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
661 invisible(dev.off())
7
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
662
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
663 } else if (workMode == "glm") {
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
664 # Generating design information
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
665 if (secFactName == "none") {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
666
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
667 factors <- factor(data$sample$group)
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
668 design <- model.matrix(~0 + factors)
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
669
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
670 colnames(design) <- gsub("factors", "", colnames(design), fixed=TRUE)
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
671
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
672 } else {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
673
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
674 factors <- factor(data$sample$group)
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
675
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
676 if (inputType == "counts") {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
677
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
678 sampleNames <- colnames(counts)
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
679 matchedIndex <- match(sampleNames, samples$ID)
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
680 factors <- factor(samples$group[matchedIndex])
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
681
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
682 secFactors <- factor(samples[[secFactName]][matchedIndex])
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
683
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
684 } else if (inputType == "fastq" || inputType == "pairedFastq") {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
685
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
686 secFactors <- factor(data$sample[[secFactName]])
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
687
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
688 }
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
689
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
690 design <- model.matrix(~0 + factors + secFactors)
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
691
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
692 colnames(design) <- gsub("factors", "", colnames(design), fixed=TRUE)
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
693 colnames(design) <- gsub("secFactors", secFactName, colnames(design),
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
694 fixed=TRUE)
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
695 }
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
696
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
697
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
698 # Split up contrasts seperated by comma into a vector
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
699 contrastData <- unlist(strsplit(contrastData, split=","))
7
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
700
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
701 for (i in 1:length(contrastData)) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
702 # Generate contrasts information
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
703 contrasts <- makeContrasts(contrasts=contrastData[i], levels=design)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
704
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
705 # Fit negative bionomial GLM
7
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
706 fit <- glmFit(data, design)
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
707 # Carry out Likelihood ratio test
7
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
708 testData <- glmLRT(fit, contrast=contrasts)
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
709
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
710 # Select hairpins with FDR < 0.05 to highlight on plot
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
711 top <- topTags(testData, n=Inf)
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
712
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
713 if (selectDirection == "all") {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
714 topIDs <- top$table[(top$table$FDR < fdrThresh) &
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
715 (abs(top$table$logFC) > lfcThresh), 1]
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
716 } else if (selectDirection == "up") {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
717 topIDs <- top$table[(top$table$FDR < fdrThresh) &
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
718 (top$table$logFC > lfcThresh), 1]
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
719 } else if (selectDirection == "down") {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
720 topIDs <- top$table[(top$table$FDR < fdrThresh) &
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
721 (top$table$logFC < -lfcThresh), 1]
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
722 }
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
723
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
724 write.table(top, file=topOut[i], row.names=FALSE, sep="\t")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
725
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
726 linkName <- paste0("Top Tags Table(", contrastData[i], ") (.tsv)")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
727 linkAddr <- paste0("toptag(", contrastData[i], ").tsv")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
728 linkData <- rbind(linkData, c(linkName, linkAddr))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
729
7
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
730 # Collect counts for differential representation
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
731 upCount[i] <- sum(top$table$FDR < fdrThresh & top$table$logFC > lfcThresh)
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
732 downCount[i] <- sum(top$table$FDR < fdrThresh &
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
733 top$table$logFC < -lfcThresh)
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
734 flatCount[i] <- sum(top$table$FDR > fdrThresh |
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
735 abs(top$table$logFC) < lfcThresh)
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
736
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
737 # Make a plot of logFC versus logCPM
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
738 png(smearPng[i], height=600, width=600)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
739 plotTitle <- paste("Smear Plot:", gsub(".", " ", contrastData[i],
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
740 fixed=TRUE))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
741 plotSmear(testData, de.tags=topIDs, pch=20, cex=0.8, main=plotTitle)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
742 abline(h=c(-1, 0, 1), col=c("dodgerblue", "yellow", "dodgerblue"), lty=2)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
743
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
744 imgName <- paste0("Smear Plot(", contrastData[i], ")")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
745 imgAddr <- paste0("smear(", contrastData[i], ").png")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
746 imageData <- rbind(imageData, c(imgName, imgAddr))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
747 invisible(dev.off())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
748
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
749 pdf(smearPdf[i])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
750 plotTitle <- paste("Smear Plot:", gsub(".", " ", contrastData[i],
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
751 fixed=TRUE))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
752 plotSmear(testData, de.tags=topIDs, pch=20, cex=0.8, main=plotTitle)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
753 abline(h=c(-1, 0, 1), col=c("dodgerblue", "yellow", "dodgerblue"), lty=2)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
754
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
755 linkName <- paste0("Smear Plot(", contrastData[i], ") (.pdf)")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
756 linkAddr <- paste0("smear(", contrastData[i], ").pdf")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
757 linkData <- rbind(linkData, c(linkName, linkAddr))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
758 invisible(dev.off())
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
759
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
760 genes <- as.character(data$genes$Gene)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
761 unq <- unique(genes)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
762 unq <- unq[!is.na(unq)]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
763 geneList <- list()
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
764 for (gene in unq) {
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
765 if (length(which(genes == gene)) >= hairpinReq) {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
766 geneList[[gene]] <- which(genes == gene)
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
767 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
768 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
769
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
770 if (wantRoast) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
771 # Input preparaton for roast
7
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
772 nrot <- 9999
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
773 set.seed(602214129)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
774 roastData <- mroast(data, index=geneList, design=design,
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
775 contrast=contrasts, nrot=nrot)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
776 roastData <- cbind(GeneID=rownames(roastData), roastData)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
777 write.table(roastData, file=roastOut[i], row.names=FALSE, sep="\t")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
778 linkName <- paste0("Gene Level Analysis Table(", contrastData[i],
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
779 ") (.tsv)")
8
548802b3492f Version 1.0.9
shian_su <registertonysu@gmail.com>
parents: 7
diff changeset
780 linkAddr <- paste0("gene_level(", contrastData[i], ").tsv")
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
781 linkData <- rbind(linkData, c(linkName, linkAddr))
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
782 if (selectOpt == "rank") {
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
783 selectedGenes <- rownames(roastData)[selectVals]
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
784 } else {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
785 selectedGenes <- selectVals
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
786 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
787
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
788 if (packageVersion("limma")<"3.19.19") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
789 png(barcodePng[i], width=600, height=length(selectedGenes)*150)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
790 } else {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
791 png(barcodePng[i], width=600, height=length(selectedGenes)*300)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
792 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
793 par(mfrow=c(length(selectedGenes), 1))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
794 for (gene in selectedGenes) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
795 barcodeplot(testData$table$logFC, index=geneList[[gene]],
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
796 main=paste("Barcode Plot for", gene, "(logFCs)",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
797 gsub(".", " ", contrastData[i])),
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
798 labels=c("Positive logFC", "Negative logFC"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
799 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
800 imgName <- paste0("Barcode Plot(", contrastData[i], ")")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
801 imgAddr <- paste0("barcode(", contrastData[i], ").png")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
802 imageData <- rbind(imageData, c(imgName, imgAddr))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
803 dev.off()
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
804 if (packageVersion("limma")<"3.19.19") {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
805 pdf(barcodePdf[i], width=8, height=2)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
806 } else {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
807 pdf(barcodePdf[i], width=8, height=4)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
808 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
809 for (gene in selectedGenes) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
810 barcodeplot(testData$table$logFC, index=geneList[[gene]],
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
811 main=paste("Barcode Plot for", gene, "(logFCs)",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
812 gsub(".", " ", contrastData[i])),
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
813 labels=c("Positive logFC", "Negative logFC"))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
814 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
815 linkName <- paste0("Barcode Plot(", contrastData[i], ") (.pdf)")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
816 linkAddr <- paste0("barcode(", contrastData[i], ").pdf")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
817 linkData <- rbind(linkData, c(linkName, linkAddr))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
818 dev.off()
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
819 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
820 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
821 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
822
8
548802b3492f Version 1.0.9
shian_su <registertonysu@gmail.com>
parents: 7
diff changeset
823 # Generate data frame of the significant differences
7
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
824 sigDiff <- data.frame(Up=upCount, Flat=flatCount, Down=downCount)
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
825 if (workMode == "glm") {
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
826
7
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
827 row.names(sigDiff) <- contrastData
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
828
7
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
829 } else if (workMode == "classic") {
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
830
7
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
831 row.names(sigDiff) <- paste0(pairData[2], "-", pairData[1])
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
832
7
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
833 }
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
834
8
548802b3492f Version 1.0.9
shian_su <registertonysu@gmail.com>
parents: 7
diff changeset
835 # Output table of summarised counts
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
836 ID <- rownames(data$counts)
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
837 outputCounts <- cbind(ID, data$counts)
8
548802b3492f Version 1.0.9
shian_su <registertonysu@gmail.com>
parents: 7
diff changeset
838 write.table(outputCounts, file=countsOut, row.names=FALSE, sep="\t",
548802b3492f Version 1.0.9
shian_su <registertonysu@gmail.com>
parents: 7
diff changeset
839 quote=FALSE)
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
840 linkName <- "Counts table (.tsv)"
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
841 linkAddr <- "counts.tsv"
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
842 linkData <- rbind(linkData, c(linkName, linkAddr))
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
843
8
548802b3492f Version 1.0.9
shian_su <registertonysu@gmail.com>
parents: 7
diff changeset
844 # Record session info
548802b3492f Version 1.0.9
shian_su <registertonysu@gmail.com>
parents: 7
diff changeset
845 writeLines(capture.output(sessionInfo()), sessionOut)
548802b3492f Version 1.0.9
shian_su <registertonysu@gmail.com>
parents: 7
diff changeset
846 linkData <- rbind(linkData, c("Session Info", "session_info.txt"))
548802b3492f Version 1.0.9
shian_su <registertonysu@gmail.com>
parents: 7
diff changeset
847
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
848 # Record ending time and calculate total run time
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
849 timeEnd <- as.character(Sys.time())
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
850 timeTaken <- capture.output(round(difftime(timeEnd,timeStart), digits=3))
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
851 timeTaken <- gsub("Time difference of ", "", timeTaken, fixed=TRUE)
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
852 ################################################################################
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
853 ### HTML Generation
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
854 ################################################################################
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
855 # Clear file
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
856 cat("", file=htmlPath)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
857
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
858 cata("<html>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
859 HtmlHead("EdgeR Output")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
860
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
861 cata("<body>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
862 cata("<h3>EdgeR Analysis Output:</h3>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
863 cata("<h4>Input Summary:</h4>\n")
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
864 if (inputType == "fastq" || inputType == "pairedFastq") {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
865
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
866 cata("<ul>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
867 ListItem(hpReadout[1])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
868 ListItem(hpReadout[2])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
869 cata("</ul>\n")
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
870 cata(hpReadout[3], "<br />\n")
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
871 cata("<ul>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
872 ListItem(hpReadout[4])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
873 ListItem(hpReadout[7])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
874 cata("</ul>\n")
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
875 cata(hpReadout[8:11], sep="<br />\n")
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
876 cata("<br />\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
877 cata("<b>Please check that read percentages are consistent with ")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
878 cata("expectations.</b><br >\n")
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
879
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
880 } else if (inputType == "counts") {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
881
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
882 cata("<ul>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
883 ListItem("Number of Samples: ", ncol(data$counts))
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
884 ListItem("Number of Hairpins: ", countsRows)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
885 ListItem("Number of annotations provided: ", annoRows)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
886 ListItem("Number of annotations matched to hairpin: ", annoMatched)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
887 cata("</ul>\n")
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
888
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
889 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
890
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
891 cata("The estimated common biological coefficient of variation (BCV) is: ",
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
892 commonBCV, "<br />\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
893
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
894 if (secFactName == "none") {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
895
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
896 cata("No secondary factor specified.<br />\n")
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
897
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
898 } else {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
899
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
900 cata("Secondary factor specified as: ", secFactName, "<br />\n")
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
901
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
902 }
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
903
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
904 cata("<h4>Output:</h4>\n")
7
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
905 cata("PDF copies of JPEGS available in 'Plots' section.<br />\n")
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
906 for (i in 1:nrow(imageData)) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
907 if (grepl("barcode", imageData$Link[i])) {
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
908
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
909 if (packageVersion("limma")<"3.19.19") {
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
910
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
911 HtmlImage(imageData$Link[i], imageData$Label[i],
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
912 height=length(selectedGenes)*150)
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
913
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
914 } else {
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
915
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
916 HtmlImage(imageData$Link[i], imageData$Label[i],
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
917 height=length(selectedGenes)*300)
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
918
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
919 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
920 } else {
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
921
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
922 HtmlImage(imageData$Link[i], imageData$Label[i])
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
923
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
924 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
925 }
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
926 cata("<br />\n")
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
927
7
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
928 cata("<h4>Differential Representation Counts:</h4>\n")
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
929
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
930 cata("<table border=\"1\" cellpadding=\"4\">\n")
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
931 cata("<tr>\n")
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
932 TableItem()
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
933 for (i in colnames(sigDiff)) {
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
934 TableHeadItem(i)
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
935 }
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
936 cata("</tr>\n")
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
937 for (i in 1:nrow(sigDiff)) {
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
938 cata("<tr>\n")
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
939 TableHeadItem(unmake.names(row.names(sigDiff)[i]))
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
940 for (j in 1:ncol(sigDiff)) {
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
941 TableItem(as.character(sigDiff[i, j]))
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
942 }
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
943 cata("</tr>\n")
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
944 }
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
945 cata("</table>")
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
946
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
947 cata("<h4>Plots:</h4>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
948 for (i in 1:nrow(linkData)) {
8
548802b3492f Version 1.0.9
shian_su <registertonysu@gmail.com>
parents: 7
diff changeset
949 if (grepl(".pdf", linkData$Link[i])) {
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
950 HtmlLink(linkData$Link[i], linkData$Label[i])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
951 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
952 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
953
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
954 cata("<h4>Tables:</h4>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
955 for (i in 1:nrow(linkData)) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
956 if (grepl(".tsv", linkData$Link[i])) {
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
957 HtmlLink(linkData$Link[i], linkData$Label[i])
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
958 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
959 }
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
960
7
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
961 cata("<p>Alt-click links to download file.</p>\n")
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
962 cata("<p>Click floppy disc icon on associated history item to download ")
7
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
963 cata("all files.</p>\n")
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
964 cata("<p>.tsv files can be viewed in Excel or any spreadsheet program.</p>\n")
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
965
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
966 cata("<h4>Additional Information:</h4>\n")
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
967
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
968 if (inputType == "fastq") {
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
969
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
970 ListItem("Data was gathered from fastq raw read file(s).")
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
971
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
972 } else if (inputType == "counts") {
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
973
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
974 ListItem("Data was gathered from a table of counts.")
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
975
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
976 }
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
977
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
978 if (cpmReq != 0 && sampleReq != 0) {
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
979 tempStr <- paste("Target sequences without more than", cpmReq,
7
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
980 "CPM in at least", sampleReq, "samples are insignificant",
91e411fcdecc Version 1.0.8
shian_su <registertonysu@gmail.com>
parents: 6
diff changeset
981 "and filtered out.")
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
982 ListItem(tempStr)
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
983
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
984 filterProp <- round(filteredCount/preFilterCount*100, digits=2)
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
985 tempStr <- paste0(filteredCount, " of ", preFilterCount," (", filterProp,
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
986 "%) target sequences were filtered out for low ",
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
987 "count-per-million.")
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
988 ListItem(tempStr)
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
989 }
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
990
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
991 if (sampleReq != 0) {
15
5a917ea5bed2 - Fixed read requirement report statistic.
shian_su <registertonysu@gmail.com>
parents: 13
diff changeset
992 tempStr <- paste("Samples that did not produce more than", readReq,
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
993 "counts were filtered out.")
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
994 ListItem(tempStr)
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
995
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
996 tempStr <- paste0(sampleFilterCount, " samples were filtered out for low ",
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
997 "counts.")
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
998 ListItem(tempStr)
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
999 }
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1000
10
8923d4ea858b - Added check for zero library size, will now filter out zero library size
shian_su <registertonysu@gmail.com>
parents: 9
diff changeset
1001 if (exists("filteredSamples")) {
8923d4ea858b - Added check for zero library size, will now filter out zero library size
shian_su <registertonysu@gmail.com>
parents: 9
diff changeset
1002 tempStr <- paste("The following samples were filtered out for having zero",
8923d4ea858b - Added check for zero library size, will now filter out zero library size
shian_su <registertonysu@gmail.com>
parents: 9
diff changeset
1003 "library size: ", filteredSamples)
8923d4ea858b - Added check for zero library size, will now filter out zero library size
shian_su <registertonysu@gmail.com>
parents: 9
diff changeset
1004 ListItem(tempStr)
8923d4ea858b - Added check for zero library size, will now filter out zero library size
shian_su <registertonysu@gmail.com>
parents: 9
diff changeset
1005 }
8923d4ea858b - Added check for zero library size, will now filter out zero library size
shian_su <registertonysu@gmail.com>
parents: 9
diff changeset
1006
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1007 if (workMode == "classic") {
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
1008 ListItem("An exact test was performed on each target sequence.")
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1009 } else if (workMode == "glm") {
13
7aaa9bc23e3c Added support for paired end reads
shian_su <registertonysu@gmail.com>
parents: 12
diff changeset
1010 ListItem("A generalised linear model was fitted to each target sequence.")
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1011 }
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1012
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1013 cit <- character()
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1014 link <-character()
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1015 link[1] <- paste0("<a href=\"",
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1016 "http://www.bioconductor.org/packages/release/bioc/",
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1017 "vignettes/limma/inst/doc/usersguide.pdf",
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1018 "\">", "limma User's Guide", "</a>.")
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1019 link[2] <- paste0("<a href=\"",
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1020 "http://www.bioconductor.org/packages/release/bioc/",
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1021 "vignettes/edgeR/inst/doc/edgeRUsersGuide.pdf",
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1022 "\">", "edgeR User's Guide", "</a>")
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1023
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1024 cit[1] <- paste("Robinson MD, McCarthy DJ and Smyth GK (2010).",
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1025 "edgeR: a Bioconductor package for differential",
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1026 "expression analysis of digital gene expression",
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1027 "data. Bioinformatics 26, 139-140")
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1028 cit[2] <- paste("Robinson MD and Smyth GK (2007). Moderated statistical tests",
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1029 "for assessing differences in tag abundance. Bioinformatics",
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1030 "23, 2881-2887")
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1031 cit[3] <- paste("Robinson MD and Smyth GK (2008). Small-sample estimation of",
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1032 "negative binomial dispersion, with applications to SAGE data.",
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1033 "Biostatistics, 9, 321-332")
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1034
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1035 cit[4] <- paste("McCarthy DJ, Chen Y and Smyth GK (2012). Differential",
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1036 "expression analysis of multifactor RNA-Seq experiments with",
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1037 "respect to biological variation. Nucleic Acids Research 40,",
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1038 "4288-4297")
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1039
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1040 cata("<h4>Citations</h4>")
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1041 cata("<ol>\n")
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1042 ListItem(cit[1])
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1043 ListItem(cit[2])
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1044 ListItem(cit[3])
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1045 ListItem(cit[4])
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1046 cata("</ol>\n")
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1047
8
548802b3492f Version 1.0.9
shian_su <registertonysu@gmail.com>
parents: 7
diff changeset
1048 cata("<p>Report problems to: su.s@wehi.edu.au</p>\n")
548802b3492f Version 1.0.9
shian_su <registertonysu@gmail.com>
parents: 7
diff changeset
1049
548802b3492f Version 1.0.9
shian_su <registertonysu@gmail.com>
parents: 7
diff changeset
1050 for (i in 1:nrow(linkData)) {
548802b3492f Version 1.0.9
shian_su <registertonysu@gmail.com>
parents: 7
diff changeset
1051 if (grepl("session_info", linkData$Link[i])) {
548802b3492f Version 1.0.9
shian_su <registertonysu@gmail.com>
parents: 7
diff changeset
1052 HtmlLink(linkData$Link[i], linkData$Label[i])
548802b3492f Version 1.0.9
shian_su <registertonysu@gmail.com>
parents: 7
diff changeset
1053 }
548802b3492f Version 1.0.9
shian_su <registertonysu@gmail.com>
parents: 7
diff changeset
1054 }
548802b3492f Version 1.0.9
shian_su <registertonysu@gmail.com>
parents: 7
diff changeset
1055
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
1056 cata("<table border=\"0\">\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
1057 cata("<tr>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
1058 TableItem("Task started at:"); TableItem(timeStart)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
1059 cata("</tr>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
1060 cata("<tr>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
1061 TableItem("Task ended at:"); TableItem(timeEnd)
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
1062 cata("</tr>\n")
6
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1063 cata("<tr>\n")
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1064 TableItem("Task run time:"); TableItem(timeTaken)
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1065 cata("<tr>\n")
3d04308a99f9 - Added differentially expressed hairpin count output
shian_su <registertonysu@gmail.com>
parents: 4
diff changeset
1066 cata("</table>\n")
2
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
1067
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
1068 cata("</body>\n")
076ca575208f First commit
shian_su <registertonysu@gmail.com>
parents:
diff changeset
1069 cata("</html>")