function [motifs] = enumerateMotifs(p,varargin) % returns a string cell array that contains all motifs of length p. % Optional argument 'fuzzy' contains the positions in motif that allow % fuzzy letters (i.e. all IUPAC symbols). % Note: a motif and its reverse complement only occurs in the list once. %nargin okargs = {'fuzzy' 'keepcomplements'}; defaults = {[] false}; [eid,emsg,fuzzy,keepcomplements] = mygetargs(okargs,defaults,varargin{:}); fuzzyPositions = zeros(1,p); fuzzyPositions(fuzzy) = 1; nonfuzzy = find(fuzzyPositions==0); numfuzzypos = sum(fuzzyPositions); % --- n is the total number of such motifs. Afuzzy = 15; nonfuzzyn =1; fuzzyn=1; for i=1:p if fuzzyPositions(i) fuzzyn = fuzzyn*Afuzzy; else nonfuzzyn = nonfuzzyn*4; end end n = fuzzyn*nonfuzzyn; motifs = cell(1,n); ind=1; for i=1:fuzzyn for j=1:nonfuzzyn fuzzys = dec2base(i-1,Afuzzy,numfuzzypos); nonfuzzys = dec2base(j-1,4,p-numfuzzypos); s = blanks(p); fcount = 1; count=1; for k=1:p if fuzzyPositions(k) s(k) = fuzzys(fcount); fcount=fcount+1; else s(k) = nonfuzzys(count); count=count+1; end end motifs{ind} = blanks(p); for k=1:length(s) if fuzzyPositions(k) base = Afuzzy; else base=4; end motifs{ind}(k) = int2nt(base2dec(s(k),base)+1); end ind = ind+1; end end if ~keepcomplements % get rid of reverse complements. keep=zeros(1,n); for i=1:n temp = seqreverse(seqcomplement(motifs{i})); x1=0; for j=1:numfuzzypos b = mynt2int(temp(fuzzy(j)))-1; x1 = x1+b*(Afuzzy^(numfuzzypos-j)); end x1=x1; numnonfuzzypos=p-numfuzzypos; x2=0; for j=1:(numnonfuzzypos) b = mynt2int(temp(nonfuzzy(j)))-1; x2 = x2+b*(4^(numnonfuzzypos-j)); end x2=x2+1; tempind = x1*nonfuzzyn+x2; if tempind<=i keep(i) = 1; end % fprintf('%s %s %d\n',motifs{i},motifs{tempind},keep(i)); end motifs=motifs(find(keep)); end