MVAPACK Master Script: Difference between revisions

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


==The Script==
==The Script==
<nowiki>
<code>
#Get Files
#1 Get Files<br />
display('Using typical unix filename syntax (i.e. ./* or ../your/file/is/here/* or ???). This will only use directories.')
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");
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
F.fileglob = glob(filepath);  %% Number of ? is the number of digits of the file name<br />


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


<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 />


#Extract Data
#3 Apodization, Zerofill and Fourier Transform<br />
%% 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")<br />
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 />


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


zerofilling = input('Would you like to zerofill?(y,n) ', "s");
#4 Phase and extract real<br />
if zerofilling == 'y' || zerofilling == 'Y'
%% phase correction method objective can be decided<br />
  numberofzerofills = input('How many zerofills would you like? '); %% User choice on number
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 />
  F.data = zerofill(F.data,F.parms,numberofzerofills);
phaseobjective = ('Which objective do you choose? ', "s");<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
[S.data, S.phc0, S.phc1] = autophase(S.data, F.parms, phaseobjective);<br />
X.data = realnmr(S.data, F.parms); %% extract numerical data<br />
X.ppm = S.ppm;<br />


#Phase and extract real
#5 Alignment and Referencing<br />
%% phase correction method objective can be decided
%% an if could be used to decide if icosshift or cosshift here**<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)')
display('With "@coshift" and "@icoshift" as your options.')<br />
phaseobjective = ('Which objective do you choose? ', "s");
alignmentoption = input('Which alignment method would you like to use? ',"s");<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
X.data = feval(alignmentoption, X.data, X.ppm);<br />
X.ppm = S.ppm;
plot(X.ppm, X.data);<br />


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


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


   plot(X.ppm, X.data);
   adjust_input = input('Do you need to zero?(y/n)  ',"s");<br />
  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 />


  adjust_input = input('Do you need to zero?(y/n)  ',"s");
%% this can be selected as the manual removal method - otherwise ROI methods could be used?**<br />
  if adjust_input == "Y" || adjust_input == "y"
  remove_var = 1;<br />
          adjust_zero = 1;
   while remove_var<br />
        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_input = input('Do you need to remove data?(y/n)  ',"s");<br />
  remove_var = 1;
  if remove_input == "Y" || remove_input == "y"<br />
   while remove_var
          remove_var = 1;<br />
        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 />


  remove_input = input('Do you need to remove data?(y/n)  ',"s");
%% binning can be done a number of ways we default to adaptive binning***<br />
  if remove_input == "Y" || remove_input == "y"
display('There are multiple ways of binning, this walkthrough uses binadapt.')<br />
          remove_var = 1;
[X.bindata, X.binppm] = binadapt(X.data, X.ppm, F.parms);<br />
        kmin_input = input('What is the minumum of the range?  ');
%% normalization has multiple options these need to be considered ***<br />
            kmax_input = input('What is the maximum of the range?  ');
X.bindata = histmatch(X.bindata);<br />
            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('To this point, the important data is extracted and binned as "X.bindata" and can be analyzed');<br />
display('There are multiple ways of binning, this walkthrough uses binadapt.')
</code>
[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:18, 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

  1. 1 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


  1. 2 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

  1. 3 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

  1. 4 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;

  1. 5 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');