]> git.donarmstrong.com Git - mothur.git/blobdiff - validparameter.cpp
changing command name classify.shared to classifyrf.shared
[mothur.git] / validparameter.cpp
index 4ea677f4df472014321ee8d00fc7bf45d5e322f3..7d1af2551c7a6717c1d3ea807af0e56de0fc218e 100644 (file)
@@ -15,6 +15,20 @@ ValidParameters::ValidParameters() {
        try {
                m = MothurOut::getInstance();
                initParameterRanges();
+               commandName = "";
+       }
+       catch(exception& e) {
+               m->errorOut(e, "ValidParameters", "ValidParameters");
+               exit(1);
+       }
+}
+/***********************************************************************/
+
+ValidParameters::ValidParameters(string c) {
+       try {
+               m = MothurOut::getInstance();
+               initParameterRanges();
+               commandName = c;
        }
        catch(exception& e) {
                m->errorOut(e, "ValidParameters", "ValidParameters");
@@ -55,7 +69,7 @@ bool ValidParameters::isValidParameter(string parameter, vector<string> cParams,
                vector<string> range = parameterRanges[parameter];
                
                vector<string> values;
-               splitAtDash(value, values);
+               m->splitAtDash(value, values);
                
                for(int i = 0; i < values.size(); i++) {
                        value = values.at(i);
@@ -197,35 +211,110 @@ bool ValidParameters::isValidParameter(string parameter, vector<string> cParams,
 
 /******************************************************/
 
-string ValidParameters::validFile(map<string, string> container, string parameter, bool isFile) {
+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);
                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;
+                               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
-
-                               ableToOpen = openInputFile(it->second, in);
+                               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  
-                                       MPI_Bcast(&ableToOpen, 1, MPI_INT, 0, MPI_COMM_WORLD);  //send ableToOPen
+                                       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_Bcast(&ableToOpen, 1, MPI_INT, 0, MPI_COMM_WORLD); //get ableToOPen
+                                       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) { return "not open"; }
+                               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"; }
                
@@ -259,7 +348,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"};