X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=averagelinkage.cpp;h=db2c51edc5b182b52dcf540456baad7b5782c61e;hb=832d53a9dfac6b1795735eec643d8cf627b0d8e3;hp=ec619cae3a5e373d7cd482c4bc25667e552a6687;hpb=bfbc55964f1977da72c2cea984288a427d370a59;p=mothur.git diff --git a/averagelinkage.cpp b/averagelinkage.cpp index ec619ca..db2c51e 100644 --- a/averagelinkage.cpp +++ b/averagelinkage.cpp @@ -1,84 +1,63 @@ #ifndef AVERAGE_H #define AVERAGE_H + +#include "mothur.h" #include "cluster.hpp" #include "rabundvector.hpp" #include "sparsematrix.hpp" -#include "mothur.h" /* This class implements the average UPGMA, average neighbor clustering algorithm */ /***********************************************************************/ -AverageLinkage::AverageLinkage(RAbundVector* rav, ListVector* lv, SparseMatrix* dm) : -Cluster(rav, lv, dm) -{} +AverageLinkage::AverageLinkage(RAbundVector* rav, ListVector* lv, SparseMatrix* dm, float c) : + Cluster(rav, lv, dm, c) +{ + saveRow = -1; + saveCol = -1; +} + + +/***********************************************************************/ +//This function returns the tag of the method. +string AverageLinkage::getTag() { + return("an"); +} + /***********************************************************************/ -//THis function clusters based on the average method -void AverageLinkage::update(){ - try{ - getRowColCells(); - - vector found(nColCells, 0); - - int rowBin = rabund->get(smallRow); - int colBin = rabund->get(smallCol); - int totalBin = rowBin + colBin; - - for(int i=1;iget(smallRow); + colBin = rabund->get(smallCol); + totalBin = rowBin + colBin; + saveRow = smallRow; + saveCol = smallCol; + } - int search; + float oldColCell = colCell->dist; - if(rowCells[i]->row == smallRow){ - search = rowCells[i]->column; - } - else{ - search = rowCells[i]->row; - } + colCell->dist = (colBin * colCell->dist + rowBin * rowCell->dist) / totalBin; - for(int j=1;jrow == search || colCells[j]->column == search){ - colCells[j]->dist = (colBin * colCells[j]->dist + rowBin * rowCells[i]->dist) / totalBin; - - found[j] = 1; - - if(colCells[j]->vectorMap != NULL){ - *(colCells[j]->vectorMap) = NULL; - colCells[j]->vectorMap = NULL; - } - - break; - } - - } - dMatrix->rmCell(rowCells[i]); - } - - clusterBins(); - clusterNames(); - - for(int i=0;irmCell(colCells[i]); - } + //warn user if merge with value above cutoff produces a value below cutoff + if ((colCell->dist < cutoff) && ((oldColCell > cutoff) || (rowCell->dist > cutoff)) ) { + mothurOut("Warning: merging " + toString(oldColCell) + " with " + toString(rowCell->dist) + ", new value = " + toString(colCell->dist) + ". Results will differ from those if cutoff was used in the read.dist command."); mothurOutEndLine(); } + + return(true); } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the AverageLinkage class Function update. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the AverageLinkage class function update. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + errorOut(e, "AverageLinkage", "updateDistance"); exit(1); } - - } /***********************************************************************/ -#endif +/***********************************************************************/ +#endif