Skip to content

Commit

Permalink
Comments for the plotting function edited.
Browse files Browse the repository at this point in the history
snikumbh committed Jul 30, 2017
1 parent 3aa7aa2 commit cf9fa31
Showing 4 changed files with 74 additions and 71 deletions.
4 changes: 2 additions & 2 deletions analyze_wvector.m
Original file line number Diff line number Diff line change
@@ -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);
57 changes: 57 additions & 0 deletions plotHeatmap.m
Original file line number Diff line number Diff line change
@@ -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
26 changes: 15 additions & 11 deletions plot_heatmap.R
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@

#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
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)
58 changes: 0 additions & 58 deletions plot_heatmap.m

This file was deleted.

0 comments on commit cf9fa31

Please sign in to comment.