%% Figure 9 
%Long range intensity trends and posible solutions
% detrending could work, I see it here but better not implement it, keeping
% the long range trends might give bio-relevant info
% This code is the base for figure 3c


%% rolling average for long-range intensity trends 
% ampl=0.03;
% figure
% for i=1:16
%  %tiledlayout(2,1,'TileSpacing','compact')
%  %nexttile
%  plot(bT_newpsf_scer{i}.rawBarcode+i*ampl)
%  %nexttile
%  hold on
%  plot(movmean(bT_newpsf_scer{i}.rawBarcode,100)+i*ampl,'r','LineWidth',2)
% end

%%
% ampl=0.03;
% figure
% for i=1:3
%  %tiledlayout(2,1,'TileSpacing','compact')
%  %nexttile
%  plot(bT_newpsf_pombe{i}.rawBarcode+i*ampl-0.1)
%  %nexttile
%  hold on
%  plot(movmean(bT_newpsf_pombe{i}.rawBarcode,100)+i*ampl-0.1,'r','LineWidth',2)
% end
% 
% 
% figure
% plot(zscore(cGenAll{9}.rawBarcode(7:724)))
% hold on
% plot(zscore(detrend(cGenAll{9}.rawBarcode(7:724))),'r')


%% Let's add some detrending to the theory
ampl=0.03;
mov_mean_size=100;
figure
for i=1:3
 %tiledlayout(2,1,'TileSpacing','compact')
 %nexttile
 plot(bT_newpsf_pombe{i}.rawBarcode(3:end-2)+i*ampl-0.1,'Color',[0.5 0.5 0.5])
 %nexttile
 hold on
 plot(movmean(bT_newpsf_pombe{i}.rawBarcode(3:end-2),mov_mean_size)+i*ampl-0.1,'r','LineWidth',2)
  %plot(detrend(bT_newpsf_pombe{i}.rawBarcode)+i*ampl-0.1)
 %nexttile
 
   set(gca,'Color','white')
end


