]> git.donarmstrong.com Git - mothur.git/blobdiff - matrixoutputcommand.cpp
added pipeline commands which involved change to command factory and command class...
[mothur.git] / matrixoutputcommand.cpp
index a55edd04e1db2f2acd24f57862b4dffb51e0ab8e..020ccff57c813168625132e83c9c198eb113a121 100644 (file)
 #include "sharedmorisitahorn.h"
 #include "sharedbraycurtis.h"
 
-
+//**********************************************************************************************************************
+vector<string> MatrixOutputCommand::getValidParameters(){      
+       try {
+               string Array[] =  {"label","calc","groups","outputdir","inputdir", "output"};
+               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "MatrixOutputCommand", "getValidParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+MatrixOutputCommand::MatrixOutputCommand(){    
+       try {
+               //initialize outputTypes
+               vector<string> tempOutNames;
+               outputTypes["phylip"] = tempOutNames;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "MatrixOutputCommand", "MatrixOutputCommand");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> MatrixOutputCommand::getRequiredParameters(){   
+       try {
+               vector<string> myArray;
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "MatrixOutputCommand", "getRequiredParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> MatrixOutputCommand::getRequiredFiles(){        
+       try {
+               string Array[] =  {"shared"};
+               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "MatrixOutputCommand", "getRequiredFiles");
+               exit(1);
+       }
+}
 //**********************************************************************************************************************
 
 MatrixOutputCommand::MatrixOutputCommand(string option)  {
@@ -49,6 +95,10 @@ MatrixOutputCommand::MatrixOutputCommand(string option)  {
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //initialize outputTypes
+                       vector<string> tempOutNames;
+                       outputTypes["phylip"] = 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 = ""; 
@@ -199,7 +249,7 @@ int MatrixOutputCommand::execute(){
                //as long as you are not at the end of the file or done wih the lines you want
                while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
                
-                       if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0;  }
+                       if (m->control_pressed) { outputTypes.clear(); delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } for (int i = 0; i < outputNames.size(); i++) {     remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0;  }
                
                        if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){                  
                                m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
@@ -232,7 +282,7 @@ int MatrixOutputCommand::execute(){
                        lookup = input->getSharedRAbundVectors();
                }
                
-               if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0;  }
+               if (m->control_pressed) { outputTypes.clear(); delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < outputNames.size(); i++) {     remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0;  }
 
                //output error messages about any remaining user labels
                set<string>::iterator it;
@@ -247,7 +297,7 @@ int MatrixOutputCommand::execute(){
                        }
                }
                
-               if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL;  for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0;  }
+               if (m->control_pressed) { outputTypes.clear(); delete read; delete input; globaldata->ginput = NULL;  for (int i = 0; i < outputNames.size(); i++) {    remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0;  }
 
                //run last label if you need to
                if (needToRun == true)  {
@@ -259,7 +309,7 @@ int MatrixOutputCommand::execute(){
                        for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } 
                }
                
-               if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL;  for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0;  }
+               if (m->control_pressed) { outputTypes.clear();  delete read; delete input; globaldata->ginput = NULL;  for (int i = 0; i < outputNames.size(); i++) {   remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0;  }
                
                //reset groups parameter
                globaldata->Groups.clear();  
@@ -349,7 +399,7 @@ int MatrixOutputCommand::process(vector<SharedRAbundVector*> thisLookup){
                                        
                                        exportFileName = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + matrixCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + output + ".dist";
                                        m->openOutputFile(exportFileName, out);
-                                       outputNames.push_back(exportFileName);
+                                       outputNames.push_back(exportFileName); outputTypes["phylip"].push_back(exportFileName);
                                        
                                        printSims(out);
                                        out.close();