+
+ if (method == "totalgroup") {
+
+ for (int j = 0; j < thisLookUp[0]->getNumBins(); j++) {
+
+ for (int i = 0; i < thisLookUp.size(); i++) {
+
+ if (m->control_pressed) { return 0; }
+
+ int abund = thisLookUp[i]->getAbundance(j);
+
+ float relabund = abund / (float) thisLookUp[i]->getNumSeqs();
+ float newNorm = relabund * norm;
+
+ //round to nearest int
+ int finalNorm = (int) floor((newNorm + 0.5));
+
+ thisLookUp[i]->set(j, finalNorm, thisLookUp[i]->getGroup());
+ }
+ }
+
+ }else if (method == "zscore") {
+
+ for (int j = 0; j < thisLookUp[0]->getNumBins(); j++) {
+
+ if (m->control_pressed) { return 0; }
+
+ //calc mean
+ float mean = 0.0;
+ for (int i = 0; i < thisLookUp.size(); i++) { mean += thisLookUp[i]->getAbundance(j); }
+ mean /= (float) thisLookUp.size();
+
+ //calc standard deviation
+ float sumSquared = 0.0;
+ for (int i = 0; i < thisLookUp.size(); i++) { sumSquared += (((float)thisLookUp[i]->getAbundance(j) - mean) * ((float)thisLookUp[i]->getAbundance(j) - mean)); }
+ sumSquared /= (float) thisLookUp.size();
+
+ float standardDev = sqrt(sumSquared);
+
+ for (int i = 0; i < thisLookUp.size(); i++) {
+ int finalNorm = 0;
+ if (standardDev != 0) { // stop divide by zero
+ float newNorm = ((float)thisLookUp[i]->getAbundance(j) - mean) / standardDev;
+ //round to nearest int
+ finalNorm = (int) floor((newNorm + 0.5));
+ }
+
+ thisLookUp[i]->set(j, finalNorm, thisLookUp[i]->getGroup());
+ }
+ }
+
+ }else{ m->mothurOut(method + " is not a valid scaling option."); m->mothurOutEndLine(); m->control_pressed = true; return 0; }
+
+
+
+ eliminateZeroOTUS(thisLookUp);
+
+ for (int i = 0; i < thisLookUp.size(); i++) {
+ out << thisLookUp[i]->getLabel() << '\t' << thisLookUp[i]->getGroup() << '\t';
+ thisLookUp[i]->print(out);
+ }
+
+ return 0;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "NormalizeSharedCommand", "normalize");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************