]> git.donarmstrong.com Git - mothur.git/blobdiff - unifracunweightedcommand.cpp
changing command name classify.shared to classifyrf.shared
[mothur.git] / unifracunweightedcommand.cpp
index 5f3cffc2b1ab807b279ba3185444dc96a0a3b863..272ae8255b6566e0f2c0ff04489580a9a36acdfd 100644 (file)
@@ -421,7 +421,7 @@ int UnifracUnweightedCommand::execute() {
                 delete newCt;
                 delete subSampleTree;
                 
-                if((thisIter+1) % 100 == 0){   m->mothurOut(toString(thisIter+1)); m->mothurOutEndLine();              }
+                if((thisIter+1) % 100 == 0){   m->mothurOutJustToScreen(toString(thisIter+1)+"\n");            }
             }
             if (subsample) { m->mothurOut("It took " + toString(time(NULL) - startSubsample) + " secs to run the subsampling."); m->mothurOutEndLine(); }
             
@@ -481,43 +481,31 @@ int UnifracUnweightedCommand::execute() {
 int UnifracUnweightedCommand::getAverageSTDMatrices(vector< vector<double> >& dists, int treeNum) {
        try {
         //we need to find the average distance and standard deviation for each groups distance
-        
         //finds sum
-        vector<double> averages; averages.resize(numComp, 0); 
-        for (int thisIter = 0; thisIter < subsampleIters; thisIter++) {
-            for (int i = 0; i < dists[thisIter].size(); i++) {  
-                averages[i] += dists[thisIter][i];
-            }
-        }
-        
-        //finds average.
-        for (int i = 0; i < averages.size(); i++) {  averages[i] /= (float) subsampleIters; }
+        vector<double> averages = m->getAverages(dists);
         
         //find standard deviation
-        vector<double> stdDev; stdDev.resize(numComp, 0);
-        
-        for (int thisIter = 0; thisIter < subsampleIters; thisIter++) { //compute the difference of each dist from the mean, and square the result of each
-            for (int j = 0; j < dists[thisIter].size(); j++) {
-                stdDev[j] += ((dists[thisIter][j] - averages[j]) * (dists[thisIter][j] - averages[j]));
-            }
-        }
-        for (int i = 0; i < stdDev.size(); i++) {  
-            stdDev[i] /= (float) subsampleIters; 
-            stdDev[i] = sqrt(stdDev[i]);
-        }
+        vector<double> stdDev = m->getStandardDeviation(dists, averages);
         
         //make matrix with scores in it
-        vector< vector<double> > avedists;     avedists.resize(m->getNumGroups());
+        vector< vector<double> > avedists;     //avedists.resize(m->getNumGroups());
         for (int i = 0; i < m->getNumGroups(); i++) {
-            avedists[i].resize(m->getNumGroups(), 0.0);
+            vector<double> temp;
+            for (int j = 0; j < m->getNumGroups(); j++) { temp.push_back(0.0); }
+            avedists.push_back(temp);
         }
         
         //make matrix with scores in it
-        vector< vector<double> > stddists;     stddists.resize(m->getNumGroups());
+        vector< vector<double> > stddists;     //stddists.resize(m->getNumGroups());
         for (int i = 0; i < m->getNumGroups(); i++) {
-            stddists[i].resize(m->getNumGroups(), 0.0);
+            vector<double> temp;
+            for (int j = 0; j < m->getNumGroups(); j++) { temp.push_back(0.0); }
+            //stddists[i].resize(m->getNumGroups(), 0.0);
+            stddists.push_back(temp);
         }
         
+        if (m->debug) { m->mothurOut("[DEBUG]: about to fill matrix.\n"); }
+        
         //flip it so you can print it
         int count = 0;
         for (int r=0; r<m->getNumGroups(); r++) { 
@@ -530,6 +518,8 @@ int UnifracUnweightedCommand::getAverageSTDMatrices(vector< vector<double> >& di
             }
         }
         
+        if (m->debug) { m->mothurOut("[DEBUG]: done filling matrix.\n"); }
+        
         map<string, string> variables; 
                variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(treefile));
         variables["[tag]"] = toString(treeNum+1);