-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaSS.m
180 lines (178 loc) · 6.23 KB
/
MaSS.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
173
174
175
176
177
178
179
180
%% function: MaSS (Merge a Single Sample)
%% --------------------------------------------------------------
%% Created by: Benjamin Green and Alex Szalay - Johns Hopkins - 01/09/2019
%% --------------------------------------------------------------
%% Description
% run cleanup protocol for multipass phenotyping of a single sample. The
% output .csv files for each image is placed into
% *\inform output\Phenotyped\Results. Additional
% details located at the github repo: https://github.com/AstropathJHU/MaSS
%% --------------------------------------------------------------
%% input:
%%% wd: working directory for inform data in the astropath workflow this is
%%% defined as: *\inform_data
%%% the directory should contain the following subfolders
%%% + Component_Tiffs (component_data.tiff for each image)
%%% + Phenotyped (The *\Phenotyped folder should contain: all ABs
%%% analyzed in seperate folders, designated by their Target names)
%%% | - + ABX1 (Every ABXN folder should have cell_seg_data.txt for
%%% each image)
%%% | - + ABX2
%%% | - + ABXN...
%%% EX. \inform_data\Phenotyped\CD8
%%% EX. \inform_data\Phenotyped\Tumor
%%% EX. \inform_data\Phenotyped\PDL1
%%% EX. \inform_data\Phenotyped\PD1
%%% EX. \inform_data\Phenotyped\FoxP3
%%% EX. \inform_data\Phenotyped\CD163
%%%
%%% For segmentations; ABXN with the lowest Opal for each segmentation
%%% type should have the *_binary_seg_maps.tif images exported
%%%
%%% The binary segmentation maps should contain 4 layers;
%%% Note: when saving the inform algorithm turn on all mask
%%% layers to be sure all segmentations are exported
%%%
%%% sname: the sample name of the slide
%%% MergeConfig: full path to the merge configuration file
%%% logstring: the intial portion of the logstring (project;cohort;)
%% Usage:
%%% wd = 'W:\Clincial_Specimen\M1_1\inform_data'
%%% sname = 'M1_1'
%%% MergeConfig = '\\bki03\Clinical_Specimen_4\Batch\MergeConfig_01.xlsx'
%%% logstring = '1;2;'
%% output:
% *\inform_data\Phenotyped\Results\Tables\*_cleaned_phenotyped_table.csv &
% *\inform_data\Phenotyped\Results\tmp_ForFiguresTables\* _cleaned_phenotyped_table.mat
% files for each image. Additional details located at the github repo:
% https://github.com/AstropathJHU/MaSS
%% --------------------------------------------------------------
%% License:
% Copyright (c) 2019 Benjamin Green, Alex Szalay.
% Permission is hereby granted, free of charge, to any person obtaining a
% copy of this software and associated documentation files (the "Software"),
% to deal in the Software without restriction, including without limitation
% the rights to use, copy, modify, merge, publish, distribute, sublicense,
% and/or sell copies of the Software, and to permit persons to whom the
% Software is furnished to do so, subject to the following conditions:
% The above copyright notice and this permission notice shall be included
% in all copies or substantial portions of the Software.
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
% OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
% IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
% CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
% TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
% SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
%% --------------------------------------------------------------
%%
function [err_val] = MaSS(wd, sname, MergeConfig, logstring)
%
filepath = fileparts(mfilename('fullpath'));
addpath(genpath(filepath))
%
if nargin < 4
logstring = '';
version = '0.01.001';
else
l = strsplit(logstring, '-');
if length(l) == 1
version = '0.01.001';
logstring = l{1};
else
version = l{2};
logstring = l{1};
end
end
%
if strcmp(version,'0.0.2')
imall = 1;
else
imall = 0;
end
%
err_val = mywritetolog(wd, sname, logstring, '', 1, 'Tables', version);
e_code = err_handl(wd, sname, logstring, [], err_val, 'Tables', '');
if e_code == 1
return
end
%
err_str = ['-wd: ', replace(wd, '\', '\\'), ' -sname: ', sname];
mywritetolog(wd, sname, logstring, err_str, 2, 'Tables');
%
% get Markers structure
%
err_str = ['parsing MergeConfig file: ', replace(MergeConfig, '\', '\\')];
mywritetolog(wd, sname, logstring, err_str, 2, 'Tables');
%
try
%
[Markers, err_val] = createmarks(MergeConfig);
%
catch
err_val = 8;
err_handl(wd, sname, logstring, [], err_val, 'Tables', '');
return
end
%
e_code = err_handl(wd, sname, logstring, Markers, err_val, 'Tables', '');
if e_code == 1
return
end
%
% get all filenames for a directory
%
err_str = 'get filenames and check image output';
mywritetolog(wd, sname, logstring, err_str, 2, 'Tables');
%
try
%
[filenms, sum_filenames, err_val] = getfilenames(wd, Markers);
%
catch
err_val = 13;
err_handl(wd, sname, logstring, Markers, err_val, 'Tables', '');
return
end
%
e_code = err_handl(wd, sname, logstring, Markers, err_val, 'Tables', '');
if e_code == 1
return
end
%
% run the file loop for the sample
%
err_str = ['merging ',num2str(length(filenms)), ' file(s)'];
mywritetolog(wd, sname, logstring, err_str, 2, 'Tables');
%
try
%
[e, nfiles, Markers] = ...
fileloop(wd, sname, filenms, sum_filenames, Markers, logstring, imall);
%
catch EM
disp(EM.message);
err_val = 15;
err_handl(wd, sname, logstring, Markers, err_val, 'Tables', '');
return
end
%
err_str = ['successfully merged ',num2str(nfiles),...
' file(s)'];
mywritetolog(wd, sname, logstring, err_str, 2, 'Tables');
if any(cell2mat(e))
err_val = 15;
err_handl(wd, sname, logstring, Markers, err_val, 'Tables', '');
return
end
%
if length(filenms) == nfiles
err_str = 'MaSS finished';
mywritetolog(wd, sname, logstring, err_str, 2, 'Tables');
else
err_str = 'MaSS failed';
mywritetolog(wd, sname, logstring, err_str, 2, 'Tables');
end
%
end
%%