]> git.donarmstrong.com Git - mothur.git/blobdiff - consensuscommand.cpp
added sequence name to error string in fastq.info. Changed np_shannon to npshannon.
[mothur.git] / consensuscommand.cpp
index 37cd39578c953e3d843c4cd0892b1be992511a88..e522b098f0703d6909f1906c3039fb4459e99854 100644 (file)
 #include "consensuscommand.h"
 
 //**********************************************************************************************************************
-
-ConcensusCommand::ConcensusCommand(string fileroot)  {
+vector<string> ConcensusCommand::setParameters(){      
        try {
-               globaldata = GlobalData::getInstance();
-               abort = false;
-               
-               filename = fileroot;
-               
-               t = globaldata->gTree;
-       
+               vector<string> myArray;
+               for (int i = 0; i < parameters.size(); i++) {   myArray.push_back(parameters[i].name);          }
+               return myArray;
        }
        catch(exception& e) {
-               m->errorOut(e, "ConcensusCommand", "ConcensusCommand");
+               m->errorOut(e, "ConcensusCommand", "setParameters");
                exit(1);
        }
 }
-
 //**********************************************************************************************************************
-
-void ConcensusCommand::help(){
+string ConcensusCommand::getHelpString(){      
        try {
-               m->mothurOut("The consensus command can only be executed after a successful read.tree command.\n");
-               m->mothurOut("The consensus command has no parameters.\n");
-               m->mothurOut("The consensus command should be in the following format: consensus().\n");
-               m->mothurOut("The consensus command output two files: .consensus.tre and .consensuspairs.\n");
-               m->mothurOut("The .consensus.tre file contains the consensus tree of the trees in your input file.\n");
-               m->mothurOut("The branch lengths are the percentage of trees in your input file that had the given pair.\n");
-               m->mothurOut("The .consensuspairs file contains a list of the internal nodes in your tree.  For each node, the pair that was used in the consensus tree \n");
-               m->mothurOut("is reported with its percentage, as well as the other pairs that were seen for that node but not used and their percentages.\n\n");               
+               string helpString = "";
+               helpString += "The consensus command can only be executed after a successful read.tree command.\n";
+               helpString += "The consensus command has no parameters.\n";
+               helpString += "The consensus command should be in the following format: consensus().\n";
+               helpString += "The consensus command output two files: .consensus.tre and .consensuspairs.\n";
+               helpString += "The .consensus.tre file contains the consensus tree of the trees in your input file.\n";
+               helpString += "The branch lengths are the percentage of trees in your input file that had the given pair.\n";
+               helpString += "The .consensuspairs file contains a list of the internal nodes in your tree.  For each node, the pair that was used in the consensus tree \n";
+               helpString += "is reported with its percentage, as well as the other pairs that were seen for that node but not used and their percentages.\n";         
+               return helpString;
        }
        catch(exception& e) {
-               m->errorOut(e, "ConcensusCommand", "help");
+               m->errorOut(e, "ConcensusCommand", "getHelpString");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+ConcensusCommand::ConcensusCommand(){  
+       try {
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> tempOutNames;
+               outputTypes["tree"] = tempOutNames;
+               outputTypes["nodepairs"] = tempOutNames;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "ConcensusCommand", "ConcensusCommand");
                exit(1);
        }
 }
-
 //**********************************************************************************************************************
 
-ConcensusCommand::~ConcensusCommand(){}
-
+ConcensusCommand::ConcensusCommand(string fileroot)  {
+       try {
+               abort = false; calledHelp = false;   
+               
+               setParameters();
+               
+               //initialize outputTypes
+               vector<string> tempOutNames;
+               outputTypes["tree"] = tempOutNames;
+               outputTypes["nodepairs"] = tempOutNames;
+               
+               filename = fileroot;
+       
+       }
+       catch(exception& e) {
+               m->errorOut(e, "ConcensusCommand", "ConcensusCommand");
+               exit(1);
+       }
+}
 //**********************************************************************************************************************
 
 int ConcensusCommand::execute(){
        try {
                
-               if (abort == true) { return 0; }
-               else {  
-                       numNodes = t[0]->getNumNodes();
-                       numLeaves = t[0]->getNumLeaves();
-               }
+               if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
+               
+               
+               m->mothurOut("This command is not currently in use."); m->mothurOutEndLine();
+       /*      
+               t = globaldata->gTree;
+               numNodes = t[0]->getNumNodes();
+               numLeaves = t[0]->getNumLeaves();
+               
                
                //get the possible pairings
                getSets();      
@@ -67,8 +96,8 @@ int ConcensusCommand::execute(){
                if (m->control_pressed) { return 0; }
                
                //open file for pairing not included in the tree
-               notIncluded = filename + ".cons.pairs";
-               openOutputFile(notIncluded, out2);
+               notIncluded = filename + ".cons.pairs"; outputNames.push_back(notIncluded);  outputTypes["nodepairs"].push_back(notIncluded);
+               m->openOutputFile(notIncluded, out2);
                
                consensusTree = new Tree();
                
@@ -150,15 +179,22 @@ int ConcensusCommand::execute(){
                        out2 << '\t' << it2->second << endl;
                }
                
-               outputFile = filename + ".cons.tre";
-               openOutputFile(outputFile, out);
+               outputFile = filename + ".cons.tre";  outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile);
+               m->openOutputFile(outputFile, out);
                
-               consensusTree->printForBoot(out);
+               consensusTree->print(out, "boot");
                
                out.close(); out2.close();
                
                delete consensusTree; 
                
+               //set first tree file as new current treefile
+               string currentTree = "";
+               itTypes = outputTypes.find("tree");
+               if (itTypes != outputTypes.end()) {
+                       if ((itTypes->second).size() != 0) { currentTree = (itTypes->second)[0]; m->setTreeFile(currentTree); }
+               }
+               */
                return 0;
        }
        catch(exception& e) {
@@ -262,13 +298,13 @@ int ConcensusCommand::getSets() {
                while (nodePairsCopy.size() != 0) {
                        if (m->control_pressed) { return 1; }
                
-                       vector<string> small = getSmallest(nodePairsCopy);
+                       vector<string> smallOne = getSmallest(nodePairsCopy);
                        
-                       int subgrouprate = getSubgroupRating(small);
+                       int subgrouprate = getSubgroupRating(smallOne);
                
-                       nodePairsInitialRate[small] = nodePairs[small] + subgrouprate;
+                       nodePairsInitialRate[smallOne] = nodePairs[smallOne] + subgrouprate;
                        
-                       nodePairsCopy.erase(small);
+                       nodePairsCopy.erase(smallOne);
                }
                
                return 0;