X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=splitgroupscommand.cpp;h=c15ba3a4d588b3eedcaca7713c6d5acb8610aee2;hb=541bab1dac00688b4c3a8c4a95ab464412663c50;hp=f3c6cd9e2b7a5e5308bc6624bb4489062f71b2a8;hpb=96dbe925073caefaed6e6db85659c144a806aeb1;p=mothur.git diff --git a/splitgroupscommand.cpp b/splitgroupscommand.cpp index f3c6cd9..c15ba3a 100644 --- a/splitgroupscommand.cpp +++ b/splitgroupscommand.cpp @@ -15,13 +15,13 @@ //********************************************************************************************************************** vector SplitGroupCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "CountGroup", "none",false,false); parameters.push_back(pcount); - CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "CountGroup", "none",false,false); parameters.push_back(pgroup); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - 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", "none", "none","name",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "CountGroup", "none","count",false,false,true); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "CountGroup", "none","group",false,false,true); parameters.push_back(pgroup); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + 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); } @@ -36,14 +36,14 @@ vector SplitGroupCommand::setParameters(){ string SplitGroupCommand::getHelpString(){ try { string helpString = ""; - helpString += "The split.group command reads a group or count file, and parses your fasta and names or count files by groups. \n"; - helpString += "The split.group command parameters are fasta, name, group, count and groups.\n"; + helpString += "The split.groups command reads a group or count file, and parses your fasta and names or count files by groups. \n"; + helpString += "The split.groups command parameters are fasta, name, group, count and groups.\n"; helpString += "The fasta and group or count parameters are required.\n"; helpString += "The groups parameter allows you to select groups to create files for. \n"; helpString += "For example if you set groups=A-B-C, you will get a .A.fasta, .A.names, .B.fasta, .B.names, .C.fasta, .C.names files. \n"; helpString += "If you want .fasta and .names files for all groups, set groups=all. \n"; - helpString += "The split.group command should be used in the following format: split.group(fasta=yourFasta, group=yourGroupFile).\n"; - helpString += "Example: split.group(fasta=abrecovery.fasta, group=abrecovery.groups).\n"; + helpString += "The split.groups command should be used in the following format: split.group(fasta=yourFasta, group=yourGroupFile).\n"; + helpString += "Example: split.groups(fasta=abrecovery.fasta, group=abrecovery.groups).\n"; helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n"; return helpString; } @@ -53,27 +53,23 @@ string SplitGroupCommand::getHelpString(){ } } //********************************************************************************************************************** -string SplitGroupCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string SplitGroupCommand::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 == "name") { outputFileName = "names"; } - else if (type == "count") { outputFileName = "count_table"; } - 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, "SplitGroupCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "fasta") { pattern = "[filename],[group],fasta"; } + else if (type == "name") { pattern = "[filename],[group],names"; } + else if (type == "count") { pattern = "[filename],[group],count_table"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "SplitGroupCommand", "getOutputPattern"); + exit(1); + } } + //********************************************************************************************************************** SplitGroupCommand::SplitGroupCommand(){ try { @@ -289,8 +285,13 @@ int SplitGroupCommand::runNameGroup(){ m->mothurOut("Processing group: " + Groups[i]); m->mothurOutEndLine(); - string newFasta = fastafileRoot + Groups[i] + "." + getOutputFileNameTag("fasta"); - string newName = namefileRoot + Groups[i] + "." + getOutputFileNameTag("name"); + map variables; + variables["[filename]"] = fastafileRoot; + variables["[group]"] = Groups[i]; + + string newFasta = getOutputFileName("fasta",variables); + variables["[filename]"] = namefileRoot; + string newName = getOutputFileName("name",variables); parser->getSeqs(Groups[i], newFasta, false); outputNames.push_back(newFasta); outputTypes["fasta"].push_back(newFasta); @@ -319,7 +320,7 @@ int SplitGroupCommand::runCount(){ try { CountTable ct; - ct.readTable(countfile); + ct.readTable(countfile, true); if (!ct.hasGroupInfo()) { m->mothurOut("[ERROR]: your count file does not contain group info, cannot split by group.\n"); m->control_pressed = true; } if (m->control_pressed) { return 0; } @@ -334,12 +335,16 @@ int SplitGroupCommand::runCount(){ for (int i=0; igetRootName(m->getSimpleName(fastafile)) + Groups[i] + "." + getOutputFileNameTag("fasta"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastafile)); + variables["[group]"] = Groups[i]; + string newFasta = getOutputFileName("fasta",variables); outputNames.push_back(newFasta); outputTypes["fasta"].push_back(newFasta); m->openOutputFile(newFasta, (*temp)); temp = new ofstream; cfiles[Groups[i]] = temp; - string newCount = outputDir + m->getRootName(m->getSimpleName(countfile)) + Groups[i] + "." + getOutputFileNameTag("count"); + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(countfile)); + string newCount = getOutputFileName("count",variables); m->openOutputFile(newCount, (*temp)); outputNames.push_back(newCount); outputTypes["count"].push_back(newCount); (*temp) << "Representative_Sequence\ttotal\t" << Groups[i] << endl;