MVAPACK Master Script: Difference between revisions

From Powers Wiki
No edit summary
No edit summary
 
(7 intermediate revisions by the same user not shown)
Line 5: Line 5:


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


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

Latest revision as of 20:47, 23 March 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);
currentdir = pwd;
for i = [1:sizeoffileglob]
if isfolder(F.fileglob{i})
cd(F.fileglob{i});
if (stat('ser') || stat('fid'))
continue;
end
cd(currentdir);
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 = input('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');