X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=averagelinkage.cpp;h=8627253777c1b09a1b4b16d1ff2ad4f90468248c;hp=54f380353c6d97f018218c74e7667b3df1f89637;hb=d1c97b8c04bb75faca1e76ffad60b37a4d789d3d;hpb=c5c7502f435e1413c19e373dab1dfebcaa67588d diff --git a/averagelinkage.cpp b/averagelinkage.cpp index 54f3803..8627253 100644 --- a/averagelinkage.cpp +++ b/averagelinkage.cpp @@ -1,85 +1,56 @@ #ifndef AVERAGE_H #define AVERAGE_H - +//test #include "mothur.h" #include "cluster.hpp" #include "rabundvector.hpp" -#include "sparsematrix.hpp" +#include "sparsedistancematrix.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, SparseDistanceMatrix* dm, float c, string s, float a) : +Cluster(rav, lv, dm, c, s, a) +{ + 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;irow == smallRow){ - search = rowCells[i]->column; - } - else{ - search = rowCells[i]->row; - } - - 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]); - } +//This function updates the distance based on the average linkage method. +bool AverageLinkage::updateDistance(PDistCell& colCell, PDistCell& rowCell) { + try { + if ((saveRow != smallRow) || (saveCol != smallCol)) { + rowBin = rabund->get(smallRow); + colBin = rabund->get(smallCol); + totalBin = rowBin + colBin; + saveRow = smallRow; + saveCol = smallCol; } + //cout << "colcell.dist = " << colCell.dist << '\t' << smallRow << '\t' << smallCol << '\t' << rowCell.dist << endl; + colCell.dist = (colBin * colCell.dist + rowBin * rowCell.dist) / totalBin; + + 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"; + m->errorOut(e, "AverageLinkage", "updateDistance"); 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"; - exit(1); - } - - } /***********************************************************************/ -#endif +/***********************************************************************/ +#endif