X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=averagelinkage.cpp;fp=averagelinkage.cpp;h=1ab5160f07720f2330c7a627654e8ed264098e54;hb=20a2d0350a737a434c89f303662d64a8eeea7b05;hp=0000000000000000000000000000000000000000;hpb=bbb5879a7e566935c23d63d42bb945072424b939;p=mothur.git diff --git a/averagelinkage.cpp b/averagelinkage.cpp new file mode 100644 index 0000000..1ab5160 --- /dev/null +++ b/averagelinkage.cpp @@ -0,0 +1,78 @@ + +#include "cluster.hpp" +#include "rabundvector.hpp" +#include "sparsematrix.hpp" +#include + +/* This class implements the average UPGMA, average neighbor clustering algorithm */ + +/***********************************************************************/ + +AverageLinkage::AverageLinkage(RAbundVector* rav, ListVector* lv, SparseMatrix* dm) : +Cluster(rav, lv, dm) +{} + +/***********************************************************************/ +//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]); + } + } + } + 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"; + exit(1); + } + + +} + +/***********************************************************************/