]> git.donarmstrong.com Git - mothur.git/commitdiff
added weightedlinkage.cpp
authorpschloss <pschloss>
Wed, 9 Jun 2010 14:51:50 +0000 (14:51 +0000)
committerpschloss <pschloss>
Wed, 9 Jun 2010 14:51:50 +0000 (14:51 +0000)
Mothur.xcodeproj/project.pbxproj
cluster.cpp
cluster.hpp
clustercommand.cpp
makefile
weightedlinkage.cpp [new file with mode: 0644]

index ab546df5272e5ed9044d1fb1d8bc053748579e9a..2f5722c6efbb90886e04cbbb52967d09714f3331 100644 (file)
@@ -7,6 +7,7 @@
        objects = {
 
 /* Begin PBXFileReference section */
+               7EC61A0911BEA6AF00F668D9 /* weightedlinkage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = weightedlinkage.cpp; sourceTree = "<group>"; };
                A703FE931194645F002C397E /* makegroupcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = makegroupcommand.h; sourceTree = SOURCE_ROOT; };
                A703FE941194645F002C397E /* makegroupcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = makegroupcommand.cpp; sourceTree = SOURCE_ROOT; };
                A71D924211AEB42400D00CBC /* clustersplitcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = clustersplitcommand.cpp; sourceTree = "<group>"; };
                                A7DA2170113FECD400BF472F /* uvest.h */,
                                A7DA2179113FECD400BF472F /* weighted.cpp */,
                                A7DA217A113FECD400BF472F /* weighted.h */,
+                               7EC61A0911BEA6AF00F668D9 /* weightedlinkage.cpp */,
                                A7DA217B113FECD400BF472F /* whittaker.cpp */,
                                A7DA217C113FECD400BF472F /* whittaker.h */,
                        );
index 96ca44061436f873ee8b663e248ddcc386c995cb..40537fe7b51eb759cf7be438bdd61978835a192c 100644 (file)
@@ -235,7 +235,7 @@ void Cluster::update(double& cutOFF){
                                        }               
                                }
                                //if not merged it you need it for warning 
-                               if ((!merged) && (method == "average")) {  
+                               if ((!merged) && (method == "average" || method == "weighted")) {  
                                        //m->mothurOut("Warning: trying to merge cell " + toString(rowCells[i]->row+1) + " " + toString(rowCells[i]->column+1) + " distance " + toString(rowCells[i]->dist) + " with value above cutoff. Results may vary from using cutoff at cluster command instead of read.dist."); m->mothurOutEndLine(); 
                                        if (cutOFF > rowCells[i]->dist) {  
                                                cutOFF = rowCells[i]->dist;  
@@ -254,7 +254,7 @@ void Cluster::update(double& cutOFF){
                // could be avoided
                for (int i=nColCells-1;i>=0;i--) {
                        if (foundCol[i] == 0) {
-                               if (method == "average") {
+                               if (method == "average" || method == "weighted") {
                                        if (!((colCells[i]->row == smallRow) && (colCells[i]->column == smallCol))) {
                                                //m->mothurOut("Warning: merging cell " + toString(colCells[i]->row+1) + " " + toString(colCells[i]->column+1) + " distance " + toString(colCells[i]->dist) + " value above cutoff. Results may vary from using cutoff at cluster command instead of read.dist."); m->mothurOutEndLine();
                                                if (cutOFF > colCells[i]->dist) {  
index 72d3611a093296b3dc18d9ddb7bf12d0a0a9a0e5..aa517a057400e09cdca593f4db1e2559dca74972 100644 (file)
@@ -94,4 +94,17 @@ private:
 
 /***********************************************************************/
 
+class WeightedLinkage : public Cluster {
+public:
+       WeightedLinkage(RAbundVector*, ListVector*, SparseMatrix*, float, string);
+       bool updateDistance(MatData& colCell, MatData& rowCell);
+       string getTag();
+       
+private:
+       int saveRow;
+       int saveCol;    
+};
+
+/***********************************************************************/
+
 #endif
index 30c45e167ad6a398b23727293577f92362f5d6c7..e9df82f6e430b9d11965248882cdc34a650b3a3f 100644 (file)
@@ -67,8 +67,8 @@ ClusterCommand::ClusterCommand(string option)  {
                        method = validParameter.validFile(parameters, "method", false);
                        if (method == "not found") { method = "furthest"; }
                        
-                       if ((method == "furthest") || (method == "nearest") || (method == "average")) { }
-                       else { m->mothurOut("Not a valid clustering method.  Valid clustering algorithms are furthest, nearest or average."); m->mothurOutEndLine(); abort = true; }
+                       if ((method == "furthest") || (method == "nearest") || (method == "average") || (method == "weighted")) { }
+                       else { m->mothurOut("Not a valid clustering method.  Valid clustering algorithms are furthest, nearest, average, and weighted."); m->mothurOutEndLine(); abort = true; }
 
                        showabund = validParameter.validFile(parameters, "showabund", false);
                        if (showabund == "not found") { showabund = "T"; }
@@ -91,6 +91,7 @@ ClusterCommand::ClusterCommand(string option)  {
                                if (method == "furthest")       {       cluster = new CompleteLinkage(rabund, list, matrix, cutoff, method); }
                                else if(method == "nearest"){   cluster = new SingleLinkage(rabund, list, matrix, cutoff, method); }
                                else if(method == "average"){   cluster = new AverageLinkage(rabund, list, matrix, cutoff, method);     }
+                               else if(method == "weighted"){  cluster = new WeightedLinkage(rabund, list, matrix, cutoff, method);    }
                                tag = cluster->getTag();
                                
                                if (outputDir == "") { outputDir += hasPath(globaldata->inputFileName); }
index 91a269c759cc52ad4142d3513f5aa17442e482a5..8c33659b9fe6e158a316cbae12a0dd829d9b57e2 100644 (file)
--- a/makefile
+++ b/makefile
@@ -153,6 +153,7 @@ mothur : \
                ./splitabundcommand.o\\r
                ./splitmatrix.o\\r
                ./clustersplitcommand.o\\r
+               ./weightedlinkage.o\\r
                ./inputdata.o\\r
                ./jackknife.o\\r
                ./kmer.o\\r
@@ -362,6 +363,7 @@ mothur : \
                ./splitabundcommand.o\\r
                ./splitmatrix.o\\r
                ./clustersplitcommand.o\\r
+               ./weightedlinkage.o\\r
                ./inputdata.o\\r
                ./jackknife.o\\r
                ./kmer.o\\r
@@ -461,7 +463,7 @@ mothur : \
                ./logsd.o\\r
                ./geom.o\\r
                ./setlogfilecommand.o\\r
-               -o ../Release/mothur\r
+               -o mothur\r
 \r
 clean : \r
                rm \\r
@@ -574,6 +576,7 @@ clean :
                ./splitabundcommand.o\\r
                ./splitmatrix.o\\r
                ./clustersplitcommand.o\\r
+               ./weightedlinkage.o\\r
                ./inputdata.o\\r
                ./jackknife.o\\r
                ./kmer.o\\r
@@ -1705,5 +1708,8 @@ install : mothur
 ./classifyotucommand.o : classifyotucommand.cpp\r
        $(CC) $(CC_OPTIONS) classifyotucommand.cpp -c $(INCLUDE) -o ./classifyotucommand.o\r
 \r
+# Item # 209 -- splitmatrix --\r
+./weightedlinkage.o : weightedlinkage.cpp\r
+       $(CC) $(CC_OPTIONS) weightedlinkage.cpp -c $(INCLUDE) -o ./weightedlinkage.o\r
 \r
 ##### END RUN ####\r
diff --git a/weightedlinkage.cpp b/weightedlinkage.cpp
new file mode 100644 (file)
index 0000000..0851bd7
--- /dev/null
@@ -0,0 +1,56 @@
+#ifndef WEIGHTEDLINKAGE_H
+#define WEIGHTEDLINKAGE_H
+
+
+#include "mothur.h"
+#include "cluster.hpp"
+#include "rabundvector.hpp"
+#include "sparsematrix.hpp"
+
+/* This class implements the WPGMA, weighted average neighbor clustering algorithm */
+
+/***********************************************************************/
+
+WeightedLinkage::WeightedLinkage(RAbundVector* rav, ListVector* lv, SparseMatrix* dm, float c, string s) :
+       Cluster(rav, lv, dm, c, s)
+{
+       saveRow = -1;
+       saveCol = -1;
+}
+
+
+/***********************************************************************/
+//This function returns the tag of the method.
+string WeightedLinkage::getTag() {
+       return("wn");
+}
+
+
+/***********************************************************************/
+//This function updates the distance based on the average linkage method.
+bool WeightedLinkage::updateDistance(MatData& colCell, MatData& rowCell) {
+       try {
+               if ((saveRow != smallRow) || (saveCol != smallCol)) {
+//                     rowBin = rabund->get(smallRow);
+//                     colBin = rabund->get(smallCol);
+//                     totalBin = rowBin + colBin;
+                       saveRow = smallRow;
+                       saveCol = smallCol;
+               }
+               
+               colCell->dist = (colCell->dist + rowCell->dist) / 2.0;
+               
+               return(true);
+       }
+       catch(exception& e) {
+               m->errorOut(e, "WeightedLinkage", "updateDistance");
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+
+/***********************************************************************/
+
+#endif