]> git.donarmstrong.com Git - mothur.git/blobdiff - chimeraslayercommand.cpp
added pipeline commands which involved change to command factory and command class...
[mothur.git] / chimeraslayercommand.cpp
index d2f3067a3beb153242cfd5c945156e0e11f42b9b..2172369e70d38915ab6a3831f0ab53e4a34f759d 100644 (file)
 #include "chimeraslayercommand.h"
 #include "chimeraslayer.h"
 
-
+//**********************************************************************************************************************
+vector<string> ChimeraSlayerCommand::getValidParameters(){     
+       try {
+               string AlignArray[] =  {"fasta", "processors", "window", "template","numwanted", "ksize", "match","mismatch", 
+                       "divergence", "minsim","mincov","minbs", "minsnp","parents", "iters","outputdir","inputdir", "search","realign" };
+               vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "ChimeraSlayerCommand", "getValidParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+ChimeraSlayerCommand::ChimeraSlayerCommand(){  
+       try {
+               vector<string> tempOutNames;
+               outputTypes["chimera"] = tempOutNames;
+               outputTypes["accnos"] = tempOutNames;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "ChimeraSlayerCommand", "ChimeraSlayerCommand");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> ChimeraSlayerCommand::getRequiredParameters(){  
+       try {
+               string AlignArray[] =  {"template","fasta"};
+               vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "ChimeraSlayerCommand", "getRequiredParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> ChimeraSlayerCommand::getRequiredFiles(){       
+       try {
+               vector<string> myArray;
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "ChimeraSlayerCommand", "getRequiredFiles");
+               exit(1);
+       }
+}
 //***************************************************************************************************************
-
 ChimeraSlayerCommand::ChimeraSlayerCommand(string option)  {
        try {
                abort = false;
@@ -37,6 +83,10 @@ ChimeraSlayerCommand::ChimeraSlayerCommand(string option)  {
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       vector<string> tempOutNames;
+                       outputTypes["chimera"] = tempOutNames;
+                       outputTypes["accnos"] = 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 = "";          }
@@ -80,6 +130,16 @@ ChimeraSlayerCommand::ChimeraSlayerCommand(string option)  {
                                                        fastaFileNames[i] = tryPath;
                                                }
                                        }
+                                       
+                                       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) { 
@@ -258,7 +318,7 @@ int ChimeraSlayerCommand::execute(){
                                MPI_File_open(MPI_COMM_WORLD, outFilename, outMode, MPI_INFO_NULL, &outMPI);
                                MPI_File_open(MPI_COMM_WORLD, outAccnosFilename, outMode, MPI_INFO_NULL, &outMPIAccnos);
 
-                               if (m->control_pressed) {  MPI_File_close(&inMPI);  MPI_File_close(&outMPI);   MPI_File_close(&outMPIAccnos); for (int j = 0; j < outputNames.size(); j++) {    remove(outputNames[j].c_str()); }   delete chimera; return 0;  }
+                               if (m->control_pressed) { outputTypes.clear();  MPI_File_close(&inMPI);  MPI_File_close(&outMPI);   MPI_File_close(&outMPIAccnos); for (int j = 0; j < outputNames.size(); j++) {       remove(outputNames[j].c_str()); }   delete chimera; return 0;  }
                        
                                if (pid == 0) { //you are the root process 
                                        m->mothurOutEndLine();
@@ -291,7 +351,7 @@ int ChimeraSlayerCommand::execute(){
                                        //do your part
                                        driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPI, outMPIAccnos, MPIPos);
                                        
-                                       if (m->control_pressed) {  MPI_File_close(&inMPI);  MPI_File_close(&outMPI);   MPI_File_close(&outMPIAccnos);  for (int j = 0; j < outputNames.size(); j++) {   remove(outputNames[j].c_str()); }  remove(outputFileName.c_str());  remove(accnosFileName.c_str());  delete chimera; return 0;  }
+                                       if (m->control_pressed) { outputTypes.clear();  MPI_File_close(&inMPI);  MPI_File_close(&outMPI);   MPI_File_close(&outMPIAccnos);  for (int j = 0; j < outputNames.size(); j++) {      remove(outputNames[j].c_str()); }  remove(outputFileName.c_str());  remove(accnosFileName.c_str());  delete chimera; return 0;  }
 
                                }else{ //you are a child process
                                        MPI_Recv(&numSeqs, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);
@@ -306,7 +366,7 @@ int ChimeraSlayerCommand::execute(){
                                        //do your part
                                        driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPI, outMPIAccnos, MPIPos);
                                        
-                                       if (m->control_pressed) {  MPI_File_close(&inMPI);  MPI_File_close(&outMPI);   MPI_File_close(&outMPIAccnos);  for (int j = 0; j < outputNames.size(); j++) {   remove(outputNames[j].c_str()); }  delete chimera; return 0;  }
+                                       if (m->control_pressed) { outputTypes.clear();  MPI_File_close(&inMPI);  MPI_File_close(&outMPI);   MPI_File_close(&outMPIAccnos);  for (int j = 0; j < outputNames.size(); j++) {      remove(outputNames[j].c_str()); }  delete chimera; return 0;  }
                                }
                                
                                //close files 
@@ -334,7 +394,7 @@ int ChimeraSlayerCommand::execute(){
                                if(processors == 1){
                                        numSeqs = driver(lines[0], outputFileName, fastaFileNames[s], accnosFileName);
                                        
-                                       if (m->control_pressed) { remove(outputFileName.c_str()); remove(tempHeader.c_str()); remove(accnosFileName.c_str()); for (int j = 0; j < outputNames.size(); j++) {    remove(outputNames[j].c_str()); } for (int i = 0; i < lines.size(); i++) {  delete lines[i];  }  lines.clear(); delete chimera; return 0; }
+                                       if (m->control_pressed) { outputTypes.clear(); remove(outputFileName.c_str()); remove(tempHeader.c_str()); remove(accnosFileName.c_str()); for (int j = 0; j < outputNames.size(); j++) {       remove(outputNames[j].c_str()); } for (int i = 0; i < lines.size(); i++) {  delete lines[i];  }  lines.clear(); delete chimera; return 0; }
                                        
                                }else{
                                        processIDS.resize(0);
@@ -356,13 +416,13 @@ int ChimeraSlayerCommand::execute(){
                                                remove((accnosFileName + toString(processIDS[i]) + ".temp").c_str());
                                        }
                                        
-                                       if (m->control_pressed) { remove(outputFileName.c_str()); remove(accnosFileName.c_str()); for (int j = 0; j < outputNames.size(); j++) {        remove(outputNames[j].c_str()); } for (int i = 0; i < lines.size(); i++) {  delete lines[i];  }  lines.clear(); delete chimera; return 0; }
+                                       if (m->control_pressed) { outputTypes.clear(); remove(outputFileName.c_str()); remove(accnosFileName.c_str()); for (int j = 0; j < outputNames.size(); j++) {   remove(outputNames[j].c_str()); } for (int i = 0; i < lines.size(); i++) {  delete lines[i];  }  lines.clear(); delete chimera; return 0; }
                                }
 
                        #else
                                numSeqs = driver(lines[0], outputFileName, fastaFileNames[s], accnosFileName);
                                
-                               if (m->control_pressed) { remove(outputFileName.c_str()); remove(tempHeader.c_str()); remove(accnosFileName.c_str()); for (int j = 0; j < outputNames.size(); j++) {    remove(outputNames[j].c_str()); } for (int i = 0; i < lines.size(); i++) {  delete lines[i];  }  lines.clear(); delete chimera; return 0; }
+                               if (m->control_pressed) { outputTypes.clear(); remove(outputFileName.c_str()); remove(tempHeader.c_str()); remove(accnosFileName.c_str()); for (int j = 0; j < outputNames.size(); j++) {       remove(outputNames[j].c_str()); } for (int i = 0; i < lines.size(); i++) {  delete lines[i];  }  lines.clear(); delete chimera; return 0; }
                                
                        #endif
                        
@@ -377,8 +437,8 @@ int ChimeraSlayerCommand::execute(){
                        
                        for (int i = 0; i < lines.size(); i++) {  delete lines[i];  }  lines.clear();
                        
-                       outputNames.push_back(outputFileName);
-                       outputNames.push_back(accnosFileName); 
+                       outputNames.push_back(outputFileName); outputTypes["chimera"].push_back(outputFileName);
+                       outputNames.push_back(accnosFileName); outputTypes["accnos"].push_back(accnosFileName);
                        
                        m->mothurOutEndLine(); m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(numSeqs) + " sequences."); m->mothurOutEndLine();
                }