]> git.donarmstrong.com Git - mothur.git/blobdiff - metastatscommand.cpp
Merge remote-tracking branch 'origin/master'
[mothur.git] / metastatscommand.cpp
index 4744424d426d61243894d4779fa60dcd20781be3..b5b01e7f97166ed80143d349b9ae8c340d53e654 100644 (file)
@@ -60,6 +60,27 @@ string MetaStatsCommand::getHelpString(){
                exit(1);
        }
 }
+//**********************************************************************************************************************
+string MetaStatsCommand::getOutputFileNameTag(string type, string inputName=""){       
+       try {
+        string outputFileName = "";
+               map<string, vector<string> >::iterator it;
+        
+        //is this a type this command creates
+        it = outputTypes.find(type);
+        if (it == outputTypes.end()) {  m->mothurOut("[ERROR]: this command doesn't create a " + type + " output file.\n"); }
+        else {
+            if (type == "metastats")        {   outputFileName = "metastats";       }
+            else { m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true;  }
+        }
+        return outputFileName;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "MetaStatsCommand", "getOutputFileNameTag");
+               exit(1);
+       }
+}
+
 //**********************************************************************************************************************
 MetaStatsCommand::MetaStatsCommand(){  
        try {
@@ -449,7 +470,7 @@ 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";
+                       string outputFileName = outputDir +  m->getRootName(m->getSimpleName(sharedfile)) + thisLookUp[0]->getLabel() + "." + setA + "-" + setB + "." + getOutputFileNameTag("metastats");
                        outputNames.push_back(outputFileName); outputTypes["metastats"].push_back(outputFileName);
                        //int nameLength = outputFileName.length();
                        //char * output = new char[nameLength];
@@ -483,25 +504,16 @@ int MetaStatsCommand::driver(int start, int num, vector<SharedRAbundVector*>& th
                                outputNames.pop_back();
                        }else {
                 
-                ofstream outTemp;
-                string tempOut = outputDir + "data." + setA + "-" + setB + ".matrix";
-                m->openOutputFile(tempOut, outTemp);
-                for (int i = 0; i < subset.size(); i++) { outTemp << '\t' << subset[i]->getGroup(); }
-                outTemp << endl;
-                
-                
                                //fill data
                                for (int j = 0; j < thisLookUp[0]->getNumBins(); j++) {
                                        //data[j] = new double[subset.size()];
                                        data2[j].resize(subset.size(), 0.0);
-                    outTemp << "OTU" << (j+1);
+                   
                                        for (int i = 0; i < subset.size(); i++) {
                                                data2[j][i] = (subset[i]->getAbundance(j));
-                        outTemp << '\t' << subset[i]->getAbundance(j);
                                        }
-                    outTemp << endl;
                                }
-                               outTemp.close();
+                               
                                m->mothurOut("Comparing " + setA + " and " + setB + "..."); m->mothurOutEndLine(); 
                                //metastat_main(output, thisLookUp[0]->getNumBins(), subset.size(), threshold, iters, data, setACount);