- mothurOut("The get.oturep command can only be executed after a successful read.dist command.\n");
- mothurOut("The get.oturep command parameters are list, fasta, name, group, large, sorted and label. The fasta and list parameters are required.\n");
- mothurOut("The label parameter allows you to select what distance levels you would like a output files created for, and is separated by dashes.\n");
- mothurOut("The get.oturep command should be in the following format: get.oturep(fasta=yourFastaFile, list=yourListFile, name=yourNamesFile, group=yourGroupFile, label=yourLabels).\n");
- mothurOut("Example get.oturep(fasta=amazon.fasta, list=amazon.fn.list, group=amazon.groups, name=amazon.names).\n");
- mothurOut("The default value for label is all labels in your inputfile.\n");
- mothurOut("The sorted parameter allows you to indicate you want the output sorted. You can sort by sequence name, bin number, bin size or group. The default is no sorting, but your options are name, number, size, or group.\n");
- mothurOut("The large parameter allows you to indicate that your distance matrix is too large to fit in RAM. The default value is false.\n");
- mothurOut("The get.oturep command outputs a .fastarep and .rep.names file for each distance you specify, selecting one OTU representative for each bin.\n");
- mothurOut("If you provide a groupfile, then it also appends the names of the groups present in that bin.\n");
- mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n");
+
+ if (abort == true) { if (calledHelp) { return 0; } return 2; }
+ int error;
+ list = NULL;
+
+ 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;