]> git.donarmstrong.com Git - mothur.git/blobdiff - errorchecking.cpp
adding treeclimber and unifrac pieces
[mothur.git] / errorchecking.cpp
index 6ec145b7e97341178f3821e0be1dfb6cc7e360c6..03844d5fa5b132e21ad1ae60e1c9e7b43e343aa2 100644 (file)
@@ -18,6 +18,12 @@ ErrorCheck::ErrorCheck() {
        validCommand = new ValidCommands();
        validParameter = new ValidParameters();
        validCalculator = new ValidCalculators();
+}
+/*******************************************************/
+
+/******************************************************/
+
+void ErrorCheck::refresh() {
        columnfile = globaldata->getColumnFile();
        phylipfile = globaldata->getPhylipFile();
        listfile = globaldata->getListFile();
@@ -31,8 +37,9 @@ ErrorCheck::ErrorCheck() {
        cutoff = globaldata->getCutOff();
        format = globaldata->getFormat();
        method = globaldata->getMethod();
-
+       randomtree = globaldata->getRandomTree();
 }
+
 /*******************************************************/
 
 /******************************************************/
@@ -46,7 +53,10 @@ ErrorCheck::~ErrorCheck() {}
 bool ErrorCheck::checkInput(string input) {
                errorFree = true;
                clear();
-
+               
+               //refresh variable
+               refresh();
+               
                //get command name and parameters
                int openParen = input.find_first_of('(');
                int closeParen = input.find_last_of(')');
@@ -91,6 +101,7 @@ bool ErrorCheck::checkInput(string input) {
                                if (parameter == "fileroot" )           { fileroot = value; }
                                if (parameter == "line" )                       { line = value; }
                                if (parameter == "label" )                      { label = value; }
+                               if (parameter == "randomtree" )         { randomtree = value;   }
 
                                if (parameter == "single") {//stores estimators in a vector
                                        singleEsimators.clear(); //clears out old values
@@ -160,6 +171,7 @@ bool ErrorCheck::checkInput(string input) {
                                if (parameter == "fileroot" )           { fileroot = value; }
                                if (parameter == "line" )                       { line = value; }
                                if (parameter == "label" )                      { label = value; }
+                               if (parameter == "randomtree" )         { randomtree = value;   }
 
                                if (parameter == "single") {//stores estimators in a vector
                                        singleEsimators.clear(); //clears out old values
@@ -223,6 +235,7 @@ bool ErrorCheck::checkInput(string input) {
                }else if (commandName == "read.tree") { 
                        validateTreeFiles(); //checks the treefile and groupfile parameters
                }else if (commandName == "deconvolute") {
+                       if (fastafile == "") { cout << "You must enter a fastafile with the deconvolute() command." << endl; return false; }
                        validateReadFiles();
                }
                
@@ -233,6 +246,14 @@ bool ErrorCheck::checkInput(string input) {
                                errorFree = false;
                } 
                
+               if (commandName == "parsimony") {
+                       //are you trying to use parsimony without reading a tree or saying you want random distribution
+                       if (randomtree == "0")  {
+                               if ((globaldata->getTreeFile() == "") || (globaldata->getGroupFile() == "")) {
+                                       cout << "You must read a treefile and a groupfile or set the randomtree parameter to 1, before you may execute the parsimony command." << endl; return false;  }
+                       }
+               }
+               
                //check for valid method
                if (commandName == "cluster") {
                        if ((method == "furthest") || (method == "nearest") || (method == "average")) { }
@@ -240,12 +261,12 @@ bool ErrorCheck::checkInput(string input) {
                }
                
                if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single") ){ 
-                       if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { cout << "You must read a listfile, sabundfile or rabundfile before you can use the collect.single, rarefaction.single or summary.single commands." << endl; return false; }
+                       if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { cout << "You must read a list, sabund or rabund before you can use the collect.single, rarefaction.single or summary.single commands." << endl; return false; }
                }
                
-               if ((commandName == "collect.shared") || (commandName == "rarefaction.shared") || (commandName == "summary.shared") || (commandName == "shared") ){ 
-                       if (globaldata->getListFile() == "") { cout << "You must read a listfile and a groupfile before you can use the collect.shared, rarefaction.shared, summary.shared or shared commands." << endl; return false; }
-                       else if (globaldata->getGroupFile() == "") { cout << "You must read a listfile and a groupfile before you can use the collect.shared, rarefaction.shared, summary.shared or shared commands." << endl; return false; }
+               if ((commandName == "collect.shared") || (commandName == "rarefaction.shared") || (commandName == "summary.shared") ){ 
+                       if (globaldata->getListFile() == "") { cout << "You must read a list and a group before you can use the collect.shared, rarefaction.shared or summary.shared commands." << endl; return false; }
+                       else if (globaldata->getGroupFile() == "") { cout << "You must read a list and a group before you can use the collect.shared, rarefaction.shared or summary.shared commands." << endl; return false; }
                }
  
                
@@ -328,12 +349,12 @@ void ErrorCheck::validateReadDist() {
                ifstream filehandle;
                int ableToOpen;
                
-               if ((phylipfile == "") && (columnfile == "")) { cout << "When executing a read.dist you must enter a phylipfile or a columnfile." << endl; errorFree = false; }
-               else if ((phylipfile != "") && (columnfile != "")) { cout << "When executing a read.dist you must enter ONLY ONE of the following: phylipfile or columnfile." << endl; errorFree = false; }
+               if ((phylipfile == "") && (columnfile == "")) { cout << "When executing a read.dist you must enter a phylip or a column." << endl; errorFree = false; }
+               else if ((phylipfile != "") && (columnfile != "")) { cout << "When executing a read.dist you must enter ONLY ONE of the following: phylip or column." << endl; errorFree = false; }
                
                if (columnfile != "") {
                        if (namefile == "") {
-                               cout << "You need to provide a namefile name if you are going to use the column format." << endl;
+                               cout << "You need to provide a namefile if you are going to use the column format." << endl;
                                errorFree = false; 
                        }else {
                                ableToOpen = openInputFile(namefile, filehandle);
@@ -364,8 +385,8 @@ void ErrorCheck::validateParseFiles() {
                
                //checks for valid files
        
-               if (listfile == "") { cout << "When executing a read.list you must enter a listfile and a groupfile." << endl; errorFree = false; }
-               else if (groupfile == "") { cout << "When executing a read.list you must enter a listfile and a groupfile." << endl; errorFree = false; }
+               if (listfile == "") { cout << "When executing a read.otu for groups you must enter a list and a group." << endl; errorFree = false; }
+               else if (groupfile == "") { cout << "When executing a read.otu for groups you must enter a list and a group." << endl; errorFree = false; }
        
                //checks parameters on the read command
                if (listfile != "") {
@@ -446,15 +467,15 @@ void ErrorCheck::validateReadPhil() {
                //checks to make sure only one file type is given
                if (listfile != "") { 
                        if ((rabundfile != "") || (sabundfile != "")) { 
-                               cout << "When executing a read.otu you must enter ONLY ONE of the following: listfile, rabundfile or sabundfile." << endl; errorFree = false; }
+                               cout << "When executing a read.otu you must enter ONLY ONE of the following: list, rabund or sabund." << endl; errorFree = false; }
                }else if (rabundfile != "") { 
                        if ((listfile != "") || (sabundfile != "")) { 
-                               cout << "When executing a read.otu you must enter ONLY ONE of the following: listfile, rabundfile or sabundfile." << endl; errorFree = false; }
+                               cout << "When executing a read.otu you must enter ONLY ONE of the following: list, rabund or sabund." << endl; errorFree = false; }
                }else if (sabundfile != "") { 
                        if ((listfile != "") || (rabundfile != "")) { 
-                               cout << "When executing a read.otu you must enter ONLY ONE of the following: listfile, rabundfile or sabundfile." << endl; errorFree = false; }
+                               cout << "When executing a read.otu you must enter ONLY ONE of the following: list, rabund or sabund." << endl; errorFree = false; }
                }else if ((listfile == "") && (rabundfile == "") && (sabundfile == "")) {
-                           cout << "When executing a read.otu you must enter one of the following: listfile, rabundfile or sabundfile." << endl; errorFree = false; 
+                           cout << "When executing a read.otu you must enter one of the following: list, rabund or sabund." << endl; errorFree = false; 
                }
                
                //checks parameters on the read command