2 * removerarecommand.cpp
5 * Created by westcott on 1/21/11.
6 * Copyright 2011 Schloss Lab. All rights reserved.
10 #include "removerarecommand.h"
11 #include "sequence.hpp"
13 #include "sharedutilities.h"
14 #include "inputdata.h"
16 //**********************************************************************************************************************
17 vector<string> RemoveRareCommand::getValidParameters(){
19 string Array[] = {"rabund","sabund", "group", "list", "shared","bygroup","nseqs","groups","label","outputdir","inputdir"};
20 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
24 m->errorOut(e, "RemoveRareCommand", "getValidParameters");
28 //**********************************************************************************************************************
29 RemoveRareCommand::RemoveRareCommand(){
31 abort = true; calledHelp = true;
32 vector<string> tempOutNames;
33 outputTypes["rabund"] = tempOutNames;
34 outputTypes["sabund"] = tempOutNames;
35 outputTypes["list"] = tempOutNames;
36 outputTypes["group"] = tempOutNames;
37 outputTypes["shared"] = tempOutNames;
40 m->errorOut(e, "RemoveRareCommand", "RemoveRareCommand");
44 //**********************************************************************************************************************
45 vector<string> RemoveRareCommand::getRequiredParameters(){
47 string Array[] = {"nseqs"};
48 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
52 m->errorOut(e, "RemoveRareCommand", "getRequiredParameters");
56 //**********************************************************************************************************************
57 vector<string> RemoveRareCommand::getRequiredFiles(){
59 vector<string> myArray;
63 m->errorOut(e, "RemoveRareCommand", "getRequiredFiles");
67 //**********************************************************************************************************************
68 RemoveRareCommand::RemoveRareCommand(string option) {
70 globaldata = GlobalData::getInstance();
71 abort = false; calledHelp = false;
74 //allow user to run help
75 if(option == "help") { help(); abort = true; calledHelp = true; }
78 //valid paramters for this command
79 string Array[] = {"rabund","sabund", "group", "list", "shared", "bygroup", "nseqs","groups","label","outputdir","inputdir"};
80 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
82 OptionParser parser(option);
83 map<string,string> parameters = parser.getParameters();
85 ValidParameters validParameter;
86 map<string,string>::iterator it;
88 //check to make sure all parameters are valid for command
89 for (it = parameters.begin(); it != parameters.end(); it++) {
90 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
93 //initialize outputTypes
94 vector<string> tempOutNames;
95 outputTypes["rabund"] = tempOutNames;
96 outputTypes["sabund"] = tempOutNames;
97 outputTypes["list"] = tempOutNames;
98 outputTypes["group"] = tempOutNames;
99 outputTypes["shared"] = tempOutNames;
101 //if the user changes the output directory command factory will send this info to us in the output parameter
102 outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; }
104 //if the user changes the input directory command factory will send this info to us in the output parameter
105 string inputDir = validParameter.validFile(parameters, "inputdir", false);
106 if (inputDir == "not found"){ inputDir = ""; }
109 it = parameters.find("list");
110 //user has given a template file
111 if(it != parameters.end()){
112 path = m->hasPath(it->second);
113 //if the user has not given a path then, add inputdir. else leave path alone.
114 if (path == "") { parameters["list"] = inputDir + it->second; }
117 it = parameters.find("group");
118 //user has given a template file
119 if(it != parameters.end()){
120 path = m->hasPath(it->second);
121 //if the user has not given a path then, add inputdir. else leave path alone.
122 if (path == "") { parameters["group"] = inputDir + it->second; }
125 it = parameters.find("sabund");
126 //user has given a template file
127 if(it != parameters.end()){
128 path = m->hasPath(it->second);
129 //if the user has not given a path then, add inputdir. else leave path alone.
130 if (path == "") { parameters["sabund"] = inputDir + it->second; }
133 it = parameters.find("rabund");
134 //user has given a template file
135 if(it != parameters.end()){
136 path = m->hasPath(it->second);
137 //if the user has not given a path then, add inputdir. else leave path alone.
138 if (path == "") { parameters["rabund"] = inputDir + it->second; }
141 it = parameters.find("shared");
142 //user has given a template file
143 if(it != parameters.end()){
144 path = m->hasPath(it->second);
145 //if the user has not given a path then, add inputdir. else leave path alone.
146 if (path == "") { parameters["shared"] = inputDir + it->second; }
151 //check for file parameters
152 listfile = validParameter.validFile(parameters, "list", true);
153 if (listfile == "not open") { abort = true; }
154 else if (listfile == "not found") { listfile = ""; }
156 sabundfile = validParameter.validFile(parameters, "sabund", true);
157 if (sabundfile == "not open") { abort = true; }
158 else if (sabundfile == "not found") { sabundfile = ""; }
160 rabundfile = validParameter.validFile(parameters, "rabund", true);
161 if (rabundfile == "not open") { abort = true; }
162 else if (rabundfile == "not found") { rabundfile = ""; }
164 groupfile = validParameter.validFile(parameters, "group", true);
165 if (groupfile == "not open") { groupfile = ""; abort = true; }
166 else if (groupfile == "not found") { groupfile = ""; }
168 sharedfile = validParameter.validFile(parameters, "shared", true);
169 if (sharedfile == "not open") { sharedfile = ""; abort = true; }
170 else if (sharedfile == "not found") { sharedfile = ""; }
172 if ((sabundfile == "") && (rabundfile == "") && (sharedfile == "") && (listfile == "")) { m->mothurOut("You must provide at least one of the following: rabund, sabund, shared or list."); m->mothurOutEndLine(); abort = true; }
174 groups = validParameter.validFile(parameters, "groups", false);
175 if (groups == "not found") { groups = "all"; }
176 m->splitAtDash(groups, Groups);
178 label = validParameter.validFile(parameters, "label", false);
179 if (label == "not found") { label = ""; }
181 if(label != "all") { m->splitAtDash(label, labels); allLines = 0; }
182 else { allLines = 1; }
185 string temp = validParameter.validFile(parameters, "nseqs", false);
186 if (temp == "not found") { m->mothurOut("nseqs is a required parameter."); m->mothurOutEndLine(); abort = true; }
187 else { convert(temp, nseqs); }
189 temp = validParameter.validFile(parameters, "bygroup", false); if (temp == "not found") { temp = "f"; }
190 byGroup = m->isTrue(temp);
192 if (byGroup && (sharedfile == "")) { m->mothurOut("The byGroup parameter is only valid with a shared file."); m->mothurOutEndLine(); }
194 if ((groupfile != "") && (listfile == "")) { m->mothurOut("A groupfile is only valid with a list file."); m->mothurOutEndLine(); groupfile = ""; }
198 catch(exception& e) {
199 m->errorOut(e, "RemoveRareCommand", "RemoveRareCommand");
203 //**********************************************************************************************************************
205 void RemoveRareCommand::help(){
207 m->mothurOut("The remove.rare command parameters are list, rabund, sabund, shared, group, label, groups, bygroup and nseqs.\n");
208 m->mothurOut("The remove.rare command reads one of the following file types: list, rabund, sabund or shared file. It outputs a new file after removing the rare otus.\n");
209 m->mothurOut("The groups parameter allows you to specify which of the groups you would like analyzed. Default=all. You may separate group names with dashes.\n");
210 m->mothurOut("The label parameter is used to analyze specific labels in your input. default=all. You may separate label names with dashes.\n");
211 m->mothurOut("The bygroup parameter is only valid with the shared file. default=f, meaning remove any OTU that has nseqs or fewer sequences across all groups.\n");
212 m->mothurOut("bygroups=T means remove any OTU that has nseqs or fewer sequences in each group (if groupA has 1 sequence and group B has 100 sequences in OTUZ and nseqs=1, then set the groupA count for OTUZ to 0 and keep groupB's count at 100.) \n");
213 m->mothurOut("The nseqs parameter allows you to set the cutoff for an otu to be deemed rare. It is required.\n");
214 m->mothurOut("The remove.rare command should be in the following format: remove.rare(shared=yourSharedFile, nseqs=yourRareCutoff).\n");
215 m->mothurOut("Example remove.rare(shared=amazon.fn.shared, nseqs=2).\n");
216 m->mothurOut("Note: No spaces between parameter labels (i.e. shared), '=' and parameters (i.e.yourSharedFile).\n\n");
218 catch(exception& e) {
219 m->errorOut(e, "RemoveRareCommand", "help");
224 //**********************************************************************************************************************
226 int RemoveRareCommand::execute(){
229 if (abort == true) { if (calledHelp) { return 0; } return 2; }
231 if (m->control_pressed) { return 0; }
233 //read through the correct file and output lines you want to keep
234 if (sabundfile != "") { processSabund(); }
235 if (rabundfile != "") { processRabund(); }
236 if (listfile != "") { processList(); }
237 if (sharedfile != "") { processShared(); }
239 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
241 if (outputNames.size() != 0) {
242 m->mothurOutEndLine();
243 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
244 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
245 m->mothurOutEndLine();
251 catch(exception& e) {
252 m->errorOut(e, "RemoveRareCommand", "execute");
257 //**********************************************************************************************************************
258 int RemoveRareCommand::processList(){
260 string thisOutputDir = outputDir;
261 if (outputDir == "") { thisOutputDir += m->hasPath(listfile); }
262 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + "pick" + m->getExtension(listfile);
263 string outputGroupFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "pick" + m->getExtension(groupfile);
265 ofstream out, outGroup;
266 m->openOutputFile(outputFileName, out);
268 bool wroteSomething = false;
270 //you must provide a label because the names in the listfile need to be consistent
271 string thisLabel = "";
272 if (allLines) { m->mothurOut("For the listfile you must select one label, using first label in your listfile."); m->mothurOutEndLine(); }
273 else if (labels.size() > 1) { m->mothurOut("For the listfile you must select one label, using " + (*labels.begin()) + "."); m->mothurOutEndLine(); thisLabel = *labels.begin(); }
274 else { thisLabel = *labels.begin(); }
276 InputData input(listfile, "list");
277 ListVector* list = input.getListVector();
279 //get first one or the one we want
280 if (thisLabel != "") {
281 //use smart distancing
282 set<string> userLabels; userLabels.insert(thisLabel);
283 set<string> processedLabels;
284 string lastLabel = list->getLabel();
285 while((list != NULL) && (userLabels.size() != 0)) {
286 if(userLabels.count(list->getLabel()) == 1){
287 processedLabels.insert(list->getLabel());
288 userLabels.erase(list->getLabel());
292 if ((m->anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
293 processedLabels.insert(list->getLabel());
294 userLabels.erase(list->getLabel());
296 list = input.getListVector(lastLabel);
299 lastLabel = list->getLabel();
301 list = input.getListVector();
303 if (userLabels.size() != 0) {
304 m->mothurOut("Your file does not include the label " + thisLabel + ". I will use " + lastLabel + "."); m->mothurOutEndLine();
305 list = input.getListVector(lastLabel);
309 //if groupfile is given then use it
311 if (groupfile != "") {
312 groupMap = new GroupMap(groupfile); groupMap->readMap();
314 util.setGroups(Groups, groupMap->namesOfGroups);
315 m->openOutputFile(outputGroupFileName, outGroup);
320 //make a new list vector
322 newList.setLabel(list->getLabel());
325 for (int i = 0; i < list->getNumBins(); i++) {
326 if (m->control_pressed) { if (groupfile != "") { delete groupMap; outGroup.close(); remove(outputGroupFileName.c_str()); } out.close(); remove(outputFileName.c_str()); return 0; }
328 //parse out names that are in accnos file
329 string binnames = list->get(i);
330 vector<string> names;
331 string saveBinNames = binnames;
332 m->splitAtComma(binnames, names);
334 vector<string> newGroupFile;
335 if (groupfile != "") {
336 vector<string> newNames;
338 for(int k = 0; k < names.size(); k++) {
339 string group = groupMap->getGroup(names[k]);
341 if (m->inUsersGroups(group, Groups)) {
342 newGroupFile.push_back(names[k] + "\t" + group);
344 newNames.push_back(names[k]);
345 saveBinNames += names[k] + ",";
349 saveBinNames = saveBinNames.substr(0, saveBinNames.length()-1);
352 if (names.size() > nseqs) { //keep bin
353 newList.push_back(saveBinNames);
354 for(int k = 0; k < newGroupFile.size(); k++) { outGroup << newGroupFile[k] << endl; }
358 //print new listvector
359 if (newList.getNumBins() != 0) {
360 wroteSomething = true;
366 if (groupfile != "") { outGroup.close(); outputTypes["group"].push_back(outputGroupFileName); outputNames.push_back(outputGroupFileName); }
368 if (wroteSomething == false) { m->mothurOut("Your file contains only rare sequences."); m->mothurOutEndLine(); }
369 outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName);
373 catch(exception& e) {
374 m->errorOut(e, "RemoveRareCommand", "processList");
378 //**********************************************************************************************************************
379 int RemoveRareCommand::processSabund(){
381 string thisOutputDir = outputDir;
382 if (outputDir == "") { thisOutputDir += m->hasPath(sabundfile); }
383 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sabundfile)) + "pick" + m->getExtension(sabundfile);
384 outputTypes["sabund"].push_back(outputFileName); outputNames.push_back(outputFileName);
387 m->openOutputFile(outputFileName, out);
389 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
390 InputData input(sabundfile, "sabund");
391 SAbundVector* sabund = input.getSAbundVector();
392 string lastLabel = sabund->getLabel();
393 set<string> processedLabels;
394 set<string> userLabels = labels;
396 while((sabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
398 if (m->control_pressed) { delete sabund; out.close(); return 0; }
400 if(allLines == 1 || labels.count(sabund->getLabel()) == 1){
402 m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
403 processedLabels.insert(sabund->getLabel());
404 userLabels.erase(sabund->getLabel());
406 if (sabund->getMaxRank() > nseqs) {
407 for(int i = 1; i <=nseqs; i++) { sabund->set(i, 0); }
408 }else { sabund->clear(); }
410 if (sabund->getNumBins() > 0) { sabund->print(out); }
413 if ((m->anyLabelsToProcess(sabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
414 string saveLabel = sabund->getLabel();
417 sabund = input.getSAbundVector(lastLabel);
419 m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
420 processedLabels.insert(sabund->getLabel());
421 userLabels.erase(sabund->getLabel());
423 if (sabund->getMaxRank() > nseqs) {
424 for(int i = 1; i <=nseqs; i++) { sabund->set(i, 0); }
425 }else { sabund->clear(); }
427 if (sabund->getNumBins() > 0) { sabund->print(out); }
429 //restore real lastlabel to save below
430 sabund->setLabel(saveLabel);
433 lastLabel = sabund->getLabel();
436 sabund = input.getSAbundVector();
439 if (m->control_pressed) { out.close(); return 0; }
441 //output error messages about any remaining user labels
442 set<string>::iterator it;
443 bool needToRun = false;
444 for (it = userLabels.begin(); it != userLabels.end(); it++) {
445 m->mothurOut("Your file does not include the label " + *it);
446 if (processedLabels.count(lastLabel) != 1) {
447 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
450 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
454 //run last label if you need to
455 if (needToRun == true) {
456 if (sabund != NULL) { delete sabund; }
457 sabund = input.getSAbundVector(lastLabel);
459 m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
461 if (sabund->getMaxRank() > nseqs) {
462 for(int i = 1; i <=nseqs; i++) { sabund->set(i, 0); }
463 }else { sabund->clear(); }
465 if (sabund->getNumBins() > 0) { sabund->print(out); }
472 catch(exception& e) {
473 m->errorOut(e, "RemoveRareCommand", "processSabund");
477 //**********************************************************************************************************************
478 int RemoveRareCommand::processRabund(){
480 string thisOutputDir = outputDir;
481 if (outputDir == "") { thisOutputDir += m->hasPath(rabundfile); }
482 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(rabundfile)) + "pick" + m->getExtension(rabundfile);
483 outputTypes["rabund"].push_back(outputFileName); outputNames.push_back(outputFileName);
486 m->openOutputFile(outputFileName, out);
488 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
489 InputData input(rabundfile, "rabund");
490 RAbundVector* rabund = input.getRAbundVector();
491 string lastLabel = rabund->getLabel();
492 set<string> processedLabels;
493 set<string> userLabels = labels;
495 while((rabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
497 if (m->control_pressed) { delete rabund; out.close(); return 0; }
499 if(allLines == 1 || labels.count(rabund->getLabel()) == 1){
501 m->mothurOut(rabund->getLabel()); m->mothurOutEndLine();
502 processedLabels.insert(rabund->getLabel());
503 userLabels.erase(rabund->getLabel());
505 RAbundVector newRabund; newRabund.setLabel(rabund->getLabel());
506 for (int i = 0; i < rabund->getNumBins(); i++) {
507 if (rabund->get(i) > nseqs) {
508 newRabund.push_back(rabund->get(i));
511 if (newRabund.getNumBins() > 0) { newRabund.print(out); }
514 if ((m->anyLabelsToProcess(rabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
515 string saveLabel = rabund->getLabel();
518 rabund = input.getRAbundVector(lastLabel);
520 m->mothurOut(rabund->getLabel()); m->mothurOutEndLine();
521 processedLabels.insert(rabund->getLabel());
522 userLabels.erase(rabund->getLabel());
524 RAbundVector newRabund; newRabund.setLabel(rabund->getLabel());
525 for (int i = 0; i < rabund->getNumBins(); i++) {
526 if (rabund->get(i) > nseqs) {
527 newRabund.push_back(rabund->get(i));
530 if (newRabund.getNumBins() > 0) { newRabund.print(out); }
532 //restore real lastlabel to save below
533 rabund->setLabel(saveLabel);
536 lastLabel = rabund->getLabel();
539 rabund = input.getRAbundVector();
542 if (m->control_pressed) { out.close(); return 0; }
544 //output error messages about any remaining user labels
545 set<string>::iterator it;
546 bool needToRun = false;
547 for (it = userLabels.begin(); it != userLabels.end(); it++) {
548 m->mothurOut("Your file does not include the label " + *it);
549 if (processedLabels.count(lastLabel) != 1) {
550 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
553 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
557 //run last label if you need to
558 if (needToRun == true) {
559 if (rabund != NULL) { delete rabund; }
560 rabund = input.getRAbundVector(lastLabel);
562 m->mothurOut(rabund->getLabel()); m->mothurOutEndLine();
564 RAbundVector newRabund; newRabund.setLabel(rabund->getLabel());
565 for (int i = 0; i < rabund->getNumBins(); i++) {
566 if (rabund->get(i) > nseqs) {
567 newRabund.push_back(rabund->get(i));
570 if (newRabund.getNumBins() > 0) { newRabund.print(out); }
577 catch(exception& e) {
578 m->errorOut(e, "RemoveRareCommand", "processRabund");
582 //**********************************************************************************************************************
583 int RemoveRareCommand::processShared(){
585 globaldata->Groups = Groups;
587 string thisOutputDir = outputDir;
588 if (outputDir == "") { thisOutputDir += m->hasPath(sharedfile); }
589 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)) + "pick" + m->getExtension(sharedfile);
590 outputTypes["shared"].push_back(outputFileName); outputNames.push_back(outputFileName);
593 m->openOutputFile(outputFileName, out);
595 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
596 InputData input(sharedfile, "sharedfile");
597 vector<SharedRAbundVector*> lookup = input.getSharedRAbundVectors();
598 string lastLabel = lookup[0]->getLabel();
599 set<string> processedLabels;
600 set<string> userLabels = labels;
602 while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
604 if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } out.close(); return 0; }
606 if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){
608 m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
609 processedLabels.insert(lookup[0]->getLabel());
610 userLabels.erase(lookup[0]->getLabel());
612 processLookup(lookup, out);
615 if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
616 string saveLabel = lookup[0]->getLabel();
618 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
619 lookup = input.getSharedRAbundVectors(lastLabel);
621 m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
622 processedLabels.insert(lookup[0]->getLabel());
623 userLabels.erase(lookup[0]->getLabel());
625 processLookup(lookup, out);
627 //restore real lastlabel to save below
628 lookup[0]->setLabel(saveLabel);
631 lastLabel = lookup[0]->getLabel();
633 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
634 lookup = input.getSharedRAbundVectors();
637 if (m->control_pressed) { out.close(); return 0; }
639 //output error messages about any remaining user labels
640 set<string>::iterator it;
641 bool needToRun = false;
642 for (it = userLabels.begin(); it != userLabels.end(); it++) {
643 m->mothurOut("Your file does not include the label " + *it);
644 if (processedLabels.count(lastLabel) != 1) {
645 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
648 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
652 //run last label if you need to
653 if (needToRun == true) {
654 for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } }
655 lookup = input.getSharedRAbundVectors(lastLabel);
657 m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
659 processLookup(lookup, out);
661 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
666 catch(exception& e) {
667 m->errorOut(e, "RemoveRareCommand", "processSabund");
671 //**********************************************************************************************************************
672 int RemoveRareCommand::processLookup(vector<SharedRAbundVector*>& lookup, ofstream& out){
675 vector<SharedRAbundVector> newRabunds; newRabunds.resize(lookup.size());
676 for (int i = 0; i < lookup.size(); i++) {
677 newRabunds[i].setGroup(lookup[i]->getGroup());
678 newRabunds[i].setLabel(lookup[i]->getLabel());
684 for (int i = 0; i < lookup[0]->getNumBins(); i++) {
687 if (m->control_pressed) { return 0; }
690 for (int j = 0; j < lookup.size(); j++) {
693 if (lookup[j]->getAbundance(i) > nseqs) {
694 newRabunds[j].push_back(lookup[j]->getAbundance(i), newRabunds[j].getGroup());
697 newRabunds[j].push_back(0, newRabunds[j].getGroup());
701 //eliminates zero otus
702 if (allZero) { for (int j = 0; j < newRabunds.size(); j++) { newRabunds[j].pop_back(); } }
706 for (int i = 0; i < lookup[0]->getNumBins(); i++) {
708 if (m->control_pressed) { return 0; }
711 //get total otu abundance
712 for (int j = 0; j < lookup.size(); j++) {
713 newRabunds[j].push_back(lookup[j]->getAbundance(i), newRabunds[j].getGroup());
714 totalAbund += lookup[j]->getAbundance(i);
717 //eliminates otus below rare cutoff
718 if (totalAbund <= nseqs) { for (int j = 0; j < newRabunds.size(); j++) { newRabunds[j].pop_back(); } }
722 //do we have any otus above the rare cutoff
723 if (newRabunds[0].getNumBins() != 0) {
724 for (int j = 0; j < newRabunds.size(); j++) {
725 out << newRabunds[j].getLabel() << '\t' << newRabunds[j].getGroup() << '\t';
726 newRabunds[j].print(out);
732 catch(exception& e) {
733 m->errorOut(e, "RemoveRareCommand", "processLookup");
737 //**********************************************************************************************************************