]> git.donarmstrong.com Git - mothur.git/blobdiff - classifyseqscommand.cpp
modified calculators to use doubles, added numotu and fontsize parameters to heatmap...
[mothur.git] / classifyseqscommand.cpp
index 2a210b01ad3a8fb0812c1877595028a851bdbee7..128fd01fd9f8b042ba736b97fbf89cdf86626fc8 100644 (file)
@@ -32,7 +32,7 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option)  {
                        OptionParser parser(option);
                        map<string, string> parameters = parser.getParameters(); 
                        
-                       ValidParameters validParameter;
+                       ValidParameters validParameter("classify.seqs");
                        map<string, string>::iterator it;
                        
                        //check to make sure all parameters are valid for command
@@ -98,31 +98,22 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option)  {
                                        
                                        int ableToOpen;
                                        
-                                       #ifdef USE_MPI  
-                                               int pid;
-                                               MPI_Comm_size(MPI_COMM_WORLD, &processors); //set processors to the number of mpi processes running
-                                               MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
-                               
-                                               if (pid == 0) {
-                                       #endif
-                                       
                                        ifstream in;
-                                       ableToOpen = openInputFile(fastaFileNames[i], in);
-                                       in.close();
-                                       
-                                       #ifdef USE_MPI  
-                                                       for (int j = 1; j < processors; j++) {
-                                                               MPI_Send(&ableToOpen, 1, MPI_INT, j, 2001, MPI_COMM_WORLD); 
-                                                       }
-                                               }else{
-                                                       MPI_Status status;
-                                                       MPI_Recv(&ableToOpen, 1, MPI_INT, 0, 2001, MPI_COMM_WORLD, &status);
+                                       ableToOpen = openInputFile(fastaFileNames[i], in, "noerror");
+                               
+                                       //if you can't open it, try default location
+                                       if (ableToOpen == 1) {
+                                               if (m->getDefaultPath() != "") { //default path is set
+                                                       string tryPath = m->getDefaultPath() + getSimpleName(fastaFileNames[i]);
+                                                       m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine();
+                                                       ableToOpen = openInputFile(tryPath, in, "noerror");
+                                                       fastaFileNames[i] = tryPath;
                                                }
-                                               
-                                       #endif
+                                       }
+                                       in.close();
                                        
                                        if (ableToOpen == 1) { 
-                                               m->mothurOut(fastaFileNames[i] + " will be disregarded."); m->mothurOutEndLine(); 
+                                               m->mothurOut("Unable to open " + fastaFileNames[i] + ". It will be disregarded."); m->mothurOutEndLine(); 
                                                //erase from file list
                                                fastaFileNames.erase(fastaFileNames.begin()+i);
                                                i--;
@@ -159,30 +150,27 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option)  {
                                        }
                                        int ableToOpen;
                                        
-                                       #ifdef USE_MPI  
-                                               int pid;
-                                               MPI_Comm_size(MPI_COMM_WORLD, &processors); //set processors to the number of mpi processes running
-                                               MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
-                               
-                                               if (pid == 0) {
-                                       #endif
-
                                        ifstream in;
-                                       ableToOpen = openInputFile(namefileNames[i], in);
-                                       in.close();
-                                       
-                                       #ifdef USE_MPI  
-                                                       for (int j = 1; j < processors; j++) {
-                                                               MPI_Send(&ableToOpen, 1, MPI_INT, j, 2001, MPI_COMM_WORLD); 
-                                                       }
-                                               }else{
-                                                       MPI_Status status;
-                                                       MPI_Recv(&ableToOpen, 1, MPI_INT, 0, 2001, MPI_COMM_WORLD, &status);
+                                       ableToOpen = openInputFile(namefileNames[i], in, "noerror");
+                               
+                                       //if you can't open it, try default location
+                                       if (ableToOpen == 1) {
+                                               if (m->getDefaultPath() != "") { //default path is set
+                                                       string tryPath = m->getDefaultPath() + getSimpleName(namefileNames[i]);
+                                                       m->mothurOut("Unable to open " + namefileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine();
+                                                       ableToOpen = openInputFile(tryPath, in, "noerror");
+                                                       namefileNames[i] = tryPath;
                                                }
-                                               
-                                       #endif
-                                       if (ableToOpen == 1) {  m->mothurOut("Unable to match name file with fasta file."); m->mothurOutEndLine(); abort = true;        }
+                                       }
+                                       in.close();
                                        
+                                       if (ableToOpen == 1) { 
+                                               m->mothurOut("Unable to open " + namefileNames[i] + ". It will be disregarded."); m->mothurOutEndLine();  abort = true;
+                                               //erase from file list
+                                               namefileNames.erase(namefileNames.begin()+i);
+                                               i--;
+                                       }
+
                                }
                        }
 
@@ -204,30 +192,26 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option)  {
                                        }
                                        int ableToOpen;
                                        
-                                       #ifdef USE_MPI  
-                                               int pid;
-                                               MPI_Comm_size(MPI_COMM_WORLD, &processors); //set processors to the number of mpi processes running
-                                               MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
-                               
-                                               if (pid == 0) {
-                                       #endif
-
                                        ifstream in;
-                                       ableToOpen = openInputFile(groupfileNames[i], in);
-                                       in.close();
-                                       
-                                       #ifdef USE_MPI  
-                                                       for (int j = 1; j < processors; j++) {
-                                                               MPI_Send(&ableToOpen, 1, MPI_INT, j, 2001, MPI_COMM_WORLD); 
-                                                       }
-                                               }else{
-                                                       MPI_Status status;
-                                                       MPI_Recv(&ableToOpen, 1, MPI_INT, 0, 2001, MPI_COMM_WORLD, &status);
+                                       ableToOpen = openInputFile(groupfileNames[i], in, "noerror");
+                               
+                                       //if you can't open it, try default location
+                                       if (ableToOpen == 1) {
+                                               if (m->getDefaultPath() != "") { //default path is set
+                                                       string tryPath = m->getDefaultPath() + getSimpleName(groupfileNames[i]);
+                                                       m->mothurOut("Unable to open " + groupfileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine();
+                                                       ableToOpen = openInputFile(tryPath, in, "noerror");
+                                                       groupfileNames[i] = tryPath;
                                                }
-                                               
-                                       #endif
-                                       if (ableToOpen == 1) {  m->mothurOut("Unable to match group file with fasta file, not using " + groupfileNames[i] + "."); m->mothurOutEndLine(); groupfileNames[i] = "";        }
+                                       }
+                                       in.close();
                                        
+                                       if (ableToOpen == 1) { 
+                                               m->mothurOut("Unable to open " + groupfileNames[i] + ". It will be disregarded."); m->mothurOutEndLine(); groupfileNames[i] = "";
+                                               //erase from file list
+                                               groupfileNames.erase(groupfileNames.begin()+i);
+                                               i--;
+                                       }
                                }
                        }
 
@@ -358,10 +342,20 @@ int ClassifySeqsCommand::execute(){
                
                        m->mothurOut("Classifying sequences from " + fastaFileNames[s] + " ..." ); m->mothurOutEndLine();
                        
+                       string RippedTaxName = getRootName(getSimpleName(taxonomyFileName));
+                       RippedTaxName = getExtension(RippedTaxName.substr(0, RippedTaxName.length()-1));
+                       if (RippedTaxName[0] == '.') { RippedTaxName = RippedTaxName.substr(1, RippedTaxName.length()); }
+                       RippedTaxName +=  "."; 
+               
                        if (outputDir == "") { outputDir += hasPath(fastaFileNames[s]); }
-                       string newTaxonomyFile = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + getRootName(getSimpleName(taxonomyFileName)) + "taxonomy";
+                       string newTaxonomyFile = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + RippedTaxName + "taxonomy";
                        string tempTaxonomyFile = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + "taxonomy.temp";
-                       string taxSummary = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + getRootName(getSimpleName(taxonomyFileName)) + "tax.summary";
+                       string taxSummary = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + RippedTaxName + "tax.summary";
+                       
+                       if ((method == "knn") && (search == "distance")) { 
+                               string DistName = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + "match.dist";
+                               classify->setDistName(DistName);  outputNames.push_back(DistName);
+                       }
                        
                        outputNames.push_back(newTaxonomyFile);
                        outputNames.push_back(taxSummary);
@@ -373,7 +367,7 @@ int ClassifySeqsCommand::execute(){
 #ifdef USE_MPI 
                                int pid, end, numSeqsPerProcessor; 
                                int tag = 2001;
-                               vector<long> MPIPos;
+                               vector<unsigned long int> MPIPos;
                                
                                MPI_Status status; 
                                MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
@@ -800,7 +794,7 @@ int ClassifySeqsCommand::driver(linePair* line, string taxFName, string tempTFNa
 }
 //**********************************************************************************************************************
 #ifdef USE_MPI
-int ClassifySeqsCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_File& newFile, MPI_File& tempFile, vector<long>& MPIPos){
+int ClassifySeqsCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_File& newFile, MPI_File& tempFile, vector<unsigned long int>& MPIPos){
        try {
                MPI_Status statusNew; 
                MPI_Status statusTemp;