From cf9fa313fc337159b55bff3f47cc16392b6f0662 Mon Sep 17 00:00:00 2001 From: Sarvesh Prakash Nikumbh Date: Sun, 30 Jul 2017 22:19:17 +0200 Subject: [PATCH] Comments for the plotting function edited. --- analyze_wvector.m | 4 ++-- plotHeatmap.m | 57 ++++++++++++++++++++++++++++++++++++++++++++++ plot_heatmap.R | 26 ++++++++++++--------- plot_heatmap.m | 58 ----------------------------------------------- 4 files changed, 74 insertions(+), 71 deletions(-) create mode 100644 plotHeatmap.m delete mode 100644 plot_heatmap.m diff --git a/analyze_wvector.m b/analyze_wvector.m index 687dc1f..557715c 100644 --- a/analyze_wvector.m +++ b/analyze_wvector.m @@ -81,8 +81,8 @@ jump_pos = j*max_dist; perfect_pos = start_pos + jump_pos; norms_pair_matrix(i+1,j+1) = norm( twoD_means(perfect_pos : perfect_pos + max_dist-1), 2); - end%inner for ends -end%outer for ends + end % inner for ends +end % outer for ends heatmapCSV_fname = strcat(folderName, '/weightVectorNormed_rank', num2str(rankId), '.csv'); csvwrite(heatmapCSV_fname, norms_pair_matrix); diff --git a/plotHeatmap.m b/plotHeatmap.m new file mode 100644 index 0000000..4945414 --- /dev/null +++ b/plotHeatmap.m @@ -0,0 +1,57 @@ +function [plotDataM] = plotHeatmap(dataM, filename, climmin, climmax) + +% PLOTHEATMAP +% Plots the heatmap given a matrix +% +% INPUT PARAMS +% Param dataM +% The matrix to be plotted +% +% Param filename +% Filename for the PDF with the matrix plotted +% +% Param climmin, climmax +% Colormap limits -- minimum and maximum +% +% OUTPUT PARAMS +% Param plotDataM +% +% ADDITIONAL NOTES +% -- Standardize the values in the range [0,1] +% -- Plot the heatmap +% +% Author: snikumbh@mpi-inf.mpg.de + +% instances along columns +% sequences along rows + +shading interp; + +if nargin < 4 + climmin = 0.75; + climmax = 0.95; +elseif nargin < 2 + filename = 'Heatmap.pdf'; +end + +%standardize matrix rows to range 0-to-1 +normDataM = standardizeMatrix(dataM); +% plotDataM = normDataM; +plotDataM = zeros(size(normDataM)); +% using rankings +[~, rankingDataM] = sort(normDataM(1:size(dataM,1),1:size(dataM,2)), 2, 'descend'); +for i=1:size(plotDataM,1) + plotDataM(i,rankingDataM(i,:)) = 1:size(dataM,2); +end +% +fig = figure; +% +clims = [climmin climmax]; +% clims = [0 1]; +imagesc(plotDataM); +cb = colorbar; +% +% saveas(gcf, filename, 'pdf'); +print(gcf, filename, '-dpdf', '-r900'); + +end diff --git a/plot_heatmap.R b/plot_heatmap.R index 8256b90..352a329 100644 --- a/plot_heatmap.R +++ b/plot_heatmap.R @@ -1,27 +1,32 @@ -#Reusing this R script from an earlier project. +# 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 cellline, region#, oligoLen -#send inputFilename outputFolder rank oligoLen +args <- commandArgs(TRUE) +# send inputFilename outputFolder rank and oligoLen inputFilename <- args[1] outputFolder <- args[2] rank <- args[3] -#oligoLen <- 2 oligoLen <- as.numeric(args[4]) - +# this project, we only use the heatmap functionality plot_heatmap <- TRUE if(plot_heatmap == TRUE){ - -library(lattice) + library(lattice) pdfname <- paste0(outputFolder, "/norms_mat_rank", rank, "_oligolen", oligoLen, ".pdf") - #print(PDF_FNAME) 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 #paste0(a"all_weight_vectors/", cellline, "/heatmaps/norms_mat_run", runs[i], "_fold", folds[j] ,"_region", regions[r], "_oligolen", oligoLen, ".csv") - #print(fname) + fname <- inputFilename mat_data <- as.matrix(read.csv(fname, header = FALSE)) rownames(mat_data) <- names colnames(mat_data) <- names @@ -29,7 +34,6 @@ library(lattice) 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) diff --git a/plot_heatmap.m b/plot_heatmap.m deleted file mode 100644 index 4a9d41a..0000000 --- a/plot_heatmap.m +++ /dev/null @@ -1,58 +0,0 @@ -function [plotDataM] = plot_heatmap(dataM, filename, climmin, climmax) -%1. normalize the values range [0,1] - -%2. Plot three heatmaps: Non-shifted, Shifted and averaged/smoothed case - -% instances along columns -%columnLabels = ; -% sequences along rows -%dataM = rand(100,10); -%standardize matrix rows to range 0-to-1. -shading interp; - -if nargin < 4 - climmin = 0.75; - climmax = 0.95; -elseif nargin < 2 - filename = 'Heatmap.pdf'; -end - -normDataM = standardizeMatrix(dataM); -%plotDataM = normDataM; -plotDataM = zeros(size(normDataM)); -%using rankings -[~, rankingDataM] = sort(normDataM(1:size(dataM,1),1:size(dataM,2)), 2, 'descend'); -for i=1:size(plotDataM,1) - plotDataM(i,rankingDataM(i,:)) = 1:size(dataM,2); -end -% adjust indices -%nCols = (size(plotDataM,2)+1)/2; -%idx = []; -%for i=1:nCols -% idx = [idx i i+(nCols)]; -%end -%nidx = idx(1:(end-1)); -%plotDataM_adjusted = plotDataM(:,nidx); -fig = figure; -%colormap(map) -% -%colormap(gray(climmax-climmin+1)); -% -clims = [climmin climmax]; -%clims = [0 1]; -imagesc(plotDataM); -%imagesc(standardizeMatrix(dataM)); -cb = colorbar; -% -%caxismin = 1; -%caxismax = climmax-climmin+1; -%caxis([caxismin caxismax]); % sets colorbar limits -%set(cb,'xtick',[climmin climmax]); -%set(cb, 'ylim', climmin+0.5:1:climmax); -%labels = {'Rank 1', 'Rank 2','Rank 3 \& beyond'}; -%lcolorbar(labels,'fontweight','bold'); -% -%saveas(gcf, filename, 'pdf'); -print(gcf, filename, '-dpdf', '-r900'); - -end