]> git.donarmstrong.com Git - mothur.git/blobdiff - errorchecking.cpp
rarefaction.shared() fixed bug
[mothur.git] / errorchecking.cpp
index 903c58137c1de81036dd43adf6cc3619a861a3c6..7d63e9b5a53b77afcb277963f31418ac8bdfccd9 100644 (file)
@@ -26,6 +26,8 @@ ErrorCheck::ErrorCheck() {
        namefile = globaldata->getNameFile();
        groupfile = globaldata->getGroupFile();
        orderfile = globaldata->getOrderFile();
+       fastafile = globaldata->getFastaFile();
+       treefile = globaldata->getTreeFile();
        cutoff = globaldata->getCutOff();
        format = globaldata->getFormat();
        method = globaldata->getMethod();
@@ -70,14 +72,16 @@ bool ErrorCheck::checkInput(string input) {
                                //is it a valid parameter
                                if (validParameter->isValidParameter(parameter) != true) { return false; }
                                
-                               if (parameter == "phylipfile" )         { phylipfile = value; }
-                               if (parameter == "columnfile" )         { columnfile = value; }
-                               if (parameter == "listfile" )           { listfile = value; }
-                               if (parameter == "rabundfile" )         { rabundfile = value; }
-                               if (parameter == "sabundfile" )         { sabundfile = value; }
-                               if (parameter == "namefile" )           { namefile = value; }
-                               if (parameter == "orderfile" )          { orderfile = value; }
-                               if (parameter == "groupfile" )          { groupfile = value; }
+                               if (parameter == "phylip" )             { phylipfile = value; }
+                               if (parameter == "column" )             { columnfile = value; }
+                               if (parameter == "list" )               { listfile = value; }
+                               if (parameter == "rabund" )             { rabundfile = value; }
+                               if (parameter == "sabund" )             { sabundfile = value; }
+                               if (parameter == "name" )               { namefile = value; }
+                               if (parameter == "order" )              { orderfile = value; }
+                               if (parameter == "fasta" )              { fastafile = value; }
+                               if (parameter == "treefile" )           { treefile = value; }
+                               if (parameter == "group" )              { groupfile = value; }
                                if (parameter == "cutoff" )                     { cutoff = value; }
                                if (parameter == "precision" )          { precision = value; }
                                if (parameter == "iters" )                      { iters = value; }
@@ -137,14 +141,16 @@ bool ErrorCheck::checkInput(string input) {
                                //is it a valid parameter
                                if (validParameter->isValidParameter(parameter) != true) { return false; }
                                
-                               if (parameter == "phylipfile" )         { phylipfile = value; }
-                               if (parameter == "columnfile" )         { columnfile = value; }                         
-                               if (parameter == "listfile" )           { listfile = value; }
-                               if (parameter == "rabundfile" )         { rabundfile = value; }
-                               if (parameter == "sabundfile" )         { sabundfile = value; }
-                               if (parameter == "namefile" )           { namefile = value; }
-                               if (parameter == "orderfile" )          { orderfile = value; }
-                               if (parameter == "groupfile" )          { groupfile = value; }
+                               if (parameter == "phylip" )             { phylipfile = value; }
+                               if (parameter == "column" )             { columnfile = value; }                         
+                               if (parameter == "list" )               { listfile = value; }
+                               if (parameter == "rabund" )             { rabundfile = value; }
+                               if (parameter == "sabund" )             { sabundfile = value; }
+                               if (parameter == "name" )               { namefile = value; }
+                               if (parameter == "order" )              { orderfile = value; }
+                               if (parameter == "group" )              { groupfile = value; }
+                               if (parameter == "fasta" )              { fastafile = value; }
+                               if (parameter == "treefile" )           { treefile = value; }
                                if (parameter == "cutoff" )                     { cutoff = value; }
                                if (parameter == "precision" )          { precision = value; }
                                if (parameter == "iters" )                      { iters = value; }
@@ -207,10 +213,18 @@ bool ErrorCheck::checkInput(string input) {
                        validateReadFiles();
                        validateReadDist();
                }else if (commandName == "read.otu") { 
+                       //you want to do shared commands
+                       if ((listfile != "") && (groupfile != ""))      {
+                               validateParseFiles(); //checks the listfile and groupfile parameters
+                       }else { //you want to do single commands
+                               validateReadFiles();
+                               validateReadPhil();
+                       }
+               }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();
-                       validateReadPhil();     
-               }else if (commandName == "read.list") { 
-                       validateParseFiles(); //checks the listfile and groupfile parameters
                }
                
                //are you trying to cluster before you have read something                      
@@ -227,12 +241,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; }
                }
  
                
@@ -285,6 +299,12 @@ void ErrorCheck::validateReadFiles() {
                        //unable to open
                        if (ableToOpen == 1) {  errorFree = false; }
                        else { globaldata->inputFileName = sabundfile; }
+               }else if (fastafile != "") {
+                       ableToOpen = openInputFile(fastafile, filehandle);
+                       filehandle.close();
+                       //unable to open
+                       if (ableToOpen == 1) {  errorFree = false; }
+                       else { globaldata->inputFileName = fastafile; }
                }else{ //no file given
                        errorFree = false;
                }
@@ -309,12 +329,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);
@@ -345,8 +365,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 != "") {
@@ -373,6 +393,46 @@ void ErrorCheck::validateParseFiles() {
                exit(1);
        }
 }
+/*******************************************************/
+
+/******************************************************/
+//This function checks to make sure the user entered appropriate
+// format parameters on a parselistcommand
+void ErrorCheck::validateTreeFiles() {
+       try {
+               ifstream filehandle;
+               int ableToOpen;
+               
+               //checks for valid files
+       
+               if (treefile == "") { cout << "When executing a read.tree you must enter a treefile and a groupfile." << endl; errorFree = false; }
+               else if (groupfile == "") { cout << "When executing a read.tree you must enter a treefile and a groupfile." << endl; errorFree = false; }
+       
+               //checks parameters on the read command
+               if (treefile != "") {
+                       ableToOpen = openInputFile(treefile, filehandle);
+                       filehandle.close();
+                       if (ableToOpen == 1) { //unable to open
+                               errorFree = false;
+                       }
+                       if (groupfile != "") {
+                               ableToOpen = openInputFile(groupfile, filehandle);
+                               filehandle.close();
+                               if (ableToOpen == 1) { //unable to open
+                                       errorFree = false;;
+                               }
+                       }
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateTreeFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ErrorCheck class function validateTreeFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
 
 /*******************************************************/
 
@@ -387,15 +447,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