-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract_time_trace_mp_template.m
115 lines (100 loc) · 3.58 KB
/
extract_time_trace_mp_template.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
%% Add path
addpath('../../neuRoi')
%% Clear variables
clear all
close all
%%
% Step01 Load experiment configuration from file
expName = '20221026_NT0012_f3_13dpf_testNTvsRModors';
resultDir = fullfile(pwd,'results');
expFilePath = fullfile(resultDir,sprintf('experimentConfig_%s.mat',expName));
foo = load(expFilePath);
myexp = foo.myexp;
nTrials = length(myexp.rawFileList);
disp(myexp.expInfo)
%% Step02 (optional) Sepcify options for opening a trial
myexp.roiDir = myexp.getDefaultDir('roi');
myexp.loadFileType = 'binned';
myexp.trialOptionRaw = struct('process',true,...
'noSignalWindow',[1 6],...
'intensityOffset',-30);
myexp.trialOptionBinned = struct('process',false,...
'noSignalWindow',[],...
'intensityOffset',-10);
myexp.responseOption = struct('offset',-10,...
'fZeroWindow',[1 9],...
'responseWindow',[12 20]);
myexp.responseMaxOption = struct('offset',-10,...
'fZeroWindow',[3 7],...
'slidingWindowSize',5);
myexp.mapsAfterLoading = {'response','responseMax'};
% myexp.mapsAfterLoading = {};
myexp.alignToTemplate = false;
%% Step03 Open neuRoi GUI
myexp.planeNum = 2;
myexp.mapsAfterLoading = {'response'};
mycon = NrController(myexp);
%% Add local correlation (optional)
mapType = 'localCorrelation';
mapOption = struct('tileSize',32);
trial = myexp.getCurrentTrial();
trial.calculateAndAddNewMap(mapType,mapOption);
%% Copy ROI
trial = myexp.getCurrentTrial();
idx = trial.findRoiByTag(trial.selectedRoiTagArray(1))
roiClipboard = trial.roiArray(idx)
%% Paste ROI
trial = myexp.getCurrentTrial();
trial.addRoi(roiClipboard);
%% Remove very small ROIs generated by false clicking
%% Delete point ROIs
%% Delete ROIs with only one point
% Get current trial
trial = myexp.getCurrentTrial();
roiArray = trial.roiArray;
deleteTagArray = {};
for k = 1:length(roiArray)
roi = roiArray(k);
if size(roi.position,1)<2
deleteTagArray{end+1} = roi.tag;
end
end
% Delete point ROIs
for k=1:length(deleteTagArray)
tag = deleteTagArray{k};
trial.deleteRoi(tag);
end
%% Step04 Extract time trace with template ROI in all trials
% Apply template ROI map and correct ROIs in each trial
% If you accidentally closed the GUI, the following code might
% throw an error. In that case, just run Step01, then continue with
% Step04
for planeNum = 1
myexp.alignToTemplate = false;
myexp.trialOptionRaw = struct('process',true,...
'noSignalWindow',[1 6]);
fileIdxList = 1:nTrials;
% planeNum = myexp.planeNum;
prefix = '';
appendix = '';
load(strcat(resultDir,'\BUnwarpj\','plane0',num2str(planeNum),'\',strcat(prefix,'Rois',appendix,'.mat')));
roiFileList=squeeze(struct2cell(RoiArray))';
plotTrace = true;
myexp.extractTimeTraceBatch(fileIdxList, ...
roiFileList,planeNum, ...
plotTrace);
end
% %% Save ROI tags and results directories for each roi to pool later
% planeString = NrModel.getPlaneString(myexp.planeNum);
% resultDirSave= fullfile(myexp.resultDir,'time_trace',planeString);
% expID = repmat(cellstr(resultDirSave),length(roiArray),1);
% for roiroi=1:length(roiArray)
% roiID {roiroi,1} = roiArray (roiroi).tag;
% end
%
%
% roiIDFilePath = fullfile(resultDirSave, ...
% 'roiID.mat');
% %save(roiIDFilePath,'roiID','expID','category')
% save(roiIDFilePath,'roiID','expID')
disp("****** done! ********")