-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcodonvolatility.m
99 lines (79 loc) · 2.04 KB
/
codonvolatility.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
function [v,V] = codonvolatility(aln)
%CODONVOLATILITY - Calculates codon volatility
%REFERENCE: JOSHUA B. PLOTKIN, JONATHAN DUSHOFF & HUNTER B. FRASER, Detecting
%selection using a single genome sequence of M. tuberculosis and P. falciparum
%
% Syntax: [v,V] = codonvolatility(aln)
%
% Inputs:
% aln - Input sequences (Alignment struct)
%
% Outputs:
% v - Mean codon volatility for input sequences
% V - Matrix containing codon volatility for each codon
%
% See also: GETSYNNONSYNSITES, GETSYNNONSYNDIFF
% Molecular Biology and Evolution Toolbox (MBEToolbox)
% Author: James Cai
% Email: jcai@tamu.edu
% Website: http://bioinformatics.org/mbetoolbox/
%
% $LastChangedDate: 2013-01-05 12:04:29 -0600 (Sat, 05 Jan 2013) $
% $LastChangedRevision: 327 $
% $LastChangedBy: jcai $
if ~(isvalidaln(aln,'CODING'))
error ('ERROR: Not coding seq')
end
if (hasgap(aln))
disp ('WARNING: Sequences cannot contain gaps. Gaps will be removed by using REMOVEGAPS.')
aln=rmcodongaps(aln);
end
global CODON TABLE stops icode
h = waitbar(0.15,'Please wait...');
icode=aln.geneticcode;
[CodonSeq]=codonise64(aln.seq);
[n,m3]=size(aln.seq);
m=m3/3;
V=zeros(n,m);
[TABLE,CODON] = codontable;
stops=find(TABLE(icode,:)=='*');
if (m>64)
SN=zeros(1,64);
for (k=1:64), [SN(1,k)] = cal_v(k); end
V=SN(CodonSeq);
else
for i=15:30, waitbar(i/100,h); end
for (i=1:n),
seq=CodonSeq(i,:);
for (j=1:m),
cdon=seq(1,j);
V(i,j)=V(i,j)+cal_v(cdon);
end % for (j=1:m)
end
for i=30:95, waitbar(i/100,h); end
end
v = sum(V,2)./m;
waitbar(1,h);
close(h);
%%%%%%%%%%%%%
%%% SUBS %%%
%%%%%%%%%%%%%
function [v] = cal_v(cdon)
%Calculate codon volatility for single codon
global CODON TABLE stops icode
if ~(ismember(cdon,stops))
SynDif=0;
AsynDif=0;
for (k=1:64)
if ~(ismember(k,stops))
ndiff=sum(CODON(cdon,:)~=CODON(k,:));
if (ndiff==1)
SynDif = SynDif + (TABLE(icode,k)==TABLE(icode,cdon));
AsynDif = AsynDif + (TABLE(icode,k)~=TABLE(icode,cdon));
end
end
end
v = AsynDif./(AsynDif+SynDif);
else
v = 0;
end