]> git.donarmstrong.com Git - mothur.git/blobdiff - clustercommand.cpp
fixes while testing
[mothur.git] / clustercommand.cpp
index 3f27560ae9bfbc69c5ac3d49875847a829f49bf3..6043d39be8d559010e156111f41a856b716cda40 100644 (file)
@@ -9,6 +9,56 @@
 
 #include "clustercommand.h"
 
+//**********************************************************************************************************************
+vector<string> ClusterCommand::getValidParameters(){   
+       try {
+               string AlignArray[] =  {"cutoff","precision","method","showabund","timing","hard","outputdir","inputdir"};
+               vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "ClusterCommand", "getValidParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+ClusterCommand::ClusterCommand(){      
+       try {
+               abort = true;
+               //initialize outputTypes
+               vector<string> tempOutNames;
+               outputTypes["list"] = tempOutNames;
+               outputTypes["rabund"] = tempOutNames;
+               outputTypes["sabund"] = tempOutNames;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "ClusterCommand", "ClusterCommand");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> ClusterCommand::getRequiredParameters(){        
+       try {
+               vector<string> myArray; 
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "ClusterCommand", "getRequiredParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> ClusterCommand::getRequiredFiles(){     
+       try {
+               string Array[] =  {"phylip","column","or"};
+               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "ClusterCommand", "getRequiredFiles");
+               exit(1);
+       }
+}
 //**********************************************************************************************************************
 //This function checks to make sure the cluster command has no errors and then clusters based on the method chosen.
 ClusterCommand::ClusterCommand(string option)  {
@@ -37,6 +87,12 @@ ClusterCommand::ClusterCommand(string option)  {
                                }
                        }
                        
+                       //initialize outputTypes
+                       vector<string> tempOutNames;
+                       outputTypes["list"] = tempOutNames;
+                       outputTypes["rabund"] = tempOutNames;
+                       outputTypes["sabund"] = tempOutNames;
+               
                        //if the user changes the output directory command factory will send this info to us in the output parameter 
                        outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = "";         }
                        
@@ -57,7 +113,7 @@ ClusterCommand::ClusterCommand(string option)  {
                        convert(temp, precision); 
                        
                        temp = validParameter.validFile(parameters, "hard", false);                     if (temp == "not found") { temp = "F"; }
-                       hard = isTrue(temp);
+                       hard = m->isTrue(temp);
                        
                        temp = validParameter.validFile(parameters, "cutoff", false);
                        if (temp == "not found") { temp = "10"; }
@@ -94,16 +150,16 @@ ClusterCommand::ClusterCommand(string option)  {
                                else if(method == "weighted"){  cluster = new WeightedLinkage(rabund, list, matrix, cutoff, method);    }
                                tag = cluster->getTag();
                                
-                               if (outputDir == "") { outputDir += hasPath(globaldata->inputFileName); }
-                               fileroot = outputDir + getRootName(getSimpleName(globaldata->inputFileName));
+                               if (outputDir == "") { outputDir += m->hasPath(globaldata->inputFileName); }
+                               fileroot = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName));
                        
-                               openOutputFile(fileroot+ tag + ".sabund",       sabundFile);
-                               openOutputFile(fileroot+ tag + ".rabund",       rabundFile);
-                               openOutputFile(fileroot+ tag + ".list",         listFile);
+                               m->openOutputFile(fileroot+ tag + ".sabund",    sabundFile);
+                               m->openOutputFile(fileroot+ tag + ".rabund",    rabundFile);
+                               m->openOutputFile(fileroot+ tag + ".list",              listFile);
                                
-                               outputNames.push_back(fileroot+ tag + ".sabund");
-                               outputNames.push_back(fileroot+ tag + ".rabund");
-                               outputNames.push_back(fileroot+ tag + ".list");
+                               outputNames.push_back(fileroot+ tag + ".sabund"); outputTypes["sabund"].push_back(fileroot+ tag + ".sabund");
+                               outputNames.push_back(fileroot+ tag + ".rabund"); outputTypes["rabund"].push_back(fileroot+ tag + ".rabund");
+                               outputNames.push_back(fileroot+ tag + ".list"); outputTypes["list"].push_back(fileroot+ tag + ".list");
                        }
                }
        }
@@ -165,13 +221,13 @@ int ClusterCommand::execute(){
                                if (globaldata->getFormat() == "phylip") { globaldata->setPhylipFile(""); }
                                else if (globaldata->getFormat() == "column") { globaldata->setColumnFile(""); }
                                sabundFile.close();rabundFile.close();listFile.close();
-                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }
+                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         } outputTypes.clear();
                                return 0;
                        }
                
-                       if (print_start && isTrue(timing)) {
+                       if (print_start && m->isTrue(timing)) {
                                m->mothurOut("Clustering (" + tag + ") dist " + toString(matrix->getSmallDist()) + "/" 
-                                       + toString(roundDist(matrix->getSmallDist(), precision)) 
+                                       + toString(m->roundDist(matrix->getSmallDist(), precision)) 
                                        + "\t(precision: " + toString(precision) + ", Nodes: " + toString(matrix->getNNodes()) + ")");
                                cout.flush();
                                print_start = false;
@@ -184,9 +240,9 @@ int ClusterCommand::execute(){
                        float dist = matrix->getSmallDist();
                        float rndDist;
                        if (hard) {
-                               rndDist = ceilDist(dist, precision); 
+                               rndDist = m->ceilDist(dist, precision); 
                        }else{
-                               rndDist = roundDist(dist, precision); 
+                               rndDist = m->roundDist(dist, precision); 
                        }
 
                        if(previousDist <= 0.0000 && dist != previousDist){
@@ -202,7 +258,7 @@ int ClusterCommand::execute(){
                        oldList = *list;
                }
 
-               if (print_start && isTrue(timing)) {
+               if (print_start && m->isTrue(timing)) {
                        m->mothurOut("Clustering (" + tag + ") for distance " + toString(previousDist) + "/" + toString(rndPreviousDist) 
                                         + "\t(precision: " + toString(precision) + ", Nodes: " + toString(matrix->getNNodes()) + ")");
                        cout.flush();
@@ -233,8 +289,8 @@ int ClusterCommand::execute(){
                listFile.close();
        
                if (saveCutoff != cutoff) { 
-                       if (hard)       {  saveCutoff = ceilDist(saveCutoff, precision);        }
-                       else            {       saveCutoff = roundDist(saveCutoff, precision);  }
+                       if (hard)       {  saveCutoff = m->ceilDist(saveCutoff, precision);     }
+                       else            {       saveCutoff = m->roundDist(saveCutoff, precision);  }
 
                        m->mothurOut("changed cutoff to " + toString(cutoff)); m->mothurOutEndLine(); 
                }
@@ -245,7 +301,7 @@ int ClusterCommand::execute(){
                m->mothurOutEndLine();
 
                
-               //if (isTrue(timing)) {
+               //if (m->isTrue(timing)) {
                        m->mothurOut("It took " + toString(time(NULL) - estart) + " seconds to cluster"); m->mothurOutEndLine();
                //}
                
@@ -262,7 +318,7 @@ int ClusterCommand::execute(){
 
 void ClusterCommand::printData(string label){
        try {
-               if (isTrue(timing)) {
+               if (m->isTrue(timing)) {
                        m->mothurOut("\tTime: " + toString(time(NULL) - start) + "\tsecs for " + toString(oldRAbund.getNumBins()) 
                     + "\tclusters. Updates: " + toString(loops)); m->mothurOutEndLine();
                }
@@ -271,7 +327,7 @@ void ClusterCommand::printData(string label){
                start = time(NULL);
 
                oldRAbund.setLabel(label);
-               if (isTrue(showabund)) {
+               if (m->isTrue(showabund)) {
                        oldRAbund.getSAbundVector().print(cout);
                }
                oldRAbund.print(rabundFile);