]> git.donarmstrong.com Git - mothur.git/blob - normalizesharedcommand.cpp
added [ERROR] flag if command aborts
[mothur.git] / normalizesharedcommand.cpp
1 /*
2  *  normalizesharedcommand.cpp
3  *  Mothur
4  *
5  *  Created by westcott on 9/15/10.
6  *  Copyright 2010 Schloss Lab. All rights reserved.
7  *
8  */
9
10 #include "normalizesharedcommand.h"
11
12 //**********************************************************************************************************************
13 vector<string> NormalizeSharedCommand::getValidParameters(){    
14         try {
15                 string Array[] =  {"groups","label","method","makerelabund","outputdir","inputdir","norm"};
16                 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
17                 return myArray;
18         }
19         catch(exception& e) {
20                 m->errorOut(e, "NormalizeSharedCommand", "getValidParameters");
21                 exit(1);
22         }
23 }
24 //**********************************************************************************************************************
25 NormalizeSharedCommand::NormalizeSharedCommand(){       
26         try {
27                 abort = true; calledHelp = true; 
28                 vector<string> tempOutNames;
29                 outputTypes["shared"] = tempOutNames;
30         }
31         catch(exception& e) {
32                 m->errorOut(e, "NormalizeSharedCommand", "NormalizeSharedCommand");
33                 exit(1);
34         }
35 }
36 //**********************************************************************************************************************
37 vector<string> NormalizeSharedCommand::getRequiredParameters(){ 
38         try {
39                 vector<string> myArray;
40                 return myArray;
41         }
42         catch(exception& e) {
43                 m->errorOut(e, "NormalizeSharedCommand", "getRequiredParameters");
44                 exit(1);
45         }
46 }
47 //**********************************************************************************************************************
48 vector<string> NormalizeSharedCommand::getRequiredFiles(){      
49         try {
50                 string Array[] =  {"shared"};
51                 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
52                 return myArray;
53         }
54         catch(exception& e) {
55                 m->errorOut(e, "NormalizeSharedCommand", "getRequiredFiles");
56                 exit(1);
57         }
58 }
59 //**********************************************************************************************************************
60
61 NormalizeSharedCommand::NormalizeSharedCommand(string option) {
62         try {
63                 globaldata = GlobalData::getInstance();
64                 abort = false; calledHelp = false;   
65                 allLines = 1;
66                 labels.clear();
67                 
68                 //allow user to run help
69                 if(option == "help") { help(); abort = true; calledHelp = true; }
70                 
71                 else {
72                         //valid paramters for this command
73                         string AlignArray[] =  {"groups","label","method","makerelabund","outputdir","inputdir","norm"};
74                         vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
75                         
76                         OptionParser parser(option);
77                         map<string,string> parameters = parser.getParameters();
78                         
79                         ValidParameters validParameter;
80                         
81                         //check to make sure all parameters are valid for command
82                         for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
83                                 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
84                         }
85                         
86                         //initialize outputTypes
87                         vector<string> tempOutNames;
88                         outputTypes["shared"] = tempOutNames;
89                         
90                         //if the user changes the output directory command factory will send this info to us in the output parameter 
91                         outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
92                                 outputDir = ""; 
93                                 outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it       
94                         }
95                         
96                         //make sure the user has already run the read.otu command
97                         if ((globaldata->getSharedFile() == "") && (globaldata->getRelAbundFile() == "")) {
98                                  m->mothurOut("You must read a list and a group, shared or relabund file before you can use the normalize.shared command."); m->mothurOutEndLine(); abort = true; 
99                         }
100                         
101                         if ((globaldata->getSharedFile() != "") && (globaldata->getRelAbundFile() != "")) {
102                                 m->mothurOut("You may not use both a shared and relabund file as input for normalize.shared command."); m->mothurOutEndLine(); abort = true; 
103                         }
104                         
105
106                         //check for optional parameter and set defaults
107                         // ...at some point should added some additional type checking...
108                         label = validParameter.validFile(parameters, "label", false);                   
109                         if (label == "not found") { label = ""; }
110                         else { 
111                                 if(label != "all") {  m->splitAtDash(label, labels);  allLines = 0;  }
112                                 else { allLines = 1;  }
113                         }
114                         
115                         //if the user has not specified any labels use the ones from read.otu
116                         if (label == "") {  
117                                 allLines = globaldata->allLines; 
118                                 labels = globaldata->labels; 
119                         }
120                         
121                         groups = validParameter.validFile(parameters, "groups", false);                 
122                         if (groups == "not found") { groups = ""; pickedGroups = false; }
123                         else { 
124                                 pickedGroups = true;
125                                 m->splitAtDash(groups, Groups);
126                                 globaldata->Groups = Groups;
127                         }
128                         
129                         method = validParameter.validFile(parameters, "method", false);                         if (method == "not found") { method = "totalgroup"; }
130                         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; }
131                 
132                         string temp = validParameter.validFile(parameters, "norm", false);                              
133                         if (temp == "not found") {  
134                                 norm = 0;  //once you have read, set norm to smallest group number
135                         }else { 
136                                 convert(temp, norm);
137                                 if (norm < 0) { m->mothurOut("norm must be positive."); m->mothurOutEndLine(); abort=true; }
138                         }
139                         
140                         temp = validParameter.validFile(parameters, "makerelabund", false);     if (temp == "") { temp = "f"; }
141                         makeRelabund = m->isTrue(temp);
142                         
143                         if ((globaldata->getFormat() != "sharedfile") && makeRelabund) { m->mothurOut("makerelabund can only be used with a shared file."); m->mothurOutEndLine(); }
144                         
145                 }
146
147         }
148         catch(exception& e) {
149                 m->errorOut(e, "NormalizeSharedCommand", "NormalizeSharedCommand");
150                 exit(1);
151         }
152 }
153
154 //**********************************************************************************************************************
155
156 void NormalizeSharedCommand::help(){
157         try {
158                 m->mothurOut("The normalize.shared command can only be executed after a successful read.otu command of a list and group, shared or relabund file.\n");
159                 m->mothurOut("The normalize.shared command parameters are groups, method, norm, makerelabund and label.  No parameters are required.\n");
160                 m->mothurOut("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");
161                 m->mothurOut("The label parameter allows you to select what distance levels you would like, and are also separated by dashes.\n");
162                 m->mothurOut("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");
163                 m->mothurOut("The makerelabund parameter allows you to convert a shared file to a relabund file before you normalize. default=f.\n");
164                 m->mothurOut("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");
165                 m->mothurOut("The normalize.shared command should be in the following format: normalize.shared(groups=yourGroups, label=yourLabels).\n");
166                 m->mothurOut("Example normalize.shared(groups=A-B-C, scale=totalgroup).\n");
167                 m->mothurOut("The default value for groups is all the groups in your groupfile, and all labels in your inputfile will be used.\n");
168                 m->mothurOut("The normalize.shared command outputs a .norm.shared file.\n");
169                 m->mothurOut("Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n");
170
171         }
172         catch(exception& e) {
173                 m->errorOut(e, "NormalizeSharedCommand", "help");
174                 exit(1);
175         }
176 }
177
178 //**********************************************************************************************************************
179
180 NormalizeSharedCommand::~NormalizeSharedCommand(){}
181
182 //**********************************************************************************************************************
183
184 int NormalizeSharedCommand::execute(){
185         try {
186         
187                 if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
188                 
189                 string outputFileName = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + "norm.shared";
190                 ofstream out;
191                 m->openOutputFile(outputFileName, out);
192                 
193                 if (globaldata->getFormat() == "sharedfile") {  input = new InputData(globaldata->inputFileName, "sharedfile"); }
194                 else { input = new InputData(globaldata->inputFileName, "relabund"); }
195
196                 //you are reading a sharedfile and you do not want to make relabund
197                 if ((globaldata->getFormat() == "sharedfile") && (!makeRelabund)) {
198                         lookup = input->getSharedRAbundVectors();
199                         string lastLabel = lookup[0]->getLabel();
200                         
201                         //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
202                         set<string> processedLabels;
203                         set<string> userLabels = labels;
204                         
205                         if (method == "totalgroup") {
206                                 //set norm to smallest group number
207                                 if (norm == 0) { 
208                                         norm = lookup[0]->getNumSeqs();
209                                         for (int i = 1; i < lookup.size(); i++) {
210                                                 if (lookup[i]->getNumSeqs() < norm) { norm = lookup[i]->getNumSeqs();  }
211                                         }  
212                                 }
213                                 
214                                 m->mothurOut("Normalizing to " + toString(norm) + "."); m->mothurOutEndLine();
215                         }
216                         
217                         //as long as you are not at the end of the file or done wih the lines you want
218                         while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
219                                 
220                                 if (m->control_pressed) { outputTypes.clear();  for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } globaldata->Groups.clear();   out.close(); remove(outputFileName.c_str()); return 0; }
221                                 
222                                 if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){                  
223                                         
224                                         m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
225                                         normalize(lookup, out);
226                                         
227                                         processedLabels.insert(lookup[0]->getLabel());
228                                         userLabels.erase(lookup[0]->getLabel());
229                                 }
230                                 
231                                 if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
232                                         string saveLabel = lookup[0]->getLabel();
233                                         
234                                         for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }  
235                                         lookup = input->getSharedRAbundVectors(lastLabel);
236                                         m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
237                                         
238                                         normalize(lookup, out);
239                                         
240                                         processedLabels.insert(lookup[0]->getLabel());
241                                         userLabels.erase(lookup[0]->getLabel());
242                                         
243                                         //restore real lastlabel to save below
244                                         lookup[0]->setLabel(saveLabel);
245                                 }
246                                 
247                                 lastLabel = lookup[0]->getLabel();
248                                 //prevent memory leak
249                                 for (int i = 0; i < lookup.size(); i++) {  delete lookup[i]; lookup[i] = NULL; }
250                                 
251                                 if (m->control_pressed) {  outputTypes.clear(); globaldata->Groups.clear();  out.close(); remove(outputFileName.c_str()); return 0; }
252                                 
253                                 //get next line to process
254                                 lookup = input->getSharedRAbundVectors();                               
255                         }
256                         
257                         if (m->control_pressed) { outputTypes.clear(); globaldata->Groups.clear();  out.close(); remove(outputFileName.c_str());  return 0; }
258                         
259                         //output error messages about any remaining user labels
260                         set<string>::iterator it;
261                         bool needToRun = false;
262                         for (it = userLabels.begin(); it != userLabels.end(); it++) {  
263                                 m->mothurOut("Your file does not include the label " + *it); 
264                                 if (processedLabels.count(lastLabel) != 1) {
265                                         m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
266                                         needToRun = true;
267                                 }else {
268                                         m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
269                                 }
270                         }
271                         
272                         //run last label if you need to
273                         if (needToRun == true)  {
274                                 for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } }  
275                                 lookup = input->getSharedRAbundVectors(lastLabel);
276                                 
277                                 m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
278                                 
279                                 normalize(lookup, out);
280                                 
281                                 for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }
282                         }
283                         
284                 }else{ //relabund values
285                         lookupFloat = input->getSharedRAbundFloatVectors();
286                         string lastLabel = lookupFloat[0]->getLabel();
287                         
288                         //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
289                         set<string> processedLabels;
290                         set<string> userLabels = labels;
291                         
292                         //set norm to smallest group number
293                         if (method == "totalgroup") {
294                                 if (norm == 0) { 
295                                         norm = lookupFloat[0]->getNumSeqs();
296                                         for (int i = 1; i < lookupFloat.size(); i++) {
297                                                 if (lookupFloat[i]->getNumSeqs() < norm) { norm = lookupFloat[i]->getNumSeqs();  }
298                                         }  
299                                 }
300                                 
301                                 m->mothurOut("Normalizing to " + toString(norm) + "."); m->mothurOutEndLine();
302                         }
303                         
304                         //as long as you are not at the end of the file or done wih the lines you want
305                         while((lookupFloat[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
306                                 
307                                 if (m->control_pressed) { outputTypes.clear();  for (int i = 0; i < lookupFloat.size(); i++) {  delete lookupFloat[i];  } globaldata->Groups.clear();   out.close(); remove(outputFileName.c_str()); return 0; }
308                                 
309                                 if(allLines == 1 || labels.count(lookupFloat[0]->getLabel()) == 1){                     
310                                         
311                                         m->mothurOut(lookupFloat[0]->getLabel()); m->mothurOutEndLine();
312                                         normalize(lookupFloat, out);
313                                         
314                                         processedLabels.insert(lookupFloat[0]->getLabel());
315                                         userLabels.erase(lookupFloat[0]->getLabel());
316                                 }
317                                 
318                                 if ((m->anyLabelsToProcess(lookupFloat[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
319                                         string saveLabel = lookupFloat[0]->getLabel();
320                                         
321                                         for (int i = 0; i < lookupFloat.size(); i++) {  delete lookupFloat[i];  }  
322                                         lookupFloat = input->getSharedRAbundFloatVectors(lastLabel);
323                                         m->mothurOut(lookupFloat[0]->getLabel()); m->mothurOutEndLine();
324                                         
325                                         normalize(lookupFloat, out);
326                                         
327                                         processedLabels.insert(lookupFloat[0]->getLabel());
328                                         userLabels.erase(lookupFloat[0]->getLabel());
329                                         
330                                         //restore real lastlabel to save below
331                                         lookupFloat[0]->setLabel(saveLabel);
332                                 }
333                                 
334                                 lastLabel = lookupFloat[0]->getLabel();
335                                 //prevent memory leak
336                                 for (int i = 0; i < lookupFloat.size(); i++) {  delete lookupFloat[i]; lookupFloat[i] = NULL; }
337                                 
338                                 if (m->control_pressed) {  outputTypes.clear(); globaldata->Groups.clear();  out.close(); remove(outputFileName.c_str()); return 0; }
339                                 
340                                 //get next line to process
341                                 lookupFloat = input->getSharedRAbundFloatVectors();                             
342                         }
343                         
344                         if (m->control_pressed) { outputTypes.clear(); globaldata->Groups.clear();  out.close(); remove(outputFileName.c_str());  return 0; }
345                         
346                         //output error messages about any remaining user labels
347                         set<string>::iterator it;
348                         bool needToRun = false;
349                         for (it = userLabels.begin(); it != userLabels.end(); it++) {  
350                                 m->mothurOut("Your file does not include the label " + *it); 
351                                 if (processedLabels.count(lastLabel) != 1) {
352                                         m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
353                                         needToRun = true;
354                                 }else {
355                                         m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
356                                 }
357                         }
358                         
359                         //run last label if you need to
360                         if (needToRun == true)  {
361                                 for (int i = 0; i < lookupFloat.size(); i++) { if (lookupFloat[i] != NULL) { delete lookupFloat[i]; } }  
362                                 lookupFloat = input->getSharedRAbundFloatVectors(lastLabel);
363                                 
364                                 m->mothurOut(lookupFloat[0]->getLabel()); m->mothurOutEndLine();
365                                 
366                                 normalize(lookupFloat, out);
367                                 
368                                 for (int i = 0; i < lookupFloat.size(); i++) {  delete lookupFloat[i];  }
369                         }
370                         
371                 }
372                 //reset groups parameter
373                 globaldata->Groups.clear();  
374                 delete input;
375                 out.close();
376                 
377                 if (m->control_pressed) { outputTypes.clear(); remove(outputFileName.c_str()); return 0;}
378                 
379                 m->mothurOutEndLine();
380                 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
381                 m->mothurOut(outputFileName); m->mothurOutEndLine(); outputNames.push_back(outputFileName); outputTypes["shared"].push_back(outputFileName);
382                 m->mothurOutEndLine();
383                 
384                 return 0;
385         }
386         catch(exception& e) {
387                 m->errorOut(e, "NormalizeSharedCommand", "execute");
388                 exit(1);
389         }
390 }
391 //**********************************************************************************************************************
392
393 int NormalizeSharedCommand::normalize(vector<SharedRAbundVector*>& thisLookUp, ofstream& out){
394         try {
395                 if (pickedGroups) { eliminateZeroOTUS(thisLookUp); }
396                                 
397                 if (method == "totalgroup") { 
398                                         
399                         for (int j = 0; j < thisLookUp[0]->getNumBins(); j++) {
400                                                 
401                                         for (int i = 0; i < thisLookUp.size(); i++) {
402                                                         
403                                                 if (m->control_pressed) { return 0; }
404                                                         
405                                                 int abund = thisLookUp[i]->getAbundance(j);
406                                                         
407                                                 float relabund = relabund = abund / (float) thisLookUp[i]->getNumSeqs();
408                                                 float newNorm = relabund * norm;
409                                                 
410                                                 //round to nearest int
411                                                 int finalNorm = (int) floor((newNorm + 0.5));
412                                                 
413                                                 thisLookUp[i]->set(j, finalNorm, thisLookUp[i]->getGroup());
414                                         }
415                                 }
416                                         
417                 }else if (method == "zscore") {
418                         
419                         for (int j = 0; j < thisLookUp[0]->getNumBins(); j++) {
420                                 
421                                 if (m->control_pressed) { return 0; }
422                                 
423                                 //calc mean
424                                 float mean = 0.0;
425                                 for (int i = 0; i < thisLookUp.size(); i++) {  mean += thisLookUp[i]->getAbundance(j); }
426                                 mean /= (float) thisLookUp.size();
427                                         
428                                 //calc standard deviation
429                                 float sumSquared = 0.0;
430                                 for (int i = 0; i < thisLookUp.size(); i++) { sumSquared += (((float)thisLookUp[i]->getAbundance(j) - mean) * ((float)thisLookUp[i]->getAbundance(j) - mean)); }
431                                 sumSquared /= (float) thisLookUp.size();
432                                 
433                                 float standardDev = sqrt(sumSquared);
434                                         
435                                 for (int i = 0; i < thisLookUp.size(); i++) {
436                                         int finalNorm = 0;
437                                         if (standardDev != 0) { // stop divide by zero
438                                                 float newNorm = ((float)thisLookUp[i]->getAbundance(j) - mean) / standardDev;
439                                                 //round to nearest int
440                                                 finalNorm = (int) floor((newNorm + 0.5));
441                                         }
442                                         
443                                         thisLookUp[i]->set(j, finalNorm, thisLookUp[i]->getGroup());
444                                 }
445                         }
446                                                 
447                 }else{ m->mothurOut(method + " is not a valid scaling option."); m->mothurOutEndLine(); m->control_pressed = true; return 0; }
448                                 
449                                 
450                                                 
451                 eliminateZeroOTUS(thisLookUp);
452                  
453                 for (int i = 0; i < thisLookUp.size(); i++) {
454                         out << thisLookUp[i]->getLabel() << '\t' << thisLookUp[i]->getGroup() << '\t';
455                         thisLookUp[i]->print(out);
456                 }
457                 
458                 return 0;
459         }
460         catch(exception& e) {
461                 m->errorOut(e, "NormalizeSharedCommand", "normalize");
462                 exit(1);
463         }
464 }
465 //**********************************************************************************************************************
466
467 int NormalizeSharedCommand::normalize(vector<SharedRAbundFloatVector*>& thisLookUp, ofstream& out){
468         try {
469                 if (pickedGroups) { eliminateZeroOTUS(thisLookUp); }
470                 
471                 if (method == "totalgroup") { 
472                         
473                         for (int j = 0; j < thisLookUp[0]->getNumBins(); j++) {
474                                 
475                                 for (int i = 0; i < thisLookUp.size(); i++) {
476                                         
477                                         if (m->control_pressed) { return 0; }
478                                         
479                                         float abund = thisLookUp[i]->getAbundance(j);
480                                         
481                                         float relabund = relabund = abund / (float) thisLookUp[i]->getNumSeqs();
482                                         float newNorm = relabund * norm;
483                                         
484                                         thisLookUp[i]->set(j, newNorm, thisLookUp[i]->getGroup());
485                                 }
486                         }
487                         
488                 }else if (method == "zscore") {
489                         for (int j = 0; j < thisLookUp[0]->getNumBins(); j++) {
490                                 
491                                 if (m->control_pressed) { return 0; }
492                                 
493                                 //calc mean
494                                 float mean = 0.0;
495                                 for (int i = 0; i < thisLookUp.size(); i++) {  mean += thisLookUp[i]->getAbundance(j); }
496                                 mean /= (float) thisLookUp.size();
497                                 
498                                 //calc standard deviation
499                                 float sumSquared = 0.0;
500                                 for (int i = 0; i < thisLookUp.size(); i++) { sumSquared += ((thisLookUp[i]->getAbundance(j) - mean) * (thisLookUp[i]->getAbundance(j) - mean)); }
501                                 sumSquared /= (float) thisLookUp.size();
502                                 
503                                 float standardDev = sqrt(sumSquared);
504                                 
505                                 for (int i = 0; i < thisLookUp.size(); i++) {
506                                         float newNorm = 0.0;
507                                         if (standardDev != 0) { // stop divide by zero
508                                                 newNorm = (thisLookUp[i]->getAbundance(j) - mean) / standardDev;
509                                         }
510                                         thisLookUp[i]->set(j, newNorm, thisLookUp[i]->getGroup());
511                                 }
512                         }                       
513                         
514                 }else{ m->mothurOut(method + " is not a valid scaling option."); m->mothurOutEndLine(); m->control_pressed = true; return 0; }
515                 
516                 
517                 eliminateZeroOTUS(thisLookUp);
518                 
519                 for (int i = 0; i < thisLookUp.size(); i++) {
520                         out << thisLookUp[i]->getLabel() << '\t' << thisLookUp[i]->getGroup() << '\t';
521                         thisLookUp[i]->print(out);
522                 }
523                 
524                 return 0;
525         }
526         catch(exception& e) {
527                 m->errorOut(e, "NormalizeSharedCommand", "normalize");
528                 exit(1);
529         }
530 }
531 //**********************************************************************************************************************
532 int NormalizeSharedCommand::eliminateZeroOTUS(vector<SharedRAbundVector*>& thislookup) {
533         try {
534                 
535                 vector<SharedRAbundVector*> newLookup;
536                 for (int i = 0; i < thislookup.size(); i++) {
537                         SharedRAbundVector* temp = new SharedRAbundVector();
538                         temp->setLabel(thislookup[i]->getLabel());
539                         temp->setGroup(thislookup[i]->getGroup());
540                         newLookup.push_back(temp);
541                 }
542                 
543                 //for each bin
544                 for (int i = 0; i < thislookup[0]->getNumBins(); i++) {
545                         if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) {  delete newLookup[j];  } return 0; }
546                 
547                         //look at each sharedRabund and make sure they are not all zero
548                         bool allZero = true;
549                         for (int j = 0; j < thislookup.size(); j++) {
550                                 if (thislookup[j]->getAbundance(i) != 0) { allZero = false;  break;  }
551                         }
552                         
553                         //if they are not all zero add this bin
554                         if (!allZero) {
555                                 for (int j = 0; j < thislookup.size(); j++) {
556                                         newLookup[j]->push_back(thislookup[j]->getAbundance(i), thislookup[j]->getGroup());
557                                 }
558                         }
559                 }
560
561                 for (int j = 0; j < thislookup.size(); j++) {  delete thislookup[j];  }
562
563                 thislookup = newLookup;
564                 
565                 return 0;
566  
567         }
568         catch(exception& e) {
569                 m->errorOut(e, "NormalizeSharedCommand", "eliminateZeroOTUS");
570                 exit(1);
571         }
572 }
573 //**********************************************************************************************************************
574 int NormalizeSharedCommand::eliminateZeroOTUS(vector<SharedRAbundFloatVector*>& thislookup) {
575         try {
576                 
577                 vector<SharedRAbundFloatVector*> newLookup;
578                 for (int i = 0; i < thislookup.size(); i++) {
579                         SharedRAbundFloatVector* temp = new SharedRAbundFloatVector();
580                         temp->setLabel(thislookup[i]->getLabel());
581                         temp->setGroup(thislookup[i]->getGroup());
582                         newLookup.push_back(temp);
583                 }
584                 
585                 //for each bin
586                 for (int i = 0; i < thislookup[0]->getNumBins(); i++) {
587                         if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) {  delete newLookup[j];  } return 0; }
588                         
589                         //look at each sharedRabund and make sure they are not all zero
590                         bool allZero = true;
591                         for (int j = 0; j < thislookup.size(); j++) {
592                                 if (thislookup[j]->getAbundance(i) != 0) { allZero = false;  break;  }
593                         }
594                         
595                         //if they are not all zero add this bin
596                         if (!allZero) {
597                                 for (int j = 0; j < thislookup.size(); j++) {
598                                         newLookup[j]->push_back(thislookup[j]->getAbundance(i), thislookup[j]->getGroup());
599                                 }
600                         }
601                 }
602                 
603                 for (int j = 0; j < thislookup.size(); j++) {  delete thislookup[j];  }
604                 
605                 thislookup = newLookup;
606                 
607                 return 0;
608                 
609         }
610         catch(exception& e) {
611                 m->errorOut(e, "NormalizeSharedCommand", "eliminateZeroOTUS");
612                 exit(1);
613         }
614 }
615
616 //**********************************************************************************************************************