rewrite the seqneighjoin function in matlab -
i have task rewrite seqneighjoin function in matlab adding frequency of sequences. after searching, understand function returns phylogenetic tree object obtained seqences neighbor joinn method wiki http://en.wikipedia.org/wiki/neighbor_joining now, have following 2 questions. (1): data structure of phytree object obtained function? how express it? example, similar linkage function, returns phylogenetic tree, , data structure clear there, i.e., matrix 3 columns, i-th column indicates nodes combined , corresponding distance when combined. time , attention.
(2): based on wiki, how supposed add frequency function seqneighjoin? totally confused.
thanks time , attention. appreciate that.
edit: following code.
function z = seqneighjoin(d_all, freq) n = size (d_all, 2); m=(1+sqrt(8*n+1))/2; z=zeros(m-1,3); q=zeros(m,m); str = zeros (m,m); % initialize distance matrix d d=ones(m,m); d(tril(d,-1)==1)=d_all; d(triu(d,1)==1)=d_all; d(eye(m,m)==1) = 1:m; % diagonal entries of matrix d indices of clusters % initialize matrix str r=1:m c=1:m str(r,c)=freq(r)*freq(c)*d(r,c); str(c,r)=freq(r)*freq(c); end end % loop through m-1 times create matrix z k = 1:m-1 % initialize (for first time) or update (for other times) % matrix q colsum = sum(d, 1); rowsum=sum(d,2); a=size(colsum, 2); colsumm=colsum(ones(a,1),:); rowsunm=rowsum(:,ones(1,a)); q=(a-2)*d-colsumm-rowsumm; % find minimum element in matrix q u=min(q); v=min(u); [i,j]=find(q==v); r=i(1); c=j(1); % combine d(r,r) , d(c,c) new node m+k z(k,:)=[d(r,r), d(c,c), v]; % calculate distance between new node m+k , other node % not m+k d(r,:) = (d(r,:) + d(c,:) - d(r,c) )/2; d(r,r) = m+k; d(c,:)=[]; d(:,c)=[]; end
here, d_all vector representation of distance matrix returned seqpdist function in matlab, , freq vector indicating frequency of sequences.
Comments
Post a Comment