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(){
32 //initialize outputTypes
33 vector<string> tempOutNames;
34 outputTypes["rabund"] = tempOutNames;
35 outputTypes["sabund"] = tempOutNames;
36 outputTypes["list"] = tempOutNames;
37 outputTypes["group"] = tempOutNames;
38 outputTypes["shared"] = tempOutNames;
41 m->errorOut(e, "RemoveRareCommand", "RemoveRareCommand");
45 //**********************************************************************************************************************
46 vector<string> RemoveRareCommand::getRequiredParameters(){
48 string Array[] = {"nseqs"};
49 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
53 m->errorOut(e, "RemoveRareCommand", "getRequiredParameters");
57 //**********************************************************************************************************************
58 vector<string> RemoveRareCommand::getRequiredFiles(){
60 vector<string> myArray;
64 m->errorOut(e, "RemoveRareCommand", "getRequiredFiles");
68 //**********************************************************************************************************************
69 RemoveRareCommand::RemoveRareCommand(string option) {
71 globaldata = GlobalData::getInstance();
75 //allow user to run help
76 if(option == "help") { help(); abort = true; }
79 //valid paramters for this command
80 string Array[] = {"rabund","sabund", "group", "list", "shared", "bygroup", "nseqs","groups","label","outputdir","inputdir"};
81 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
83 OptionParser parser(option);
84 map<string,string> parameters = parser.getParameters();
86 ValidParameters validParameter;
87 map<string,string>::iterator it;
89 //check to make sure all parameters are valid for command
90 for (it = parameters.begin(); it != parameters.end(); it++) {
91 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
94 //initialize outputTypes
95 vector<string> tempOutNames;
96 outputTypes["rabund"] = tempOutNames;
97 outputTypes["sabund"] = tempOutNames;
98 outputTypes["list"] = tempOutNames;
99 outputTypes["group"] = tempOutNames;
100 outputTypes["shared"] = tempOutNames;
102 //if the user changes the output directory command factory will send this info to us in the output parameter
103 outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; }
105 //if the user changes the input directory command factory will send this info to us in the output parameter
106 string inputDir = validParameter.validFile(parameters, "inputdir", false);
107 if (inputDir == "not found"){ inputDir = ""; }
110 it = parameters.find("list");
111 //user has given a template file
112 if(it != parameters.end()){
113 path = m->hasPath(it->second);
114 //if the user has not given a path then, add inputdir. else leave path alone.
115 if (path == "") { parameters["list"] = inputDir + it->second; }
118 it = parameters.find("group");
119 //user has given a template file
120 if(it != parameters.end()){
121 path = m->hasPath(it->second);
122 //if the user has not given a path then, add inputdir. else leave path alone.
123 if (path == "") { parameters["group"] = inputDir + it->second; }
126 it = parameters.find("sabund");
127 //user has given a template file
128 if(it != parameters.end()){
129 path = m->hasPath(it->second);
130 //if the user has not given a path then, add inputdir. else leave path alone.
131 if (path == "") { parameters["sabund"] = inputDir + it->second; }
134 it = parameters.find("rabund");
135 //user has given a template file
136 if(it != parameters.end()){
137 path = m->hasPath(it->second);
138 //if the user has not given a path then, add inputdir. else leave path alone.
139 if (path == "") { parameters["rabund"] = inputDir + it->second; }
142 it = parameters.find("shared");
143 //user has given a template file
144 if(it != parameters.end()){
145 path = m->hasPath(it->second);
146 //if the user has not given a path then, add inputdir. else leave path alone.
147 if (path == "") { parameters["shared"] = inputDir + it->second; }
152 //check for file parameters
153 listfile = validParameter.validFile(parameters, "list", true);
154 if (listfile == "not open") { abort = true; }
155 else if (listfile == "not found") { listfile = ""; }
157 sabundfile = validParameter.validFile(parameters, "sabund", true);
158 if (sabundfile == "not open") { abort = true; }
159 else if (sabundfile == "not found") { sabundfile = ""; }
161 rabundfile = validParameter.validFile(parameters, "rabund", true);
162 if (rabundfile == "not open") { abort = true; }
163 else if (rabundfile == "not found") { rabundfile = ""; }
165 groupfile = validParameter.validFile(parameters, "group", true);
166 if (groupfile == "not open") { groupfile = ""; abort = true; }
167 else if (groupfile == "not found") { groupfile = ""; }
169 sharedfile = validParameter.validFile(parameters, "shared", true);
170 if (sharedfile == "not open") { sharedfile = ""; abort = true; }
171 else if (sharedfile == "not found") { sharedfile = ""; }
173 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; }
175 groups = validParameter.validFile(parameters, "groups", false);
176 if (groups == "not found") { groups = "all"; }
177 m->splitAtDash(groups, Groups);
179 label = validParameter.validFile(parameters, "label", false);
180 if (label == "not found") { label = ""; }
182 if(label != "all") { m->splitAtDash(label, labels); allLines = 0; }
183 else { allLines = 1; }
186 string temp = validParameter.validFile(parameters, "nseqs", false);
187 if (temp == "not found") { m->mothurOut("nseqs is a required parameter."); m->mothurOutEndLine(); abort = true; }
188 else { convert(temp, nseqs); }
190 temp = validParameter.validFile(parameters, "bygroup", false); if (temp == "not found") { temp = "f"; }
191 byGroup = m->isTrue(temp);
193 if (byGroup && (sharedfile == "")) { m->mothurOut("The byGroup parameter is only valid with a shared file."); m->mothurOutEndLine(); }
195 if ((groupfile != "") && (listfile == "")) { m->mothurOut("A groupfile is only valid with a list file."); m->mothurOutEndLine(); groupfile = ""; }
199 catch(exception& e) {
200 m->errorOut(e, "RemoveRareCommand", "RemoveRareCommand");
204 //**********************************************************************************************************************
206 void RemoveRareCommand::help(){
208 m->mothurOut("The remove.rare command parameters are list, rabund, sabund, shared, group, label, groups, bygroup and nseqs.\n");
209 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");
210 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");
211 m->mothurOut("The label parameter is used to analyze specific labels in your input. default=all. You may separate label names with dashes.\n");
212 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");
213 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");
214 m->mothurOut("The nseqs parameter allows you to set the cutoff for an otu to be deemed rare. It is required.\n");
215 m->mothurOut("The remove.rare command should be in the following format: remove.rare(shared=yourSharedFile, nseqs=yourRareCutoff).\n");
216 m->mothurOut("Example remove.rare(shared=amazon.fn.shared, nseqs=2).\n");
217 m->mothurOut("Note: No spaces between parameter labels (i.e. shared), '=' and parameters (i.e.yourSharedFile).\n\n");
219 catch(exception& e) {
220 m->errorOut(e, "RemoveRareCommand", "help");
225 //**********************************************************************************************************************
227 int RemoveRareCommand::execute(){
230 if (abort == true) { return 0; }
232 if (m->control_pressed) { return 0; }
234 //read through the correct file and output lines you want to keep
235 if (sabundfile != "") { processSabund(); }
236 if (rabundfile != "") { processRabund(); }
237 if (listfile != "") { processList(); }
238 if (sharedfile != "") { processShared(); }
240 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
242 if (outputNames.size() != 0) {
243 m->mothurOutEndLine();
244 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
245 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
246 m->mothurOutEndLine();
252 catch(exception& e) {
253 m->errorOut(e, "RemoveRareCommand", "execute");
258 //**********************************************************************************************************************
259 int RemoveRareCommand::processList(){
261 string thisOutputDir = outputDir;
262 if (outputDir == "") { thisOutputDir += m->hasPath(listfile); }
263 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + "pick" + m->getExtension(listfile);
264 string outputGroupFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "pick" + m->getExtension(groupfile);
266 ofstream out, outGroup;
267 m->openOutputFile(outputFileName, out);
269 bool wroteSomething = false;
271 //you must provide a label because the names in the listfile need to be consistent
272 string thisLabel = "";
273 if (allLines) { m->mothurOut("For the listfile you must select one label, using first label in your listfile."); m->mothurOutEndLine(); }
274 else if (labels.size() > 1) { m->mothurOut("For the listfile you must select one label, using " + (*labels.begin()) + "."); m->mothurOutEndLine(); thisLabel = *labels.begin(); }
275 else { thisLabel = *labels.begin(); }
277 InputData input(listfile, "list");
278 ListVector* list = input.getListVector();
280 //get first one or the one we want
281 if (thisLabel != "") {
282 //use smart distancing
283 set<string> userLabels; userLabels.insert(thisLabel);
284 set<string> processedLabels;
285 string lastLabel = list->getLabel();
286 while((list != NULL) && (userLabels.size() != 0)) {
287 if(userLabels.count(list->getLabel()) == 1){
288 processedLabels.insert(list->getLabel());
289 userLabels.erase(list->getLabel());
293 if ((m->anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
294 processedLabels.insert(list->getLabel());
295 userLabels.erase(list->getLabel());
297 list = input.getListVector(lastLabel);
300 lastLabel = list->getLabel();
302 list = input.getListVector();
304 if (userLabels.size() != 0) {
305 m->mothurOut("Your file does not include the label " + thisLabel + ". I will use " + lastLabel + "."); m->mothurOutEndLine();
306 list = input.getListVector(lastLabel);
310 //if groupfile is given then use it
312 if (groupfile != "") {
313 groupMap = new GroupMap(groupfile); groupMap->readMap();
315 util.setGroups(Groups, groupMap->namesOfGroups);
316 m->openOutputFile(outputGroupFileName, outGroup);
321 //make a new list vector
323 newList.setLabel(list->getLabel());
326 for (int i = 0; i < list->getNumBins(); i++) {
327 if (m->control_pressed) { if (groupfile != "") { delete groupMap; outGroup.close(); remove(outputGroupFileName.c_str()); } out.close(); remove(outputFileName.c_str()); return 0; }
329 //parse out names that are in accnos file
330 string binnames = list->get(i);
331 vector<string> names;
332 string saveBinNames = binnames;
333 m->splitAtComma(binnames, names);
335 vector<string> newGroupFile;
336 if (groupfile != "") {
337 vector<string> newNames;
339 for(int k = 0; k < names.size(); k++) {
340 string group = groupMap->getGroup(names[k]);
342 if (m->inUsersGroups(group, Groups)) {
343 newGroupFile.push_back(names[k] + "\t" + group);
345 newNames.push_back(names[k]);
346 saveBinNames += names[k] + ",";
350 saveBinNames = saveBinNames.substr(0, saveBinNames.length()-1);
353 if (names.size() > nseqs) { //keep bin
354 newList.push_back(saveBinNames);
355 for(int k = 0; k < newGroupFile.size(); k++) { outGroup << newGroupFile[k] << endl; }
359 //print new listvector
360 if (newList.getNumBins() != 0) {
361 wroteSomething = true;
367 if (groupfile != "") { outGroup.close(); outputTypes["group"].push_back(outputGroupFileName); outputNames.push_back(outputGroupFileName); }
369 if (wroteSomething == false) { m->mothurOut("Your file contains only rare sequences."); m->mothurOutEndLine(); }
370 outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName);
374 catch(exception& e) {
375 m->errorOut(e, "RemoveRareCommand", "processList");
379 //**********************************************************************************************************************
380 int RemoveRareCommand::processSabund(){
382 string thisOutputDir = outputDir;
383 if (outputDir == "") { thisOutputDir += m->hasPath(sabundfile); }
384 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sabundfile)) + "pick" + m->getExtension(sabundfile);
385 outputTypes["sabund"].push_back(outputFileName); outputNames.push_back(outputFileName);
388 m->openOutputFile(outputFileName, out);
390 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
391 InputData input(sabundfile, "sabund");
392 SAbundVector* sabund = input.getSAbundVector();
393 string lastLabel = sabund->getLabel();
394 set<string> processedLabels;
395 set<string> userLabels = labels;
397 while((sabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
399 if (m->control_pressed) { delete sabund; out.close(); return 0; }
401 if(allLines == 1 || labels.count(sabund->getLabel()) == 1){
403 m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
404 processedLabels.insert(sabund->getLabel());
405 userLabels.erase(sabund->getLabel());
407 if (sabund->getMaxRank() > nseqs) {
408 for(int i = 1; i <=nseqs; i++) { sabund->set(i, 0); }
409 }else { sabund->clear(); }
411 if (sabund->getNumBins() > 0) { sabund->print(out); }
414 if ((m->anyLabelsToProcess(sabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
415 string saveLabel = sabund->getLabel();
418 sabund = input.getSAbundVector(lastLabel);
420 m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
421 processedLabels.insert(sabund->getLabel());
422 userLabels.erase(sabund->getLabel());
424 if (sabund->getMaxRank() > nseqs) {
425 for(int i = 1; i <=nseqs; i++) { sabund->set(i, 0); }
426 }else { sabund->clear(); }
428 if (sabund->getNumBins() > 0) { sabund->print(out); }
430 //restore real lastlabel to save below
431 sabund->setLabel(saveLabel);
434 lastLabel = sabund->getLabel();
437 sabund = input.getSAbundVector();
440 if (m->control_pressed) { out.close(); return 0; }
442 //output error messages about any remaining user labels
443 set<string>::iterator it;
444 bool needToRun = false;
445 for (it = userLabels.begin(); it != userLabels.end(); it++) {
446 m->mothurOut("Your file does not include the label " + *it);
447 if (processedLabels.count(lastLabel) != 1) {
448 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
451 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
455 //run last label if you need to
456 if (needToRun == true) {
457 if (sabund != NULL) { delete sabund; }
458 sabund = input.getSAbundVector(lastLabel);
460 m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
462 if (sabund->getMaxRank() > nseqs) {
463 for(int i = 1; i <=nseqs; i++) { sabund->set(i, 0); }
464 }else { sabund->clear(); }
466 if (sabund->getNumBins() > 0) { sabund->print(out); }
473 catch(exception& e) {
474 m->errorOut(e, "RemoveRareCommand", "processSabund");
478 //**********************************************************************************************************************
479 int RemoveRareCommand::processRabund(){
481 string thisOutputDir = outputDir;
482 if (outputDir == "") { thisOutputDir += m->hasPath(rabundfile); }
483 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(rabundfile)) + "pick" + m->getExtension(rabundfile);
484 outputTypes["rabund"].push_back(outputFileName); outputNames.push_back(outputFileName);
487 m->openOutputFile(outputFileName, out);
489 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
490 InputData input(rabundfile, "rabund");
491 RAbundVector* rabund = input.getRAbundVector();
492 string lastLabel = rabund->getLabel();
493 set<string> processedLabels;
494 set<string> userLabels = labels;
496 while((rabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
498 if (m->control_pressed) { delete rabund; out.close(); return 0; }
500 if(allLines == 1 || labels.count(rabund->getLabel()) == 1){
502 m->mothurOut(rabund->getLabel()); m->mothurOutEndLine();
503 processedLabels.insert(rabund->getLabel());
504 userLabels.erase(rabund->getLabel());
506 RAbundVector newRabund; newRabund.setLabel(rabund->getLabel());
507 for (int i = 0; i < rabund->getNumBins(); i++) {
508 if (rabund->get(i) > nseqs) {
509 newRabund.push_back(rabund->get(i));
512 if (newRabund.getNumBins() > 0) { newRabund.print(out); }
515 if ((m->anyLabelsToProcess(rabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
516 string saveLabel = rabund->getLabel();
519 rabund = input.getRAbundVector(lastLabel);
521 m->mothurOut(rabund->getLabel()); m->mothurOutEndLine();
522 processedLabels.insert(rabund->getLabel());
523 userLabels.erase(rabund->getLabel());
525 RAbundVector newRabund; newRabund.setLabel(rabund->getLabel());
526 for (int i = 0; i < rabund->getNumBins(); i++) {
527 if (rabund->get(i) > nseqs) {
528 newRabund.push_back(rabund->get(i));
531 if (newRabund.getNumBins() > 0) { newRabund.print(out); }
533 //restore real lastlabel to save below
534 rabund->setLabel(saveLabel);
537 lastLabel = rabund->getLabel();
540 rabund = input.getRAbundVector();
543 if (m->control_pressed) { out.close(); return 0; }
545 //output error messages about any remaining user labels
546 set<string>::iterator it;
547 bool needToRun = false;
548 for (it = userLabels.begin(); it != userLabels.end(); it++) {
549 m->mothurOut("Your file does not include the label " + *it);
550 if (processedLabels.count(lastLabel) != 1) {
551 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
554 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
558 //run last label if you need to
559 if (needToRun == true) {
560 if (rabund != NULL) { delete rabund; }
561 rabund = input.getRAbundVector(lastLabel);
563 m->mothurOut(rabund->getLabel()); m->mothurOutEndLine();
565 RAbundVector newRabund; newRabund.setLabel(rabund->getLabel());
566 for (int i = 0; i < rabund->getNumBins(); i++) {
567 if (rabund->get(i) > nseqs) {
568 newRabund.push_back(rabund->get(i));
571 if (newRabund.getNumBins() > 0) { newRabund.print(out); }
578 catch(exception& e) {
579 m->errorOut(e, "RemoveRareCommand", "processRabund");
583 //**********************************************************************************************************************
584 int RemoveRareCommand::processShared(){
586 globaldata->Groups = Groups;
588 string thisOutputDir = outputDir;
589 if (outputDir == "") { thisOutputDir += m->hasPath(sharedfile); }
590 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)) + "pick" + m->getExtension(sharedfile);
591 outputTypes["shared"].push_back(outputFileName); outputNames.push_back(outputFileName);
594 m->openOutputFile(outputFileName, out);
596 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
597 InputData input(sharedfile, "sharedfile");
598 vector<SharedRAbundVector*> lookup = input.getSharedRAbundVectors();
599 string lastLabel = lookup[0]->getLabel();
600 set<string> processedLabels;
601 set<string> userLabels = labels;
603 while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
605 if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } out.close(); return 0; }
607 if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){
609 m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
610 processedLabels.insert(lookup[0]->getLabel());
611 userLabels.erase(lookup[0]->getLabel());
613 processLookup(lookup, out);
616 if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
617 string saveLabel = lookup[0]->getLabel();
619 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
620 lookup = input.getSharedRAbundVectors(lastLabel);
622 m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
623 processedLabels.insert(lookup[0]->getLabel());
624 userLabels.erase(lookup[0]->getLabel());
626 processLookup(lookup, out);
628 //restore real lastlabel to save below
629 lookup[0]->setLabel(saveLabel);
632 lastLabel = lookup[0]->getLabel();
634 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
635 lookup = input.getSharedRAbundVectors();
638 if (m->control_pressed) { out.close(); return 0; }
640 //output error messages about any remaining user labels
641 set<string>::iterator it;
642 bool needToRun = false;
643 for (it = userLabels.begin(); it != userLabels.end(); it++) {
644 m->mothurOut("Your file does not include the label " + *it);
645 if (processedLabels.count(lastLabel) != 1) {
646 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
649 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
653 //run last label if you need to
654 if (needToRun == true) {
655 for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } }
656 lookup = input.getSharedRAbundVectors(lastLabel);
658 m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
660 processLookup(lookup, out);
662 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
667 catch(exception& e) {
668 m->errorOut(e, "RemoveRareCommand", "processSabund");
672 //**********************************************************************************************************************
673 int RemoveRareCommand::processLookup(vector<SharedRAbundVector*>& lookup, ofstream& out){
676 vector<SharedRAbundVector> newRabunds; newRabunds.resize(lookup.size());
677 for (int i = 0; i < lookup.size(); i++) {
678 newRabunds[i].setGroup(lookup[i]->getGroup());
679 newRabunds[i].setLabel(lookup[i]->getLabel());
685 for (int i = 0; i < lookup[0]->getNumBins(); i++) {
688 if (m->control_pressed) { return 0; }
691 for (int j = 0; j < lookup.size(); j++) {
694 if (lookup[j]->getAbundance(i) > nseqs) {
695 newRabunds[j].push_back(lookup[j]->getAbundance(i), newRabunds[j].getGroup());
698 newRabunds[j].push_back(0, newRabunds[j].getGroup());
702 //eliminates zero otus
703 if (allZero) { for (int j = 0; j < newRabunds.size(); j++) { newRabunds[j].pop_back(); } }
707 for (int i = 0; i < lookup[0]->getNumBins(); i++) {
709 if (m->control_pressed) { return 0; }
712 //get total otu abundance
713 for (int j = 0; j < lookup.size(); j++) {
714 newRabunds[j].push_back(lookup[j]->getAbundance(i), newRabunds[j].getGroup());
715 totalAbund += lookup[j]->getAbundance(i);
718 //eliminates otus below rare cutoff
719 if (totalAbund <= nseqs) { for (int j = 0; j < newRabunds.size(); j++) { newRabunds[j].pop_back(); } }
723 //do we have any otus above the rare cutoff
724 if (newRabunds[0].getNumBins() != 0) {
725 for (int j = 0; j < newRabunds.size(); j++) {
726 out << newRabunds[j].getLabel() << '\t' << newRabunds[j].getGroup() << '\t';
727 newRabunds[j].print(out);
733 catch(exception& e) {
734 m->errorOut(e, "RemoveRareCommand", "processLookup");
738 //**********************************************************************************************************************