Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
44 lines (41 sloc)
1.66 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Reusing this R script from an earlier project. | |
# R script to plot a heatmap of the l2-normed weight vector | |
# | |
# Input: | |
# Input filename, output folder (path), rank of the weight vector, | |
# and the oligomer length for ODH | |
# | |
# Output: Weight vector l2-norm matrix heatmap | |
# | |
# Author: snikumbh@mpi-inf.mpg.de | |
args <- commandArgs(TRUE) | |
# send inputFilename outputFolder rank and oligoLen | |
inputFilename <- args[1] | |
outputFolder <- args[2] | |
rank <- args[3] | |
oligoLen <- as.numeric(args[4]) | |
# this project, we only use the heatmap functionality | |
plot_heatmap <- TRUE | |
if(plot_heatmap == TRUE){ | |
library(lattice) | |
pdfname <- paste0(outputFolder, "/norms_mat_rank", rank, "_oligolen", oligoLen, ".pdf") | |
names <- seq(1,4^oligoLen, by=1) | |
x <- expand.grid(rep(list(c('A', 'C', 'G', 'T')), 2)) | |
names <- do.call(paste0, rev(x)) | |
new.palette <- colorRampPalette(c("white","blue"),space="rgb") | |
fname <- inputFilename | |
mat_data <- as.matrix(read.csv(fname, header = FALSE)) | |
rownames(mat_data) <- names | |
colnames(mat_data) <- names | |
pdf(pdfname) | |
p <- levelplot(mat_data, col.regions=new.palette(20), scales=list(x=list(cex=.5, rot= 90),y=list(cex=.5)), xlab=list(label=paste0(oligoLen, "-mers"), cex=.9), ylab=list(label=paste0(oligoLen, "-mers"), cex=.9), region = TRUE, main="", title = paste0("_heatmaps")) | |
print(p) | |
dev.off() | |
}else{ | |
pdf("barplot_max_weight_subvector.pdf") | |
weights <- as.matrix(read.table("max_weight_subvector.lsv", sep = ",", header = FALSE), ncol = 1) | |
barplot(weights[,1], main="", ylim = c(-0.1, 0.6), ylab="discriminant weights", cex.lab = 1.0) | |
text(50.0, -0.05, "Distances", cex=1.0, pos=4, col="black") | |
box() | |
dev.off() | |
} |