Skip to content
Permalink
Browse files

Merge pull request #173 from tiborauer/master

Improvements and debugs
  • Loading branch information...
jooh committed Mar 7, 2019
2 parents ee48221 + 80beecd commit 1a68e1d52067c0ad6ad8f08a812158c2f4e462d1
Showing with 476 additions and 375 deletions.
  1. +4 −0 aa_engine/aa_doprocessing.m
  2. +4 −0 aa_engine/aaq/nonDCS/PoolClass.m
  3. +1 −0 aa_engine/aaq/nonDCS/TaskClass.m
  4. +4 −0 aa_engine/aaq/nonDCS/aaq_qsub_nonDCS.m
  5. +3 −4 aa_engine/aas_checkreg.m
  6. +21 −20 aa_engine/aas_connectAApipelines.m
  7. +1 −2 aa_engine/aas_convertseries_fromstream.m
  8. +5 −5 aa_engine/aas_findinputstreamsources.m
  9. +87 −63 aa_modules/aamod_CoSMoMVPA.m
  10. +15 −1 aa_modules/aamod_CoSMoMVPA.xml
  11. +2 −2 aa_modules/aamod_autoidentifyseries.m
  12. +2 −2 aa_modules/aamod_coreg_extended_2.m
  13. +6 −9 aa_modules/{aamod_coreg_extended_2_RSA.xml → aamod_coreg_extended_2.xml}
  14. +2 −0 aa_modules/aamod_coreg_extended_2epi.xml
  15. +34 −23 aa_modules/aamod_dartel_denorm.m
  16. +26 −0 aa_modules/aamod_dartel_denormepi.xml
  17. +2 −2 aa_modules/aamod_diffusion_dartel_denormDKI.xml
  18. +2 −2 aa_modules/aamod_diffusion_dartel_denormDTI.xml
  19. +9 −9 aa_modules/aamod_diffusionfromnifti.m
  20. +7 −7 aa_modules/aamod_epifromnifti.m
  21. +3 −3 aa_modules/aamod_fieldmapfromnifti.m
  22. +2 −2 aa_modules/aamod_firstlevel_threshold.m
  23. +7 −7 aa_modules/aamod_freesurfer_register.m
  24. +20 −4 aa_modules/aamod_mask_fromsegment.m
  25. +3 −0 aa_modules/aamod_mask_fromsegment.xml
  26. +3 −3 aa_modules/aamod_maths.m
  27. +1 −0 aa_modules/aamod_maths.xml
  28. +1 −1 aa_modules/aamod_norm_write.m
  29. +3 −3 aa_modules/aamod_norm_write.xml
  30. +0 −31 aa_modules/aamod_norm_write_RSA.xml
  31. +0 −35 aa_modules/aamod_norm_write_RSA_dartel.xml
  32. +1 −1 aa_modules/aamod_norm_write_dartel.m
  33. +3 −3 aa_modules/aamod_norm_write_dartel.xml
  34. +1 −1 aa_modules/aamod_roi_extract.m
  35. +5 −5 aa_modules/aamod_segment8.m
  36. +6 −6 aa_modules/aamod_structuralfromnifti.m
  37. +3 −2 aa_toolbox/aa_build_standalone_2_build.m
  38. +65 −25 aa_toolbox/aa_export_toBIDS.m
  39. +0 −2 aa_toolbox/aa_standalone.m
  40. +4 −3 aa_toolbox/provenance/aa-o.ttl
  41. +49 −39 aa_toolbox/provenance/aa_provenance.m
  42. +1 −1 examples/aa_user_bids_ds000114.m
  43. +2 −2 examples/cbu/aa_user_diffusion.m
  44. +2 −2 examples/cbu/aa_user_diffusion_with_topup.m
  45. +11 −16 external/tsdiffana/tsdiffplot.m
  46. +1 −1 extrafunctions/make_stats_table.m
  47. +42 −26 extrafunctions/meminfo.m
@@ -433,6 +433,10 @@
aapsavefn=fullfile(aapsavepth,'aap_parameters');
aap.internal.aapversion=aa.Version;
aap.internal.aappath=aa.Path;
aap.internal.spmversion=spm('Version');
aap.internal.spmpath=spm('Dir');
aap.internal.matlabversion=version;
aap.internal.matlabpath=matlabroot;
save(aapsavefn,'aap');
end
end
@@ -4,6 +4,9 @@
JobStorageLocation
Jobs = JobClass.empty

Host = getenv('HOSTNAME')
NumWorkers

reqMemory = 1
reqWalltime = 1
initialConfiguration = ''
@@ -51,6 +54,7 @@

obj.Type = pool.Type;
obj.JobStorageLocation = pool.JobStorageLocation;
obj.NumWorkers = pool.NumWorkers;

switch obj.Type
case 'Torque'
@@ -79,6 +79,7 @@
function val = get.State(obj)
val = 'unknown';
if exist(obj.ProcessFile,'file')
val = 'running';
fid = fopen(obj.ProcessFile,'r');
lines = textscan(fid,'%s','delimiter','@'); lines = lines{1};
fclose(fid);
@@ -26,11 +26,15 @@
pool.ResourceTemplate = '';
pool.SubmitArguments = '';
pool.AdditionalProperties.AdditionalSubmitArgs = '';

keyInd = arrayfun(@(x) strcmp(x.ATTRIBUTE.name,'NumWorkers'), xml.settings(2).settings.settings.key);
pool.NumWorkers = xml.settings(2).settings.settings.key(keyInd).double.value;
end
end
obj.pool = PoolClass(pool,obj.initialSubmitArguments,obj.poolConf{3});
obj.pool.reqMemory = aaparallel.memory;
obj.pool.reqWalltime = aaparallel.walltime;
obj.pool.NumWorkers = aaparallel.numberofworkers;
end

function obj = pool_args(obj,varargin)
@@ -57,9 +57,6 @@ function aas_checkreg(aap,varargin)
if ~isfield(aap.tasklist.currenttask.settings,'diagnostic') ||...
isstruct(aap.tasklist.currenttask.settings.diagnostic) ||...
aap.tasklist.currenttask.settings.diagnostic
% This will only work for 1-7 overlays
OVERcolours = {[1 0 0], [0 1 0], [0 0 1], ...
[1 1 0], [1 0 1], [0 1 1], [1 1 1]};

% One-by-one
for i = 1:size(image{1},1)
@@ -83,9 +80,11 @@ function aas_checkreg(aap,varargin)
end
if i > 1
% Summary
OVERcolours = distinguishable_colors(size(image{1},1));

spm_check_registration(image{2});
for i = 1:size(image{1},1)
spm_orthviews('addcolouredimage',1,image{1}(i,:), OVERcolours{i})
spm_orthviews('addcolouredimage',1,image{1}(i,:), OVERcolours(i,:))
end
aas_checkreg_avi(aap, index, 0,'_summary');
close(1);
@@ -66,38 +66,35 @@
%
% -------------------------------------------------------
% created by: cwild 2014-03-10
%
% updates:
%
% rhodri & cwild 2014-09-*: Update to allow fully qualified stream names in
% local and remote analyses. E.g., using aamod_realign_00001.epi to fetch
% the epi stream from the realign stage of a remote analysis, instead of
% the last occurence of epi.
% cwild 2014-09-09: output/input stream searching respects branches in the
% local and remote analyses.
% cwild 2014-04-02: Major update, added check for udpated data on the
% remote
% cwild 2014-03-18: misc cleaning
%

% Error checking:
if isempty(aap.acq_details.subjects)
aas_log(aap, 1, 'aas_connectAApipelines() should be used after you have added subjects in your user script.');
end

if isempty(aap.acq_details.sessions)
aas_log(aap, 1, 'aas_connectAApipelines() should be used after you have added sessions in your user script.');
end

if any(~isfield(remoteAAlocations, {'host', 'directory', 'allowcache', 'maxstagetag', 'checkMD5'}))
aas_log(aap, 1, 'remoteAAlocations (input to aas_connectAApipelines) should be a struct array with the following fields: ''host'', ''directory'', ''allowcache'', ''maxstagetag'' ''checkMD5''');
end

global aaworker;

% We need to transfer over the remote AAP files, will put them here
studyPath = aas_getstudypath(aap);
% We need study directory for aas_findinputstreamsources and to transfer over the remote AAP files
studyPath = fullfile(aas_getstudypath(aap),[aap.directory_conventions.analysisid aap.directory_conventions.analysisid_suffix]);
aas_makedir(aap, studyPath);

% Initialise aap
% - evaluate subject names
aap=aas_doprocessing_initialisationmodules(aap);
% - integrate initial streams into the pipelines, if any
aap=aas_builddependencymap(aap);
v0 = aap.options.verbose;
aap.options.verbose = -1; % mute error on missing streams, for they will be connected later
aap=aas_findinputstreamsources(aap);
aap.options.verbose = v0;
% - remove partial initialisation
aap = rmfield(aap,'internal');

% Collect remote AA structures here
remoteAA = {};
@@ -284,6 +281,8 @@
srcDomain = remoteAA{remoteOutput.locI}.schema.tasksettings.(remoteModule.name)(remoteModule.index).ATTRIBUTE.domain;
srcModality = remoteAA{remoteOutput.locI}.schema.tasksettings.(remoteModule.name)(remoteModule.index).ATTRIBUTE.modality;

if strcmp(trgDomain,'*'), trgDomain = srcDomain; end % for general purpose modules, such as aamod_maths

remoteStreams(end+1) = struct('stream', inputStreams{iI}, ...
'stagetag', aas_getstagetag(remoteAA{remoteOutput.locI}, remoteOutput.modI), ...
'sourcedomain', srcDomain, ...
@@ -401,9 +400,11 @@
else

if isstruct(aap.schema.tasksettings.(mod.name)(mod.index).inputstreams.stream{iI}) && ...
isfield(aap.schema.tasksettings.(mod.name)(mod.index).inputstreams.stream{iI}, 'isessential') && ...
aap.schema.tasksettings.(mod.name)(mod.index).inputstreams.stream{iI}.ATTRIBUTE.isessential
aas_log(aap, 1, sprintf('%s''s input stream ''%s'' does not come from any module in this AA, or from one of your remote locations.\nTry connecting the AA pipelines *after* all aas_addinitialstream() calls in your user script.', mod.name, inputStreams{iI}));
(~isfield(aap.schema.tasksettings.(mod.name)(mod.index).inputstreams.stream{iI}, 'isessential') || ...
aap.schema.tasksettings.(mod.name)(mod.index).inputstreams.stream{iI}.isessential) && ...
(~isfield(aap.schema.tasksettings.(mod.name)(mod.index).inputstreams.stream{iI}.ATTRIBUTE, 'isessential') || ...
aap.schema.tasksettings.(mod.name)(mod.index).inputstreams.stream{iI}.ATTRIBUTE.isessential)
aas_log(aap, 1, sprintf('%s''s input stream ''%s'' does not come from any module in this pipeline, or from one of your remote locations.\nTry connecting the pipelines *after* all aas_addinitialstream() and aas_renamestream() calls in your user script.', mod.name, inputStreams{iI}));
end

end
@@ -80,7 +80,6 @@
memLimit = meminfo; memLimit = memLimit.ResFree;
k=1;


while (k<=size(dicomdata_subdir,1))

oldAcquisitionNumber=-1;
@@ -90,7 +89,7 @@
% This array is used to collect sliceing timing info so we can
% reconstruct the slice order
sliceInfoD = zeros(0, 3);

while (k<=size(dicomdata_subdir,1))

tmp = spm_dicom_headers(deblank(dicomdata_subdir(k,:)));
@@ -64,7 +64,7 @@
end;

% Now we have one stream per cell
for i=1:length(streamlist)
for i=1:numel(streamlist)
inputstreamname=inputstreams.stream{i};
ismodified=1; isessential=1;
if isstruct(inputstreamname)
@@ -153,12 +153,12 @@
end;
end;
end;
if ~isempty(findremote) || ~isempty(stagethatoutputs)
% change domain and modality if needed (due to input)
if (~isempty(findremote) || ~isempty(stagethatoutputs)) && (i==numel(streamlist))
% change domain and modality if needed (due to input, which is expected to be the last stream)
currstage = aap.schema.tasksettings.(stagename)(index).ATTRIBUTE;
currstream = aap.internal.inputstreamsources{k1}.stream(end);
if (strcmp(currstage.domain,'*') && strcmp(currstage.modality,'MRI')) && ... % general-purpose module
(~isempty(strfind(currstream.sourcedomain,'session')) || ~strcmp(currstream.sourcemodality,'MRI')) % special
if (strcmp(currstage.domain,'*') && strcmp(currstage.modality,'MRI'))% general-purpose module
% (~isempty(strfind(currstream.sourcedomain,'session')) || ~strcmp(currstream.sourcemodality,'MRI')) % special
aap.schema.tasksettings.(stagename)(index).ATTRIBUTE.modality = currstream.sourcemodality;
aap.internal.aap_initial.schema.tasksettings.(stagename)(index).ATTRIBUTE.modality = currstream.sourcemodality;
aap.schema.tasksettings.(stagename)(index).ATTRIBUTE.domain = currstream.sourcedomain;
@@ -3,46 +3,48 @@

switch task
case 'report'
% localpath = aas_getpath_bydomain(aap,aap.tasklist.currenttask.domain,[subj,sess]);
%
% fdiag = dir(fullfile(localpath,'diagnostic_*.jpg'));
% if isempty(fdiag)
% streams=aas_getstreams(aap,'output');
% for streamind=1:length(streams)
% % obtain output
% outputfnames = aas_getfiles_bystream(aap,aap.tasklist.currenttask.domain,[subj sess],streams{streamind},'output');
%
% % perform diagnostics
% do_diag(outputfnames);
% end
% fdiag = dir(fullfile(localpath,'diagnostic_*.jpg'));
% end
%
% for d = 1:numel(fdiag)
% aap = aas_report_add(aap,subj,'<table><tr><td>');
% imgpath = fullfile(localpath,fdiag(d).name);
% aap=aas_report_addimage(aap,subj,imgpath);
% aap = aas_report_add(aap,subj,'</td></tr></table>');
% end
% localpath = aas_getpath_bydomain(aap,aap.tasklist.currenttask.domain,[subj,sess]);
%
% fdiag = dir(fullfile(localpath,'diagnostic_*.jpg'));
% if isempty(fdiag)
% streams=aas_getstreams(aap,'output');
% for streamind=1:length(streams)
% % obtain output
% outputfnames = aas_getfiles_bystream(aap,aap.tasklist.currenttask.domain,[subj sess],streams{streamind},'output');
%
% % perform diagnostics
% do_diag(outputfnames);
% end
% fdiag = dir(fullfile(localpath,'diagnostic_*.jpg'));
% end
%
% for d = 1:numel(fdiag)
% aap = aas_report_add(aap,subj,'<table><tr><td>');
% imgpath = fullfile(localpath,fdiag(d).name);
% aap=aas_report_addimage(aap,subj,imgpath);
% aap = aas_report_add(aap,subj,'</td></tr></table>');
% end
case 'doit'
%% Prepare data
TASKS = textscan(aas_getsetting(aap,'tasks'),'%s','Delimiter',':'); TASKS = TASKS{1}';

RSAROOT = fullfile(aas_getsubjpath(aap,subj),'RSA');
aas_makedir(aap,RSAROOT);

inps = aas_getstreams(aap,'input');
inps = inps(logical(cellfun(@(x) exist(aas_getinputstreamfilename(aap,'subject',subj,x),'file'), inps)));
struct_fn = aas_getfiles_bystream(aap,'subject',subj,inps{1});

fnMask = cellfun(@(x) aas_getfiles_bystream(aap,'subject',subj,x), inps(cell_index(inps,'firstlevel_brainmask')),'UniformOutput',false);
fnMask = cellfun(@(x) aas_getfiles_bystream(aap,'subject',subj,x), inps(cell_index(inps,'mask')),'UniformOutput',false);
fnSPM = cellfun(@(x) aas_getfiles_bystream(aap,'subject',subj,x), inps(cellfun(@(x) ~isempty(regexp(x,'firstlevel_spm$', 'once')), inps)),'UniformOutput',false);
fnTmaps = cellfun(@(x) aas_getfiles_bystream(aap,'subject',subj,x), inps(cell_index(inps,'firstlevel_spmts')),'UniformOutput',false);

if numel(fnSPM) > 1
if numel(fnMask) > 1
brain_mask = spm_imcalc(spm_vol(char(fnMask)),fullfile(RSAROOT,'brain_mask.nii'),'min(X)',{1});
else
brain_mask.fname = char(fnMask);
end

ITEMS = aas_getsetting(aap,'itemList');
fnT = {};
for run = 1:numel(fnSPM)
@@ -60,46 +62,68 @@
cosmo_set_path
cosmo_check_external('-tic');

% Data
ds=cosmo_fmri_dataset(fullfile(RSAROOT,'glm_T_stats_perrun.nii'),'mask',brain_mask.fname,...
'targets',repmat(1:numel(ITEMS),1,numel(fnSPM))');
ds=cosmo_fx(ds, @(x)mean(x,1), 'targets', 1);
ds.sa.labels=cellfun(@(x) x{1}, ITEMS, 'UniformOutput', false)';
ds.sa.set=(1:numel(ITEMS))';
cosmo_check_dataset(ds);

% Searchlight
nbrhood=cosmo_spherical_neighborhood(ds,'count',aas_getsetting(aap,'searchlightVox'));
if cell_index(TASKS, 'RSA') && isempty(aas_getsetting(aap,'bsMatrix')), TASKS(cell_index(TASKS, 'RSA')) = []; end

% Model
target_dsm=importdata(aas_getsetting(aap,'bsMatrix'));
measure=@cosmo_target_dsm_corr_measure;
measure_args=struct();
measure_args.target_dsm=target_dsm;

%% Info
aas_log(aap,false,'INFO:Dataset input:'); cosmo_disp(ds);
aas_log(aap,false,'INFO:Searchlight neighborhood definition:'); cosmo_disp(nbrhood);
aas_log(aap,false,'INFO:Target DSM:'); disp(target_dsm);

% imagesc(target_dsm)
% set(gca,'XTick',1:size(ds.samples,1),'XTickLabel',ds.sa.labels,...
% 'YTick',1:size(ds.samples,1),'YTickLabel',ds.sa.labels)

%% Run
ds_rsm_behav=cosmo_searchlight(ds,nbrhood,measure,measure_args);

% cosmo_plot_slices(ds_rsm_behav);

% store results
rsa_fn=fullfile(RSAROOT,'RSAmap.nii');
cosmo_map2fmri(ds_rsm_behav,rsa_fn);

%% Cleanup
path(oldPath);

aap=aas_desc_outputs(aap,'subject',subj,'RSAmap',rsa_fn);

for t = TASKS
% Data
switch t{1}
case 'RSA'
ds=cosmo_fmri_dataset(fullfile(RSAROOT,'glm_T_stats_perrun.nii'),'mask',brain_mask.fname,...
'targets',repmat(1:numel(ITEMS),1,numel(fnSPM))');
ds=cosmo_fx(ds, @(x)mean(x,1), 'targets', 1);
ds.sa.labels=cellfun(@(x) x{1}, ITEMS, 'UniformOutput', false)';
ds.sa.set=(1:numel(ITEMS))';
case 'C'
ds=cosmo_fmri_dataset(fullfile(RSAROOT,'glm_T_stats_perrun.nii'),'mask',brain_mask.fname,...
'targets',repmat(1:numel(ITEMS),1,numel(fnSPM))','chunks',floor(((1:numel(ITEMS)*numel(fnSPM))-1)/numel(ITEMS))+1);
ds.sa.labels=cellfun(@(x) x{1}, repmat(ITEMS,1,numel(fnSPM)), 'UniformOutput', false)';
ds.sa.set=repmat((1:numel(ITEMS))',numel(fnSPM),1);
end

% Data
cosmo_check_dataset(ds);

% Searchlight
nbrhood=cosmo_spherical_neighborhood(ds,'count',aas_getsetting(aap,'searchlightVox'));

% Model
target_dsm = 'not specified';
switch t{1}
case 'RSA'
target_dsm=importdata(aas_getsetting(aap,'bsMatrix'));
measure=@cosmo_target_dsm_corr_measure;
measure_args = aas_getsetting(aap,'RSAsettings');
measure_args.target_dsm=target_dsm;
case 'C'
measure_args = aas_getsetting(aap,'Csettings');
measure_args.classifier = str2func(['cosmo_classify_' lower(measure_args.classifier)]);
measure_args.partitions = cosmo_balance_partitions(cosmo_nfold_partitioner(ds), ds);
measure=@cosmo_crossvalidation_measure;
end

%% Info
aas_log(aap,false,'INFO:Dataset input:'); cosmo_disp(ds);
aas_log(aap,false,'INFO:Searchlight neighborhood definition:'); cosmo_disp(nbrhood);
aas_log(aap,false,'INFO:Target DSM:'); disp(target_dsm);

% imagesc(target_dsm)
% set(gca,'XTick',1:size(ds.samples,1),'XTickLabel',ds.sa.labels,...
% 'YTick',1:size(ds.samples,1),'YTickLabel',ds.sa.labels)

%% Run
ds_rsm_behav=cosmo_searchlight(ds,nbrhood,measure,measure_args);

% cosmo_plot_slices(ds_rsm_behav);

% store results
rsa_fn=fullfile(RSAROOT,[t{1} 'map.nii']);
cosmo_map2fmri(ds_rsm_behav,rsa_fn);

%% Cleanup
path(oldPath);

aap=aas_desc_outputs(aap,'subject',subj,[t{1} 'map'],rsa_fn);
end
case 'checkrequirements'

otherwise
Oops, something went wrong.

0 comments on commit 1a68e1d

Please sign in to comment.
You can’t perform that action at this time.