% This script is provided "as is", and the authors are not responsible
% whatsoever for the outcomes of this script or any modification.		
% The usage of the script in any publication should be acknowledged by citing:
% Barbieri L, Luchinat E, "Monitoring Protein-Ligand Interactions in Human 
% Cells by Real-Time Quantitative In-Cell NMR using a High Cell Density 
% Bioreactor", Journal of Visualized Experiments.
% ---------------------------------------------------

% Split and reshape optput spectra from MCR-ALS
sopt_A140 = reshape(sopt(1:2,1:1271).',31,41,[]);
sopt_N53 = reshape(sopt(1:2,1272:6677).',51,106,[]);
sopt_G10 = reshape(sopt(1:2,6678:8723).',31,66,[]);
sopt_V14 = reshape(sopt(1:2,8724:16979).',86,96,[]);

% Create chemical shift for each spectral region
cs_H_A140 = 10.50936 - Params.xSW*((502:542)/576)/Params.xOBS;
cs_N_A140 = 134.2204 - Params.ySW*((180:210)/384)/Params.yOBS;
cs_H_N53 = 10.50936 - Params.xSW*((445:550)/576)/Params.xOBS;
cs_N_N53 = 134.2204 - Params.ySW*((260:310)/384)/Params.yOBS;
cs_H_G10 = 10.50936 - Params.xSW*((200:265)/576)/Params.xOBS;
cs_N_G10 = 134.2204 - Params.ySW*((220:250)/384)/Params.yOBS;
cs_H_V14 = 10.50936 - Params.xSW*((370:465)/576)/Params.xOBS;
cs_N_V14 = 134.2204 - Params.ySW*((120:205)/384)/Params.yOBS;

% Contour plots
clev = 4000000*1.2.^(0:31);
subplot(2,2,1); 
contour(cs_H_A140,cs_N_A140,sopt_A140(:,:,1), clev, 'k');
hold on
contour(cs_H_A140,cs_N_A140,sopt_A140(:,:,2), clev, 'r');
hold off
ax = gca; ax.XDir = 'reverse'; ax.YDir = 'reverse';
ax.FontSize = 8; ax.TickDir = 'out'; ax.TickLength = [0.02 0.02];
subplot(2,2,2); 
contour(cs_H_N53,cs_N_N53,sopt_N53(:,:,1), clev, 'k');
hold on
contour(cs_H_N53,cs_N_N53,sopt_N53(:,:,2), clev, 'r');
hold off
ax = gca; ax.XDir = 'reverse'; ax.YDir = 'reverse';
ax.FontSize = 8; ax.TickDir = 'out'; ax.TickLength = [0.02 0.02];
subplot(2,2,3); 
contour(cs_H_G10,cs_N_G10,sopt_G10(:,:,1), clev, 'k');
hold on
contour(cs_H_G10,cs_N_G10,sopt_G10(:,:,2), clev, 'r');
hold off
ax = gca; ax.XDir = 'reverse'; ax.YDir = 'reverse';
ax.FontSize = 8; ax.TickDir = 'out'; ax.TickLength = [0.02 0.02];
subplot(2,2,4); 
contour(cs_H_V14,cs_N_V14,sopt_V14(:,:,1), clev, 'k');
hold on
contour(cs_H_V14,cs_N_V14,sopt_V14(:,:,2), clev, 'r');
hold off
ax = gca; ax.XDir = 'reverse'; ax.YDir = 'reverse';
ax.FontSize = 8; ax.TickDir = 'out'; ax.TickLength = [0.02 0.02];
