X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=validparameter.cpp;h=7d1af2551c7a6717c1d3ea807af0e56de0fc218e;hp=486316fcdc814307e78e029f9fc7400451cd9393;hb=615301e57c25e241356a9c2380648d117709458d;hpb=0470f6d037aacb3563c3f7010708120a4a67d4e6 diff --git a/validparameter.cpp b/validparameter.cpp index 486316f..7d1af25 100644 --- a/validparameter.cpp +++ b/validparameter.cpp @@ -13,16 +13,27 @@ ValidParameters::ValidParameters() { try { + m = MothurOut::getInstance(); initParameterRanges(); + commandName = ""; } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the ValidParameters class Function ValidParameters. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "ValidParameters", "ValidParameters"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the ValidParameters class function ValidParameters. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; +} +/***********************************************************************/ + +ValidParameters::ValidParameters(string c) { + try { + m = MothurOut::getInstance(); + initParameterRanges(); + commandName = c; + } + catch(exception& e) { + m->errorOut(e, "ValidParameters", "ValidParameters"); exit(1); - } + } } /***********************************************************************/ @@ -42,11 +53,11 @@ bool ValidParameters::isValidParameter(string parameter, vector cParams, } } if(!valid) { - cout << "'" << parameter << "' is not a valid parameter." << endl; - cout << "The valid parameters are: "; + m->mothurOut(parameter + " is not a valid parameter."); m->mothurOutEndLine(); + m->mothurOut("The valid parameters are: "); for(int i = 0; i < numParams-1; i++) - cout << cParams.at(i) << ", "; - cout << "and " << cParams.at(numParams-1) << ".\n"; + m->mothurOut(cParams.at(i) + ", "); + m->mothurOut("and " + cParams.at(numParams-1) + ".\n"); return false; } @@ -58,7 +69,7 @@ bool ValidParameters::isValidParameter(string parameter, vector cParams, vector range = parameterRanges[parameter]; vector values; - splitAtDash(value, values); + m->splitAtDash(value, values); for(int i = 0; i < values.size(); i++) { value = values.at(i); @@ -77,7 +88,7 @@ bool ValidParameters::isValidParameter(string parameter, vector cParams, double logNum = log10((double)pVal); double diff = (double)((int)logNum - logNum); if(diff != 0) { - cout << "The precision parameter can only take powers of 10 as a value (e.g. 10,1000,1000, etc.)\n"; + m->mothurOut("The precision parameter can only take powers of 10 as a value (e.g. 10,1000,1000, etc.)\n"); return false; } } @@ -103,7 +114,7 @@ bool ValidParameters::isValidParameter(string parameter, vector cParams, else if(range.at(4).compare("only") == 0) c = 1; else { - cout << "The range can only be 'between' or 'only' the bounding numbers.\n"; + m->mothurOut("The range can only be 'between' or 'only' the bounding numbers.\n"); return false; } @@ -112,7 +123,7 @@ bool ValidParameters::isValidParameter(string parameter, vector cParams, else if(range.at(0).compare(">=") == 0 || range[3].compare("=>") == 0) d = 1; else { - cout << "The parameter value can only be '>', '>=', or '=>' the lower bounding number.\n"; + m->mothurOut("The parameter value can only be '>', '>=', or '=>' the lower bounding number.\n"); return false; } @@ -121,7 +132,7 @@ bool ValidParameters::isValidParameter(string parameter, vector cParams, else if(range.at(2).compare("<=") == 0 || range[4].compare("=<") == 0) e = 1; else { - cout << "The parameter value can only be '<', '<=', or '=<' the upper bounding number.\n"; + m->mothurOut("The parameter value can only be '<', '<=', or '=<' the upper bounding number.\n"); return false; } @@ -165,25 +176,25 @@ bool ValidParameters::isValidParameter(string parameter, vector cParams, if(!valid) { - cout << "The '" << parameter << "' parameter needs to be "; + m->mothurOut("The '" + parameter + "' parameter needs to be "); if(c == 1) - cout << "either '" << a << "' or '" << b << "'.\n"; + m->mothurOut("either '" + toString(a) + "' or '" + toString(b) + "'.\n"); else { if(a != piSentinel) { - cout << ">"; + m->mothurOut(">"); if(d != 0) - cout << "="; - cout << " '" << a << "'"; + m->mothurOut("="); + m->mothurOut(" '" + toString(a) + "'"); } if(b == piSentinel) - cout << "'.\n"; + m->mothurOut( "'.\n"); else if(a != piSentinel) - cout << " and "; + m->mothurOut(" and "); if(b != piSentinel) { - cout << "<"; + m->mothurOut("<"); if(e != 0) - cout << "="; - cout << " '" << b << "'.\n"; + m->mothurOut("="); + m->mothurOut(" '" + toString(b) + "'.\n"); } } return false; @@ -192,11 +203,7 @@ bool ValidParameters::isValidParameter(string parameter, vector cParams, return true; } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the ValidParameters class Function isValidParameter. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the ValidParameters class function isValidParameter. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "ValidParameters", "isValidParameters"); exit(1); } } @@ -204,18 +211,110 @@ bool ValidParameters::isValidParameter(string parameter, vector cParams, /******************************************************/ -string ValidParameters::validFile(map container, string parameter, bool isFile) { +string ValidParameters::validFile(map& container, string parameter, bool isFile) { try { int ableToOpen; - ifstream in; + map::iterator it; it = container.find(parameter); if(it != container.end()){ //no parameter given + if(isFile == true) { - ableToOpen = openInputFile(it->second, in); - if (ableToOpen == 1) { return "not open"; } + + int pos = (it->second).find(".tx."); + if (pos != string::npos) { m->sharedHeaderMode = "tax"; } + else { m->sharedHeaderMode = "otu"; } + + #ifdef USE_MPI + int pid, processors; + MPI_Status status; + MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are + MPI_Comm_size(MPI_COMM_WORLD, &processors); + + if (commandName == "") { processors = 1; } + + if (pid == 0) { + #endif + ifstream in; + ableToOpen = m->openInputFile(it->second, in, "noerror"); in.close(); + + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getDefaultPath() != "") { //default path is set + string tryPath = m->getDefaultPath() + m->getSimpleName(it->second); + m->mothurOut("Unable to open " + it->second + ". Trying default " + tryPath); m->mothurOutEndLine(); + ifstream in2; + ableToOpen = m->openInputFile(tryPath, in2, "noerror"); + in2.close(); + container[parameter] = tryPath; + } + } + + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getOutputDir() != "") { //default path is set + string tryPath = m->getOutputDir() + m->getSimpleName(it->second); + m->mothurOut("Unable to open " + it->second + ". Trying output directory " + tryPath); m->mothurOutEndLine(); + ifstream in2; + ableToOpen = m->openInputFile(tryPath, in2, "noerror"); + container[parameter] = tryPath; + in2.close(); + } + } + + + + #ifdef USE_MPI + for(int i = 1; i < processors; i++) { + MPI_Send(&ableToOpen, 1, MPI_INT, i, 2001, MPI_COMM_WORLD); + + int length = container[parameter].length(); + MPI_Send(&length, 1, MPI_INT, i, 2001, MPI_COMM_WORLD); + MPI_Send(&(container[parameter][0]), length, MPI_CHAR, i, 2001, MPI_COMM_WORLD); + + } + }else { + MPI_Recv(&ableToOpen, 1, MPI_INT, 0, 2001, MPI_COMM_WORLD, &status); + + int length; + MPI_Recv(&length, 1, MPI_INT, 0, 2001, MPI_COMM_WORLD, &status); + //recieve container + char* tempBuf = new char[length]; + MPI_Recv(&tempBuf[0], length, MPI_CHAR, 0, 2001, MPI_COMM_WORLD, &status); + + container[parameter] = tempBuf; + if (container[parameter].length() > length) { container[parameter] = container[parameter].substr(0, length); } + delete tempBuf; + } + + #endif + + if (ableToOpen == 1) { + m->mothurOut("Unable to open " + container[parameter]); m->mothurOutEndLine(); + return "not open"; + } + + //check phylip file to make sure its really phylip and not column + if ((it->first == "phylip") && (ableToOpen != 1)) { + ifstream inPhylip; + m->openInputFile(it->second, inPhylip); + + string numTest, name; + inPhylip >> numTest >> name; + inPhylip.close(); + + if (!m->isContainingOnlyDigits(numTest)) { m->mothurOut("[ERROR]: expected a number and got " + numTest + ". I suspect you entered a column formatted file as a phylip file, aborting."); m->mothurOutEndLine(); return "not found"; } + } + + //check for blank file + if (ableToOpen != 1) { + if (m->isBlank(container[parameter])) { + m->mothurOut("[ERROR]: " + container[parameter] + " is blank, aborting."); m->mothurOutEndLine(); return "not found"; + } + } + } }else { return "not found"; } @@ -223,11 +322,7 @@ string ValidParameters::validFile(map container, string paramete } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the ValidParameters class Function validFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the ValidParameters class function validFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "ValidParameters", "validFile"); exit(1); } } @@ -253,15 +348,9 @@ void ValidParameters::initParameterRanges() { string precisionArray[] = {">=","10", "<","NA", "between"}; parameterRanges["precision"] = addParameters(precisionArray, rangeSize); - string itersArray[] = {">=","10", "<","NA", "between"}; + string itersArray[] = {">=","1", "<","NA", "between"}; parameterRanges["iters"] = addParameters(itersArray, rangeSize); - string freqArray[] = {">=","1", "<","NA", "between"}; - parameterRanges["freq"] = addParameters(freqArray, rangeSize); - - //string lineArray[] = {">=","1", "<","NA", "between"}; - //parameterRanges["line"] = addParameters(lineArray, rangeSize); - string abundArray[] = {">=","5", "<","NA", "between"}; parameterRanges["abund"] = addParameters(abundArray, rangeSize); @@ -272,11 +361,7 @@ void ValidParameters::initParameterRanges() { parameterRanges["size"] = addParameters(sizeArray, rangeSize); } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the ValidParameters class Function isValidParameter. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the ValidParameters class function isValidParameter. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "ValidParameters", "initParameterRanges"); exit(1); } } @@ -290,11 +375,7 @@ vector ValidParameters::addParameters(string parameters[], int size) { return pVector; } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the ValidParameters class Function isValidParameter. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the ValidParameters class function isValidParameter. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "ValidParameters", "addParameters"); exit(1); } }