[422372]: / functions / studyfunc / std_checkfiles.m

Download this file

186 lines (170 with data), 8.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
% STD_CHECKFILES - Check all STUDY files consistency
%
% Usage:
% >> boolval = std_checkfiles(STUDY, ALLEEG);
% Inputs:
% STUDY - EEGLAB STUDY set comprising some or all of the EEG datasets in ALLEEG.
% ALLEEG - All EEGLAB datasets
%
% Outputs:
% boolval - [0|1] 1 if uniform
%
% Authors: Arnaud Delorme, CERCO, 2010-
% Copyright (C) Arnaud Delorme, CERCO
%
% This file is part of EEGLAB, see http://www.eeglab.org
% for the documentation and details.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are met:
%
% 1. Redistributions of source code must retain the above copyright notice,
% this list of conditions and the following disclaimer.
%
% 2. Redistributions in binary form must reproduce the above copyright notice,
% this list of conditions and the following disclaimer in the documentation
% and/or other materials provided with the distribution.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
% THE POSSIBILITY OF SUCH DAMAGE.
function [boolval npersubj] = std_checkfiles(STUDY, ALLEEG);
if nargin < 2
help std_checkfiles;
return;
end
return;
filetypes = { 'daterp' 'datspec' 'datersp' 'datitc' 'dattimef' ...
'icaerp' 'icaspec' 'icaersp' 'icaitc' 'icatopo' };
% set channel interpolation mode
% ------------------------------
uniformchannels = std_uniformsetinds( STUDY );
disp('---------------------------------------------');
disp('Checking data files integrity and consistency');
passall = 1;
for index = 1:length(filetypes)
% scan datasets
% -------------
[ tmpstruct compinds filepresent ] = std_fileinfo(ALLEEG, filetypes{index});
if ~isempty(tmpstruct)
fprintf('Files of type "%s" detected, checking...', filetypes{index});
end
% check if the structures are equal
% ---------------------------------
notequal = any(~filepresent);
if ~isempty(tmpstruct)
if any(filepresent == 0)
fprintf(' Error, some files inconsistent or missing\n');
notequal = 1;
passall = 0;
else
firstpass = 1;
fields = fieldnames(tmpstruct);
for f_ind = 1:length(fields)
firstval = getfield(tmpstruct, {1}, fields{f_ind});
for dat = 2:length(tmpstruct)
tmpval = getfield(tmpstruct, {dat}, fields{f_ind});
if ~isequal(firstval, tmpval)
% check for NaNs
if iscell(firstval) && iscell(tmpval)
for cind = 1:length(firstval)
if isreal(firstval{cind}) && ~isempty(firstval{cind}) && isnan(firstval{cind}(1))
firstval{cind} = 'NaN';
end
end
for cind = 1:length(tmpval)
if isreal(tmpval{cind}) && ~isempty(tmpval{cind}) && isnan(tmpval{cind}(1))
tmpval{cind} = 'NaN';
end
end
end
if ~isequal(firstval, tmpval)
if ~strcmpi(fields{f_ind}, 'labels') || strcmpi(uniformchannels, 'on')
if firstpass == 1, fprintf('\n'); firstpass = 0; end
fprintf(' Error, difference across data files for field "%s"\n', fields{f_ind});
notequal = 1;
passall = 0;
break;
end
end
end
end
end
end
end
% check the consistency of changrp and cluster with saved information
% -------------------------------------------------------------------
if isempty(tmpstruct), notequal = 1; end
if filetypes{index}(1) == 'd' && notequal == 0
% scan all channel labels
% -----------------------
if isfield(tmpstruct(1), 'labels')
for cind = 1:length(STUDY.changrp)
if notequal == 0
for inddat = 1:length(ALLEEG)
tmpind = cellfun(@(x)(find(x == inddat)), STUDY.changrp(cind).setinds(:), 'uniformoutput', false);
indnonempty = find(~cellfun(@isempty, tmpind(:)));
if ~isempty(indnonempty)
tmpchan = STUDY.changrp(cind).allinds{indnonempty}(tmpind{indnonempty}); % channel index for dataset inddat
tmpchan2 = strmatch(STUDY.changrp(cind).name, tmpstruct(inddat).labels, 'exact'); % channel index in file
if ~isempty(tmpchan2) || ~strcmpi(filetypes{index}, 'datspec') % the last statement is because channel labels did not use to be saved in spec files
if ~isequal(tmpchan2, tmpchan)
fprintf('\nError: channel index in STUDY.changrp(%d) for dataset %d is "%d" but "%d" in data files\n', cind, inddat, tmpchan, tmpchan2);
notequal = 1;
break;
end
end
end
end
end
end
end
elseif notequal == 0 && ~isempty(STUDY.cluster) % components
% check that the cell structures are present
% ------------------------------------------
if ~isfield(STUDY.cluster, 'setinds')
STUDY.cluster(1).setinds = [];
STUDY.cluster(1).allinds = [];
end
for cind = 1:length(STUDY.cluster)
if isempty(STUDY.cluster(cind).setinds)
STUDY.cluster(cind) = std_setcomps2cell(STUDY, cind);
end
end
for cind = 1:length(STUDY.cluster)
if notequal == 0
for inddat = 1:length(ALLEEG)
tmpind = cellfun(@(x)(find(x == inddat)), STUDY.cluster(cind).setinds(:), 'uniformoutput', false);
indnonempty = find(~cellfun(@isempty, tmpind(:)));
tmpcomp = [];
for jind = 1:length(indnonempty)
tmpcomp = [ tmpcomp STUDY.cluster(cind).allinds{indnonempty(jind)}(tmpind{indnonempty(jind)}) ];
end
if ~isempty(setdiff(tmpcomp, compinds{inddat}))
if ~(isempty(compinds{inddat}) && strcmpi(filetypes{index}, 'icatopo'))
fprintf('\nError: some components in clusters %d are absent from .%s files\n', cind, filetypes{index});
notequal = 1;
passall = 0;
break;
end
end
end
end
end
end
if notequal == 0, fprintf(' Pass\n'); end
end
if ~passall
disp('**** Recompute any measure above not receiving a "Pass" by')
disp('**** calling menu items "STUDY > Precompute Channel/Component measures" ');
disp('**** and by selecting the "Recompute even if present on disk" checkbox');
end
disp('Checking completed.');