%%%%%%% % bioadjmat.m % Author: Lance Harden, Davidson College % June 2006 % % Description: Bioadjmat creates an adjacency matrix for all signed % permutations of length k that are molecularly unique. The input s allows % the user to choose between 1 or 2 spatulas (prefix sorting by reversals % vs. sorting by reversals). function [adj] = bioadjmat(k,s) if nargin < 2, s = 2; end B = bioperms(k); b = length(B); adj = zeros(b); if s == 1 for j = 1:b P = B(j,:); for FL = 1:k range = FL - 1; G = [fliplr(P(1:range)) P(FL:k)]; for f = 1:range G(f) = -G(f); end comp = -(fliplr(G)); for i = 1:b if ( all(G == B(i,:)) || all(comp == B(i,:)) ) adj(i,j) = 1; break end end end end else for j = 1:b P = B(j,:); for FL = 1:k range = FL - 1; for t = 1:(k+1-FL) G = [P(1:t-1) fliplr(P(t:t+range)) P(t+FL:k)]; for f = t:t+range G(f) = -G(f); end comp = -(fliplr(G)); for i = 1:b if ( all(G == B(i,:)) || all(comp == B(i,:)) ) adj(i,j) = 1; break end end end end end end