+ if (method=="distance") {
+ readDist();
+ if ((!weighted) && (namefile != "")) { readNamesFile(weighted); }
+ }else {
+ //map name -> abundance for use if findRepAbund
+ if (namefile != "") { nameToIndex = m->readNames(namefile); }
+ }
+
+ if (m->control_pressed) { if (method=="distance") { if (large) { inRow.close(); m->mothurRemove(distFile); } }return 0; }
+
+ if (groupfile != "") {
+ //read in group map info.
+ groupMap = new GroupMap(groupfile);
+ int error = groupMap->readMap();
+ if (error == 1) { delete groupMap; m->mothurOut("Error reading your groupfile. Proceeding without groupfile."); m->mothurOutEndLine(); groupfile = ""; }
+
+ if (Groups.size() != 0) {
+ SharedUtil util;
+ vector<string> gNamesOfGroups = groupMap->getNamesOfGroups();
+ util.setGroups(Groups, gNamesOfGroups, "getoturep");
+ groupMap->setNamesOfGroups(gNamesOfGroups);
+ }
+ }else if (hasGroups) {
+ if (Groups.size() != 0) {
+ SharedUtil util;
+ vector<string> gNamesOfGroups = ct.getNamesOfGroups();
+ util.setGroups(Groups, gNamesOfGroups, "getoturep");
+ }
+ }
+
+ //done with listvector from matrix
+ if (list != NULL) { delete list; }
+
+ InputData input(listfile, "list");
+ 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) { if (method=="distance") { if (large) { inRow.close(); m->mothurRemove(distFile); } } delete list; return 0; }
+
+ while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
+
+ if (allLines == 1 || labels.count(list->getLabel()) == 1){
+ m->mothurOut(list->getLabel() + "\t" + toString(list->size())); m->mothurOutEndLine();
+ error = process(list);
+ if (error == 1) { return 0; } //there is an error in hte input files, abort command
+
+ if (m->control_pressed) {
+ if (method=="distance") { if (large) { inRow.close(); m->mothurRemove(distFile); } }
+ for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear();
+ delete list; return 0;
+ }
+
+ 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() + "\t" + toString(list->size())); m->mothurOutEndLine();
+ error = process(list);
+ if (error == 1) { return 0; } //there is an error in hte input files, abort command
+
+ if (m->control_pressed) {
+ if (method=="distance") { if (large) { inRow.close(); m->mothurRemove(distFile); } }
+ for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear();
+ delete list; return 0;
+ }
+
+ 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
+ bool needToRun = false;
+ for (set<string>::iterator 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() + "\t" + toString(list->size())); m->mothurOutEndLine();
+ error = process(list);
+ delete list;
+ if (error == 1) { return 0; } //there is an error in hte input files, abort command
+
+ if (m->control_pressed) {
+ if (method=="distance") { if (large) { inRow.close(); m->mothurRemove(distFile); } }
+ for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear();
+ delete list; return 0;
+ }
+ }
+
+ //close and remove formatted matrix file
+ if (method=="distance") { if (large) { inRow.close(); m->mothurRemove(distFile); } if (!weighted) { nameFileMap.clear(); } }
+
+ if (fastafile != "") {
+ //read fastafile
+ FastaMap* fasta = new FastaMap();
+ fasta->readFastaFile(fastafile);
+
+ //if user gave a namesfile then use it
+ if (namefile != "") { readNamesFile(fasta); }
+
+ //output create and output the .rep.fasta files
+ map<string, string>::iterator itNameFile;
+ for (itNameFile = outputNameFiles.begin(); itNameFile != outputNameFiles.end(); itNameFile++) {
+ processFastaNames(itNameFile->first, itNameFile->second, fasta);
+ }
+ delete fasta;
+ }else {
+ //output create and output the .rep.fasta files
+ map<string, string>::iterator itNameFile;
+ for (itNameFile = outputNameFiles.begin(); itNameFile != outputNameFiles.end(); itNameFile++) {
+ processNames(itNameFile->first, itNameFile->second);
+ }
+ }
+
+
+ if (groupfile != "") { delete groupMap; }
+
+ if (m->control_pressed) { return 0; }
+
+ //set fasta file as new current fastafile - use first one??
+ string current = "";
+ itTypes = outputTypes.find("fasta");
+ if (itTypes != outputTypes.end()) {
+ if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setFastaFile(current); }
+ }
+
+ itTypes = outputTypes.find("name");
+ if (itTypes != outputTypes.end()) {
+ if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setNameFile(current); }
+ }
+
+ itTypes = outputTypes.find("count");
+ if (itTypes != outputTypes.end()) {
+ if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setCountTableFile(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, "GetOTURepCommand", "execute");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+int GetOTURepCommand::readDist() {
+ try {
+
+ if (!large) {