Skip to content

Commit

Permalink
Fixed: Corrected bug in cat_vol_qa with missing rating.
Browse files Browse the repository at this point in the history
Fixed:    Corrected bug reported by Torben Lund in cat_surf_info in
          case of specific SPM.mat files.

Changed paths:
 M CHANGES.txt
 M cat_io_subfolders.m
 M cat_run_newcatch.m
 M cat_surf_info.m
 M cat_vol_qa.m
  • Loading branch information
robdahn committed Apr 17, 2024
1 parent 155d902 commit 56d0095
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 45 deletions.
13 changes: 13 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
------------------------------------------------------------------------
r2573 | dahnke | 2024-04-17 17:58:34

Changed paths:
M CHANGES.txt
M cat_io_subfolders.m
M cat_run_newcatch.m
M cat_surf_info.m
M cat_vol_qa.m

Fixed: Corrected bug in cat_vol_qa with missing rating.
Fixed: Corrected bug reported by Torben Lund in cat_surf_info in
case of specific SPM.mat files.
------------------------------------------------------------------------
r2572 | dahnke | 2024-04-17 13:59:42

Changed paths:
Expand Down
2 changes: 1 addition & 1 deletion cat_io_subfolders.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
fname = char(fname);
% to indicate BIDS structure the last subfolder has to be named "anat"
% and "sub-" folders should exist
if isfield(job.extopts,'BIDSfolder')
if exist('job','var') && isfield(job,'extopts') && isfield(job.extopts,'BIDSfolder')
ind = max(strfind(spm_fileparts(fname),[filesep 'sub-']));
if ~isempty(ind) % && strcmp(spm_file(spm_file(fname,'fpath'),'basename'),'anat')
% RD202303: I think it better to fosing only on the sub- directory
Expand Down
2 changes: 1 addition & 1 deletion cat_run_newcatch.m
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function cat_run_newcatch(job,tpm,subj)
for si=1:numel(caterr.stack)
str_err = [str_err '|' caterr.stack(si).name ':' num2str(caterr.stack(si).line)];
end
urlinfo = sprintf('%s/%s/%s/%s\%s/%s/%s/%s',CATrel,computer,'errors',['r' CATver],caterr_id,version('-release'),caterr_message_str,str_err);
urlinfo = sprintf('%s/%s/%s/%s/%s/%s/%s/%s',CATrel,computer,'errors',['r' CATver],caterr_id,version('-release'),caterr_message_str,str_err);
cat_io_send_to_server(urlinfo);
end

Expand Down
82 changes: 51 additions & 31 deletions cat_surf_info.m
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@

for i=1:numel(P)
[pp,ff,ee] = spm_fileparts(P{i});
if strcmp(ee,'.dat')
P{i} = spm_file(P{i},'ext','.gii');
end
sinfo(i).fdata = dir(P{i});

sinfo(i).fname = P{i};
Expand Down Expand Up @@ -163,6 +166,8 @@
clear S;
try
S = cat_io_FreeSurfer('read_annotation',P{1});
catch
cat_io_cprintf('warn',sprintf('Warning: Error while reading annotation file: \n %s\n',P{1}));
end
end
if exist('S','var')
Expand All @@ -173,19 +178,23 @@
sinfo(i).ee = '';
sinfo(i).ftype = 0;
if sinfo(i).exist && readsurf
% this files are not specified by ending so we will just try to read something
clear S;
try
try %#ok<TRYNC>
S = cat_io_FreeSurfer('read_surf',P{1});
if size(S.faces,2)~=3 || size(S.faces,1)<10000
if ~isstruct(S) || ~isfield(S,'faces') || (size(S.faces,2)~=3 || size(S.faces,1)<10000)
clear S;
end
end
try
S.cdata = cat_io_FreeSurfer('read_surf_data',P{1});
try %#ok<TRYNC>
S.cdata = cat_io_FreeSurfer('read_surf_data',P{1});
if size(S.face,2)==3 || size(S.face,1)<10000
S = rmfield(S,'cdata');
end
end
if ~exist('S','var')
cat_io_cprintf('warn',sprintf('Warning: Error while reading surface file: \n %s\n',P{1}));
end
end
if exist('S','var')
sinfo(i).ftype = 2;
Expand All @@ -199,12 +208,12 @@
sinfo(i).statready = ~isempty(regexp(noname,'^s(?<smooth>\d+)\..*'));

% side
if strfind(noname,'lh.'), sinfo(i).side='lh'; sidei = strfind(noname,'lh.');
elseif strfind(noname,'rh.'), sinfo(i).side='rh'; sidei = strfind(noname,'rh.');
elseif strfind(noname,'cb.'), sinfo(i).side='cb'; sidei = strfind(noname,'cb.');
elseif strfind(noname,'mesh.'), sinfo(i).side='mesh'; sidei = strfind(noname,'mesh.');
elseif strfind(noname,'lc.'), sinfo(i).side='lc'; sidei = strfind(noname,'lc.');
elseif strfind(noname,'rc.'), sinfo(i).side='rc'; sidei = strfind(noname,'rc.');
if cat_io_contains(noname,'lh.'), sinfo(i).side='lh'; sidei = strfind(noname,'lh.');
elseif cat_io_contains(noname,'rh.'), sinfo(i).side='rh'; sidei = strfind(noname,'rh.');
elseif cat_io_contains(noname,'cb.'), sinfo(i).side='cb'; sidei = strfind(noname,'cb.');
elseif cat_io_contains(noname,'mesh.'), sinfo(i).side='mesh'; sidei = strfind(noname,'mesh.');
elseif cat_io_contains(noname,'lc.'), sinfo(i).side='lc'; sidei = strfind(noname,'lc.');
elseif cat_io_contains(noname,'rc.'), sinfo(i).side='rc'; sidei = strfind(noname,'rc.');
else

% skip for volume files
Expand All @@ -213,21 +222,30 @@
end

% if SPM.mat exist use that for side information
if exist(fullfile(pp,'SPM.mat'),'file')
load(fullfile(pp,'SPM.mat'));
[pp2,ff2] = spm_fileparts(SPM.xY.VY(1).fname);

% find mesh string
hemi_ind = strfind(ff2,'mesh.');
if ~isempty(hemi_ind)
sinfo(i).side = ff2(hemi_ind(1):hemi_ind(1)+3);
else
% find lh|rh string
hemi_ind = [strfind(ff2,'lh.') strfind(ff2,'rh.') strfind(ff2,'lc.') strfind(ff2,'rc.')];
sinfo(i).side = ff2(hemi_ind(1):hemi_ind(1)+1);
% Torben Lund Mail 20240409: issues with reading some SPM.mat files that did not include the right
if ~isempty(pp) && exist(fullfile(pp,'SPM.mat'),'file')
try %#ok<TRYNC>
load(fullfile(pp,'SPM.mat'),'SPM'); % this will give a warning if the var SPM does not exist
end
if exist('SPM','var')
if isfield(SPM,'xY') && isfield (SPM.xY,'VY') && isfield(SPM.xY.VY(1),'fname')
[~,ff2] = spm_fileparts(SPM.xY.VY(1).fname);

% find mesh string
hemi_ind = strfind(ff2,'mesh.');
if ~isempty(hemi_ind)
sinfo(i).side = ff2(hemi_ind(1):hemi_ind(1)+3);
else
% find lh|rh string
hemi_ind = [strfind(ff2,'lh.') strfind(ff2,'rh.') strfind(ff2,'lc.') strfind(ff2,'rc.')];
sinfo(i).side = ff2(hemi_ind(1):hemi_ind(1)+1);
end

sidei = []; % handle this later
else
cat_io_cprintf('warn',sprintf('Warning: Error SPM.mat does not include required fields: \n %s\n',P{1}));
end
end

sidei=[];
else
if gui
if cat_get_defaults('extopts.expertgui')
Expand Down Expand Up @@ -274,7 +292,7 @@
isempty(strfind(sinfo(i).posside,'.resampled_32k'));
sinfo(i).resampled_32k = ~isempty(strfind(sinfo(i).posside,'.resampled_32k'));
% template
sinfo(i).template = ~isempty(strfind(lower(sinfo(i).ff),'.template'));
sinfo(i).template = cat_io_contains(lower(sinfo(1).ff),'.template');
% CG20210226: This caused crashes in cat_surf_surf2roi.m for some files
% if sinfo(i).template, sinfo(i).resampled = 1; end

Expand All @@ -299,7 +317,7 @@
% if not points exist that the string is the name
sinfo(i).name = '';
sinfo(i).texture = sinfo(i).posside;
elseif numel(doti)==1
elseif isscalar(doti)
% if one point exist that the first string is the dataname and the second the subject name
sinfo(i).name = sinfo(i).posside(doti+1:end);
sinfo(i).texture = sinfo(i).posside(1:doti-1);
Expand Down Expand Up @@ -422,8 +440,8 @@
[pp2,ff2,xx2] = spm_fileparts(SPM.xVol.G);
% rename old Template name from previous versions
ff2 = strrep(ff2,'Template_T1_IXI555_MNI152_GS',cat_get_defaults('extopts.shootingsurf'));
if ~isempty(strfind(ff2,'.central.freesurfer')) || ~isempty(strfind(ff2,['.central.' cat_get_defaults('extopts.shootingsurf')]))
if strfind(pp2,'templates_surfaces_32k')
if cat_io_contains(ff2,'.central.freesurfer') || cat_io_contains(ff2,['.central.' cat_get_defaults('extopts.shootingsurf')])
if cat_io_contains(pp2,'templates_surfaces_32k')
SPM.xVol.G = fullfile(fileparts(mfilename('fullpath')),'templates_surfaces_32k',[ff2 xx2]);
else
SPM.xVol.G = fullfile(fileparts(mfilename('fullpath')),'templates_surfaces',[ff2 xx2]);
Expand Down Expand Up @@ -453,7 +471,9 @@
if sinfo(i).exist && ~readsurf
clear S;
try
S = cat_io_FreeSurfer('read_annotation',P{1});
S = cat_io_FreeSurfer('read_annotation',P{1});
catch
cat_io_cprintf('warn',sprintf('Warning: Error while reading annotation file: \n %s\n',P{1}));
end
end
end
Expand Down Expand Up @@ -532,8 +552,8 @@
if ~isempty(sinfo(i).Pmesh) && exist(sinfo(i).Pmesh,'file')
S2 = gifti(sinfo(i).Pmesh);
if ~isstruct(S), clear S; end
if isfield(S2,'vertices'), S.vertices = S2.vertices; else S.vertices = []; end
if isfield(S2,'faces'), S.faces = S2.faces; else S.faces = []; end
if isfield(S2,'vertices'), S.vertices = S2.vertices; else, S.vertices = []; end
if isfield(S2,'faces'), S.faces = S2.faces; else, S.faces = []; end
end
if isfield(S,'vertices')
sinfo(i).nvertices = size(S.vertices,1);
Expand Down
15 changes: 3 additions & 12 deletions cat_vol_qa.m
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@
case 'cat12'
% Direct call of the specific QC version with input images given by the
% varargin structure used in the CAT12 pipeline (processing of one case)
sprintf('[QAS,QAR] = %s(''cat12'',varargin{:});', opt.version)
%sprintf('[QAS,QAR] = %s(''cat12'',varargin{:});', opt.version)
if isstruct(varargin{end}), varargin{end}.write_xml = 0; end

eval(sprintf('[QAS,QAR] = %s(''cat12'',varargin{:});', opt.version));
Expand Down Expand Up @@ -651,16 +651,13 @@
end

% export
if opt.write_xml && fi==1
if strcmp(action,'cat12') % exist('Pp0','var') && isscalar(Pp0) && opt.write_xml
QAS.qualityratings = QAR.qualityratings;
QAS.subjectratings = QAR.subjectratings;
QAS.ratings_help = QAR.help;

[pp,ff] = spm_fileparts(QAS.filedata.fname);
fullfile(pp,reportfolder,[opt.prefix ff '.xml']);

fprintf( 'XML-File-QA: "%s" \n' ,fullfile(pp,reportfolder,[opt.prefix ff '.xml']) )

cat_io_xml( fullfile(pp,reportfolder,[opt.prefix ff '.xml']) ,QAS,'write'); %struct('QAS',QAS,'QAM',QAM)
end

Expand Down Expand Up @@ -885,13 +882,7 @@

% export
if opt.write_xml

fprintf( 'XML-File-QAERR: "%s" \n' ,fullfile(pp,reportfolder,[opt.prefix ff '.xml']) )

cat_io_xml(fullfile(pp,reportfolder,[opt.prefix ff '.xml']),QAS,'write');
else
fprintf( 'no - XML-File-QA: "%s" \n' ,fullfile(pp,reportfolder,[opt.prefix ff '.xml']) )

cat_io_xml(fullfile(pp,reportfolder,[opt.prefix ff '.xml']),QAS,'write');
end
end
%==========================================================================
Expand Down

0 comments on commit 56d0095

Please sign in to comment.