Skip to content

Commit a3b32f9

Browse files
authored
Merge pull request #41 from SCIInstitute/scripting
Scripting
2 parents 9eead63 + 63d6b8e commit a3b32f9

29 files changed

+2384
-1603
lines changed

SOURCE/Fiducializing/autoProcessSignal.m

+57-46
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,18 @@
2323

2424

2525
function success = autoProcessSignal()
26-
% do all the autoprocessing. Use the fiducials in the fiducialed beat to find all other beats of
27-
% that run and fiducialise those beats, too. Handle & save the autoprocessed beats just like the
28-
% beat done by the user.
26+
% do all the autoprocessing. Use the fiducials in the fiducialed beat to find
27+
% all other beats of that run and fiducialise those beats, too. Handle & save
28+
% the autoprocessed beats just like the beat done by the user.
2929

3030
%set up globals
3131
clear global AUTOPROCESSING % just in case, so previous stuff doesnt mess anything up
3232
global TS SCRIPTDATA AUTOPROCESSING
3333

3434
unslicedDataIndex = SCRIPTDATA.unslicedDataIndex;
3535
templateFids = TS{SCRIPTDATA.CURRENTTS}.fids;
36-
templateBeatEnvelope = [TS{SCRIPTDATA.CURRENTTS}.selframes(1), TS{SCRIPTDATA.CURRENTTS}.selframes(2)];
36+
templateBeatEnvelope = [TS{SCRIPTDATA.CURRENTTS}.selframes(1), ...
37+
TS{SCRIPTDATA.CURRENTTS}.selframes(2)];
3738
badLeads = (find(TS{SCRIPTDATA.unslicedDataIndex}.leadinfo > 0))';
3839

3940

@@ -55,7 +56,8 @@
5556
settings.RunNumber = SCRIPTDATA.ACQNUM;
5657

5758

58-
[AUTOPROCESSING.beats, AUTOPROCESSING.allFids, info, success] = getBeatsAndFids(TS{unslicedDataIndex}.potvals, templateBeatEnvelope, templateFids, badLeads, settings);
59+
[AUTOPROCESSING.beats, AUTOPROCESSING.allFids, info, success] = getBeatsAndFids(...
60+
TS{unslicedDataIndex}.potvals, templateBeatEnvelope, templateFids, badLeads, settings);
5961
if ~success, return, end
6062

6163
AUTOPROCESSING.leadsToAutofiducialize = info.leadsToAutofiducialize;
@@ -76,15 +78,18 @@
7678
success = 1;
7779
return;
7880
end
79-
save(SCRIPTDATA.SCRIPTFILE,'SCRIPTDATA') % save settings.. in case user made a change in autofiducializing window
81+
% save settings.. in case user made a change in autofiducializing window
82+
save(SCRIPTDATA.SCRIPTFILE,'SCRIPTDATA')
8083
end
8184

8285
%%%%% main loop: process each beat.
83-
global times % to do: remove this? this global is only there to measure time efficiency..
86+
% to do: remove this? this global is only there to measure time efficiency..
87+
global times
8488
times=struct();
8589
times(1).count=1;
8690

87-
for beatNumber=2:length(AUTOPROCESSING.beats) % skip the first beat, as this is the user fiducialized one
91+
% skip the first beat, as this is the user fiducialized one
92+
for beatNumber=2:length(AUTOPROCESSING.beats)
8893
b=tic;
8994
success = processBeat(beatNumber);
9095
t2=toc(b);
@@ -103,31 +108,14 @@
103108

104109

105110

106-
107-
108-
109-
110-
111-
112-
113-
114-
115-
116-
117-
118-
119-
120-
121-
122-
123-
124111

125112

126113

127114
%%%%%%%%%%% functions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128115

129116
function getFaultyBeats
130-
% determine the beats, where autoprocessing didn't quite work ( eg those with very high variance)
117+
% determine the beats, where autoprocessing didn't quite work
118+
% ( eg those with very high variance)
131119
% fill AUTOPROCESSING.faultyBeatInfo and AUTOPROCESSING.faultyBeatIndeces with info
132120

133121
global AUTOPROCESSING SCRIPTDATA
@@ -141,8 +129,11 @@
141129
%%%% set up variables
142130
treshold_variance = SCRIPTDATA.TRESHOLD_VAR;
143131
faultyBeatIndeces =[]; % the indeces in .Beats of faulty beats
144-
faultyBeatInfo = {}; % which fiducials (which types) in the beat are bad? e.g faultyBeatInfo = { [2 4], [5 6 7],.. }
145-
faultyBeatValues = {}; % correspondes with faultyBeatInfo, but contains the value instead of type
132+
% which fiducials (which types) in the beat are bad?
133+
% e.g faultyBeatInfo = { [2 4], [5 6 7],.. }
134+
faultyBeatInfo = {};
135+
% correspondes with faultyBeatInfo, but contains the value instead of type
136+
faultyBeatValues = {};
146137
numBeats = length(AUTOPROCESSING.beats);
147138

148139
if ~isempty(AUTOPROCESSING.allFids)
@@ -163,7 +154,8 @@
163154
faultyBeatInfo{end+1} = faultyFids;
164155

165156
%%%% get the faultyValues of that faulty beat
166-
faultyIndeces = faultyIndeces + numFids; % now faultyIndeces are indeces of global bad fiducials
157+
% now faultyIndeces are indeces of global bad fiducials
158+
faultyIndeces = faultyIndeces + numFids;
167159
faultyValues = [AUTOPROCESSING.allFids{beatNumber}(faultyIndeces).value];
168160
faultyBeatValues{end+1}=faultyValues;
169161
end
@@ -191,7 +183,8 @@
191183
%%%% slice "complete ts" into beat (in TS{newBeatIdx} )
192184
a=tic;
193185
newBeatIdx=tsNew(1);
194-
beatframes=AUTOPROCESSING.beats{beatNumber}(1):AUTOPROCESSING.beats{beatNumber}(2); % all time frames of the beat
186+
% all time frames of the beat
187+
beatframes=AUTOPROCESSING.beats{beatNumber}(1):AUTOPROCESSING.beats{beatNumber}(2);
195188

196189
TS{newBeatIdx}=TS{SCRIPTDATA.unslicedDataIndex};
197190
TS{newBeatIdx}.potvals=TS{newBeatIdx}.potvals(:,beatframes);
@@ -218,7 +211,8 @@
218211
for fidIdx=1:length(fids)
219212
fids(fidIdx).value=fids(fidIdx).value - reference + 1; % fids now in relative frame
220213
end
221-
if isfield(fids,'variance'), fids=rmfield(fids,'variance'); end %variance not wanted in the output
214+
%variance not wanted in the output
215+
if isfield(fids,'variance'), fids=rmfield(fids,'variance'); end
222216
TS{newBeatIdx}.fids=fids;
223217
t=toc(a);
224218
times(times(1).count).b_MakeFidsLocalAndRemvoeVariance=t;
@@ -276,14 +270,16 @@
276270
%%%% split TS{newIdx} into numGroups smaller ts in grIndices
277271
splitgroup = [];
278272
for p=1:length(SCRIPTDATA.GROUPNAME{SCRIPTDATA.CURRENTRUNGROUP})
279-
if SCRIPTDATA.GROUPDONOTPROCESS{SCRIPTDATA.CURRENTRUNGROUP}{p} == 0, splitgroup = [splitgroup p]; end
273+
if SCRIPTDATA.GROUPDONOTPROCESS{SCRIPTDATA.CURRENTRUNGROUP}{p} == 0, ...
274+
splitgroup = [splitgroup p]; end
280275
end
281276
% splitgroup is now eg [1 3] if there are 3 groups but the 2 should
282277
% not be processed
283278
channels=SCRIPTDATA.GROUPLEADS{SCRIPTDATA.CURRENTRUNGROUP}(splitgroup);
284279
grIndices = tsSplitTS(newBeatIdx, channels);
285280
% update the filenames (add '-groupextension' to filename)
286-
tsDeal(grIndices,'filename',ioUpdateFilename('.mat',filename,SCRIPTDATA.GROUPEXTENSION{SCRIPTDATA.CURRENTRUNGROUP}(splitgroup)));
281+
tsDeal(grIndices,'filename',ioUpdateFilename('.mat',filename,SCRIPTDATA.GROUPEXTENSION{...
282+
SCRIPTDATA.CURRENTRUNGROUP}(splitgroup)));
287283
tsClear(newBeatIdx);
288284

289285
t=toc(a);
@@ -296,6 +292,7 @@
296292
ts=TS{grIdx};
297293
fullFilename=fullfile(SCRIPTDATA.MATODIR, ts.filename);
298294
fprintf('Saving file: %s\n',ts.filename)
295+
SCRIPTDATA.OUTFILENAME{end+1} = ts.filename;
299296
save(fullFilename,'ts','-v6')
300297
end
301298
t=toc(a);
@@ -309,21 +306,24 @@
309306
if SCRIPTDATA.DO_INTEGRALMAPS == 1
310307
a=tic;
311308
if SCRIPTDATA.DO_DETECT == 0
312-
msg=sprintf('Need fiducials (at least QRS wave or T wave) to do integral maps for %s. Aborting..', filename);
309+
msg=sprintf(['Need fiducials (at least QRS wave or T wave) to do integral ' ...
310+
'maps for %s. Aborting..'], filename);
313311
errordlg(msg)
314312
success = 0;
315313
return
316314
end
317315
mapindices = fidsIntAll(grIndices);
318316
if length(splitgroup)~=length(mapindices)
319-
msg=sprintf('Fiducials (QRS wave or T wave) necessary to do integral maps. However, for %s there are no fiducials for all groups. Aborting...',filename);
317+
msg=sprintf(['Fiducials (QRS wave or T wave) necessary to do integral maps. '...
318+
'However, for %s there are no fiducials for all groups. Aborting...'],filename);
320319
errordlg(msg)
321320
success = 0;
322321
return
323322
end
324323

325324

326-
fnames=ioUpdateFilename('.mat',filename,SCRIPTDATA.GROUPEXTENSION{SCRIPTDATA.CURRENTRUNGROUP}(splitgroup),'-itg');
325+
fnames=ioUpdateFilename('.mat',filename,SCRIPTDATA.GROUPEXTENSION{...
326+
SCRIPTDATA.CURRENTRUNGROUP}(splitgroup),'-itg');
327327

328328
tsDeal(mapindices,'filename',fnames);
329329
tsSet(mapindices,'newfileext','');
@@ -333,6 +333,7 @@
333333
ts=TS{mapIdx};
334334
fullFilename=fullfile(SCRIPTDATA.MATODIR, ts.filename);
335335
fprintf('Saving file: %s\n',ts.filename)
336+
SCRIPTDATA.ITGFILENAME{end+1} = ts.filename;
336337
save(fullFilename,'ts','-v6')
337338
end
338339
tsClear(mapindices);
@@ -349,22 +350,25 @@
349350
a=tic;
350351

351352
if SCRIPTDATA.DO_DETECT == 0 % 'Detect fiducials must be selected'
352-
errordlg('Fiducials needed to do Activationsmaps! Select the ''Do Fiducials'' button to do Activationmaps. Aborting...')
353+
errordlg(['Fiducials needed to do Activationsmaps! Select the ''Do Fiducials'' '...
354+
'button to do Activationmaps. Aborting...'])
353355
return
354356
end
355357

356358
%%%% make new ts at TS(mapindices). That new ts is like the old
357359
%%%% one, but has ts.potvals=[act rec act-rec]
358360
[mapindices, success] = sigActRecMap(grIndices);
359361
if ~success,return, end
360-
tsDeal(mapindices,'filename',ioUpdateFilename('.mat',filename,SCRIPTDATA.GROUPEXTENSION{SCRIPTDATA.CURRENTRUNGROUP}(splitgroup),'-ari'));
362+
tsDeal(mapindices,'filename',ioUpdateFilename('.mat',filename,SCRIPTDATA.GROUPEXTENSION{...
363+
SCRIPTDATA.CURRENTRUNGROUP}(splitgroup),'-ari'));
361364
tsSet(mapindices,'newfileext','');
362365

363366
%%%% save the 'new act/rec' ts as eg 'Run0009-gr1-ari.mat and clearTS{mapindex}
364367
for mapIdx=mapindices
365368
ts=TS{mapIdx};
366369
fullFilename=fullfile(SCRIPTDATA.MATODIR, ts.filename);
367370
fprintf('Saving file: %s\n',ts.filename)
371+
SCRIPTDATA.ARIFILENAME{end+1} = ts.filename;
368372
save(fullFilename,'ts','-v6')
369373
end
370374
tsClear(mapindices);
@@ -396,7 +400,8 @@
396400
qstart_indeces=find([TS{newBeatIdx}.fids.type]==2);
397401
qend_indeces=find([TS{newBeatIdx}.fids.type]==4);
398402
if isempty(qstart_indeces) || isempty(qend_indeces)
399-
msg = sprintf('There is no qrs-wave for the file %s. Therefore, activation detection cannot be done for this file. Aborting...',TS{newBeatIdx}.filename);
403+
msg = sprintf(['There is no qrs-wave for the file %s. Therefore, activation '...
404+
'detection cannot be done for this file. Aborting...'],TS{newBeatIdx}.filename);
400405
errordlg(msg)
401406
success = 0;
402407
return
@@ -433,7 +438,8 @@
433438
if ~success, return, end
434439

435440
if any((qe-qs) < 15)
436-
msg = sprintf('The QRS-wave in beat %d is to small! This often causes the activation detetection to fail',newBeatIdx);
441+
msg = sprintf(['The QRS-wave in beat %d is to small! This often causes the '...
442+
'activation detetection to fail'],newBeatIdx);
437443
errordlg(msg)
438444
success = 0 ;
439445
return
@@ -442,8 +448,10 @@
442448
try
443449
for leadNumber=1:numchannels
444450
%for each lead in each group = for all leads..
445-
%[act(leadNumber)] = (actFktHandle(TS{newBeatIdx}.potvals(leadNumber,qs(leadNumber):qe(leadNumber)),win,deg)-1)/SCRIPTDATA.SAMPLEFREQ + qs(leadNumber);
446-
[act(leadNumber)] = (actFktHandle(TS{newBeatIdx}.potvals(leadNumber,qs(leadNumber):qe(leadNumber)),win,deg)-1) + qs(leadNumber);
451+
%[act(leadNumber)] = (actFktHandle(TS{newBeatIdx}.potvals(leadNumber,...
452+
%qs(leadNumber):qe(leadNumber)),win,deg)-1)/SCRIPTDATA.SAMPLEFREQ + qs(leadNumber);
453+
[act(leadNumber)] = (actFktHandle(TS{newBeatIdx}.potvals(leadNumber,...
454+
qs(leadNumber):qe(leadNumber)),win,deg)-1) + qs(leadNumber);
447455
end
448456
catch
449457
errordlg('The selected function used to find the activations caused an error. Aborting...')
@@ -477,7 +485,8 @@
477485
tStartIndeces=find([TS{newBeatIdx}.fids.type]==5);
478486
tEndIndeces=find([TS{newBeatIdx}.fids.type]==7);
479487
if isempty(tStartIndeces) || isempty(tEndIndeces)
480-
msg = sprintf('There is no t-wave for the file %s. Therefore, recovery detection cannot be done for this file. Aborting...',TS{newBeatIdx}.filename);
488+
msg = sprintf(['There is no t-wave for the file %s. Therefore, recovery '...
489+
'detection cannot be done for this file. Aborting...'],TS{newBeatIdx}.filename);
481490
errordlg(msg)
482491
success = 0;
483492
return
@@ -512,8 +521,10 @@
512521
if ~success, return, end
513522
try
514523
for leadNumber=1:numchannels
515-
%rec(leadNumber) = recFktHandle(TS{newBeatIdx}.potvals(leadNumber,ts(leadNumber):te(leadNumber)),win,deg)/SCRIPTDATA.SAMPLEFREQ + ts(leadNumber);
516-
rec(leadNumber) = recFktHandle(TS{newBeatIdx}.potvals(leadNumber,ts(leadNumber):te(leadNumber)),win,deg) + ts(leadNumber);
524+
%rec(leadNumber) = recFktHandle(TS{newBeatIdx}.potvals(leadNumber,...
525+
%ts(leadNumber):te(leadNumber)),win,deg)/SCRIPTDATA.SAMPLEFREQ + ts(leadNumber);
526+
rec(leadNumber) = recFktHandle(TS{newBeatIdx}.potvals(leadNumber,...
527+
ts(leadNumber):te(leadNumber)),win,deg) + ts(leadNumber);
517528

518529
end
519530
catch

SOURCE/Functions/app/CloseFcn.m

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
% MIT License
2+
%
3+
% Copyright (c) 2017 The Scientific Computing and Imaging Institute
4+
%
5+
% Permission is hereby granted, free of charge, to any person obtaining a copy
6+
% of this software and associated documentation files (the "Software"), to deal
7+
% in the Software without restriction, including without limitation the rights
8+
% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
% copies of the Software, and to permit persons to whom the Software is
10+
% furnished to do so, subject to the following conditions:
11+
%
12+
% The above copyright notice and this permission notice shall be included in all
13+
% copies or substantial portions of the Software.
14+
%
15+
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
% SOFTWARE.
22+
23+
24+
25+
26+
function CloseFcn(~)
27+
%callback function for the 'close' buttons.
28+
global SCRIPTDATA PROCESSINGDATA FIDSDISPLAY SLICEDISPLAY TS
29+
30+
%%%% save setting
31+
try
32+
if ~isempty(SCRIPTDATA.SCRIPTFILE)
33+
saveSettings
34+
disp('Saved SETTINGS before closing PFEIFER')
35+
else
36+
disp('PFEIFER closed without saving SETTINGS')
37+
end
38+
catch
39+
%do nothing
40+
end
41+
42+
%%%% delete all gui figures
43+
delete(findobj(allchild(0),'tag','PROCESSINGSCRIPTMENU'));
44+
delete(findobj(allchild(0),'tag','PROCESSINGSCRIPTSETTINGS'));
45+
delete(findobj(allchild(0),'tag','SLICEDISPLAY'));
46+
delete(findobj(allchild(0),'tag','FIDSDISPLAY'));
47+
48+
%%%% delete all waitbars
49+
waitObjs = findall(0,'type','figure','tag','waitbar');
50+
delete(waitObjs);
51+
52+
%%%% delete all error dialog windows
53+
errordlgObjs = findall(0,'type','figure','tag','Msgbox_Error Dialog');
54+
delete(errordlgObjs);
55+
56+
%%%% clear globals
57+
clear global FIDSDISPLAY SLICEDISPLAY TS
58+
end

0 commit comments

Comments
 (0)