+//**********************************************************************************************************************
+int GetRAbundCommand::processList(ofstream& out){
+ try {
+ CountTable ct;
+ ct.readTable(countfile, false);
+
+ InputData input(inputfile, format);
+ ListVector* list = input.getListVector();
+ string lastLabel = list->getLabel();
+
+ //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
+ set<string> processedLabels;
+ set<string> userLabels = labels;
+
+ if (m->control_pressed) { delete list; return 0; }
+
+ while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
+
+ if(allLines == 1 || labels.count(list->getLabel()) == 1){
+ m->mothurOut(list->getLabel()); m->mothurOutEndLine();
+
+ if (m->control_pressed) { delete list; return 0; }
+
+ RAbundVector* rabund = new RAbundVector();
+ createRabund(ct, list, rabund);
+
+ if(sorted) { rabund->print(out); }
+ else { rabund->nonSortedPrint(out); }
+
+ delete rabund;
+ processedLabels.insert(list->getLabel());
+ userLabels.erase(list->getLabel());
+ }
+
+ if ((m->anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
+ string saveLabel = list->getLabel();
+
+ delete list;
+ list = input.getListVector(lastLabel);
+
+ m->mothurOut(list->getLabel()); m->mothurOutEndLine();
+
+ if (m->control_pressed) { delete list; return 0; }
+
+ RAbundVector* rabund = new RAbundVector();
+ createRabund(ct, list, rabund);
+
+ if(sorted) { rabund->print(out); }
+ else { rabund->nonSortedPrint(out); }
+
+ delete rabund;
+ processedLabels.insert(list->getLabel());
+ userLabels.erase(list->getLabel());
+
+ //restore real lastlabel to save below
+ list->setLabel(saveLabel);
+ }
+
+ lastLabel = list->getLabel();
+
+ delete list;
+ list = input.getListVector();
+ }
+
+ //output error messages about any remaining user labels
+ set<string>::iterator it;
+ bool needToRun = false;
+ for (it = userLabels.begin(); it != userLabels.end(); it++) {
+ m->mothurOut("Your file does not include the label " + *it);
+ if (processedLabels.count(lastLabel) != 1) {
+ m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
+ needToRun = true;
+ }else {
+ m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
+ }
+ }
+
+ //run last label if you need to
+ if (needToRun == true) {
+ if (list != NULL) { delete list; }
+ list = input.getListVector(lastLabel);
+
+ m->mothurOut(list->getLabel()); m->mothurOutEndLine();
+
+ if (m->control_pressed) { delete list; return 0; }
+
+ RAbundVector* rabund = new RAbundVector();
+ createRabund(ct, list, rabund);
+
+ if(sorted) { rabund->print(out); }
+ else { rabund->nonSortedPrint(out); }
+
+ delete rabund;
+ delete list;
+ }
+
+ return 0;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "GetRAbundCommand", "processList");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+
+int GetRAbundCommand::createRabund(CountTable& ct, ListVector*& list, RAbundVector*& rabund){
+ try {
+
+ rabund->setLabel(list->getLabel());
+ for(int i = 0; i < list->getNumBins(); i++) {
+ if (m->control_pressed) { return 0; }
+ vector<string> binNames;
+ string bin = list->get(i);
+ m->splitAtComma(bin, binNames);
+ int total = 0;
+ for (int j = 0; j < binNames.size(); j++) {
+ total += ct.getNumSeqs(binNames[j]);
+ }
+ rabund->push_back(total);
+ }
+
+ return 0;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "GetRAbundCommand", "createRabund");
+ exit(1);
+ }
+
+}