+
+ designMap = new GroupMap(designfile);
+ designMap->readDesignMap();
+
+ if (groupfile != "") { processGroupFile(designMap); }
+ if (sharedfile != "") { processSharedFile(designMap); }
+
+ //reset groups parameter
+ m->clearGroups();
+ delete designMap;
+
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0;}
+
+
+ //set shared file as new current sharedfile
+ string current = "";
+ itTypes = outputTypes.find("shared");
+ if (itTypes != outputTypes.end()) {
+ if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setSharedFile(current); }
+ }
+
+ itTypes = outputTypes.find("group");
+ if (itTypes != outputTypes.end()) {
+ if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setGroupFile(current); }
+ }
+
+ m->mothurOutEndLine();
+ m->mothurOut("Output File Names: "); m->mothurOutEndLine();
+ for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
+ m->mothurOutEndLine();
+
+ return 0;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "MergeGroupsCommand", "execute");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+
+int MergeGroupsCommand::process(vector<SharedRAbundVector*>& thisLookUp, ofstream& out){
+ try {
+
+ map<string, SharedRAbundVector> merged;
+ map<string, SharedRAbundVector>::iterator it;
+
+ for (int i = 0; i < thisLookUp.size(); i++) {
+
+ if (m->control_pressed) { return 0; }
+
+ //what grouping does this group belong to
+ string grouping = designMap->getGroup(thisLookUp[i]->getGroup());
+ if (grouping == "not found") { m->mothurOut("[ERROR]: " + thisLookUp[i]->getGroup() + " is not in your design file. Ignoring!"); m->mothurOutEndLine(); grouping = "NOTFOUND"; }
+
+ else {
+ //do we already have a member of this grouping?
+ it = merged.find(grouping);
+
+ if (it == merged.end()) { //nope, so create it
+ merged[grouping] = *thisLookUp[i];
+ merged[grouping].setGroup(grouping);
+ }else { //yes, merge it
+
+ for (int j = 0; j < thisLookUp[i]->getNumBins(); j++) {
+ int abund = (it->second).getAbundance(j);
+ abund += thisLookUp[i]->getAbundance(j);
+
+ (it->second).set(j, abund, grouping);
+ }
+ }
+ }
+ }