Skip to content

Commit 6be8e9a

Browse files
committed
latest version of livecellminer including statistics features
1 parent ca1f76f commit 6be8e9a

23 files changed

+1752
-72
lines changed

Source/callback_livecellminer_compute_additional_single_features.m

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
return;
3333
end
3434

35-
deltaT = 3;
35+
numFramesOrientation = 8; %% uses the last numFramesOrientation before MA to compute the sum of angles
36+
deltaT = 3; %% duration between two frames in minutes
3637

3738
%% initialize a new feature and add a new specifier
3839
d_org(:,end+1) = 0;
@@ -42,25 +43,29 @@
4243

4344
%% add the specifier for the new single feature
4445
if (size(d_org,2) == 1)
45-
dorgbez = char('IPToMALength_Frames', 'IPToMALength_Minutes', 'InterphaseMeanIntensity', 'AccumulatedOrientationDiffPMA');
46+
dorgbez = char('IPToMALength_Frames', 'IPToMALength_Minutes', 'InterphaseMeanIntensity', 'MeanOrientationDiffPMA');
4647
else
47-
dorgbez = char(dorgbez, 'IPToMALength_Frames', 'IPToMALength_Minutes', 'InterphaseMeanIntensity', 'AccumulatedOrientationDiffPMA');
48+
dorgbez = char(dorgbez, 'IPToMALength_Frames', 'IPToMALength_Minutes', 'InterphaseMeanIntensity', 'MeanOrientationDiffPMA');
4849
end
4950
IPToMALengthFramesIndex = callback_livecellminer_find_single_feature(dorgbez, 'IPToMALength_Frames');
5051
IPToMALengthMinutesIndex = callback_livecellminer_find_single_feature(dorgbez, 'IPToMALength_Minutes');
5152
InterphaseMeanIntensityIndex = callback_livecellminer_find_single_feature(dorgbez, 'InterphaseMeanIntensity');
52-
AccumulatedOrientationDiffPMAIndex = callback_livecellminer_find_single_feature(dorgbez, 'AccumulatedOrientationDiffPMA');
53+
MeanOrientationDiffPMAIndex = callback_livecellminer_find_single_feature(dorgbez, 'MeanOrientationDiffPMA');
5354

5455
%% compute the number of frames between the IP and MA transition
5556
for i=1:size(d_orgs,1)
5657
intIndices = find(d_orgs(i,:,syncFeatureIndex) == 1);
5758
pmaIndices = find(d_orgs(i,:,syncFeatureIndex) == 2);
5859
atiIndices = find(d_orgs(i,:,syncFeatureIndex) == 3);
5960

61+
if (isempty(intIndices) || isempty(pmaIndices) || isempty(atiIndices))
62+
continue;
63+
end
64+
6065
d_org(i, IPToMALengthFramesIndex) = length(pmaIndices);
6166
d_org(i, IPToMALengthMinutesIndex) = d_org(i, IPToMALengthFramesIndex) * deltaT;
6267
d_org(i, InterphaseMeanIntensityIndex) = mean(d_orgs(i, intIndices, meanIntensityFeatureIndex));
63-
d_org(i, AccumulatedOrientationDiffPMAIndex) = sum(abs(diff(d_orgs(i, pmaIndices, orientationFeatureIndex))));
68+
d_org(i, MeanOrientationDiffPMAIndex) = mean(abs(diff(d_orgs(i, pmaIndices, orientationFeatureIndex))));
6469
end
6570

6671
%% update the GUI for the new time series to show up
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
%%
2+
% LiveCellMiner.
3+
% Copyright (C) 2020 D. Moreno-Andres, A. Bhattacharyya, W. Antonin, J. Stegmaier
4+
%
5+
% Licensed under the Apache License, Version 2.0 (the "License");
6+
% you may not use this file except in compliance with the License.
7+
% You may obtain a copy of the Liceense at
8+
%
9+
% http://www.apache.org/licenses/LICENSE-2.0
10+
%
11+
% Unless required by applicable law or agreed to in writing, software
12+
% distributed under the License is distributed on an "AS IS" BASIS,
13+
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
% See the License for the specific language governing permissions and
15+
% limitations under the License.
16+
%
17+
% Please refer to the documentation for more information about the software
18+
% as well as for installation instructions.
19+
%
20+
% If you use this application for your work, please cite the repository and one
21+
% of the following publications:
22+
%
23+
% TBA
24+
%
25+
%%
26+
27+
function [resultHeatMap] = callback_livecellminer_compute_aligned_heatmap(d_orgs, validIndices, synchronizationIndex, featureIndex, parameter)
28+
29+
%% get the parameters from the GUI
30+
IPTransition = parameter.gui.livecellminer.IPTransition;
31+
MATransition = parameter.gui.livecellminer.MATransition;
32+
alignedLength = parameter.gui.livecellminer.alignedLength;
33+
timeRange = parameter.gui.zeitreihen.segment_start:parameter.gui.zeitreihen.segment_ende;
34+
alignPlots = parameter.gui.livecellminer.alignPlots;
35+
36+
%% create the current heat map
37+
if (alignPlots == false)
38+
resultHeatMap = zeros(length(validIndices), length(timeRange));
39+
for c=1:length(validIndices)
40+
resultHeatMap(c, :) = squeeze(d_orgs(validIndices(c), timeRange, featureIndex));
41+
end
42+
else
43+
resultHeatMap = nan(length(validIndices), alignedLength);
44+
for c=1:length(validIndices)
45+
currentStageTransitions = squeeze(d_orgs(validIndices(c), timeRange, synchronizationIndex));
46+
currentFeatureValues = squeeze(d_orgs(validIndices(c), timeRange, featureIndex));
47+
48+
indicesIP = find(currentStageTransitions == 1);
49+
indicesPM = find(currentStageTransitions == 2);
50+
indicesMA = find(currentStageTransitions == 3);
51+
52+
splitPoint = round(length(indicesPM) / 2);
53+
indicesPM1 = indicesPM(1:splitPoint);
54+
indicesPM2 = indicesPM((splitPoint+1):end);
55+
56+
%% fill the values in an aligned fashion
57+
resultHeatMap(c, (IPTransition-length(indicesIP)+1):IPTransition) = currentFeatureValues(indicesIP);
58+
59+
resultHeatMap(c, (IPTransition+1):(IPTransition+length(indicesPM1))) = currentFeatureValues(indicesPM1);
60+
resultHeatMap(c, (MATransition-length(indicesPM2)):(MATransition-1)) = currentFeatureValues(indicesPM2);
61+
62+
resultHeatMap(c, MATransition:(MATransition+length(indicesMA)-1)) = currentFeatureValues(indicesMA);
63+
end
64+
65+
%% trim the heat map in case any line exceeded the maximum length
66+
resultHeatMap = resultHeatMap(:, 1:alignedLength);
67+
end
68+
end
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
%%
2+
% LiveCellMiner.
3+
% Copyright (C) 2020 D. Moreno-Andres, A. Bhattacharyya, W. Antonin, J. Stegmaier
4+
%
5+
% Licensed under the Apache License, Version 2.0 (the "License");
6+
% you may not use this file except in compliance with the License.
7+
% You may obtain a copy of the Liceense at
8+
%
9+
% http://www.apache.org/licenses/LICENSE-2.0
10+
%
11+
% Unless required by applicable law or agreed to in writing, software
12+
% distributed under the License is distributed on an "AS IS" BASIS,
13+
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
% See the License for the specific language governing permissions and
15+
% limitations under the License.
16+
%
17+
% Please refer to the documentation for more information about the software
18+
% as well as for installation instructions.
19+
%
20+
% If you use this application for your work, please cite the repository and one
21+
% of the following publications:
22+
%
23+
% TBA
24+
%
25+
%%
26+
27+
28+
%% get the selected single features
29+
selectedFeatures = parameter.gui.merkmale_und_klassen.ind_em;
30+
selectedOutputVariable = parameter.gui.merkmale_und_klassen.ausgangsgroesse;
31+
32+
%% find the manual synchronization index
33+
synchronizationIndex = callback_livecellminer_find_time_series(var_bez, 'manualSynchronization');
34+
35+
%% get stage transitions
36+
if (synchronizationIndex > 0)
37+
confirmedTrack = squeeze(d_orgs(ind_auswahl, 1, synchronizationIndex)) > 0;
38+
else
39+
confirmedTrack = ones(size(ind_auswahl));
40+
end
41+
42+
%% retrieve the parameters and convert them to numbers
43+
significanceLevel = 3;
44+
45+
disp(['Computing Median Absolute Deviation (MAD) using a threshold of ' num2str(significanceLevel) '*MAD for hits.']);
46+
47+
%% perform selected test to all selected features independently for each of the output variables
48+
for f=selectedFeatures
49+
50+
%% get the selected output classes
51+
selectedOutputClasses = unique(code(ind_auswahl));
52+
numOutputClasses = length(selectedOutputClasses);
53+
54+
55+
%% open result files for writing
56+
outputFileName = ['MADTest_' kill_lz(dorgbez(f,:)) '_TestResult.csv'];
57+
fileHandle = fopen([parameter.projekt.pfad filesep outputFileName], 'wb');
58+
59+
%% write the specifiers
60+
fprintf(fileHandle, 'Feature Name; Median; MAD\n');
61+
62+
%% compute the global median
63+
currentValues = d_org(ind_auswahl(confirmedTrack), f);
64+
currentValues(isinf(currentValues) | isnan(currentValues)) = [];
65+
globalMedian = median(currentValues);
66+
medianValues = zeros(numOutputClasses, 1);
67+
medianDeviations = zeros(numOutputClasses, 1);
68+
69+
%% compute absolute median deviation
70+
for i=1:numOutputClasses
71+
72+
%% get the current output classes
73+
currentClass = selectedOutputClasses(i);
74+
75+
%% find indices matching the feature and output classes
76+
selectedIndices = intersect(ind_auswahl, find(code_alle(ind_auswahl, selectedOutputVariable) == currentClass & confirmedTrack));
77+
outputVariableName = zgf_y_bez(selectedOutputVariable, currentClass).name;
78+
79+
%% get the feature values
80+
currentFeatureValues = d_org(selectedIndices, f);
81+
currentFeatureValues(isinf(currentFeatureValues) | isnan(currentFeatureValues)) = [];
82+
83+
medianValues(i) = median(currentFeatureValues);
84+
medianDeviations(i) = abs(medianValues(i) - globalMedian);
85+
end
86+
87+
MADValue = mean(medianDeviations);
88+
MADThreshold = globalMedian + 3*MADValue;
89+
90+
fprintf(fileHandle, 'Global Median; %f; %f\n', globalMedian, MADValue);
91+
92+
showHistogram = false; showViolinPlots = true; callback_livecellminer_show_combined_boxplots(parameter, d_org, d_orgs, dorgbez, var_bez, ind_auswahl, bez_code, code_alle, zgf_y_bez, showHistogram, showViolinPlots);
93+
94+
fh = gcf; hold on;
95+
plot([0, numOutputClasses+1], [globalMedian, globalMedian], '--k', 'LineWidth', 2);
96+
plot([0, numOutputClasses+1], [globalMedian + significanceLevel*MADValue, globalMedian + 3*MADValue], '-.k', 'LineWidth', 2);
97+
plot([0, numOutputClasses+1], [globalMedian - significanceLevel*MADValue, globalMedian - 3*MADValue], '-.k', 'LineWidth', 2);
98+
99+
currentYLim = get(gca, 'YLim');
100+
textOffset = (currentYLim(2) - currentYLim(1)) / 60;
101+
text(0.01, globalMedian + textOffset, 'Global Median');
102+
text(0.01, globalMedian + 3*MADValue + textOffset, sprintf('Global Median + %i*MAD', significanceLevel));
103+
text(0.01, globalMedian - 3*MADValue - textOffset, sprintf('Global Median - %i*MAD', significanceLevel));
104+
105+
%% compute absolute median deviation
106+
for i=1:numOutputClasses
107+
108+
%% get the current output classes
109+
currentClass = selectedOutputClasses(i);
110+
111+
%% find indices matching the feature and output classes
112+
outputVariableName = zgf_y_bez(selectedOutputVariable, currentClass).name;
113+
114+
%% get the feature values
115+
currentMAD = (medianValues(i) - globalMedian) / MADValue;
116+
117+
%% print the current feature name
118+
fprintf(fileHandle, '%s;%f;%f;\n', outputVariableName, medianValues(i), currentMAD);
119+
end
120+
121+
%% close the file handles
122+
fclose(fileHandle);
123+
end
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
%%
2+
% LiveCellMiner.
3+
% Copyright (C) 2020 D. Moreno-Andres, A. Bhattacharyya, W. Antonin, J. Stegmaier
4+
%
5+
% Licensed under the Apache License, Version 2.0 (the "License");
6+
% you may not use this file except in compliance with the License.
7+
% You may obtain a copy of the Liceense at
8+
%
9+
% http://www.apache.org/licenses/LICENSE-2.0
10+
%
11+
% Unless required by applicable law or agreed to in writing, software
12+
% distributed under the License is distributed on an "AS IS" BASIS,
13+
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
% See the License for the specific language governing permissions and
15+
% limitations under the License.
16+
%
17+
% Please refer to the documentation for more information about the software
18+
% as well as for installation instructions.
19+
%
20+
% If you use this application for your work, please cite the repository and one
21+
% of the following publications:
22+
%
23+
% TBA
24+
%
25+
%%
26+
27+
%% remember the previous selection
28+
syncFeatureIndex = callback_livecellminer_find_time_series(var_bez, 'manualSynchronization');
29+
30+
%% find the manual synchronization feature
31+
positionIndices = [3,4];
32+
positionIndices(1) = callback_livecellminer_find_time_series(var_bez, 'xpos');
33+
positionIndices(2) = callback_livecellminer_find_time_series(var_bez, 'ypos');
34+
35+
%% find the selected features
36+
selectedFeatures = parameter.gui.merkmale_und_klassen.ind_zr;
37+
numFeatures = length(selectedFeatures);
38+
if (numFeatures <= 0)
39+
disp('No valid features selected!');
40+
return;
41+
end
42+
43+
44+
%% compute the Sister cell distance
45+
d_orgs(:,:,end+1) = 0;
46+
recoveryFeatureIndex = size(d_orgs, 3);
47+
if (strcmp(kill_lz(var_bez(end,:)), 'y') || var_bez(end,1) == 'y')
48+
var_bez = char(var_bez(1:end-1, :), 'RecoveryFeature');
49+
else
50+
var_bez = char(var_bez, 'RecoveryFeature');
51+
end
52+
aktparawin;
53+
54+
%% process all data points and compute the Sister distances.
55+
for i=1:size(d_orgs,1)
56+
57+
%% don't process the last entry of d_orgs
58+
if (i >= size(d_orgs,1) || max(d_orgs(i,:,syncFeatureIndex)) <= 0)
59+
continue;
60+
end
61+
62+
intIndices = find(d_orgs(i,:,syncFeatureIndex) == 1);
63+
pmaIndices = find(d_orgs(i,:,syncFeatureIndex) == 2);
64+
atiIndices = find(d_orgs(i,:,syncFeatureIndex) == 3);
65+
66+
%% find normalization time point
67+
featureWeight = 1 / numFeatures;
68+
recoveryFeature = zeros(1, size(d_orgs,2));
69+
for j=selectedFeatures
70+
targetValue = mean(mean(d_orgs(i,intIndices, j)));
71+
recoveryFeature = recoveryFeature + featureWeight * (100*(abs(targetValue - d_orgs(i,:, j)) / targetValue));
72+
end
73+
recoveryFeature = 100 - recoveryFeature;
74+
75+
%% set the Sister distance feature
76+
d_orgs(i, :, recoveryFeatureIndex) = recoveryFeature;
77+
end
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
%%
2+
% LiveCellMiner.
3+
% Copyright (C) 2020 D. Moreno-Andres, A. Bhattacharyya, W. Antonin, J. Stegmaier
4+
%
5+
% Licensed under the Apache License, Version 2.0 (the "License");
6+
% you may not use this file except in compliance with the License.
7+
% You may obtain a copy of the Liceense at
8+
%
9+
% http://www.apache.org/licenses/LICENSE-2.0
10+
%
11+
% Unless required by applicable law or agreed to in writing, software
12+
% distributed under the License is distributed on an "AS IS" BASIS,
13+
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
% See the License for the specific language governing permissions and
15+
% limitations under the License.
16+
%
17+
% Please refer to the documentation for more information about the software
18+
% as well as for installation instructions.
19+
%
20+
% If you use this application for your work, please cite the repository and one
21+
% of the following publications:
22+
%
23+
% TBA
24+
%
25+
%%
26+
27+
%% remember the previous selection
28+
selectedFeatures = parameter.gui.merkmale_und_klassen.ind_zr;
29+
syncFeatureIndex = callback_livecellminer_find_time_series(var_bez, 'manualSynchronization');
30+
31+
if (isempty(next_function_parameter))
32+
prompt = {'Enter frames after MA:'};
33+
dlgtitle = 'Specify number of frames after MA to extract the single feature...';
34+
dims = [1 35];
35+
definput = {'10'};
36+
answer = inputdlg(prompt,dlgtitle,dims,definput);
37+
numFrames = round(str2double(answer{1}));
38+
else
39+
numFrames = next_function_parameter;
40+
next_function_parameter = [];
41+
end
42+
43+
for f=selectedFeatures
44+
45+
%% compute the Sister cell distance
46+
d_org(:,end+1) = 0;
47+
newFeatureIndex = size(d_org, 2);
48+
49+
if (strcmp(kill_lz(dorgbez(end,:)), 'y'))
50+
dorgbez = char(dorgbez(1:end-1, :), sprintf('%s_%02dFramesAfterMA', kill_lz(var_bez(f,:)), numFrames));
51+
else
52+
dorgbez = char(dorgbez, sprintf('%s-%02dFramesAfterMA', kill_lz(var_bez(f,:)), numFrames));
53+
end
54+
55+
%% update the time series
56+
aktparawin;
57+
58+
%% process all data points and compute the Sister distances.
59+
for i=1:size(d_orgs,1)
60+
61+
%% don't process the last entry of d_orgs
62+
if (i >= size(d_orgs,1))
63+
continue;
64+
end
65+
66+
%% find the MA transition
67+
currentMATransition = find(d_orgs(i, :, syncFeatureIndex) == 3, 1, 'first');
68+
69+
if (isempty(currentMATransition) || (currentMATransition+numFrames) > size(d_orgs,2))
70+
d_orgs(i, :, syncFeatureIndex) = -1;
71+
continue;
72+
end
73+
74+
%% find normalization time point
75+
featureAfterAnaphaseOnset = squeeze(d_orgs(i,currentMATransition+numFrames,f));
76+
77+
%% set the Sister distance feature
78+
d_org(i, newFeatureIndex) = featureAfterAnaphaseOnset;
79+
end
80+
end

0 commit comments

Comments
 (0)