X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=splitabundcommand.cpp;h=bc1cdb3ecfaa8ca528b88c2534e40c61263aacef;hb=0cefb55a2616975bd4a144fc345693695ffc9bb6;hp=aa47940a030f968e02686b915d26e84c29584b8d;hpb=7bf9a81bba76538ecaf351ae208de3da4bf1b6dd;p=mothur.git diff --git a/splitabundcommand.cpp b/splitabundcommand.cpp index aa47940..bc1cdb3 100644 --- a/splitabundcommand.cpp +++ b/splitabundcommand.cpp @@ -56,7 +56,30 @@ string SplitAbundCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string SplitAbundCommand::getOutputFileNameTag(string type, string inputName=""){ + try { + string outputFileName = ""; + map >::iterator it; + + //is this a type this command creates + it = outputTypes.find(type); + if (it == outputTypes.end()) { m->mothurOut("[ERROR]: this command doesn't create a " + type + " output file.\n"); } + else { + if (type == "fasta") { outputFileName = "fasta"; } + else if (type == "list") { outputFileName = "list"; } + else if (type == "name") { outputFileName = "names"; } + else if (type == "group") { outputFileName = "groups"; } + else if (type == "accnos") { outputFileName = "accnos"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true; } + } + return outputFileName; + } + catch(exception& e) { + m->errorOut(e, "SplitAbundCommand", "getOutputFileNameTag"); + exit(1); + } +} //********************************************************************************************************************** SplitAbundCommand::SplitAbundCommand(){ try { @@ -181,7 +204,7 @@ SplitAbundCommand::SplitAbundCommand(string option) { groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = ""; } else if (groups == "all") { - if (groupfile != "") { Groups = groupMap->namesOfGroups; } + if (groupfile != "") { Groups = groupMap->getNamesOfGroups(); } else { m->mothurOut("You cannot select groups without a valid groupfile, I will disregard your groups selection. "); m->mothurOutEndLine(); groups = ""; } }else { m->splitAtDash(groups, Groups); @@ -213,10 +236,9 @@ SplitAbundCommand::SplitAbundCommand(string option) { accnos = m->isTrue(temp); temp = validParameter.validFile(parameters, "cutoff", false); if (temp == "not found") { temp = "0"; } - convert(temp, cutoff); + m->mothurConvert(temp, cutoff); if (cutoff == 0) { m->mothurOut("You must provide a cutoff to qualify what is abundant for the split.abund command. "); m->mothurOutEndLine(); abort = true; } - } } @@ -250,11 +272,11 @@ int SplitAbundCommand::execute(){ if (namefile != "") { readNamesFile(); } else { createNameMap(list); } - if (m->control_pressed) { delete input; delete list; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { delete input; delete list; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { delete input; delete list; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { delete input; delete list; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } if(allLines == 1 || labels.count(list->getLabel()) == 1){ @@ -288,7 +310,7 @@ int SplitAbundCommand::execute(){ list = input->getListVector(); //get new list vector to process } - if (m->control_pressed) { delete input; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { 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::iterator it; @@ -304,7 +326,7 @@ int SplitAbundCommand::execute(){ } - if (m->control_pressed) { delete input; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { 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) { @@ -319,7 +341,7 @@ int SplitAbundCommand::execute(){ delete input; - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } }else { //you are using the namefile to determine abundance if (outputDir == "") { outputDir = m->hasPath(namefile); } @@ -435,11 +457,11 @@ int SplitAbundCommand::writeList(ListVector* thisList, string tag) { ofstream aout; ofstream rout; - string rare = outputDir + m->getRootName(m->getSimpleName(listfile)) + tag + "rare.list"; + string rare = outputDir + m->getRootName(m->getSimpleName(listfile)) + tag + "rare." + getOutputFileNameTag("list"); m->openOutputFile(rare, rout); outputNames.push_back(rare); outputTypes["list"].push_back(rare); - string abund = outputDir + m->getRootName(m->getSimpleName(listfile)) + tag + "abund.list"; + string abund = outputDir + m->getRootName(m->getSimpleName(listfile)) + tag + "abund." + getOutputFileNameTag("list"); m->openOutputFile(abund, aout); outputNames.push_back(abund); outputTypes["list"].push_back(abund); @@ -477,10 +499,12 @@ int SplitAbundCommand::writeList(ListVector* thisList, string tag) { temp2 = new ofstream; filehandles[Groups[i]+".abund"] = temp2; - m->openOutputFile(fileroot + Groups[i] + tag + ".rare.list", *(filehandles[Groups[i]+".rare"])); - m->openOutputFile(fileroot + Groups[i] + tag + ".abund.list", *(filehandles[Groups[i]+".abund"])); - outputNames.push_back(fileroot + Groups[i] + tag + ".rare.list"); outputTypes["list"].push_back(fileroot + Groups[i] + tag + ".rare.list"); - outputNames.push_back(fileroot + Groups[i] + tag + ".abund.list"); outputTypes["list"].push_back(fileroot + Groups[i] + tag + ".abund.list"); + string rareGroupFileName = fileroot + Groups[i] + tag + ".rare." + getOutputFileNameTag("list"); + string abundGroupFileName = fileroot + Groups[i] + tag + ".abund." + getOutputFileNameTag("list"); + m->openOutputFile(rareGroupFileName, *(filehandles[Groups[i]+".rare"])); + m->openOutputFile(abundGroupFileName, *(filehandles[Groups[i]+".abund"])); + outputNames.push_back(rareGroupFileName); outputTypes["list"].push_back(rareGroupFileName); + outputNames.push_back(abundGroupFileName); outputTypes["list"].push_back(abundGroupFileName); } map groupVector; @@ -643,11 +667,11 @@ int SplitAbundCommand::writeNames() { //namefile ofstream aout; ofstream rout; - string rare = outputDir + m->getRootName(m->getSimpleName(namefile)) + "rare.names"; + string rare = outputDir + m->getRootName(m->getSimpleName(namefile)) + "rare." + getOutputFileNameTag("name"); m->openOutputFile(rare, rout); outputNames.push_back(rare); outputTypes["name"].push_back(rare); - string abund = outputDir + m->getRootName(m->getSimpleName(namefile)) + "abund.names"; + string abund = outputDir + m->getRootName(m->getSimpleName(namefile)) + "abund." + getOutputFileNameTag("name"); m->openOutputFile(abund, aout); outputNames.push_back(abund); outputTypes["name"].push_back(abund); @@ -678,8 +702,10 @@ int SplitAbundCommand::writeNames() { //namefile temp2 = new ofstream; filehandles[Groups[i]+".abund"] = temp2; - m->openOutputFile(fileroot + Groups[i] + ".rare.names", *(filehandles[Groups[i]+".rare"])); - m->openOutputFile(fileroot + Groups[i] + ".abund.names", *(filehandles[Groups[i]+".abund"])); + string rareGroupFileName = fileroot + Groups[i] + ".rare." + getOutputFileNameTag("name"); + string abundGroupFileName = fileroot + Groups[i] + ".abund." + getOutputFileNameTag("name"); + m->openOutputFile(rareGroupFileName, *(filehandles[Groups[i]+".rare"])); + m->openOutputFile(abundGroupFileName, *(filehandles[Groups[i]+".abund"])); } for (map::iterator itName = nameMap.begin(); itName != nameMap.end(); itName++) { @@ -715,7 +741,7 @@ int SplitAbundCommand::writeNames() { //namefile for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { (*(filehandles[it3->first])).close(); - outputNames.push_back(fileroot + it3->first + ".names"); outputTypes["name"].push_back(fileroot + it3->first + ".names"); + outputNames.push_back(fileroot + it3->first + "." + getOutputFileNameTag("name")); outputTypes["name"].push_back(fileroot + it3->first + "." + getOutputFileNameTag("name")); delete it3->second; } } @@ -740,7 +766,7 @@ int SplitAbundCommand::writeAccnos(string tag) { ofstream rout; - string rare = outputDir + m->getRootName(m->getSimpleName(inputFile)) + tag + "rare.accnos"; + string rare = outputDir + m->getRootName(m->getSimpleName(inputFile)) + tag + "rare." + getOutputFileNameTag("accnos"); m->openOutputFile(rare, rout); outputNames.push_back(rare); outputTypes["accnos"].push_back(rare); @@ -749,7 +775,7 @@ int SplitAbundCommand::writeAccnos(string tag) { } rout.close(); - string abund = outputDir + m->getRootName(m->getSimpleName(inputFile)) + tag + "abund.accnos"; + string abund = outputDir + m->getRootName(m->getSimpleName(inputFile)) + tag + "abund." + getOutputFileNameTag("accnos"); m->openOutputFile(abund, aout); outputNames.push_back(abund); outputTypes["accnos"].push_back(abund); @@ -771,8 +797,8 @@ int SplitAbundCommand::writeAccnos(string tag) { temp2 = new ofstream; filehandles[Groups[i]+".abund"] = temp2; - m->openOutputFile(fileroot + tag + Groups[i] + ".rare.accnos", *(filehandles[Groups[i]+".rare"])); - m->openOutputFile(fileroot + tag + Groups[i] + ".abund.accnos", *(filehandles[Groups[i]+".abund"])); + m->openOutputFile(fileroot + tag + Groups[i] + ".rare." + getOutputFileNameTag("accnos"), *(filehandles[Groups[i]+".rare"])); + m->openOutputFile(fileroot + tag + Groups[i] + ".abund." + getOutputFileNameTag("accnos"), *(filehandles[Groups[i]+".abund"])); } //write rare @@ -796,7 +822,7 @@ int SplitAbundCommand::writeAccnos(string tag) { //close files for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { (*(filehandles[it3->first])).close(); - outputNames.push_back(fileroot + tag + it3->first + ".accnos"); outputTypes["accnos"].push_back(fileroot + tag + it3->first + ".accnos"); + outputNames.push_back(fileroot + tag + it3->first + "." + getOutputFileNameTag("accnos")); outputTypes["accnos"].push_back(fileroot + tag + it3->first + "." + getOutputFileNameTag("accnos")); delete it3->second; } } @@ -819,11 +845,12 @@ int SplitAbundCommand::parseGroup(string tag) { //namefile ofstream aout; ofstream rout; - string rare = outputDir + m->getRootName(m->getSimpleName(groupfile)) + tag + "rare.groups"; + string rare = outputDir + m->getRootName(m->getSimpleName(groupfile)) + tag + "rare." + getOutputFileNameTag("group"); m->openOutputFile(rare, rout); outputNames.push_back(rare); outputTypes["group"].push_back(rare); - string abund = outputDir + m->getRootName(m->getSimpleName(groupfile)) + tag + "abund.groups"; + string abund = outputDir + m->getRootName(m->getSimpleName(groupfile)) + tag + "abund." + getOutputFileNameTag("group"); +; m->openOutputFile(abund, aout); outputNames.push_back(abund); outputTypes["group"].push_back(abund); @@ -863,8 +890,8 @@ int SplitAbundCommand::parseGroup(string tag) { //namefile temp2 = new ofstream; filehandles[Groups[i]+".abund"] = temp2; - m->openOutputFile(fileroot + tag + Groups[i] + ".rare.groups", *(filehandles[Groups[i]+".rare"])); - m->openOutputFile(fileroot + tag + Groups[i] + ".abund.groups", *(filehandles[Groups[i]+".abund"])); + m->openOutputFile(fileroot + tag + Groups[i] + ".rare." + getOutputFileNameTag("group"), *(filehandles[Groups[i]+".rare"])); + m->openOutputFile(fileroot + tag + Groups[i] + ".abund." + getOutputFileNameTag("group"), *(filehandles[Groups[i]+".abund"])); } for (map::iterator itName = nameMap.begin(); itName != nameMap.end(); itName++) { @@ -890,7 +917,7 @@ int SplitAbundCommand::parseGroup(string tag) { //namefile for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { (*(filehandles[it3->first])).close(); - outputNames.push_back(fileroot + tag + it3->first + ".groups"); outputTypes["group"].push_back(fileroot + tag + it3->first + ".groups"); + outputNames.push_back(fileroot + tag + it3->first + "." + getOutputFileNameTag("group")); outputTypes["group"].push_back(fileroot + tag + it3->first + "." + getOutputFileNameTag("group")); delete it3->second; } } @@ -913,11 +940,11 @@ int SplitAbundCommand::parseFasta(string tag) { //namefile ofstream aout; ofstream rout; - string rare = outputDir + m->getRootName(m->getSimpleName(fastafile)) + tag + "rare.fasta"; + string rare = outputDir + m->getRootName(m->getSimpleName(fastafile)) + tag + "rare." + getOutputFileNameTag("fasta"); m->openOutputFile(rare, rout); outputNames.push_back(rare); outputTypes["fasta"].push_back(rare); - string abund = outputDir + m->getRootName(m->getSimpleName(fastafile)) + tag + "abund.fasta"; + string abund = outputDir + m->getRootName(m->getSimpleName(fastafile)) + tag + "abund." + getOutputFileNameTag("fasta"); m->openOutputFile(abund, aout); outputNames.push_back(abund); outputTypes["fasta"].push_back(abund); @@ -964,8 +991,8 @@ int SplitAbundCommand::parseFasta(string tag) { //namefile temp2 = new ofstream; filehandles[Groups[i]+".abund"] = temp2; - m->openOutputFile(fileroot + tag + Groups[i] + ".rare.fasta", *(filehandles[Groups[i]+".rare"])); - m->openOutputFile(fileroot + tag + Groups[i] + ".abund.fasta", *(filehandles[Groups[i]+".abund"])); + m->openOutputFile(fileroot + tag + Groups[i] + ".rare." + getOutputFileNameTag("fasta"), *(filehandles[Groups[i]+".rare"])); + m->openOutputFile(fileroot + tag + Groups[i] + ".abund." + getOutputFileNameTag("fasta"), *(filehandles[Groups[i]+".abund"])); } //open input file @@ -1010,7 +1037,7 @@ int SplitAbundCommand::parseFasta(string tag) { //namefile for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { (*(filehandles[it3->first])).close(); - outputNames.push_back(fileroot + tag + it3->first + ".fasta"); outputTypes["fasta"].push_back(fileroot + tag + it3->first + ".fasta"); + outputNames.push_back(fileroot + tag + it3->first + "." + getOutputFileNameTag("fasta")); outputTypes["fasta"].push_back(fileroot + tag + it3->first + "." + getOutputFileNameTag("fasta")); delete it3->second; } }