-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindexCorrection.m
More file actions
78 lines (69 loc) · 4.13 KB
/
Copy pathindexCorrection.m
File metadata and controls
78 lines (69 loc) · 4.13 KB
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
% indexCorrection(DeletedFrameRecordAbsolutePath, ResultsMatPath,
% FinalFrameNum, OriginalFrameNum)
function indexCorrection(DeletedFrameRecordAbsolutePath, ResultsMatPath, varargin)
FrameColIdx = 3; % The index of the column recording the frame# in each cell of FullMitosis
StartFrameColIdx = 1; % The index of the column recording the start frame# in FullMitosisStats
EndFrameColIdx = 2; % The index of the column recording the end frame# in FullMitosisStats
TotalFrameNumColIdx = 3; % The index of the column recording the total frame# in FullMitosisStats
[DeletedFrameRecordDirectory, ~, ~] = fileparts(DeletedFrameRecordAbsolutePath);
if isempty(DeletedFrameRecordDirectory)
error('please specify the !absolute! path of the DeletedFrameRecord.');
end
if (exist(DeletedFrameRecordAbsolutePath, 'file') == 2) % the DeletedFrameRecord exists
DeletedIndeces = load(DeletedFrameRecordAbsolutePath);
%% Determine whether #frames(deleted) matches (#frames(original) - #frames(final))
if ~isempty(varargin)
if (length(DeletedIndeces) + varargin{1} == varargin{2})
disp('#frames(deleted) matches (#frames(original) - #frames(final)).');
else
error('#frames(deleted) does not match (#frames(original) - #frames(final))!');
end
end
%% Correct FullMitosis (cell structure)
load(ResultsMatPath);
for i = 1 : length(FullMitosis)
UncorrectedFrameIdx = FullMitosis{i}(:, FrameColIdx);
CorrectedFrameIdx = zeros(size(UncorrectedFrameIdx));
for j = 1 : length(UncorrectedFrameIdx)
CorrectedFrameIdx(j) = UncorrectedFrameIdx(j) + ...
sum(DeletedIndeces - (1 : length(DeletedIndeces)) < UncorrectedFrameIdx(j));
end
FullMitosis{i}(:, FrameColIdx) = CorrectedFrameIdx;
end
%% Correct FullMitosisStats (matrix)
UncorrectedStartFrameIdx = FullMitosisStats(:, StartFrameColIdx);
CorrectedStartFrameIdx = zeros(size(UncorrectedStartFrameIdx));
for i = 1 : length(UncorrectedStartFrameIdx)
CorrectedStartFrameIdx(i) = UncorrectedStartFrameIdx(i) + ...
sum(DeletedIndeces - (1 : length(DeletedIndeces)) < UncorrectedStartFrameIdx(i));
end
FullMitosisStats(:, StartFrameColIdx) = CorrectedStartFrameIdx;
UncorrectedEndFrameIdx = FullMitosisStats(:, EndFrameColIdx);
CorrectedEndFrameIdx = zeros(size(UncorrectedEndFrameIdx));
for i = 1 : length(UncorrectedEndFrameIdx)
CorrectedEndFrameIdx(i) = UncorrectedEndFrameIdx(i) + ...
sum(DeletedIndeces - (1 : length(DeletedIndeces)) < UncorrectedEndFrameIdx(i));
end
FullMitosisStats(:, EndFrameColIdx) = CorrectedEndFrameIdx;
FullMitosisStats(:, TotalFrameNumColIdx) = ...
FullMitosisStats(:, EndFrameColIdx) - FullMitosisStats(:, StartFrameColIdx) + 1;
%% Save corrected FullMitosisStats & FullMitosis as a new .mat file
[ResultsMatParentalFolder, OriginalResultsMatFileName, ~] = fileparts(ResultsMatPath);
if isempty(ResultsMatParentalFolder)
ResultsMatParentalFolder = pwd;
end
CorrectedResultsMatPath = sprintf('%s%s%s_Corrected.mat', ...
ResultsMatParentalFolder, filesep, OriginalResultsMatFileName);
save(CorrectedResultsMatPath, 'FullMitosis', 'FullMitosisStats', 'AnnotationTag');
fileattrib(CorrectedResultsMatPath, '-w', 'a');
%% Write corrected FullMitosisStats into a new .txt file
CorrectedResultsTxtPath = sprintf('%s%s%s_Corrected.txt', ...
ResultsMatParentalFolder, filesep, OriginalResultsMatFileName);
OutputFileID = fopen(CorrectedResultsTxtPath, 'w'); % open file for writing; discard existing contents
fprintf(OutputFileID, '%d %d %d %.1f %.1f %.1f %.1f\n', FullMitosisStats');
fclose(OutputFileID);
fileattrib(CorrectedResultsTxtPath, '-w', 'a');
else
warning('no DeletedFrameRecord with the specified path exists.');
end
end