-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathROI3DTraceCheck.m
107 lines (87 loc) · 4.71 KB
/
ROI3DTraceCheck.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
% Loop through the ROI3DWithTraceTable of one session and check the calcium trace of each 3DROI
ROI3DNum = max(ROI3DWithTraceTable.ROI3DIdx);
ROIRegisteredNumber = zeros(ROI3DNum,1); % the matrix to save the registered status
ROIRegisteredStatus = zeros(ROI3DNum,1);
sessionNum = questdlg('Which session of data you want to check:','session check',...
'session1','session2','session3','session1'); %choose the session to check
sessionStr = append('registered_trace_',sessionNum); %create the session string
commonX = 1:1000; %only plot the first 1000 frames
for i = 91:ROI3DNum % loop through the 3DROI table
close(gcf)
tempStruct = ROI3DWithTraceTable.(sessionStr)(i); %check registered session2 trace 24.10.31
f = figure('units','normalized','outerposition',[0 0.5 0.5 0.5]); %show the new figure at left up corner
legendStr = {}; %pre assign the empty legend string
tempCount = 0; %counter of the imaging planes with calcium trace
for j = 1:8 % loop through all the imaging planes
tempFieldStr = append('Z',num2str(j-1));
tempValue = cell2mat(tempStruct.(tempFieldStr));
if ~isempty(tempValue)
tempCount = tempCount + 1;
ROIRegisteredNumber(i) = ROIRegisteredNumber(i) + 1; % if there are registered values
hold on
plot(commonX,tempValue(1:1000)+(80-j*10))
legendStr{end+1} = tempFieldStr; % add the legend string
end
end
%add the scale bar and change the info of axes
xlabel('Time (s)');
xlim([0 1000]);
ylabel('Deconv F (a.u.)');
ylim([-10 inf])
timeScale = 20 * 2.2; %scale bar of time: 10 seconds * frequency
ampScale = 10; %scale bar of amplitude: 5 a.u.
xPos = commonX(end) - timeScale - 5; %start point of time scale
yPos = ampScale; %amp scale start from 0
plot([xPos, xPos + timeScale],[yPos-10, yPos-10],'k','LineWidth',1);
text(xPos + timeScale/2, yPos - 12, [num2str(timeScale/2.2),' s'],...
'HorizontalAlignment','center'); %plot time scale bar
plot([xPos + timeScale, xPos + timeScale],[yPos - 10, yPos - 10 + ampScale],'k','LineWidth',1);
text(xPos + timeScale + 10, yPos - 10 + ampScale/2,[num2str(ampScale),' a.u.'],...
'HorizontalAlignment','center','Rotation',90);
axis off
legend(legendStr,'FontSize',12,'Location','best'); %avoid blocking the plotting area
titleStr = append('ROI #',num2str(i));
title(titleStr,'FontSize',20);
hold off
saveStr = append(titleStr,'.png');
saveas(f,saveStr)
if tempCount == 0
ROIRegisteredStatus(i) = 0; %not registered to any planes
ROI3DWithTraceTable.(sessionStr)(i).selected = []; %11.1 add the selected field to the struct,when segmentation, only use the .selected field
elseif tempCount == 1
ROIRegisteredStatus(i) = 1; %registered to one plane
ROI3DWithTraceTable.(sessionStr)(i).selected = ROI3DWithTraceTable.(sessionStr)(i).(legendStr{1}); %give the .selected field with the only field with value
elseif tempCount >= 2
tempAnswer2 = questdlg('matched or unmatched?', ...
titleStr, ...
'unmatched', ...
'partially matched', ...
'ALL MATCHED', ...
'unmatched');
switch tempAnswer2
case 'unmatched'
ROIRegisteredStatus(i) = 2; %2: unmatched multiple planes
case 'partially matched'
ROIRegisteredStatus(i) = 3; %3: partially matched planes
case 'ALL MATCHED'
ROIRegisteredStatus(i) = 4; %4: all matched planes
end
[indx,tf] = listdlg('PromptString',{'Select the plane represent this 3D-ROI'},...
'ListString',legendStr,'SelectionMode','single',...
'ListSize',[500 300]); %use the fields with value to create a list dialog box
if tf
ROI3DWithTraceTable.(sessionStr)(i).selected = ROI3DWithTraceTable.(sessionStr)(i).(legendStr{indx});
end
end
tempAnswer3 = questdlg('Move to the next ROI?', ...
'NEXT', ...
'Next ROI', ...
'Stop the program', ...
'Next ROI');
switch tempAnswer3
case 'Next ROI'
continue
case 'Stop the program'
break
end
end