]> git.donarmstrong.com Git - mothur.git/blobdiff - clearcutcommand.cpp
get.oturep change and trim.seqs fix
[mothur.git] / clearcutcommand.cpp
index d6c284d68159b66255d3cdb29d57217e9dd73af6..a2d0aaa5331a402a538d253e4d1f00d7800fa77e 100644 (file)
@@ -8,7 +8,62 @@
  */
 
 #include "clearcutcommand.h"
-
+#ifdef __cplusplus
+extern "C" {
+#endif
+#include "clearcut.h"
+#ifdef __cplusplus
+}
+#endif
+//**********************************************************************************************************************
+vector<string> ClearcutCommand::getValidParameters(){  
+       try {
+               string AlignArray[] =  {"fasta","phylip","version","verbose","quiet","seed","norandom","shuffle","neighbor","expblen",
+                                                               "expdist","ntrees","matrixout","stdout","kimura","jukes","protein","DNA","outputdir","inputdir"};
+               vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "ClearcutCommand", "getValidParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+ClearcutCommand::ClearcutCommand(){    
+       try {
+               abort = true;
+               //initialize outputTypes
+               vector<string> tempOutNames;
+               outputTypes["tree"] = tempOutNames;
+               outputTypes["matrixout"] = tempOutNames;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "ClearcutCommand", "ClearcutCommand");
+               exit(1);
+       }
+}//**********************************************************************************************************************
+vector<string> ClearcutCommand::getRequiredParameters(){       
+       try {
+               string Array[] =  {"fasta","phylip","or"};
+               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "ClearcutCommand", "getRequiredParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> ClearcutCommand::getRequiredFiles(){    
+       try {
+               vector<string> myArray;
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "ClearcutCommand", "getRequiredFiles");
+               exit(1);
+       }
+}
 /**************************************************************************************/
 ClearcutCommand::ClearcutCommand(string option)  {     
        try {
@@ -34,6 +89,11 @@ ClearcutCommand::ClearcutCommand(string option)  {
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //initialize outputTypes
+                       vector<string> tempOutNames;
+                       outputTypes["tree"] = tempOutNames;
+                       outputTypes["matrixout"] = 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 = "";          }
@@ -135,7 +195,6 @@ void ClearcutCommand::help(){
        try {
                m->mothurOut("The clearcut command interfaces mothur with the clearcut program written by Initiative for Bioinformatics and Evolutionary Studies (IBEST) at the University of Idaho.\n");
                m->mothurOut("For more information about clearcut refer to http://bioinformatics.hungry.com/clearcut/ \n");
-               m->mothurOut("The clearcut executable must be in a folder called clearcut in the same folder as your mothur executable, similar to mothur's requirements for using blast. \n");
                m->mothurOut("The clearcut command parameters are phylip, fasta, version, verbose, quiet, seed, norandom, shuffle, neighbor, expblen, expdist, ntrees, matrixout, stdout, kimura, jukes, protein, DNA. \n");
                m->mothurOut("The phylip parameter allows you to enter your phylip formatted distance matrix. \n");
                m->mothurOut("The fasta parameter allows you to enter your aligned fasta file, if you enter a fastafile you specify if the sequences are DNA or protein using the DNA or protein parameters. \n");
@@ -173,62 +232,88 @@ int ClearcutCommand::execute() {
        try {
                
                if (abort == true) { return 0; }
-                               
+               
                //prepare filename
                string outputName = outputDir + m->getRootName(m->getSimpleName(inputFile)) + "tre";
+               outputNames.push_back(outputName); outputTypes["tree"].push_back(outputName);
                
-               //get location of clearcut
-               GlobalData* globaldata = GlobalData::getInstance();
-               string path = globaldata->argv;
-               path = path.substr(0, (path.find_last_of('m')));
+               vector<char*> cPara;
                
-               string clearcutCommand = path + "clearcut ";
+               char* tempClearcut = new char[8];  
+               strcpy(tempClearcut, "clearcut"); 
+               cPara.push_back(tempClearcut);
                                
                //you gave us a distance matrix
-               if (phylipfile != "") { clearcutCommand += "--distance ";       }
+               if (phylipfile != "") {  char* temp = new char[10];  strcpy(temp, "--distance");  cPara.push_back(temp);        }
                
                //you gave us a fastafile
-               if (fastafile != "") { clearcutCommand += "--alignment ";       }
-               
-               if (version)                    {  clearcutCommand += "--version ";             }
-               if (verbose)                    {  clearcutCommand += "--verbose ";             }
-               if (quiet)                              {  clearcutCommand += "--quiet ";               }
-               if (seed != "*")                {  clearcutCommand += "--seed=" + seed + " "; }
-               if (norandom)                   {  clearcutCommand += "--norandom ";    }
-               if (shuffle)                    {  clearcutCommand += "--shuffle ";             }
-               if (neighbor)                   {  clearcutCommand += "--neighbor ";    }
-               
-               #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
-                       clearcutCommand += "--in=" + inputFile + " "; 
-               #else
-                       clearcutCommand += "--in=\"" + inputFile + "\" "; 
-               #endif
-               
-               if (stdoutWanted)               {  clearcutCommand += "--stdout ";              }
+               if (fastafile != "") { char* temp = new char[11];  strcpy(temp, "--alignment");  cPara.push_back(temp);         }
+               
+               if (version)                    {  char* temp = new char[9];  strcpy(temp, "--version");  cPara.push_back(temp);        }
+               if (verbose)                    {  char* temp = new char[9];  strcpy(temp, "--verbose");  cPara.push_back(temp);        }
+               if (quiet)                              {  char* temp = new char[7];  strcpy(temp, "--quiet");  cPara.push_back(temp);  }
+               if (seed != "*")                {  
+                       string tempSeed = "--seed=" + seed;
+                       char* temp = new char[tempSeed.length()];
+                       strcpy(temp, tempSeed.c_str());
+                       cPara.push_back(temp);
+               }
+               if (norandom)                   {  char* temp = new char[10];  strcpy(temp, "--norandom");  cPara.push_back(temp);      }
+               if (shuffle)                    {  char* temp = new char[9];  strcpy(temp, "--shuffle");  cPara.push_back(temp);        }
+               if (neighbor)                   {  char* temp = new char[10];  strcpy(temp, "--neighbor");  cPara.push_back(temp);      }
+               
+               string tempIn = "--in=" + inputFile;  
+               char* tempI = new char[tempIn.length()];
+               strcpy(tempI, tempIn.c_str());
+               cPara.push_back(tempI);
+               
+               if (stdoutWanted)               {  char* temp = new char[8];  strcpy(temp, "--stdout");  cPara.push_back(temp); }
                else{  
-                       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
-                               clearcutCommand += "--out=" + outputName + " "; }
-                       #else
-                               clearcutCommand += "--out=\"" + outputName + "\" "; }
-                       #endif
-               
-               if (DNA)                                {  clearcutCommand += "--DNA ";                 }
-               if (protein)                    {  clearcutCommand += "--protein ";             }
-               if (jukes)                              {  clearcutCommand += "--jukes ";               }
-               if (kimura)                             {  clearcutCommand += "--kimura ";              }
-               if (matrixout != "")    {  clearcutCommand += "--matrixout=" + matrixout + " ";  }
-               if (ntrees != "1")              {  clearcutCommand += "--ntrees=" + ntrees + " "; }
-               if (expblen)                    {  clearcutCommand += "--expblen ";             }
-               if (expdist)                    {  clearcutCommand += "--expdist ";             }
-       
-               //run clearcut
-               system(clearcutCommand.c_str());
+                       string tempOut = "--out=" + outputName;  
+                       
+                       char* temp = new char[tempOut.length()];
+                       strcpy(temp, tempOut.c_str());
+                       cPara.push_back(temp);
+               }
+                       
+               if (DNA)                                {  char* temp = new char[5];  strcpy(temp, "--DNA");  cPara.push_back(temp);            }
+               if (protein)                    {  char* temp = new char[9];  strcpy(temp, "--protein");  cPara.push_back(temp);        }
+               if (jukes)                              {  char* temp = new char[7];  strcpy(temp, "--jukes");  cPara.push_back(temp);          }
+               if (kimura)                             { char* temp = new char[8];  strcpy(temp, "--kimura");  cPara.push_back(temp);          }
+               if (matrixout != "")    {  
+                       string tempMatrix =  "--matrixout=" + outputDir + matrixout; 
+                       char* temp = new char[tempMatrix.length()];
+                       strcpy(temp, tempMatrix.c_str());
+                       cPara.push_back(temp);
+                       outputNames.push_back((outputDir + matrixout));
+                       outputTypes["matrixout"].push_back((outputDir + matrixout));
+               }
+
+               if (ntrees != "1")              {  
+                       string tempNtrees = "--ntrees=" + ntrees; 
+                       char* temp = new char[tempNtrees.length()];
+                       strcpy(temp, tempNtrees.c_str());
+                       cPara.push_back(temp);
+               }
+
+               if (expblen)                    { char* temp = new char[9];  strcpy(temp, "--expblen");  cPara.push_back(temp);         }
+               if (expdist)                    { char* temp = new char[9];  strcpy(temp, "--expdist");  cPara.push_back(temp); }
+               
+               char** clearcutParameters;
+               clearcutParameters = new char*[cPara.size()];
+               for (int i = 0; i < cPara.size(); i++) {  clearcutParameters[i] = cPara[i];  }
+               int numArgs = cPara.size();
+               
+               clearcut_main(numArgs, clearcutParameters); 
+               
+               //free memory
+               for(int i = 0; i < cPara.size(); i++)  {  delete[] cPara[i];  }
+               delete[] clearcutParameters; 
                
                if (!stdoutWanted) {    
                        m->mothurOutEndLine();
                        m->mothurOut("Output File Names: "); m->mothurOutEndLine();
-                       m->mothurOut(outputName); m->mothurOutEndLine();
-                       if (matrixout != "")    {  m->mothurOut(matrixout); m->mothurOutEndLine();  }
+                       for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }
                        m->mothurOutEndLine();
                }