2 * normalizesharedcommand.cpp
5 * Created by westcott on 9/15/10.
6 * Copyright 2010 Schloss Lab. All rights reserved.
10 #include "normalizesharedcommand.h"
12 //**********************************************************************************************************************
13 vector<string> NormalizeSharedCommand::setParameters(){
15 CommandParameter pshared("shared", "InputTypes", "", "", "LRSS", "LRSS", "none","shared",false,false,true); parameters.push_back(pshared);
16 CommandParameter prelabund("relabund", "InputTypes", "", "", "LRSS", "LRSS", "none","shared",false,false,true); parameters.push_back(prelabund);
17 CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups);
18 CommandParameter pmethod("method", "Multiple", "totalgroup-zscore", "totalgroup", "", "", "","",false,false,true); parameters.push_back(pmethod);
19 CommandParameter pnorm("norm", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pnorm);
20 CommandParameter pmakerelabund("makerelabund", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pmakerelabund);
21 CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel);
22 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
23 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
25 vector<string> myArray;
26 for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
30 m->errorOut(e, "NormalizeSharedCommand", "setParameters");
34 //**********************************************************************************************************************
35 string NormalizeSharedCommand::getHelpString(){
37 string helpString = "";
38 helpString += "The normalize.shared command parameters are shared, relabund, groups, method, norm, makerelabund and label. shared or relabund is required, unless you have a valid current file.\n";
39 helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like included. The group names are separated by dashes.\n";
40 helpString += "The label parameter allows you to select what distance levels you would like, and are also separated by dashes.\n";
41 helpString += "The method parameter allows you to select what method you would like to use to normalize. The options are totalgroup and zscore. We hope to add more ways to normalize in the future, suggestions are welcome!\n";
42 helpString += "The makerelabund parameter allows you to convert a shared file to a relabund file before you normalize. default=f.\n";
43 helpString += "The norm parameter allows you to number you would like to normalize to. By default this is set to the number of sequences in your smallest group.\n";
44 helpString += "The normalize.shared command should be in the following format: normalize.shared(groups=yourGroups, label=yourLabels).\n";
45 helpString += "Example normalize.shared(groups=A-B-C, scale=totalgroup).\n";
46 helpString += "The default value for groups is all the groups in your groupfile, and all labels in your inputfile will be used.\n";
47 helpString += "The normalize.shared command outputs a .norm.shared file.\n";
48 helpString += "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n";
52 m->errorOut(e, "NormalizeSharedCommand", "getHelpString");
56 //**********************************************************************************************************************
57 string NormalizeSharedCommand::getOutputPattern(string type) {
61 if (type == "shared") { pattern = "[filename],[distance],norm.shared"; }
62 else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; }
67 m->errorOut(e, "NormalizeSharedCommand", "getOutputPattern");
71 //**********************************************************************************************************************
72 NormalizeSharedCommand::NormalizeSharedCommand(){
74 abort = true; calledHelp = true;
76 vector<string> tempOutNames;
77 outputTypes["shared"] = tempOutNames;
80 m->errorOut(e, "NormalizeSharedCommand", "NormalizeSharedCommand");
84 //**********************************************************************************************************************
86 NormalizeSharedCommand::NormalizeSharedCommand(string option) {
88 abort = false; calledHelp = false;
91 //allow user to run help
92 if(option == "help") { help(); abort = true; calledHelp = true; }
93 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
96 vector<string> myArray = setParameters();
98 OptionParser parser(option);
99 map<string,string> parameters = parser.getParameters();
100 map<string,string>::iterator it;
102 ValidParameters validParameter;
104 //check to make sure all parameters are valid for command
105 for (it = parameters.begin(); it != parameters.end(); it++) {
106 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
109 //initialize outputTypes
110 vector<string> tempOutNames;
111 outputTypes["shared"] = tempOutNames;
113 //if the user changes the input directory command factory will send this info to us in the output parameter
114 string inputDir = validParameter.validFile(parameters, "inputdir", false);
115 if (inputDir == "not found"){ inputDir = ""; }
118 it = parameters.find("shared");
119 //user has given a template file
120 if(it != parameters.end()){
121 path = m->hasPath(it->second);
122 //if the user has not given a path then, add inputdir. else leave path alone.
123 if (path == "") { parameters["shared"] = inputDir + it->second; }
126 it = parameters.find("relabund");
127 //user has given a template file
128 if(it != parameters.end()){
129 path = m->hasPath(it->second);
130 //if the user has not given a path then, add inputdir. else leave path alone.
131 if (path == "") { parameters["relabund"] = inputDir + it->second; }
135 sharedfile = validParameter.validFile(parameters, "shared", true);
136 if (sharedfile == "not open") { sharedfile = ""; abort = true; }
137 else if (sharedfile == "not found") { sharedfile = ""; }
138 else { format = "sharedfile"; inputfile = sharedfile; m->setSharedFile(sharedfile); }
140 relabundfile = validParameter.validFile(parameters, "relabund", true);
141 if (relabundfile == "not open") { relabundfile = ""; abort = true; }
142 else if (relabundfile == "not found") { relabundfile = ""; }
143 else { format = "relabund"; inputfile = relabundfile; m->setRelAbundFile(relabundfile); }
146 if ((sharedfile == "") && (relabundfile == "")) {
147 //is there are current file available for any of these?
148 //give priority to shared, then list, then rabund, then sabund
149 //if there is a current shared file, use it
150 sharedfile = m->getSharedFile();
151 if (sharedfile != "") { inputfile = sharedfile; format = "sharedfile"; m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); }
153 relabundfile = m->getRelAbundFile();
154 if (relabundfile != "") { inputfile = relabundfile; format = "relabund"; m->mothurOut("Using " + relabundfile + " as input file for the relabund parameter."); m->mothurOutEndLine(); }
156 m->mothurOut("No valid current files. You must provide a list, sabund, rabund, relabund or shared file."); m->mothurOutEndLine();
163 //if the user changes the output directory command factory will send this info to us in the output parameter
164 outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = m->hasPath(inputfile); }
168 //check for optional parameter and set defaults
169 // ...at some point should added some additional type checking...
170 label = validParameter.validFile(parameters, "label", false);
171 if (label == "not found") { label = ""; }
173 if(label != "all") { m->splitAtDash(label, labels); allLines = 0; }
174 else { allLines = 1; }
177 groups = validParameter.validFile(parameters, "groups", false);
178 if (groups == "not found") { groups = ""; pickedGroups = false; }
181 m->splitAtDash(groups, Groups);
182 m->setGroups(Groups);
185 method = validParameter.validFile(parameters, "method", false); if (method == "not found") { method = "totalgroup"; }
186 if ((method != "totalgroup") && (method != "zscore")) { m->mothurOut(method + " is not a valid scaling option for the normalize.shared command. The options are totalgroup and zscore. We hope to add more ways to normalize in the future, suggestions are welcome!"); m->mothurOutEndLine(); abort = true; }
188 string temp = validParameter.validFile(parameters, "norm", false);
189 if (temp == "not found") {
190 norm = 0; //once you have read, set norm to smallest group number
192 m->mothurConvert(temp, norm);
193 if (norm < 0) { m->mothurOut("norm must be positive."); m->mothurOutEndLine(); abort=true; }
196 temp = validParameter.validFile(parameters, "makerelabund", false); if (temp == "") { temp = "f"; }
197 makeRelabund = m->isTrue(temp);
201 catch(exception& e) {
202 m->errorOut(e, "NormalizeSharedCommand", "NormalizeSharedCommand");
206 //**********************************************************************************************************************
208 int NormalizeSharedCommand::execute(){
211 if (abort == true) { if (calledHelp) { return 0; } return 2; }
213 input = new InputData(inputfile, format);
215 //you are reading a sharedfile and you do not want to make relabund
216 if ((format == "sharedfile") && (!makeRelabund)) {
217 lookup = input->getSharedRAbundVectors();
218 string lastLabel = lookup[0]->getLabel();
220 //look for groups whose numseqs is below norm and remove them, warning the user
223 vector<string> mGroups;
224 vector<SharedRAbundVector*> temp;
225 for (int i = 0; i < lookup.size(); i++) {
226 if (lookup[i]->getNumSeqs() < norm) {
227 m->mothurOut(lookup[i]->getGroup() + " contains " + toString(lookup[i]->getNumSeqs()) + ". Eliminating."); m->mothurOutEndLine();
230 mGroups.push_back(lookup[i]->getGroup());
231 temp.push_back(lookup[i]);
235 m->setGroups(mGroups);
238 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
239 set<string> processedLabels;
240 set<string> userLabels = labels;
242 if (method == "totalgroup") {
243 //set norm to smallest group number
245 norm = lookup[0]->getNumSeqs();
246 for (int i = 1; i < lookup.size(); i++) {
247 if (lookup[i]->getNumSeqs() < norm) { norm = lookup[i]->getNumSeqs(); }
251 m->mothurOut("Normalizing to " + toString(norm) + "."); m->mothurOutEndLine();
255 //as long as you are not at the end of the file or done wih the lines you want
256 while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
258 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } m->clearGroups(); return 0; }
260 if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){
262 m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
265 processedLabels.insert(lookup[0]->getLabel());
266 userLabels.erase(lookup[0]->getLabel());
269 if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
270 string saveLabel = lookup[0]->getLabel();
272 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
273 lookup = input->getSharedRAbundVectors(lastLabel);
274 m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
278 processedLabels.insert(lookup[0]->getLabel());
279 userLabels.erase(lookup[0]->getLabel());
281 //restore real lastlabel to save below
282 lookup[0]->setLabel(saveLabel);
285 lastLabel = lookup[0]->getLabel();
286 //prevent memory leak
287 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; }
289 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); m->clearGroups(); return 0; }
291 //get next line to process
292 lookup = input->getSharedRAbundVectors();
295 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); m->clearGroups(); return 0; }
297 //output error messages about any remaining user labels
298 set<string>::iterator it;
299 bool needToRun = false;
300 for (it = userLabels.begin(); it != userLabels.end(); it++) {
301 m->mothurOut("Your file does not include the label " + *it);
302 if (processedLabels.count(lastLabel) != 1) {
303 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
306 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
310 //run last label if you need to
311 if (needToRun == true) {
312 for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } }
313 lookup = input->getSharedRAbundVectors(lastLabel);
315 m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
319 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
322 }else{ //relabund values
323 lookupFloat = input->getSharedRAbundFloatVectors();
324 string lastLabel = lookupFloat[0]->getLabel();
326 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
327 set<string> processedLabels;
328 set<string> userLabels = labels;
330 //look for groups whose numseqs is below norm and remove them, warning the user
333 vector<string> mGroups;
334 vector<SharedRAbundFloatVector*> temp;
335 for (int i = 0; i < lookupFloat.size(); i++) {
336 if (lookupFloat[i]->getNumSeqs() < norm) {
337 m->mothurOut(lookupFloat[i]->getGroup() + " contains " + toString(lookupFloat[i]->getNumSeqs()) + ". Eliminating."); m->mothurOutEndLine();
338 delete lookupFloat[i];
340 mGroups.push_back(lookupFloat[i]->getGroup());
341 temp.push_back(lookupFloat[i]);
345 m->setGroups(mGroups);
348 //set norm to smallest group number
349 if (method == "totalgroup") {
351 norm = lookupFloat[0]->getNumSeqs();
352 for (int i = 1; i < lookupFloat.size(); i++) {
353 if (lookupFloat[i]->getNumSeqs() < norm) { norm = lookupFloat[i]->getNumSeqs(); }
357 m->mothurOut("Normalizing to " + toString(norm) + "."); m->mothurOutEndLine();
360 //as long as you are not at the end of the file or done wih the lines you want
361 while((lookupFloat[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
363 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } m->clearGroups(); return 0; }
365 if(allLines == 1 || labels.count(lookupFloat[0]->getLabel()) == 1){
367 m->mothurOut(lookupFloat[0]->getLabel()); m->mothurOutEndLine();
369 normalize(lookupFloat);
371 processedLabels.insert(lookupFloat[0]->getLabel());
372 userLabels.erase(lookupFloat[0]->getLabel());
375 if ((m->anyLabelsToProcess(lookupFloat[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
376 string saveLabel = lookupFloat[0]->getLabel();
378 for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; }
379 lookupFloat = input->getSharedRAbundFloatVectors(lastLabel);
381 m->mothurOut(lookupFloat[0]->getLabel()); m->mothurOutEndLine();
383 normalize(lookupFloat);
385 processedLabels.insert(lookupFloat[0]->getLabel());
386 userLabels.erase(lookupFloat[0]->getLabel());
388 //restore real lastlabel to save below
389 lookupFloat[0]->setLabel(saveLabel);
392 lastLabel = lookupFloat[0]->getLabel();
393 //prevent memory leak
394 for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; lookupFloat[i] = NULL; }
396 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); m->clearGroups(); return 0; }
398 //get next line to process
399 lookupFloat = input->getSharedRAbundFloatVectors();
402 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); m->clearGroups(); return 0; }
404 //output error messages about any remaining user labels
405 set<string>::iterator it;
406 bool needToRun = false;
407 for (it = userLabels.begin(); it != userLabels.end(); it++) {
408 m->mothurOut("Your file does not include the label " + *it);
409 if (processedLabels.count(lastLabel) != 1) {
410 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
413 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
417 //run last label if you need to
418 if (needToRun == true) {
419 for (int i = 0; i < lookupFloat.size(); i++) { if (lookupFloat[i] != NULL) { delete lookupFloat[i]; } }
420 lookupFloat = input->getSharedRAbundFloatVectors(lastLabel);
422 m->mothurOut(lookupFloat[0]->getLabel()); m->mothurOutEndLine();
424 normalize(lookupFloat);
426 for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; }
430 //reset groups parameter
434 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); return 0;}
436 m->mothurOutEndLine();
437 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
438 //m->mothurOut(outputFileName); m->mothurOutEndLine(); outputNames.push_back(outputFileName); outputTypes["shared"].push_back(outputFileName);
439 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
440 m->mothurOutEndLine();
442 //set shared file as new current sharedfile
444 itTypes = outputTypes.find("shared");
445 if (itTypes != outputTypes.end()) {
446 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setSharedFile(current); }
451 catch(exception& e) {
452 m->errorOut(e, "NormalizeSharedCommand", "execute");
456 //**********************************************************************************************************************
458 int NormalizeSharedCommand::normalize(vector<SharedRAbundVector*>& thisLookUp){
460 //save mothurOut's binLabels to restore for next label
461 vector<string> saveBinLabels = m->currentBinLabels;
463 if (pickedGroups) { eliminateZeroOTUS(thisLookUp); }
465 map<string, string> variables;
466 variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputfile));
467 variables["[distance]"] = thisLookUp[0]->getLabel();
468 string outputFileName = getOutputFileName("shared",variables);
471 m->openOutputFile(outputFileName, out);
472 outputNames.push_back(outputFileName); outputTypes["shared"].push_back(outputFileName);
474 if (method == "totalgroup") {
476 //save numSeqs since they will change as the data is normalized
478 for (int i = 0; i < thisLookUp.size(); i++) { sizes.push_back(thisLookUp[i]->getNumSeqs()); }
480 for (int j = 0; j < thisLookUp[0]->getNumBins(); j++) {
482 for (int i = 0; i < thisLookUp.size(); i++) {
484 if (m->control_pressed) { out.close(); return 0; }
486 int abund = thisLookUp[i]->getAbundance(j);
488 float relabund = abund / (float) sizes[i];
489 float newNorm = relabund * norm;
491 //round to nearest int
492 int finalNorm = (int) floor((newNorm + 0.5));
494 thisLookUp[i]->set(j, finalNorm, thisLookUp[i]->getGroup());
498 }else if (method == "zscore") {
500 for (int j = 0; j < thisLookUp[0]->getNumBins(); j++) {
502 if (m->control_pressed) { out.close(); return 0; }
506 for (int i = 0; i < thisLookUp.size(); i++) { mean += thisLookUp[i]->getAbundance(j); }
507 mean /= (float) thisLookUp.size();
509 //calc standard deviation
510 float sumSquared = 0.0;
511 for (int i = 0; i < thisLookUp.size(); i++) { sumSquared += (((float)thisLookUp[i]->getAbundance(j) - mean) * ((float)thisLookUp[i]->getAbundance(j) - mean)); }
512 sumSquared /= (float) thisLookUp.size();
514 float standardDev = sqrt(sumSquared);
516 for (int i = 0; i < thisLookUp.size(); i++) {
518 if (standardDev != 0) { // stop divide by zero
519 float newNorm = ((float)thisLookUp[i]->getAbundance(j) - mean) / standardDev;
520 //round to nearest int
521 finalNorm = (int) floor((newNorm + 0.5));
524 thisLookUp[i]->set(j, finalNorm, thisLookUp[i]->getGroup());
528 }else{ m->mothurOut(method + " is not a valid scaling option."); m->mothurOutEndLine(); m->control_pressed = true; return 0; }
532 eliminateZeroOTUS(thisLookUp);
534 thisLookUp[0]->printHeaders(out);
536 for (int i = 0; i < thisLookUp.size(); i++) {
537 out << thisLookUp[i]->getLabel() << '\t' << thisLookUp[i]->getGroup() << '\t';
538 thisLookUp[i]->print(out);
543 m->currentBinLabels = saveBinLabels;
547 catch(exception& e) {
548 m->errorOut(e, "NormalizeSharedCommand", "normalize");
552 //**********************************************************************************************************************
554 int NormalizeSharedCommand::normalize(vector<SharedRAbundFloatVector*>& thisLookUp){
557 //save mothurOut's binLabels to restore for next label
558 vector<string> saveBinLabels = m->currentBinLabels;
560 map<string, string> variables;
561 variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputfile));
562 variables["[distance]"] = thisLookUp[0]->getLabel();
563 string outputFileName = getOutputFileName("shared",variables);
565 m->openOutputFile(outputFileName, out);
566 outputNames.push_back(outputFileName); outputTypes["shared"].push_back(outputFileName);
569 if (pickedGroups) { eliminateZeroOTUS(thisLookUp); }
571 if (method == "totalgroup") {
573 //save numSeqs since they will change as the data is normalized
575 for (int i = 0; i < thisLookUp.size(); i++) { sizes.push_back(thisLookUp[i]->getNumSeqs()); }
577 for (int j = 0; j < thisLookUp[0]->getNumBins(); j++) {
579 for (int i = 0; i < thisLookUp.size(); i++) {
581 if (m->control_pressed) { out.close(); return 0; }
583 float abund = thisLookUp[i]->getAbundance(j);
585 float relabund = abund / (float) sizes[i];
586 float newNorm = relabund * norm;
588 thisLookUp[i]->set(j, newNorm, thisLookUp[i]->getGroup());
592 }else if (method == "zscore") {
593 for (int j = 0; j < thisLookUp[0]->getNumBins(); j++) {
595 if (m->control_pressed) { out.close(); return 0; }
599 for (int i = 0; i < thisLookUp.size(); i++) { mean += thisLookUp[i]->getAbundance(j); }
600 mean /= (float) thisLookUp.size();
602 //calc standard deviation
603 float sumSquared = 0.0;
604 for (int i = 0; i < thisLookUp.size(); i++) { sumSquared += ((thisLookUp[i]->getAbundance(j) - mean) * (thisLookUp[i]->getAbundance(j) - mean)); }
605 sumSquared /= (float) thisLookUp.size();
607 float standardDev = sqrt(sumSquared);
609 for (int i = 0; i < thisLookUp.size(); i++) {
611 if (standardDev != 0) { // stop divide by zero
612 newNorm = (thisLookUp[i]->getAbundance(j) - mean) / standardDev;
614 thisLookUp[i]->set(j, newNorm, thisLookUp[i]->getGroup());
618 }else{ m->mothurOut(method + " is not a valid scaling option."); m->mothurOutEndLine(); m->control_pressed = true; return 0; }
621 eliminateZeroOTUS(thisLookUp);
623 thisLookUp[0]->printHeaders(out);
625 for (int i = 0; i < thisLookUp.size(); i++) {
626 out << thisLookUp[i]->getLabel() << '\t' << thisLookUp[i]->getGroup() << '\t';
627 thisLookUp[i]->print(out);
632 m->currentBinLabels = saveBinLabels;
636 catch(exception& e) {
637 m->errorOut(e, "NormalizeSharedCommand", "normalize");
641 //**********************************************************************************************************************
642 int NormalizeSharedCommand::eliminateZeroOTUS(vector<SharedRAbundVector*>& thislookup) {
645 vector<SharedRAbundVector*> newLookup;
646 for (int i = 0; i < thislookup.size(); i++) {
647 SharedRAbundVector* temp = new SharedRAbundVector();
648 temp->setLabel(thislookup[i]->getLabel());
649 temp->setGroup(thislookup[i]->getGroup());
650 newLookup.push_back(temp);
654 vector<string> newBinLabels;
655 string snumBins = toString(thislookup[0]->getNumBins());
656 for (int i = 0; i < thislookup[0]->getNumBins(); i++) {
657 if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; }
659 //look at each sharedRabund and make sure they are not all zero
661 for (int j = 0; j < thislookup.size(); j++) {
662 if (thislookup[j]->getAbundance(i) != 0) { allZero = false; break; }
665 //if they are not all zero add this bin
667 for (int j = 0; j < thislookup.size(); j++) {
668 newLookup[j]->push_back(thislookup[j]->getAbundance(i), thislookup[j]->getGroup());
670 //if there is a bin label use it otherwise make one
671 string binLabel = "Otu";
672 string sbinNumber = toString(i+1);
673 if (sbinNumber.length() < snumBins.length()) {
674 int diff = snumBins.length() - sbinNumber.length();
675 for (int h = 0; h < diff; h++) { binLabel += "0"; }
677 binLabel += sbinNumber;
678 if (i < m->currentBinLabels.size()) { binLabel = m->currentBinLabels[i]; }
680 newBinLabels.push_back(binLabel);
684 for (int j = 0; j < thislookup.size(); j++) { delete thislookup[j]; }
686 thislookup = newLookup;
687 m->currentBinLabels = newBinLabels;
692 catch(exception& e) {
693 m->errorOut(e, "NormalizeSharedCommand", "eliminateZeroOTUS");
697 //**********************************************************************************************************************
698 int NormalizeSharedCommand::eliminateZeroOTUS(vector<SharedRAbundFloatVector*>& thislookup) {
701 vector<SharedRAbundFloatVector*> newLookup;
702 for (int i = 0; i < thislookup.size(); i++) {
703 SharedRAbundFloatVector* temp = new SharedRAbundFloatVector();
704 temp->setLabel(thislookup[i]->getLabel());
705 temp->setGroup(thislookup[i]->getGroup());
706 newLookup.push_back(temp);
710 vector<string> newBinLabels;
711 string snumBins = toString(thislookup[0]->getNumBins());
712 for (int i = 0; i < thislookup[0]->getNumBins(); i++) {
713 if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; }
715 //look at each sharedRabund and make sure they are not all zero
717 for (int j = 0; j < thislookup.size(); j++) {
718 if (thislookup[j]->getAbundance(i) != 0) { allZero = false; break; }
721 //if they are not all zero add this bin
723 for (int j = 0; j < thislookup.size(); j++) {
724 newLookup[j]->push_back(thislookup[j]->getAbundance(i), thislookup[j]->getGroup());
726 //if there is a bin label use it otherwise make one
727 string binLabel = "Otu";
728 string sbinNumber = toString(i+1);
729 if (sbinNumber.length() < snumBins.length()) {
730 int diff = snumBins.length() - sbinNumber.length();
731 for (int h = 0; h < diff; h++) { binLabel += "0"; }
733 binLabel += sbinNumber;
734 if (i < m->currentBinLabels.size()) { binLabel = m->currentBinLabels[i]; }
736 newBinLabels.push_back(binLabel);
740 for (int j = 0; j < thislookup.size(); j++) { delete thislookup[j]; }
742 thislookup = newLookup;
743 m->currentBinLabels = newBinLabels;
748 catch(exception& e) {
749 m->errorOut(e, "NormalizeSharedCommand", "eliminateZeroOTUS");
754 //**********************************************************************************************************************