comparison 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
comparison
equal deleted inserted replaced
19:c9c6427edfe9 20:0921444c832d
77 string <- gsub(" *[,] *", ",", string) 77 string <- gsub(" *[,] *", ",", string)
78 string <- gsub("^\\s+|\\s+$", "", string) 78 string <- gsub("^\\s+|\\s+$", "", string)
79 return(string) 79 return(string)
80 } 80 }
81 81
82 # Function to make contrast contain valid R names
83 sanitiseContrast <- function(string) {
84 string <- strsplit(string, split="-")
85 string <- lapply(string, make.names)
86 string <- lapply(string, paste, collapse="-")
87 return(string)
88 }
89
82 # Function to change periods to whitespace in a string 90 # Function to change periods to whitespace in a string
83 unmake.names <- function(string) { 91 unmake.names <- function(string) {
84 string <- gsub(".", " ", string, fixed=TRUE) 92 string <- gsub(".", " ", string, fixed=TRUE)
85 return(string) 93 return(string)
86 } 94 }
351 contrastData <- contrastData[, 1, drop=TRUE] 359 contrastData <- contrastData[, 1, drop=TRUE]
352 } else { 360 } else {
353 # Split up contrasts seperated by comma into a vector then sanitise 361 # Split up contrasts seperated by comma into a vector then sanitise
354 contrastData <- unlist(strsplit(opt$contrastInput, split=",")) 362 contrastData <- unlist(strsplit(opt$contrastInput, split=","))
355 } 363 }
356
357 # in case input groups start with numbers this will make the names valid R names, required for makeContrasts
358 contrastData <- sanitiseEquation(contrastData) 364 contrastData <- sanitiseEquation(contrastData)
359 contrastData <- gsub(" ", ".", contrastData, fixed=TRUE) 365 contrastData <- gsub(" ", ".", contrastData, fixed=TRUE)
366
367 # in case input groups start with numbers make the names valid R names, required for makeContrasts
360 cons <- NULL 368 cons <- NULL
369 cons_d <- NULL
361 for (i in contrastData) { 370 for (i in contrastData) {
362 i <- strsplit(i, split="-") 371
363 i <- lapply(i, make.names) 372 # if the contrast is a difference of differences e.g. (A-B)-(X-Y)
364 i <- lapply(i, paste, collapse="-") 373 if (grepl("\\)-\\(", i)) {
365 cons <- append(cons, unlist(i)) 374 i <- unlist(strsplit(i, split="\\)-\\("))
375 i <- gsub("\\(|\\)","", i)
376 for (j in i) {
377 j <- sanitiseContrast(j)
378 j <- paste0("(", j, ")")
379 cons_d <- append(cons_d, unlist(j))
380 }
381 cons_d <- paste(cons_d, collapse = '-')
382 cons <- append(cons, unlist(cons_d))
383 } else {
384 i <- sanitiseContrast(i)
385 cons <- append(cons, unlist(i))
386 }
366 } 387 }
367 388
368 plots <- character() 389 plots <- character()
369 if (!is.null(opt$plots)) { 390 if (!is.null(opt$plots)) {
370 plots <- unlist(strsplit(opt$plots, split=",")) 391 plots <- unlist(strsplit(opt$plots, split=","))
850 status = decideTests(fit, adjust.method=opt$pAdjOpt, p.value=opt$pValReq, 871 status = decideTests(fit, adjust.method=opt$pAdjOpt, p.value=opt$pValReq,
851 lfc=opt$lfcReq) 872 lfc=opt$lfcReq)
852 sumStatus <- summary(status) 873 sumStatus <- summary(status)
853 874
854 for (i in 1:length(cons)) { 875 for (i in 1:length(cons)) {
876 con_name <- cons[i]
855 con <- cons[i] 877 con <- cons[i]
856 con <- gsub("\\(|\\)", "", con) 878 con <- gsub("\\(|\\)", "", con)
857 # Collect counts for differential expression 879 # Collect counts for differential expression
858 upCount[i] <- sumStatus["Up", i] 880 upCount[i] <- sumStatus["Up", i]
859 downCount[i] <- sumStatus["Down", i] 881 downCount[i] <- sumStatus["Down", i]
955 } 977 }
956 978
957 imgName <- paste0("MDVolPlot_", con) 979 imgName <- paste0("MDVolPlot_", con)
958 imgAddr <- paste0("mdvolplot_", con, ".png") 980 imgAddr <- paste0("mdvolplot_", con, ".png")
959 imageData <- rbind(imageData, c(imgName, imgAddr)) 981 imageData <- rbind(imageData, c(imgName, imgAddr))
960 title(paste0("Contrast: ", unmake.names(con)), outer=TRUE, cex.main=1.5) 982 title(paste0("Contrast: ", con_name), outer=TRUE, cex.main=1.5)
961 invisible(dev.off()) 983 invisible(dev.off())
962 984
963 if ("h" %in% plots) { 985 if ("h" %in% plots) {
964 # Plot Heatmap 986 # Plot Heatmap
965 topgenes <- rownames(top[1:opt$topgenes, ]) 987 topgenes <- rownames(top[1:opt$topgenes, ])
1074 cata("</table>") 1096 cata("</table>")
1075 1097
1076 cata("<h4>Plots:</h4>\n") 1098 cata("<h4>Plots:</h4>\n")
1077 #PDFs 1099 #PDFs
1078 for (i in 1:nrow(linkData)) { 1100 for (i in 1:nrow(linkData)) {
1079 if (grepl("density|cpm|boxplot|mds|mdplots|voom|saplot", linkData$Link[i])) { 1101 if (grepl(".pdf", linkData$Link[i]) & grepl("density|cpm|boxplot|mds|mdplots|voom|saplot", linkData$Link[i])) {
1080 HtmlLink(linkData$Link[i], linkData$Label[i]) 1102 HtmlLink(linkData$Link[i], linkData$Label[i])
1081 } 1103 }
1082 } 1104 }
1083 1105
1084 for (i in 1:nrow(linkData)) { 1106 for (i in 1:nrow(linkData)) {