+ return stdDev;
+ }
+ catch(exception& e) {
+ errorOut(e, "MothurOut", "getStandardDeviation");
+ exit(1);
+ }
+}
+/**************************************************************************************************/
+vector< vector<seqDist> > MothurOut::getAverages(vector< vector< vector<seqDist> > >& calcDistsTotals, string mode) {
+ try{
+
+ vector< vector<seqDist> > calcAverages; //calcAverages.resize(calcDistsTotals[0].size());
+ for (int i = 0; i < calcDistsTotals[0].size(); i++) { //initialize sums to zero.
+ //calcAverages[i].resize(calcDistsTotals[0][i].size());
+ vector<seqDist> temp;
+ for (int j = 0; j < calcDistsTotals[0][i].size(); j++) {
+ seqDist tempDist;
+ tempDist.seq1 = calcDistsTotals[0][i][j].seq1;
+ tempDist.seq2 = calcDistsTotals[0][i][j].seq2;
+ tempDist.dist = 0.0;
+ temp.push_back(tempDist);
+ }
+ calcAverages.push_back(temp);
+ }
+
+ if (mode == "average") {
+ for (int thisIter = 0; thisIter < calcDistsTotals.size(); thisIter++) { //sum all groups dists for each calculator
+ for (int i = 0; i < calcAverages.size(); i++) { //initialize sums to zero.
+ for (int j = 0; j < calcAverages[i].size(); j++) {
+ calcAverages[i][j].dist += calcDistsTotals[thisIter][i][j].dist;
+ }
+ }
+ }
+
+ for (int i = 0; i < calcAverages.size(); i++) { //finds average.
+ for (int j = 0; j < calcAverages[i].size(); j++) {
+ calcAverages[i][j].dist /= (float) calcDistsTotals.size();
+ }
+ }
+ }else { //find median
+ for (int i = 0; i < calcAverages.size(); i++) { //for each calc
+ for (int j = 0; j < calcAverages[i].size(); j++) { //for each comparison
+ vector<double> dists;
+ for (int thisIter = 0; thisIter < calcDistsTotals.size(); thisIter++) { //for each subsample
+ dists.push_back(calcDistsTotals[thisIter][i][j].dist);
+ }
+ sort(dists.begin(), dists.end());
+ calcAverages[i][j].dist = dists[(calcDistsTotals.size()/2)];
+ }
+ }
+ }
+
+ return calcAverages;
+ }
+ catch(exception& e) {
+ errorOut(e, "MothurOut", "getAverages");
+ exit(1);
+ }
+}
+/**************************************************************************************************/
+vector< vector<seqDist> > MothurOut::getAverages(vector< vector< vector<seqDist> > >& calcDistsTotals) {
+ try{
+
+ vector< vector<seqDist> > calcAverages; //calcAverages.resize(calcDistsTotals[0].size());
+ for (int i = 0; i < calcDistsTotals[0].size(); i++) { //initialize sums to zero.
+ //calcAverages[i].resize(calcDistsTotals[0][i].size());
+ vector<seqDist> temp;
+ for (int j = 0; j < calcDistsTotals[0][i].size(); j++) {
+ seqDist tempDist;
+ tempDist.seq1 = calcDistsTotals[0][i][j].seq1;
+ tempDist.seq2 = calcDistsTotals[0][i][j].seq2;
+ tempDist.dist = 0.0;
+ temp.push_back(tempDist);
+ }
+ calcAverages.push_back(temp);
+ }
+
+
+ for (int thisIter = 0; thisIter < calcDistsTotals.size(); thisIter++) { //sum all groups dists for each calculator
+ for (int i = 0; i < calcAverages.size(); i++) { //initialize sums to zero.
+ for (int j = 0; j < calcAverages[i].size(); j++) {
+ calcAverages[i][j].dist += calcDistsTotals[thisIter][i][j].dist;
+ }
+ }
+ }
+
+ for (int i = 0; i < calcAverages.size(); i++) { //finds average.
+ for (int j = 0; j < calcAverages[i].size(); j++) {
+ calcAverages[i][j].dist /= (float) calcDistsTotals.size();
+ }
+ }
+
+ return calcAverages;
+ }
+ catch(exception& e) {
+ errorOut(e, "MothurOut", "getAverages");
+ exit(1);
+ }
+}
+/**************************************************************************************************/
+vector< vector<seqDist> > MothurOut::getStandardDeviation(vector< vector< vector<seqDist> > >& calcDistsTotals) {
+ try{
+
+ vector< vector<seqDist> > calcAverages = getAverages(calcDistsTotals);
+
+ //find standard deviation
+ vector< vector<seqDist> > stdDev;
+ for (int i = 0; i < calcDistsTotals[0].size(); i++) { //initialize sums to zero.
+ vector<seqDist> temp;
+ for (int j = 0; j < calcDistsTotals[0][i].size(); j++) {
+ seqDist tempDist;
+ tempDist.seq1 = calcDistsTotals[0][i][j].seq1;
+ tempDist.seq2 = calcDistsTotals[0][i][j].seq2;
+ tempDist.dist = 0.0;
+ temp.push_back(tempDist);
+ }
+ stdDev.push_back(temp);
+ }
+
+ for (int thisIter = 0; thisIter < calcDistsTotals.size(); thisIter++) { //compute the difference of each dist from the mean, and square the result of each
+ for (int i = 0; i < stdDev.size(); i++) {
+ for (int j = 0; j < stdDev[i].size(); j++) {
+ stdDev[i][j].dist += ((calcDistsTotals[thisIter][i][j].dist - calcAverages[i][j].dist) * (calcDistsTotals[thisIter][i][j].dist - calcAverages[i][j].dist));
+ }
+ }
+ }
+
+ for (int i = 0; i < stdDev.size(); i++) { //finds average.
+ for (int j = 0; j < stdDev[i].size(); j++) {
+ stdDev[i][j].dist /= (float) calcDistsTotals.size();
+ stdDev[i][j].dist = sqrt(stdDev[i][j].dist);
+ }
+ }
+
+ return stdDev;
+ }
+ catch(exception& e) {
+ errorOut(e, "MothurOut", "getAverages");
+ exit(1);
+ }
+}
+/**************************************************************************************************/
+vector< vector<seqDist> > MothurOut::getStandardDeviation(vector< vector< vector<seqDist> > >& calcDistsTotals, vector< vector<seqDist> >& calcAverages) {
+ try{
+ //find standard deviation
+ vector< vector<seqDist> > stdDev;
+ for (int i = 0; i < calcDistsTotals[0].size(); i++) { //initialize sums to zero.
+ vector<seqDist> temp;
+ for (int j = 0; j < calcDistsTotals[0][i].size(); j++) {
+ seqDist tempDist;
+ tempDist.seq1 = calcDistsTotals[0][i][j].seq1;
+ tempDist.seq2 = calcDistsTotals[0][i][j].seq2;
+ tempDist.dist = 0.0;
+ temp.push_back(tempDist);
+ }
+ stdDev.push_back(temp);
+ }
+
+ for (int thisIter = 0; thisIter < calcDistsTotals.size(); thisIter++) { //compute the difference of each dist from the mean, and square the result of each
+ for (int i = 0; i < stdDev.size(); i++) {
+ for (int j = 0; j < stdDev[i].size(); j++) {
+ stdDev[i][j].dist += ((calcDistsTotals[thisIter][i][j].dist - calcAverages[i][j].dist) * (calcDistsTotals[thisIter][i][j].dist - calcAverages[i][j].dist));
+ }
+ }
+ }
+
+ for (int i = 0; i < stdDev.size(); i++) { //finds average.
+ for (int j = 0; j < stdDev[i].size(); j++) {
+ stdDev[i][j].dist /= (float) calcDistsTotals.size();
+ stdDev[i][j].dist = sqrt(stdDev[i][j].dist);
+ }
+ }
+