-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFSAoutput.m
297 lines (296 loc) · 11.8 KB
/
FSAoutput.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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
function [ pool ] = FSAoutput( pool )
if strcmp(pool.anaMode,'SSR')
pool.binmatrix = pool.ssr.binmatrix;
pool.fragmentsize = pool.ssr.fragmentsize;
end
if isempty(pool.fragmentsize)
statusbox(pool,'Error: Analysis failed.');
return;
end
statusbox(pool,'Printing data to analysis folder...');
%% print binmatrix
statusbox(pool,'...binmatrix...');
samplenames = strrep(pool.filename, '.fsa', '');
for i=1:1:size(pool.allFilesData{1}.DyeName,1)
updateWB(pool,size(pool.allFilesData{1}.DyeName,1),i,1);
dyenames(i,:) = pool.allFilesData{1}.DyeName(i,(2:size(pool.allFilesData{1}.DyeName(i,:),2)));
end
updateWB(pool,size(pool.allFilesData{1}.DyeName,1),i,0);
fname = strcat(pool.Date,'Binmatrix.',pool.dyenames(pool.selC,:),'.txt');
fid=fopen(fullfile(pool.txtpathmkdir,fname),'w');
if strcmp(pool.anaMode,'SSR')
for i=1:1:size(pool.binmatrix,2)
updateWB(pool,size(pool.binmatrix,2),i,1);
fprintf(fid,'%s', samplenames{i});
fprintf(fid, '\r\n');
for u=1:1:size(pool.binmatrix{i}.locus,2)
locus=strcat('Locus',{' '},num2str(u),{' '},'"',pool.ssr.lociUI.NAME{u},'":',{' '});
fprintf(fid,'%s', locus{1});
fprintf(fid, '%g,', [pool.binmatrix{i}.locus{u}]');
fprintf(fid, '\r\n');
end
end
else
for i=1:1:size(pool.binmatrix,2)
updateWB(pool,size(pool.binmatrix,2),i,1);
fprintf(fid,'%s', samplenames{i});
fprintf(fid, ',%g', pool.binmatrix(:,i)');
fprintf(fid, '\r\n');
end
end
updateWB(pool,size(pool.binmatrix,2),i,0);
fclose(fid);
statusbox(pool,'...done...');
%% print all Peaks
if strcmp(pool.anaMode,'TBP') || (strcmp(pool.anaMode,'SSR') && pool.selC==1)
statusbox(pool,'...all peak positions...');
fname = strcat(pool.Date,'PeakPos.txt');
fid=fopen(fullfile(pool.txtpathmkdir,fname),'w');
for i=1:1:size(samplenames,2)
updateWB(pool,size(samplenames,2),i,1);
if i~=1
fprintf(fid, '\r\n');
fprintf(fid, '\r\n');
end
fprintf(fid, 'File: %s',samplenames{i});
fprintf(fid, '\r\n');
for u=1:1:size(pool.corrPeakData,2)
fprintf(fid, '\r\n');
fprintf(fid, 'Peak Locations - %s',dyenames(u,:));
fprintf(fid, '\r\n');
fprintf(fid, 'X');
fprintf(fid, '\t');
fprintf(fid, '\t');
fprintf(fid, 'Y');
fprintf(fid, '\r\n');
for z=1:1:size(pool.corrPeakData{i,u},1)
fprintf(fid, '%g',pool.corrPeakData{i,u}(z,1));
fprintf(fid, '\t');
fprintf(fid, '\t');
fprintf(fid, '%g',pool.corrPeakData{i,u}(z,2));
fprintf(fid, '\r\n');
end
end
end
updateWB(pool,size(samplenames,2),i,0);
fclose(fid);
statusbox(pool,'...done...');
end
%% print Fragmentsize
statusbox(pool,'...fragmentsize of selected dye channel...');
fname = strcat(pool.Date,'FragmentsizeBasePairs.',pool.dyenames(pool.selC,:),'.txt');
fid=fopen(fullfile(pool.txtpathmkdir,fname),'w');
if strcmp(pool.anaMode,'SSR')
fprintf(fid, 'Color: %s',dyenames(pool.selC,:));
fprintf(fid, ' || bp = base pairs');
fprintf(fid, '\r\n');
fprintf(fid, '-------------------------------');
fprintf(fid, '\r\n');
for i=1:1:size(samplenames,2)
updateWB(pool,size(samplenames,2),i,1);
if i~=1%&& i~=size(samplenames,2) für später... hehe
fprintf(fid, '\r\n');
fprintf(fid, '\r\n');
end
fprintf(fid, 'File: %s',samplenames{i});
fprintf(fid, '\r\n');
for u=1:1:size(pool.fragmentsize{i}.locus,2)
locus=strcat('Locus',{' '},num2str(u),{' '},'"',pool.ssr.lociUI.NAME{u},'":',{' '});
fprintf(fid,'%s', locus{1});
fprintf(fid, '\r\n');
for z=1:1:size(pool.fragmentsize{i}.locus{u},2)
fprintf(fid, '%g',pool.fragmentsize{i}.locus{u}(z));
fprintf(fid, '\t');
fprintf(fid, 'bp');
fprintf(fid, '\r\n');
end
end
end
else
fprintf(fid, 'Color: %s',dyenames(pool.selC,:));
fprintf(fid, ' || bp = base pairs');
fprintf(fid, '\r\n');
fprintf(fid, '-------------------------------');
fprintf(fid, '\r\n');
for i=1:1:size(samplenames,2)
updateWB(pool,size(samplenames,2),i,1);
if i~=1%&& i~=size(samplenames,2) für später... hehe
fprintf(fid, '\r\n');
fprintf(fid, '\r\n');
end
fprintf(fid, 'File: %s',samplenames{i});
fprintf(fid, '\r\n');
for u=1:1:size(pool.fragmentsize{i},2)
fprintf(fid, '%g',pool.fragmentsize{i}(u));
fprintf(fid, '\t');
fprintf(fid, 'bp');
fprintf(fid, '\r\n');
end
end
end
updateWB(pool,size(samplenames,2),i,0);
fclose(fid);
statusbox(pool,'...done...');
%% print Jaccard distance and index
if strcmp(pool.anaMode,'TBP')
if isempty(pool.statistics)
statusbox(pool,'Error: Analysis failed.');
return;
end
statusbox(pool,'...jaccard distance and index...');
sqJD = squareform(pool.statistics.JD);%percental equality
sqJI = squareform(pool.statistics.JI);%percental defference
fnameJD = strcat(pool.Date,'JaccardDistance.',pool.dyenames(pool.selC,:),'.txt');
fidJD=fopen(fullfile(pool.txtpathmkdir,fnameJD),'w');
for i=1:1:size(sqJD,1)
updateWB(pool,size(sqJD,1),i,1);
for u=1:1:length(sqJD)
fprintf(fidJD, '%.4g\t\t', sqJD(i,u));
end
fprintf(fidJD, '\r\n');
end
updateWB(pool,size(sqJD,1),i,0);
fclose(fidJD);
fnameJI = strcat(pool.Date,'JaccardIndex.',pool.dyenames(pool.selC,:),'.txt');
fidJI=fopen(fullfile(pool.txtpathmkdir,fnameJI),'w');
for i=1:1:size(sqJI,1)
updateWB(pool,size(sqJI,1),i,1);
for u=1:1:length(sqJI)
fprintf(fidJI, '%.4g\t\t', sqJI(i,u));
end
fprintf(fidJI, '\r\n');
end
updateWB(pool,size(sqJI,1),i,0);
fclose(fidJI);
fnameJ = strcat(pool.Date,'JaccardValues.',pool.dyenames(pool.selC,:),'.txt');
fidJ=fopen(fullfile(pool.txtpathmkdir,fnameJ),'w');
fprintf(fid, '"Jaccard Index"');
fprintf(fidJ, '\r\n');
fprintf(fidJ, 'Percentage share of non-zero positions that differ');
fprintf(fidJ, '\r\n');
for i=1:1:size(sqJI,1)
updateWB(pool,size(sqJI,1),i,1);
for u=1:1:length(sqJI)
fprintf(fidJ, '%.4g\t\t', sqJI(i,u));
end
fprintf(fidJ, '\r\n');
end
updateWB(pool,size(sqJI,1),i,0);
fprintf(fidJ, '\r\n');
fprintf(fidJ, '\r\n');
fprintf(fid, '"Jaccard Distance"');
fprintf(fidJ, '\r\n');
fprintf(fidJ, 'Percentage share of non-zero positions that are the same (1 - Jaccard Index)');
fprintf(fidJ, '\r\n');
for i=1:1:size(sqJI,1)
updateWB(pool,size(sqJI,1),i,1);
for u=1:1:length(sqJD)
fprintf(fidJ, '%.4g\t\t', sqJD(i,u));
end
fprintf(fidJ, '\r\n');
end
updateWB(pool,size(sqJI,1),i,0);
fclose(fidJ);
statusbox(pool,'...done...');
end
%% print statistics
if strcmp(pool.anaMode,'TBP')
statusbox(pool,'...statistical data...');
fname = strcat(pool.Date,'StatisticalData.',pool.dyenames(pool.selC,:),'.txt');
fid=fopen(fullfile(pool.txtpathmkdir,fname),'w');
fprintf(fid, 'User Threshold:\t%0.f \r\n',pool.minTH);
fprintf(fid, 'Color: %s \r\n',dyenames(pool.selC,:));
fprintf(fid, '\r\n');
fprintf(fid, 'Statistics: \r\n');
fprintf(fid, '\r\n');
fprintf(fid, 'Number of selected Dye Data:\t%0.f\r\n',pool.selC);
fprintf(fid, '\r\n');
fprintf(fid, 'Number of different Species:\t%0.f\r\n',pool.statistics.differentaccessionsC);
fprintf(fid, '\r\n');
fprintf(fid, 'Cophenetic correlation coefficient:\t%0.4f\r\n',pool.statistics.cophen);
fprintf(fid, 'Expected Heterozygosity (EH):\t\t%0.4f\r\n',pool.statistics.H);
fprintf(fid, 'Polymorphism Information Content (PIC):\t%0.4f\r\n',pool.statistics.PIC);
fprintf(fid, '\r\n');
fprintf(fid, 'Positions of Monomorphic Bands: \r\n');
for j=1:1:length(pool.statistics.monoMbands)
updateWB(pool,length(pool.statistics.monoMbands),i,1);
specname(j) = pool.species(pool.statistics.specC{j}(1));
fprintf(fid,'%s\t(%0.f)\t:\t',specname{j},length(pool.statistics.monoMbands{j}));
for i=1:1:length(pool.statistics.monoMbands{j})
fprintf(fid, '%0.f,',pool.statistics.monoMbands{j}(i));
end
fprintf(fid, '\r\n');
end
updateWB(pool,length(pool.statistics.monoMbands),i,0);
fprintf(fid, '\r\n');
fprintf(fid, 'Positions of Polymorphic Bands: \r\n');
for j=1:1:length(pool.statistics.polyMbands)
updateWB(pool,length(pool.statistics.polyMbands),j,1);
fprintf(fid, '%s\t(%0.f)\t:\t',specname{j},length(pool.statistics.polyMbands{j}));
for i=1:1:length(pool.statistics.polyMbands{j})
fprintf(fid, '%0.f,',pool.statistics.polyMbands{j}(i));
end
fprintf(fid, '\r\n');
end
updateWB(pool,length(pool.statistics.polyMbands),i,0);
fprintf(fid, '\r\n');
fprintf(fid, 'Sum of all allels: %0.f \r\n',pool.statistics.allelc);
fprintf(fid, '\r\n');
fprintf(fid, 'Sum of allels in each Species: \r\n');
for i=1:1:length(pool.statistics.specC)
updateWB(pool,length(pool.statistics.specC),i,1);
fprintf(fid, '%0.f\t:\t%s\r\n',length(pool.statistics.polyMbands{i}),specname{i});
end
updateWB(pool,length(pool.statistics.specC),i,0);
fprintf(fid, '\r\n');
fprintf(fid, 'Sum of allels in each Accession: \r\n');
for i=1:1:length(pool.filename)
updateWB(pool,length(pool.filename),i,1);
fname = strsplit(pool.filename{i},'.');
fprintf(fid, '%0.f\t:\t%s\r\n',pool.statistics.allelc2{i},fname{1});
end
updateWB(pool,length(pool.filename),i,0);
fprintf(fid, '\r\n');
fprintf(fid, 'Allelfrequency for each allel:\r\n');
fprintf(fid, '\r\n');
fprintf(fid, 'Length of fragment:\tAllelfrequency:\r\n');
allelfreq = pool.statistics.allelfreq';
for i=1:1:length(pool.statistics.allBands)
updateWB(pool,length(pool.statistics.allBands),i,1);
fprintf(fid, '%0.f \t\t\t',pool.statistics.allBands(i));
fprintf(fid, '%0.5f',allelfreq(i));
fprintf(fid, '\r\n');
end
updateWB(pool,length(pool.statistics.allBands),i,0);
fprintf(fid, '=====================================\r\n');
fprintf(fid, 'Sum of all frequencies:\t %0.6f \r\n',sum(allelfreq));
fclose(fid);
statusbox(pool,'...done.');
end
%%
statusbox(pool,'...SSR allel table...');
fname = strcat(pool.Date,'allelTable.',pool.dyenames(pool.selC,:),'.txt');
fid=fopen(fullfile(pool.txtpathmkdir,fname),'w');
for i=1:1:size(pool.filename,2)
updateWB(pool,size(pool.filename,2),i,1);
for u=1:1:size(pool.ssr.fragmentsizeREPh{i}.locus,2)
fprintf(fid, '%s\t\t%s\t\tL%g\t\t',samplenames{i},pool.ssr.lociUI.NAME{u},u);
if (size(pool.ssr.fragmentsizeREPh{i}.locus{u},2)==1 && pool.ssr.fragmentsizeREPh{i}.locus{u} ~= 0)
fprintf(fid, '%g\t\t%g',pool.ssr.fragmentsizeREPh{i}.locus{u}(1),pool.ssr.fragmentsizeREPh{i}.locus{u}(1));
else
for z=1:1:size(pool.ssr.fragmentsizeREPh{i}.locus{u},2)
if pool.ssr.fragmentsizeREPh{i}.locus{u}(z)
fprintf(fid, '%g\t\t',pool.ssr.fragmentsizeREPh{i}.locus{u}(z));
else
fprintf(fid, 'NO PEAKS \t NO PEAKS');
end
end
end
fprintf(fid, '\r\n');
end
% fprintf(fid, '\r\n');
end
fclose(fid);
updateWB(pool,length(pool.filename),i,0);
statusbox(pool,'...done.');
end