X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=errorchecking.cpp;h=5f587a9b83a1a140409fc0cbdfa4bba0169ea518;hb=cfb66eb46a9678a751a8f21f3ea740dffd525f5e;hp=067d246d4c50f1427840c3879be04bac2ff7cdf8;hpb=b2dca66a02f8f82aa5528e531eace60fbbd2967b;p=mothur.git diff --git a/errorchecking.cpp b/errorchecking.cpp index 067d246..5f587a9 100644 --- a/errorchecking.cpp +++ b/errorchecking.cpp @@ -17,7 +17,6 @@ ErrorCheck::ErrorCheck() { globaldata = GlobalData::getInstance(); validCommand = new ValidCommands(); validParameter = new ValidParameters(); - validCalculator = new ValidCalculators(); } /*******************************************************/ @@ -38,6 +37,7 @@ void ErrorCheck::refresh() { format = globaldata->getFormat(); method = globaldata->getMethod(); randomtree = globaldata->getRandomTree(); + sharedfile = globaldata->getSharedFile(); } /*******************************************************/ @@ -73,14 +73,15 @@ 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 - globaldata->splitAtComma(value, optionText); - globaldata->splitAtEquals(parameter, value); + splitAtComma(value, optionText); + splitAtEquals(parameter, value); //is it a valid parameter - if (validParameter->isValidParameter(parameter) != true) { return false; } + if (validParameter->isValidParameter(parameter, commandName) != true) { return false; } if (parameter == "phylip" ) { phylipfile = value; } if (parameter == "column" ) { columnfile = value; } @@ -92,6 +93,7 @@ bool ErrorCheck::checkInput(string input) { if (parameter == "fasta" ) { fastafile = value; } if (parameter == "tree" ) { treefile = value; } if (parameter == "group" ) { groupfile = value; } + if (parameter == "shared" ) { sharedfile = value; } if (parameter == "cutoff" ) { cutoff = value; } if (parameter == "precision" ) { precision = value; } if (parameter == "iters" ) { iters = value; } @@ -101,56 +103,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 == "single") {//stores estimators in a vector - singleEsimators.clear(); //clears out old values - globaldata->splitAtDash(value, singleEsimators); - for (int i = 0; i < singleEsimators.size(); i++) { //loop through estimators - //is it a valid calculator - if (validCalculator->isValidCalculator(parameter, singleEsimators[i]) != true) { return false; } - } - } - if (parameter == "rarefaction") {//stores estimators in a vector - rareEstimators.clear(); //clears out old values - globaldata->splitAtDash(value, rareEstimators); - for (int i = 0; i < rareEstimators.size(); i++) { //loop through estimators - //is it a valid calculator - if (validCalculator->isValidCalculator(parameter, rareEstimators[i]) != true) { return false; } - } - } - if (parameter == "shared") {//stores estimators in a vector - sharedEstimators.clear(); //clears out old values - globaldata->splitAtDash(value, sharedEstimators); - for (int i = 0; i < sharedEstimators.size(); i++) { //loop through estimators - //is it a valid calculator - if (validCalculator->isValidCalculator(parameter, sharedEstimators[i]) != true) { return false; } - } - } - if (parameter == "summary") { //stores summaries to be used in a vector - summaryEstimators.clear(); //clears out old values - globaldata->splitAtDash(value, summaryEstimators); - for (int i = 0; i < summaryEstimators.size(); i++) { //loop through estimators - //is it a valid calculator - if (validCalculator->isValidCalculator(parameter, summaryEstimators[i]) != true) { return false; } - } - } - if (parameter == "sharedrarefaction") { //stores summaries to be used in a vector - sharedRareEstimators.clear(); //clears out old values - globaldata->splitAtDash(value, sharedRareEstimators); - for (int i = 0; i < sharedRareEstimators.size(); i++) { //loop through estimators - //is it a valid calculator - if (validCalculator->isValidCalculator(parameter, sharedRareEstimators[i]) != true) { return false; } - } - } + if (parameter == "abund" ) { abund = value; } + if (parameter == "random" ) { randomtree = value; } } //gets the last parameter and value if (errorFree) { //gets the last parameter and value value = optionText; - globaldata->splitAtEquals(parameter, value); + splitAtEquals(parameter, value); //is it a valid parameter - if (validParameter->isValidParameter(parameter) != true) { return false; } + if (validParameter->isValidParameter(parameter, commandName) != true) { return false; } if (parameter == "phylip" ) { phylipfile = value; } if (parameter == "column" ) { columnfile = value; } @@ -160,6 +122,7 @@ bool ErrorCheck::checkInput(string input) { if (parameter == "name" ) { namefile = value; } if (parameter == "order" ) { orderfile = value; } if (parameter == "group" ) { groupfile = value; } + if (parameter == "shared" ) { sharedfile = value; } if (parameter == "fasta" ) { fastafile = value; } if (parameter == "tree" ) { treefile = value; } if (parameter == "cutoff" ) { cutoff = value; } @@ -171,55 +134,13 @@ 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 - globaldata->splitAtDash(value, singleEsimators); - for (int i = 0; i < singleEsimators.size(); i++) { //loop through estimators - //is it a valid calculator - if (validCalculator->isValidCalculator(parameter, singleEsimators[i]) != true) { return false; } - } - } - if (parameter == "rarefaction") {//stores estimators in a vector - rareEstimators.clear(); //clears out old values - globaldata->splitAtDash(value, rareEstimators); - for (int i = 0; i < rareEstimators.size(); i++) { //loop through estimators - //is it a valid calculator - if (validCalculator->isValidCalculator(parameter, rareEstimators[i]) != true) { return false; } - } - } - if (parameter == "shared") {//stores estimators in a vector - sharedEstimators.clear(); //clears out old values - globaldata->splitAtDash(value, sharedEstimators); - for (int i = 0; i < sharedEstimators.size(); i++) { //loop through estimators - //is it a valid calculator - if (validCalculator->isValidCalculator(parameter, sharedEstimators[i]) != true) { return false; } - } - } - if (parameter == "summary") { //stores summaries to be used in a vector - summaryEstimators.clear(); //clears out old values - globaldata->splitAtDash(value, summaryEstimators); - for (int i = 0; i < summaryEstimators.size(); i++) { //loop through estimators - //is it a valid calculator - if (validCalculator->isValidCalculator(parameter, summaryEstimators[i]) != true) { return false; } - } - } - if (parameter == "sharedrarefaction") { //stores summaries to be used in a vector - sharedRareEstimators.clear(); //clears out old values - globaldata->splitAtDash(value, sharedRareEstimators); - for (int i = 0; i < sharedRareEstimators.size(); i++) { //loop through estimators - //is it a valid calculator - if (validCalculator->isValidCalculator(parameter, sharedRareEstimators[i]) != true) { return false; } - } - } - + if (parameter == "random" ) { randomtree = value; } + if (parameter == "abund" ) { abund = 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; } - if (commandName == "read.dist") { validateReadFiles(); @@ -228,9 +149,13 @@ 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 + }else if (listfile != "") { //you want to do single commands validateReadFiles(); validateReadPhil(); + }else if ((listfile == "") && (sharedfile == "")) { + cout << "You must enter either a listfile or a sharedfile with the read.otu command. " << endl; return false; + }else{//you are reading a shared file + validateReadFiles(); } }else if (commandName == "read.tree") { validateTreeFiles(); //checks the treefile and groupfile parameters @@ -240,17 +165,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)) { + cout << "You must read in a matrix 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; } } } @@ -260,6 +189,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; } @@ -270,11 +205,12 @@ bool ErrorCheck::checkInput(string input) { } 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; } + if (globaldata->getSharedFile() == "") { + if (globaldata->getListFile() == "") { 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; } + 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; } + } } - - + return errorFree; } @@ -296,7 +232,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(); @@ -330,6 +266,12 @@ void ErrorCheck::validateReadFiles() { //unable to open if (ableToOpen == 1) { errorFree = false; } else { globaldata->inputFileName = fastafile; } + }else if (sharedfile != "") { + ableToOpen = openInputFile(sharedfile, filehandle); + filehandle.close(); + //unable to open + if (ableToOpen == 1) { errorFree = false; } + else { globaldata->inputFileName = sharedfile; } }else{ //no file given errorFree = false; } @@ -354,6 +296,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; } @@ -515,6 +464,7 @@ void ErrorCheck::clear() { namefile = ""; groupfile = ""; orderfile = ""; + sharedfile = ""; line = ""; label = ""; method = "furthest";