X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=splitabundcommand.cpp;h=17809631f9e9cc590e510a33ec5528e493a14d3c;hb=a76d81690125ca57d7f602ac93abad75cf9796c2;hp=df085b4d05954517e904d4bbf1993bc2b687a026;hpb=a6c4005cb8b45030d6621404d6082723b3b98003;p=mothur.git diff --git a/splitabundcommand.cpp b/splitabundcommand.cpp index df085b4..1780963 100644 --- a/splitabundcommand.cpp +++ b/splitabundcommand.cpp @@ -42,7 +42,7 @@ SplitAbundCommand::SplitAbundCommand(string option) { it = parameters.find("list"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["list"] = inputDir + it->second; } } @@ -50,7 +50,7 @@ SplitAbundCommand::SplitAbundCommand(string option) { it = parameters.find("group"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["group"] = inputDir + it->second; } } @@ -58,7 +58,7 @@ SplitAbundCommand::SplitAbundCommand(string option) { it = parameters.find("fasta"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["fasta"] = inputDir + it->second; } } @@ -66,7 +66,7 @@ SplitAbundCommand::SplitAbundCommand(string option) { it = parameters.find("name"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["name"] = inputDir + it->second; } } @@ -109,7 +109,7 @@ SplitAbundCommand::SplitAbundCommand(string option) { if (groupfile != "") { Groups = groupMap->namesOfGroups; } else { m->mothurOut("You cannot select groups without a valid groupfile, I will disregard your groups selection. "); m->mothurOutEndLine(); groups = ""; } }else { - splitAtDash(groups, Groups); + m->splitAtDash(groups, Groups); } if ((groupfile == "") && (groups != "")) { m->mothurOut("You cannot select groups without a valid groupfile, I will disregard your groups selection. "); m->mothurOutEndLine(); groups = ""; Groups.clear(); } @@ -122,12 +122,12 @@ SplitAbundCommand::SplitAbundCommand(string option) { label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; allLines = 1; } else { - if(label != "all") { splitAtDash(label, labels); allLines = 0; } + if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } } string temp = validParameter.validFile(parameters, "accnos", false); if (temp == "not found") { temp = "F"; } - accnos = isTrue(temp); + accnos = m->isTrue(temp); temp = validParameter.validFile(parameters, "cutoff", false); if (temp == "not found") { temp = "0"; } convert(temp, cutoff); @@ -146,7 +146,7 @@ SplitAbundCommand::SplitAbundCommand(string option) { void SplitAbundCommand::help(){ try { m->mothurOut("The split.abund command reads a fasta file and a list or a names file splits the sequences into rare and abundant groups. \n"); - m->mothurOut("The split.abund command parameters are list, name, cutoff, group, label, groups and accnos.\n"); + m->mothurOut("The split.abund command parameters are fasta, list, name, cutoff, group, label, groups, cutoff and accnos.\n"); m->mothurOut("The fasta and a list or name parameter are required, and you must provide a cutoff value.\n"); m->mothurOut("The cutoff parameter is used to qualify what is abundant and rare.\n"); m->mothurOut("The group parameter allows you to parse a group file into rare and abundant groups.\n"); @@ -155,8 +155,8 @@ void SplitAbundCommand::help(){ m->mothurOut("The groups parameter allows you to parse the files into rare and abundant files by group. \n"); m->mothurOut("For example if you set groups=A-B-C, you will get a .A.abund, .A.rare, .B.abund, .B.rare, .C.abund, .C.rare files. \n"); m->mothurOut("If you want .abund and .rare files for all groups, set groups=all. \n"); - m->mothurOut("The split.abund command should be used in the following format: split.abund(list=yourListFile, group=yourGroupFile, label=yourLabels, cutoff=yourCutoff).\n"); - m->mothurOut("Example: split.abundt(list=abrecovery.fn.list, group=abrecovery.groups, label=0.03, cutoff=2).\n"); + m->mothurOut("The split.abund command should be used in the following format: split.abund(fasta=yourFasta, list=yourListFile, group=yourGroupFile, label=yourLabels, cutoff=yourCutoff).\n"); + m->mothurOut("Example: split.abund(fasta=abrecovery.fasta, list=abrecovery.fn.list, group=abrecovery.groups, label=0.03, cutoff=2).\n"); m->mothurOut("Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile).\n\n"); } @@ -176,22 +176,23 @@ int SplitAbundCommand::execute(){ if (abort == true) { return 0; } if (listfile != "") { //you are using a listfile to determine abundance + if (outputDir == "") { outputDir = m->hasPath(listfile); } //remove old files so you can append later.... - string fileroot = outputDir + getRootName(getSimpleName(listfile)); + string fileroot = outputDir + m->getRootName(m->getSimpleName(listfile)); if (Groups.size() == 0) { remove((fileroot + "rare.list").c_str()); remove((fileroot + "abund.list").c_str()); - wroteListFile["rare"] = false; - wroteListFile["abund"] = false; + outputNames.push_back((fileroot + "rare.list")); + outputNames.push_back((fileroot + "abund.list")); }else{ for (int i=0; igetLabel()); } - if ((anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + if ((m->anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = list->getLabel(); delete list; @@ -276,20 +277,11 @@ int SplitAbundCommand::execute(){ delete input; - for (map::iterator itBool = wroteListFile.begin(); itBool != wroteListFile.end(); itBool++) { - string filename = fileroot + itBool->first; - if (itBool->second) { //we wrote to this file - outputNames.push_back(filename); - }else{ - remove(filename.c_str()); - } - } - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } - }else { //you are using the namefile to determine abundance - + if (outputDir == "") { outputDir = m->hasPath(namefile); } + splitNames(); writeNames(); @@ -324,7 +316,7 @@ int SplitAbundCommand::splitList(ListVector* thisList) { string bin = thisList->get(i); vector names; - splitAtComma(bin, names); //parses bin into individual sequence names + m->splitAtComma(bin, names); //parses bin into individual sequence names int size = names.size(); if (size <= cutoff) { @@ -372,39 +364,39 @@ int SplitAbundCommand::writeList(ListVector* thisList) { ofstream aout; ofstream rout; - if (rareNames.size() != 0) { - string rare = outputDir + getRootName(getSimpleName(listfile)) + ".rare.list"; - wroteListFile["rare"] = true; - openOutputFileAppend(rare, rout); - rout << thisList->getLabel() << '\t' << numRareBins << '\t'; - } + string rare = outputDir + m->getRootName(m->getSimpleName(listfile)) + "rare.list"; + m->openOutputFileAppend(rare, rout); + //outputNames.push_back(rare); - if (abundNames.size() != 0) { - string abund = outputDir + getRootName(getSimpleName(listfile)) + ".abund.list"; - wroteListFile["abund"] = true; - openOutputFileAppend(abund, aout); - rout << thisList->getLabel() << '\t' << numAbundBins << '\t'; - } + string abund = outputDir + m->getRootName(m->getSimpleName(listfile)) + "abund.list"; + m->openOutputFileAppend(abund, aout); + //outputNames.push_back(abund); + + if (rareNames.size() != 0) { rout << thisList->getLabel() << '\t' << numRareBins << '\t'; } + if (abundNames.size() != 0) { aout << thisList->getLabel() << '\t' << numAbundBins << '\t'; } for (int i = 0; i < thisList->getNumBins(); i++) { if (m->control_pressed) { break; } string bin = list->get(i); - int size = getNumNames(bin); + int size = m->getNumNames(bin); if (size <= cutoff) { rout << bin << '\t'; } else { aout << bin << '\t'; } } - if (rareNames.size() != 0) { rout << endl; rout.close(); } - if (abundNames.size() != 0) { aout << endl; aout.close(); } - + if (rareNames.size() != 0) { rout << endl; } + if (abundNames.size() != 0) { aout << endl; } + + rout.close(); + aout.close(); + }else{ //parse names by abundance and group - string fileroot = outputDir + getRootName(getSimpleName(listfile)); + string fileroot = outputDir + m->getRootName(m->getSimpleName(listfile)); ofstream* temp; ofstream* temp2; - map wroteFile; + //map wroteFile; map filehandles; map::iterator it3; @@ -414,8 +406,8 @@ int SplitAbundCommand::writeList(ListVector* thisList) { temp2 = new ofstream; filehandles[Groups[i]+".abund"] = temp2; - openOutputFileAppend(fileroot + Groups[i] + ".rare.list", *(filehandles[Groups[i]+".rare"])); - openOutputFileAppend(fileroot + Groups[i] + ".abund.list", *(filehandles[Groups[i]+".abund"])); + m->openOutputFileAppend(fileroot + Groups[i] + ".rare.list", *(filehandles[Groups[i]+".rare"])); + m->openOutputFileAppend(fileroot + Groups[i] + ".abund.list", *(filehandles[Groups[i]+".abund"])); } map groupVector; @@ -434,7 +426,7 @@ int SplitAbundCommand::writeList(ListVector* thisList) { string bin = list->get(i); vector names; - splitAtComma(bin, names); //parses bin into individual sequence names + m->splitAtComma(bin, names); //parses bin into individual sequence names //parse bin into list of sequences in each group for (int j = 0; j < names.size(); j++) { @@ -447,7 +439,7 @@ int SplitAbundCommand::writeList(ListVector* thisList) { string group = groupMap->getGroup(names[j]); - if (inUsersGroups(group, Groups)) { //only add if this is in a group we want + if (m->inUsersGroups(group, Groups)) { //only add if this is in a group we want itGroup = groupBins.find(group+rareAbund); if(itGroup == groupBins.end()) { groupBins[group+rareAbund] = names[j]; //add first name @@ -469,7 +461,6 @@ int SplitAbundCommand::writeList(ListVector* thisList) { //end list vector for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { (*(filehandles[it3->first])) << thisList->getLabel() << '\t' << groupNumBins[it3->first] << '\t' << groupVector[it3->first] << endl; // label numBins listvector for that group - wroteListFile[it3->first] = true; (*(filehandles[it3->first])).close(); delete it3->second; } @@ -492,17 +483,17 @@ int SplitAbundCommand::splitNames() { //namefile //open input file ifstream in; - openInputFile(namefile, in); + m->openInputFile(namefile, in); while (!in.eof()) { if (m->control_pressed) { break; } string firstCol, secondCol; - in >> firstCol >> secondCol; gobble(in); + in >> firstCol >> secondCol; m->gobble(in); nameMap[firstCol] = secondCol; - int size = getNumNames(secondCol); + int size = m->getNumNames(secondCol); if (size <= cutoff) { rareNames.insert(firstCol); @@ -525,13 +516,13 @@ int SplitAbundCommand::readNamesFile() { try { //open input file ifstream in; - openInputFile(namefile, in); + m->openInputFile(namefile, in); while (!in.eof()) { if (m->control_pressed) { break; } string firstCol, secondCol; - in >> firstCol >> secondCol; gobble(in); + in >> firstCol >> secondCol; m->gobble(in); nameMap[firstCol] = secondCol; } @@ -556,7 +547,7 @@ int SplitAbundCommand::createNameMap(ListVector* thisList) { string bin = thisList->get(i); vector names; - splitAtComma(bin, names); //parses bin into individual sequence names + m->splitAtComma(bin, names); //parses bin into individual sequence names for (int j = 0; j < names.size(); j++) { nameMap[names[j]] = names[j]; } }//end for @@ -579,33 +570,32 @@ int SplitAbundCommand::writeNames() { //namefile ofstream aout; ofstream rout; + string rare = outputDir + m->getRootName(m->getSimpleName(namefile)) + "rare.names"; + m->openOutputFile(rare, rout); + outputNames.push_back(rare); + + string abund = outputDir + m->getRootName(m->getSimpleName(namefile)) + "abund.names"; + m->openOutputFile(abund, aout); + outputNames.push_back(abund); + if (rareNames.size() != 0) { - string rare = outputDir + getRootName(getSimpleName(namefile)) + "rare.names"; - openOutputFile(rare, rout); - outputNames.push_back(rare); - for (set::iterator itRare = rareNames.begin(); itRare != rareNames.end(); itRare++) { rout << (*itRare) << '\t' << nameMap[(*itRare)] << endl; } - rout.close(); } + rout.close(); if (abundNames.size() != 0) { - string abund = outputDir + getRootName(getSimpleName(namefile)) + "abund.names"; - openOutputFile(abund, aout); - outputNames.push_back(abund); - for (set::iterator itAbund = abundNames.begin(); itAbund != abundNames.end(); itAbund++) { aout << (*itAbund) << '\t' << nameMap[(*itAbund)] << endl; } - aout.close(); } - + aout.close(); + }else{ //parse names by abundance and group - string fileroot = outputDir + getRootName(getSimpleName(namefile)); + string fileroot = outputDir + m->getRootName(m->getSimpleName(namefile)); ofstream* temp; ofstream* temp2; - map wroteFile; map filehandles; map::iterator it3; @@ -615,16 +605,13 @@ int SplitAbundCommand::writeNames() { //namefile temp2 = new ofstream; filehandles[Groups[i]+".abund"] = temp2; - openOutputFile(fileroot + Groups[i] + ".rare.names", *(filehandles[Groups[i]+".rare"])); - openOutputFile(fileroot + Groups[i] + ".abund.names", *(filehandles[Groups[i]+".abund"])); - - wroteFile[Groups[i] + ".rare"] = false; - wroteFile[Groups[i] + ".abund"] = false; + m->openOutputFile(fileroot + Groups[i] + ".rare.names", *(filehandles[Groups[i]+".rare"])); + m->openOutputFile(fileroot + Groups[i] + ".abund.names", *(filehandles[Groups[i]+".abund"])); } for (map::iterator itName = nameMap.begin(); itName != nameMap.end(); itName++) { vector names; - splitAtComma(itName->second, names); //parses bin into individual sequence names + m->splitAtComma(itName->second, names); //parses bin into individual sequence names string rareAbund; if (rareNames.count(itName->first) != 0) { //you are a rare name @@ -639,7 +626,7 @@ int SplitAbundCommand::writeNames() { //namefile string group = groupMap->getGroup(names[i]); - if (inUsersGroups(group, Groups)) { //only add if this is in a group we want + if (m->inUsersGroups(group, Groups)) { //only add if this is in a group we want itout = outputStrings.find(group+rareAbund); if (itout == outputStrings.end()) { outputStrings[group+rareAbund] = names[i] + '\t' + names[i]; @@ -649,17 +636,13 @@ int SplitAbundCommand::writeNames() { //namefile } } - for (itout = outputStrings.begin(); itout != outputStrings.end(); itout++) { - *(filehandles[itout->first]) << itout->second << endl; - wroteFile[itout->first] = true; - } + for (itout = outputStrings.begin(); itout != outputStrings.end(); itout++) { *(filehandles[itout->first]) << itout->second << endl; } } for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { (*(filehandles[it3->first])).close(); - if (wroteFile[it3->first] == true) { outputNames.push_back(fileroot + it3->first + ".names"); } - else { remove((it3->first).c_str()); } + outputNames.push_back(fileroot + it3->first + ".names"); delete it3->second; } } @@ -683,32 +666,29 @@ int SplitAbundCommand::writeAccnos(string tag) { ofstream aout; ofstream rout; - if (rareNames.size() != 0) { - string rare = outputDir + getRootName(getSimpleName(inputFile)) + tag + "rare.accnos"; - openOutputFile(rare, rout); - outputNames.push_back(rare); - - for (set::iterator itRare = rareNames.begin(); itRare != rareNames.end(); itRare++) { - rout << (*itRare) << endl; - } - rout.close(); + + string rare = outputDir + m->getRootName(m->getSimpleName(inputFile)) + tag + "rare.accnos"; + m->openOutputFile(rare, rout); + outputNames.push_back(rare); + + for (set::iterator itRare = rareNames.begin(); itRare != rareNames.end(); itRare++) { + rout << (*itRare) << endl; } + rout.close(); + + string abund = outputDir + m->getRootName(m->getSimpleName(inputFile)) + tag + "abund.accnos"; + m->openOutputFile(abund, aout); + outputNames.push_back(abund); - if (abundNames.size() != 0) { - string abund = outputDir + getRootName(getSimpleName(inputFile)) + tag + "abund.accnos"; - openOutputFile(abund, aout); - outputNames.push_back(abund); - - for (set::iterator itAbund = abundNames.begin(); itAbund != abundNames.end(); itAbund++) { - aout << (*itAbund) << endl; - } - aout.close(); + for (set::iterator itAbund = abundNames.begin(); itAbund != abundNames.end(); itAbund++) { + aout << (*itAbund) << endl; } + aout.close(); + }else{ //parse names by abundance and group - string fileroot = outputDir + getRootName(getSimpleName(inputFile)); + string fileroot = outputDir + m->getRootName(m->getSimpleName(inputFile)); ofstream* temp; ofstream* temp2; - map wroteFile; map filehandles; map::iterator it3; @@ -718,20 +698,16 @@ int SplitAbundCommand::writeAccnos(string tag) { temp2 = new ofstream; filehandles[Groups[i]+".abund"] = temp2; - openOutputFile(fileroot + tag + Groups[i] + ".rare.accnos", *(filehandles[Groups[i]+".rare"])); - openOutputFile(fileroot + tag + Groups[i] + ".abund.accnos", *(filehandles[Groups[i]+".abund"])); - - wroteFile[Groups[i] + ".rare"] = false; - wroteFile[Groups[i] + ".abund"] = false; + m->openOutputFile(fileroot + tag + Groups[i] + ".rare.accnos", *(filehandles[Groups[i]+".rare"])); + m->openOutputFile(fileroot + tag + Groups[i] + ".abund.accnos", *(filehandles[Groups[i]+".abund"])); } //write rare for (set::iterator itRare = rareNames.begin(); itRare != rareNames.end(); itRare++) { string group = groupMap->getGroup(*itRare); - if (inUsersGroups(group, Groups)) { //only add if this is in a group we want + if (m->inUsersGroups(group, Groups)) { //only add if this is in a group we want *(filehandles[group+".rare"]) << *itRare << endl; - wroteFile[group+".rare"] = true; } } @@ -739,17 +715,15 @@ int SplitAbundCommand::writeAccnos(string tag) { for (set::iterator itAbund = abundNames.begin(); itAbund != abundNames.end(); itAbund++) { string group = groupMap->getGroup(*itAbund); - if (inUsersGroups(group, Groups)) { //only add if this is in a group we want + if (m->inUsersGroups(group, Groups)) { //only add if this is in a group we want *(filehandles[group+".abund"]) << *itAbund << endl; - wroteFile[group+".abund"] = true; } } //close files for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { (*(filehandles[it3->first])).close(); - if (wroteFile[it3->first] == true) { outputNames.push_back(fileroot + tag + it3->first + ".accnos"); } - else { remove((fileroot + tag + it3->first + ".accnos").c_str()); } + outputNames.push_back(fileroot + tag + it3->first + ".accnos"); delete it3->second; } } @@ -772,22 +746,17 @@ int SplitAbundCommand::parseGroup(string tag) { //namefile ofstream aout; ofstream rout; - if (rareNames.size() != 0) { - string rare = outputDir + getRootName(getSimpleName(groupfile)) + tag + "rare.groups"; - openOutputFile(rare, rout); - outputNames.push_back(rare); - } + string rare = outputDir + m->getRootName(m->getSimpleName(groupfile)) + tag + "rare.groups"; + m->openOutputFile(rare, rout); + outputNames.push_back(rare); + + string abund = outputDir + m->getRootName(m->getSimpleName(groupfile)) + tag + "abund.groups"; + m->openOutputFile(abund, aout); + outputNames.push_back(abund); - if (abundNames.size() != 0) { - string abund = outputDir + getRootName(getSimpleName(groupfile)) + tag + "abund.groups"; - openOutputFile(abund, aout); - outputNames.push_back(abund); - } - - for (map::iterator itName = nameMap.begin(); itName != nameMap.end(); itName++) { vector names; - splitAtComma(itName->second, names); //parses bin into individual sequence names + m->splitAtComma(itName->second, names); //parses bin into individual sequence names for (int i = 0; i < names.size(); i++) { @@ -799,20 +768,19 @@ int SplitAbundCommand::parseGroup(string tag) { //namefile if (rareNames.count(itName->first) != 0) { //you are a rare name rout << names[i] << '\t' << group << endl; }else{ //you are a abund name - rout << names[i] << '\t' << group << endl; + aout << names[i] << '\t' << group << endl; } } } } - if (rareNames.size() != 0) { rout.close(); } - if (abundNames.size() != 0) { aout.close(); } + rout.close(); + aout.close(); }else{ //parse names by abundance and group - string fileroot = outputDir + getRootName(getSimpleName(groupfile)); + string fileroot = outputDir + m->getRootName(m->getSimpleName(groupfile)); ofstream* temp; ofstream* temp2; - map wroteFile; map filehandles; map::iterator it3; @@ -822,16 +790,13 @@ int SplitAbundCommand::parseGroup(string tag) { //namefile temp2 = new ofstream; filehandles[Groups[i]+".abund"] = temp2; - openOutputFile(fileroot + tag + Groups[i] + ".rare.groups", *(filehandles[Groups[i]+".rare"])); - openOutputFile(fileroot + tag + Groups[i] + ".abund.groups", *(filehandles[Groups[i]+".abund"])); - - wroteFile[Groups[i] + ".rare"] = false; - wroteFile[Groups[i] + ".abund"] = false; + m->openOutputFile(fileroot + tag + Groups[i] + ".rare.groups", *(filehandles[Groups[i]+".rare"])); + m->openOutputFile(fileroot + tag + Groups[i] + ".abund.groups", *(filehandles[Groups[i]+".abund"])); } for (map::iterator itName = nameMap.begin(); itName != nameMap.end(); itName++) { vector names; - splitAtComma(itName->second, names); //parses bin into individual sequence names + m->splitAtComma(itName->second, names); //parses bin into individual sequence names string rareAbund; if (rareNames.count(itName->first) != 0) { //you are a rare name @@ -844,17 +809,15 @@ int SplitAbundCommand::parseGroup(string tag) { //namefile string group = groupMap->getGroup(names[i]); - if (inUsersGroups(group, Groups)) { //only add if this is in a group we want + if (m->inUsersGroups(group, Groups)) { //only add if this is in a group we want *(filehandles[group+rareAbund]) << names[i] << '\t' << group << endl; - wroteFile[group+rareAbund] = true; } } } for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { (*(filehandles[it3->first])).close(); - if (wroteFile[it3->first] == true) { outputNames.push_back(fileroot + tag + it3->first + ".groups"); } - else { remove((fileroot + tag + it3->first + ".groups").c_str()); } + outputNames.push_back(fileroot + tag + it3->first + ".groups"); delete it3->second; } } @@ -877,27 +840,22 @@ int SplitAbundCommand::parseFasta(string tag) { //namefile ofstream aout; ofstream rout; - if (rareNames.size() != 0) { - string rare = outputDir + getRootName(getSimpleName(fastafile)) + tag + "rare.fasta"; - openOutputFile(rare, rout); - outputNames.push_back(rare); - } - - if (abundNames.size() != 0) { - string abund = outputDir + getRootName(getSimpleName(fastafile)) + tag + "abund.fasta"; - openOutputFile(abund, aout); - outputNames.push_back(abund); - } - - + string rare = outputDir + m->getRootName(m->getSimpleName(fastafile)) + tag + "rare.fasta"; + m->openOutputFile(rare, rout); + outputNames.push_back(rare); + + string abund = outputDir + m->getRootName(m->getSimpleName(fastafile)) + tag + "abund.fasta"; + m->openOutputFile(abund, aout); + outputNames.push_back(abund); + //open input file ifstream in; - openInputFile(fastafile, in); + m->openInputFile(fastafile, in); while (!in.eof()) { if (m->control_pressed) { break; } - Sequence seq(in); gobble(in); + Sequence seq(in); m->gobble(in); if (seq.getName() != "") { @@ -917,14 +875,13 @@ int SplitAbundCommand::parseFasta(string tag) { //namefile } } in.close(); - if (rareNames.size() != 0) { rout.close(); } - if (abundNames.size() != 0) { aout.close(); } + rout.close(); + aout.close(); }else{ //parse names by abundance and group - string fileroot = outputDir + getRootName(getSimpleName(fastafile)); + string fileroot = outputDir + m->getRootName(m->getSimpleName(fastafile)); ofstream* temp; ofstream* temp2; - map wroteFile; map filehandles; map::iterator it3; @@ -934,21 +891,18 @@ int SplitAbundCommand::parseFasta(string tag) { //namefile temp2 = new ofstream; filehandles[Groups[i]+".abund"] = temp2; - openOutputFile(fileroot + tag + Groups[i] + ".rare.fasta", *(filehandles[Groups[i]+".rare"])); - openOutputFile(fileroot + tag + Groups[i] + ".abund.fasta", *(filehandles[Groups[i]+".abund"])); - - wroteFile[Groups[i] + ".rare"] = false; - wroteFile[Groups[i] + ".abund"] = false; + m->openOutputFile(fileroot + tag + Groups[i] + ".rare.fasta", *(filehandles[Groups[i]+".rare"])); + m->openOutputFile(fileroot + tag + Groups[i] + ".abund.fasta", *(filehandles[Groups[i]+".abund"])); } //open input file ifstream in; - openInputFile(fastafile, in); + m->openInputFile(fastafile, in); while (!in.eof()) { if (m->control_pressed) { break; } - Sequence seq(in); gobble(in); + Sequence seq(in); m->gobble(in); if (seq.getName() != "") { map::iterator itNames = nameMap.find(seq.getName()); @@ -957,7 +911,7 @@ int SplitAbundCommand::parseFasta(string tag) { //namefile m->mothurOut(seq.getName() + " is not in your namesfile, ignoring."); m->mothurOutEndLine(); }else{ vector names; - splitAtComma(itNames->second, names); //parses bin into individual sequence names + m->splitAtComma(itNames->second, names); //parses bin into individual sequence names string rareAbund; if (rareNames.count(itNames->first) != 0) { //you are a rare name @@ -970,9 +924,8 @@ int SplitAbundCommand::parseFasta(string tag) { //namefile string group = groupMap->getGroup(seq.getName()); - if (inUsersGroups(group, Groups)) { //only add if this is in a group we want + if (m->inUsersGroups(group, Groups)) { //only add if this is in a group we want seq.printSequence(*(filehandles[group+rareAbund])); - wroteFile[group+rareAbund] = true; }else if(group == "not found") { m->mothurOut(seq.getName() + " is not in your groupfile. Ignoring."); m->mothurOutEndLine(); } @@ -984,8 +937,7 @@ int SplitAbundCommand::parseFasta(string tag) { //namefile for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { (*(filehandles[it3->first])).close(); - if (wroteFile[it3->first] == true) { outputNames.push_back(fileroot + tag + it3->first + ".fasta"); } - else { remove((fileroot + tag + it3->first + ".fasta").c_str()); } + outputNames.push_back(fileroot + tag + it3->first + ".fasta"); delete it3->second; } }