% 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.
% ---------------------------------------------------
% NOTE: this script makes use of the ‘Read_Bruker_2D’ 
% script available from the NMRFAM library 
% (http://pine.nmrfam.wisc.edu/download_scripts.html)
% ---------------------------------------------------

%choose NMR dataset
folder = uigetdir();

% Load 2rr file info for each spectrum (2rr)
filelist = dir(fullfile(folder, '\*\pdata\1\2rr')); 

% Get full path names for each text file
input_file = fullfile({filelist.folder}, {filelist.name});
% file_paths will contain only the paths where '2rr' is present

Acqus_H_File_Path = fullfile({filelist.folder}, '..\..\acqus');
Procs_H_File_Path = fullfile({filelist.folder}, 'procs');
Acqus_2nD_File_Path = fullfile({filelist.folder}, '..\..\acqu2s');
Procs_2nD_File_Path = fullfile({filelist.folder}, 'proc2s');

for i = 1 : numel(input_file)
    
    [Spectrum, Params] = Read_Bruker_2D(input_file{i}, Acqus_H_File_Path{i}, Procs_H_File_Path{i}, Acqus_2nD_File_Path{i}, Procs_2nD_File_Path{i});
    Spectra(:,:,i) = Spectrum;
end

% Get 1H chemical shift --you need to know how many points and the offset--
cs_H = 10.50936 - Params.xSW*((1:576)/576)/Params.xOBS;

% Get 15N chemical shift
cs_N = 134.2204 - Params.ySW*((1:384)/384)/Params.yOBS;

% Plot first spectrum
figure, contour(cs_H,cs_N,Spectra(:,:,1), 64); title('Spectrum 1')
ax = gca;
ax.XDir = 'reverse';
ax.YDir = 'reverse';
%fprintf('-xSW= %.03f -ySW= %.03f\n', Params.xSW, Params.ySW);
%fprintf('-xOBS= %.03f -yOBS= %.03f\n', Params.xOBS, Params.yOBS);
%fprintf('-xCAR= %.03f -yCAR= %.03f\n', Params.xCAR, Params.yCAR);
