TEST(Test_Container_SharedRabundVector, GetSabundVector) { vector<int> abunds(10, 5); SharedRAbundVector temp(abunds); EXPECT_EQ(temp.getNumBins(), 10); EXPECT_EQ(temp.getNumSeqs(), 50); EXPECT_EQ(temp.getMaxRank(), 5); SAbundVector sabund = temp.getSAbundVector(); EXPECT_EQ(sabund.getNumBins(), 10); EXPECT_EQ(sabund.getNumSeqs(), 50); EXPECT_EQ(sabund.getMaxRank(), 5); EXPECT_EQ(sabund.get(5), 10); }
int Rarefact::driver(RarefactionCurveData* rcd, int increment, int nIters = 1000){ try { for(int iter=0;iter<nIters;iter++){ for(int i=0;i<displays.size();i++){ displays[i]->init(label); } RAbundVector* lookup = new RAbundVector(order->getNumBins()); SAbundVector* rank = new SAbundVector(order->getMaxRank()+1); random_shuffle(order->begin(), order->end()); for(int i=0;i<numSeqs;i++){ if (m->control_pressed) { delete lookup; delete rank; delete rcd; return 0; } int binNumber = order->get(i); int abundance = lookup->get(binNumber); rank->set(abundance, rank->get(abundance)-1); abundance++; lookup->set(binNumber, abundance); rank->set(abundance, rank->get(abundance)+1); if((i == 0) || ((i+1) % increment == 0) || (ends.count(i+1) != 0)){ rcd->updateRankData(rank); } } if((numSeqs % increment != 0) || (ends.count(numSeqs) != 0)){ rcd->updateRankData(rank); } for(int i=0;i<displays.size();i++){ displays[i]->reset(); } delete lookup; delete rank; } return 0; } catch(exception& e) { m->errorOut(e, "Rarefact", "driver"); exit(1); } }
//********************************************************************************************************************** void MGClusterCommand::printData(ListVector* mergedList){ try { mergedList->print(listFile); mergedList->getRAbundVector().print(rabundFile); SAbundVector sabund = mergedList->getSAbundVector(); sabund.print(cout); sabund.print(sabundFile); } catch(exception& e) { m->errorOut(e, "MGClusterCommand", "printData"); exit(1); } }
int Collect::getCurve(float percentFreq = 0.01){ try { RAbundVector* lookup = new RAbundVector(order->getNumBins()); SAbundVector* rank = new SAbundVector(order->getMaxRank()+1); CollectorsCurveData* ccd = new CollectorsCurveData(); //sets displays label for(int i=0;i<displays.size();i++){ displays[i]->init(label); } ccd->registerDisplays(displays); //convert freq percentage to number int increment = 1; if (percentFreq < 1.0) { increment = numSeqs * percentFreq; } else { increment = percentFreq; } for(int i=0;i<numSeqs;i++){ if (m->getControl_pressed()) { delete lookup; delete rank; delete ccd; return 1; } int binNumber = order->get(i); int abundance = lookup->get(binNumber); rank->set(abundance, rank->get(abundance)-1); abundance++; lookup->set(binNumber, abundance); rank->set(abundance, rank->get(abundance)+1); //increment rank(abundance) if((i == 0) || (i+1) % increment == 0){ ccd->updateRankData(rank); } } if(numSeqs % increment != 0){ ccd->updateRankData(rank); } for(int i=0;i<displays.size();i++){ displays[i]->reset(); } delete lookup; delete rank; delete ccd; return 0; } catch(exception& e) { m->errorOut(e, "Collect", "getCurve"); exit(1); } }
//********************************************************************************************************************** vector<string> CatchAllCommand::parseSharedFile(string filename) { try { vector<string> filenames; //read first line InputData input(filename, "sharedfile"); vector<SharedRAbundVector*> lookup = input.getSharedRAbundVectors(); string sharedFileRoot = outputDir + m->getRootName(m->getSimpleName(filename)); //clears file before we start to write to it below for (int i=0; i<lookup.size(); i++) { m->mothurRemove((sharedFileRoot + lookup[i]->getGroup() + ".sabund")); filenames.push_back((sharedFileRoot + lookup[i]->getGroup() + ".sabund")); groups.push_back(lookup[i]->getGroup()); } while(lookup[0] != NULL) { for (int i = 0; i < lookup.size(); i++) { SAbundVector sav = lookup[i]->getSAbundVector(); ofstream out; m->openOutputFileAppend(sharedFileRoot + lookup[i]->getGroup() + ".sabund", out); sav.print(out); out.close(); } for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup = input.getSharedRAbundVectors(); } return filenames; } catch(exception& e) { m->errorOut(e, "CatchAllCommand", "parseSharedFile"); exit(1); } }
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); } }
//********************************************************************************************************************** int RemoveRareCommand::processSabund(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(sabundfile); } string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sabundfile)) + "pick" + m->getExtension(sabundfile); outputTypes["sabund"].push_back(outputFileName); outputNames.push_back(outputFileName); ofstream out; m->openOutputFile(outputFileName, out); //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. InputData input(sabundfile, "sabund"); SAbundVector* sabund = input.getSAbundVector(); string lastLabel = sabund->getLabel(); set<string> processedLabels; set<string> userLabels = labels; while((sabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { if (m->control_pressed) { delete sabund; out.close(); return 0; } if(allLines == 1 || labels.count(sabund->getLabel()) == 1){ m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); processedLabels.insert(sabund->getLabel()); userLabels.erase(sabund->getLabel()); if (sabund->getMaxRank() > nseqs) { for(int i = 1; i <=nseqs; i++) { sabund->set(i, 0); } }else { sabund->clear(); } if (sabund->getNumBins() > 0) { sabund->print(out); } } 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()); if (sabund->getMaxRank() > nseqs) { for(int i = 1; i <=nseqs; i++) { sabund->set(i, 0); } }else { sabund->clear(); } if (sabund->getNumBins() > 0) { sabund->print(out); } //restore real lastlabel to save below sabund->setLabel(saveLabel); } lastLabel = sabund->getLabel(); delete sabund; sabund = input.getSAbundVector(); } if (m->control_pressed) { out.close(); 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(); if (sabund->getMaxRank() > nseqs) { for(int i = 1; i <=nseqs; i++) { sabund->set(i, 0); } }else { sabund->clear(); } if (sabund->getNumBins() > 0) { sabund->print(out); } delete sabund; } return 0; } catch(exception& e) { m->errorOut(e, "RemoveRareCommand", "processSabund"); exit(1); } }
//********************************************************************************************************************** int GetSAbundCommand::processList(ofstream& out){ try { CountTable ct; ct.readTable(countfile, false); InputData input(inputfile, format); ListVector* 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) { delete list; return 0; } while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { if(allLines == 1 || labels.count(list->getLabel()) == 1){ m->mothurOut(list->getLabel()); m->mothurOutEndLine(); if (m->control_pressed) { delete list; return 0; } RAbundVector* rabund = new RAbundVector(); createRabund(ct, list, rabund); SAbundVector sabund = rabund->getSAbundVector(); sabund.print(out); delete rabund; 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()); m->mothurOutEndLine(); if (m->control_pressed) { delete list; return 0; } RAbundVector* rabund = new RAbundVector(); createRabund(ct, list, rabund); SAbundVector sabund = rabund->getSAbundVector(); sabund.print(out); delete rabund; 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 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 (list != NULL) { delete list; } list = input.getListVector(lastLabel); m->mothurOut(list->getLabel()); m->mothurOutEndLine(); if (m->control_pressed) { delete list; return 0; } RAbundVector* rabund = new RAbundVector(); createRabund(ct, list, rabund); SAbundVector sabund = rabund->getSAbundVector(); sabund.print(out); delete rabund; delete list; } return 0; } catch(exception& e) { m->errorOut(e, "GetSAbundCommand", "processList"); exit(1); } }
int GetSAbundCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } map<string, string> variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputfile)); filename = getOutputFileName("sabund", variables); m->openOutputFile(filename, out); if (countfile != "") { processList(out); }else { InputData input(inputfile, format); SAbundVector* sabund = input.getSAbundVector(); string lastLabel = sabund->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) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete sabund; return 0; } while((sabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { if(allLines == 1 || labels.count(sabund->getLabel()) == 1){ m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); sabund->print(out); if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); 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(); sabund->print(out); if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); 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(); sabund->print(out); delete sabund; if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); return 0; } } } out.close(); if (m->control_pressed) { outputTypes.clear(); m->mothurRemove(filename); return 0; } m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); m->mothurOut(filename); m->mothurOutEndLine(); outputNames.push_back(filename); outputTypes["sabund"].push_back(filename); m->mothurOutEndLine(); //set sabund file as new current sabundfile string current = ""; itTypes = outputTypes.find("sabund"); if (itTypes != outputTypes.end()) { if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setSabundFile(current); } } return 0; } catch(exception& e) { m->errorOut(e, "GetSAbundCommand", "execute"); exit(1); } }