]> git.donarmstrong.com Git - mothur.git/blobdiff - setcurrentcommand.cpp
added modify names parameter to set.dir
[mothur.git] / setcurrentcommand.cpp
index a4f5c5c1f7ac756c1803bb25dfd7a95133477580..9d59696ba2f47157dd059c066af108d6bb76e731 100644 (file)
 #include "setcurrentcommand.h"
 
 //**********************************************************************************************************************
-vector<string> SetCurrentCommand::getValidParameters(){        
+vector<string> SetCurrentCommand::setParameters(){     
        try {
-               string Array[] =  {"outputdir","inputdir","clear", "phylip", "column", "list","rabund","sabund","name","group",
-                       "design","order","tree","shared","ordergroup","relabund","fasta","qfile","sff","oligos","accnos","taxonomy"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               
+               CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors);
+               CommandParameter pflow("flow", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pflow);
+        CommandParameter pbiom("biom", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pbiom);
+               CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pphylip);
+               CommandParameter pcolumn("column", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pcolumn);
+        CommandParameter psummary("summary", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(psummary);
+               CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pfasta);
+               CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pname);
+               CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pgroup);
+               CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(plist);
+               CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(ptaxonomy);
+               CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pqfile);
+               CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(paccnos);         
+               CommandParameter prabund("rabund", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(prabund);
+               CommandParameter psabund("sabund", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(psabund);
+               CommandParameter pdesign("design", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pdesign);
+               CommandParameter porder("order", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(porder);
+               CommandParameter ptree("tree", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(ptree);
+               CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pshared);
+               CommandParameter pordergroup("ordergroup", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pordergroup);
+        CommandParameter pcount("count", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pcount);
+               CommandParameter prelabund("relabund", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(prelabund);
+               CommandParameter psff("sff", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(psff);
+               CommandParameter poligos("oligos", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(poligos);
+               CommandParameter pclear("clear", "String", "", "", "", "", "","",false,false); parameters.push_back(pclear);
+               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, "SetCurrentCommand", "getValidParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-SetCurrentCommand::SetCurrentCommand(){        
-       try {
-               abort = true; calledHelp = true; 
-       }
-       catch(exception& e) {
-               m->errorOut(e, "SetCurrentCommand", "SetCurrentCommand");
+               m->errorOut(e, "SetCurrentCommand", "setParameters");
                exit(1);
        }
 }
 //**********************************************************************************************************************
-vector<string> SetCurrentCommand::getRequiredParameters(){     
+string SetCurrentCommand::getHelpString(){     
        try {
-               vector<string> myArray;
-               return myArray;
+               string helpString = "";
+               helpString += "The set.current command allows you to set the current files saved by mothur.\n";
+               helpString += "The set.current command parameters are: clear, phylip, column, list, rabund, sabund, name, group, design, order, tree, shared, ordergroup, relabund, fasta, qfile, sff, oligos, accnos, biom, count, summary and taxonomy.\n";
+               helpString += "The clear paramter is used to indicate which file types you would like to clear values for, multiple types can be separated by dashes.\n";
+               helpString += "The set.current command should be in the following format: \n";
+               helpString += "set.current(fasta=yourFastaFile) or set.current(fasta=amazon.fasta, clear=name-accnos)\n";
+               return helpString;
        }
        catch(exception& e) {
-               m->errorOut(e, "SetCurrentCommand", "getRequiredParameters");
+               m->errorOut(e, "SetCurrentCommand", "getHelpString");
                exit(1);
        }
 }
+
+
 //**********************************************************************************************************************
-vector<string> SetCurrentCommand::getRequiredFiles(){  
+SetCurrentCommand::SetCurrentCommand(){        
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true;
+               setParameters();
        }
        catch(exception& e) {
-               m->errorOut(e, "SetCurrentCommand", "getRequiredFiles");
+               m->errorOut(e, "SetCurrentCommand", "SetCurrentCommand");
                exit(1);
        }
 }
@@ -61,12 +86,11 @@ SetCurrentCommand::SetCurrentCommand(string option)  {
                
                //allow user to run help
                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[] =  {"outputdir","inputdir","clear", "phylip", "column", "list","rabund","sabund","name","group",
-                               "design","order","tree","shared","ordergroup","relabund","fasta","qfile","sff","oligos","accnos","taxonomy"};
-                       vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
@@ -188,6 +212,14 @@ SetCurrentCommand::SetCurrentCommand(string option)  {
                                        if (path == "") {       parameters["ordergroup"] = inputDir + it->second;               }
                                }
                                
+                it = parameters.find("count");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = m->hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["count"] = inputDir + it->second;            }
+                               }
+                
                                it = parameters.find("relabund");
                                //user has given a template file
                                if(it != parameters.end()){ 
@@ -243,6 +275,30 @@ SetCurrentCommand::SetCurrentCommand(string option)  {
                                        //if the user has not given a path then, add inputdir. else leave path alone.
                                        if (path == "") {       parameters["taxonomy"] = inputDir + it->second;         }
                                }
+                               
+                               it = parameters.find("flow");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = m->hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["flow"] = inputDir + it->second;             }
+                               }
+                
+                it = parameters.find("biom");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = m->hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["biom"] = inputDir + it->second;             }
+                               }
+                
+                it = parameters.find("summary");
+                               //user has given a template file
+                               if(it != parameters.end()){
+                                       path = m->hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["summary"] = inputDir + it->second;          }
+                               }
                        }
                        
                        //check for parameters
@@ -280,6 +336,11 @@ SetCurrentCommand::SetCurrentCommand(string option)  {
                        if (groupfile == "not open") { m->mothurOut("Ignoring: " + parameters["group"]); m->mothurOutEndLine(); groupfile = ""; }
                        else if (groupfile == "not found") {  groupfile = "";  }
                        if (groupfile != "") { m->setGroupFile(groupfile); }
+            
+            countfile = validParameter.validFile(parameters, "count", true);
+                       if (countfile == "not open") { m->mothurOut("Ignoring: " + parameters["count"]); m->mothurOutEndLine(); countfile = ""; }
+                       else if (countfile == "not found") {  countfile = "";  }
+                       if (countfile != "") { m->setCountTableFile(countfile); }
                        
                        designfile = validParameter.validFile(parameters, "design", true);
                        if (designfile == "not open") { m->mothurOut("Ignoring: " + parameters["design"]); m->mothurOutEndLine(); designfile = ""; }
@@ -341,6 +402,26 @@ SetCurrentCommand::SetCurrentCommand(string option)  {
                        else if (taxonomyfile == "not found") {  taxonomyfile = "";  }  
                        if (taxonomyfile != "") { m->setTaxonomyFile(taxonomyfile); }
                        
+                       flowfile = validParameter.validFile(parameters, "flow", true);
+                       if (flowfile == "not open") { m->mothurOut("Ignoring: " + parameters["flow"]); m->mothurOutEndLine(); flowfile = ""; }
+                       else if (flowfile == "not found") {  flowfile = "";  }  
+                       if (flowfile != "") { m->setFlowFile(flowfile); }
+            
+            biomfile = validParameter.validFile(parameters, "biom", true);
+                       if (biomfile == "not open") { m->mothurOut("Ignoring: " + parameters["biom"]); m->mothurOutEndLine(); biomfile = ""; }
+                       else if (biomfile == "not found") {  biomfile = "";  }  
+                       if (biomfile != "") { m->setBiomFile(biomfile); }
+            
+            summaryfile = validParameter.validFile(parameters, "summary", true);
+                       if (summaryfile == "not open") { m->mothurOut("Ignoring: " + parameters["summary"]); m->mothurOutEndLine(); summaryfile = ""; }
+                       else if (summaryfile == "not found") {  summaryfile = "";  }
+                       if (summaryfile != "") { m->setSummaryFile(summaryfile); }
+
+                       
+                       processors = validParameter.validFile(parameters, "processors", false);
+                       if (processors == "not found") {  processors = "1";  }  
+                       if (processors != "") { m->setProcessors(processors); }
+                       
                        clearTypes = validParameter.validFile(parameters, "clear", false);                      
                        if (clearTypes == "not found") { clearTypes = ""; }
                        else { m->splitAtDash(clearTypes, types);       }
@@ -354,25 +435,6 @@ SetCurrentCommand::SetCurrentCommand(string option)  {
 }
 //**********************************************************************************************************************
 
-void SetCurrentCommand::help(){
-       try {
-               m->mothurOut("The set.current command allows you to set the current files saved by mothur.\n");
-               m->mothurOut("The set.current command parameters are: clear, phylip, column, list, rabund, sabund, name, group, design, order, tree, shared, ordergroup, relabund, fasta, qfile, sff, oligos, accnos, taxonomy.\n");
-               m->mothurOut("The clear paramter is used to indicate which file types you would like to clear values for, multiple types can be separated by dashes.\n");
-               m->mothurOut("The set.current command should be in the following format: \n");
-               m->mothurOut("set.current(fasta=yourFastaFile) or set.current(fasta=amazon.fasta, clear=name-accnos)\n");
-               
-       }
-       catch(exception& e) {
-               m->errorOut(e, "SetCurrentCommand", "help");
-               exit(1);
-       }
-}
-
-//**********************************************************************************************************************
-SetCurrentCommand::~SetCurrentCommand(){}
-//**********************************************************************************************************************
-
 int SetCurrentCommand::execute(){
        try {
                
@@ -423,6 +485,16 @@ int SetCurrentCommand::execute(){
                                        m->setAccnosFile("");
                                }else if (types[i] == "taxonomy") {
                                        m->setTaxonomyFile("");
+                               }else if (types[i] == "flow") {
+                                       m->setFlowFile("");
+                }else if (types[i] == "biom") {
+                                       m->setBiomFile("");
+                }else if (types[i] == "count") {
+                                       m->setCountTableFile("");
+                }else if (types[i] == "summary") {
+                                       m->setSummaryFile("");
+                               }else if (types[i] == "processors") {
+                                       m->setProcessors("1");
                                }else if (types[i] == "all") {
                                        m->clearCurrentFiles();
                                }else {