forked from cortex-lab/Suite2P
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild_ops3.m
171 lines (142 loc) · 6.12 KB
/
build_ops3.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
function ops = build_ops3(db, ops)
ops.nplanes = getOr(ops, 'nplanes', 1);
ops.nchannels = getOr(ops, 'nchannels', 1);
ops = addfields(ops, db);
for k = 1:length(db.expts)
ops.SubDirs{k} = num2str(db.expts(k));
end
if ops.doRegistration
ops.RootDir = fullfile(ops.RootStorage, ops.mouse_name, ops.date);
else
ops.RootDir = fullfile(ops.RootStorage, ops.mouse_name, ops.date,'Corrected');
ops.RootDirRaw = fullfile(ops.RootStorage, ops.mouse_name, ops.date);
end
disp(ops.RootDir);
% build file list
ops.fsroot = [];
overview_ind = [];
for j = 1:ops.nplanes %length(ops.SubDirs) % changed on 16/11/25 by SK
ops.fsroot{j} = dir(fullfile(ops.RootDir,sprintf('*Slice%02d*.tif',j)));
if j==1
ops.rawMovies = dir(fullfile(ops.RootDirRaw,'FOV1_0*.tif'));
for k = 1:length(ops.rawMovies)
% Do not include overview image
if isfinite(strfind(ops.rawMovies(k).name,'overview'));
overview_ind = k;
end
end
if ~isempty(overview_ind)
pick_ind = (1:length(ops.rawMovies))~=overview_ind;
ops.rawMovies = ops.rawMovies(pick_ind);
end
end
% ops.fsroot{j} = dir(fullfile(ops.RootDir,sprintf('*Slice%02d*_File001.tif',j)));
for k = 1:length(ops.fsroot{j})
% Do not include overview image
if isempty(strfind(ops.fsroot{j}(k).name,'overview'));
ops.fsroot{j}(k).name = fullfile(ops.RootDir, ops.fsroot{j}(k).name);
else
ops.fsroot{j}(k).name = [];
end
end
% ops.fsroot{j} = ops.fsroot{j}(1:20); % select some fraction of files
end
try
% MK code for automatically determining number of planes and channels
[~, header] = loadFramesBuff(fullfile(ops.RootDirRaw,ops.rawMovies(1).name), 1, 1, 1);
% [~, header] = loadFramesBuff(ops.fsroot{1}(1).name, 1, 1, 1);
hh=header{1};
verStr = ['SI.VERSION_MAJOR = ',char(39),'2016b',char(39)];
if strfind(hh, verStr) % For scanimage 2016b, SF
str = hh(strfind(hh,'channelSave = '):end);
ind = strfind(str, 'SI');
ch = str2num(str(15 : ind(1)-1));
ops.nchannels = length(ch);
fastZEnable = sscanf(hh(strfind(hh,'hFastZ.enable = '):end), 'hFastZ.enable = %s');
fastZEnable = strcmp(fastZEnable,'true');
fastZDiscardFlybackFrames = sscanf(hh(strfind(hh, 'hFastZ.discardFlybackFrames = '):end), 'hFastZ.discardFlybackFrames = %s');
fastZDiscardFlybackFrames = strcmp(fastZDiscardFlybackFrames,'true');
stackNumSlices = sscanf(hh(strfind(hh, 'hStackManager.numSlices = '):end), 'hStackManager.numSlices = %d');
ops.nplanes = 1;
if fastZEnable
ops.nplanes = stackNumSlices+fastZDiscardFlybackFrames;
end
str = hh(strfind(hh, 'scanZoomFactor = '):end);
ind = strfind(str, 'SI');
ops.zoomMicro = str2double(str(18 : ind(1)-1));
ops.imageRate = sscanf(hh(strfind(hh, 'scanFrameRate = '):end), 'scanFrameRate = %f');
if isfield(db, 'expred') && ~isempty(db.expred) && ...
(~isfield(db, 'nchannels_red') || isempty(db.nchannels_red))
[~, header] = loadFramesBuff(ops.fsred(1).name, 1, 1, 1);
hh=header{1};
str = hh(strfind(hh, 'channelSave = '):end);
ind = strfind(str, 'SI');
ch = str2num(str(15 : ind(1)-1));
ops.nchannels_red = length(ch);
end
end
% Old scanimage
str = hh(strfind(hh, 'channelsSave = '):end);
ind = strfind(str, 'scanimage');
ch = str2num(str(16 : ind(1)-1));
ops.nchannels = length(ch);
fastZEnable = sscanf(hh(strfind(hh, 'fastZEnable = '):end), 'fastZEnable = %d');
fastZDiscardFlybackFrames = sscanf(hh(strfind(hh, 'fastZDiscardFlybackFrames = '):end), 'fastZDiscardFlybackFrames = %d');
if isempty(fastZDiscardFlybackFrames)
fastZDiscardFlybackFrames = 0;
end
stackNumSlices = sscanf(hh(strfind(hh, 'stackNumSlices = '):end), 'stackNumSlices = %d');
ops.nplanes = 1;
if fastZEnable
ops.nplanes = stackNumSlices+fastZDiscardFlybackFrames;
end
str = hh(strfind(hh, 'scanZoomFactor = '):end);
ind = strfind(str, 'scanimage');
ops.zoomMicro = str2double(str(18 : ind(1)-1));
ops.imageRate = sscanf(hh(strfind(hh, 'scanFrameRate = '):end), 'scanFrameRate = %f');
% get number of channels of red experiment
if isfield(db, 'expred') && ~isempty(db.expred) && ...
(~isfield(db, 'nchannels_red') || isempty(db.nchannels_red))
[~, header] = loadFramesBuff(ops.fsred(1).name, 1, 1, 1);
hh=header{1};
str = hh(strfind(hh, 'channelsSave = '):end);
ind = strfind(str, 'scanimage');
ch = str2num(str(16 : ind(1)-1));
ops.nchannels_red = length(ch);
end
catch
% for Scanimage 2015 -- extracting SI metadata SK 17/02/28
info = imfinfo(fullfile(ops.RootDirRaw,ops.rawMovies(1).name));
temp = info.Software;
ind = strfind(temp,'SI.');
temp(ind(2:end)-1) = ';';
temp(end) = ';';
eval(temp);
fZ = SI.hFastZ.enable;
ops.nchannels = length(SI.hChannels.channelSave);
if fZ
stackNumSlices = SI.hFastZ.numFramesPerVolume;
fastZDiscardFlybackFrames = SI.hFastZ.discardFlybackFrames;
ops.nplanes = stackNumSlices+fastZDiscardFlybackFrames;
else
stackNumSlices = 1;
ops.nplanes = 1;
end
ops.zoomMicro = SI.hRoiManager.scanZoomFactor;
end
if ~(isfield(ops, 'planesToProcess') && ~isempty(ops.planesToProcess))
% ops.planesToProcess = 1:ops.nplanes;
ops.planesToProcess = 1:stackNumSlices; % changed by SK 16/12/14
else
% planesToProcess is not working right now
ops.planesToProcess = 1:ops.nplanes;
end
CharSubDirs = '';
for i = 1:length(ops.SubDirs)
CharSubDirs = [CharSubDirs ops.SubDirs{i} '_'];
end
CharSubDirs = CharSubDirs(1:end-1);
ops.CharSubDirs = CharSubDirs;
ops.ResultsSavePath = sprintf('%s\\%s\\%s\\%s\\', ops.ResultsSavePath, ops.mouse_name, ops.date);
% ops.ResultsSavePath = sprintf('%s\\%s\\%s\\%s\\', ops.ResultsSavePath, ops.mouse_name, ops.date, CharSubDirs);
end