Skip to content

Commit

Permalink
Merge pull request automaticanalysis#209 from tiborauer/master
Browse files Browse the repository at this point in the history
DEBUGS
  • Loading branch information
jones-michael-s authored Feb 6, 2020
2 parents 5d0db17 + 462ad2a commit 05be61d
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 15 deletions.
3 changes: 3 additions & 0 deletions aa_engine/aas_getfiles_bystream_dep.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
function fname = aas_getfiles_bystream_dep(aap,domain,indices,stream)
% locate inputstream
inputstreamindex = strcmp({aap.internal.inputstreamsources{aap.tasklist.currenttask.modulenumber}.stream.name},stream);
if not(any(inputstreamindex))
inputstreamindex = cell2mat(cellfun(@(x) any(strcmp(strsplit(x,'.'),stream)),{aap.internal.inputstreamsources{aap.tasklist.currenttask.modulenumber}.stream.name},'UniformOutput',false));
end

% obnain source module number
sourcenumber = aap.internal.inputstreamsources{aap.tasklist.currenttask.modulenumber}.stream(inputstreamindex).sourcenumber;
Expand Down
24 changes: 12 additions & 12 deletions aa_modules/aamod_bet.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@
[pth nme ext]=fileparts(Simg);

outStruct=fullfile(pth,['bet_' nme fslext]);


fslcommand = sprintf('bet %s %s -f %f -v',Simg,outStruct, ...
aap.tasklist.currenttask.settings.bet_f_parameter);

if aap.tasklist.currenttask.settings.robust
% Run BET [-R Using robust setting to improve performance!]
aas_log(aap,false,'1st BET pass (recursive) to find optimal centre of gravity and radius')
[junk, w]=aas_runfslcommand(aap, ...
sprintf('bet %s %s -f %f -v -R',Simg,outStruct, ...
aap.tasklist.currenttask.settings.bet_f_parameter));
else
aas_log(aap,false,'1st BET pass')
[junk, w]=aas_runfslcommand(aap, ...
sprintf('bet %s %s -f %f -v ',Simg,outStruct, ...
aap.tasklist.currenttask.settings.bet_f_parameter));
fslcommand = [fslcommand ' -R'];
else aap.tasklist.currenttask.settings.biasneck
aas_log(aap,false,'1st BET pass (using bias field and neck cleanup) to find optimal centre of gravity and radius')
fslcommand = [fslcommand ' -B'];
end

[junk, w]=aas_runfslcommand(aap, fslcommand);

aas_log(aap,false,sprintf('Bet output: %s',w));

% This outputs last radius from recursive command...
Expand Down Expand Up @@ -151,7 +151,6 @@ function diag(aap,varargin)
outstreams = aas_getstreams(aap,'output'); %
Simg = aas_getfiles_bystream(aap,aap.tasklist.currenttask.domain,[varargin{:}],inpstreams{1},'input');
outStruct = aas_getfiles_bystream(aap,aap.tasklist.currenttask.domain,[varargin{:}],outstreams{1},'output');
outMesh = aas_getfiles_bystream(aap,aap.tasklist.currenttask.domain,[varargin{:}],outstreams{3},'output');

spm_check_registration(Simg)

Expand All @@ -165,6 +164,7 @@ function diag(aap,varargin)
spm_orthviews('addcolouredimage',1,outStruct, [0.9 0.4 0.4])
% Add mesh outlines, to see if BET has worked properly!
if aap.tasklist.currenttask.settings.masks
outMesh = aas_getfiles_bystream(aap,aap.tasklist.currenttask.domain,[varargin{:}],outstreams{3},'output');
for r = 1:size(outMesh,1)
if strfind(outMesh(r,:), aas_getfslext(aap))
indx = indx + 1;
Expand All @@ -181,4 +181,4 @@ function diag(aap,varargin)
set(gcf,'PaperPositionMode','auto','Renderer','zbuffer');
print('-djpeg','-r75',fullfile(aas_getpath_bydomain(aap,aap.tasklist.currenttask.domain,[varargin{:}]), ...
['diagnostic_' aap.tasklist.main.module(aap.tasklist.currenttask.modulenumber).name '_' aap.acq_details.subjects(varargin{1}).subjname '.jpg']));
end
end
7 changes: 6 additions & 1 deletion aa_modules/aamod_bet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@

<!-- BET F parameter - from 0 to 1 (least to most agressive skull stripping -->
<bet_f_parameter>0.5</bet_f_parameter>

<!-- The following parameters are mutually exclusive. Their existence will be tested sequentially in this order -->
<!-- Robust bet (recursive BET)? 0 - NO; 1 - YES -->
<robust>1</robust>
<!-- Bias field and neck cleanup? 0 - NO; 1 - YES -->
<biasneck>0</biasneck>

<!-- Do we want to output the masks & meshes from BET? 0 - NO; 1 - YES
This might slightly increase the accuracy of BET -->
<masks>1</masks>
Expand All @@ -42,4 +47,4 @@

</currenttask>
</tasklist>
</aap>
</aap>
2 changes: 1 addition & 1 deletion aa_modules/aamod_firstlevel_contrasts.m
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
else
sessweights = ones(1,numel(sessions));
end
[junk, indsess] = intersect(sessnames,sessions);
indsess = cellfun(@(x) find(strcmp(sessnames,x)), sessions);
sessforcon(indsess) = sessweights;
end

Expand Down
33 changes: 32 additions & 1 deletion aa_modules/aamod_secondlevel_model.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,38 @@

switch task
case 'report'
if ~exist(fullfile(aas_getstudypath(aap),['diagnostic_' aap.tasklist.main.module(aap.tasklist.currenttask.modulenumber).name '_design.jpg']),'file')
if numel(cellstr(spm_select('List',aas_getstudypath(aap),'^diagnostic.*'))) < 2 % two images expected
% group mask
for subj = 1:numel(aap.acq_details.subjects)
mask{subj} = aas_getfiles_bystream(aap,'subject',subj,'firstlevel_brainmask');
end
Vm = cell2mat(spm_vol(mask));
Ym = spm_read_vols(Vm);
Ys = sum(Ym,4);
Vs = Vm(1);
Vs.fname = fullfile(aas_getstudypath(aap),'groupmaps_summary.nii');
spm_write_vol(Vs,Ys)

so = slover;
so.figure = spm_figure('GetWin', 'SliceOverlay');

so.img.vol = spm_vol(fullfile(aap.directory_conventions.spmdir,aap.directory_conventions.T1template));
so.img.prop = 1;
so.transform = 'axial';
so = fill_defaults(so);
so.slices = -72:6:108;

so.img(2).vol = Vs;
so.img(2).type = 'truecolour';
so.img(2).prop = 0.33;
so.img(2).cmap = hot;
so.img(2).range = [0 max(Ys(:))];
so.cbar = [so.cbar 2];

so = paint(so);
spm_print(fullfile(aas_getstudypath(aap),['diagnostic_' aap.tasklist.main.module(aap.tasklist.currenttask.modulenumber).name '_groupmasksummary.jpg']),so.figure,'jpg');

% design
fSPM = aas_getfiles_bystream(aap,aap.tasklist.currenttask.outputstreams.stream{1}); fSPM = deblank(fSPM(1,:)); %all models are the same (number of inputs may vary)
load(fSPM);
spm_DesRep('DesOrth',SPM.xX);
Expand Down
1 change: 1 addition & 0 deletions aa_modules/aamod_secondlevel_model.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<permanenceofoutput>3</permanenceofoutput>

<inputstreams>
<stream diagnostic="1">firstlevel_brainmask</stream>
<stream>firstlevel_spm</stream>
<stream>firstlevel_cons</stream>
</inputstreams>
Expand Down

0 comments on commit 05be61d

Please sign in to comment.