//********************************************************************************************************************** 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 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 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); } }