]> git.donarmstrong.com Git - mothur.git/blob - normalizesharedcommand.cpp
added set.current and get.current commands and modified existing commands to update...
[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                 //set shared file as new current sharedfile
385                 string current = "";
386                 itTypes = outputTypes.find("shared");
387                 if (itTypes != outputTypes.end()) {
388                         if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setSharedFile(current); }
389                 }
390                 
391                 return 0;
392         }
393         catch(exception& e) {
394                 m->errorOut(e, "NormalizeSharedCommand", "execute");
395                 exit(1);
396         }
397 }
398 //**********************************************************************************************************************
399
400 int NormalizeSharedCommand::normalize(vector<SharedRAbundVector*>& thisLookUp, ofstream& out){
401         try {
402                 if (pickedGroups) { eliminateZeroOTUS(thisLookUp); }
403                                 
404                 if (method == "totalgroup") { 
405                                         
406                         for (int j = 0; j < thisLookUp[0]->getNumBins(); j++) {
407                                                 
408                                         for (int i = 0; i < thisLookUp.size(); i++) {
409                                                         
410                                                 if (m->control_pressed) { return 0; }
411                                                         
412                                                 int abund = thisLookUp[i]->getAbundance(j);
413                                                         
414                                                 float relabund = abund / (float) thisLookUp[i]->getNumSeqs();
415                                                 float newNorm = relabund * norm;
416                                                 
417                                                 //round to nearest int
418                                                 int finalNorm = (int) floor((newNorm + 0.5));
419                                                 
420                                                 thisLookUp[i]->set(j, finalNorm, thisLookUp[i]->getGroup());
421                                         }
422                                 }
423                                         
424                 }else if (method == "zscore") {
425                         
426                         for (int j = 0; j < thisLookUp[0]->getNumBins(); j++) {
427                                 
428                                 if (m->control_pressed) { return 0; }
429                                 
430                                 //calc mean
431                                 float mean = 0.0;
432                                 for (int i = 0; i < thisLookUp.size(); i++) {  mean += thisLookUp[i]->getAbundance(j); }
433                                 mean /= (float) thisLookUp.size();
434                                         
435                                 //calc standard deviation
436                                 float sumSquared = 0.0;
437                                 for (int i = 0; i < thisLookUp.size(); i++) { sumSquared += (((float)thisLookUp[i]->getAbundance(j) - mean) * ((float)thisLookUp[i]->getAbundance(j) - mean)); }
438                                 sumSquared /= (float) thisLookUp.size();
439                                 
440                                 float standardDev = sqrt(sumSquared);
441                                         
442                                 for (int i = 0; i < thisLookUp.size(); i++) {
443                                         int finalNorm = 0;
444                                         if (standardDev != 0) { // stop divide by zero
445                                                 float newNorm = ((float)thisLookUp[i]->getAbundance(j) - mean) / standardDev;
446                                                 //round to nearest int
447                                                 finalNorm = (int) floor((newNorm + 0.5));
448                                         }
449                                         
450                                         thisLookUp[i]->set(j, finalNorm, thisLookUp[i]->getGroup());
451                                 }
452                         }
453                                                 
454                 }else{ m->mothurOut(method + " is not a valid scaling option."); m->mothurOutEndLine(); m->control_pressed = true; return 0; }
455                                 
456                                 
457                                                 
458                 eliminateZeroOTUS(thisLookUp);
459                  
460                 for (int i = 0; i < thisLookUp.size(); i++) {
461                         out << thisLookUp[i]->getLabel() << '\t' << thisLookUp[i]->getGroup() << '\t';
462                         thisLookUp[i]->print(out);
463                 }
464                 
465                 return 0;
466         }
467         catch(exception& e) {
468                 m->errorOut(e, "NormalizeSharedCommand", "normalize");
469                 exit(1);
470         }
471 }
472 //**********************************************************************************************************************
473
474 int NormalizeSharedCommand::normalize(vector<SharedRAbundFloatVector*>& thisLookUp, ofstream& out){
475         try {
476                 if (pickedGroups) { eliminateZeroOTUS(thisLookUp); }
477                 
478                 if (method == "totalgroup") { 
479                         
480                         for (int j = 0; j < thisLookUp[0]->getNumBins(); j++) {
481                                 
482                                 for (int i = 0; i < thisLookUp.size(); i++) {
483                                         
484                                         if (m->control_pressed) { return 0; }
485                                         
486                                         float abund = thisLookUp[i]->getAbundance(j);
487                                         
488                                         float relabund = abund / (float) thisLookUp[i]->getNumSeqs();
489                                         float newNorm = relabund * norm;
490                                         
491                                         thisLookUp[i]->set(j, newNorm, thisLookUp[i]->getGroup());
492                                 }
493                         }
494                         
495                 }else if (method == "zscore") {
496                         for (int j = 0; j < thisLookUp[0]->getNumBins(); j++) {
497                                 
498                                 if (m->control_pressed) { return 0; }
499                                 
500                                 //calc mean
501                                 float mean = 0.0;
502                                 for (int i = 0; i < thisLookUp.size(); i++) {  mean += thisLookUp[i]->getAbundance(j); }
503                                 mean /= (float) thisLookUp.size();
504                                 
505                                 //calc standard deviation
506                                 float sumSquared = 0.0;
507                                 for (int i = 0; i < thisLookUp.size(); i++) { sumSquared += ((thisLookUp[i]->getAbundance(j) - mean) * (thisLookUp[i]->getAbundance(j) - mean)); }
508                                 sumSquared /= (float) thisLookUp.size();
509                                 
510                                 float standardDev = sqrt(sumSquared);
511                                 
512                                 for (int i = 0; i < thisLookUp.size(); i++) {
513                                         float newNorm = 0.0;
514                                         if (standardDev != 0) { // stop divide by zero
515                                                 newNorm = (thisLookUp[i]->getAbundance(j) - mean) / standardDev;
516                                         }
517                                         thisLookUp[i]->set(j, newNorm, thisLookUp[i]->getGroup());
518                                 }
519                         }                       
520                         
521                 }else{ m->mothurOut(method + " is not a valid scaling option."); m->mothurOutEndLine(); m->control_pressed = true; return 0; }
522                 
523                 
524                 eliminateZeroOTUS(thisLookUp);
525                 
526                 for (int i = 0; i < thisLookUp.size(); i++) {
527                         out << thisLookUp[i]->getLabel() << '\t' << thisLookUp[i]->getGroup() << '\t';
528                         thisLookUp[i]->print(out);
529                 }
530                 
531                 return 0;
532         }
533         catch(exception& e) {
534                 m->errorOut(e, "NormalizeSharedCommand", "normalize");
535                 exit(1);
536         }
537 }
538 //**********************************************************************************************************************
539 int NormalizeSharedCommand::eliminateZeroOTUS(vector<SharedRAbundVector*>& thislookup) {
540         try {
541                 
542                 vector<SharedRAbundVector*> newLookup;
543                 for (int i = 0; i < thislookup.size(); i++) {
544                         SharedRAbundVector* temp = new SharedRAbundVector();
545                         temp->setLabel(thislookup[i]->getLabel());
546                         temp->setGroup(thislookup[i]->getGroup());
547                         newLookup.push_back(temp);
548                 }
549                 
550                 //for each bin
551                 for (int i = 0; i < thislookup[0]->getNumBins(); i++) {
552                         if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) {  delete newLookup[j];  } return 0; }
553                 
554                         //look at each sharedRabund and make sure they are not all zero
555                         bool allZero = true;
556                         for (int j = 0; j < thislookup.size(); j++) {
557                                 if (thislookup[j]->getAbundance(i) != 0) { allZero = false;  break;  }
558                         }
559                         
560                         //if they are not all zero add this bin
561                         if (!allZero) {
562                                 for (int j = 0; j < thislookup.size(); j++) {
563                                         newLookup[j]->push_back(thislookup[j]->getAbundance(i), thislookup[j]->getGroup());
564                                 }
565                         }
566                 }
567
568                 for (int j = 0; j < thislookup.size(); j++) {  delete thislookup[j];  }
569
570                 thislookup = newLookup;
571                 
572                 return 0;
573  
574         }
575         catch(exception& e) {
576                 m->errorOut(e, "NormalizeSharedCommand", "eliminateZeroOTUS");
577                 exit(1);
578         }
579 }
580 //**********************************************************************************************************************
581 int NormalizeSharedCommand::eliminateZeroOTUS(vector<SharedRAbundFloatVector*>& thislookup) {
582         try {
583                 
584                 vector<SharedRAbundFloatVector*> newLookup;
585                 for (int i = 0; i < thislookup.size(); i++) {
586                         SharedRAbundFloatVector* temp = new SharedRAbundFloatVector();
587                         temp->setLabel(thislookup[i]->getLabel());
588                         temp->setGroup(thislookup[i]->getGroup());
589                         newLookup.push_back(temp);
590                 }
591                 
592                 //for each bin
593                 for (int i = 0; i < thislookup[0]->getNumBins(); i++) {
594                         if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) {  delete newLookup[j];  } return 0; }
595                         
596                         //look at each sharedRabund and make sure they are not all zero
597                         bool allZero = true;
598                         for (int j = 0; j < thislookup.size(); j++) {
599                                 if (thislookup[j]->getAbundance(i) != 0) { allZero = false;  break;  }
600                         }
601                         
602                         //if they are not all zero add this bin
603                         if (!allZero) {
604                                 for (int j = 0; j < thislookup.size(); j++) {
605                                         newLookup[j]->push_back(thislookup[j]->getAbundance(i), thislookup[j]->getGroup());
606                                 }
607                         }
608                 }
609                 
610                 for (int j = 0; j < thislookup.size(); j++) {  delete thislookup[j];  }
611                 
612                 thislookup = newLookup;
613                 
614                 return 0;
615                 
616         }
617         catch(exception& e) {
618                 m->errorOut(e, "NormalizeSharedCommand", "eliminateZeroOTUS");
619                 exit(1);
620         }
621 }
622
623 //**********************************************************************************************************************