]> git.donarmstrong.com Git - mothur.git/blobdiff - shhhseqscommand.cpp
changed random forest output filename
[mothur.git] / shhhseqscommand.cpp
index 6a339b880eb54eedaa7be7af3c297ed0089beb10..82d956189a6f025fd57dc7e901e585456f59f8ab 100644 (file)
 //**********************************************************************************************************************
 vector<string> ShhhSeqsCommand::setParameters(){       
        try {
-               CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta);
-               CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pname);
-               CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pgroup);
-               CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors);
-               CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
-               CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
-               CommandParameter psigma("sigma", "Number", "", "0.01", "", "", "",false,false); parameters.push_back(psigma);
+               CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","fasta-map",false,true,true); parameters.push_back(pfasta);
+               CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none","name",false,true,true); parameters.push_back(pname);
+               CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pgroup);
+               CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors);
+               CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
+               CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
+               CommandParameter psigma("sigma", "Number", "", "0.01", "", "", "","",false,false); parameters.push_back(psigma);
                
                vector<string> myArray;
                for (int i = 0; i < parameters.size(); i++) {   myArray.push_back(parameters[i].name);          }
@@ -54,6 +54,24 @@ string ShhhSeqsCommand::getHelpString(){
                exit(1);
        }
 }
+//**********************************************************************************************************************
+string ShhhSeqsCommand::getOutputPattern(string type) {
+    try {
+        string pattern = "";
+        
+        if (type == "fasta")            {   pattern = "[filename],shhh_seqs.fasta";   }
+        else if (type == "name")    {   pattern = "[filename],shhh_seqs.names";   }
+        else if (type == "map")        {   pattern = "[filename],shhh_seqs.map";   }
+        else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true;  }
+        
+        return pattern;
+    }
+    catch(exception& e) {
+        m->errorOut(e, "ShhhSeqsCommand", "getOutputPattern");
+        exit(1);
+    }
+}
+
 //**********************************************************************************************************************
 
 ShhhSeqsCommand::ShhhSeqsCommand(){    
@@ -161,10 +179,16 @@ ShhhSeqsCommand::ShhhSeqsCommand(string option) {
                        
                        string temp     = validParameter.validFile(parameters, "sigma", false);         if(temp == "not found"){        temp = "0.01"; }
                        m->mothurConvert(temp, sigma); 
-                       
+                       sigma = 1/sigma;
+            
                        temp = validParameter.validFile(parameters, "processors", false);       if (temp == "not found"){       temp = m->getProcessors();      }
                        m->setProcessors(temp);
                        m->mothurConvert(temp, processors);
+                       
+                       if (namefile == "") {
+                               vector<string> files; files.push_back(fastafile);
+                               parser.getNameFile(files);
+                       }
                }
        }
        catch(exception& e) {
@@ -178,10 +202,13 @@ int ShhhSeqsCommand::execute() {
                
                if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
                
-               if (outputDir == "") { outputDir = m->hasPath(fastafile);  }//if user entered a file with a path then preserve it                               
-               string outputFileName = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "shhh.fasta";
-               string nameFileName = outputDir + m->getRootName(m->getSimpleName(fastafile))  + "shhh.names";
-               string mapFileName = outputDir + m->getRootName(m->getSimpleName(fastafile))  + "shhh.map";
+               if (outputDir == "") { outputDir = m->hasPath(fastafile);  }//if user entered a file with a path then preserve it               
+               
+        map<string, string> variables; 
+               variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastafile));
+               string outputFileName = getOutputFileName("fasta",variables);
+               string nameFileName = getOutputFileName("name",variables);
+               string mapFileName = getOutputFileName("map",variables);
                
                if (groupfile != "") {
                        //Parse sequences by group
@@ -358,7 +385,7 @@ vector<string> ShhhSeqsCommand::createProcessesGroups(SequenceParser& parser, st
                        lines.push_back(linePair(startIndex, endIndex));
                }
                
-#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)          
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)         
                
                //loop through and create all the processes you want
                while (process != processors) {
@@ -447,6 +474,9 @@ vector<string> ShhhSeqsCommand::createProcessesGroups(SequenceParser& parser, st
                
                //Close all thread handles and free memory allocations.
                for(int i=0; i < pDataArray.size(); i++){
+            if (pDataArray[i]->count != (pDataArray[i]->end-pDataArray[i]->start)) {
+                m->mothurOut("[ERROR]: process " + toString(i) + " only processed " + toString(pDataArray[i]->count) + " of " + toString(pDataArray[i]->end-pDataArray[i]->start) + " groups assigned to it, quitting. \n"); m->control_pressed = true; 
+            }
                        for (int j = 0; j < pDataArray[i]->mapfileNames.size(); j++) {
                                mapfileNames.push_back(pDataArray[i]->mapfileNames[j]);
                        }
@@ -689,14 +719,15 @@ int ShhhSeqsCommand::deconvoluteResults(string fastaFile, string nameFile){
                string inputString = "fasta=" + fastaFile + ", name=" + nameFile;
                m->mothurOut("/******************************************/"); m->mothurOutEndLine(); 
                m->mothurOut("Running command: unique.seqs(" + inputString + ")"); m->mothurOutEndLine(); 
-               
+               m->mothurCalling = true;
+        
                Command* uniqueCommand = new DeconvoluteCommand(inputString);
                uniqueCommand->execute();
                
                map<string, vector<string> > filenames = uniqueCommand->getOutputFiles();
                
                delete uniqueCommand;
-               
+               m->mothurCalling = false;
                m->mothurOut("/******************************************/"); m->mothurOutEndLine(); 
                
                string newnameFile = filenames["name"][0];