Skip to content

Commit

Permalink
Merge pull request automaticanalysis#213 from tiborauer/master
Browse files Browse the repository at this point in the history
aacache, toolboxes
  • Loading branch information
jooh authored Aug 25, 2020
2 parents 53ef81e + 20c15bb commit 5d8fc68
Show file tree
Hide file tree
Showing 59 changed files with 765 additions and 729 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ More information can be found on the [wiki](https://github.com/automaticanalysis
- System: Linux or MacOX (Windows is not supported. Sorry!)
- Softwares:
- **MATLAB** - It has been tested with version r2013a and later
- **SPM** - It has been tested with versions SPM12 and later (SPM12 r7487 is recommended!)
- **SPM** - It has been tested with versions SPM12 and later (SPM12 r7487 or later **required**!)
- Recommended software for features:
- For MEG (maxfilter): Neuromag (Elekta Instrument AB Stockholm, Stockholm, Sweden)
- For visual representation of the pipeline: [GraphViz](http://www.graphviz.org)
Expand Down Expand Up @@ -58,7 +58,7 @@ Some parameters (path settings, format settings) stored in **_<aarootdir>/aa_par
- *directory_conventions/seriesoutputformat*: `sprintf` formatting string to get series directory as stored in subject directory
- *directory_conventions/protocol_structural*: Name of the structural/anatomical protocol as stored in the DICOM header
- *directory_conventions/dicomfilter*: Directory listing filter to find DICOM data
- *directory_conventions/spmdir*: Path to SPM. **N.B.: You should not modify SPM version in your user script but rather in your local parameter file.**
- *directory_conventions/toolboxes/spm*: Settings for SPM. **N.B.: You should not modify SPM version in your user script but rather in your local parameter file.**
Optional:
- For distortion correction using fieldmap:
- *directory_conventions/protocol_fieldmap*: Name of the fieldmap protocol as stored in the DICOM header
Expand All @@ -84,10 +84,10 @@ Optional:
- *directory_conventions/freesurfershell*: Shell used to run FreeSurfer. It should be in accordance with *directory_conventions/freesurfersetup* and *directory_conventions/freesurferenvironment*
- *directory_conventions/freesurferenvironment*: Path to FreeSurfer environmental setup script, executing before any FreeSurfer command

- *directory_conventions/eeglabdir*: Path to EEGLab
- *directory_conventions/toolboxes/eeglab*: Settings for EEGLab
- *directory_conventions/GIFTdir*: Path to GIFT
- *directory_conventions/ANTSdir*: Path to ANTS
- *directory_conventions/fieldtripdir*: Path to FieldTrip
- *directory_conventions/toolboxes/fieldtrip*: Settings for FieldTrip
- *directory_conventions/BrainWaveletdir*: Path to BrainWavelet
- *directory_conventions/spmtoolsdir*: Path to external/custom SPM toolboxes

Expand Down
2 changes: 1 addition & 1 deletion aaClass.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
fprintf(' <a href = "%s">%s</a>\n',obj.ManuscriptURL,d{2});
fprintf(' <a href = "%s">%s</a>\n',obj.ManuscriptURL,d{3});
fprintf('\nPlease visit <a href = "%s">The aa website</a> for more information!\n',obj.aaURL);
fprintf('\nHere you can find example <a href = "matlab: cd %s">tasklists</a> and <a href = "matlab: cd %s">scripts</a>.\n',...
fprintf('\nHere you can find example <a href = "matlab: cd %s">parameter sets</a> and <a href = "matlab: cd %s">examples</a>.\n',...
fullfile(obj.Path,'aa_parametersets'),fullfile(obj.Path,'examples'));
fprintf('Ready.\n');
end
Expand Down
17 changes: 8 additions & 9 deletions aa_engine/aa_close.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,20 @@ function aa_close(varargin)
tasks = varargin(2:end);
end

global aacache;

if cell_index(tasks,'restorepath') && ...
(~isstruct(aap) || ~isfield(aap.options,'restorepath') ||... % not specified
aap.options.restorepath) % specified and enabled
if isstruct(aacache) && isfield(aacache,'path')
if isfield(aacache.path,'bcp_path'), path(aacache.path.bcp_path); end
if isfield(aacache.path,'bcp_shellpath'), setenv('PATH', aacache.path.bcp_shellpath); end
end
[s,p] = aas_cache_get(aap,'bcp_path','system'); if s, path(p); end
[s,p] = aas_cache_get(aap,'bcp_shellpath','system'); if s, setenv('PATH', p); end
end

% restore warnings
if cell_index(tasks,'restorewarnings') && isstruct(aacache) && isfield(aacache,'warnings')
for w = aacache.warnings
warning(w);
if cell_index(tasks,'restorewarnings')
[s,ws] = aas_cache_get(aap,'warnings','system');
if s
for w = ws
warning(w);
end
end
end

Expand Down
4 changes: 4 additions & 0 deletions aa_engine/aa_doprocessing_onetask.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
function aap=aa_doprocessing_onetask(aap,task,modulenum,indices,gaaworker)

global aaworker
global aacache
if nargin == 5 % aaworker passed
aaworker = gaaworker;
end
if isfield(aaworker,'aacache')
aacache = aaworker.aacache;
end

aaworker.modulestarttime=now;

Expand Down
183 changes: 102 additions & 81 deletions aa_engine/aa_init.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
% Automatic analysis - initialise paths from recipe

function [aap]=aa_init(aap)

global aa
Expand Down Expand Up @@ -31,47 +30,70 @@
end
end

global aacache
% Set UTC time function
if exist('utc_time','file')
aacache.utc_time = @utc_time;
utime = @utc_time;
else
aas_log(aap,false,'INFO: utc_time is not found. java function will be used\n')
aacache.utc_time = @java.lang.System.currentTimeMillis;
utime = @java.lang.System.currentTimeMillis;
end
aas_cache_put(aap,'utc_time',utime,'utils');

%% Set Paths
aacache.path.bcp_path = path;
aacache.path.bcp_shellpath = getenv('PATH');
aas_cache_put(aap,'bcp_path',path,'system');
aas_cache_put(aap,'bcp_shellpath',getenv('PATH'),'system');

% Path for SPM
if ~isempty(aap.directory_conventions.spmdir)
% by setting this environment variable it becomes possible to define other
% paths relative to $SPMDIR in defaults files and task lists
setenv('SPMDIR',aap.directory_conventions.spmdir);
SPMDIR = '';
doKeepInPath = true;
% backward compatibility
if isfield(aap.directory_conventions,'spmdir') && ~isempty(aap.directory_conventions.spmdir)
SPMDIR = aap.directory_conventions.spmdir;
end

% toolboxes
if isfield(aap.directory_conventions,'toolbox')
tbxInd = strcmp({aap.directory_conventions.toolbox.name},'spm');
if any(tbxInd)
SPMDIR = aap.directory_conventions.toolbox(tbxInd).dir;
doKeepInPath = aap.directory_conventions.toolbox(tbxInd).extraparameters.doKeepInPath;
end
end
% path
if isempty(SPMDIR)
if isempty(which('spm'))
aas_log(aap,true,'You''re going to need SPM, add it to your paths manually or set in aap.directory_conventions.toolbox');
else
SPMDIR = spm('Dir');
doKeepInPath = true;
end
end
% deployed
if isdeployed
aap.directory_conventions.spmdir = spm('Dir');
setenv('SPMDIR',aap.directory_conventions.spmdir);
SPMDIR = spm('Dir');
doKeepInPath = true;
end
% reset
if isfield(aap.directory_conventions,'spmdir'), aap.directory_conventions.spmdir = SPMDIR; end
if isfield(aap.directory_conventions,'toolbox') && any(tbxInd)
aap.directory_conventions.toolbox(tbxInd).name = 'spm';
aap.directory_conventions.toolbox(tbxInd).dir = SPMDIR;
aap.directory_conventions.toolbox(tbxInd).extraparameters.doKeepInPath = 1;
end

% by setting this environment variable it becomes possible to define other
% paths relative to $SPMDIR in defaults files and task lists
setenv('SPMDIR',SPMDIR);

% expand shell paths (before SPM so SPM can be in e.g. home directory)
aap = aas_expandpathbyvars(aap, aap.options.verbose>2);

if isempty(aap.directory_conventions.spmdir)
if isempty(which('spm'))
aas_log(aap,true,'You''re going to need SPM, add it to your paths manually or set aap.directory_conventions.spmdir');
else
aap.directory_conventions.spmdir=spm('Dir');
end;
end;

if isfield(aap, 'spm') && isfield(aap.spm, 'defaults')
oldspmdefaults = aap.spm.defaults;
end

addpath(aap.directory_conventions.spmdir);
spm_jobman('initcfg');
SPM = spmClass(SPMDIR,'doAddToPath',true,'doKeepInPath',doKeepInPath);
SPM.load;
aas_cache_put(aap,'spm',SPM);

try
aap.spm.defaults=spm_get_defaults;
Expand All @@ -92,8 +114,7 @@

% Path for SPM MEG/EEG
addpath(fullfile(spm('Dir'),'external','fieldtrip'));
clear ft_defaults
clear global ft_default
global ft_default; ft_default = [];
ft_defaults;
global ft_default
ft_default.trackcallinfo = 'no';
Expand All @@ -109,35 +130,35 @@
fullfile(spm('Dir'),'toolbox', 'Neural_Models'),...
fullfile(spm('Dir'),'toolbox', 'MEEGtools'));

% Path fore spmtools
if isfield(aap.directory_conventions,'spmtoolsdir') && ~isempty(aap.directory_conventions.spmtoolsdir)
SPMTools = textscan(aap.directory_conventions.spmtoolsdir,'%s','delimiter', ':'); SPMTools = SPMTools{1};
for pp = SPMTools'
addpath(genpath(pp{1}));
end
% Path fore matlabtools
if isfield(aap.directory_conventions,'matlabtoolsdir') && ~isempty(aap.directory_conventions.matlabtoolsdir)
addpath(strrep(aap.directory_conventions.matlabtoolsdir,':',pathsep))
end

% Path for EEGLAB, if specified
if ~isempty(aap.directory_conventions.eeglabdir)
addpath(...
fullfile(aap.directory_conventions.eeglabdir,'functions'),...
fullfile(aap.directory_conventions.eeglabdir,'functions', 'adminfunc'),...
fullfile(aap.directory_conventions.eeglabdir,'functions', 'sigprocfunc'),...
fullfile(aap.directory_conventions.eeglabdir,'functions', 'guifunc'),...
fullfile(aap.directory_conventions.eeglabdir,'functions', 'studyfunc'),...
fullfile(aap.directory_conventions.eeglabdir,'functions', 'popfunc'),...
fullfile(aap.directory_conventions.eeglabdir,'functions', 'statistics'),...
fullfile(aap.directory_conventions.eeglabdir,'functions', 'timefreqfunc'),...
fullfile(aap.directory_conventions.eeglabdir,'functions', 'miscfunc'),...
fullfile(aap.directory_conventions.eeglabdir,'functions', 'resources'),...
fullfile(aap.directory_conventions.eeglabdir,'functions', 'javachatfunc')...
);
else
% Check whether already in path, give warning if not
if isempty(which('eeglab'))
aas_log(aap,false,sprintf('EEG lab not found, if you need this you should add it to the matlab path manually, or set aap.directory_conventions.eeglabdir'));
end;
end;

% Toolboxes
if isfield(aap.directory_conventions,'toolbox') && isstruct(aap.directory_conventions.toolbox)
for TBX = aap.directory_conventions.toolbox
if strcmp(TBX.name,'spm'), continue; end
if ~exist([TBX.name 'Class'],'class')
aas_log(aap,false,sprintf('No interfaces for %s in extrafunctions/toolboxes',TBX.name));
else
constr = str2func([TBX.name 'Class']);
params = {};
if isfield(TBX,'extraparameters')
for p = fieldnames(TBX.extraparameters)
val = TBX.extraparameters.(p{1});
if isempty(val), continue; end
if ischar(val) && contains(val,':'), val = strsplit(val,':'); end
params{end+1} = p{1};
params{end+1} = val;
end
end
T = constr(TBX.dir,params{:});
aas_cache_put(aap,TBX.name,T);
end
end
end

% Path to GIFT
if ~isempty(aap.directory_conventions.GIFTdir)
Expand All @@ -146,8 +167,8 @@
% Check whether already in path, give warning if not
if isempty(which('icatb_runAnalysis'))
aas_log(aap,false,sprintf('GIFT not found, if you need this you should add it to the matlab path manually, or set aap.directory_conventions.GIFTdir'));
end;
end;
end
end

% Path to BrainWavelet
if ~isempty(aap.directory_conventions.BrainWaveletdir)
Expand All @@ -160,7 +181,7 @@
% Check whether already in path, give warning if not
if isempty(which('WaveletDespike'))
aas_log(aap,false,sprintf('BrainWavelet not found, if you need this you should add it to the matlab path manually, or set aap.directory_conventions.BrainWaveletdir'));
end;
end
end

% Path to FaceMasking
Expand All @@ -170,8 +191,8 @@
% Check whether already in path, give warning if not
if isempty(which('mask_surf_auto'))
aas_log(aap,false,sprintf('FaceMasking not found, if you need this you should add it to the matlab path manually, or set aap.directory_conventions.FaceMaskingdir'));
end;
end;
end
end

% Path to LI toolbox
if isfield(aap.directory_conventions,'LIdir') && ~isempty(aap.directory_conventions.LIdir)
Expand All @@ -180,13 +201,14 @@
% Check whether already in path, give warning if not
if isempty(which('LI'))
aas_log(aap,false,sprintf('LI toolbox not found, if you need this you should add it to the matlab path manually, or set aap.directory_conventions.LIdir'));
end;
end;
end
end


% Path to DCMTK
if isfield(aap.directory_conventions,'DCMTKdir') && ~isempty(aap.directory_conventions.DCMTKdir)
setenv('PATH',[aacache.path.bcp_shellpath ':' fullfile(aap.directory_conventions.DCMTKdir,'bin')]);
[s,p] = aas_cache_get(aap,'bcp_shellpath','system');
setenv('PATH',[p ':' fullfile(aap.directory_conventions.DCMTKdir,'bin')]);
end


Expand All @@ -201,17 +223,24 @@
p = textscan(path,'%s','delimiter',':'); p = p{1};

% spm
p_ind = cell_index(p,aap.directory_conventions.spmdir); % SPM-related dir
p_ind = cell_index(p,SPMDIR); % SPM-related dir
for ip = p_ind
reqpath{end+1} = p{ip};
end
% spmtools
if isfield(aap.directory_conventions,'spmtoolsdir') && ~isempty(aap.directory_conventions.spmtoolsdir)
SPMTools = textscan(aap.directory_conventions.spmtoolsdir,'%s','delimiter', ':'); SPMTools = SPMTools{1};
for pp = SPMTools'
if exist(pp{1},'dir')
pdir = textscan(genpath(pp{1}),'%s','delimiter', ':'); pdir = pdir{1};
reqpath = [reqpath; pdir];

% matlabtoolsdir
if isfield(aap.directory_conventions,'matlabtoolsdir') && ~isempty(aap.directory_conventions.matlabtoolsdir)
matlabtools = textscan(aap.directory_conventions.matlabtoolsdir,'%s','delimiter', ':'); matlabtools = matlabtools{1};
for pp = matlabtools'
if exist(pp{1},'dir'), reqpath = [reqpath; pp{1}]; end
end
end

% Toolboxes
if isfield(aap.directory_conventions,'toolbox') && isstruct(aap.directory_conventions.toolbox)
for TBX = aap.directory_conventions.toolbox
if isfield(TBX,'extraparameters') && isfield(TBX.extraparameters,'doAddToPath') && TBX.extraparameters.doAddToPath
reqpath{end+1} = TBX.dir;
end
end
end
Expand All @@ -224,14 +253,6 @@
end
end

% EEGLAB
if ~isempty(aap.directory_conventions.eeglabdir)
p_ind = cell_index(p,aap.directory_conventions.eeglabdir);
for ip = p_ind
reqpath{end+1} = p{ip};
end
end;

% GIFT
if ~isempty(aap.directory_conventions.GIFTdir)
p_ind = cell_index(p,aap.directory_conventions.GIFTdir);
Expand Down Expand Up @@ -265,12 +286,12 @@
end

% clean
reqpath=reqpath(strcmp('',reqpath)==0);
reqpath = reqpath(strcmp('',reqpath)==0);
exc = cell_index(reqpath,'.git');
if exc, reqpath(exc) = []; end

aacache.path.reqpath = reqpath;
aas_cache_put(aap,'reqpath',reqpath,'system');
% switch off warnings
aacache.warnings(1) = warning('off','MATLAB:Completion:CorrespondingMCodeIsEmpty');
aacache.warnings(2) = warning('off','MATLAB:getframe:RequestedRectangleExceedsFigureBounds');

warnings(1) = warning('off','MATLAB:Completion:CorrespondingMCodeIsEmpty');
warnings(2) = warning('off','MATLAB:getframe:RequestedRectangleExceedsFigureBounds');
aas_cache_put(aap,'warnings',warnings,'system');
6 changes: 4 additions & 2 deletions aa_engine/aaq/aaq_qsub.m
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,8 @@ function close(obj)
function [obj]=qsub_q_job(obj,job)
global aaworker
global aacache
aaworker.aacache = aacache;
[s, reqpath] = aas_cache_get(obj.aap,'reqpath','system');
% Let's store all our qsub thingies in one particular directory
qsubpath=fullfile(aaworker.parmpath,'qsub');
aas_makedir(obj.aap,qsubpath);
Expand Down Expand Up @@ -468,9 +470,9 @@ function close(obj)
% them the aa paths. Users don't need to remember to update
% their own default paths (e.g. for a new aa version)
if isprop(J,'AdditionalPaths')
J.AdditionalPaths = aacache.path.reqpath;
J.AdditionalPaths = reqpath;
elseif isprop(J,'PathDependencies')
J.PathDependencies = aacache.path.reqpath;
J.PathDependencies = reqpath;
end
createTask(J,cj,nrtn,inparg,'CaptureDiary',true);
success = false;
Expand Down
Loading

0 comments on commit 5d8fc68

Please sign in to comment.