X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=errorchecking.cpp;h=c866ca0060960ab20f50f53ffbd774c066ffc628;hb=ec453945974b5c72af0bea042e3517312566d592;hp=9a0846214bb97a9f4cce7fa42540b0e4a642dda0;hpb=cd10743907df223b7dd5b3a3deb20fde758b8ed7;p=mothur.git diff --git a/errorchecking.cpp b/errorchecking.cpp index 9a08462..c866ca0 100644 --- a/errorchecking.cpp +++ b/errorchecking.cpp @@ -23,28 +23,33 @@ ErrorCheck::ErrorCheck() { /******************************************************/ void ErrorCheck::refresh() { - 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(); - randomtree = globaldata->getRandomTree(); - sharedfile = globaldata->getSharedFile(); + + //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(); + //randomtree = globaldata->getRandomTree(); + //sharedfile = globaldata->getSharedFile(); + } /*******************************************************/ /******************************************************/ -ErrorCheck::~ErrorCheck() {} +ErrorCheck::~ErrorCheck() { + delete validCommand; + delete validParameter; +} /*******************************************************/ @@ -71,7 +76,6 @@ bool ErrorCheck::checkInput(string input) { //is it a valid command if (validCommand->isValidCommand(commandName) != true) { return false; } - string parameter, value; //reads in parameters and values @@ -81,7 +85,7 @@ bool ErrorCheck::checkInput(string input) { splitAtEquals(parameter, value); //is it a valid parameter - if (validParameter->isValidParameter(parameter, commandName) != true) { return false; } + if (validParameter->isValidParameter(parameter, commandName, value) != true) { return false; } if (parameter == "phylip" ) { phylipfile = value; } if (parameter == "column" ) { columnfile = value; } @@ -91,9 +95,11 @@ bool ErrorCheck::checkInput(string input) { if (parameter == "name" ) { namefile = value; } if (parameter == "order" ) { orderfile = value; } if (parameter == "fasta" ) { fastafile = value; } + if (parameter == "nexus" ) { nexusfile = value; } + if (parameter == "clustal" ) { clustalfile = value; } if (parameter == "tree" ) { treefile = value; } - if (parameter == "group" ) { groupfile = value; } - if (parameter == "shared" ) { sharedfile = 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; } @@ -104,7 +110,15 @@ bool ErrorCheck::checkInput(string input) { if (parameter == "line" ) { line = value; } if (parameter == "label" ) { label = value; } if (parameter == "abund" ) { abund = value; } - if (parameter == "random" ) { randomtree = value; } + if (parameter == "random" ) { randomtree = value; } + if (parameter == "sorted" ) { sorted = value; } + if (parameter == "trump" ) { trump = value; } + if (parameter == "soft" ) { soft = value; } + if (parameter == "filter" ) { filter = value; } + if (parameter == "scale" ) { scale = value; } + if (parameter == "ends" ) { ends = value; } + if (parameter == "processors" ) { processors = value; } + } //gets the last parameter and value @@ -112,7 +126,8 @@ bool ErrorCheck::checkInput(string input) { value = optionText; splitAtEquals(parameter, value); //is it a valid parameter - if (validParameter->isValidParameter(parameter, commandName) != true) { return false; } + if (validParameter->isValidParameter(parameter, commandName, value) != true) { return false; } + if (parameter == "phylip" ) { phylipfile = value; } if (parameter == "column" ) { columnfile = value; } @@ -124,6 +139,8 @@ bool ErrorCheck::checkInput(string input) { if (parameter == "group" ) { groupfile = value; } if (parameter == "shared" ) { sharedfile = value; } if (parameter == "fasta" ) { fastafile = value; } + if (parameter == "nexus" ) { nexusfile = value; } + if (parameter == "clustal" ) { clustalfile = value; } if (parameter == "tree" ) { treefile = value; } if (parameter == "cutoff" ) { cutoff = value; } if (parameter == "precision" ) { precision = value; } @@ -136,12 +153,21 @@ bool ErrorCheck::checkInput(string input) { if (parameter == "label" ) { label = value; } if (parameter == "random" ) { randomtree = value; } if (parameter == "abund" ) { abund = value; } + if (parameter == "sorted" ) { sorted = value; } + if (parameter == "trump" ) { trump = value; } + if (parameter == "soft" ) { soft = value; } + if (parameter == "filter" ) { filter = value; } + if (parameter == "scale" ) { scale = value; } + if (parameter == "ends" ) { ends = value; } + if (parameter == "processors" ) { processors = 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,12 +175,15 @@ bool ErrorCheck::checkInput(string input) { //you want to do shared commands if ((listfile != "") && (groupfile != "")) { validateParseFiles(); //checks the listfile and groupfile parameters - }else if (listfile != "") { //you want to do single commands + //you want to do single commands + }else if ((listfile != "") || (rabundfile != "") || (sabundfile != "")){ 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 + //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.tree") { @@ -164,7 +193,7 @@ bool ErrorCheck::checkInput(string input) { validateReadFiles(); } - //are you trying to cluster before you have read something + //are you trying to cluster before you have read something 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; @@ -172,7 +201,7 @@ bool ErrorCheck::checkInput(string input) { } if ((commandName == "libshuff") && ((globaldata->gMatrix == NULL) || (globaldata->gGroupmap == NULL))) { - cout << "You must read in a matrix and groupfile before you use the libshuff command. " << endl; return false; + 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") { @@ -183,9 +212,9 @@ bool ErrorCheck::checkInput(string input) { } } - if ((commandName == "unifrac.weighted") || (commandName == "unifrac.unweighted")) { + if ((commandName == "unifrac.weighted") || (commandName == "unifrac.unweighted") || (commandName == "concensus")) { if (globaldata->gTree.size() == 0) {//no trees were read - cout << "You must execute the read.tree command, before you may execute the unifrac.weighted or unifrac.unweighted command." << endl; return false; } + cout << "You must execute the read.tree command, before you may execute the unifrac.weighted, unifrac.unweighted or concensus command." << endl; return false; } } //check for valid method @@ -204,12 +233,40 @@ bool ErrorCheck::checkInput(string input) { 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") ){ + if ((commandName == "collect.shared") || (commandName == "rarefaction.shared") || (commandName == "summary.shared") || (commandName == "tree.shared") || (commandName == "bootstrap.shared")){ 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; } + if (globaldata->getListFile() == "") { cout << "You must read a list and a group, or a shared before you can use the collect.shared, rarefaction.shared, summary.shared, tree.shared or bootstrap.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, summary.shared, tree.shared or bootstrap.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; + } + } + + if ((commandName == "filter.seqs") || (commandName == "dist.seq")) { + if ((fastafile == "") && (nexusfile == "") && (clustalfile == "") && (phylipfile == "")) { + cout << "You must read either a fasta, nexus, clustal, or phylip file before you can use the filter.seqs command." << endl; return false; } + validateSeqsFiles(); + } + + if ((commandName == "bin.seqs")) { + if ((globaldata->getListFile() == "")) { cout << "You must read a list file before you can use the bin.seqs command." << endl; return false; } + validateBinFiles(); } + + if ((commandName == "get.oturep")) { + if ((globaldata->gSparseMatrix == NULL) || (globaldata->gListVector == NULL)) { + cout << "Before you use the get.oturep command, you first need to read in a distance matrix." << endl; + errorFree = false; + } + if (listfile == "") { cout << "list is a required parameter for the get.oturep command." << endl; errorFree = false; } + validateBinFiles(); + } + return errorFree; } @@ -428,7 +485,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; } @@ -452,6 +509,123 @@ void ErrorCheck::validateReadPhil() { } /*******************************************************/ +/******************************************************/ +//This function checks to make sure the user entered appropriate +// format parameters on a distfile read +void ErrorCheck::validateSeqsFiles() { + try { + ifstream filehandle; + int ableToOpen; + + //checks to make sure only one file type is given + if (phylipfile != "") { + if ((nexusfile != "") || (fastafile != "") || (clustalfile != "")) { + cout << "You may enter ONLY ONE of the following: phylip, fasta, nexus or clustal." << endl; errorFree = false; } + else { + ableToOpen = openInputFile(phylipfile, filehandle); + filehandle.close(); + if (ableToOpen == 1) { //unable to open + errorFree = false; + } + } + }else if (nexusfile != "") { + if ((phylipfile != "") || (fastafile != "") || (clustalfile != "")) { + cout << "You may enter ONLY ONE of the following: phylip, fasta, nexus or clustal." << endl; errorFree = false; } + else { + ableToOpen = openInputFile(nexusfile, filehandle); + filehandle.close(); + if (ableToOpen == 1) { //unable to open + errorFree = false; + } + } + }else if (fastafile != "") { + if ((phylipfile != "") || (nexusfile != "") || (clustalfile != "")) { + cout << "You may enter ONLY ONE of the following: phylip, fasta, nexus or clustal." << endl; errorFree = false; } + else { + ableToOpen = openInputFile(fastafile, filehandle); + filehandle.close(); + if (ableToOpen == 1) { //unable to open + errorFree = false; + } + } + }else if (clustalfile != "") { + if ((phylipfile != "") || (nexusfile != "") || (fastafile != "")) { + cout << "You may enter ONLY ONE of the following: phylip, fasta, nexus or clustal." << endl; errorFree = false; } + else { + ableToOpen = openInputFile(clustalfile, 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 validateSeqsFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the ErrorCheck class function validateSeqsFiles. 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 bin.seq command +void ErrorCheck::validateBinFiles() { + try { + ifstream filehandle; + int ableToOpen; + + if (fastafile == "") { + cout << "fasta is a required parameter for bin.seqs and get.oturep commands." << endl; errorFree = false; + }else if (fastafile != "") { + //is it a valid filename' + ableToOpen = openInputFile(fastafile, filehandle); + filehandle.close(); + //unable to open + if (ableToOpen == 1) { errorFree = false; } + }else if (listfile != "") { + //is it a valid filename' + ableToOpen = openInputFile(listfile, filehandle); + filehandle.close(); + //unable to open + if (ableToOpen == 1) { errorFree = false; } + }else if (globaldata->getNameFile() != "") { + //is it a valid filename' + ifstream filehandle; + int ableToOpen = openInputFile(globaldata->getNameFile(), filehandle); + filehandle.close(); + //unable to open + if (ableToOpen == 1) { errorFree = false; } + }else if (namefile != "") { + //is it a valid filename' + ifstream filehandle; + int ableToOpen = openInputFile(namefile, filehandle); + filehandle.close(); + //unable to open + if (ableToOpen == 1) { errorFree = false; } + } + + + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateBinFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the ErrorCheck class function validateBinFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} + +/*******************************************************/ + /******************************************************/ void ErrorCheck::clear() { @@ -465,6 +639,9 @@ void ErrorCheck::clear() { groupfile = ""; orderfile = ""; sharedfile = ""; + fastafile = ""; + nexusfile = ""; + clustalfile = ""; line = ""; label = ""; method = "furthest";