]> git.donarmstrong.com Git - mothur.git/blobdiff - metastatscommand.cpp
sffinfo bug with flow grams right index when clipQualRight=0
[mothur.git] / metastatscommand.cpp
index 59916492213cf56c8851969876b1df7907f26f23..9dff3543f49efa25037ce7fb3dd9eeeebbe8c787 100644 (file)
@@ -8,23 +8,22 @@
  */
 
 #include "metastatscommand.h"
-#include "metastats.h"
 #include "sharedutilities.h"
 
 
 //**********************************************************************************************************************
 vector<string> MetaStatsCommand::setParameters(){      
        try {
-               CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pshared);
-               CommandParameter pdesign("design", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pdesign);
-               CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors);
-               CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters);
-               CommandParameter pthreshold("threshold", "Number", "", "0.05", "", "", "",false,false); parameters.push_back(pthreshold);
-               CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel);
-               CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups);
-               CommandParameter psets("sets", "String", "", "", "", "", "",false,false); parameters.push_back(psets);
-               CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
-               CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
+               CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none","metastats",false,true,true); parameters.push_back(pshared);
+               CommandParameter pdesign("design", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(pdesign);
+               CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors);
+               CommandParameter piters("iters", "Number", "", "1000", "", "", "","",false,false); parameters.push_back(piters);
+               CommandParameter pthreshold("threshold", "Number", "", "0.05", "", "", "","",false,false); parameters.push_back(pthreshold);
+               CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel);
+               CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups);
+               CommandParameter psets("sets", "String", "", "", "", "", "","",false,false); parameters.push_back(psets);
+               CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
+               CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
                
                vector<string> myArray;
                for (int i = 0; i < parameters.size(); i++) {   myArray.push_back(parameters[i].name);          }
@@ -62,6 +61,21 @@ string MetaStatsCommand::getHelpString(){
        }
 }
 //**********************************************************************************************************************
+string MetaStatsCommand::getOutputPattern(string type) {
+    try {
+        string pattern = "";
+        
+        if (type == "metastats") {  pattern = "[filename],[distance],[group],metastats"; } 
+        else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true;  }
+        
+        return pattern;
+    }
+    catch(exception& e) {
+        m->errorOut(e, "MetaStatsCommand", "getOutputPattern");
+        exit(1);
+    }
+}
+//**********************************************************************************************************************
 MetaStatsCommand::MetaStatsCommand(){  
        try {
                abort = true; calledHelp = true;
@@ -343,7 +357,7 @@ int MetaStatsCommand::process(vector<SharedRAbundVector*>& thisLookUp){
                                }else{
                                        int process = 1;
                                        vector<int> processIDS;
-               #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) {
                                                int pid = fork();
@@ -417,6 +431,9 @@ int MetaStatsCommand::process(vector<SharedRAbundVector*>& thisLookUp){
                     
                     //Close all thread handles and free memory allocations.
                     for(int i=0; i < pDataArray.size(); i++){
+                        if (pDataArray[i]->count != (pDataArray[i]->num)) {
+                            m->mothurOut("[ERROR]: process " + toString(i) + " only processed " + toString(pDataArray[i]->count) + " of " + toString(pDataArray[i]->num) + " groups assigned to it, quitting. \n"); m->control_pressed = true; 
+                        }
                         for (int j = 0; j < pDataArray[i]->thisLookUp.size(); j++) {  delete pDataArray[i]->thisLookUp[j];  } 
                         for (int j = 0; j < pDataArray[i]->outputNames.size(); j++) {  
                             outputNames.push_back(pDataArray[i]->outputNames[j]);
@@ -450,7 +467,11 @@ int MetaStatsCommand::driver(int start, int num, vector<SharedRAbundVector*>& th
                        string setB = namesOfGroupCombos[c][1];
                
                        //get filename
-                       string outputFileName = outputDir +  m->getRootName(m->getSimpleName(sharedfile)) + thisLookUp[0]->getLabel() + "." + setA + "-" + setB + ".metastats";
+            map<string, string> variables; 
+            variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(sharedfile));
+            variables["[distance]"] = thisLookUp[0]->getLabel();
+            variables["[group]"] = setA + "-" + setB;
+                       string outputFileName = getOutputFileName("metastats",variables);
                        outputNames.push_back(outputFileName); outputTypes["metastats"].push_back(outputFileName);
                        //int nameLength = outputFileName.length();
                        //char * output = new char[nameLength];
@@ -483,12 +504,13 @@ int MetaStatsCommand::driver(int start, int num, vector<SharedRAbundVector*>& th
                                m->mothurOut("Missing shared info for " + setA + " or " + setB + ". Skipping comparison."); m->mothurOutEndLine(); 
                                outputNames.pop_back();
                        }else {
+                
                                //fill data
                                for (int j = 0; j < thisLookUp[0]->getNumBins(); j++) {
                                        //data[j] = new double[subset.size()];
                                        data2[j].resize(subset.size(), 0.0);
+                   
                                        for (int i = 0; i < subset.size(); i++) {
-                                               //data[j][i] = (subset[i]->getAbundance(j));
                                                data2[j][i] = (subset[i]->getAbundance(j));
                                        }
                                }
@@ -500,7 +522,6 @@ int MetaStatsCommand::driver(int start, int num, vector<SharedRAbundVector*>& th
                                MothurMetastats mothurMeta(threshold, iters);
                                mothurMeta.runMetastats(outputFileName , data2, setACount);
                                m->mothurOutEndLine();
-                               
                                m->mothurOutEndLine(); 
                        }