-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_mutations.m
153 lines (137 loc) · 4.72 KB
/
get_mutations.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
% Code to determine mutation rates from OR NGS data
% EAJ 10/31/2023
clear
cutoff = 0.000;
names = 'triple_mismatch_figure_3'; %Name of experiment
fignum = 1;
expt = 'nucsko'; %Datasets labeled with 'wt' for wild-type or 'nucsko' for NucS Knock-out strain
directory = ['C:\Users\eajoseph\Box\NucS manuscript\data\' names '\' expt '\']; %Directory with data
mlist = dir([directory '*_R1*.fastq']);
s = 'CCGCAGACCCTGATCAACATCCGTCCCGTCGTGGCGGCGATCAAGGAGTTCTTCGGCACCAGCCAGCTGTCGCAGTTCATGGACCAGAACAACCCGCTGTCGGGTCTGACCCACAAGCGTCGTCTTTCGGCGCTGGGCCCCGGCGGTCTGTCCCGTGAGCGCGCCGGCCTCGAGGTCCGCGACGTGCACCCCAGCCACTACGGCCGCATGTGCCCGATCGAGACCCCTGAGGGTCCCAACATCGGTCTG';
three = ('GAAAGACGACGCTTGTGGGT')
five = ('CTCCTTGATCGCCGCCACGA')
oligos = ['CAGACCCGACAGCGGGTTGTTCTGGTCCATGAACTGCGACAGCTGGCTGGTGCCGAAGAA'];
rifr = 35;
rifrs = 'A';
target = oligos(1,:);
fid = fopen(['C:\Users\eajoseph\Box\NucS manuscript\data\' names '.txt'],'r')
while ~feof(fid)
oligos = [oligos;fgetl(fid)]
end
fclose(fid)
target = oligos(1,:);
mm = find(sum(oligos~=target)~=0);
target(mm)='X';
target = strrep(target,'X','[ATCG]');
%
c=0;
mutG = zeros(numel(mlist),length(oligos(1,:)));
mutA = zeros(numel(mlist),length(oligos(1,:)));
mutT = zeros(numel(mlist),length(oligos(1,:)));
mutC = zeros(numel(mlist),length(oligos(1,:)));
for x = 1:numel(mlist);
fid = fopen([directory 'oligo_region' num2str(x) '.txt'],'w+');
n1o = [directory mlist(x).name]
n2o = strrep(n1o,'_R1_','_R2_');
f1 = fastqread([n1o]);
f2 = fastqread([n2o]);
for y = 1:numel(f1)
forw = char(cellstr(regexp(f2(y).Sequence,target,'match')));
rev = char(cellstr(regexp(seqrcomplement(f1(y).Sequence),target,'match')));
if (length(forw)>0).*(length(rev)>0)
if sum(forw==rev)==length(forw)
if forw(rifr)==rifrs;
fprintf(fid,'%s\n',forw);
end
end
end
end
fclose(fid);
fid = fopen([directory 'oligo_region' num2str(x) '.txt'],'r');
fid2 = fopen([directory 'mutations_at_hotspots' num2str(x) '.txt'],'w+');
while ~feof(fid)
r = fgetl(fid);
for m = 1:numel(mm);
if r(1,mm(m))~=oligos(1,mm(m))
if r(1,mm(m))=='A'
mutA(x,mm(m))=mutA(x,mm(m))+1;
fprintf(fid2,'%s','A');
elseif r(1,mm(m))=='T'
mutT(x,mm(m))=mutT(x,mm(m))+1;
fprintf(fid2,'%s','T');
elseif r(1,mm(m))=='G'
mutG(x,mm(m))=mutG(x,mm(m))+1;
fprintf(fid2,'%s','G');
elseif r(1,mm(m))=='C'
mutC(x,mm(m))=mutC(x,mm(m))+1;
fprintf(fid2,'%s','C');
end
else
fprintf(fid2,'%s','n');
end
end
fprintf(fid2,'\n');
end
fclose(fid) ;
fclose(fid2) ;
end
mut = [mutG+mutC+mutA+mutT]';
mA = mutA(:,sum(mut')~=0)./(max(mut))'*100;
mG = mutG(:,sum(mut')~=0)./(max(mut))'*100;
mC = mutC(:,sum(mut')~=0)./(max(mut))'*100;
mT = mutT(:,sum(mut')~=0)./(max(mut))'*100;
mA(mA==0)=nan;
mC(mC==0)=nan;
mG(mG==0)=nan;
mT(mT==0)=nan;
L = 1:length(oligos(1,:));
L = L(sum(mut')~=0);
figure(fignum);
hold off
%stem(L-.75/2,mA','g.')
scatter(L-.75/2,mA',20,'g','filled','MarkerEdgeColor',[0 0 0],'LineWidth',1)
hold on
scatter(L-0.25/2,mT',20,'r','filled','MarkerEdgeColor',[0 0 0],'LineWidth',1)
scatter(L+.25/2,mG',20,'k','filled','MarkerEdgeColor',[0 0 0],'LineWidth',1)
scatter(L+.75/2,mC',20,'c','filled','MarkerEdgeColor',[0 0 0],'LineWidth',1)
%stem(L-0.25/2,mT','r.')
%stem(L+.25/2,mG','k.')
%stem(L+.75/2,mC','b.')
xticks([1 mm length(oligos(1,:))])
axis([min(mm)-1,max(mm)+1,-0.5 20.5])
gca.FontSize = 6;
drawnow
variant_list='';
for x = 1:numel(mlist);
variants='';
fid = fopen([directory 'mutations_at_hotspots' num2str(x) '.txt'],'r');
while ~feof(fid)
variants = [variants; fgetl(fid)];
end
eval(['v' num2str(x) ' = variants;']);
variant_list = unique([variants;variant_list],'rows');
end
fclose(fid);
v = zeros(size(variant_list,1), 3);
for x = 1:size(variant_list,1)
for y = 1:numel(mlist)
eval(['vv = v' num2str(y) ';']);
v(x,y)=sum(sum(vv==variant_list(x,:),2)==length(variant_list(1,:)));
end
end
meanv = (mean(v./sum(v),2)')';
goodv = find(meanv>=0.003);
goodvar = variant_list(goodv,:);
vorder = sortrows([meanv(goodv) (1:numel(goodv))' ],'descend');
mordered = vorder(:,1);
vorder = vorder(:,2);
sortgoodvar = goodvar(vorder,:);
varmat = nt2int(sortgoodvar);
varmat(varmat==15) = 0;
hold off
figure(fignum+1)
imagesc(varmat)
xticks([1:length(mm)])
xticklabels(mm)
yticks(1:numel(goodv));
yticklabels(mordered);