]> git.donarmstrong.com Git - mothur.git/blobdiff - matrixoutputcommand.cpp
Merge remote-tracking branch 'origin/master'
[mothur.git] / matrixoutputcommand.cpp
index e1c8a984d7539dcc36379bc18df72e7f6002aeac..ccd4f538ab03f7ea86c59b2d3381d2de1a2de52f 100644 (file)
@@ -61,6 +61,26 @@ string MatrixOutputCommand::getHelpString(){
        }
 }
 //**********************************************************************************************************************
+string MatrixOutputCommand::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 == "phylip")             {   outputFileName =  "dist";         }
+            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, "MatrixOutputCommand", "getOutputFileNameTag");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
 MatrixOutputCommand::MatrixOutputCommand(){    
        try {
                abort = true; calledHelp = true; 
@@ -179,7 +199,7 @@ MatrixOutputCommand::MatrixOutputCommand(string option)  {
                 else { subsample = false; }
             }
             
-            if (subsample == false) { iters = 1; }
+            if (subsample == false) { iters = 0; }
             
                        if (abort == false) {
                        
@@ -447,7 +467,7 @@ void MatrixOutputCommand::printSims(ostream& out, vector< vector<double> >& simM
                                out << endl;
                        }
                }else{
-                       for (int b = 0; b < simMatrix.size(); m++)      {
+                       for (int b = 0; b < simMatrix.size(); b++)      {
                                out << lookup[b]->getGroup() << '\t';
                                for (int n = 0; n < simMatrix[b].size(); n++)   {
                                        out << simMatrix[b][n] << '\t'; 
@@ -653,8 +673,9 @@ int MatrixOutputCommand::process(vector<SharedRAbundVector*> thisLookup){
                         matrix[column][row] = dist;
                     }
                     
-                    string distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + matrixCalculators[i]->getName() + "." + thisLookup[0]->getLabel()  + "." + output + ".dist";
+                    string distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + matrixCalculators[i]->getName() + "." + thisLookup[0]->getLabel()  + "." + output + "." + getOutputFileNameTag("phylip");
                     outputNames.push_back(distFileName); outputTypes["phylip"].push_back(distFileName);
+                    
                     ofstream outDist;
                     m->openOutputFile(distFileName, outDist);
                     outDist.setf(ios::fixed, ios::floatfield); outDist.setf(ios::showpoint);
@@ -667,7 +688,7 @@ int MatrixOutputCommand::process(vector<SharedRAbundVector*> thisLookup){
             for (int i = 0; i < calcDists.size(); i++) {  calcDists[i].clear(); }
                }
                
-        if (iters != 1) {
+        if (iters != 0) {
             //we need to find the average distance and standard deviation for each groups distance
             
             vector< vector<seqDist>  > calcAverages; calcAverages.resize(matrixCalculators.size()); 
@@ -757,7 +778,7 @@ int MatrixOutputCommand::process(vector<SharedRAbundVector*> thisLookup){
                     stdmatrix[column][row] = stdDist;
                 }
             
-                string distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + matrixCalculators[i]->getName() + "." + thisLookup[0]->getLabel()  + "." + output + ".ave.dist";
+                string distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + matrixCalculators[i]->getName() + "." + thisLookup[0]->getLabel()  + "." + output + ".ave." + getOutputFileNameTag("phylip");
                 outputNames.push_back(distFileName); outputTypes["phylip"].push_back(distFileName);
                 ofstream outAve;
                 m->openOutputFile(distFileName, outAve);
@@ -767,7 +788,7 @@ int MatrixOutputCommand::process(vector<SharedRAbundVector*> thisLookup){
                 
                 outAve.close();
                 
-                distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + matrixCalculators[i]->getName() + "." + thisLookup[0]->getLabel()  + "." + output + ".std.dist";
+                distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + matrixCalculators[i]->getName() + "." + thisLookup[0]->getLabel()  + "." + output + ".std." + getOutputFileNameTag("phylip");
                 outputNames.push_back(distFileName); outputTypes["phylip"].push_back(distFileName);
                 ofstream outSTD;
                 m->openOutputFile(distFileName, outSTD);