+
+ if (abort == true) { if (calledHelp) { return 0; } return 2; }
+
+ if ((format != "sharedfile")) { inputFileNames.push_back(inputfile); }
+ else { inputFileNames = parseSharedFile(sharedfile); format = "rabund"; }
+
+ if (m->control_pressed) { return 0; }
+
+ int numLines = 0;
+ int numCols = 0;
+ map<string, string> groupIndex;
+
+ for (int p = 0; p < inputFileNames.size(); p++) {
+
+ numLines = 0;
+ numCols = 0;
+
+ map<string, string> variables;
+ variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p]));
+ string fileNameRoot = getOutputFileName("summary",variables);
+ variables["[tag]"] = "ave-std";
+ string fileNameAve = getOutputFileName("summary",variables);
+ outputNames.push_back(fileNameRoot); outputTypes["summary"].push_back(fileNameRoot);
+
+ if (inputFileNames.size() > 1) {
+ m->mothurOutEndLine(); m->mothurOut("Processing group " + groups[p]); m->mothurOutEndLine(); m->mothurOutEndLine();
+ groupIndex[fileNameRoot] = groups[p];
+ }
+
+ sumCalculators.clear();
+
+ ValidCalculators validCalculator;
+
+ for (int i=0; i<Estimators.size(); i++) {
+ if (validCalculator.isValidCalculator("summary", Estimators[i]) == true) {
+ if(Estimators[i] == "sobs"){
+ sumCalculators.push_back(new Sobs());
+ }else if(Estimators[i] == "chao"){
+ sumCalculators.push_back(new Chao1());
+ }else if(Estimators[i] == "coverage"){
+ sumCalculators.push_back(new Coverage());
+ }else if(Estimators[i] == "geometric"){
+ sumCalculators.push_back(new Geom());
+ }else if(Estimators[i] == "logseries"){
+ sumCalculators.push_back(new LogSD());
+ }else if(Estimators[i] == "qstat"){
+ sumCalculators.push_back(new QStat());
+ }else if(Estimators[i] == "bergerparker"){
+ sumCalculators.push_back(new BergerParker());
+ }else if(Estimators[i] == "bstick"){
+ sumCalculators.push_back(new BStick());
+ }else if(Estimators[i] == "ace"){
+ if(abund < 5)
+ abund = 10;
+ sumCalculators.push_back(new Ace(abund));
+ }else if(Estimators[i] == "jack"){
+ sumCalculators.push_back(new Jackknife());
+ }else if(Estimators[i] == "shannon"){
+ sumCalculators.push_back(new Shannon());
+ }else if(Estimators[i] == "shannoneven"){
+ sumCalculators.push_back(new ShannonEven());
+ }else if(Estimators[i] == "npshannon"){
+ sumCalculators.push_back(new NPShannon());
+ }else if(Estimators[i] == "heip"){
+ sumCalculators.push_back(new Heip());
+ }else if(Estimators[i] == "smithwilson"){
+ sumCalculators.push_back(new SmithWilson());
+ }else if(Estimators[i] == "simpson"){
+ sumCalculators.push_back(new Simpson());
+ }else if(Estimators[i] == "simpsoneven"){
+ sumCalculators.push_back(new SimpsonEven());
+ }else if(Estimators[i] == "invsimpson"){
+ sumCalculators.push_back(new InvSimpson());
+ }else if(Estimators[i] == "bootstrap"){
+ sumCalculators.push_back(new Bootstrap());
+ }else if (Estimators[i] == "nseqs") {
+ sumCalculators.push_back(new NSeqs());
+ }else if (Estimators[i] == "goodscoverage") {
+ sumCalculators.push_back(new GoodsCoverage());
+ }else if (Estimators[i] == "efron") {
+ sumCalculators.push_back(new Efron(size));
+ }else if (Estimators[i] == "boneh") {
+ sumCalculators.push_back(new Boneh(size));
+ }else if (Estimators[i] == "solow") {
+ sumCalculators.push_back(new Solow(size));
+ }else if (Estimators[i] == "shen") {
+ sumCalculators.push_back(new Shen(size, abund));
+ }
+ }
+ }
+
+ //if the users entered no valid calculators don't execute command
+ if (sumCalculators.size() == 0) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; }
+
+ ofstream outputFileHandle;
+ m->openOutputFile(fileNameRoot, outputFileHandle);
+ outputFileHandle << "label";
+
+ ofstream outAve;
+ if (subsample) {
+ m->openOutputFile(fileNameAve, outAve);
+ outputNames.push_back(fileNameAve); outputTypes["summary"].push_back(fileNameAve);
+ outAve << "label\tmethod";
+ outAve.setf(ios::fixed, ios::floatfield); outAve.setf(ios::showpoint);
+ if (inputFileNames.size() > 1) {
+ groupIndex[fileNameAve] = groups[p];
+ }
+ }
+
+ input = new InputData(inputFileNames[p], format);
+ sabund = input->getSAbundVector();
+ string lastLabel = sabund->getLabel();
+
+ for(int i=0;i<sumCalculators.size();i++){
+ if(sumCalculators[i]->getCols() == 1){
+ outputFileHandle << '\t' << sumCalculators[i]->getName();
+ if (subsample) { outAve << '\t' << sumCalculators[i]->getName(); }
+ numCols++;
+ }
+ else{
+ outputFileHandle << '\t' << sumCalculators[i]->getName() << "\t" << sumCalculators[i]->getName() << "_lci\t" << sumCalculators[i]->getName() << "_hci";
+ if (subsample) { outAve << '\t' << sumCalculators[i]->getName() << "\t" << sumCalculators[i]->getName() << "_lci\t" << sumCalculators[i]->getName() << "_hci"; }
+ numCols += 3;
+ }
+ }
+ outputFileHandle << endl;
+ if (subsample) { outAve << endl; }
+
+ //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) { outputFileHandle.close(); outAve.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; } delete sabund; delete input; return 0; }
+
+ while((sabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
+
+ if (m->control_pressed) { outputFileHandle.close(); outAve.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; } delete sabund; delete input; return 0; }
+
+ if(allLines == 1 || labels.count(sabund->getLabel()) == 1){
+
+ m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
+ processedLabels.insert(sabund->getLabel());
+ userLabels.erase(sabund->getLabel());
+
+ process(sabund, outputFileHandle, outAve);
+
+ if (m->control_pressed) { outputFileHandle.close(); outAve.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; } delete sabund; delete input; return 0; }
+ numLines++;
+ }
+
+ if ((m->anyLabelsToProcess(sabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
+ string saveLabel = sabund->getLabel();
+
+ delete sabund;
+ sabund = input->getSAbundVector(lastLabel);
+
+ m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
+ processedLabels.insert(sabund->getLabel());
+ userLabels.erase(sabund->getLabel());
+
+ process(sabund, outputFileHandle, outAve);
+
+ if (m->control_pressed) { outputFileHandle.close(); outAve.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; } delete sabund; delete input; return 0; }
+ numLines++;
+
+ //restore real lastlabel to save below
+ sabund->setLabel(saveLabel);
+ }
+
+ lastLabel = sabund->getLabel();
+
+ delete sabund;
+ sabund = input->getSAbundVector();
+ }
+
+ if (m->control_pressed) { outputFileHandle.close(); outAve.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; } delete input; return 0; }
+
+ //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 (sabund != NULL) { delete sabund; }
+ sabund = input->getSAbundVector(lastLabel);
+
+ m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
+ process(sabund, outputFileHandle, outAve);
+
+ if (m->control_pressed) { outputFileHandle.close(); outAve.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; } delete sabund; delete input; return 0; }
+ numLines++;
+ delete sabund;
+ }
+
+ outputFileHandle.close();
+ if (subsample) { outAve.close(); }
+
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; } delete input; return 0; }
+
+
+ delete input;
+ for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; }
+ }
+
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; }
+
+ //create summary file containing all the groups data for each label - this function just combines the info from the files already created.
+ if ((sharedfile != "") && (groupMode)) { vector<string> comboNames = createGroupSummaryFile(numLines, numCols, outputNames, groupIndex); for (int i = 0; i < comboNames.size(); i++) { outputNames.push_back(comboNames[i]); } }
+
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; }
+
+ 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;