X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=validparameter.cpp;h=7d1af2551c7a6717c1d3ea807af0e56de0fc218e;hp=cfe9d509112e921aef92c0cf914e10f6ca885079;hb=615301e57c25e241356a9c2380648d117709458d;hpb=8bc3e5b38c2317a1715f53be22fa96455868c281 diff --git a/validparameter.cpp b/validparameter.cpp index cfe9d50..7d1af25 100644 --- a/validparameter.cpp +++ b/validparameter.cpp @@ -214,13 +214,17 @@ bool ValidParameters::isValidParameter(string parameter, vector cParams, 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) { + + int pos = (it->second).find(".tx."); + if (pos != string::npos) { m->sharedHeaderMode = "tax"; } + else { m->sharedHeaderMode = "otu"; } #ifdef USE_MPI int pid, processors; @@ -232,15 +236,18 @@ string ValidParameters::validFile(map& container, string paramet 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(); - ableToOpen = m->openInputFile(tryPath, in, "noerror"); + ifstream in2; + ableToOpen = m->openInputFile(tryPath, in2, "noerror"); + in2.close(); container[parameter] = tryPath; } } @@ -250,12 +257,14 @@ string ValidParameters::validFile(map& container, string paramet 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(); - ableToOpen = m->openInputFile(tryPath, in, "noerror"); + ifstream in2; + ableToOpen = m->openInputFile(tryPath, in2, "noerror"); container[parameter] = tryPath; + in2.close(); } } - in.close(); + #ifdef USE_MPI for(int i = 1; i < processors; i++) { @@ -286,6 +295,26 @@ string ValidParameters::validFile(map& container, string paramet 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"; }