]> git.donarmstrong.com Git - mothur.git/blobdiff - makegroupcommand.cpp
added pipeline commands which involved change to command factory and command class...
[mothur.git] / makegroupcommand.cpp
index 8dd1d67b294517437648f314321324ca8f1baf11..fd68b8022c610557402d03a1ab970901939c9126 100644 (file)
 #include "makegroupcommand.h"
 #include "sequence.hpp"
 
+//**********************************************************************************************************************
+vector<string> MakeGroupCommand::getValidParameters(){ 
+       try {
+               string Array[] =  {"fasta", "groups","outputdir","inputdir"};
+               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "MakeGroupCommand", "getValidParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+MakeGroupCommand::MakeGroupCommand(){  
+       try {
+               //initialize outputTypes
+               vector<string> tempOutNames;
+               outputTypes["group"] = tempOutNames;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "MakeGroupCommand", "MakeGroupCommand");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> MakeGroupCommand::getRequiredParameters(){      
+       try {
+               string Array[] =  {"fasta","groups"};
+               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "MakeGroupCommand", "getRequiredParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> MakeGroupCommand::getRequiredFiles(){   
+       try {
+               vector<string> myArray;
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "MakeGroupCommand", "getRequiredFiles");
+               exit(1);
+       }
+}
 //**********************************************************************************************************************
 
 MakeGroupCommand::MakeGroupCommand(string option)  {
@@ -36,7 +83,11 @@ MakeGroupCommand::MakeGroupCommand(string option)  {
                        for (it = parameters.begin(); it != parameters.end(); it++) { 
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
-
+                       
+                       //initialize outputTypes
+                       vector<string> tempOutNames;
+                       outputTypes["group"] = tempOutNames;
+               
                        //if the user changes the input directory command factory will send this info to us in the output parameter 
                        string inputDir = validParameter.validFile(parameters, "inputdir", false);              
                        if (inputDir == "not found"){   inputDir = "";          }
@@ -68,6 +119,16 @@ MakeGroupCommand::MakeGroupCommand(string option)  {
                                                        fastaFileNames[i] = tryPath;
                                                }
                                        }
+                                       
+                                       //if you can't open it, try default location
+                                       if (ableToOpen == 1) {
+                                               if (m->getOutputDir() != "") { //default path is set
+                                                       string tryPath = m->getOutputDir() + m->getSimpleName(fastaFileNames[i]);
+                                                       m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine();
+                                                       ableToOpen = m->openInputFile(tryPath, in, "noerror");
+                                                       fastaFileNames[i] = tryPath;
+                                               }
+                                       }
                                        in.close();
                                        
                                        if (ableToOpen == 1) { 
@@ -140,7 +201,7 @@ int MakeGroupCommand::execute(){
                
                for (int i = 0; i < fastaFileNames.size(); i++) {
                
-                       if (m->control_pressed) {  out.close(); remove(filename.c_str()); return 0; }
+                       if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); return 0; }
                        
                        ifstream in;
                        m->openInputFile(fastaFileNames[i], in);
@@ -149,7 +210,7 @@ int MakeGroupCommand::execute(){
                                
                                Sequence seq(in, "no align"); m->gobble(in);
                                
-                               if (m->control_pressed) {  in.close(); out.close(); remove(filename.c_str()); return 0; }
+                               if (m->control_pressed) { outputTypes.clear();  in.close(); out.close(); remove(filename.c_str()); return 0; }
                                
                                if (seq.getName() != "") {      out << seq.getName() << '\t' << groupsNames[i] << endl;         }
                        }
@@ -159,7 +220,7 @@ int MakeGroupCommand::execute(){
                out.close();
                
                m->mothurOutEndLine();
-               m->mothurOut("Output File Name: " + filename); m->mothurOutEndLine();
+               m->mothurOut("Output File Name: " + filename); m->mothurOutEndLine(); outputNames.push_back(filename); outputTypes["group"].push_back(filename); 
                m->mothurOutEndLine();
 
                return 0;