%==============================================================================
%    find_dup_genomes.m
%    Copyright (C) 2007  Amoolya H. Singh, singh@embl.de
%
%    This program is free software: you can redistribute it and/or modify
%    it under the terms of the GNU General Public License as published by
%    the Free Software Foundation, either version 3 of the License, or
%    (at your option) any later version.
%
%    This program is distributed in the hope that it will be useful,
%    but WITHOUT ANY WARRANTY; without even the implied warranty of
%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%    GNU General Public License for more details.
%
%    You should have received a copy of the GNU General Public License
%    along with this program.  If not, see <http://www.gnu.org/licenses/>.
%===============================================================================
function t = find_dup_genomes(frac)
%------------------------------------------------------------------------------
%
% t = find_dup_genomes(frac) recommends phylogenetically duplicate
% genomes to remove from the analysis
%
% Input: 
%   frac, threshold of shared orthologs above which genomes are
%         considered duplicate (ranges between 0 and 1)
% Output:
%   t, indices of duplicate genomes in taxid vector
%
%------------------------------------------------------------------------------

load orthdata.mat;
[i,j] = find(F > frac);

[S(i,:),S(j,:)];

matrix = connected(i,j);
ncols = size(matrix,2);
keep = matrix(:,1);

m = matrix(:,2:end);
foo = reshape(m,1,prod(size(m)));
discard = foo(find(foo));

S(keep,:);
S(discard,:);

F = fopen('~/../db/duplicate-species.txt','w');
for k=1:length(discard)
  fprintf(F,'%s\n',deblank(S(discard(k),:)));
end
fclose(F);

t = string_taxids(discard);



