]> git.donarmstrong.com Git - mothur.git/blobdiff - errorchecking.cpp
I've changed the listfile, sabundfile, etc. option handles to not need the "file...
[mothur.git] / errorchecking.cpp
index 78b082d3e2b3c76108845a3bd15a749d4ff465b6..6ec145b7e97341178f3821e0be1dfb6cc7e360c6 100644 (file)
@@ -18,13 +18,16 @@ ErrorCheck::ErrorCheck() {
        validCommand = new ValidCommands();
        validParameter = new ValidParameters();
        validCalculator = new ValidCalculators();
-       distfile = globaldata->getDistFile();
+       columnfile = globaldata->getColumnFile();
+       phylipfile = globaldata->getPhylipFile();
        listfile = globaldata->getListFile();
        rabundfile = globaldata->getRabundFile();
        sabundfile = globaldata->getSabundFile();
        namefile = globaldata->getNameFile();
        groupfile = globaldata->getGroupFile();
        orderfile = globaldata->getOrderFile();
+       fastafile = globaldata->getFastaFile();
+       treefile = globaldata->getTreeFile();
        cutoff = globaldata->getCutOff();
        format = globaldata->getFormat();
        method = globaldata->getMethod();
@@ -69,13 +72,16 @@ bool ErrorCheck::checkInput(string input) {
                                //is it a valid parameter
                                if (validParameter->isValidParameter(parameter) != true) { return false; }
                                
-                               if (parameter == "distfile" )           { distfile = 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; }
@@ -135,13 +141,16 @@ bool ErrorCheck::checkInput(string input) {
                                //is it a valid parameter
                                if (validParameter->isValidParameter(parameter) != true) { return false; }
                                
-                               if (parameter == "distfile" )           { distfile = 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; }
@@ -198,20 +207,23 @@ bool ErrorCheck::checkInput(string input) {
                
                //make sure the user does not use both the line and label parameters
                if ((line != "") && (label != "")) { cout << "You may use either the line or label parameters, but not both." << endl; return false; }
+       
                
-               //validate files
-               if (commandName == "parselist") {
-                       validateParseFiles(commandName);
-               }
-               if ((commandName == "read.phylip") || (commandName == "read.column")) { 
+               if (commandName == "read.dist") { 
                        validateReadFiles();
                        validateReadDist();
-               }else if ((commandName == "read.list") || (commandName == "read.rabund") || (commandName == "read.sabund")){ 
-                       validateReadFiles();
-                       validateReadPhil(commandName);  
-               }else if (commandName == "read.shared") { 
+               }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") {
                        validateReadFiles();
-                       validateParseFiles(commandName); //checks the listfile and groupfile parameters
                }
                
                //are you trying to cluster before you have read something                      
@@ -251,13 +263,20 @@ void ErrorCheck::validateReadFiles() {
                ifstream filehandle;
                int ableToOpen;
        
-               //are we reading a distfile
-               if (distfile != "") {
-                       ableToOpen = openInputFile(distfile, filehandle);
+               //are we reading a phylipfile
+               if (phylipfile != "") {
+                       ableToOpen = openInputFile(phylipfile, filehandle);
+                       filehandle.close();
+                       //unable to open
+                       if (ableToOpen == 1) { errorFree = false; }
+                       else { globaldata->inputFileName = phylipfile; }
+               //are we reading a phylipfile
+               }else if (columnfile != "") {
+                       ableToOpen = openInputFile(columnfile, filehandle);
                        filehandle.close();
                        //unable to open
                        if (ableToOpen == 1) { errorFree = false; }
-                       else { globaldata->inputFileName = distfile; }
+                       else { globaldata->inputFileName = columnfile; }
                //are we reading a listfile
                }else if (listfile!= "") {
                        ableToOpen = openInputFile(listfile, filehandle);
@@ -279,6 +298,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;
                }
@@ -303,9 +328,10 @@ void ErrorCheck::validateReadDist() {
                ifstream filehandle;
                int ableToOpen;
                
-               if (distfile == "") { cout << "When executing a read.phylip or read.column you must enter a distfile." << endl; errorFree = false; }
+               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 (commandName == "read.column") {
+               if (columnfile != "") {
                        if (namefile == "") {
                                cout << "You need to provide a namefile name if you are going to use the column format." << endl;
                                errorFree = false; 
@@ -331,20 +357,16 @@ void ErrorCheck::validateReadDist() {
 /******************************************************/
 //This function checks to make sure the user entered appropriate
 // format parameters on a parselistcommand
-void ErrorCheck::validateParseFiles(string command) {
+void ErrorCheck::validateParseFiles() {
        try {
                ifstream filehandle;
                int ableToOpen;
                
                //checks for valid files
-               if (command == "read.shared" ) {
-                       if (listfile == "") { cout << "When executing a read.shared you must enter a listfile and a groupfile." << endl; errorFree = false; }
-                       else if (groupfile == "") { cout << "When executing a read.shared you must enter a listfile and a groupfile." << endl; errorFree = false; }
-               }else if (command == "parselist" ) {
-                       if (listfile == "") { cout << "When executing a parselist you must enter a listfile and a groupfile." << endl; errorFree = false; }
-                       else if (groupfile == "") { cout << "When executing a parselist you must enter a listfile and a groupfile." << endl; errorFree = false; }
-               }
-               
+       
+               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; }
+       
                //checks parameters on the read command
                if (listfile != "") {
                        ableToOpen = openInputFile(listfile, filehandle);
@@ -370,24 +392,69 @@ void ErrorCheck::validateParseFiles(string command) {
                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);
+       }
+}
 
 /*******************************************************/
 
 /******************************************************/
 //This function checks to make sure the user entered appropriate
 // format parameters on a distfile read
-void ErrorCheck::validateReadPhil(string command) {
+void ErrorCheck::validateReadPhil() {
        try {
                ifstream filehandle;
                int ableToOpen;
                
-               //checks for valid files
-               if (command == "read.list" ) {
-                       if (listfile == "") { cout << "When executing a read.list you must enter a listfile." << endl; errorFree = false; }
-               }else if (command == "read.sabund" ) {
-                       if (sabundfile == "") { cout << "When executing a read.sabund you must enter a sabundfile." << endl; errorFree = false; }
-               }else if (command == "read.rabund" ) {
-                       if (rabundfile == "") { cout << "When executing a read.rabund you must enter a rabundfile." << endl; errorFree = false; }
+               //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; }
+               }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; }
+               }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; }
+               }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; 
                }
                
                //checks parameters on the read command
@@ -414,7 +481,8 @@ void ErrorCheck::validateReadPhil(string command) {
 
 void ErrorCheck::clear() {
        //option definitions should go here...
-       distfile                =       "";
+       phylipfile              =       "";
+       columnfile              =       "";
        listfile                =       "";
        rabundfile              =       "";
        sabundfile              =       "";