Authored by Anthony Boyer

ImaGIN_Electrode: when duplicated channels, pick the one using uppercase as iEEG…

…. ImaGIN_SpikesDetection: Now ignore channels with special characters.
@@ -139,12 +139,26 @@ for i0 = 1:size(t,1) @@ -139,12 +139,26 @@ for i0 = 1:size(t,1)
139 % If the channel was already found in the list before: check the best option based on the case 139 % If the channel was already found in the list before: check the best option based on the case
140 if ~isempty(iChanPos) && ~isempty(chMatchLog) 140 if ~isempty(iChanPos) && ~isempty(chMatchLog)
141 iPrevious = find(strcmp(Name{iChanPos}, chMatchLog(:,2))); 141 iPrevious = find(strcmp(Name{iChanPos}, chMatchLog(:,2)));
142 - if ~isempty(iPrevious) 142 + if ~isempty(iPrevious)
143 % If the new channel has strictly the same case, or if it corresponds to a replaced "prime": remove the previous match 143 % If the new channel has strictly the same case, or if it corresponds to a replaced "prime": remove the previous match
144 if isequal(Sensors.label{i1}, Name{iChanPos}) || ... 144 if isequal(Sensors.label{i1}, Name{iChanPos}) || ...
145 (any(Sensors.label{i1} == '''') && strcmp(strrep(upper(Sensors.label{i1}), '''', 'p'), Name{iChanPos})) 145 (any(Sensors.label{i1} == '''') && strcmp(strrep(upper(Sensors.label{i1}), '''', 'p'), Name{iChanPos}))
146 - disp(['ImaGIN> WARNING: Channel name conflict: ' Sensors.label{i1} ' matched with ' Name{iChanPos} ', ' chMatchLog{iPrevious,1} 'discarded.']);  
147 - chMatchLog(iPrevious,:) = []; 146 + disp(['ImaGIN> WARNING: Channel name conflict: ' Sensors.label{i1} ' matched with ' Name{iChanPos} ', ' chMatchLog{iPrevious,1} ' discarded.']);
  147 + chMatchLog(iPrevious,:) = [];
  148 + % If both labels are the same regardless of the case, pick the one with uppercase (intra-recording).
  149 + elseif strcmpi(chMatchLog{iPrevious,1},Sensors.label{i1})
  150 + uppercase_label = find([sum(isstrprop(chMatchLog{iPrevious,1},'upper'))>0 sum(isstrprop(Sensors.label{i1},'upper'))>0]);
  151 + if numel(uppercase_label) == 1
  152 + disp(['ImaGIN> WARNING: Channel name conflict: ' Sensors.label{i1} ' matched with ' Name{iChanPos} ', ' chMatchLog{iPrevious,1} ' discarded.']);
  153 + % Rename the scalp electrode and remove the coordinates
  154 + scalp_idx = find(strcmp(SpmMat.D.sensors.eeg.label,chMatchLog{iPrevious,1}));
  155 + Sensors.elecpos(scalp_idx,:) = nan(1,3);
  156 + Sensors.chanpos(scalp_idx,:) = nan(1,3);
  157 + Sensors.label{scalp_idx} = ['SCALP' Sensors.label{scalp_idx}];
  158 + chMatchLog(iPrevious,:) = [];
  159 + else
  160 + error(['Duplicated label found: ' Sensors.label{i1}]);
  161 + end
148 else 162 else
149 disp(['ImaGIN> WARNING: Channel name conflict: ' chMatchLog{iPrevious,1} ' matched with ' Name{iChanPos} ', ' Sensors.label{i1} ' discarded.']); 163 disp(['ImaGIN> WARNING: Channel name conflict: ' chMatchLog{iPrevious,1} ' matched with ' Name{iChanPos} ', ' Sensors.label{i1} ' discarded.']);
150 iChanPos = []; 164 iChanPos = [];
@@ -50,9 +50,11 @@ function ImaGIN_SpikesDetection(S) @@ -50,9 +50,11 @@ function ImaGIN_SpikesDetection(S)
50 eeg_chans_idxes = indchantype(D,'EEG'); 50 eeg_chans_idxes = indchantype(D,'EEG');
51 for cc=1:numel(eeg_chans_idxes) 51 for cc=1:numel(eeg_chans_idxes)
52 channel_name = chanlabels(D,eeg_chans_idxes(cc)); 52 channel_name = chanlabels(D,eeg_chans_idxes(cc));
53 - channels.(channel_name{:}).timeserie{ff,:} = file_baselines(eeg_chans_idxes(cc),:,:);  
54 - channels.(channel_name{:}).zeroed{ff,:} = file_zeroed(eeg_chans_idxes(cc),:,:);  
55 - channels.(channel_name{:}).coordinates{ff,:} = sensors_info.elecpos(find(strcmp(channel_name,sensors_info.label)),:); 53 + if isvarname(channel_name{:})
  54 + channels.(channel_name{:}).timeserie{ff,:} = file_baselines(eeg_chans_idxes(cc),:,:);
  55 + channels.(channel_name{:}).zeroed{ff,:} = file_zeroed(eeg_chans_idxes(cc),:,:);
  56 + channels.(channel_name{:}).coordinates{ff,:} = sensors_info.elecpos(find(strcmp(channel_name,sensors_info.label)),:);
  57 + end
56 end 58 end
57 % Tidy the channels struct with empty inputs for consistency 59 % Tidy the channels struct with empty inputs for consistency
58 temp_montage = fieldnames(channels); 60 temp_montage = fieldnames(channels);