5 * Created by Pat Schloss on 4/8/09.
6 * Copyright 2009 Patrick D. Schloss. All rights reserved.
12 /***********************************************************************/
14 void swap(int& i,int& j){ int t = i; i = j; j = t; }
16 /***********************************************************************/
18 Libshuff::Libshuff(FullMatrix* D, int it, float step, float co) : matrix(D), iters(it), stepSize(step), cutOff(co){
20 groupNames = matrix->getGroups();
21 groupSizes = matrix->getSizes();
22 numGroups = matrix->getNumGroups();
24 initializeGroups(matrix);
27 cout << "Standard Error: " << e.what() << " has occurred in the Libshuff class Function Libshuff. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
31 cout << "An unknown error has occurred in the Libshuff class function Libshuff. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
37 /***********************************************************************/
39 void Libshuff::initializeGroups(FullMatrix* matrix){
41 groups.resize(numGroups);
42 savedGroups.resize(numGroups);
44 savedGroups.resize(numGroups);
45 for(int i=0;i<numGroups;i++) {
46 groups[i].resize(groupSizes[i]);
47 savedGroups[i].resize(groupSizes[i]);
50 for(int i=0;i<numGroups;i++){
51 for(int j=0;j<groupSizes[i];j++){
52 savedGroups[i][j] = groups[i][j] = index++;
57 cout << "Standard Error: " << e.what() << " has occurred in the Libshuff class Function initializeGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
61 cout << "An unknown error has occurred in the Libshuff class function initializeGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
67 /***********************************************************************/
69 vector<vector<vector<double> > > Libshuff::getSavedMins(){
73 /***********************************************************************/
75 vector<double> Libshuff::getMinX(int x){
77 vector<double> minX(groupSizes[x], 0);
78 for(int i=0;i<groupSizes[x];i++){
79 minX[i] = (groupSizes[x] > 1 ? (i==0 ? matrix->get(groups[x][0], groups[x][1]) : matrix->get(groups[x][i], groups[x][0])) : 0.0);
80 for(int j=0;j<groupSizes[x];j++){
82 double dx = matrix->get(groups[x][i], groups[x][j]);
83 if(dx < minX[i]){ minX[i] = dx; }
90 cout << "Standard Error: " << e.what() << " has occurred in the Libshuff class Function getMinX. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
94 cout << "An unknown error has occurred in the Libshuff class function getMinX. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
100 /***********************************************************************/
102 vector<double> Libshuff::getMinXY(int x, int y){
104 vector<double> minXY(groupSizes[x], 0);
106 for(int i=0;i<groupSizes[x];i++){
107 minXY[i] = matrix->get(groups[x][i], groups[y][0]);
108 for(int j=0;j<groupSizes[y];j++){
109 double dxy = matrix->get(groups[x][i], groups[y][j]);
110 if(dxy<minXY[i]){ minXY[i] = dxy; }
115 catch(exception& e) {
116 cout << "Standard Error: " << e.what() << " has occurred in the Libshuff class Function getMinXY. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
120 cout << "An unknown error has occurred in the Libshuff class function getMinXY. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
125 /***********************************************************************/
127 void Libshuff::randomizeGroups(int x, int y){
129 int nv = groupSizes[x]+groupSizes[y];
133 for(int k=0;k<groupSizes[x];k++) { v[index++] = groups[x][k]; }
134 for(int k=0;k<groupSizes[y];k++) { v[index++] = groups[y][k]; }
136 for(int k=nv-1;k>0;k--){
137 int z = (int)(rand() % k);
142 for(int k=0;k<groupSizes[x];k++) { groups[x][k]=v[index++]; }
143 for(int k=0;k<groupSizes[y];k++) { groups[y][k]=v[index++]; }
145 catch(exception& e) {
146 cout << "Standard Error: " << e.what() << " has occurred in the Libshuff class Function randomizeGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
150 cout << "An unknown error has occurred in the Libshuff class function randomizeGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
155 /***********************************************************************/
157 void Libshuff::resetGroup(int x){
159 for(int k=0;k<groupSizes[x];k++) { groups[x][k] = savedGroups[x][k]; }
163 /***********************************************************************/