function nn = degeneracySetSize(degen, overlap, hamming)
%degeneracySetPvalue - calculates size of set of nmers
%
%  S = degeneracySetSize(DEGEN, M, H)
%
%  DEGEN is a vector with the # of possibilities for each
%        degenerate base in the degenerate consensus sequence
%        ASC -->  [1 2 1] and AAVG -->  [1 1 3 1]
%
%  M is the overlap between the consensus sequence and the
%    degenerate sequence motif.  DEFAULT LENGTH(DEGEN)
%    Note that if M < LENGTH(DEGEN) then S is only an
%    upper bound on the on the set size (because some
%    subsequences could be identical).
%
%  H is the hamming distance from the target sequence
%    to the closest member of the degenerate set.  e.g
%    "ASC" has hamming distance 0 to ACC but 1 to ATC.
%    DEFAULT 0
%
%  S is the size of the set of M-mers (where M is the length of the overlap)
%    hamming distance H or less to the closest member of the set covered
%    by DEGEN
%
%  This function is only designed for hamming distances of 0 or 1
%
%  Written by Quaid Morris, May 2006

if nargin == 1 | (nargin == 2 & overlap == length(degen)) | ...
        (nargin == 3 & overlap == length(degen) & hamming == 0)
    nn = prod(degen);
elseif nargin == 2
    if overlap > length(degen) | overlap < 1
        error('OVERLAP must be >0 and < LENGTH(DEGEN)');
    else
        nn = degeneracySetSize(degen(1:overlap));
        for ii = 1:length(degen)-overlap
            nn = nn + degeneracySetSize(degen(ii+1:overlap+ii));
        end
    end
elseif nargin == 3
    if hamming > 1
        error('Currently only handles HAMMING distances of 0 or 1');
    end
    nn = degeneracySetSize(degen, overlap);
    for ii = 1:length(degen)
        dd = degen;
        dd(ii) = 4-dd(ii);
        nn = nn + degeneracySetSize(dd, overlap);
    end
end

    



