]> git.donarmstrong.com Git - mothur.git/blobdiff - clearcutcommand.cpp
fixes while testing 1.33.0
[mothur.git] / clearcutcommand.cpp
index f8d389c60d81654f944e6b892ef7ad19a6d91859..1b0a532cace0792297ce3162a03c7a382b66b282 100644 (file)
  */
 
 #include "clearcutcommand.h"
-#include "globaldata.hpp"
+#ifdef __cplusplus
+extern "C" {
+#endif
+#include "clearcut.h"
+#ifdef __cplusplus
+}
+#endif
 
+//**********************************************************************************************************************
+vector<string> ClearcutCommand::setParameters(){       
+       try {
+               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);          }
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "ClearcutCommand", "setParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+string ClearcutCommand::getHelpString(){       
+       try {
+               string helpString = "";
+               helpString += "The clearcut command interfaces mothur with the clearcut program written by Initiative for Bioinformatics and Evolutionary Studies (IBEST) at the University of Idaho.\n";
+               helpString += "For more information about clearcut refer to http://bioinformatics.hungry.com/clearcut/ \n";
+               helpString += "The clearcut command parameters are phylip, fasta, version, verbose, quiet, seed, norandom, shuffle, neighbor, expblen, expdist, ntrees, matrixout, stdout, kimura, jukes, protein, DNA. \n";
+               helpString += "The phylip parameter allows you to enter your phylip formatted distance matrix. \n";
+               helpString += "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";
+               
+               helpString += "The version parameter prints out the version of clearcut you are using, default=F. \n";
+               helpString += "The verbose parameter prints out more output from clearcut, default=F. \n";
+               helpString += "The quiet parameter turns on silent operation mode, default=F. \n";
+               helpString += "The seed parameter allows you to explicitly set the PRNG seed to a specific value. \n";
+               helpString += "The norandom parameter allows you to attempt joins deterministically, default=F. \n";
+               helpString += "The shuffle parameter allows you to randomly shuffle the distance matrix, default=F. \n";
+               helpString += "The neighbor parameter allows you to use traditional Neighbor-Joining algorithm, default=T. \n";
+               
+               helpString += "The DNA parameter allows you to indicate your fasta file contains DNA sequences, default=F. \n";
+               helpString += "The protein parameter allows you to indicate your fasta file contains protein sequences, default=F. \n";
+               
+               helpString += "The stdout parameter outputs your tree to STDOUT, default=F. \n";
+               helpString += "The matrixout parameter allows you to specify a filename to output a distance matrix to. \n";
+               helpString += "The ntrees parameter allows you to specify the number of output trees, default=1. \n";
+               helpString += "The expblen parameter allows you to use exponential notation for branch lengths, default=F. \n";
+               helpString += "The expdist parameter allows you to use exponential notation for distance outputs, default=F. \n";
+               
+               helpString += "The clearcut command should be in the following format: \n";
+               helpString += "clearcut(phylip=yourDistanceFile) \n";
+               helpString += "Example: clearcut(phylip=abrecovery.phylip.dist) \n";    
+               return helpString;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "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 {
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> tempOutNames;
+               outputTypes["tree"] = tempOutNames;
+               outputTypes["matrixout"] = tempOutNames;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "ClearcutCommand", "ClearcutCommand");
+               exit(1);
+       }
+}
 /**************************************************************************************/
 ClearcutCommand::ClearcutCommand(string option)  {     
        try {
-               abort = false;
+               abort = false; calledHelp = false;   
                
                //allow user to run help
-               if(option == "help") { help(); abort = true; }
+               if(option == "help") { help(); abort = true; calledHelp = true; }
+               else if(option == "citation") { citation(); abort = true; calledHelp = true;}
                
                else {
-                       //valid paramters for this command
-                       string Array[] =  {"fasta","phylip","version","verbose","quiet","seed","norandom","shuffle","neighbor","expblen",
-                                                               "expdist","ntrees","matrixout","stdout","kimura","jukes","protein","DNA","stdin","outputdir","inputdir"};
-                       vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
@@ -35,6 +139,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 = "";          }
@@ -43,7 +152,7 @@ ClearcutCommand::ClearcutCommand(string option)  {
                                it = parameters.find("fasta");
                                //user has given a template file
                                if(it != parameters.end()){ 
-                                       path = hasPath(it->second);
+                                       path = m->hasPath(it->second);
                                        //if the user has not given a path then, add inputdir. else leave path alone.
                                        if (path == "") {       parameters["fasta"] = inputDir + it->second;            }
                                }
@@ -51,7 +160,7 @@ ClearcutCommand::ClearcutCommand(string option)  {
                                it = parameters.find("phylip");
                                //user has given a template file
                                if(it != parameters.end()){ 
-                                       path = hasPath(it->second);
+                                       path = m->hasPath(it->second);
                                        //if the user has not given a path then, add inputdir. else leave path alone.
                                        if (path == "") {       parameters["phylip"] = inputDir + it->second;           }
                                }
@@ -61,68 +170,78 @@ ClearcutCommand::ClearcutCommand(string option)  {
                        fastafile = validParameter.validFile(parameters, "fasta", true);
                        if (fastafile == "not open") { fastafile = ""; abort = true; }
                        else if (fastafile == "not found") { fastafile = ""; }  
-                       else { inputFile = fastafile;  }
+                       else { inputFile = fastafile;  m->setFastaFile(fastafile); }
                        
                        phylipfile = validParameter.validFile(parameters, "phylip", true);
                        if (phylipfile == "not open") { phylipfile = ""; abort = true; }
                        else if (phylipfile == "not found") { phylipfile = ""; }
-                       else { inputFile = phylipfile;  }
+                       else { inputFile = phylipfile;  m->setPhylipFile(phylipfile); }
                                
-                       if ((phylipfile == "") && (fastafile == "")) {  m->mothurOut("You must provide either a phylip formatted distance matrix or an aligned fasta file."); m->mothurOutEndLine(); abort=true; }
+                       if ((phylipfile == "") && (fastafile == "")) {  
+                               //is there are current file available for either of these?
+                               //give priority to phylip, then fasta
+                               phylipfile = m->getPhylipFile(); 
+                               if (phylipfile != "") {  inputFile = phylipfile; m->mothurOut("Using " + phylipfile + " as input file for the phylip parameter."); m->mothurOutEndLine(); }
+                               else { 
+                                       fastafile = m->getFastaFile(); 
+                                       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;
+                                       }
+                               }
+                       }
                        if ((phylipfile != "") && (fastafile != "")) {  m->mothurOut("You must provide either a phylip formatted distance matrix or an aligned fasta file, not BOTH."); m->mothurOutEndLine(); abort=true; }
 
                        
                        //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 = ""; }
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = m->hasPath(inputFile);      }
                        
                        string temp;
                        temp = validParameter.validFile(parameters, "version", false);          if (temp == "not found"){       temp = "F";                     }
-                       version = isTrue(temp);
+                       version = m->isTrue(temp);
                        
                        temp = validParameter.validFile(parameters, "verbose", false);          if (temp == "not found"){       temp = "F";                     }
-                       verbose = isTrue(temp); 
+                       verbose = m->isTrue(temp); 
                        
                        temp = validParameter.validFile(parameters, "quiet", false);            if (temp == "not found"){       temp = "F";                     }
-                       quiet = isTrue(temp); 
+                       quiet = m->isTrue(temp); 
                        
                        seed = validParameter.validFile(parameters, "seed", false);                     if (seed == "not found"){       seed = "*";                     }
                        
                        temp = validParameter.validFile(parameters, "norandom", false);         if (temp == "not found"){       temp = "F";                     }
-                       norandom = isTrue(temp); 
+                       norandom = m->isTrue(temp); 
                        
                        temp = validParameter.validFile(parameters, "shuffle", false);          if (temp == "not found"){       temp = "F";                     }
-                       shuffle = isTrue(temp); 
+                       shuffle = m->isTrue(temp); 
                        
-                       temp = validParameter.validFile(parameters, "neighbor", false);         if (temp == "not found"){       temp = "F";                     }
-                       neighbor = isTrue(temp); 
-                       
-                       temp = validParameter.validFile(parameters, "stdin", false);            if (temp == "not found"){       temp = "F";                     }
-                       stdin = isTrue(temp); 
+                       temp = validParameter.validFile(parameters, "neighbor", false);         if (temp == "not found"){       temp = "T";                     }
+                       neighbor = m->isTrue(temp); 
                        
                        temp = validParameter.validFile(parameters, "DNA", false);                      if (temp == "not found"){       temp = "F";                     }
-                       DNA = isTrue(temp);
+                       DNA = m->isTrue(temp);
                        
                        temp = validParameter.validFile(parameters, "protein", false);          if (temp == "not found"){       temp = "F";                     }
-                       protein = isTrue(temp);
+                       protein = m->isTrue(temp);
                        
                        temp = validParameter.validFile(parameters, "jukes", false);            if (temp == "not found"){       temp = "F";                     }
-                       jukes = isTrue(temp);
+                       jukes = m->isTrue(temp);
                        
                        temp = validParameter.validFile(parameters, "kimura", false);           if (temp == "not found"){       temp = "F";                     }
-                       kimura = isTrue(temp);
+                       kimura = m->isTrue(temp);
                        
                        temp = validParameter.validFile(parameters, "stdout", false);           if (temp == "not found"){       temp = "F";                     }
-                       stdout = isTrue(temp); 
+                       stdoutWanted = m->isTrue(temp); 
                        
                        matrixout = validParameter.validFile(parameters, "matrixout", false);   if (matrixout == "not found"){  matrixout = "";         }
                        
                        ntrees = validParameter.validFile(parameters, "ntrees", false);         if (ntrees == "not found"){     ntrees = "1";           }
                        
                        temp = validParameter.validFile(parameters, "expblen", false);          if (temp == "not found"){       temp = "F";                     }
-                       expblen = isTrue(temp);
+                       expblen = m->isTrue(temp);
                        
                        temp = validParameter.validFile(parameters, "expdist", false);          if (temp == "not found"){       temp = "F";                     }
-                       expdist = isTrue(temp);
+                       expdist = m->isTrue(temp);
                        
                        if ((fastafile != "") && ((!DNA) && (!protein))) { m->mothurOut("You must specify the type of sequences you are using: DNA or protein"); m->mothurOutEndLine(); abort=true; }
                }
@@ -133,96 +252,102 @@ ClearcutCommand::ClearcutCommand(string option)  {
                exit(1);
        }
 }
-//**********************************************************************************************************************
-
-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, stdin. \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");
-               
-               m->mothurOut("The version parameter prints out the version of clearcut you are using, default=F. \n");
-               m->mothurOut("The verbose parameter prints out more output from clearcut, default=F. \n");
-               m->mothurOut("The quiet parameter turns on silent operation mode, default=F. \n");
-               m->mothurOut("The seed parameter allows you to explicitly set the PRNG seed to a specific value. \n");
-               m->mothurOut("The norandom parameter allows you to attempt joins deterministically, default=F. \n");
-               m->mothurOut("The shuffle parameter allows you to randomly shuffle the distance matrix, default=F. \n");
-               m->mothurOut("The neighbor parameter allows you to use traditional Neighbor-Joining algorithm, default=F. \n");
-               
-               m->mothurOut("The stdin parameter reads input from STDIN, default=F. \n");
-               m->mothurOut("The DNA parameter allows you to indicate your fasta file contains DNA sequences, default=F. \n");
-               m->mothurOut("The protein parameter allows you to indicate your fasta file contains protein sequences, default=F. \n");
-               
-               m->mothurOut("The stdout parameter outputs your tree to STDOUT, default=F. \n");
-               m->mothurOut("The matrixout parameter allows you to specify a filename to output a distance matrix to. \n");
-               m->mothurOut("The ntrees parameter allows you to specify the number of output trees, default=1. \n");
-               m->mothurOut("The expblen parameter allows you to use exponential notation for branch lengths, default=F. \n");
-               m->mothurOut("The expdist parameter allows you to use exponential notation for distance outputs, default=F. \n");
-
-               m->mothurOut("The clearcut command should be in the following format: \n");
-               m->mothurOut("clearcut(phylip=yourDistanceFile) \n");
-               m->mothurOut("Example: clearcut(phylip=abrecovery.phylip.dist) \n");    
-       }
-       catch(exception& e) {
-               m->errorOut(e, "ClearcutCommand", "help");
-               exit(1);
-       }
-}
-
 /**************************************************************************************/
 int ClearcutCommand::execute() {       
        try {
                
-               if (abort == true) { return 0; }
-                               
+               if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
+               
                //prepare filename
-               string outputName = outputDir + getRootName(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);
                
-               //get location of clearcut
-               GlobalData* globaldata = GlobalData::getInstance();
-               string path = globaldata->argv;
-               path = path.substr(0, (path.find_last_of('m')));
-
-               string clearcutCommand = path + "clearcut/clearcut ";
+               vector<char*> cPara;
                
+               char* tempClearcut = new char[9];  
+               *tempClearcut = '\0'; strncat(tempClearcut, "clearcut", 8); 
+               cPara.push_back(tempClearcut);
+                               
                //you gave us a distance matrix
-               if (phylipfile != "") { clearcutCommand += "--distance ";       }
+               if (phylipfile != "") {  char* temp = new char[11];  *temp = '\0'; strncat(temp, "--distance", 10);  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 (stdin)                              {  clearcutCommand += "--stdin ";               }
-               else                                    {  clearcutCommand += "--in=" + inputFile + " "; }
-               if (stdout)                             {  clearcutCommand += "--stdout ";              }
-               else                                    {  clearcutCommand += "--out=" + outputName + " "; }
-               
-               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());
-               
-               if (!stdout) {  
+               if (fastafile != "") { char* temp = new char[12];  *temp = '\0'; strncat(temp, "--alignment", 11);  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()+1];
+                       *temp = '\0'; strncat(temp, tempSeed.c_str(), tempSeed.length());
+                       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()+1];
+               *tempI = '\0'; strncat(tempI, tempIn.c_str(), tempIn.length());
+               cPara.push_back(tempI);
+               
+               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()+1];
+                       *temp = '\0'; strncat(temp, tempOut.c_str(), tempOut.length());
+                       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()+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));
+               }
+
+               if (ntrees != "1")              {  
+                       string tempNtrees = "--ntrees=" + ntrees; 
+                       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[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()];
+               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) {    
+                       
+                       //set first tree file as new current treefile
+                       string currentTree = "";
+                       itTypes = outputTypes.find("tree");
+                       if (itTypes != outputTypes.end()) {
+                               if ((itTypes->second).size() != 0) { currentTree = (itTypes->second)[0]; m->setTreeFile(currentTree); }
+                       }
+                       
                        m->mothurOutEndLine();
                        m->mothurOut("Output File Names: "); m->mothurOutEndLine();
-                       m->mothurOut(outputName); m->mothurOutEndLine();        
+                       for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }
                        m->mothurOutEndLine();
                }