]> git.donarmstrong.com Git - mothur.git/blobdiff - clearcutcommand.cpp
fixes while testing 1.33.0
[mothur.git] / clearcutcommand.cpp
index 29a5d725ff121b47b5c8f3132f54776f3e8a34ff..1b0a532cace0792297ce3162a03c7a382b66b282 100644 (file)
@@ -19,26 +19,26 @@ extern "C" {
 //**********************************************************************************************************************
 vector<string> ClearcutCommand::setParameters(){       
        try {
-               CommandParameter pphylip("phylip", "InputTypes", "", "", "FastaPhylip", "FastaPhylip", "none",false,false); parameters.push_back(pphylip);
-               CommandParameter pfasta("fasta", "InputTypes", "", "", "FastaPhylip", "FastaPhylip", "none",false,false); parameters.push_back(pfasta);
-               CommandParameter pverbose("verbose", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pverbose);
-               CommandParameter pquiet("quiet", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pquiet);
-               CommandParameter pversion("version", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pversion);
-               CommandParameter pseed("seed", "String", "", "", "*", "", "",false,false); parameters.push_back(pseed);
-               CommandParameter pnorandom("norandom", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pnorandom);
-               CommandParameter pshuffle("shuffle", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pshuffle);
-               CommandParameter pneighbor("neighbor", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pneighbor);
-               CommandParameter pexpblen("expblen", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pexpblen);
-               CommandParameter pexpdist("expdist", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pexpdist);
-               CommandParameter pDNA("DNA", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pDNA);
-               CommandParameter pprotein("protein", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pprotein);
-               CommandParameter pjukes("jukes", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pjukes);
-               CommandParameter pkimura("kimura", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pkimura);
-               CommandParameter pstdout("stdout", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pstdout);
-               CommandParameter pntrees("ntrees", "Number", "", "1", "", "", "",false,false); parameters.push_back(pntrees);
-               CommandParameter pmatrixout("matrixout", "String", "", "", "", "", "",false,false); parameters.push_back(pmatrixout);
-               CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
-               CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
+               CommandParameter pphylip("phylip", "InputTypes", "", "", "FastaPhylip", "FastaPhylip", "none","tree",false,false,true); parameters.push_back(pphylip);
+               CommandParameter pfasta("fasta", "InputTypes", "", "", "FastaPhylip", "FastaPhylip", "none","tree",false,false,true); parameters.push_back(pfasta);
+               CommandParameter pverbose("verbose", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pverbose);
+               CommandParameter pquiet("quiet", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pquiet);
+               CommandParameter pversion("version", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pversion);
+               CommandParameter pseed("seed", "String", "", "", "*", "", "","",false,false); parameters.push_back(pseed);
+               CommandParameter pnorandom("norandom", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pnorandom);
+               CommandParameter pshuffle("shuffle", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pshuffle);
+               CommandParameter pneighbor("neighbor", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pneighbor);
+               CommandParameter pexpblen("expblen", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pexpblen);
+               CommandParameter pexpdist("expdist", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pexpdist);
+               CommandParameter pDNA("DNA", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pDNA);
+               CommandParameter pprotein("protein", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pprotein);
+               CommandParameter pjukes("jukes", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pjukes);
+               CommandParameter pkimura("kimura", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pkimura);
+               CommandParameter pstdout("stdout", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pstdout);
+               CommandParameter pntrees("ntrees", "Number", "", "1", "", "", "","",false,false); parameters.push_back(pntrees);
+               CommandParameter pmatrixout("matrixout", "String", "", "", "", "", "","",false,false); parameters.push_back(pmatrixout);
+               CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
+               CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
                
                vector<string> myArray;
                for (int i = 0; i < parameters.size(); i++) {   myArray.push_back(parameters[i].name);          }
@@ -86,7 +86,22 @@ string ClearcutCommand::getHelpString(){
                exit(1);
        }
 }
-
+//**********************************************************************************************************************
+string ClearcutCommand::getOutputPattern(string type) {
+    try {
+        string pattern = "";
+        
+        if (type == "matrixout") {  pattern = "[filename],"; } 
+        else if (type == "tree") {  pattern = "[filename],tre"; } 
+        else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true;  }
+        
+        return pattern;
+    }
+    catch(exception& e) {
+        m->errorOut(e, "ClearcutCommand", "getOutputPattern");
+        exit(1);
+    }
+}
 //**********************************************************************************************************************
 ClearcutCommand::ClearcutCommand(){    
        try {
@@ -166,10 +181,10 @@ ClearcutCommand::ClearcutCommand(string option)  {
                                //is there are current file available for either of these?
                                //give priority to phylip, then fasta
                                phylipfile = m->getPhylipFile(); 
-                               if (phylipfile != "") {  m->mothurOut("Using " + phylipfile + " as input file for the phylip parameter."); m->mothurOutEndLine(); }
+                               if (phylipfile != "") {  inputFile = phylipfile; m->mothurOut("Using " + phylipfile + " as input file for the phylip parameter."); m->mothurOutEndLine(); }
                                else { 
                                        fastafile = m->getFastaFile(); 
-                                       if (fastafile != "") {  m->mothurOut("Using " + fastafile + " as input file for the fasta parameter."); m->mothurOutEndLine(); }
+                                       if (fastafile != "") { inputFile = fastafile;  m->mothurOut("Using " + fastafile + " as input file for the fasta parameter."); m->mothurOutEndLine(); }
                                        else { 
                                                m->mothurOut("No valid current files. You must provide a phylip or fasta file before you can use the clearcut command."); m->mothurOutEndLine(); 
                                                abort = true;
@@ -244,56 +259,57 @@ int ClearcutCommand::execute() {
                if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
                
                //prepare filename
-               string outputName = outputDir + m->getRootName(m->getSimpleName(inputFile)) + "tre";
+        map<string, string> variables; 
+        variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputFile));
+               string outputName = getOutputFileName("tree", variables);
                outputNames.push_back(outputName); outputTypes["tree"].push_back(outputName);
                
                vector<char*> cPara;
                
-               char* tempClearcut = new char[8];  
-               strcpy(tempClearcut, "clearcut"); 
+               char* tempClearcut = new char[9];  
+               *tempClearcut = '\0'; strncat(tempClearcut, "clearcut", 8); 
                cPara.push_back(tempClearcut);
                                
                //you gave us a distance matrix
-               if (phylipfile != "") {  char* temp = new char[10];  strcpy(temp, "--distance");  cPara.push_back(temp);        }
+               if (phylipfile != "") {  char* temp = new char[11];  *temp = '\0'; strncat(temp, "--distance", 10);  cPara.push_back(temp);     }
                
                //you gave us a fastafile
-               if (fastafile != "") { char* temp = new char[11];  strcpy(temp, "--alignment");  cPara.push_back(temp);         }
+               if (fastafile != "") { char* temp = new char[12];  *temp = '\0'; strncat(temp, "--alignment", 11);  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 (version)                    {  char* temp = new char[10];  *temp = '\0'; strncat(temp, "--version", 9);  cPara.push_back(temp);     }
+               if (verbose)                    {  char* temp = new char[10];  *temp = '\0'; strncat(temp, "--verbose", 9);  cPara.push_back(temp);     }
+               if (quiet)                              {  char* temp = new char[8];  *temp = '\0'; strncat(temp, "--quiet", 7);  cPara.push_back(temp);        }
                if (seed != "*")                {  
                        string tempSeed = "--seed=" + seed;
-                       char* temp = new char[tempSeed.length()];
-                       strcpy(temp, tempSeed.c_str());
+                       char* temp = new char[tempSeed.length()+1];
+                       *temp = '\0'; strncat(temp, tempSeed.c_str(), tempSeed.length());
                        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);      }
+               if (norandom)                   {  char* temp = new char[11];  *temp = '\0'; strncat(temp, "--norandom", 10);  cPara.push_back(temp);   }
+               if (shuffle)                    {  char* temp = new char[10];  *temp = '\0'; strncat(temp, "--shuffle", 9);  cPara.push_back(temp);     }
+               if (neighbor)                   {  char* temp = new char[11];  *temp = '\0'; strncat(temp, "--neighbor", 10);  cPara.push_back(temp);   }
                
                string tempIn = "--in=" + inputFile;  
-               char* tempI = new char[tempIn.length()];
-               strcpy(tempI, tempIn.c_str());
+               char* tempI = new char[tempIn.length()+1];
+               *tempI = '\0'; strncat(tempI, tempIn.c_str(), tempIn.length());
                cPara.push_back(tempI);
                
-               if (stdoutWanted)               {  char* temp = new char[8];  strcpy(temp, "--stdout");  cPara.push_back(temp); }
+               if (stdoutWanted)               {  char* temp = new char[9];  *temp = '\0'; strncat(temp, "--stdout", 8);  cPara.push_back(temp);       }
                else{  
                        string tempOut = "--out=" + outputName;  
-                       
-                       char* temp = new char[tempOut.length()];
-                       strcpy(temp, tempOut.c_str());
+                       char* temp = new char[tempOut.length()+1];
+                       *temp = '\0'; strncat(temp, tempOut.c_str(), tempOut.length());
                        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 (DNA)                                {  char* temp = new char[6];  *temp = '\0'; strncat(temp, "--DNA", 5);  cPara.push_back(temp);          }
+               if (protein)                    {  char* temp = new char[10];  *temp = '\0'; strncat(temp, "--protein", 9);  cPara.push_back(temp);     }
+               if (jukes)                              {  char* temp = new char[8];  *temp = '\0'; strncat(temp, "--jukes", 7);  cPara.push_back(temp);                }
+               if (kimura)                             { char* temp = new char[9];  *temp = '\0'; strncat(temp, "--kimura", 8);  cPara.push_back(temp);                }
                if (matrixout != "")    {  
                        string tempMatrix =  "--matrixout=" + outputDir + matrixout; 
-                       char* temp = new char[tempMatrix.length()];
-                       strcpy(temp, tempMatrix.c_str());
+                       char* temp = new char[tempMatrix.length()+1];
+                       *temp = '\0'; strncat(temp, tempMatrix.c_str(), tempMatrix.length());
                        cPara.push_back(temp);
                        outputNames.push_back((outputDir + matrixout));
                        outputTypes["matrixout"].push_back((outputDir + matrixout));
@@ -301,13 +317,13 @@ int ClearcutCommand::execute() {
 
                if (ntrees != "1")              {  
                        string tempNtrees = "--ntrees=" + ntrees; 
-                       char* temp = new char[tempNtrees.length()];
-                       strcpy(temp, tempNtrees.c_str());
+                       char* temp = new char[tempNtrees.length()+1];
+                       *temp = '\0'; strncat(temp, tempNtrees.c_str(), tempNtrees.length());
                        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); }
+               if (expblen)                    { char* temp = new char[10];  *temp = '\0'; strncat(temp, "--expblen", 9);  cPara.push_back(temp);      }
+               if (expdist)                    { char* temp = new char[10];  *temp = '\0'; strncat(temp, "--expdist", 9);  cPara.push_back(temp);      }
                
                char** clearcutParameters;
                clearcutParameters = new char*[cPara.size()];