X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=splitabundcommand.cpp;h=580493b60a1e4d449a71b8689635e8ced4dea397;hp=48fada8eb7fc89d858f24c4d54dcc0a64d8a8225;hb=615301e57c25e241356a9c2380648d117709458d;hpb=90708fe9701e3827e477c82fb3652539c3bf2a0d diff --git a/splitabundcommand.cpp b/splitabundcommand.cpp index 48fada8..580493b 100644 --- a/splitabundcommand.cpp +++ b/splitabundcommand.cpp @@ -13,17 +13,17 @@ //********************************************************************************************************************** vector SplitAbundCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "FNGLT", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none",false,false); parameters.push_back(pgroup); - CommandParameter plist("list", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(plist); - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); - CommandParameter pcutoff("cutoff", "Number", "", "0", "", "", "",false,true); parameters.push_back(pcutoff); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter paccnos("accnos", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(paccnos); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","fasta",false,true,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "FNGLT", "none","name",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none","count",false,false); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none","group",false,false); parameters.push_back(pgroup); + CommandParameter plist("list", "InputTypes", "", "", "none", "FNGLT", "none","list",false,false,true); parameters.push_back(plist); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); + CommandParameter pcutoff("cutoff", "Number", "", "0", "", "", "","",false,true); parameters.push_back(pcutoff); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + CommandParameter paccnos("accnos", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(paccnos); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir); vector myArray; for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } @@ -58,30 +58,26 @@ string SplitAbundCommand::getHelpString(){ exit(1); } } + //********************************************************************************************************************** -string SplitAbundCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string SplitAbundCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "count") { outputFileName = "count_table"; } - 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); - } + if (type == "fasta") { pattern = "[filename],[tag],[tag2],fasta-[filename],[tag],[group],[tag2],fasta"; } + else if (type == "list") { pattern = "[filename],[tag],[tag2],list-[filename],[group],[tag],[tag2],list"; } + else if (type == "name") { pattern = "[filename],[tag],names-[filename],[group],[tag],names"; } + else if (type == "count") { pattern = "[filename],[tag],[tag2],count_table-[filename],[tag],count_table"; } + else if (type == "group") { pattern = "[filename],[tag],[tag2],groups-[filename],[tag],[group],[tag2],groups"; } + else if (type == "accnos") { pattern = "[filename],[tag],[tag2],accnos-[filename],[tag],[group],[tag2],accnos"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "SplitAbundCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** SplitAbundCommand::SplitAbundCommand(){ @@ -216,7 +212,7 @@ SplitAbundCommand::SplitAbundCommand(string option) { else if (countfile == "not found") { countfile = ""; } else { m->setCountTableFile(countfile); - ct.readTable(countfile); + ct.readTable(countfile, true); } if ((namefile != "") && (countfile != "")) { @@ -471,7 +467,7 @@ int SplitAbundCommand::splitList(ListVector* thisList) { }//end for - string tag = thisList->getLabel() + "."; + string tag = thisList->getLabel(); writeList(thisList, tag, numRareBins); @@ -500,11 +496,16 @@ int SplitAbundCommand::writeList(ListVector* thisList, string tag, int numRareBi ofstream aout; ofstream rout; - string rare = outputDir + m->getRootName(m->getSimpleName(listfile)) + tag + "rare." + getOutputFileNameTag("list"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(listfile)); + variables["[tag]"] = tag; + variables["[tag2]"] = "rare"; + string rare = getOutputFileName("list",variables); m->openOutputFile(rare, rout); outputNames.push_back(rare); outputTypes["list"].push_back(rare); - string abund = outputDir + m->getRootName(m->getSimpleName(listfile)) + tag + "abund." + getOutputFileNameTag("list"); + variables["[tag2]"] = "abund"; + string abund = getOutputFileName("list",variables); m->openOutputFile(abund, aout); outputNames.push_back(abund); outputTypes["list"].push_back(abund); @@ -548,8 +549,14 @@ int SplitAbundCommand::writeList(ListVector* thisList, string tag, int numRareBi temp2 = new ofstream; filehandles[Groups[i]+".abund"] = temp2; - string rareGroupFileName = fileroot + Groups[i] +"."+ tag + "rare." + getOutputFileNameTag("list"); - string abundGroupFileName = fileroot + Groups[i] +"."+ tag + "abund." + getOutputFileNameTag("list"); + map variables; + variables["[filename]"] = fileroot; + variables["[tag]"] = tag; + variables["[tag2]"] = "rare"; + variables["[group]"] = Groups[i]; + string rareGroupFileName = getOutputFileName("list",variables); + variables["[tag2]"] = "abund"; + string abundGroupFileName = getOutputFileName("list",variables); m->openOutputFile(rareGroupFileName, *(filehandles[Groups[i]+".rare"])); m->openOutputFile(abundGroupFileName, *(filehandles[Groups[i]+".abund"])); outputNames.push_back(rareGroupFileName); outputTypes["list"].push_back(rareGroupFileName); @@ -759,10 +766,14 @@ int SplitAbundCommand::parseCount(string tag) { //namefile map filehandles; if (Groups.size() == 0) { - string rare = outputDir + m->getRootName(m->getSimpleName(countfile)) + tag + "rare." + getOutputFileNameTag("count"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(countfile)); + variables["[tag]"] = tag; + variables["[tag2]"] = "rare"; + string rare = getOutputFileName("count",variables); outputNames.push_back(rare); outputTypes["count"].push_back(rare); - - string abund = outputDir + m->getRootName(m->getSimpleName(countfile)) + tag + "abund." + getOutputFileNameTag("count"); + variables["[tag2]"] = "abund"; + string abund = getOutputFileName("count",variables); outputNames.push_back(abund); outputTypes["count"].push_back(abund); CountTable rareTable; @@ -846,7 +857,10 @@ int SplitAbundCommand::parseCount(string tag) { //namefile for (it3 = countTableMap.begin(); it3 != countTableMap.end(); it3++) { string fileroot = outputDir + m->getRootName(m->getSimpleName(countfile)); - string filename = fileroot + it3->first + "." + getOutputFileNameTag("count"); + map variables; + variables["[filename]"] = fileroot; + variables["[tag]"] = it3->first; + string filename = getOutputFileName("count",variables); outputNames.push_back(filename); outputTypes["count"].push_back(filename); (it3->second)->printTable(filename); delete it3->second; @@ -871,11 +885,15 @@ int SplitAbundCommand::writeNames() { //namefile ofstream aout; ofstream rout; - string rare = outputDir + m->getRootName(m->getSimpleName(namefile)) + "rare." + getOutputFileNameTag("name"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(namefile)); + variables["[tag]"] = "rare"; + string rare = getOutputFileName("name", variables); m->openOutputFile(rare, rout); outputNames.push_back(rare); outputTypes["name"].push_back(rare); - string abund = outputDir + m->getRootName(m->getSimpleName(namefile)) + "abund." + getOutputFileNameTag("name"); + variables["[tag]"] = "abund"; + string abund = getOutputFileName("name", variables); m->openOutputFile(abund, aout); outputNames.push_back(abund); outputTypes["name"].push_back(abund); @@ -906,8 +924,13 @@ int SplitAbundCommand::writeNames() { //namefile temp2 = new ofstream; filehandles[Groups[i]+".abund"] = temp2; - string rareGroupFileName = fileroot + Groups[i] + ".rare." + getOutputFileNameTag("name"); - string abundGroupFileName = fileroot + Groups[i] + ".abund." + getOutputFileNameTag("name"); + map variables; + variables["[filename]"] = fileroot; + variables["[tag]"] = "rare"; + variables["[group]"] = Groups[i]; + string rareGroupFileName = getOutputFileName("name",variables); + variables["[tag]"] = "abund"; + string abundGroupFileName = getOutputFileName("name",variables); m->openOutputFile(rareGroupFileName, *(filehandles[Groups[i]+".rare"])); m->openOutputFile(abundGroupFileName, *(filehandles[Groups[i]+".abund"])); } @@ -945,7 +968,10 @@ int SplitAbundCommand::writeNames() { //namefile for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { (*(filehandles[it3->first])).close(); - outputNames.push_back(fileroot + it3->first + "." + getOutputFileNameTag("name")); outputTypes["name"].push_back(fileroot + it3->first + "." + getOutputFileNameTag("name")); + map variables; + variables["[filename]"] = fileroot; + variables["[tag]"] = it3->first; + outputNames.push_back(getOutputFileName("name",variables)); outputTypes["name"].push_back(getOutputFileName("name",variables)); delete it3->second; } } @@ -969,8 +995,11 @@ int SplitAbundCommand::writeAccnos(string tag) { ofstream aout; ofstream rout; - - string rare = outputDir + m->getRootName(m->getSimpleName(inputFile)) + tag + "rare." + getOutputFileNameTag("accnos"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputFile)); + variables["[tag]"] = tag; + variables["[tag2]"] = "rare"; + string rare = getOutputFileName("accnos",variables); m->openOutputFile(rare, rout); outputNames.push_back(rare); outputTypes["accnos"].push_back(rare); @@ -979,7 +1008,8 @@ int SplitAbundCommand::writeAccnos(string tag) { } rout.close(); - string abund = outputDir + m->getRootName(m->getSimpleName(inputFile)) + tag + "abund." + getOutputFileNameTag("accnos"); + variables["[tag2]"] = "abund"; + string abund = getOutputFileName("accnos",variables); m->openOutputFile(abund, aout); outputNames.push_back(abund); outputTypes["accnos"].push_back(abund); @@ -1001,8 +1031,14 @@ int SplitAbundCommand::writeAccnos(string tag) { temp2 = new ofstream; filehandles[Groups[i]+".abund"] = temp2; - 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"])); + map variables; + variables["[filename]"] = fileroot; + variables["[tag]"] = tag; + variables["[tag2]"] = "rare"; + variables["[group]"] = Groups[i]; + m->openOutputFile(getOutputFileName("accnos",variables), *(filehandles[Groups[i]+".rare"])); + variables["[tag2]"] = "abund"; + m->openOutputFile(getOutputFileName("accnos",variables), *(filehandles[Groups[i]+".abund"])); } //write rare @@ -1026,7 +1062,11 @@ 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 + "." + getOutputFileNameTag("accnos")); outputTypes["accnos"].push_back(fileroot + tag + it3->first + "." + getOutputFileNameTag("accnos")); + map variables; + variables["[filename]"] = fileroot; + variables["[tag]"] = tag; + variables["[tag2]"] = it3->first; + outputNames.push_back(getOutputFileName("accnos",variables)); outputTypes["accnos"].push_back(getOutputFileName("accnos",variables)); delete it3->second; } } @@ -1049,11 +1089,16 @@ int SplitAbundCommand::parseGroup(string tag) { //namefile ofstream aout; ofstream rout; - string rare = outputDir + m->getRootName(m->getSimpleName(groupfile)) + tag + "rare." + getOutputFileNameTag("group"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(groupfile)); + variables["[tag]"] = tag; + variables["[tag2]"] = "rare"; + string rare = getOutputFileName("group",variables); m->openOutputFile(rare, rout); outputNames.push_back(rare); outputTypes["group"].push_back(rare); - string abund = outputDir + m->getRootName(m->getSimpleName(groupfile)) + tag + "abund." + getOutputFileNameTag("group"); + variables["[tag2]"] = "abund"; + string abund = getOutputFileName("group",variables); ; m->openOutputFile(abund, aout); outputNames.push_back(abund); outputTypes["group"].push_back(abund); @@ -1094,8 +1139,14 @@ int SplitAbundCommand::parseGroup(string tag) { //namefile temp2 = new ofstream; filehandles[Groups[i]+".abund"] = temp2; - 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"])); + map variables; + variables["[filename]"] = fileroot; + variables["[tag]"] = tag; + variables["[tag2]"] = "rare"; + variables["[group]"] = Groups[i]; + m->openOutputFile(getOutputFileName("group",variables), *(filehandles[Groups[i]+".rare"])); + variables["[tag2]"] = "abund"; + m->openOutputFile(getOutputFileName("group",variables), *(filehandles[Groups[i]+".abund"])); } for (map::iterator itName = nameMap.begin(); itName != nameMap.end(); itName++) { @@ -1121,7 +1172,11 @@ 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 + "." + getOutputFileNameTag("group")); outputTypes["group"].push_back(fileroot + tag + it3->first + "." + getOutputFileNameTag("group")); + map variables; + variables["[filename]"] = fileroot; + variables["[tag]"] = tag; + variables["[tag2]"] = it3->first; + outputNames.push_back(getOutputFileName("group",variables)); outputTypes["group"].push_back(getOutputFileName("group",variables)); delete it3->second; } } @@ -1144,11 +1199,16 @@ int SplitAbundCommand::parseFasta(string tag) { //namefile ofstream aout; ofstream rout; - string rare = outputDir + m->getRootName(m->getSimpleName(fastafile)) + tag + "rare." + getOutputFileNameTag("fasta"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastafile)); + variables["[tag]"] = tag; + variables["[tag2]"] = "rare"; + string rare = getOutputFileName("fasta",variables); m->openOutputFile(rare, rout); outputNames.push_back(rare); outputTypes["fasta"].push_back(rare); - string abund = outputDir + m->getRootName(m->getSimpleName(fastafile)) + tag + "abund." + getOutputFileNameTag("fasta"); + variables["[tag2]"] = "abund"; + string abund = getOutputFileName("fasta",variables); m->openOutputFile(abund, aout); outputNames.push_back(abund); outputTypes["fasta"].push_back(abund); @@ -1195,8 +1255,14 @@ int SplitAbundCommand::parseFasta(string tag) { //namefile temp2 = new ofstream; filehandles[Groups[i]+".abund"] = temp2; - 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"])); + map variables; + variables["[filename]"] = fileroot; + variables["[tag]"] = tag; + variables["[tag2]"] = "rare"; + variables["[group]"] = Groups[i]; + m->openOutputFile(getOutputFileName("fasta",variables), *(filehandles[Groups[i]+".rare"])); + variables["[tag2]"] = "abund"; + m->openOutputFile(getOutputFileName("fasta",variables), *(filehandles[Groups[i]+".abund"])); } //open input file @@ -1249,7 +1315,11 @@ 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 + "." + getOutputFileNameTag("fasta")); outputTypes["fasta"].push_back(fileroot + tag + it3->first + "." + getOutputFileNameTag("fasta")); + map variables; + variables["[filename]"] = fileroot; + variables["[tag]"] = tag; + variables["[tag2]"] = it3->first; + outputNames.push_back(getOutputFileName("fasta",variables)); outputTypes["fasta"].push_back(getOutputFileName("fasta",variables)); delete it3->second; } }