]> git.donarmstrong.com Git - mothur.git/blobdiff - validparameter.cpp
fixing bugs while testing
[mothur.git] / validparameter.cpp
index 38a90940095b799634494a20ddf3d1688f2a0f3a..7855ddedd11f05b8e8c628e2d5c49c82be646a9b 100644 (file)
@@ -214,7 +214,7 @@ bool ValidParameters::isValidParameter(string parameter, vector<string> cParams,
 string ValidParameters::validFile(map<string, string>& container, string parameter, bool isFile) {
        try {
                int ableToOpen;
-               ifstream in;
+               
                map<string, string>::iterator it;
                
                it = container.find(parameter);
@@ -232,20 +232,35 @@ string ValidParameters::validFile(map<string, string>& 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;
                                        }
                                }
                                
-                               in.close();
+                               //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++) { 
@@ -276,6 +291,18 @@ string ValidParameters::validFile(map<string, string>& 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"; }
+                               }
                        }
                }else { return "not found"; }
                
@@ -309,7 +336,7 @@ 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 abundArray[] = {">=","5", "<","NA", "between"};