Skip to content

Commit

Permalink
DEBUGs
Browse files Browse the repository at this point in the history
- Termination of the pipeline via aaq_qsubVeiwerClass is correctly
detected by aaq_qsub and aa_doprocessing
- aamod_fieldmapfromnifti now correctly outputs TEs from specified
header
- Reporting includes distributions of (both the first- and second-level)
contrasts
  • Loading branch information
Tibor Auer committed Mar 18, 2016
1 parent 3dd8045 commit 4a61770
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 41 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## 5.1.0 ##

#### New general features ####
- [aa_export_toBIDS](https://github.com/rhodricusack/automaticanalysis/blob/v5/aa_toolbox/aa_export_toBIDS.m) export raw data from aa pipeline in BIDS format (limited functionality)

#### New features for structural ####
- automatic inputstream detection (and renaming) for aamod_roi_valid_structural

Expand All @@ -15,8 +18,10 @@
- aas_log works with empty `aap`
- [aas_runfslcommand](https://github.com/rhodricusack/automaticanalysis/blob/v5/aa_engine/aas_runfslcommand.m) and [aas_runFScommand](https://github.com/rhodricusack/automaticanalysis/blob/v5/aa_engine/aas_runFScommand.m) now pass run-time MATLAB path to in-shell MATLAB (if applicable)
- [aa_provenance](https://github.com/rhodricusack/automaticanalysis/blob/v5/aa_toolbox/provenance/aa_provenance.m) now uses run-time dependency (see "New features ...")
- [QueueViewer](https://github.com/rhodricusack/automaticanalysis/blob/v5/aa_engine/aaq/QueueViewerClass.m) will not delete jobs finished with errors --> job folder will be kept for debugging and [aaq_qsubVeiwerClass](https://github.com/rhodricusack/automaticanalysis/blob/v5/aa_engine/aaq/aaq_qsubVeiwerClass.m) will not interfere with `aaq`
- Distributions of the contrasts are reported
- [QueueViewer](https://github.com/rhodricusack/automaticanalysis/blob/v5/aa_engine/aaq/QueueViewerClass.m) will not delete jobs finished with errors --> job folder will be kept for debugging
- Termination of the pipeline via [aaq_qsubVeiwerClass](https://github.com/rhodricusack/automaticanalysis/blob/v5/aa_engine/aaq/aaq_qsubVeiwerClass.m) is correctly detected by [aaq_qsub](https://github.com/rhodricusack/automaticanalysis/blob/v5/aa_engine/aaq/aaq_qsub.m) and [aa_doprocessing](https://github.com/rhodricusack/automaticanalysis/blob/v5/aa_engine/aa_doprocessing.m)
- [aamod_fieldmapfromnifti](https://github.com/rhodricusack/automaticanalysis/blob/v5/aa_modules/aamod_fieldmapfromnifti.xml) now correctly outputs TEs from specified header
- Reporting includes distributions of (both the first- and second-level) contrasts
- [aamod_firstlevel_threshold](https://github.com/rhodricusack/automaticanalysis/blob/v5/aa_modules/aamod_firstlevel_threshold.xml) now correctly outputs coronal sections
- [aamod_secondlevel_model](https://github.com/rhodricusack/automaticanalysis/blob/v5/aa_modules/aamod_secondlevel_model.xml) now correctly outputs for each firstlevel contrasts
- [aas_add_meg_session](https://github.com/rhodricusack/automaticanalysis/blob/v5/aa_engine/aas_add_meg_session.m) now prevents adding the same session multiple times (e.g. when the function is called per subject)
Expand Down
26 changes: 14 additions & 12 deletions aa_engine/aa_doprocessing.m
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@
if ~isempty(localtaskqueue.jobqueue),
localtaskqueue.runall(dontcloseexistingworkers, false);
end
if isfield(taskqueue,'killed') && taskqueue.killed, break; end
if isprop(taskqueue,'killed') && taskqueue.killed, break; end
end
% Wait until all the jobs have finished
taskqueue.runall(dontcloseexistingworkers, true);
Expand All @@ -408,20 +408,22 @@
% end
% aas_log(aap,0,'Message deleted');

if ismethod(taskqueue,'QVClose'), taskqueue.QVClose; end

if ~isempty(aap.options.email)
% In case the server is broken...
try
aas_finishedMail(aap.options.email, aap.acq_details.root)
catch
if ~isprop(taskqueue,'killed') || ~taskqueue.killed
if ismethod(taskqueue,'QVClose'), taskqueue.QVClose; end

if ~isempty(aap.options.email)
% In case the server is broken...
try
aas_finishedMail(aap.options.email, aap.acq_details.root)
catch
end
end

if isfield(aap.options,'garbagecollection') && aap.options.garbagecollection
aas_garbagecollection(aap,1)
end
end

if isfield(aap.options,'garbagecollection') && aap.options.garbagecollection
aas_garbagecollection(aap,1)
end

aa_close;

end
Expand Down
4 changes: 2 additions & 2 deletions aa_engine/aaq/aaq_qsub.m
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
JobID = obj.taskinqueue(ftmind);
Jobs = obj.scheduler.Jobs([obj.scheduler.Jobs.ID] == JobID);
if isempty(Jobs) % cleared by the GUI
obj.QV.Hold = false;
if obj.QV.isvalid, obj.QV.Hold = false; end
obj.killed = true;
return;
end
Expand Down Expand Up @@ -187,7 +187,7 @@
end

function obj = QVClose(obj)
if ~isempty(obj.QV)
if ~isempty(obj.QV) && obj.QV.isvalid
obj.QV.Close;
obj.QV.delete;
obj.QV = [];
Expand Down
2 changes: 2 additions & 0 deletions aa_modules/aamod_fieldmapfromnifti.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
for f = fieldnames(hdrfile)'
if strfind(f{1},'Time'), dcmhdr{1}.(f{1}) = hdrfile.(f{1})*1000; end
end
if isfield(dcmhdr{1},'RepetitionTime'), dcmhdr{1}.volumeTR = dcmhdr{1}.RepetitionTime/1000; end
if isfield(dcmhdr{1},'EchoTime1') && isfield(dcmhdr{1},'EchoTime2'), dcmhdr{1}.volumeTE = [dcmhdr{1}.EchoTime1 dcmhdr{1}.EchoTime2]/1000; end

%% Output
dcmhdrfn=fullfile(aas_getsesspath(aap,subj,sess),'fieldmap_dicom_header.mat');
Expand Down
30 changes: 16 additions & 14 deletions aa_modules/aamod_firstlevel_contrasts.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

switch task
case 'report' % [TA]
if ~exist(fullfile(aas_getsubjpath(aap,subj),'diagnostic_aamod_firstlevel_contrast.jpg'),'file')
efficiency(aap,subj);
if isempty(spm_select('List',aas_getsubjpath(aap,subj),'^diagnostic_.*jpg'))
diag(aap,subj);
end
fdiag = dir(fullfile(aas_getsubjpath(aap,subj),'diagnostic_*.jpg'));
for d = 1:numel(fdiag)
Expand Down Expand Up @@ -253,8 +253,8 @@
SPM = spm_contrasts(SPM);

% Efficiency based on Rik Henson's script [TA]
if settings.estimateefficiency
efficiency(aap, subj, SPM);
if settings.estimateefficiency && strcmp(aap.options.wheretoprocess,'localsingle')
diag(aap, subj, SPM);
end

% Describe outputs
Expand Down Expand Up @@ -282,15 +282,6 @@
end
cd (cwd);

%% DIAGNOSTICS (check distribution of T-values in contrasts)
cons = SPM.xCon; cons = cons([cons.STAT]=='T');
for c = cons
h = img2hist(fullfile(SPM.swd, c.Vspm.fname), [], strrep(c.name,' ',''), 0.1);
print(h,'-djpeg','-r150', fullfile(aas_getsubjpath(aap,subj), ...
['diagnostic_aamod_firstlevel_contrast_dist_' strrep(c.name,' ','') '.jpg']));
close(h);
end

case 'checkrequirements'

otherwise
Expand All @@ -299,7 +290,7 @@
end
end

function h = efficiency(aap,subj,SPM)
function h = diag(aap,subj,SPM)
% Based on Rik Henson's script

% Note this calculation of efficiency takes the 'filtered and whitened'
Expand All @@ -311,6 +302,17 @@
if nargin < 3 % SPM is not passed (e.g. reporting)
load(aas_getfiles_bystream(aap,subj,'firstlevel_spm'));
end

% distribution
cons = SPM.xCon; cons = cons([cons.STAT]=='T');
for c = cons
h = img2hist(fullfile(SPM.swd, c.Vspm.fname), [], strrep(c.name,' ',''), 0.1);
print(h,'-djpeg','-r150', fullfile(aas_getsubjpath(aap,subj), ...
['diagnostic_aamod_firstlevel_contrast_dist_' strrep(c.name,' ','') '.jpg']));
close(h);
end

% efficiency
X = SPM.xX.xKXs.X;
iXX=inv(X'*X);

Expand Down
2 changes: 1 addition & 1 deletion aa_modules/aamod_meg_average.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</qsub>

<robust>0</robust>
<conditionorder desc='Condition labels sperated with ":"'></conditionorder>
<conditionorder desc='Condition labels separated with ":"'></conditionorder>

<inputstreams>
<stream>meg</stream>
Expand Down
36 changes: 26 additions & 10 deletions aa_modules/aamod_secondlevel_contrasts.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

switch task
case 'report'
if isempty(spm_select('List',aas_getstudypath(aap),'^diagnostic_aamod_secondlevel_contrast.*jpg'))
diag(aap);
end
fdiag = dir(fullfile(aas_getstudypath(aap),'diagnostic_*.jpg'));
for d = 1:numel(fdiag)
aap = aas_report_add(aap,[],'<table><tr><td>');
Expand Down Expand Up @@ -57,16 +60,6 @@
allCons{flc} = spm_select('FPList',SPM.swd,'^con_.*');
allTs{flc} = spm_select('FPList',SPM.swd,'^spmT_.*');
allFs{flc} = spm_select('FPList',SPM.swd,'^spmF_.*');

% Diagnostics (check distribution of T-values in contrasts)
cons = SPM.xCon; cons = cons([cons.STAT]=='T');
for c = cons
h = img2hist(fullfile(SPM.swd, c.Vspm.fname), [], strrep(c.name,' ',''), 1);
print(h,'-djpeg','-r150', fullfile(aas_getstudypath(aap), ...
['diagnostic_aamod_firstlevel_contrast_dist_' basename(SPM.swd) '_' strrep(c.name,' ','') '.jpg']));
close(h);
end

end

%% Describe outputs
Expand All @@ -82,4 +75,27 @@
aas_log(aap,1,sprintf('Unknown task %s',task));

end
end

function diag(aap,SPM)

if nargin < 2 % SPM is not passed (e.g. reporting)
fnSPMs = aas_getfiles_bystream(aap,'secondlevel_spm');
for flc = 1:size(fnSPMs,1)
fnSPM = deblank(fnSPMs(flc,:));
loaded=load(fnSPM);
SPM(flc)=loaded.SPM;
end
end

for flc = 1:numel(SPM)
% distribution
cons = SPM(flc).xCon; cons = cons([cons.STAT]=='T');
for c = cons
h = img2hist(fullfile(SPM(flc).swd, c.Vspm.fname), [], strrep(c.name,' ',''), 1);
print(h,'-djpeg','-r150', fullfile(aas_getstudypath(aap), ...
['diagnostic_aamod_secondlevel_contrast_dist_' basename(SPM(flc).swd) '_' strrep(c.name,' ','') '.jpg']));
close(h);
end
end
end
29 changes: 29 additions & 0 deletions aa_toolbox/aa_convert_subjects.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function aap = aa_convert_subjects(aap)
aap0 = aarecipe('aap_parameters_defaults.xml','aap_tasklist_fmri.xml');
fields=fieldnames(aap0.schema.acq_details.subjects);
fields(strcmp(fields,'ATTRIBUTE')) = [];
for field=fields'
newsubj.(field{1})={[]};
end
fields(strcmp(fields,'subjname')) = [];
newsubj.subjname = '';

newsubj(1:numel(aap.acq_details.subjects)) = newsubj;

oldsubj = aap.acq_details.subjects;
for s = 1:numel(oldsubj)
for field=fields'
if isfield(oldsubj(s),field{1})
newsubj(s).(field{1})={oldsubj(s).(field{1})};
else
newsubj(s).(field{1})={[]};
end
end
end

aap.acq_details.subjects = newsubj;
aap.aap_beforeuserchanges.acq_details.subjects = newsubj;
for s = 1:numel(aap.acq_details.subjects)
aap = aamod_evaluatesubjectnames(aap,'doit',s);
end
aap.internal.aap_initial.acq_details.subjects = aap.acq_details.subjects;

0 comments on commit 4a61770

Please sign in to comment.