-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwholeBrain_batch.m
506 lines (428 loc) · 20.7 KB
/
wholeBrain_batch.m
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
function wholeBrain_batch(filename,handles)
%wholeBrain_batch - A batch processing script for wholeBrain paper
%Examples:
% >> wholeBrain_batch('files.txt')
% >> wholeBrain_batch('files.txt',handles)
%
%**USE**
%Must provide one input:
%
%(1) table name with desired filenames (space delimited txt file, with full filenames in first column)
%files.txt should have TIFF movie filenames in first column, dummy region matlab filenames in second column
%can have an extra columns with descriptor/factor information for the file. This will be the rowinfo that is attached to each measure observation in the following script.
%depends on readtext.m file script from matlab central - readtext('files.txt',' ');
%
%Optional:
% handles - handle structure of input variables
% handles.makeMovies - string of 'all', 'some', or 'none' to indicate if you want to make avis. Do 'none' or 'some' to speed things up.
% handles.hemisphereIndices - vector of integers, region.coord index locations in region.name for gross anatomical brain regions like 'cortex.L' and 'cortex.R' and others (e.g. 'OB.L', 'OB.R', 'SC.L', 'SC.R', etc).
% handles.backgroundRemovRadius - single numeric in pixels. Default corresponds to 681 µm radius (round(681/region.spaceres)) for the circular structured element used for background subtraction.
% handles.pthr - single numeric. Default is 0.99. Percentile threshold for the sobel edge based detection algorithm in wholeBrain_segmentation.m
% handles.makeThresh - single numeric logical. Default is 1, for estimating the graythreshold using Otsu's method for each movie separately. Alternative is to use previous movie graythresh (like for subsequent recordings).
% handles.sigma - %sigma is the standard deviation in pixels of the gaussian for smoothing. It is 56.75µm at 11.35µm/px dimensions to give a **5px sigma**. gaussSmooth.m multiplies the sigma by 2.25 standard deviations for the filter size by default.
% handles.useSobel - single numeric logical. Default is 1, to use the sobel gradient transformation of the movie array to select edge pixels within the brain that will be used to determine otsu's threshold for signal detection in the movie and resulting segmentation.
%
% Check the workflow sequence below at wholeBrain_workflow(). Briefly it is:
% 1. Segmentation
% 2. Detection
% 3. Format domain data structures
% 4. Get active fraction signals
% 5. Get correlation matrix and plots
% 6. Get cortical - motor corr results and plots
% 7. Get spatial correlation results and plots
% 8. Make contour activity maps
% 9. Batch fetch datasets
%
%Output:
%Everything is automatically saved.
% * A list of processed .mat files with data structures will be saved at filesOutput_*YYYYMMDD-HHMMSS*.txt.
% * A bunch of .png and .eps figures will be automatically saved with [fnm *YYYYMMDD-HHMMSS*] format.
% * Output data from batchFetch* functions will be appended to:
% * 'dDomainProps.txt'
% * 'dLocationProps.txt'
% * 'dLocationPropsFreq.txt'
% * 'dCorr.txt'
% * 'dMotorCorr.txt'
% * 'dSpatialCorr.txt'
%
% See also wholeBrain_segmentation.m, wholeBrain_detect.m, wholeBrain_workflow.md
%
%James B. Ackman, 2013-11-19 12:06:20
% Except where otherwise noted, all code in this program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
% You should have received a copy of the GNU General Public License along
% with this program; if not, write to the Free Software Foundation, Inc.,
% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
if nargin < 2 || isempty(handles), handles = []; end
filelist = readtext(filename,' ');
datafilename = ['filesOutput_' datestr(now,'yyyymmdd-HHMMSS') '.txt'];
mainfcnLoop(filelist,datafilename,handles)
function mainfcnLoop(filelist,datafilename,handles)
%start loop through files-----------------------------------------------------------------
if size(filelist,2) > 1
fnms = filelist(:,2); %Second column is dummy region matfiles
fnms2 = filelist(:,1); %First column is the original .tif filename
else
error('TIFF movie filename required in 1st column, region dummy filename required in 2rd column of space-delimited filelist')
end
currdir = pwd; %This assumes that the script calling wholeBrain_batch has already cd'd into the flat directory containing both .tif movie files and dummy .mat files
%Otherwise this currdir can be changed within this mainfcnloop and the paths to the files for loading .mat and .tif files ('f' and 'fn' below inside 'mainfcnloop') can be changed
if isfield(handles,'dirname')
dirname = handles.dirname;
else
dirname = datestr(now,'yyyy-mm-dd-HHMMSS');
end
if exist(fullfile(currdir,dirname),'dir') ~= 7
%If the directory does not exist locally, create it.
mkdir(dirname);
end
cd(dirname);
levels = zeros(1,numel(fnms));
for j=1:numel(fnms)
[pathstr, name, ext] = fileparts(fnms{j});
matfilename = [name ext];
f = fullfile(currdir,matfilename);
load(f,'region'); %load the dummy file at fnms{j} containing parcellations, motor signal, etc
[pathstr, name, ext] = fileparts(fnms2{j});
region.filename = [name ext]; %set the .tif file name
region.matfilename = matfilename;
fn = fullfile(currdir,region.filename);
sprintf(fnms{j})
disp('--------------------------------------------------------------------')
disp(['Processing ' num2str(j) '/' num2str(numel(fnms)) ' files...'])
makeThresh = 1;
ind = detectDrugStimuli(region)
if ~isempty(ind)
makeThresh = 0;
region.graythresh = mean(levels);
end
handles.makeThresh = makeThresh;
[fnm,thresh] = wholeBrain_workflow(fn,region,handles);
levels(1,j) = thresh;
appendCellArray2file(datafilename,{fnm})
close all
end
function ind = detectDrugStimuli(region,stimuliIndices)
if nargin < 2 || isempty(stimuliIndices), stimuliIndices = {'drug.state.control' 'drug.state.isoflurane'}; end
if isfield(region,'stimuli');
ind = [];
for i = 1:length(region.stimuli)
for k = 1:length(stimuliIndices)
if strcmp(region.stimuli{i}.description,stimuliIndices{k})
ind = [ind i];
end
end
end
else
ind = [];
end
function appendCellArray2file(filename,output)
%---Generic output function-------------
tmp=output;
fid = fopen(filename,'a');
for i=1:numel(tmp); tmp{i} = num2str(tmp{i}); end %this will be to 4 decimal points (defaut for 'format short'). Can switch to 'format long' before running this loop if need more precision.
tmp2=tmp';
fprintf(fid,[repmat('%s\t',1,size(tmp2,1)-1),'%s\n'],tmp2{:}); %tab delimited
%fprintf(fid,[repmat('%s ',1,size(tmp2,1)-1),'%s\n'],tmp2{:}); %space delimited
fclose(fid);
function [fnm,thresh] = wholeBrain_workflow(fnm,region,handles)
%==1==Segmentation============================
%fnm = '120518_07.tif';
%load('120518_07_dummyHemis2.mat');
fn = fnm; %fullfile path to the .tif file, for passing to wholeBrain_segmentation for opening. All other output saved to local subdirectory
fnm = region.filename; %set the base .tif file name for making fnm2 filenames below for saving outputs.
if ~isfield(handles,'hemisphereIndices')
hemisphereIndices = find(strcmp(region.name,'cortex.L') | strcmp(region.name,'cortex.R') | strcmp(region.name,'OB.L') | strcmp(region.name,'OB.R') | strcmp(region.name,'SC.L') | strcmp(region.name,'SC.R')); %region.coord locations of 'cortex.L' and 'cortex.R' and others.
else
hemisphereIndices = handles.hemisphereIndices;
end
if ~isfield(handles,'backgroundRemovRadius')
backgroundRemovRadius = round(681/region.spaceres); % default is 681 µm radius for the circular structured element used for background subtraction.
else
backgroundRemovRadius = handles.backgroundRemovRadius;
end
if ~isfield(handles,'makeMovies'),
makeMovies = 'all';
else
makeMovies = handles.makeMovies;
end
if ~isfield(handles,'pthr'),
pthr = 0.99;
else
pthr = handles.pthr;
end
if ~isfield(handles,'sigma')
sigma = 56.75/region.spaceres; %sigma is the standard deviation in pixels of the gaussian for smoothing. It is 56.75µm at 11.35µm/px dimensions to give a **5px sigma**. gaussSmooth.m multiplies the sigma by 2.25 standard deviations for the filter size by default.
else
sigma = handles.sigma;
end
if ~isfield(handles,'useSobel')
useSobel = 1; %sigma is the standard deviation in pixels of the gaussian for smoothing. It is 56.75µm at 11.35µm/px dimensions to give a **5px sigma**. gaussSmooth.m multiplies the sigma by 2.25 standard deviations for the filter size by default.
else
useSobel = handles.useSobel;
end
if ~isfield(handles,'makeThresh'),
makeThresh = 1;
else
makeThresh = handles.makeThresh;
end
switch makeThresh
case 1
grayThresh = [];
case 0
%grayThresh = region.graythresh;
grayThresh = [];
end
switch makeMovies
case 'all'
makeInitMovies = 1;
case 'some'
makeInitMovies = 0;
case 'none'
makeInitMovies = 0;
end
if ~isfield(handles,'thresh'),
thresh = 2;
else
thresh = handles.thresh;
end
if isfield(handles, 'mov'),
preload = 1;
else
preload = 0;
end
if preload
if ~isempty(handles.mov)
[A2, A, thresh, Amin, Amax] = wholeBrain_segmentation(fn,handles.mov,region,thresh,sigma,hemisphereIndices,makeInitMovies);
else
error('handles.mov is empty')
end
else
[A2, A, thresh, Amin, Amax] = wholeBrain_segmentationOtsu(fn,backgroundRemovRadius,region,hemisphereIndices,0,makeInitMovies,grayThresh,pthr,sigma,useSobel);
end
region.graythresh = thresh;
region.Amin = Amin;
region.Amax = Amax;
disp(['Segmentation finished: ' datestr(now,'yyyymmdd-HHMMSS')])
%==2==Detection============================
[A3, CC, STATS] = wholeBrain_detect(A2,A,[4 3],makeInitMovies,fnm,region,hemisphereIndices);
fnm2 = [fnm(1:length(fnm)-4) '_' datestr(now,'yyyymmdd-HHMMSS') '.mat'];
save([fnm2(1:length(fnm2)-4) '_connComponents' '.mat'],'A2','A3','CC','STATS','-v7.3');
clear A2 A3;
disp(['Detection finished: ' datestr(now,'yyyymmdd-HHMMSS')])
%rsync -av -e ssh [email protected]:~/data/120518i/120518_09....mat ~/Desktop
%==3==Format domain data structures============================
domains = DomainSegmentationAssignment(CC,STATS, 'false');
region.domainData.domains = domains;
region.domainData.CC = CC;
region.domainData.STATS = STATS;
clear CC STATS domains;
if ~isfield(region.domainData.STATS, 'descriptor')
for i = 1:length(region.domainData.STATS)
region.domainData.STATS(i).descriptor = '';
end
end
if isfield(region, 'taggedCentrBorders')
region = tagDomains(region, region.taggedCentrBorders, 'artifact');
end
locationIndices = find(~strcmp(region.name,'field') & ~strcmp(region.name,'craniotomy')); %because region.location may be empty to this point (usually gets tagged only as a lut for cells are grid rois)
region = Domains2region(region.domainData.domains, region.domainData.CC,region.domainData.STATS,region,locationIndices);
fnm = fnm2;
fnm = [fnm(1:end-4) '_d2r' '.mat'];
save(fnm,'region','-v7.3');
disp(['Domain assignment finished: ' datestr(now,'yyyymmdd-HHMMSS')])
%==4==Get active fraction signals=============================
sz=region.domainData.CC.ImageSize;
A3 = false(sz);
for i = 1:region.domainData.CC.NumObjects
if ~strcmp(region.domainData.STATS(i).descriptor, 'artifact')
A3(region.domainData.CC.PixelIdxList{i}) = true;
end
end
if isfield(region, 'taggedCentrBorders') && (strcmp(makeMovies,'all') | strcmp(makeMovies,'some'))
myMovie2avi(A3,fnm)
end
data = wholeBrain_activeFraction(A3,region);
region.locationData.data = data; clear data
save(fnm,'region','-v7.3');
disp('-----')
wholeBrain_activeFraction(A3,region,hemisphereIndices,'drug.state.isoflurane'); %Print just the gross anatomical hemisphereIndices traces instead of all locations
fnm2 = [fnm(1:end-4) 'actvFraction' datestr(now,'yyyymmdd-HHMMSS') '.mat'];
print(gcf, '-dpng', [fnm2(1:end-4) '-' datestr(now,'yyyymmdd-HHMMSS') '.png']);
print(gcf, '-depsc', [fnm2(1:end-4) '-' datestr(now,'yyyymmdd-HHMMSS') '.eps']);
disp(['Active fraction finished: ' datestr(now,'yyyymmdd-HHMMSS')])
%==5==More Plots=========================
%--Single contour activity map-----
wholeBrainActivityMapFig(region,[],2,1,20,[],[],'pixelFreq');
fnm2 = [fnm(1:end-4) 'ActivityMapFigContour' datestr(now,'yyyymmdd-HHMMSS') '.mat'];
print(gcf, '-dpng', [fnm2(1:end-4) '.png']);
print(gcf, '-depsc', [fnm2(1:end-4) '.eps']);
disp('complete: wholeBrainActivityMapFig, contour pixelFreq')
mapTypes = {'pixelFreq','domainFreq','domainDur','domainDiam','domainAmpl'}
for j =1:length(mapTypes)
wholeBrainActivityMapFig(region,[],2,1,0,[],[],mapTypes{j});
fnm2 = [fnm(1:end-4) 'ActivityMapFigRawProj' datestr(now,'yyyymmdd-HHMMSS') '_' mapTypes{j} '.mat'];
print(gcf, '-dpng', [fnm2(1:end-4) '.png']);
print(gcf, '-depsc', [fnm2(1:end-4) '.eps']);
disp(['complete: wholeBrainActivityMapFig, mapType=' mapTypes{j}])
end
%--Drug state contour activity maps if applicable
if isfield(region,'stimuli');
stimuliIndices = {'drug.state.control' 'drug.state.isoflurane'};
ind = detectDrugStimuli(region,stimuliIndices);
if ~isempty(ind)
wholeBrainActivityMapFig(region,[],2,5,20,ind);
fnm2 = [fnm(1:end-4) 'ActivityMapFigDrug' datestr(now,'yyyymmdd-HHMMSS') '.mat'];
print(gcf, '-dpng', [fnm2(1:end-4) '.png']);
print(gcf, '-depsc', [fnm2(1:end-4) '.eps']);
mapTypes = {'pixelFreq','domainFreq','domainDur','domainDiam','domainAmpl'}
for j =1:length(mapTypes)
wholeBrainActivityMapFig(region,[],2,7,0,ind,[],mapTypes{j});
fnm2 = [fnm(1:end-4) 'ActivityMapFigRawProjDrug' datestr(now,'yyyymmdd-HHMMSS') '_' mapTypes{j} '.mat'];
print(gcf, '-dpng', [fnm2(1:end-4) '.png']);
print(gcf, '-depsc', [fnm2(1:end-4) '.eps']);
disp(['complete: wholeBrainActivityMapFig, mapType=' mapTypes{j}])
end
end
%--Motor state contour activity maps if applicable
stimuliIndices = {'motor.state.active' 'motor.state.quiet'};
ind = detectDrugStimuli(region,stimuliIndices);
if ~isempty(ind)
wholeBrainActivityMapFig(region,[],2,5,20,ind);
fnm2 = [fnm(1:end-4) 'ActivityMapFigMotor' datestr(now,'yyyymmdd-HHMMSS') '.mat'];
print(gcf, '-dpng', [fnm2(1:end-4) '.png']);
print(gcf, '-depsc', [fnm2(1:end-4) '.eps']);
mapTypes = {'pixelFreq','domainFreq','domainDur','domainDiam','domainAmpl'}
for j =1:length(mapTypes)
wholeBrainActivityMapFig(region,[],2,7,0,ind,[],mapTypes{j});
fnm2 = [fnm(1:end-4) 'ActivityMapFigRawProjMotorState' datestr(now,'yyyymmdd-HHMMSS') '_' mapTypes{j} '.mat'];
print(gcf, '-dpng', [fnm2(1:end-4) '.png']);
print(gcf, '-depsc', [fnm2(1:end-4) '.eps']);
disp(['complete: wholeBrainActivityMapFig, mapType=' mapTypes{j}])
end
end
%--Motor onset activity maps if applicable
stimuliIndices = {'motor.onsets'};
ind = detectDrugStimuli(region,stimuliIndices);
if ~isempty(ind)
mapTypes = {'domainFreq','domainDur','domainDiam'}
for j =1:length(mapTypes)
wholeBrainActivityMapFig(region,[],2,7,0,ind,[],mapTypes{j});
fnm2 = [fnm(1:end-4) 'ActivityMapFigRawProjMotorOnsets' datestr(now,'yyyymmdd-HHMMSS') '_' mapTypes{j} '.mat'];
print(gcf, '-dpng', [fnm2(1:end-4) '.png']);
print(gcf, '-depsc', [fnm2(1:end-4) '.eps']);
disp(['complete: wholeBrainActivityMapFig, mapType=' mapTypes{j}])
end
end
end
%}
%DomainPatchesPlot(region.domainData.domains, region.domainData.CC, region.domainData.STATS,1,[],1) %DomainPatchesPlot won't work on a linux server because of a segmentation fault with drawing alpha transparency in matlab
%fnm2 = [fnm(1:end-4) 'DomainPatchesPlot' datestr(now,'yyyymmdd-HHMMSS') '.mat'];
%print(gcf, '-dpng', [fnm2(1:end-4) '.png']);
%print(gcf, '-depsc', [fnm2(1:end-4) '.eps']);
%--Maximum intensity projections of movie--
%-------Make movie array with with raw intensity values within the functional ROIs--------
A4 = A;
A4(~A3) = 0; %A3 is binary movie from above with any 'artifact' tagged domains removed (usually none on first batch analysis pass)
%A4=mat2gray(A4);
bw = max(A3,[],3);
%----Maxproj of detected domains -----
A5 = max(A4,[],3);
tmp = A5(bw);
LOW_HIGH = stretchlim(tmp);
%A6 = imadjust(A5,LOW_HIGH,[]);
A6 = mat2gray(A5);
figure;
imagesc(A6); title('maxproj of raw detected domains array'); colorbar('location','eastoutside'); axis image
fnm2 = [fnm(1:length(fnm)-4) '_maxProj1_' datestr(now,'yyyymmdd-HHMMSS')];
print('-dpng', [fnm2 '.png'])
print('-depsc', [fnm2 '.eps'])
%----Maxproj of raw dFoF array -----
A5 = max(A,[],3);
%A6 = imadjust(A5,LOW_HIGH,[]);
A6 = mat2gray(A5);
figure;
imagesc(A6); title('maxproj of dFoF movie array detected adjust'); colorbar('location','eastoutside'); axis image
fnm2 = [fnm(1:length(fnm)-4) '_maxProj2_' datestr(now,'yyyymmdd-HHMMSS')];
print('-dpng', [fnm2 '.png'])
print('-depsc', [fnm2 '.eps'])
%----Maxproj of raw dFoF array -----
figure;
%A6 = imadjust(A5);
A6 = mat2gray(A5);
imagesc(A6); title('maxproj of dFoF movie array raw adjust'); colorbar('location','eastoutside'); axis image
fnm2 = [fnm(1:length(fnm)-4) '_maxProj3_' datestr(now,'yyyymmdd-HHMMSS')];
print('-dpng', [fnm2 '.png'])
print('-depsc', [fnm2 '.eps'])
clear A A4 A5 A6;
disp(['Maps finished: ' datestr(now,'yyyymmdd-HHMMSS')])
%==6==Get opticflow==============================
%TODO: change optFlowLk usage to newer opticalFlow.m in piotrImageVideoProcessingToolbox
chkFile = exist('optFlowLk.m');
if chkFile == 2
[Vsum, ~, ~] = wholeBrain_opticFlowByDomain(A3,region,fnm,makeInitMovies);
region.domainData.Vsum = Vsum;
clear Vsum
else
disp('Skipping opticflow...optFlowLk from piotrImageVideoProcessingToolbox v.2.61 not installed')
end
%==7==Batch fetch datasets=======================
batchFetchDomainProps({fnm},region,fullfile(pwd,'dDomainProps.txt'));
batchFetchLocationProps({fnm},region,fullfile(pwd,'dLocationProps.txt'), 'true', {'motor.state.active' 'motor.state.quiet' 'drug.state.control' 'drug.state.isoflurane'});
batchFetchLocationPropsFreq({fnm},region,fullfile(pwd,'dLocationPropsFreq.txt'), 'true', {'motor.state.active' 'motor.state.quiet' 'drug.state.control' 'drug.state.isoflurane'});
%}
disp(['All batch fetch domains, location finished: ' datestr(now,'yyyymmdd-HHMMSS')])
%==8==Get spatial correlation results and plots==============
region = wholeBrain_SpatialCOMCorr(fnm,region,{'cortex.L' 'cortex.R'},1);
batchFetchSpatialCOMCorrData({fnm},region,fullfile(pwd,'dCorticalCorr.txt'),1);
%==9==Get temporal correlation results and plots for cortical hemispheres=================
region = wholeBrain_CorticalActiveFractionCorr(fnm,region,{'cortex.L' 'cortex.R'});
batchFetchCorticalCorrData({fnm},region,fullfile(pwd,'dCorticalCorr.txt'),1);
save(fnm,'region','-v7.3') ;
%===If region contains coords for more than just 'field', 'cortex.L', and 'cortex.R' proceed to fetch data and plots making use of these parcellations (functional correlation matrices, motor corr, etc)
if length(region.name) > length(hemisphereIndices)+1
%==10==Get correlation matrix and plots========================
exclude = {'cortex.L' 'cortex.R'};
region = wholeBrain_corrData(fnm, region, exclude); %will also print and save corr matrix and raster plot of the traces (activeFraction) that went into the corr matrix
save(fnm,'region','-v7.3') ;
batchFetchCorrData({fnm},region,fullfile(pwd,'dCorr.txt'),1);
%==11==Get cortical - motor corr results and plots=============
if isfield(region,'motorSignal')
if ~isempty(region.motorSignal)
clear st
st(1).str = {'HL.L' 'HL.R' 'T.L' 'T.R' 'FL.L' 'FL.R'};
st(2).str = {'M1.L' 'M1.R' 'M2.L' 'M2.R'};
st(3).str = {'barrel.L' 'barrel.R' 'AS.L' 'AS.R'};
st(4).str = {'barrel.L' 'barrel.R'};
st(5).str = {'RSA.L' 'RSA.R'};
st(6).str = {'PPC.L' 'PPC.R'};
st(7).str = {'V1.L' 'V1.R'};
st(8).str = {'V2L.L' 'V2L.R' 'V2M.L' 'V2M.R'};
st(9).str = {'V2L.L' 'V2L.R' 'V2M.L' 'V2M.R' 'V1.L' 'V1.R'};
st(10).str = {'cortex.L' 'cortex.R'};
st(11).str = {'OB.L' 'OB.R'};
st(12).str = {'SC.L' 'SC.R'};
region = wholeBrain_MotorSignalCorr(fnm,region,st,[],1);
save(fnm,'region','-v7.3') ;
batchFetchMotorCorrData({fnm},region,fullfile(pwd,'dMotorCorr.txt'),1);
end
end
else
if isfield(region,'motorSignal')
if ~isempty(region.motorSignal)
st(1).str = {'cortex.L' 'cortex.R'};
region = wholeBrain_MotorSignalCorr(fnm,region,st,[],1);
save(fnm,'region','-v7.3') ;
batchFetchMotorCorrData({fnm},region,fullfile(pwd,'dMotorCorr.txt'),1);
end
end
end
disp(['Batch finished: ' datestr(now,'yyyymmdd-HHMMSS')])
close all
clear region