forked from mporter-gre/mtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
selectROIFilesForFRAPAnalysis.m
123 lines (110 loc) · 7.56 KB
/
selectROIFilesForFRAPAnalysis.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
function selectROIFilesForFRAPAnalysis(credentials, conditions, handles)
%Analyse batches of FRAP movies and save the data into an Excel
%spreadsheet, or .csv file if Excel is not installed on the client machine.
%User will be asked to point to ROI files that relate to the movies on the
%Omero server. 4 ROIs must be drawn for each movie and lebelled
%specifically: 'FRAP' is the spot that is bleached; 'WHOLE' is the whole
%cell; 'REF' is another spot that you would like to measure - this is not
%used for the analysis; 'BASE' is the background outside the cell. All 4
%ROIs must be the same number of timepoints in length.
%
%Author Michael Porter
% Copyright (C) 2009-2014 University of Dundee.
% 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.
numConditions = length(conditions);
paths = handles.conditionsPaths;
files = handles.conditionsFiles;
dataOut = [];
dataSummary = {'File Name', 'Condition', 'T1/2', 'Mobile Fraction', 'Immobile Fraction'};
for thisCondition = 1:numConditions
if iscell(files{thisCondition})
numFiles{thisCondition} = length(files{thisCondition});
for thisFile = 1:numFiles{thisCondition}
[ROIIdx{thisCondition}{thisFile} roishapeIdx{thisCondition}{thisFile} indices] = FRAPMeasure(paths{thisCondition}, files{thisCondition}{thisFile}, credentials, thisFile, numFiles{thisCondition}, thisCondition, numConditions);
dataOut = [dataOut; {[roishapeIdx{thisCondition}{thisFile}{indices.frapIdx}.name, ' Frap analysis. T1/2 = ', num2str(roishapeIdx{thisCondition}{thisFile}{indices.frapIdx}.Thalf), 's, mobile fraction = ', num2str(roishapeIdx{thisCondition}{thisFile}{indices.frapIdx}.mobileFraction), ', immobile fraction = ', num2str(roishapeIdx{thisCondition}{thisFile}{indices.frapIdx}.immobileFraction)],'','','','','','',''}];
dataOut = [dataOut; {'File Name', 'Condition', 'Timestamp', 'Frap Intensities' 'Ref Intensities', 'Base Intensities', 'Whole Intensities', 'Frap Normalised Corrected';}];
for thisTimestamp = 1:length(roishapeIdx{thisCondition}{thisFile}{indices.frapIdx}.correctT)
dataOut = [dataOut; {roishapeIdx{thisCondition}{thisFile}{indices.frapIdx}.name conditions{thisCondition} num2str(roishapeIdx{thisCondition}{thisFile}{indices.frapIdx}.timestamp(thisTimestamp))} roishapeIdx{thisCondition}{thisFile}{indices.frapIdx}.frapData(thisTimestamp) roishapeIdx{thisCondition}{thisFile}{indices.refIdx}.refData(thisTimestamp) roishapeIdx{thisCondition}{thisFile}{indices.baseIdx}.baseData(thisTimestamp) roishapeIdx{thisCondition}{thisFile}{indices.wholeIdx}.wholeData(thisTimestamp) roishapeIdx{thisCondition}{thisFile}{indices.frapIdx}.frapNormCorr(thisTimestamp)];
end
dataOut = [dataOut; {' ',' ',' ',' ',' ',' ',' ',' '}];
dataSummary = [dataSummary; {roishapeIdx{thisCondition}{thisFile}{indices.frapIdx}.name, conditions{thisCondition}, num2str(roishapeIdx{thisCondition}{thisFile}{indices.frapIdx}.Thalf), num2str(roishapeIdx{thisCondition}{thisFile}{indices.frapIdx}.mobileFraction), num2str(roishapeIdx{thisCondition}{thisFile}{indices.frapIdx}.immobileFraction)}];
end
else
thisFile = 1;
numFiles{thisCondition} = 1;
[ROIIdx{thisCondition}{thisFile} roishapeIdx{thisCondition}{thisFile} indices] = FRAPMeasure(paths{thisCondition}, files{thisCondition}, credentials, thisFile, numFiles{thisCondition}, thisCondition, numConditions);
dataOut = [dataOut; {[roishapeIdx{thisCondition}{thisFile}{indices.frapIdx}.name, ' Frap analysis. T1/2 = ', num2str(roishapeIdx{thisCondition}{thisFile}{indices.frapIdx}.Thalf), 's, mobile fraction = ', num2str(roishapeIdx{thisCondition}{thisFile}{indices.frapIdx}.mobileFraction), ', immobile fraction = ', num2str(roishapeIdx{thisCondition}{thisFile}{indices.frapIdx}.immobileFraction)],'','','','','','',''}];
dataOut = [dataOut; {'File Name', 'Condition', 'Timestamp', 'Frap Intensities' 'Ref Intensities', 'Base Intensities', 'Whole Intensities', 'Frap Normalised Corrected';}];
for thisTimestamp = 1:length(roishapeIdx{thisCondition}{thisFile}{indices.frapIdx}.correctT)
dataOut = [dataOut; {roishapeIdx{thisCondition}{thisFile}{indices.frapIdx}.name conditions{thisCondition} num2str(roishapeIdx{thisCondition}{thisFile}{indices.frapIdx}.timestamp(thisTimestamp))} roishapeIdx{thisCondition}{thisFile}{indices.frapIdx}.frapData(thisTimestamp) roishapeIdx{thisCondition}{thisFile}{indices.refIdx}.refData(thisTimestamp) roishapeIdx{thisCondition}{thisFile}{indices.baseIdx}.baseData(thisTimestamp) roishapeIdx{thisCondition}{thisFile}{indices.wholeIdx}.wholeData(thisTimestamp) roishapeIdx{thisCondition}{thisFile}{indices.frapIdx}.frapNormCorr(thisTimestamp)];
end
dataOut = [dataOut; {' ',' ',' ',' ',' ',' ',' ',' '}];
dataSummary = [dataSummary; {roishapeIdx{thisCondition}{thisFile}{indices.frapIdx}.name, conditions{thisCondition}, num2str(roishapeIdx{thisCondition}{thisFile}{indices.frapIdx}.Thalf), num2str(roishapeIdx{thisCondition}{thisFile}{indices.frapIdx}.mobileFraction), num2str(roishapeIdx{thisCondition}{thisFile}{indices.frapIdx}.immobileFraction)}];
end
end
[saveFile savePath] = uiputfile('*.xls','Save Results',[handles.currDir, '/FrapAnalysisResults.xls']);
if isnumeric(saveFile) && isnumeric(savePath)
return;
end
try
xlswrite([savePath saveFile], dataOut, 'Data All Timepoints');
xlswrite([savePath saveFile], dataSummary, 'Data Summary');
catch
%If the xlswriter fails (no MSOffice installed, e.g.) then manually
%create a .csv file. Turn every cell to string to make it easier.
[rows cols] = size(dataOut);
for thisRow = 1:rows
for thisCol = 1:cols
if isnumeric(dataOut{thisRow, thisCol})
dataOut{thisRow, thisCol} = num2str(dataOut{thisRow, thisCol});
end
end
end
[rowsSummary colsSummary] = size(dataSummary);
for thisRow = 1:rowsSummary
for thisCol = 1:colsSummary
if isnumeric(dataSummary{thisRow, thisCol})
dataSummary{thisRow, thisCol} = num2str(dataSummary{thisRow, thisCol});
end
end
end
delete([savePath saveFile]); %Delete the .xls file and save again as .csv
[savePart remain] = strtok(saveFile, '.');
saveFile = [savePart '.csv'];
saveFileSummary = [savePart 'Summary.csv'];
%Write out DataOut to file
fid = fopen([savePath saveFile], 'w');
for thisRow = 1:rows
for thisCol = 1:cols
fprintf(fid, '%s', dataOut{thisRow, thisCol});
fprintf(fid, '%s', ',');
end
fprintf(fid, '%s\n', '');
end
fclose(fid);
%Write out dataSummary to file
fid = fopen([savePath saveFileSummary], 'w');
for thisRow = 1:rowsSummary
for thisCol = 1:colsSummary
fprintf(fid, '%s', dataSummary{thisRow, thisCol});
fprintf(fid, '%s', ',');
end
fprintf(fid, '%s\n', '');
end
fclose(fid);
end
end