diff limma_voom.R @ 20:0921444c832d draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/limma_voom commit 0cc16fe170b5c8d3b9441177bf2749aa7bddca7b
author iuc
date Wed, 29 May 2019 10:31:41 -0400
parents c9c6427edfe9
children 58c35179ebf0
line wrap: on
line diff
--- a/limma_voom.R	Tue May 28 10:04:10 2019 -0400
+++ b/limma_voom.R	Wed May 29 10:31:41 2019 -0400
@@ -79,6 +79,14 @@
     return(string)
 }
 
+# Function to make contrast contain valid R names
+sanitiseContrast <- function(string) {
+    string <- strsplit(string, split="-")
+    string <- lapply(string, make.names)
+    string <- lapply(string, paste, collapse="-")
+    return(string)
+}
+
 # Function to change periods to whitespace in a string
 unmake.names <- function(string) {
     string <- gsub(".", " ", string, fixed=TRUE)
@@ -353,16 +361,29 @@
     # Split up contrasts seperated by comma into a vector then sanitise
     contrastData <- unlist(strsplit(opt$contrastInput, split=","))
 }
-
-# in case input groups start with numbers this will make the names valid R names, required for makeContrasts
 contrastData <- sanitiseEquation(contrastData)
 contrastData <- gsub(" ", ".", contrastData, fixed=TRUE)
+
+# in case input groups start with numbers make the names valid R names, required for makeContrasts
 cons <- NULL
+cons_d <- NULL
 for (i in contrastData) {
-    i <- strsplit(i, split="-")
-    i <- lapply(i, make.names)
-    i <- lapply(i, paste, collapse="-")
-    cons <- append(cons, unlist(i))
+
+    # if the contrast is a difference of differences e.g. (A-B)-(X-Y)
+    if (grepl("\\)-\\(", i)) {
+        i <- unlist(strsplit(i, split="\\)-\\("))
+        i <- gsub("\\(|\\)","", i)
+        for (j in i) {
+           j <- sanitiseContrast(j)
+           j <- paste0("(", j, ")")
+           cons_d  <- append(cons_d, unlist(j))
+        }
+        cons_d <- paste(cons_d, collapse = '-')
+        cons <- append(cons, unlist(cons_d))
+    } else {
+        i <- sanitiseContrast(i)
+        cons <- append(cons, unlist(i))
+    }
 }
 
 plots <- character()
@@ -852,6 +873,7 @@
 sumStatus <- summary(status)
 
 for (i in 1:length(cons)) {
+    con_name <- cons[i]
     con <- cons[i]
     con <- gsub("\\(|\\)", "", con)
     # Collect counts for differential expression
@@ -957,7 +979,7 @@
     imgName <- paste0("MDVolPlot_", con)
     imgAddr <- paste0("mdvolplot_", con, ".png")
     imageData <- rbind(imageData, c(imgName, imgAddr))
-    title(paste0("Contrast: ", unmake.names(con)), outer=TRUE, cex.main=1.5)
+    title(paste0("Contrast: ", con_name), outer=TRUE, cex.main=1.5)
     invisible(dev.off())
 
     if ("h" %in% plots) {
@@ -1076,7 +1098,7 @@
 cata("<h4>Plots:</h4>\n")
 #PDFs
 for (i in 1:nrow(linkData)) {
-    if (grepl("density|cpm|boxplot|mds|mdplots|voom|saplot", linkData$Link[i])) {
+    if (grepl(".pdf", linkData$Link[i]) & grepl("density|cpm|boxplot|mds|mdplots|voom|saplot", linkData$Link[i])) {
         HtmlLink(linkData$Link[i], linkData$Label[i])
   }
 }