-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtract_data_CRISPResso_Clonal_Edited_Cells.m
More file actions
515 lines (381 loc) · 15.9 KB
/
Copy pathExtract_data_CRISPResso_Clonal_Edited_Cells.m
File metadata and controls
515 lines (381 loc) · 15.9 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
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
%Your current folder must contain the main folder
%containing subfolders of CRISPResso Results.
%Type in command Window the main folder.
prompt = 'Which folder contains subfolders with CRISPResso results? ';
expFolder = input(prompt,'s');
cd(expFolder);
%First Matlab moves all html files to a new folder html
testhtml = dir('*.html')
testhtml2 = numel(testhtml)
if testhtml2 > 0
mkdir html
movefile *.html html
end
%Matlab defines the list of CRISPResso Results subfolders
FolderList = dir(['.' '/CRISP*']);
%Type if you provided the coding sequence to CRISPResso.
prompt = 'Did you provide coding sequence to CRISPResso? (yes/no) ';
coding = input(prompt,'s');
%Depending if you provide the coding sequence MATLAB will extract different
%data
switch coding
case 'yes'
%In the case of providing the coding sequence.
%The next loop iterates the extraction of the following data
%from each subfolder:
%·Total aligned reads from the CRISPResso_mapping_statistics.txt
%·The inframe and frameshift mutations reads from Frameshift_analysis.txt
%·Total unModified and modified reads from the
%CRISPResso_quantification_of_editing_frequency.txt
%·Up to tree Allele frequencies and sequences arising from the
%Alleles_frequency_table_around*.txt
for i=1:numel(FolderList)
cd(FolderList(i).name)
FilenameS = ['CRISPResso_mapping_statistics.txt'];
FilenameF = ['Frameshift_analysis.txt'];
FilenameQ = ['CRISPResso_quantification_of_editing_frequency.txt'];
%Now matlab is going to check if the needed data files are present
%in the current subfolder. Depending of the CRISPResso analysis succes
%there are 2 conditions:
ExistenceFRAME = exist (FilenameS);
ExistenceSIMAP = exist (FilenameF);
TotalExist = ExistenceFRAME + ExistenceSIMAP;
%1.- Successful analysis when coding sequence is provided
%to CRISPResso. All files CRISPResso_mapping_statistics.txt,
%Frameshift_analysis.txt and
%CRISPResso_quantification_of_editing_frequency.txt are generated by
%CRISPResso.
if TotalExist == 4
%textscan generates variables which
%contain in their boxes the isolated values of interest.
fileID = fopen(FilenameF);
Mutationsarray = textscan(fileID,'%s', 'Delimiter',': ');
fileID = fopen(FilenameS);
Readsarray = textscan(fileID,'%s', 'Delimiter','\t');
fileID = fopen(FilenameQ);
Editing_Quantification = textscan(fileID,'%s', 'Delimiter','\t');
variablename = dir ('Alleles_frequency_table_around*.txt');
Allelesfreqdatatxt = variablename.name;
Afq = fopen(Allelesfreqdatatxt);
Allelesfrequencytable = textscan(Afq,'%s', 'Delimiter','\t');
%Matlab fixes Alignedreads, InFrameMutations, FrameshiftMutations
%UnModified_reads and UnModified_reads by calling the boxes containing
%the values of interest.
Alignedreads{i} = Readsarray{1, 1}{10, 1};
InFrameMutations{i} = Mutationsarray{1, 1}{9, 1};
FrameshiftMutations{i} = Mutationsarray{1, 1}{13, 1};
UnModified_reads{i} = Editing_Quantification{1,1}{26,1};
Modified_reads{i} = Editing_Quantification{1,1}{27,1};
Allele1Seq{i} = Allelesfrequencytable{1, 1}{9, 1};
Allele1Frequency{i} = Allelesfrequencytable{1, 1}{16, 1};
Ref_Sequence{i} = Allelesfrequencytable{1, 1}{10, 1};
%Matlab fixes up to tree allele sequences and frequencies in case they
%are detected by CRISPResso.
switch numel(Allelesfrequencytable{1})
case 16 %Only one allele is detected
Allele2Seq{i} = 'NaN';
Allele2Frequency{i} = 'NaN';
Allele3Seq{i} = 'NaN';
Allele3Frequency{i} = 'NaN';
case 24 %Only two alleles are detected
Allele2Seq{i} = Allelesfrequencytable{1, 1}{17, 1};
Allele2Frequency{i} = Allelesfrequencytable{1, 1}{24, 1};
Allele3Seq{i} = 'NaN';
Allele3Frequency{i} = 'NaN';
otherwise %More than two alleles are detected
Allele2Seq{i} = Allelesfrequencytable{1, 1}{17, 1};
Allele2Frequency{i} = Allelesfrequencytable{1, 1}{24, 1};
Allele3Seq{i} = Allelesfrequencytable{1, 1}{25, 1};
Allele3Frequency{i} = Allelesfrequencytable{1, 1}{32, 1}
end
end
%2.-NOT Successful analysis. Any of the needed files
%are generated by CRISPResso.
%Matlab fixes Alignedreads, UnModified_reads, Modified_reads,
%InFrameMutations and FrameshiftMutations with NaN because in
%these case are NOT calculated by CRISPResso.
if TotalExist == 0
Alignedreads{i} = 'NaN';
InFrameMutations{i} = 'NaN';
FrameshiftMutations{i} = 'NaN';
UnModified_reads{i} = 'NaN';
Modified_reads{i} = 'NaN';
Allele1Seq{i} = 'NaN';
Allele1Frequency{i} = 'NaN';
Ref_Sequence{i} = 'NaN';
Allele2Seq{i} = 'NaN';
Allele2Frequency{i} = 'NaN';
Allele3Seq{i} = 'NaN';
Allele3Frequency{i} = 'NaN';
end
%Matlab exits the current subfolder to start in the next one.
fclose('all')
cd ..
end
%Finally Matlab calculates:
%Percentage of reads: Un-modified, modified, with Frameshift mutations,
%with In-Frame mutations and with total NHEJ events.
%Commands as str2num char are used to make variables compatible for
%math operations.
%char transforms cell to character string and str2num
%transform to number.
for i = 1:numel(FolderList)
FS_percentage(i) = (str2num(char(FrameshiftMutations(i)))...
/str2num(char(Alignedreads(i)))) * 100;
IF_percentage(i) = (str2num(char(InFrameMutations(i)))...
/str2num(char(Alignedreads(i)))) * 100;
UnMod_percentage(i) = (str2num(char(UnModified_reads(i)))...
/str2num(char(Alignedreads(i)))) * 100;
Mod_percentage(i) = (str2num(char(Modified_reads(i)))...
/str2num(char(Alignedreads(i)))) * 100;
end
%Set percentage values cut off for homozigosity or heterozigosity.
%Matlab uses this values to assign genotypes.
%Those samples presenting allele 1 frequency higher than 80% are considered
%homozigotes. Those samples presenting allele 1 and 2 frecuencies
%higher than 40% are considered heterozigotes.
cutoff_hom = 80
cutoff_het = 40
for i = 1:numel(FolderList)
%wtwt assigment
if (UnMod_percentage(1,i) > cutoff_hom) & ...
(str2double(Allele1Frequency(1,i)) > cutoff_hom)
wtwt(i) = 1
else
wtwt(i) = 0
end
%ifwt assigment
if (IF_percentage(1,i) > cutoff_het) & ...
(UnMod_percentage(1,i) > cutoff_het) & ...
(str2double(Allele1Frequency(1,i)) > cutoff_het) & ...
(str2double(Allele2Frequency(1,i)) > cutoff_het)
ifwt(i) = 1
else
ifwt(i) = 0
end
%ifif assigment
if (IF_percentage(1,i) > cutoff_hom) & ...
( (str2double(Allele1Frequency(1,i)) > cutoff_hom) | ...
((str2double(Allele1Frequency(1,i)) > cutoff_het) & ...
(str2double(Allele2Frequency(1,i)) > cutoff_het)))
ifif(i) = 1
else
ifif(i) = 0
end
%fsif assigment
if (FS_percentage(1,i) > cutoff_het) & ...
(IF_percentage(1,i) > cutoff_het) & ...
(str2double(Allele1Frequency(1,i)) > cutoff_het) & ...
(str2double(Allele2Frequency(1,i)) > cutoff_het)
fsif(i) = 1
else
fsif(i) = 0
end
%fswt assigment
if (FS_percentage(1,i) > cutoff_het) & ...
(UnMod_percentage(1,i) > cutoff_het) & ...
(str2double(Allele1Frequency(1,i)) > cutoff_het) & ...
(str2double(Allele2Frequency(1,i)) > cutoff_het)
fswt(i) = 1
else
fswt(i) = 0
end
%fsfs assigment
if (FS_percentage(1,i) > cutoff_hom) & ...
( (str2double(Allele1Frequency(1,i)) > cutoff_hom) | ...
((str2double(Allele1Frequency(1,i)) > cutoff_het) & ...
(str2double(Allele2Frequency(1,i)) > cutoff_het)))
fsfs(i) = 1
else
fsfs(i) = 0
end
%mixed clone assigment
if (wtwt(i) + ifwt(i) + ifif(i) + fsif(i) + fswt(i) + fsfs(i)) == 0
mixed(i) = 1
else
mixed(i) = 0
end
end
%Finally, matlab builds a table that writes everything in a excel file
%(.xlsx file)
TableMyseqExperiments = table(char(FolderList(1:numel(FolderList)).name),...
char(Alignedreads{1,:}),...
char(FrameshiftMutations),...
char(InFrameMutations), ...
transpose(UnModified_reads),...
transpose(FS_percentage), ...
transpose(IF_percentage), ...
transpose(UnMod_percentage),...
transpose(Mod_percentage),...
char(Allele1Frequency{1,:}),...
char(Allele1Seq{1,:}),...
char(Allele2Frequency{1,:}),...
char(Allele2Seq{1,:}),...
char(Allele3Frequency{1,:}),...
char(Allele3Seq{1,:}),...
char(Ref_Sequence{1,:}), transpose(wtwt), transpose(ifwt),...
transpose(ifif), transpose(fsif), transpose(fswt),...
transpose(fsfs), transpose(mixed) )
TableMyseqExperiments.Properties.VariableNames = {'Sample' ...
'Aligned_Reads' 'Frameshift_Mutations' 'InFrame_Mutations' ...
'UnModified_Reads' 'Percentage_FSmut' 'Percentage_IFmut'...
'Percentage_UnMod' 'Percentage_Mod' 'Allele1_Freq' 'Allele1_Seq' ...
'Allele2_Freq' 'Allele2_Seq' 'Allele3_Freq' 'Allele3_Seq'...
'Ref_Sequence' 'wtwt' 'ifwt' 'ifif' 'fsif' 'fswt' 'fsfs'...
'mixedclone'}
writetable(TableMyseqExperiments,[expFolder '.xlsx'])
case 'no'
%In the case of NOT providing the coding sequence.
%The next loop iterates the extraction of the following data
%from each subfolder:
%·Total aligned reads from the CRISPResso_mapping_statistics.txt
%·Total unModified and Modified reads from the
%CRISPResso_quantification_of_editing_frequency.txt
%·Up to tree Allele frequencies and sequences arising from the
%Alleles_frequency_table_around*.txt
for i=1:numel(FolderList)
cd(FolderList(i).name)
FilenameS = ['CRISPResso_mapping_statistics.txt'];
FilenameQ = ['CRISPResso_quantification_of_editing_frequency.txt'];
%Now matlab is going to check if the needed data files are present
%in the current subfolder. Depending of the CRISPResso analysis succes
%there are 2 conditions:
ExistenceFRAME = exist (FilenameS);
%1.-Successful analysis when coding sequence is NOT
%provided to CRISPResso. Only CRISPResso_mapping_statistics.txt and
%CRISPResso_quantification_of_editing_frequency.txt are generated by
%CRISPResso.
if ExistenceFRAME == 2
%textscan command generates variables which
%contain in their boxes the isolated values of interest.
fileID = fopen(FilenameS);
Readsarray = textscan(fileID,'%s', 'Delimiter','\t');
fileID = fopen(FilenameQ);
Editing_Quantification = textscan(fileID,'%s', 'Delimiter','\t');
variablename = dir ('Alleles_frequency_table_around*.txt');
Allelesfreqdatatxt = variablename.name;
Afq = fopen(Allelesfreqdatatxt);
Allelesfrequencytable = textscan(Afq,'%s', 'Delimiter','\t');
%Matlab fixes Alignedreads, UnModified_reads and Modified reads
%by calling the boxes containing the values of interest.
%InFrameMutations and FrameshiftMutations
%are asigned with NaN because they are NOT calculated by CRISPResso.
Alignedreads{i} = Readsarray{1, 1}{10, 1};
UnModified_reads{i} = Editing_Quantification{1,1}{24,1};
Modified_reads{i} = Editing_Quantification{1,1}{25,1};
Allele1Seq{i} = Allelesfrequencytable{1, 1}{9, 1};
Allele1Frequency{i} = Allelesfrequencytable{1, 1}{16, 1};
Ref_Sequence{i} = Allelesfrequencytable{1, 1}{10, 1};
switch numel(Allelesfrequencytable{1})
case 16
Allele2Seq{i} = 'NaN';
Allele2Frequency{i} = 'NaN';
Allele3Seq{i} = 'NaN';
Allele3Frequency{i} = 'NaN';
case 24
Allele2Seq{i} = Allelesfrequencytable{1, 1}{17, 1};
Allele2Frequency{i} = Allelesfrequencytable{1, 1}{24, 1};
Allele3Seq{i} = 'NaN';
Allele3Frequency{i} = 'NaN';
otherwise
Allele2Seq{i} = Allelesfrequencytable{1, 1}{17, 1};
Allele2Frequency{i} = Allelesfrequencytable{1, 1}{24, 1};
Allele3Seq{i} = Allelesfrequencytable{1, 1}{25, 1};
Allele3Frequency{i} = Allelesfrequencytable{1, 1}{32, 1}
end
end
%3.-NOT Successful analysis. Any of the needed files
%are generated by CRISPResso.
%Matlab fixes Alignedreads, UnModified_reads,
%Modified_reads, InFrameMutations and FrameshiftMutations with NaN because in
%these case are NOT calculated by CRISPResso.
if TotalExist == 0
Alignedreads{i} = 'NaN';
UnModified_reads{i} = 'NaN';
Modified_reads{i} = 'NaN';
Allele1Seq{i} = 'NaN';
Allele1Frequency{i} = 'NaN';
Ref_Sequence{i} = 'NaN';
Allele2Seq{i} = 'NaN';
Allele2Frequency{i} = 'NaN';
Allele3Seq{i} = 'NaN';
Allele3Frequency{i} = 'NaN';
end
%Matlab exits the current subfolder to start in the next one.
fclose('all')
cd ..
end
%Finally Matlab calculates:
%Percentage of reads: Un-modified, with Frameshift mutations, with
%In-Frame mutations and with total NHEJ events.
%Commands as str2num char are used to make variables compatible for
%math operations.
%char transforms cell to character string and str2num transform to number.
for i = 1:numel(FolderList)
UnMod_percentage(i) = (str2num(char(UnModified_reads(i)))...
/str2num(char(Alignedreads(i)))) * 100;
Mod_percentage(i) = (str2num(char(Modified_reads(i)))...
/str2num(char(Alignedreads(i)))) * 100;
end
%Set percentage values cutoff for homozigosity or heterozigosity
cutoff_hom = 80
cutoff_het = 40
for i = 1:numel(FolderList)
%wtwt conditional
if (UnMod_percentage(1,i) > cutoff_hom) & ...
(str2double(Allele1Frequency(1,i)) > cutoff_hom)
wtwt(i) = 1
else
wtwt(i) = 0
end
%wtmut conditional
if (UnMod_percentage(1,i) > cutoff_het) & ...
(Mod_percentage(1,i) > cutoff_het) & ...
(str2double(Allele1Frequency(1,i)) > cutoff_het) & ...
(str2double(Allele2Frequency(1,i)) > cutoff_het)
wtmut(i) = 1
else
wtmut(i) = 0
end
%mutmut conditional
if (Mod_percentage(1,i) > cutoff_hom) & ...
( (str2double(Allele1Frequency(1,i)) > cutoff_hom) | ...
((str2double(Allele1Frequency(1,i)) > cutoff_het) & ...
(str2double(Allele2Frequency(1,i)) > cutoff_het)))
mutmut(i) = 1
else
mutmut(i) = 0
end
%mixed clone conditional
if (wtwt(i) + wtmut(i) + mutmut(i)) == 0
mixed(i) = 1
else
mixed(i) = 0
end
end
%Finally, matlab builds a table that writes everything in a excel file
%(.xlsx file)
TableMyseqExperiments = table(char(FolderList(1:numel(FolderList)).name),...
char(Alignedreads{1,:}),...
transpose(UnModified_reads),...
transpose(Modified_reads),...
transpose(UnMod_percentage),...
transpose(Mod_percentage),...
char(Allele1Frequency{1,:}),...
char(Allele1Seq{1,:}),...
char(Allele2Frequency{1,:}),...
char(Allele2Seq{1,:}),...
char(Allele3Frequency{1,:}),...
char(Allele3Seq{1,:}),...
char(Ref_Sequence{1,:}), transpose(wtwt), transpose(wtmut),...
transpose(mutmut), transpose(mixed))
TableMyseqExperiments.Properties.VariableNames = {'Sample' ...
'Aligned_Reads' ...
'UnModified_Reads' 'Modified_Reads'...
'Percentage_UnMod' 'Percentage_Mod' 'Allele1_Freq' 'Allele1_Seq' ...
'Allele2_Freq' 'Allele2_Seq' 'Allele3_Freq' 'Allele3_Seq'...
'Ref_Sequence' 'wtwt' 'wtmut' 'mutmut' ...
'mixedclone'}
writetable(TableMyseqExperiments,[expFolder '.xlsx'])
cd ..
end