-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdn_ntfreqdist.m
57 lines (46 loc) · 947 Bytes
/
dn_ntfreqdist.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
function [D]=dn_ntfreqdist(aln)
%DN_NTFREQDIST - Euclidean distances between nucleotide frequencies
%REF: (Orti G & Meyer A 1996 MBE)
%
% Syntax: [D]=dn_ntfreqdist(aln)
%
% Inputs:
% aln - Alignment structure
%
% Outputs:
% D - Distance matrix
%
% See also:
% 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 (isstruct(aln)),
S=aln.seq;
else
S=aln;
end
[n,m] = size(S);
D = zeros(n);
for i=1:n-1
for j=i+1:n
X1 = i_countNtComposition(S(i,:));
X2 = i_countNtComposition(S(j,:));
D(i,j) = sqrt(sum((X1-X2).^2));
D(j,i) = D(i,j);
end
end
function [X] = i_countNtComposition(Seq)
As=Seq==1;
Cs=Seq==2;
Gs=Seq==3;
Ts=Seq==4;
NA=sum(As');
NC=sum(Cs');
NG=sum(Gs');
NT=sum(Ts');
X=cat(2,NA,NC,NG,NT);