-
Notifications
You must be signed in to change notification settings - Fork 9
/
YuabExtentAnalysis.m
173 lines (150 loc) · 7.27 KB
/
YuabExtentAnalysis.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
function YuabExtentAnalysis(parentHandles, parentFigureName)
% Copyright (C) 2013-2014 University of Dundee & Open Microscopy Environment.
% All rights reserved.
%
% 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.
imageIds = getappdata(parentHandles.(parentFigureName), 'imageIds');
imageNames = getappdata(parentHandles.(parentFigureName), 'imageNames');
roiShapes = getappdata(parentHandles.(parentFigureName), 'roiShapes');
channelLabels = getappdata(parentHandles.(parentFigureName), 'channelLabels');
pixels = getappdata(parentHandles.(parentFigureName), 'pixels');
datasetNames = getappdata(parentHandles.(parentFigureName), 'datasetNames');
numImages = length(imageIds);
progress = waitbar(0,'Analysing image...');
for thisImage = 1:numImages
waitbar(thisImage/numImages, progress, ['Downloading image... ' num2str(thisImage) ' of ' num2str(numImages)])
thisPixels = pixels{thisImage};
numX = thisPixels.getSizeX.getValue;
numY = thisPixels.getSizeY.getValue;
numShapes = roiShapes{thisImage}{1}.numShapes;
zStart = roiShapes{thisImage}{1}.shape1.getTheZ.getValue;
zEnd = roiShapes{thisImage}{1}.(['shape' num2str(numShapes)]).getTheZ.getValue;
ROIZ = (zStart:zEnd);
numROIZ = length(ROIZ);
%Get the green image data from the ROI z-sections...
greenStack = zeros(numY, numX, numROIZ);
for thisZ = 1:numROIZ
greenStack(:,:,thisZ) = getPlaneFromPixelsId(thisPixels.getId.getValue, ROIZ(thisZ), 0, 0);
end
%Now segment the cells...
greenSeg = seg3D(greenStack, 0, 1, 50);
%[greenSignalStart greenExtent] = zExtent(greenSeg, thisPixels);
%Get the red image data from the ROI z-sections...
redStack = zeros(numY, numX, numROIZ);
for thisZ = 1:numROIZ
redStack(:,:,thisZ) = getPlaneFromPixelsId(thisPixels.getId.getValue, ROIZ(thisZ), 1, 0);
end
%Now segment the YuaB staining...
waitbar(thisImage/numImages, progress, ['Analysing image... ' num2str(thisImage) ' of ' num2str(numImages)])
redSeg = seg3D(redStack, 0, 1, 50);
%[redSignalStart redExtent] = zExtent(redSeg, thisPixels);
% %Find the pixel-stacks the don't have YuaB or cells...
% NaNCheck = ones(numY, numX);
% NaNCheck(redSignalStart==0 & greenSignalStart == 0) = nan;
% greenSignalStart = greenSignalStart .* NaNCheck;
% greenExtent = greenExtent .* NaNCheck;
% redSignalStart = redSignalStart .* NaNCheck;
% redExtent = redExtent .* NaNCheck;
%
% greenSignalStartMean(thisImage) = nanmean(reshape(greenSignalStart, [], 1));
% greenSignalStartStd(thisImage) = nanstd(reshape(greenSignalStart, [], 1));
% greenExtentMean(thisImage) = nanmean(reshape(greenExtent, [], 1));
% greenExtentStd(thisImage) = nanstd(reshape(greenExtent, [], 1));
%
% redSignalStartMean(thisImage) = nanmean(reshape(redSignalStart, [], 1));
% redSignalStartStd(thisImage) = nanstd(reshape(redSignalStart, [], 1));
% redExtentMean(thisImage) = nanmean(reshape(redExtent, [], 1));
% redExtentStd(thisImage) = nanstd(reshape(redExtent, [], 1));
%Count the positive pixels per Z in each stack...
[greenPos{thisImage} redPos{thisImage} greenStartZ(thisImage)] = pixelCountPerZ(greenSeg, redSeg, numROIZ);
maxROIZ(thisImage) = numROIZ;
[val idx] = max(redPos{thisImage});
% redIntensity = redStack(:,:,idx);
% redSeg1Z = redSeg(:,:,idx);
redIntensity = redStack(:,:,greenStartZ(thisImage));
redSeg1Z = redSeg(:,:,greenStartZ(thisImage));
redIntensityLinear = redIntensity(redSeg1Z == 1);
redIntensitySummary{thisImage,1} = imageIds(thisImage);
redIntensitySummary{thisImage,2} = mean(redIntensityLinear);
redIntensitySummary{thisImage,3} = std(redIntensityLinear);
redIntensitySummary{thisImage,4} = length(redIntensityLinear);
redIntensitySummary{thisImage,5} = idx;
redIntensitySummary{thisImage,6} = datasetNames{thisImage};
end
maxGreenStartZ = max(greenStartZ);
minGreenStartZ = min(greenStartZ);
maxROIZ = max(maxROIZ);
maxPosSize = maxROIZ - minGreenStartZ + 1;
maxNegSize = maxGreenStartZ -1;
greenPosMatrix = zeros(maxPosSize, numImages+1);
greenPosMatrix(:,:) = nan;
redPosMatrix = zeros(maxPosSize, numImages+1);
redPosMatrix(:,:) = nan;
greenNegMatrix = zeros(maxNegSize, numImages+1);
greenNegMatrix(:,:) = nan;
redNegMatrix = zeros(maxNegSize, numImages+1);
redNegMatrix(:,:) = nan;
for thisImage = 1:numImages
posCounter = 1;
[posSizeThisImage ~] = size(greenPos{thisImage});
for thisPos = greenStartZ(thisImage):posSizeThisImage
greenPosMatrix(posCounter, thisImage+1) = greenPos{thisImage}(thisPos);
redPosMatrix(posCounter, thisImage+1) = redPos{thisImage}(thisPos);
posCounter = posCounter + 1;
end
negCounter = maxNegSize;
maxNegThisImage = greenStartZ(thisImage) - 1;
for thisNeg = maxNegThisImage:-1:1
greenNegMatrix(negCounter, thisImage+1) = greenPos{thisImage}(thisNeg);
redNegMatrix(negCounter, thisImage+1) = redPos{thisImage}(thisNeg);
negCounter = negCounter - 1;
end
end
greenMatrix = [greenNegMatrix; greenPosMatrix];
redMatrix = [redNegMatrix; redPosMatrix];
numRows = maxPosSize + maxNegSize;
rowCounter = 1;
for thisRow = numRows:-1:1
greenMatrix(thisRow, 1) = maxPosSize - rowCounter;
redMatrix(thisRow, 1) = maxPosSize - rowCounter;
rowCounter = rowCounter + 1;
end
disp('hi');
%
% minStart = maxGreenStartZ-1 - maxGreenStartZ;
% minStartCounter = minStart;
% greenCounts = zeros(maxROIZ, numImages+1);
% redCounts = zeros(maxROIZ, numImages+1);
%
% for thisROIZ = 1:maxROIZ
% greenCount(thisROIZ,1) = minStartCounter;
% redCount(thisROIZ,1) = minStartCounter;
% for thisImage = 1:numImages
% minStartThisImage = minStart - greenStartZ(thisImage);
% end
% minStart = minStartCounter+1;
% end
setappdata(parentHandles.(parentFigureName), 'greenMatrix', greenMatrix);
setappdata(parentHandles.(parentFigureName), 'redMatrix', redMatrix);
%setappdata(parentHandles.(parentFigureName), 'greenStartZ', greenStartZ);
close(progress);
% setappdata(parentHandles.(parentFigureName), 'greenSignalStartMean', greenSignalStartMean);
% setappdata(parentHandles.(parentFigureName), 'greenSignalStartStd', greenSignalStartStd);
% setappdata(parentHandles.(parentFigureName), 'greenExtentMean', greenExtentMean);
% setappdata(parentHandles.(parentFigureName), 'greenExtentStd', greenExtentStd);
% setappdata(parentHandles.(parentFigureName), 'redSignalStartMean', redSignalStartMean);
% setappdata(parentHandles.(parentFigureName), 'redSignalStartStd', redSignalStartStd);
% setappdata(parentHandles.(parentFigureName), 'redExtentMean', redExtentMean);
% setappdata(parentHandles.(parentFigureName), 'redExtentStd', redExtentStd);