Skip to content

Commit d222e1e

Browse files
committed
Added combined PairAnalysis for SimpleStats + various fixes
1 parent 39f9520 commit d222e1e

File tree

7 files changed

+43
-22
lines changed

7 files changed

+43
-22
lines changed

MATLAB/+smi_cluster/@ClusterInterface/combinedStatistics1.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ function combinedStatistics1(SC, pathname, files, base_name, A_ROI, doHopkins)
112112

113113
% Hopkins' statistic per ROI.
114114
if doHopkins
115-
%SC.CSV = true;
115+
SC.CSV = true;
116116
P_hopkins_ROI = ...
117117
SC.plotCombined(arrayfun(@(i) rdata{i}.collected.H_ROI, 1 : n_files, ...
118118
'UniformOutput', false), ...
119119
0.01, 'Hopkins per ROI', econd, 'hopkins_ROI');
120-
%SC.CSV = false;
120+
SC.CSV = false;
121121
fprintf(out, 'P_Hopkins per ROI =\n');
122122
fprintf(out, fmt, P_hopkins_ROI);
123123
fprintf(out, '\n');

MATLAB/+smi_cluster/@PairAnalysis/PairAnalysis.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
results_o = doOverlap(n_ROIs, RoI, results_c, l12, desc, particles, ...
5050
results_dir, PlotNonOverlap, Color, plotting)
5151
results_ss = doSimpleStats(n_ROIs, RoI, PixelSize, desc, particles, ...
52-
results_dir)
52+
results_dir, combined)
5353
overlayBaGoLROIs(pathnameB, filesB, MAPNfile, ROI_sizes, SRImageZoom)
5454
doPlot2(n_ROIs, RoI, desc, particles, results_dir, Color, plotting)
5555

MATLAB/+smi_cluster/@PairAnalysis/doAnalysis.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
% Pearson's correlation and Manders' split coefficients per ROI.
124124
if any(contains(options, "SimpleStats"))
125125
results_ss = PA.doSimpleStats(n_ROIs, RoI, PixelSize, desc, particles, ...
126-
results_dir);
126+
results_dir, combined);
127127
fprintf("Done SimpleStats\n");
128128
end
129129

MATLAB/+smi_cluster/@PairAnalysis/doSimpleStats.m

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function results_ss = doSimpleStats(n_ROIs, RoI, PixelSize, desc, particles,...
2-
results_dir)
2+
results_dir, combined)
33
%doSimpleStats finds the Pearson and Manders' coefficients between two colors.
44
% pearsonCorrCoef finds the Pearson correlation coefficient between two sets of
55
% localizations given in a list of coincident ROIs when converted to histogram
@@ -16,6 +16,7 @@
1616
% desc string identifying the analysis
1717
% particles string array describing the two particles
1818
% results_dir output directory
19+
% combined produce combined results over all ROIs
1920
%
2021
% OUTPUTS:
2122
% results_ss results structure imdexed by ROI with the following fields:
@@ -44,7 +45,7 @@
4445
for i = 1 : n_ROIs
4546
SMD1 = RoI{i}.SMD{1};
4647
SMD2 = RoI{i}.SMD{2};
47-
ROI = RoI{i}.ROI / PixelSize;
48+
ROI = RoI{i}.ROI / PixelSize; % [xmin, xmax, ymin, ymax] (pixel)
4849

4950
% Pearson correlation coefficient.
5051
[pearson, p_value] = smi_stat.pearsonCorrCoef(SMD1, SMD2, SRZoom, ROI);
@@ -59,6 +60,18 @@
5960
fprintf(out, '%2d %7.4f %7.2g %7.4f %7.4f\n', ...
6061
i, pearson, p_value, M1, M2);
6162
end
63+
if combined % mean results
64+
mean_pearson = mean(arrayfun(@(i) results_ss{i}.pearson, 1 : n_ROIs));
65+
mean_M1 = mean(arrayfun(@(i) results_ss{i}.M1, 1 : n_ROIs));
66+
mean_M2 = mean(arrayfun(@(i) results_ss{i}.M2, 1 : n_ROIs));
67+
SE_pearson = std(arrayfun(@(i) results_ss{i}.pearson, 1 : n_ROIs));
68+
SE_M1 = std(arrayfun(@(i) results_ss{i}.M1, 1 : n_ROIs));
69+
SE_M2 = std(arrayfun(@(i) results_ss{i}.M2, 1 : n_ROIs));
70+
fprintf(out, 'avg %7.4f %7.4f %7.4f\n', ...
71+
mean_pearson, mean_M1, mean_M2);
72+
fprintf(out, 'SE %7.4f %7.4f %7.4f\n', ...
73+
SE_pearson, SE_M1, SE_M2);
74+
end
6275
fclose(out);
6376

6477
end

MATLAB/+smi_stat/pearsonCorrCoef.m

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
% a better estimate of the Pearson Correlation Coefficient
1515
% (default: 20)
1616
% ROI for a ROI, corner coordinates [xmin, xmax, ymin, ymax] pixels
17-
% (default: [0, 0, 256, 256] pixels)
17+
% (default: [0, 256, 0, 256] pixels)
1818
%
1919
% OUTPUTS:
2020
% pearson correlation coefficent between the Gaussian blob images of
@@ -31,16 +31,20 @@
3131
SRZoom = 20;
3232
end
3333
if ~exist('ROI', 'var')
34-
ROI = [0, 0, 256, 256];
34+
ROI = [0, 256, 0, 256];
3535
end
3636

3737
SMD1a = SMD1;
3838
SMD2a = SMD2;
39-
if ROI ~= [0, 0, 256, 256]
39+
if ROI ~= [0, 256, 0, 256]
40+
% If the ROI is not the whole image ... move the ROI to (x, y) = (0, 0)
41+
% corner. This is done to perform the correlation only within the ROI,
42+
% excluding the zero pixels outside the ROI,
4043
SMD1a.X = SMD1a.X - ROI(1);
4144
SMD2a.X = SMD2a.X - ROI(1);
4245
SMD1a.Y = SMD1a.Y - ROI(3);
4346
SMD2a.Y = SMD2a.Y - ROI(3);
47+
% delta_x/y should be integer numbers of pixels.
4448
delta_x = floor(ROI(2) - ROI(1));
4549
delta_y = floor(ROI(4) - ROI(3));
4650
SMD1a.XSize = delta_x;
@@ -57,14 +61,18 @@
5761
[r, p] = corrcoef(G1, G2);
5862
pearson = r(1, 2);
5963
p_value = p(1, 2);
60-
%fprintf('pearson = %f\n', pearson);
6164

62-
% Code to calculate pearson by hand. The results should be the same as
63-
% using the MATLAB function corrcoef.
64-
%H1 = G1(:);
65-
%H2 = G2(:);
66-
%pearsonA = sum((H1 - mean(H1)) .* (H2 - mean(H2))) ...
67-
% ./ ((numel(H1) - 1) * std(H1) * std(H2));
68-
%fprintf('pearsonA = %f\n', pearsonA);
65+
verbose = false;
66+
if verbose
67+
fprintf('pearson = %f\n', pearson);
68+
69+
% Code to calculate pearson by hand. The results should be the same as
70+
% using the MATLAB function corrcoef.
71+
H1 = G1(:);
72+
H2 = G2(:);
73+
pearsonA = sum((H1 - mean(H1)) .* (H2 - mean(H2))) ...
74+
./ ((numel(H1) - 1) * std(H1) * std(H2));
75+
fprintf('pearsonA = %f\n', pearsonA);
76+
end
6977

7078
end

MATLAB/+smi_vis/@GenerateImages/dispIm.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function dispIm()
2929
'Unit','normalize','Enable','on','Position', [0.75 0.92 0.15 0.06],'Callback',@backward);
3030

3131
function getFileList1(~,~) % Choose data file(s) and list them in the File List box
32-
[filename, pathname]=uigetfile('Y:\*.png;*.tif','MultiSelect','on');
32+
[filename, pathname]=uigetfile('*.png;*.tif','MultiSelect','on');
3333
Im = cell(1,length(filename));
3434
map = Im;
3535
for ii = 1:length(filename)

MATLAB/examples/simplePairCorr.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,12 @@
295295

296296
% Save analysisALL.mat
297297
analysis = ['analysis', desc];
298-
[results_pcc_ALL, resultsRC_pcc_ALL, results_c_ALL, results_cs_ALL, ...
299-
results_ls_ALL, results_o1_ALL, results_o2_ALL] = ...
298+
[results_pcc_ALL, resultsRC_pcc_ALL, results_ss_ALL, results_c_ALL, ...
299+
results_cs_ALL, results_ls_ALL, results_o1_ALL, results_o2_ALL] = ...
300300
PA.doAnalysis(n_ROIs_ALL, RoI_ALL, ROI_sizes, desc, particles, ...
301301
results_dir, opts, Pixel2nm, HistBinSize, RmaxAxisLimit, ...
302302
E, minPts, PlotNonOverlap, Color);
303303
save(fullfile(results_dir, analysis), 'results_pcc_ALL', ...
304-
'resultsRC_pcc_ALL', 'results_c_ALL', 'results_cs_ALL', ...
305-
'results_ls_ALL', 'results_o1_ALL', 'results_o2_ALL');
304+
'resultsRC_pcc_ALL', 'results_ss_ALL', 'results_c_ALL', ...
305+
'results_cs_ALL', 'results_ls_ALL', 'results_o1_ALL', 'results_o2_ALL');
306306
fprintf('Done %s.\n', desc);

0 commit comments

Comments
 (0)