示例#1
0
int SummaryCommand::execute() {
    try {

        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;
    }
    catch(exception& e) {
        m->errorOut(e, "SummaryCommand", "execute");
        exit(1);
    }
}
示例#2
0
int RareFactCommand::execute(){
	try {
	
		if (abort == true) { if (calledHelp) { return 0; }  return 2;	}
		
        map<string, set<int> > labelToEnds;
		if ((format != "sharedfile")) { inputFileNames.push_back(inputfile);  }
		else {  inputFileNames = parseSharedFile(sharedfile, labelToEnds);  format = "rabund"; }
        
        if (m->control_pressed) { return 0; }
		
		map<int, string> file2Group; //index in outputNames[i] -> group
		for (int p = 0; p < inputFileNames.size(); p++) {
			
			string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p]));
						
			if (m->control_pressed) {  outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) {	m->mothurRemove(outputNames[i]); 	}  m->clearGroups();  return 0; }
			
			if (inputFileNames.size() > 1) {
				m->mothurOutEndLine(); m->mothurOut("Processing group " + groups[p]); m->mothurOutEndLine(); m->mothurOutEndLine();
			}
			int i;
			ValidCalculators validCalculator;
			
            map<string, string> variables; 
            variables["[filename]"] = fileNameRoot;
			  
			for (i=0; i<Estimators.size(); i++) {
				if (validCalculator.isValidCalculator("rarefaction", Estimators[i]) == true) { 
					if (Estimators[i] == "sobs") { 
						rDisplays.push_back(new RareDisplay(new Sobs(), new ThreeColumnFile(getOutputFileName("rarefaction",variables))));
						outputNames.push_back(getOutputFileName("rarefaction",variables)); outputTypes["rarefaction"].push_back(getOutputFileName("rarefaction",variables));
					}else if (Estimators[i] == "chao") { 
						rDisplays.push_back(new RareDisplay(new Chao1(), new ThreeColumnFile(getOutputFileName("r_chao",variables))));
						outputNames.push_back(getOutputFileName("r_chao",variables)); outputTypes["r_chao"].push_back(getOutputFileName("r_chao",variables));
					}else if (Estimators[i] == "ace") { 
						if(abund < 5)
							abund = 10;
						rDisplays.push_back(new RareDisplay(new Ace(abund), new ThreeColumnFile(getOutputFileName("r_ace",variables))));
						outputNames.push_back(getOutputFileName("r_ace",variables)); outputTypes["r_ace"].push_back(getOutputFileName("r_ace",variables));
					}else if (Estimators[i] == "jack") { 
						rDisplays.push_back(new RareDisplay(new Jackknife(), new ThreeColumnFile(getOutputFileName("r_jack",variables))));
						outputNames.push_back(getOutputFileName("r_jack",variables)); outputTypes["r_jack"].push_back(getOutputFileName("r_jack",variables));
					}else if (Estimators[i] == "shannon") { 
						rDisplays.push_back(new RareDisplay(new Shannon(), new ThreeColumnFile(getOutputFileName("r_shannon",variables))));
						outputNames.push_back(getOutputFileName("r_shannon",variables)); outputTypes["r_shannon"].push_back(getOutputFileName("r_shannon",variables));
					}else if (Estimators[i] == "shannoneven") { 
						rDisplays.push_back(new RareDisplay(new ShannonEven(), new ThreeColumnFile(getOutputFileName("r_shannoneven",variables))));
						outputNames.push_back(getOutputFileName("r_shannoneven",variables)); outputTypes["r_shannoneven"].push_back(getOutputFileName("r_shannoneven",variables));
					}else if (Estimators[i] == "heip") { 
						rDisplays.push_back(new RareDisplay(new Heip(), new ThreeColumnFile(getOutputFileName("r_heip",variables))));
						outputNames.push_back(getOutputFileName("r_heip",variables)); outputTypes["r_heip"].push_back(getOutputFileName("r_heip",variables));
                    }else if (Estimators[i] == "r_shannonrange") {
                        rDisplays.push_back(new RareDisplay(new RangeShannon(alpha), new ThreeColumnFile(getOutputFileName("r_shannonrange", variables))));
                        outputNames.push_back(getOutputFileName("r_shannonrange", variables)); outputTypes["r_shannoneven"].push_back(getOutputFileName("r_shannonrange", variables));
					}else if (Estimators[i] == "smithwilson") {
						rDisplays.push_back(new RareDisplay(new SmithWilson(), new ThreeColumnFile(getOutputFileName("r_smithwilson",variables))));
						outputNames.push_back(getOutputFileName("r_smithwilson",variables)); outputTypes["r_smithwilson"].push_back(getOutputFileName("r_smithwilson",variables));
					}else if (Estimators[i] == "npshannon") { 
						rDisplays.push_back(new RareDisplay(new NPShannon(), new ThreeColumnFile(getOutputFileName("r_npshannon",variables))));
						outputNames.push_back(getOutputFileName("r_npshannon",variables)); outputTypes["r_npshannon"].push_back(getOutputFileName("r_npshannon",variables));
					}else if (Estimators[i] == "simpson") { 
						rDisplays.push_back(new RareDisplay(new Simpson(), new ThreeColumnFile(getOutputFileName("r_simpson",variables))));
						outputNames.push_back(getOutputFileName("r_simpson",variables)); outputTypes["r_simpson"].push_back(getOutputFileName("r_simpson",variables));
					}else if (Estimators[i] == "simpsoneven") { 
						rDisplays.push_back(new RareDisplay(new SimpsonEven(), new ThreeColumnFile(getOutputFileName("r_simpsoneven",variables))));
						outputNames.push_back(getOutputFileName("r_simpsoneven",variables)); outputTypes["r_simpsoneven"].push_back(getOutputFileName("r_simpsoneven",variables));
					}else if (Estimators[i] == "invsimpson") { 
						rDisplays.push_back(new RareDisplay(new InvSimpson(), new ThreeColumnFile(getOutputFileName("r_invsimpson",variables))));
						outputNames.push_back(getOutputFileName("r_invsimpson",variables)); outputTypes["r_invsimpson"].push_back(getOutputFileName("r_invsimpson",variables));
					}else if (Estimators[i] == "bootstrap") { 
						rDisplays.push_back(new RareDisplay(new Bootstrap(), new ThreeColumnFile(getOutputFileName("r_bootstrap",variables))));
						outputNames.push_back(getOutputFileName("r_bootstrap",variables)); outputTypes["r_bootstrap"].push_back(getOutputFileName("r_bootstrap",variables));
					}else if (Estimators[i] == "coverage") { 
						rDisplays.push_back(new RareDisplay(new Coverage(), new ThreeColumnFile(getOutputFileName("r_coverage",variables))));
						outputNames.push_back(getOutputFileName("r_coverage",variables)); outputTypes["r_coverage"].push_back(getOutputFileName("r_coverage",variables));
					}else if (Estimators[i] == "nseqs") { 
						rDisplays.push_back(new RareDisplay(new NSeqs(), new ThreeColumnFile(getOutputFileName("r_nseqs",variables))));
						outputNames.push_back(getOutputFileName("r_nseqs",variables)); outputTypes["r_nseqs"].push_back(getOutputFileName("r_nseqs",variables));
					}
                    if (inputFileNames.size() > 1) { file2Group[outputNames.size()-1] = groups[p]; }
				}
			}
			
			
			//if the users entered no valid calculators don't execute command
			if (rDisplays.size() == 0) { for(int i=0;i<rDisplays.size();i++){	delete rDisplays[i];	}  return 0; }
			
			input = new InputData(inputFileNames[p], format);			
			order = input->getOrderVector();
			string lastLabel = order->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) { for(int i=0;i<rDisplays.size();i++){	delete rDisplays[i];	}  delete input;  delete order;  for (int i = 0; i < outputNames.size(); i++) {	m->mothurRemove(outputNames[i]); } return 0; }
			
			//as long as you are not at the end of the file or done wih the lines you want
			while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
				
				if (m->control_pressed) { for(int i=0;i<rDisplays.size();i++){	delete rDisplays[i];	}  delete input;  delete order;  for (int i = 0; i < outputNames.size(); i++) {	m->mothurRemove(outputNames[i]); } return 0; }

				
				if(allLines == 1 || labels.count(order->getLabel()) == 1){
					
					m->mothurOut(order->getLabel()); m->mothurOutEndLine();
                    map<string, set<int> >::iterator itEndings = labelToEnds.find(order->getLabel());
                    set<int> ends;
                    if (itEndings != labelToEnds.end()) { ends = itEndings->second; }
					rCurve = new Rarefact(order, rDisplays, processors, ends);
					rCurve->getCurve(freq, nIters);
					delete rCurve;
					
					processedLabels.insert(order->getLabel());
					userLabels.erase(order->getLabel());
				}
				
				if ((m->anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
					string saveLabel = order->getLabel();
					
					delete order;
					order = (input->getOrderVector(lastLabel));
					
					m->mothurOut(order->getLabel()); m->mothurOutEndLine();
					map<string, set<int> >::iterator itEndings = labelToEnds.find(order->getLabel());
                    set<int> ends;
                    if (itEndings != labelToEnds.end()) { ends = itEndings->second; }
					rCurve = new Rarefact(order, rDisplays, processors, ends);

					rCurve->getCurve(freq, nIters);
					delete rCurve;
					
					processedLabels.insert(order->getLabel());
					userLabels.erase(order->getLabel());
					
					//restore real lastlabel to save below
					order->setLabel(saveLabel);
				}
				
				lastLabel = order->getLabel();		
				
				delete order;
				order = (input->getOrderVector());
			}
			
			if (m->control_pressed) { for(int i=0;i<rDisplays.size();i++){	delete rDisplays[i];	}  delete input;   for (int i = 0; i < outputNames.size(); i++) {	m->mothurRemove(outputNames[i]); } 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();
				}
			}
			
			if (m->control_pressed) { for(int i=0;i<rDisplays.size();i++){	delete rDisplays[i];	}  delete input;   for (int i = 0; i < outputNames.size(); i++) {	m->mothurRemove(outputNames[i]); } return 0; }

			//run last label if you need to
			if (needToRun == true)  {
				if (order != NULL) {	delete order;	}
				order = (input->getOrderVector(lastLabel));
				
				m->mothurOut(order->getLabel()); m->mothurOutEndLine();
				map<string, set<int> >::iterator itEndings = labelToEnds.find(order->getLabel());
                set<int> ends;
                if (itEndings != labelToEnds.end()) { ends = itEndings->second; }
                rCurve = new Rarefact(order, rDisplays, processors, ends);

				rCurve->getCurve(freq, nIters);
				delete rCurve;
				
				delete order;
			}
			
			
			for(int i=0;i<rDisplays.size();i++){	delete rDisplays[i];	}	
			rDisplays.clear();
			delete input;  
		}
		
		
		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)) {   outputNames = createGroupFile(outputNames, file2Group);  }

		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;
	}
	catch(exception& e) {
		m->errorOut(e, "RareFactCommand", "execute");
		exit(1);
	}
}
示例#3
0
int CatchAllCommand::execute() {	
	try {
		
		if (abort == true) { if (calledHelp) { return 0; }  return 2;	}
		
		//get location of catchall
		path = m->argv;
		path = path.substr(0, (path.find_last_of("othur")-5));
		path = m->getFullPathName(path);
		
        if (m->debug) { m->mothurOut("[DEBUG]: mothur's path = " + path + "\n"); }
       
		savedOutputDir = outputDir;
		string catchAllCommandExe = "";
        string catchAllTest = "";
        string programName = "";
		#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
			if (outputDir == "") { outputDir = "./"; } //force full pathname to be created for catchall, this is necessary because if catchall is in the path it will look for input file whereever the exe is and not the cwd.
            catchAllTest = path + "CatchAllcmdL.exe";
		#else
			if (outputDir == "") { outputDir = ".\\"; } //force full pathname to be created for catchall, this is necessary because if catchall is in the path it will look for input file whereever the exe is and not the cwd.
            catchAllTest = path + "CatchAllcmdW.exe";
		#endif
		
        //test to make sure formatdb exists
		ifstream in;
		catchAllTest = m->getFullPathName(catchAllTest);
		int ableToOpen = m->openInputFile(catchAllTest, in, "no error"); in.close();
		if(ableToOpen == 1) {	
            m->mothurOut(catchAllTest + " file does not exist. Checking path... \n");
            
            programName = "CatchAllcmdW.exe";
#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
            programName = "CatchAllcmdL.exe";
#endif
            string cLocation = m->findProgramPath(programName);
            
            ifstream in2;
            ableToOpen = m->openInputFile(cLocation, in2, "no error"); in2.close();

            if(ableToOpen == 1) {
                programName = "catchall";
                
                string cLocation = m->findProgramPath(programName);
                
                ifstream in3;
                ableToOpen = m->openInputFile(cLocation, in3, "no error"); in3.close();
                
                if(ableToOpen == 1) { m->mothurOut("[ERROR]: " + cLocation + " file does not exist. mothur requires the catchall executable."); m->mothurOutEndLine();  return 0; }else {  m->mothurOut("Found catchall in your path, using " + cLocation + "\n"); catchAllTest = cLocation; }
            }
            else {  m->mothurOut("Found catchall in your path, using " + cLocation + "\n"); catchAllTest = cLocation; }
        }
        catchAllTest = m->getFullPathName(catchAllTest);
        
#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
        if (programName == "catchall") { catchAllCommandExe += "catchall "; }
        else {  catchAllCommandExe += "mono \"" + catchAllTest + "\" ";  }
#else
        catchAllCommandExe += "\"" + catchAllTest + "\" ";
#endif
        
		//prepare full output directory
		outputDir = m->getFullPathName(outputDir);
		
        if (m->debug) { m->mothurOut("[DEBUG]: catchall location = " + catchAllCommandExe + "\n[DEBUG]: outputDir = " + outputDir + "\n"); }
        
		vector<string> inputFileNames;
		if (sharedfile != "") { inputFileNames = parseSharedFile(sharedfile);   }
		else {  inputFileNames.push_back(sabundfile);  }		
		
		for (int p = 0; p < inputFileNames.size(); p++) {
			if (inputFileNames.size() > 1) {
				m->mothurOutEndLine(); m->mothurOut("Processing group " + groups[p]); m->mothurOutEndLine(); m->mothurOutEndLine();
			}
			
			InputData input(inputFileNames[p], "sabund");
			SAbundVector* sabund = input.getSAbundVector();
			string lastLabel = sabund->getLabel();
							
			set<string> processedLabels;
			set<string> userLabels = labels;
			
            map<string, string> variables;
            variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p]));
			string summaryfilename = getOutputFileName("summary", variables);
			summaryfilename = m->getFullPathName(summaryfilename);
			
            if (m->debug) { m->mothurOut("[DEBUG]: Input File = " + inputFileNames[p] + ".\n[DEBUG]: inputdata address = " + toString(&input) + ".\n[DEBUG]: sabund address = " + toString(&sabund) + ".\n"); } 
            
			ofstream out;
			m->openOutputFile(summaryfilename, out);	
			
			out << "label\tmodel\testimate\tlci\tuci" << endl;
            
            if (m->debug) { string open = "no"; if (out.is_open()) { open = "yes"; } m->mothurOut("[DEBUG]: output stream is open = " + open + ".\n"); }
			
			//for each label the user selected
			while((sabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
				
						
				if(allLines == 1 || labels.count(sabund->getLabel()) == 1){
						m->mothurOut(sabund->getLabel());  m->mothurOutEndLine();
						
						//create catchall input file from mothur's inputfile
						string filename = process(sabund, inputFileNames[p]);
						string outputPath = m->getPathName(filename);
											
						//create system command
						string catchAllCommand = "";
						#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
							catchAllCommand += catchAllCommandExe + "\"" + filename + "\" \""  + outputPath + + "\" 1";
						#else
                            //removes extra '\\' catchall doesnt like that
                            vector<string> tempNames;
                            string tempFilename = filename;
                            m->splitAtDash(tempFilename, tempNames);
                            tempFilename = tempNames[0];
                            tempNames.clear();
                            string tempOutputPath = outputPath;
                            m->splitAtDash(tempOutputPath, tempNames);
                            tempOutputPath = tempNames[0];
                            if (tempOutputPath.length() > 0) { tempOutputPath = tempOutputPath.substr(0, tempOutputPath.length()-1); }
                            catchAllCommand += catchAllCommandExe + "\"" + tempFilename + "\" \""  + tempOutputPath + "\" 1";
                            catchAllCommand = "\"" + catchAllCommand + "\"";
						#endif
                        
                        if (m->debug) {  m->mothurOut("[DEBUG]: catchall command = " + catchAllCommand + ". About to call system.\n"); }
                    
						//run catchall
						system(catchAllCommand.c_str());
                    
                        if (m->debug) { m->mothurOut("[DEBUG]: back from system call. Keeping file: " + filename + ".\n"); }
                    
                        if (!m->debug) { m->mothurRemove(filename); }

					
						filename = m->getRootName(filename); filename = filename.substr(0, filename.length()-1); //rip off extra .
						if (savedOutputDir == "") { filename = m->getSimpleName(filename); }
					
                        variables["[filename]"] = filename;
						outputNames.push_back(getOutputFileName("analysis", variables)); outputTypes["analysis"].push_back(getOutputFileName("analysis", variables));
						outputNames.push_back(getOutputFileName("bestanalysis", variables)); outputTypes["bestanalysis"].push_back(getOutputFileName("bestanalysis", variables));
                        outputNames.push_back(getOutputFileName("models", variables)); outputTypes["models"].push_back(getOutputFileName("models", variables));
                        outputNames.push_back(getOutputFileName("bubble", variables)); outputTypes["bubble"].push_back(getOutputFileName("bubble", variables));
                        
                        if (m->debug) { m->mothurOut("[DEBUG]: About to create summary file for: " + filename + ".\n[DEBUG]: sabund label = " + sabund->getLabel() + ".\n"); }
                    
						createSummaryFile(filename + "_BestModelsAnalysis.csv", sabund->getLabel(), out);
                    
                        if (m->debug) { m->mothurOut("[DEBUG]: Done creating summary file.\n"); }
											
						if (m->control_pressed) { out.close(); for (int i = 0; i < outputNames.size(); i++) {m->mothurRemove(outputNames[i]);	}  delete sabund;  return 0; }

						processedLabels.insert(sabund->getLabel());
						userLabels.erase(sabund->getLabel());
				}
				
				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();
						

						//create catchall input file from mothur's inputfile
						string filename = process(sabund, inputFileNames[p]);
						string outputPath = m->getPathName(filename);
											
						//create system command
						string catchAllCommand = "";
						#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
                            catchAllCommand += catchAllCommandExe + "\"" + filename + "\" \""  + outputPath + + "\" 1";
						#else
                            //removes extra '\\' catchall doesnt like that
                            vector<string> tempNames;
                            string tempFilename = filename;
                            m->splitAtDash(tempFilename, tempNames);
                            tempFilename = tempNames[0];
                            tempNames.clear();
                            string tempOutputPath = outputPath;
                            m->splitAtDash(tempOutputPath, tempNames);
                            tempOutputPath = tempNames[0];
							if (tempOutputPath.length() > 0) { tempOutputPath = tempOutputPath.substr(0, tempOutputPath.length()-1); }
							catchAllCommand += catchAllCommandExe + "\"" + tempFilename + "\" \""  + tempOutputPath + "\" 1";
							catchAllCommand = "\"" + catchAllCommand + "\"";
						#endif
                        
                        if (m->debug) {  m->mothurOut("[DEBUG]: catchall command = " + catchAllCommand + ". About to call system.\n"); }
                    
						//run catchall
						system(catchAllCommand.c_str());
                    
                        if (m->debug) { m->mothurOut("[DEBUG]: back from system call. Keeping file: " + filename + ".\n"); }
                    
                        if (!m->debug) { m->mothurRemove(filename); }

					
						filename = m->getRootName(filename); filename = filename.substr(0, filename.length()-1); //rip off extra .
						if (savedOutputDir == "") { filename = m->getSimpleName(filename); }
					
                        variables["[filename]"] = filename;
                        outputNames.push_back(getOutputFileName("analysis", variables)); outputTypes["analysis"].push_back(getOutputFileName("analysis", variables));
                        outputNames.push_back(getOutputFileName("bestanalysis", variables)); outputTypes["bestanalysis"].push_back(getOutputFileName("bestanalysis", variables));
                        outputNames.push_back(getOutputFileName("models", variables)); outputTypes["models"].push_back(getOutputFileName("models", variables));
                        outputNames.push_back(getOutputFileName("bubble", variables)); outputTypes["bubble"].push_back(getOutputFileName("bubble", variables));
                        
                    
                        if (m->debug) { m->mothurOut("[DEBUG]: About to create summary file for: " + filename + ".\n[DEBUG]: sabund label = " + sabund->getLabel() + ".\n"); }
                    
						createSummaryFile(filename + "_BestModelsAnalysis.csv", sabund->getLabel(), out);
                    
                        if (m->debug) { m->mothurOut("[DEBUG]: Done creating summary file.\n"); }
					
						if (m->control_pressed) { out.close(); for (int i = 0; i < outputNames.size(); i++) {m->mothurRemove(outputNames[i]);	}   delete sabund;  return 0; }

						processedLabels.insert(sabund->getLabel());
						userLabels.erase(sabund->getLabel());
						
						//restore real lastlabel to save below
						sabund->setLabel(saveLabel);
				}
				
				
				lastLabel = sabund->getLabel();	
				
				delete sabund;		
				sabund = (input.getSAbundVector());
			}
			
			//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();
				
				//create catchall input file from mothur's inputfile
				string filename = process(sabund, inputFileNames[p]);
				string outputPath = m->getPathName(filename);
				
				//create system command
				string catchAllCommand = "";
				#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
                    catchAllCommand += catchAllCommandExe + "\"" + filename + "\" \""  + outputPath + + "\" 1";
				#else
                    //removes extra '\\' catchall doesnt like that
                    vector<string> tempNames;
                    string tempFilename = filename;
                    m->splitAtDash(tempFilename, tempNames);
                    tempFilename = tempNames[0];
                    tempNames.clear();
                    string tempOutputPath = outputPath;
                    m->splitAtDash(tempOutputPath, tempNames);
                    tempOutputPath = tempNames[0];
                    if (tempOutputPath.length() > 0) { tempOutputPath = tempOutputPath.substr(0, tempOutputPath.length()-1); }
                    catchAllCommand += catchAllCommandExe + "\"" + tempFilename + "\" \""  + tempOutputPath + "\" 1";
                    catchAllCommand = "\"" + catchAllCommand + "\"";
				#endif
                
                if (m->debug) {  m->mothurOut("[DEBUG]: catchall command = " + catchAllCommand + ". About to call system.\n"); }
				
				//run catchall
				system(catchAllCommand.c_str());
                
                if (m->debug) { m->mothurOut("[DEBUG]: back from system call. Keeping file: " + filename + ".\n"); }
				
				if (!m->debug) { m->mothurRemove(filename); }
				
				filename = m->getRootName(filename); filename = filename.substr(0, filename.length()-1); //rip off extra .
				if (savedOutputDir == "") { filename = m->getSimpleName(filename); }
				
				variables["[filename]"] = filename;
                outputNames.push_back(getOutputFileName("analysis", variables)); outputTypes["analysis"].push_back(getOutputFileName("analysis", variables));
                outputNames.push_back(getOutputFileName("bestanalysis", variables)); outputTypes["bestanalysis"].push_back(getOutputFileName("bestanalysis", variables));
                outputNames.push_back(getOutputFileName("models", variables)); outputTypes["models"].push_back(getOutputFileName("models", variables));
                outputNames.push_back(getOutputFileName("bubble", variables)); outputTypes["bubble"].push_back(getOutputFileName("bubble", variables));
                if (m->debug) { m->mothurOut("[DEBUG]: About to create summary file for: " + filename + ".\n[DEBUG]: sabund label = " + sabund->getLabel() + ".\n"); }
                
				createSummaryFile(filename + "_BestModelsAnalysis.csv", sabund->getLabel(), out);
                
                if (m->debug) { m->mothurOut("[DEBUG]: Done creating summary file.\n"); }
				
				delete sabund;
			}
			
			out.close();
			
			if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {m->mothurRemove(outputNames[i]);	} return 0; }
				
		}
		
		if (sharedfile == "") {  
			string summaryfilename = savedOutputDir + m->getRootName(m->getSimpleName(inputFileNames[0])) + "catchall.summary";
			summaryfilename = m->getFullPathName(summaryfilename);
			outputNames.push_back(summaryfilename); outputTypes["summary"].push_back(summaryfilename);
		}else { //combine summaries
			vector<string> sumNames;
			for (int i = 0; i < inputFileNames.size(); i++) {
				sumNames.push_back(m->getFullPathName(outputDir + m->getRootName(m->getSimpleName(inputFileNames[i])) + "catchall.summary"));
			}
			string summaryfilename = combineSummmary(sumNames);
			outputNames.push_back(summaryfilename); outputTypes["summary"].push_back(summaryfilename);
		}
		
		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, "CatchAllCommand", "execute");
		exit(1);
	}
}