MVAPACK Master Script: Difference between revisions

From Powers Wiki
No edit summary
No edit summary
Line 5: Line 5:


==The Script==
==The Script==
<code>
<nowiki>
#1 Get Files<br />
#Get Files
display('Using typical unix filename syntax (i.e. ./* or ../your/file/is/here/* or ???). This will only use directories.')<br />
display('Using typical unix filename syntax (i.e. ./* or ../your/file/is/here/* or ???). This will only use directories.')
filepath = input('What is the path to your data? ',"s");<br />
filepath = input('What is the path to your data? ',"s");
F.fileglob = glob(filepath);  %% Number of ? is the number of digits of the file name<br />
F.fileglob = glob(filepath);  %% Number of ? is the number of digits of the file name


%% We only use directories here<br />
%% We only use directories here
count = 1;<br />
count = 1;
sizeoffileglob = numel(F.fileglob);<br />
sizeoffileglob = numel(F.fileglob);
for i = [1:sizeoffileglob]<br />
for i = [1:sizeoffileglob]
   if isfolder(F.fileglob{i})<br />
   if isfolder(F.fileglob{i})
     if (fexist([F.fileglob{1}, '/ser']) || fexist([F.fileglob{1}, '/fid']))<br />
     if (fexist([F.fileglob{1}, '/ser']) || fexist([F.fileglob{1}, '/fid']))
       continue;<br />
       continue;
     end<br />
     end
     F.dirs{count++} = F.fileglob{i};<br />
     F.dirs{count++} = F.fileglob{i};
   end<br />
   end
end<br />
end
checkforexistence = exist('F.dirs')<br />
checkforexistence = exist('F.dirs')
if ~checkforexistence<br />
if ~checkforexistence
   error('There is no NMR data here, seems you have the wrong filepath.')<br />
   error('There is no NMR data here, seems you have the wrong filepath.')
end<br />
end


<br />
#2 Extract Data<br />
%% This could be loadnmr or loaddmx - default should be loadnmr<br />
display('With "@loadnmr" and "@loaddmx" as your choices. Refer to the manual for these functions.');<br />
loadingfunc = input('Which would you like to use? ', "s");<br />
if loadingfunc ~= '@loadnmr' || loadingfunc ~= '@loaddmx'<br />
  error('A loading function was not chosen correctly');<br />
end<br />
[F.data, F.parms, F.t] = feval(loadingfunc, F.dirs); %% Assumes F.dirs were all run with similar parameters<br />


#3 Apodization, Zerofill and Fourier Transform<br />
#Extract Data
%% This could be loadnmr or loaddmx - default should be loadnmr
display('With "@loadnmr" and "@loaddmx" as your choices. Refer to the manual for these functions.');
loadingfunc = input('Which would you like to use? ', "s");
if loadingfunc ~= '@loadnmr' || loadingfunc ~= '@loaddmx'
  error('A loading function was not chosen correctly');
end
[F.data, F.parms, F.t] = feval(loadingfunc, F.dirs); %% Assumes F.dirs were all run with similar parameters


apodizing = input('Would you like to apodize?(y,n) ', "s")<br />
#Apodization, Zerofill and Fourier Transform
if apodizing == 'y' || apodizing == 'Y'<br />
  display('With "@expwindow", "@gausswindow", and "@sinewindow" being the options.(Refer to the manual)')<br />
  functionhandleofapodization = input('Which function would you like to use? ',"s"); %% User choice on function handle<br />
  F.data = apodize(F.data,F.parms,functionhandleofapodization);<br />
end<br />


zerofilling = input('Would you like to zerofill?(y,n) ', "s");<br />
apodizing = input('Would you like to apodize?(y,n) ', "s")
if zerofilling == 'y' || zerofilling == 'Y'<br />
if apodizing == 'y' || apodizing == 'Y'
   numberofzerofills = input('How many zerofills would you like? '); %% User choice on number<br />
   display('With "@expwindow", "@gausswindow", and "@sinewindow" being the options.(Refer to the manual)')
   F.data = zerofill(F.data,F.parms,numberofzerofills);<br />
  functionhandleofapodization = input('Which function would you like to use? ',"s"); %% User choice on function handle
end<br />
   F.data = apodize(F.data,F.parms,functionhandleofapodization);
[S.data, S.ppm] = nmrft(F.data, F.parms);%% finally do something<br />
end


#4 Phase and extract real<br />
zerofilling = input('Would you like to zerofill?(y,n) ', "s");
%% phase correction method objective can be decided<br />
if zerofilling == 'y' || zerofilling == 'Y'
display('Automatic phasing will be performed, you can choose an objective function. Your options are "@simplex_minimum", "@simplex_entropy", "@simplex_whiten", or "@simplex_integral". (Refer to manual)')<br />
  numberofzerofills = input('How many zerofills would you like? '); %% User choice on number
phaseobjective = ('Which objective do you choose? ', "s");<br />
  F.data = zerofill(F.data,F.parms,numberofzerofills);
[S.data, S.phc0, S.phc1] = autophase(S.data, F.parms, phaseobjective);<br />
end
[S.data, S.phc0, S.phc1] = autophase(S.data, F.parms, phaseobjective);<br />
[S.data, S.ppm] = nmrft(F.data, F.parms);%% finally do something
X.data = realnmr(S.data, F.parms); %% extract numerical data<br />
X.ppm = S.ppm;<br />


#5 Alignment and Referencing<br />
#Phase and extract real
%% an if could be used to decide if icosshift or cosshift here**<br />
%% phase correction method objective can be decided
display('With "@coshift" and "@icoshift" as your options.')<br />
display('Automatic phasing will be performed, you can choose an objective function. Your options are "@simplex_minimum", "@simplex_entropy", "@simplex_whiten", or "@simplex_integral". (Refer to manual)')
alignmentoption = input('Which alignment method would you like to use? ',"s");<br />
phaseobjective = ('Which objective do you choose? ', "s");
X.data = feval(alignmentoption, X.data, X.ppm);<br />
[S.data, S.phc0, S.phc1] = autophase(S.data, F.parms, phaseobjective);
X.data = feval(alignmentoption, X.data, X.ppm);<br />
[S.data, S.phc0, S.phc1] = autophase(S.data, F.parms, phaseobjective);
X.data = feval(alignmentoption, X.data, X.ppm);<br />
X.data = realnmr(S.data, F.parms); %% extract numerical data
plot(X.ppm, X.data);<br />
X.ppm = S.ppm;


%% an automatic referencing method could be used instead of this (no automatic method currently available)<br />
#Alignment and Referencing
adjust_zero = 1<br />
%% an if could be used to decide if icosshift or cosshift here**
zero_adjustment = 0<br />
display('With "@coshift" and "@icoshift" as your options.')
  while adjust_zero<br />
alignmentoption = input('Which alignment method would you like to use? ',"s");
X.data = feval(alignmentoption, X.data, X.ppm);
X.data = feval(alignmentoption, X.data, X.ppm);
X.data = feval(alignmentoption, X.data, X.ppm);
plot(X.ppm, X.data);


  X.ppm = refadj(X.ppm, zero_adjustment, 0.0);<br />
%% an automatic referencing method could be used instead of this (no automatic method currently available)
adjust_zero = 1
zero_adjustment = 0
  while adjust_zero


   plot(X.ppm, X.data);<br />
   X.ppm = refadj(X.ppm, zero_adjustment, 0.0);


   adjust_input = input('Do you need to zero?(y/n)  ',"s");<br />
   plot(X.ppm, X.data);
  if adjust_input == "Y" || adjust_input == "y"<br />
          adjust_zero = 1;<br />
        zero_adjustment = input('How much Adjustment?  ');<br />
    else<br />
          adjust_zero = 0;<br />
    end<br />
  end<br />


%% this can be selected as the manual removal method - otherwise ROI methods could be used?**<br />
  adjust_input = input('Do you need to zero?(y/n)  ',"s");
  remove_var = 1;<br />
  if adjust_input == "Y" || adjust_input == "y"
   while remove_var<br />
          adjust_zero = 1;
        zero_adjustment = input('How much Adjustment?  ');
    else
          adjust_zero = 0;
    end
   end


  remove_input = input('Do you need to remove data?(y/n)  ',"s");<br />
%% this can be selected as the manual removal method - otherwise ROI methods could be used?**
  if remove_input == "Y" || remove_input == "y"<br />
  remove_var = 1;
          remove_var = 1;<br />
  while remove_var
        kmin_input = input('What is the minumum of the range?  ');<br />
            kmax_input = input('What is the maximum of the range?  ');<br />
            idxmin = findnearest(X.ppm, kmax_input);<br />
            idxmax = findnearest(X.ppm, kmax_input);<br />
            X.rmvar = [idxmax:idxmin];<br />
            [X.data, X.ppm] = rmvar(X.data, X.ppm, X.rmvar);<br />
            plot(X.ppm, X.data);<br />
    else<br />
          remove_var = 0;<br />
    end<br />
  end<br />


%% binning can be done a number of ways we default to adaptive binning***<br />
  remove_input = input('Do you need to remove data?(y/n)  ',"s");
display('There are multiple ways of binning, this walkthrough uses binadapt.')<br />
  if remove_input == "Y" || remove_input == "y"
[X.bindata, X.binppm] = binadapt(X.data, X.ppm, F.parms);<br />
          remove_var = 1;
%% normalization has multiple options these need to be considered ***<br />
        kmin_input = input('What is the minumum of the range?  ');
X.bindata = histmatch(X.bindata);<br />
            kmax_input = input('What is the maximum of the range?  ');
            idxmin = findnearest(X.ppm, kmax_input);
            idxmax = findnearest(X.ppm, kmax_input);
            X.rmvar = [idxmax:idxmin];
            [X.data, X.ppm] = rmvar(X.data, X.ppm, X.rmvar);
            plot(X.ppm, X.data);
    else
          remove_var = 0;
    end
  end


display('To this point, the important data is extracted and binned as "X.bindata" and can be analyzed');<br />
%% binning can be done a number of ways we default to adaptive binning***
</code>
display('There are multiple ways of binning, this walkthrough uses binadapt.')
[X.bindata, X.binppm] = binadapt(X.data, X.ppm, F.parms);
%% normalization has multiple options these need to be considered ***
X.bindata = histmatch(X.bindata);
 
display('To this point, the important data is extracted and binned as "X.bindata" and can be analyzed');
</nowiki>

Revision as of 02:21, 19 January 2022

A good start

This page represents a good script to get started in MVAPACK/Octave. Copy the script below, or download this one, and save as a .m file in your favorite simple text editor.


The Script

#Get Files display('Using typical unix filename syntax (i.e. ./* or ../your/file/is/here/* or ???). This will only use directories.') filepath = input('What is the path to your data? ',"s"); F.fileglob = glob(filepath);  %% Number of ? is the number of digits of the file name %% We only use directories here count = 1; sizeoffileglob = numel(F.fileglob); for i = [1:sizeoffileglob] if isfolder(F.fileglob{i}) if (fexist([F.fileglob{1}, '/ser']) || fexist([F.fileglob{1}, '/fid'])) continue; end F.dirs{count++} = F.fileglob{i}; end end checkforexistence = exist('F.dirs') if ~checkforexistence error('There is no NMR data here, seems you have the wrong filepath.') end #Extract Data %% This could be loadnmr or loaddmx - default should be loadnmr display('With "@loadnmr" and "@loaddmx" as your choices. Refer to the manual for these functions.'); loadingfunc = input('Which would you like to use? ', "s"); if loadingfunc ~= '@loadnmr' || loadingfunc ~= '@loaddmx' error('A loading function was not chosen correctly'); end [F.data, F.parms, F.t] = feval(loadingfunc, F.dirs); %% Assumes F.dirs were all run with similar parameters #Apodization, Zerofill and Fourier Transform apodizing = input('Would you like to apodize?(y,n) ', "s") if apodizing == 'y' || apodizing == 'Y' display('With "@expwindow", "@gausswindow", and "@sinewindow" being the options.(Refer to the manual)') functionhandleofapodization = input('Which function would you like to use? ',"s"); %% User choice on function handle F.data = apodize(F.data,F.parms,functionhandleofapodization); end zerofilling = input('Would you like to zerofill?(y,n) ', "s"); if zerofilling == 'y' || zerofilling == 'Y' numberofzerofills = input('How many zerofills would you like? '); %% User choice on number F.data = zerofill(F.data,F.parms,numberofzerofills); end [S.data, S.ppm] = nmrft(F.data, F.parms);%% finally do something #Phase and extract real %% phase correction method objective can be decided display('Automatic phasing will be performed, you can choose an objective function. Your options are "@simplex_minimum", "@simplex_entropy", "@simplex_whiten", or "@simplex_integral". (Refer to manual)') phaseobjective = ('Which objective do you choose? ', "s"); [S.data, S.phc0, S.phc1] = autophase(S.data, F.parms, phaseobjective); [S.data, S.phc0, S.phc1] = autophase(S.data, F.parms, phaseobjective); X.data = realnmr(S.data, F.parms); %% extract numerical data X.ppm = S.ppm; #Alignment and Referencing %% an if could be used to decide if icosshift or cosshift here** display('With "@coshift" and "@icoshift" as your options.') alignmentoption = input('Which alignment method would you like to use? ',"s"); X.data = feval(alignmentoption, X.data, X.ppm); X.data = feval(alignmentoption, X.data, X.ppm); X.data = feval(alignmentoption, X.data, X.ppm); plot(X.ppm, X.data); %% an automatic referencing method could be used instead of this (no automatic method currently available) adjust_zero = 1 zero_adjustment = 0 while adjust_zero X.ppm = refadj(X.ppm, zero_adjustment, 0.0); plot(X.ppm, X.data); adjust_input = input('Do you need to zero?(y/n) ',"s"); if adjust_input == "Y" || adjust_input == "y" adjust_zero = 1; zero_adjustment = input('How much Adjustment? '); else adjust_zero = 0; end end %% this can be selected as the manual removal method - otherwise ROI methods could be used?** remove_var = 1; while remove_var remove_input = input('Do you need to remove data?(y/n) ',"s"); if remove_input == "Y" || remove_input == "y" remove_var = 1; kmin_input = input('What is the minumum of the range? '); kmax_input = input('What is the maximum of the range? '); idxmin = findnearest(X.ppm, kmax_input); idxmax = findnearest(X.ppm, kmax_input); X.rmvar = [idxmax:idxmin]; [X.data, X.ppm] = rmvar(X.data, X.ppm, X.rmvar); plot(X.ppm, X.data); else remove_var = 0; end end %% binning can be done a number of ways we default to adaptive binning*** display('There are multiple ways of binning, this walkthrough uses binadapt.') [X.bindata, X.binppm] = binadapt(X.data, X.ppm, F.parms); %% normalization has multiple options these need to be considered *** X.bindata = histmatch(X.bindata); display('To this point, the important data is extracted and binned as "X.bindata" and can be analyzed');