% function [clusterData] = computeClusterInfoBioInf(data, clusterID) 
% computeClusterInfoBioInf provides a summary of clusters in a given 
% clustering solution, including mean coordinates, standard deviation, and
% cardinality. It requires the original input data and the clustering
% solution in the form of an array of cluster IDs, one for each data point.
%
% This file is part of Cluster4MetaAnalysis.
%     Cluster4MetaAnalysis 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.
% 
%     Cluster4MetaAnalysis 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 Cluster4MetaAnalysis.  If not, see
%     <http://www.gnu.org/licenses/>.


function [clusterData] = computeClusterInfoBioInf(data, clusterID) 

% number of clusters
numClust = max(clusterID);
% dimensionality of the input data
numDim = size(data, 2);

% initialization
clusterData = zeros(numClust, numDim*2+1); 
merge = [data clusterID];
       
% Compute and store means and standard deviations for each cluster
for i=1:numClust
   cl = merge(find(merge(:, numDim+1) == i), 1:numDim);

   % make sure that means and stds are correctly computed also for
   % singleton clsuters
   card = size(cl, 1);
   if (card == 1)
       clusterData(i, 1:numDim) = cl;
       clusterData(i, (numDim+1):(numDim*2)) = zeros(1, numDim);
       clusterData(i, numDim*2+1) = 1;     
   else 
       clusterData(i, 1:numDim) = mean(cl);
       clusterData(i, (numDim+1):(numDim*2)) = std(cl);
       clusterData(i, numDim*2+1) = card;
   end
end
