diff hairpinTool.R @ 8:548802b3492f

Version 1.0.9 - Added R session info to output - Added email for bug reports - Changed edgeR requirement to be stopping condition - Changed names of gene-wise comparison tables to "gene_level" from "roast" - Fixed selection of multiple genes for barcode plotting
author shian_su <registertonysu@gmail.com>
date Fri, 02 May 2014 17:22:24 +1000
parents 91e411fcdecc
children f1076bfb0ed1
line wrap: on
line diff
--- a/hairpinTool.R	Wed Apr 23 14:05:26 2014 +1000
+++ b/hairpinTool.R	Fri May 02 17:22:24 2014 +1000
@@ -58,7 +58,11 @@
 library(limma, quietly=TRUE, warn.conflicts=FALSE)
 
 if (packageVersion("edgeR") < "3.5.23") {
-  message("Please update 'edgeR' to version >= 3.5.23 to run this script")
+  stop("Please update 'edgeR' to version >= 3.5.23 to run this tool")
+}
+
+if (packageVersion("limma")<"3.19.19") {
+  message("Update 'limma' to version >= 3.19.19 to see updated barcode graphs")
 }
 
 ################################################################################
@@ -305,12 +309,13 @@
     smearPng[i] <- makeOut(paste0("smear(", contrastData[i], ").png"))
     smearPdf[i] <- makeOut(paste0("smear(", contrastData[i], ").pdf"))
     topOut[i] <- makeOut(paste0("toptag(", contrastData[i], ").tsv"))
-    roastOut[i] <- makeOut(paste0("roast(", contrastData[i], ").tsv"))
+    roastOut[i] <- makeOut(paste0("gene_level(", contrastData[i], ").tsv"))
     barcodePng[i] <- makeOut(paste0("barcode(", contrastData[i], ").png"))
     barcodePdf[i] <- makeOut(paste0("barcode(", contrastData[i], ").pdf"))
   }
 }
 countsOut <- makeOut("counts.tsv")
+sessionOut <- makeOut("session_info.txt")
 
 # Initialise data for html links and images, table with the link label and
 # link address
@@ -346,7 +351,7 @@
     selectVals <- as.numeric(unique(selectVals))
   } else {
     selectVals <- gsub(" ", "", selectVals, fixed=TRUE)
-    selectVals <- unlist(strsplit(selectVals, " "))
+    selectVals <- unlist(strsplit(selectVals, ","))
   }                                                           
 }
                                                   
@@ -593,7 +598,7 @@
       write.table(roastData, file=roastOut[i], row.names=FALSE, sep="\t")
       linkName <- paste0("Gene Level Analysis Table(", contrastData[i], 
                          ") (.tsv)")
-      linkAddr <- paste0("roast(", contrastData[i], ").tsv")
+      linkAddr <- paste0("gene_level(", contrastData[i], ").tsv")
       linkData <- rbind(linkData, c(linkName, linkAddr))
       if (selectOpt=="rank") {
         selectedGenes <- rownames(roastData)[selectVals]
@@ -636,6 +641,7 @@
   }
 }
 
+# Generate data frame of the significant differences
 sigDiff <- data.frame(Up=upCount, Flat=flatCount, Down=downCount)
 if (workMode == "glm") {
   row.names(sigDiff) <- contrastData
@@ -643,13 +649,19 @@
   row.names(sigDiff) <- paste0(pairData[2], "-", pairData[1])
 }
 
+# Output table of summarised counts
 ID <- rownames(data$counts)
 outputCounts <- cbind(ID, data$counts)
-write.table(outputCounts, file=countsOut, row.names=FALSE, sep="\t")
+write.table(outputCounts, file=countsOut, row.names=FALSE, sep="\t",
+            quote=FALSE)
 linkName <- "Counts table (.tsv)"
 linkAddr <- "counts.tsv"
 linkData <- rbind(linkData, c(linkName, linkAddr))
 
+# Record session info
+writeLines(capture.output(sessionInfo()), sessionOut)
+linkData <- rbind(linkData, c("Session Info", "session_info.txt"))
+
 # Record ending time and calculate total run time
 timeEnd <- as.character(Sys.time())
 timeTaken <- capture.output(round(difftime(timeEnd,timeStart), digits=3))
@@ -730,7 +742,7 @@
 
 cata("<h4>Plots:</h4>\n")
 for (i in 1:nrow(linkData)) {
-  if (!grepl(".tsv", linkData$Link[i])) {
+  if (grepl(".pdf", linkData$Link[i])) {
     HtmlLink(linkData$Link[i], linkData$Label[i])
   }
 }
@@ -756,7 +768,7 @@
 }
 
 if (cpmReq!=0 && sampleReq!=0) {
-  tempStr <- paste("Hairpins with less than", cpmReq,
+  tempStr <- paste("Hairpins without more than", cpmReq,
                    "CPM in at least", sampleReq, "samples are insignificant",
                    "and filtered out.")
   ListItem(tempStr)
@@ -807,6 +819,14 @@
 ListItem(cit[4])
 cata("</ol>\n")
 
+cata("<p>Report problems to: su.s@wehi.edu.au</p>\n")
+
+for (i in 1:nrow(linkData)) {
+  if (grepl("session_info", linkData$Link[i])) {
+    HtmlLink(linkData$Link[i], linkData$Label[i])
+  }
+}
+
 cata("<table border=\"0\">\n")
 cata("<tr>\n")
 TableItem("Task started at:"); TableItem(timeStart)