Mercurial > repos > earlhaminst > plotheatmap
changeset 1:05fbc5c891c5 draft default tip
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/main/tools/plotheatmap commit 6e40bbe92367310e9d3ec69571d08eb49af7c0a6-dirty
author | earlhaminst |
---|---|
date | Mon, 24 Feb 2025 11:03:02 +0000 |
parents | bd8fd161908b |
children | |
files | plotheatmap.xml script.R |
diffstat | 2 files changed, 59 insertions(+), 56 deletions(-) [+] |
line wrap: on
line diff
--- a/plotheatmap.xml Wed Jul 12 14:29:51 2017 -0400 +++ b/plotheatmap.xml Mon Feb 24 11:03:02 2025 +0000 @@ -1,5 +1,5 @@ -<tool id="plotheatmap" name="plotHeatmap" version="1.0"> - <description>Plot heatmap</description> +<tool id="plotheatmap" name="Plot heatmap" version="1.0"> + <description>of gene expression data</description> <requirements> <requirement type="package" version="1.34.0">bioconductor-preprocesscore</requirement> <requirement type="package" version="3.0.1">r-gplots</requirement>
--- a/script.R Wed Jul 12 14:29:51 2017 -0400 +++ b/script.R Mon Feb 24 11:03:02 2025 +0000 @@ -1,91 +1,94 @@ #!/usr/bin/env Rscript -args = commandArgs(TRUE) -countDataPath = args[1] -statsDataPath = args[2] -logFC = args[3] -logCPM = args[4] -pValue = args[5] -fdr = args[6] +args <- commandArgs(TRUE) +countDataPath <- args[1] +statsDataPath <- args[2] +logFC <- args[3] +logCPM <- args[4] +pValue <- args[5] +fdr <- args[6] -clusterRow = args[7] -clusterCol = args[8] -hclustMethod = args[9] +clusterRow <- args[7] +clusterCol <- args[8] +hclustMethod <- args[9] -mgColumnNm = as.numeric(args[10]) -mgRowNm = as.numeric(args[11]) +mgColumnNm <- as.numeric(args[10]) +mgRowNm <- as.numeric(args[11]) -pdfWidth = as.numeric(args[12]) -pdfHeight = as.numeric(args[13]) +pdfWidth <- as.numeric(args[12]) +pdfHeight <- as.numeric(args[13]) -if(clusterRow == "Yes"){ - clusterRow = TRUE +if (clusterRow == "Yes") { + clusterRow <- TRUE } else { - clusterRow = NA + clusterRow <- NA } -if(clusterCol == "Yes"){ - clusterCol = TRUE +if (clusterCol == "Yes") { + clusterCol <- TRUE } else { - clusterCol = NA + clusterCol <- NA } require(preprocessCore) require(gplots) -#prepare counts data -------------------------------------------------------- -countData = read.table(countDataPath, comment = "", - sep = "\t") +# prepare counts data -------------------------------------------------------- +countData <- read.table(countDataPath, + comment = "", + sep = "\t" +) -groups = sapply(as.character(countData[1, -1]), strsplit, ":") -groups = as.vector(t(countData[1, -1])) +groups <- sapply(as.character(countData[1, -1]), strsplit, ":") +groups <- as.vector(t(countData[1, -1])) -names = as.vector(t(countData[2, -1])) +names <- as.vector(t(countData[2, -1])) -countData = countData[-c(1,2), ] -rownames(countData) = countData[, 1] -countData = countData[, -1] -colnames(countData) = names +countData <- countData[-c(1, 2), ] +rownames(countData) <- countData[, 1] +countData <- countData[, -1] +colnames(countData) <- names -countData = countData[, order(groups, names)] +countData <- countData[, order(groups, names)] # prepare stats data ------------------------------------------------------ -statsData = read.table(statsDataPath, sep = "\t", - header = T) +statsData <- read.table(statsDataPath, + sep = "\t", + header = T +) -colnames(statsData)[-1] = sapply(colnames(statsData)[-1], function(x){ - unlist(strsplit(x, ".", fixed = T))[3] +colnames(statsData)[-1] <- sapply(colnames(statsData)[-1], function(x) { + unlist(strsplit(x, ".", fixed = T))[3] }) -wh = which(abs(statsData$logFC) >= logFC & statsData$logCPM >= logCPM & statsData$PValue <= pValue & statsData$FDR <= fdr) +wh <- which(abs(statsData$logFC) >= logFC & statsData$logCPM >= logCPM & statsData$PValue <= pValue & statsData$FDR <= fdr) -for(i in 1:ncol(countData)){ - countData[,i] = as.numeric(countData[,i]) +for (i in 1:ncol(countData)) { + countData[, i] <- as.numeric(countData[, i]) } -countDataNorm = normalize.quantiles(as.matrix(countData), copy = T) -countDataNormLog = log(countDataNorm + 1, 2) +countDataNorm <- normalize.quantiles(as.matrix(countData), copy = T) +countDataNormLog <- log(countDataNorm + 1, 2) -colnames(countDataNormLog) = colnames(countData) -rownames(countDataNormLog) = rownames(countData) +colnames(countDataNormLog) <- colnames(countData) +rownames(countDataNormLog) <- rownames(countData) -#svg("heatmap.svg", width = 3+length(names), height = 1/2*length(wh)) +# svg("heatmap.svg", width = 3+length(names), height = 1/2*length(wh)) pdf("heatmap.pdf", width = pdfWidth, height = pdfHeight) heatmap.2( - countDataNormLog[wh, ], - density.info=c("none"), - hclustfun = function(x) hclust(x, method = hclustMethod), - distfun = function(x) as.dist(1-cor(t(x))), - col = bluered(50), - scale = "row", - trace = "none", - Rowv = clusterRow, - Colv = clusterCol, - margins = c(mgColumnNm, mgRowNm) + countDataNormLog[wh, ], + density.info = c("none"), + hclustfun = function(x) hclust(x, method = hclustMethod), + distfun = function(x) as.dist(1 - cor(t(x))), + col = bluered(50), + scale = "row", + trace = "none", + Rowv = clusterRow, + Colv = clusterCol, + margins = c(mgColumnNm, mgRowNm) ) dev.off() -