X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=unifracunweightedcommand.cpp;h=272ae8255b6566e0f2c0ff04489580a9a36acdfd;hp=5f3cffc2b1ab807b279ba3185444dc96a0a3b863;hb=615301e57c25e241356a9c2380648d117709458d;hpb=deba0af0ccdcb6005ed5b2b82649b137c63fbdf7 diff --git a/unifracunweightedcommand.cpp b/unifracunweightedcommand.cpp index 5f3cffc..272ae82 100644 --- a/unifracunweightedcommand.cpp +++ b/unifracunweightedcommand.cpp @@ -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 >& dists, int treeNum) { try { //we need to find the average distance and standard deviation for each groups distance - //finds sum - vector 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 averages = m->getAverages(dists); //find standard deviation - vector 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 stdDev = m->getStandardDeviation(dists, averages); //make matrix with scores in it - vector< vector > avedists; avedists.resize(m->getNumGroups()); + vector< vector > avedists; //avedists.resize(m->getNumGroups()); for (int i = 0; i < m->getNumGroups(); i++) { - avedists[i].resize(m->getNumGroups(), 0.0); + vector 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 > stddists; stddists.resize(m->getNumGroups()); + vector< vector > stddists; //stddists.resize(m->getNumGroups()); for (int i = 0; i < m->getNumGroups(); i++) { - stddists[i].resize(m->getNumGroups(), 0.0); + vector 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; rgetNumGroups(); r++) { @@ -530,6 +518,8 @@ int UnifracUnweightedCommand::getAverageSTDMatrices(vector< vector >& di } } + if (m->debug) { m->mothurOut("[DEBUG]: done filling matrix.\n"); } + map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(treefile)); variables["[tag]"] = toString(treeNum+1);