-
Notifications
You must be signed in to change notification settings - Fork 4
/
CycIF_read96wellplate.m
255 lines (214 loc) · 8.68 KB
/
CycIF_read96wellplate.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
%% Import CycIF data from text files.
% 2017/06/27 Jerry Lin
%
% Script for importing data from the following text file:
%
% Results-Nuc-[Row][Col][Filed].txt Nuclear data
% Results-Cyto-[Row][Col][Filed].txt Cytosol data
%
% 02: including X, Y, & Field in the output
%% Initialize variables.
rows = {'A','B','C','D','E','F','G','H'};
cols = {'01','02','03','04','05','06','07','08','09','10','11','12'};
mypath = uigetdir('Z:\sorger\data\Cytell\Connor\ProcessedCycIF\');
sitedata_nuc = cell(8,12,12);
welldata_nuc = cell(8,12);
wellsum_nuc = cell(8,12);
sitedata_Cyto = cell(8,12,12);
welldata_Cyto = cell(8,12);
wellsum_Cyto = cell(8,12);
start_r = input('Please input starting row (1-8):');
end_r = input('Please input ending row (1-8):');
start_c = input('Please input starting column (1-12):');
end_c = input('Please input ending column (1-12):');
start_f = input('Please input starting field (1-12):');
end_f = input('Please input ending field (1-12):');
if end_f>10
flds = {'fld01','fld02','fld03','fld04','fld05','fld06','fld07','fld08','fld09','fld10','fld11','fld12'};
else
flds = {'fld1','fld2','fld3','fld4','fld5','fld6','fld7','fld8','fld9','fld10','fld11','fld12'};
end
%% Read nuclear data
for r=start_r:end_r;
for c=start_c:end_c;
for f=start_f:end_f;
site = strcat(rows(r),cols(c),flds(f));
well = strcat(rows(r),cols(c));
filename = strjoin(strcat(mypath,'\Results-Nuc-',site,'.txt'));
disp(strcat('Processing:',filename));
if exist(filename,'file')
%%filename = 'C:\CycIF\Results-B02fld01.txt';
delimiter = '\t';
startRow = 2;
%% Format string for each line of text:
% column1: double (%f)
% column2: text (%s)
% column3: double (%f)
% column4: double (%f)
% column5: double (%f)
% column6: double (%f)
% column7: double (%f)
% column8: double (%f)
% column9: double (%f)
% column10: double (%f)
% column11: double (%f)
% column12: double (%f)
% column13: double (%f)
% column14: double (%f)
% column15: double (%f)
% column16: double (%f)
% column17: double (%f)
% column18: double (%f)
% column19: double (%f)
% For more information, see the TEXTSCAN documentation.
formatSpec = '%f%s%f%f%f%f%f%f%f%f%f%f%f%s%s%f%f%f%f%[^\n\r]';
%% Open the text file.
fileID = fopen(filename,'r');
%% Read columns of data according to format string.
% This call is based on the structure of the file used to generate this
% code. If an error occurs for a different file, try regenerating the code
% from the Import Tool.
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'EmptyValue' ,NaN,'HeaderLines' ,startRow-1, 'ReturnOnError', false);
%% Close the text file.
fclose(fileID);
%% Post processing for unimportable data.
% No unimportable data rules were applied during the import, so no post
% processing code is included. To generate code which works for
% unimportable data, select unimportable cells in a file and regenerate the
% script.
%% Create output variable
temp = table(dataArray{1:end-1}, 'VariableNames', {'VarName1','Label','Area','Mean','StdDev','Min','Max','X','Y','Perim','Circ','IntDen','Median','VarName14','RawIntDen','Slice','AR','Round','Solidity'});
if(f<10)
temp.Channel = cellfun(@(x) x(20:length(x)),temp.Label,'UniformOutput',false);
else
temp.Channel = cellfun(@(x) x(21:length(x)),temp.Label,'UniformOutput',false);
end
temp.Well = repmat(well,length(temp.Label),1);
temp.Field = repmat(f,length(temp.Label),1);
%% Clear temporary variables
clearvars filename delimiter startRow formatSpec fileID dataArray ans;
sitedata_nuc{r,c,f}=temp;
if(istable(welldata_nuc{r,c}))
welldata_nuc{r,c} = [welldata_nuc{r,c};temp];
else
welldata_nuc{r,c} = temp;
end
end
end
%% processing well summary
temp1 = varfun(@mean,welldata_nuc{r,c},'GroupingVariables','Channel','InputVariables','Mean');
channels = temp1.Channel;
sizes = temp1.GroupCount;
allchs = zeros(sizes(1),length(channels));
for i=1:length(channels);
allchs(:,i) = welldata_nuc{r,c}.Mean(strcmp(welldata_nuc{r,c}.Channel,channels{i}));
end
channels(i+1) = {'Area'};
allchs(:,i+1) = welldata_nuc{r,c}.Area(strcmp(welldata_nuc{r,c}.Channel,channels{1}));
DAPI = welldata_nuc{r,c}.Mean(strcmp(welldata_nuc{r,c}.Channel,'DAPI-0001'));
AREA = allchs(:,i+1);
channels(i+2) = {'IntDAPI'};
allchs(:,i+2) = DAPI .* AREA;
channels(i+3) = {'X'};
allchs(:,i+3) = welldata_nuc{r,c}.X(strcmp(welldata_nuc{r,c}.Channel,channels{1}));
channels(i+4) = {'Y'};
allchs(:,i+4) = welldata_nuc{r,c}.Y(strcmp(welldata_nuc{r,c}.Channel,channels{1}));
channels(i+5) = {'Field'};
allchs(:,i+5) = welldata_nuc{r,c}.Field(strcmp(welldata_nuc{r,c}.Channel,channels{1}));
wellsum_nuc{r,c}=allchs;
%tableTemp = array2table(allchs,'VariableNames',channels);
clearvars allchs DAPI AREA temp1 sizes well temp site;
end
end
%% Read cytosol data
for r=start_r:end_r;
for c=start_c:end_c;
for f=start_f:end_f;
site = strcat(rows(r),cols(c),flds(f));
well = strcat(rows(r),cols(c));
filename = strjoin(strcat(mypath,'\Results-Cyto-',site,'.txt'));
disp(strcat('Processing:',filename));
if exist(filename,'file')
%%filename = 'C:\CycIF\Results-B02fld01.txt';
delimiter = '\t';
startRow = 2;
%% Format string for each line of text:
% column1: double (%f)
% column2: text (%s)
% column3: double (%f)
% column4: double (%f)
% column5: double (%f)
% column6: double (%f)
% column7: double (%f)
% column8: double (%f)
% column9: double (%f)
% column10: double (%f)
% column11: double (%f)
% column12: double (%f)
% column13: double (%f)
% column14: double (%f)
% column15: double (%f)
% column16: double (%f)
% column17: double (%f)
% column18: double (%f)
% column19: double (%f)
% For more information, see the TEXTSCAN documentation.
formatSpec = '%f%s%f%f%f%f%f%f%f%f%f%f%f%s%s%f%f%f%f%[^\n\r]';
%% Open the text file.
fileID = fopen(filename,'r');
%% Read columns of data according to format string.
% This call is based on the structure of the file used to generate this
% code. If an error occurs for a different file, try regenerating the code
% from the Import Tool.
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'EmptyValue' ,NaN,'HeaderLines' ,startRow-1, 'ReturnOnError', false);
%% Close the text file.
fclose(fileID);
%% Post processing for unimportable data.
% No unimportable data rules were applied during the import, so no post
% processing code is included. To generate code which works for
% unimportable data, select unimportable cells in a file and regenerate the
% script.
%% Create output variable
temp = table(dataArray{1:end-1}, 'VariableNames', {'VarName1','Label','Area','Mean','StdDev','Min','Max','X','Y','Perim','Circ','IntDen','Median','VarName14','RawIntDen','Slice','AR','Round','Solidity'});
if(f<10)
temp.Channel = cellfun(@(x) x(20:length(x)),temp.Label,'UniformOutput',false);
else
temp.Channel = cellfun(@(x) x(21:length(x)),temp.Label,'UniformOutput',false);
end
temp.Well = repmat(well,length(temp.Label),1);
temp.Field = repmat(f,length(temp.Label),1);
%% Clear temporary variables
clearvars filename delimiter startRow formatSpec fileID dataArray ans;
sitedata_Cyto{r,c,f}=temp;
if(istable(welldata_Cyto{r,c}))
welldata_Cyto{r,c} = [welldata_Cyto{r,c};temp];
else
welldata_Cyto{r,c} = temp;
end
end
end
%% processing well summary
temp1 = varfun(@mean,welldata_Cyto{r,c},'GroupingVariables','Channel','InputVariables','Mean');
channels = temp1.Channel;
sizes = temp1.GroupCount;
allchs = zeros(sizes(1),length(channels));
for i=1:length(channels);
allchs(:,i) = welldata_Cyto{r,c}.Mean(strcmp(welldata_Cyto{r,c}.Channel,channels{i}));
end
channels(i+1) = {'Area'};
allchs(:,i+1) = welldata_Cyto{r,c}.Area(strcmp(welldata_Cyto{r,c}.Channel,channels{1}));
DAPI = welldata_Cyto{r,c}.Mean(strcmp(welldata_Cyto{r,c}.Channel,'DAPI-0001'));
AREA = allchs(:,i+1);
channels(i+2) = {'IntDAPI'};
allchs(:,i+2) = DAPI .* AREA;
channels(i+3) = {'X'};
allchs(:,i+3) = welldata_nuc{r,c}.X(strcmp(welldata_nuc{r,c}.Channel,channels{1}));
channels(i+4) = {'Y'};
allchs(:,i+4) = welldata_nuc{r,c}.Y(strcmp(welldata_nuc{r,c}.Channel,channels{1}));
channels(i+5) = {'Field'};
allchs(:,i+5) = welldata_nuc{r,c}.Field(strcmp(welldata_nuc{r,c}.Channel,channels{1}));
wellsum_Cyto{r,c}=allchs;
%tableTemp = array2table(allchs,'VariableNames',channels);
clearvars allchs DAPI AREA temp1 sizes well temp site;
end
end