%%% Histogram for growth_rate %%%%%%%%
%mat1=dlmread('wm_km_growth_rate.csv',' ');
% Using the barplot in the way I have coded it is the same as using histc
% to generate the diagrams, where histc specifies bins in terms of
% their edges
mat1=dlmread('wm_km_growth_rateNoRSYmat.csv',' ');
mat1=-mat1;
j=1;
freqs1=1:20;
for i=-0.3:0.02:0.08
 gather=((mat1>= i) & (mat1< (i+0.02)));
 freqs1(j)=length(mat1(gather,:));
 j=j+1;
end
mat1rangeG=-0.3:0.02:0.1;  % this gives 20 bins with this range as edges for plotting
mat1range=-0.3:0.02:0.08;  % this gives 20 bins with this range as edges

%mat2=dlmread('wr_kr_growth_rate.csv',' ');
mat2=dlmread('wr_kr_growth_rateNoRSYmat.csv',' ');
mat2=-mat2;
j=1;
freqs2=1:20;
for i=-0.3:0.02:0.08
 gather=((mat2>=i) & (mat2<(i+0.02)));
 freqs2(j)=length(mat2(gather,:));
 j=j+1;
end

mat3=dlmread('wm_wmn_lag_time.csv',' ');
mat3=-mat3;
j=1;
freqs3=1:20;
for i=-0.3:0.02:0.08
 gather=((mat3>i) & (mat3<(i+0.02)));
 freqs3(j)=length(mat3(gather,:));
 j=j+1;
end

%%%%%%% Histogram for max OD %%%%%%%%%
%mat1=dlmread('wm_km_global_max_od.csv',' ');
mat1=dlmread('wm_km_global_max_odNoRSYmat.csv',' ');
mat1=-mat1;
j=1;
freqs1=1:20;
for i=-0.655:0.045:0.2
 gather=((mat1>i) & (mat1<(i+0.045)));
 freqs1(j)=length(mat1(gather,:));
 j=j+1;
end
mat1range=-0.655:0.045:0.2;     % this gives 20 bins with this range
mat1rangeG=-0.655:0.045:0.245;  % this gives 20 bins with this range as edges for plotting

mat1range=-0.6:0.04:0.18;     % this gives 20 bins with this range
mat1rangeG=-0.64:0.04:0.2; 

%mat2=dlmread('wr_kr_global_max_od.csv',' ');
mat2=dlmread('wr_kr_global_max_odNoRSYmat.csv',' ');
mat2=-mat2;
j=1;
freqs2=1:20;
for i=-0.655:0.045:0.2
 gather=((mat2>i) & (mat2<(i+0.045)));
 freqs2(j)=length(mat2(gather,:));
 j=j+1;
end


nfreqs=horzcat(freqs1',freqs2');

%%%% overlayed version of bar plot %%%%%%
barWidth=0.8; %1.1
%% for growth rate
%bar1=bar(mat1rangeG(1:20)+0.01,histc(mat1,mat1range),barWidth);
% OR bar1=bar(mat1range,histc(mat1,mat1range),'histc');
%% for glob_max_od
bar1=bar(mat1rangeG(1:20)+0.04,histc(mat1,mat1range),barWidth);
set(bar1,'FaceColor','b','EdgeColor','w');
hold on;
barWidth=0.4; %0.7
%% for growth rate
%bar2=bar(mat1rangeG(1:20)+0.01,histc(mat2,mat1range),barWidth);
% OR bar2=bar(mat1range,histc(mat2,mat1range),'histc');
%% for glob_max_od
bar2=bar(mat1rangeG(1:20)+0.04,histc(mat2,mat1range),barWidth);
set(bar2,'FaceColor','r','EdgeColor','w');
hold off;

%%%% grouped version of bar plot %%%%%%%
bar(mat1range(2:21),nfreqs,1.6); % number here is bar width
%cmat=[[0 0 1]; [1 0 0]];       % blue and red defined in RGB
%cmat=[[0 1 0]; [1 1 0]];       % green and yellow defined in RGB
colormap(cmat);       

%%%% for both versions %%%%%%%%
legend_handle=legend('k-w in minimal','k-w in rich',2);
set(legend_handle,'FontSize',14);

%% for individual growth rate
%legend_handle=legend('k-w in minimal',2);
legend_handle=legend('k-w in rich',2);
set(legend_handle,'FontSize',14);



xlabel('Difference in OD increase per hour (at maximum rate of OD increase)','fontsize',14);
ylabel('Frequency counts','fontsize',16);
title('Histogram of differences in Growth Rate (knockout-wtype)','fontsize',14,'fontweight','b');
line([0 0],[0 16],[0 0],'Color','k','LineStyle','--','LineWidth',2,'Marker','none');
set(gca,'xlim',[-0.3 0.1])
set(gca,'XTick',[-0.3:0.1:0.1]);
set(gca,'XTickLabel',{'-0.3';'-0.2';'-0.1';'0';'0.1'});
set(gca,'YTick',[4 8 12 16]);
set(gca,'YTickLabel',{'4';'8';'12';'16'});
set(gca,'XTickMode','manual','YTickMode','manual')
set(gca,'FontName','FixedWidth');
set(gca,'FontSize',16);
set(gca,'FontWeight','b');
set(gca,'TickLength',[0.03 0]);

%%%%% for global_max_od %%%%%%%
legend_handle=legend('k-w in minimal','k-w in rich',2);
set(legend_handle,'FontSize',14);

xlabel('Difference in Global Maximum Optical Density at 595nm','fontsize',16);
ylabel('Frequency counts','fontsize',16);
title('Histogram of differences in Global Maximum OD (knockout-wtype)','fontsize',14,'fontweight','b');
line([0 0],[0 10],[0 0],'Color','k','LineStyle','--','LineWidth',2,'Marker','none');
set(gca,'xlim',[-0.7 0.2])
set(gca,'XTick',[-0.6:0.2:0.2]);
set(gca,'XTickLabel',{'-0.6';'-0.4';'-0.2';'0';'0.2'});
%set(gca,'YTick',[4 8 12 16]);
%set(gca,'YTickLabel',{'4';'8';'12';'16'});
set(gca,'YTick',[2 4 6 8 10]);
set(gca,'YTickLabel',{'2';'4';'6';'8';'10'});
set(gca,'XTickMode','manual','YTickMode','manual')
set(gca,'FontName','FixedWidth');
set(gca,'FontSize',16);
set(gca,'FontWeight','b');
set(gca,'TickLength',[0.03 0]);

%%% histc of k-w in minimal growth_rate%%%%
fname='km_wm_growth_rate2bar.tiff';
saveas(gcf,fname,'tiff');

%%% histc of k-w in rich growth_rate%%%%
fname='kr_wr_growth_rate2bar.tiff';
saveas(gcf,fname,'tiff');

%%% histc of k-w in minimal global_max_od%%%%
fname='km_wm_global_max_od2bar.tiff';
saveas(gcf,fname,'tiff');

%%% histc of k-w in rich global_max_od%%%%
fname='kr_wr_global_max_od2bar.tiff';
saveas(gcf,fname,'tiff');

%%% overlayed version of bar plot (growth_rate)%%%%%
fname='overlayed_growth_rate0.8bar.tiff';
saveas(gcf,fname,'tiff');

%%% overlayed version of bar plot (global_max_od)%%%%%
fname='overlayed_global_max_od0.8bar.tiff';
saveas(gcf,fname,'tiff');

%%%%% grouped version of bar plot %%%%
fname='grouped_growth_rate1.6.tiff';
saveas(gcf,fname,'tiff');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


