]> git.donarmstrong.com Git - mothur.git/blobdiff - mantelcommand.cpp
fixes while testing 1.33.0
[mothur.git] / mantelcommand.cpp
index a1f7b3bafc35e3e7009462d3d944005bf055bd94..b9e4df93eff8b19bece4740e22c6526736b1faf2 100644 (file)
 #include "mantelcommand.h"
 #include "readphylipvector.h"
 
+
 //**********************************************************************************************************************
-vector<string> MantelCommand::getValidParameters(){    
+vector<string> MantelCommand::setParameters(){ 
        try {
-               string Array[] =  {"phylip1","phylip2","method","iters","outputdir","inputdir"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               CommandParameter pphylip1("phylip1", "InputTypes", "", "", "none", "none", "none","mantel",false,true,true); parameters.push_back(pphylip1);
+               CommandParameter pphylip2("phylip2", "InputTypes", "", "", "none", "none", "none","mantel",false,true,true); parameters.push_back(pphylip2);
+               CommandParameter piters("iters", "Number", "", "1000", "", "", "","",false,false); parameters.push_back(piters);
+               CommandParameter pmethod("method", "Multiple", "pearson-spearman-kendall", "pearson", "", "", "","",false,false); parameters.push_back(pmethod);
+               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, "MantelCommand", "getValidParameters");
+               m->errorOut(e, "MantelCommand", "setParameters");
                exit(1);
        }
 }
 //**********************************************************************************************************************
-vector<string> MantelCommand::getRequiredParameters(){ 
+string MantelCommand::getHelpString(){ 
        try {
-               string Array[] =  {"phylip1", "phylip2"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
+               string helpString = "";
+               helpString += "Sokal, R. R., & Rohlf, F. J. (1995). Biometry, 3rd edn. New York: Freeman.\n";
+               helpString += "The mantel command reads two distance matrices and calculates the mantel correlation coefficient.\n";
+               helpString += "The mantel command parameters are phylip1, phylip2, iters and method.  The phylip1 and phylip2 parameters are required.  Matrices must be the same size and contain the same names.\n";
+               helpString += "The method parameter allows you to select what method you would like to use. Options are pearson, spearman and kendall. Default=pearson.\n";
+               helpString += "The iters parameter allows you to set number of randomization for the P value.  The default is 1000. \n";
+               helpString += "The mantel command should be in the following format: mantel(phylip1=veg.dist, phylip2=env.dist).\n";
+               helpString += "The mantel command outputs a .mantel file.\n";
+               helpString += "Note: No spaces between parameter labels (i.e. phylip1), '=' and parameters (i.e. veg.dist).\n";
+               return helpString;
        }
        catch(exception& e) {
-               m->errorOut(e, "MantelCommand", "getRequiredParameters");
+               m->errorOut(e, "MantelCommand", "getHelpString");
                exit(1);
        }
 }
 //**********************************************************************************************************************
+string MantelCommand::getOutputPattern(string type) {
+    try {
+        string pattern = "";
+        
+        if (type == "mantel") {  pattern = "[filename],mantel"; } 
+        else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true;  }
+        
+        return pattern;
+    }
+    catch(exception& e) {
+        m->errorOut(e, "MantelCommand", "getOutputPattern");
+        exit(1);
+    }
+}
+//**********************************************************************************************************************
 MantelCommand::MantelCommand(){        
        try {
-               abort = true; calledHelp = true; 
+               abort = true; calledHelp = true;
+               setParameters();
                vector<string> tempOutNames;
                outputTypes["mantel"] = tempOutNames;
        }
@@ -46,18 +77,6 @@ MantelCommand::MantelCommand(){
                exit(1);
        }
 }
-
-//**********************************************************************************************************************
-vector<string> MantelCommand::getRequiredFiles(){      
-       try {
-               vector<string> myArray;
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "MantelCommand", "getRequiredFiles");
-               exit(1);
-       }
-}
 //**********************************************************************************************************************
 MantelCommand::MantelCommand(string option)  {
        try {
@@ -65,11 +84,10 @@ MantelCommand::MantelCommand(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[] =  {"phylip1","phylip2","method","iters","outputdir","inputdir"};
-                       vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string, string> parameters = parser.getParameters();
@@ -122,7 +140,7 @@ MantelCommand::MantelCommand(string option)  {
                        method = validParameter.validFile(parameters, "method", false);         if (method == "not found"){     method = "pearson";             }
                        
                        string temp = validParameter.validFile(parameters, "iters", false);                     if (temp == "not found") { temp = "1000"; }
-                       convert(temp, iters);
+                       m->mothurConvert(temp, iters);
                        
                        if ((method != "pearson") && (method != "spearman") && (method != "kendall")) { m->mothurOut(method + " is not a valid method. Valid methods are pearson, spearman, and kendall."); m->mothurOutEndLine(); abort = true; }
                }
@@ -134,29 +152,6 @@ MantelCommand::MantelCommand(string option)  {
 }
 //**********************************************************************************************************************
 
-void MantelCommand::help(){
-       try {
-               m->mothurOut("Sokal, R. R., & Rohlf, F. J. (1995). Biometry, 3rd edn. New York: Freeman.\n");
-               m->mothurOut("The mantel command reads two distance matrices and calculates the mantel correlation coefficient.\n");
-               m->mothurOut("The mantel command parameters are phylip1, phylip2, iters and method.  The phylip1 and phylip2 parameters are required.  Matrices must be the same size and contain the same names.\n");
-               m->mothurOut("The method parameter allows you to select what method you would like to use. Options are pearson, spearman and kendall. Default=pearson.\n");
-               m->mothurOut("The iters parameter allows you to set number of randomization for the P value.  The default is 1000. \n");
-               m->mothurOut("The mantel command should be in the following format: mantel(phylip1=veg.dist, phylip2=env.dist).\n");
-               m->mothurOut("The mantel command outputs a .mantel file.\n");
-               m->mothurOut("Note: No spaces between parameter labels (i.e. phylip1), '=' and parameters (i.e. veg.dist).\n\n");
-       }
-       catch(exception& e) {
-               m->errorOut(e, "MantelCommand", "help");        
-               exit(1);
-       }
-}
-
-//**********************************************************************************************************************
-
-MantelCommand::~MantelCommand(){}
-
-//**********************************************************************************************************************
-
 int MantelCommand::execute(){
        try {
                
@@ -226,7 +221,9 @@ int MantelCommand::execute(){
                
                if (m->control_pressed) { return 0; }
                
-               string outputFile = outputDir + m->getRootName(m->getSimpleName(phylipfile1)) + "mantel";
+        map<string, string> variables; 
+               variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(phylipfile1));
+               string outputFile = getOutputFileName("mantel",variables);
                outputNames.push_back(outputFile); outputTypes["mantel"].push_back(outputFile);
                ofstream out;