X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=errorchecking.cpp;h=59cfb66fcc3d0f3e7136eabfebeacb4cd419d76c;hb=62f1ae1378c4c36175ec11fec8f70a3d2d26112e;hp=8556c27266ab0c2fa56bd4c9ddeb644e1d81e0b8;hpb=09a01fb51eea9e81409d367410c831394193fd86;p=mothur.git diff --git a/errorchecking.cpp b/errorchecking.cpp index 8556c27..59cfb66 100644 --- a/errorchecking.cpp +++ b/errorchecking.cpp @@ -44,7 +44,10 @@ void ErrorCheck::refresh() { /******************************************************/ -ErrorCheck::~ErrorCheck() {} +ErrorCheck::~ErrorCheck() { + delete validCommand; + delete validParameter; +} /*******************************************************/ @@ -73,6 +76,7 @@ bool ErrorCheck::checkInput(string input) { if (validCommand->isValidCommand(commandName) != true) { return false; } string parameter, value; + //reads in parameters and values if((optionText != "") && (commandName != "help")){ while((optionText.find_first_of(',') != -1) && (errorFree)) { //while there are parameters @@ -80,7 +84,9 @@ bool ErrorCheck::checkInput(string input) { splitAtEquals(parameter, value); //is it a valid parameter - if (validParameter->isValidParameter(parameter) != true) { return false; } + if (validParameter->isValidParameter(parameter, commandName, value) != true) { return false; } + + if (parameter == "phylip" ) { phylipfile = value; } if (parameter == "column" ) { columnfile = value; } @@ -102,8 +108,9 @@ 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 == "abund" ) { abund = value; } + if (parameter == "random" ) { randomtree = value; } + if (parameter == "sorted" ) { sorted = value; } } //gets the last parameter and value @@ -111,7 +118,8 @@ bool ErrorCheck::checkInput(string input) { value = optionText; splitAtEquals(parameter, value); //is it a valid parameter - if (validParameter->isValidParameter(parameter) != true) { return false; } + if (validParameter->isValidParameter(parameter, commandName, value) != true) { return false; } + if (parameter == "phylip" ) { phylipfile = value; } if (parameter == "column" ) { columnfile = value; } @@ -133,15 +141,16 @@ 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 == "random" ) { randomtree = value; } + if (parameter == "abund" ) { abund = value; } + if (parameter == "sorted" ) { sorted = value; } } } //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; } - + //check for valid files if (commandName == "read.dist") { validateReadFiles(); validateReadDist(); @@ -149,13 +158,17 @@ bool ErrorCheck::checkInput(string input) { //you want to do shared commands if ((listfile != "") && (groupfile != "")) { validateParseFiles(); //checks the listfile and groupfile parameters - }else { //you want to do single commands + //you want to do single commands + }else if ((listfile != "") || (rabundfile != "") || (sabundfile != "")){ validateReadFiles(); validateReadPhil(); + //you have not given a file + }else if ((listfile == "") && (sharedfile == "") && (rabundfile == "") && (sabundfile == "")) { + cout << "You must enter either a listfile, rabundfile, sabundfile or a sharedfile with the read.otu command. " << endl; return false; + //you want to do shared commands with a shared file + }else if (sharedfile != "") {//you are reading a shared file + validateReadFiles(); } - }else if (commandName == "read.shared") { - //you want to do shared commands with just the shared file - validateReadFiles(); }else if (commandName == "read.tree") { validateTreeFiles(); //checks the treefile and groupfile parameters }else if (commandName == "deconvolute") { @@ -164,17 +177,21 @@ bool ErrorCheck::checkInput(string input) { } //are you trying to cluster before you have read something - if ((commandName == "cluster") && (globaldata->getSparseMatrix() == NULL) || - (commandName == "cluster") && (globaldata->getListVector() == NULL)) { + if (((commandName == "cluster") && (globaldata->gSparseMatrix == NULL)) || + ((commandName == "cluster") && (globaldata->gListVector == NULL))) { cout << "Before you use the cluster command, you first need to read in a distance matrix." << endl; errorFree = false; } + if ((commandName == "libshuff") && ((globaldata->gMatrix == NULL) || (globaldata->gGroupmap == NULL))) { + cout << "You must read in a matrix and groupfile using the read.dist command, before you use the libshuff command. " << endl; return 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; } + if (randomtree == "") { + if (globaldata->gTree.size() == 0) { + cout << "You must read a treefile and a groupfile or set the randomtree parameter to the output filename you wish, before you may execute the parsimony command." << endl; return false; } } } @@ -184,6 +201,12 @@ bool ErrorCheck::checkInput(string input) { } //check for valid method + if(commandName == "get.group") { + if ((globaldata->getGroupFile() == "")) { cout << "You must read a group before you can use the get.group command." << endl; return false; } + } + if (commandName == "get.label" || commandName == "get.line") { + if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { cout << "You must read a list, sabund or rabund before you can use the get.label or get.line command." << endl; return false; } + } if (commandName == "cluster") { if ((method == "furthest") || (method == "nearest") || (method == "average")) { } else {cout << "Not a valid clustering method. Valid clustering algorithms are furthest, nearest or average." << endl; return false; } @@ -199,7 +222,13 @@ bool ErrorCheck::checkInput(string input) { else if (globaldata->getGroupFile() == "") { cout << "You must read a list and a group, or a shared before you can use the collect.shared, rarefaction.shared or summary.shared commands." << endl; return false; } } } - + + if ((commandName == "heatmap") || (commandName == "venn")) { + if ((globaldata->getListFile() == "") && (globaldata->getSharedFile() == "")) { + cout << "You must read a list, or a list and a group, or a shared before you can use the heatmap or venn commands." << endl; return false; + } + } + return errorFree; } @@ -221,7 +250,7 @@ void ErrorCheck::validateReadFiles() { //unable to open if (ableToOpen == 1) { errorFree = false; } else { globaldata->inputFileName = phylipfile; } - //are we reading a phylipfile + //are we reading a columnfile }else if (columnfile != "") { ableToOpen = openInputFile(columnfile, filehandle); filehandle.close(); @@ -285,6 +314,13 @@ void ErrorCheck::validateReadDist() { ifstream filehandle; int ableToOpen; + if (groupfile != "") { + ableToOpen = openInputFile(groupfile, filehandle); + filehandle.close(); + //unable to open + if (ableToOpen == 1) { 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; } @@ -410,7 +446,7 @@ void ErrorCheck::validateReadPhil() { }else if (sabundfile != "") { if ((listfile != "") || (rabundfile != "")) { 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 == "")) { + }else if ((listfile == "") && (rabundfile == "") && (sabundfile == "") && (sharedfile == "")) { cout << "When executing a read.otu you must enter one of the following: list, rabund or sabund." << endl; errorFree = false; }