+ if ( sharedfile != "") { runShared(); }
+ else {
+ m->setGroups(Groups);
+ groupMap = new GroupMap(groupfile);
+ int error = groupMap->readMap();
+ if (error == 1) { delete groupMap; return 0; }
+
+ if (m->control_pressed) { delete groupMap; return 0; }
+
+ if (Groups.size() == 0) {
+ Groups = groupMap->getNamesOfGroups();
+
+ //make string for outputfile name
+ userGroups = "unique.";
+ for(int i = 0; i < Groups.size(); i++) { userGroups += Groups[i] + "-"; }
+ userGroups = userGroups.substr(0, userGroups.length()-1);
+ }else{
+ //sanity check for group names
+ SharedUtil util;
+ vector<string> namesOfGroups = groupMap->getNamesOfGroups();
+ util.setGroups(Groups, namesOfGroups);
+ groupMap->setNamesOfGroups(namesOfGroups);
+ }
+
+ //put groups in map to find easier
+ for(int i = 0; i < Groups.size(); i++) {
+ groupFinder[Groups[i]] = Groups[i];
+ }
+
+ if (fastafile != "") {
+ ifstream inFasta;
+ m->openInputFile(fastafile, inFasta);
+
+ while(!inFasta.eof()) {
+ if (m->control_pressed) { outputTypes.clear(); inFasta.close(); delete groupMap; return 0; }
+
+ Sequence seq(inFasta); m->gobble(inFasta);
+ if (seq.getName() != "") { seqs.push_back(seq); }
+ }
+ inFasta.close();
+ }
+
+ ListVector* lastlist = NULL;
+ string lastLabel = "";
+
+ //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;
+
+ ifstream in;
+ m->openInputFile(listfile, in);
+
+ //as long as you are not at the end of the file or done wih the lines you want
+ while((!in.eof()) && ((allLines == 1) || (userLabels.size() != 0))) {
+
+ if (m->control_pressed) {
+ if (lastlist != NULL) { delete lastlist; }
+ for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear();
+ delete groupMap; return 0;
+ }
+
+ list = new ListVector(in);
+
+ if(allLines == 1 || labels.count(list->getLabel()) == 1){
+ m->mothurOut(list->getLabel());
+ process(list);
+
+ processedLabels.insert(list->getLabel());
+ userLabels.erase(list->getLabel());
+ }
+
+ if ((m->anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
+ string saveLabel = list->getLabel();
+
+ m->mothurOut(lastlist->getLabel());
+ process(lastlist);
+
+ processedLabels.insert(lastlist->getLabel());
+ userLabels.erase(lastlist->getLabel());
+
+ //restore real lastlabel to save below
+ list->setLabel(saveLabel);
+ }
+
+ lastLabel = list->getLabel();
+
+ if (lastlist != NULL) { delete lastlist; }
+ lastlist = list;
+ }
+
+ in.close();
+
+ //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) {
+ m->mothurOut(lastlist->getLabel());
+ process(lastlist);
+
+ processedLabels.insert(lastlist->getLabel());
+ userLabels.erase(lastlist->getLabel());
+ }
+
+
+ //reset groups parameter
+ m->clearGroups();
+
+ if (lastlist != NULL) { delete lastlist; }
+
+ if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } delete groupMap; return 0; }