#include "splitabundcommand.h"
+//**********************************************************************************************************************
+vector<string> SplitAbundCommand::getValidParameters(){
+ try {
+ string Array[] = {"name","group","list","label","accnos","groups","fasta","cutoff","outputdir","inputdir"};
+ vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+ return myArray;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "SplitAbundCommand", "getValidParameters");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+SplitAbundCommand::SplitAbundCommand(){
+ try {
+ abort = true; calledHelp = true;
+ vector<string> tempOutNames;
+ outputTypes["list"] = tempOutNames;
+ outputTypes["name"] = tempOutNames;
+ outputTypes["accnos"] = tempOutNames;
+ outputTypes["group"] = tempOutNames;
+ outputTypes["fasta"] = tempOutNames;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "SplitAbundCommand", "SplitAbundCommand");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+vector<string> SplitAbundCommand::getRequiredParameters(){
+ try {
+ string Array[] = {"fasta","list","name","or"};
+ vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+ return myArray;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "SplitAbundCommand", "getRequiredParameters");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+vector<string> SplitAbundCommand::getRequiredFiles(){
+ try {
+ vector<string> myArray;
+ return myArray;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "SplitAbundCommand", "getRequiredFiles");
+ exit(1);
+ }
+}
//**********************************************************************************************************************
SplitAbundCommand::SplitAbundCommand(string option) {
try {
- abort = false;
+ abort = false; calledHelp = false;
allLines = 1;
//allow user to run help
- if(option == "help") { help(); abort = true; }
+ if(option == "help") { help(); abort = true; calledHelp = true; }
else {
//valid paramters for this command
for (it = parameters.begin(); it != parameters.end(); it++) {
if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
-
+
+ //initialize outputTypes
+ vector<string> tempOutNames;
+ outputTypes["list"] = tempOutNames;
+ outputTypes["name"] = tempOutNames;
+ outputTypes["accnos"] = tempOutNames;
+ outputTypes["group"] = tempOutNames;
+ outputTypes["fasta"] = tempOutNames;
+
//if the user changes the input directory command factory will send this info to us in the output parameter
string inputDir = validParameter.validFile(parameters, "inputdir", false);
if (inputDir == "not found"){ inputDir = ""; }
int SplitAbundCommand::execute(){
try {
- if (abort == true) { return 0; }
+ if (abort == true) { if (calledHelp) { return 0; } return 2; }
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 + m->getRootName(m->getSimpleName(listfile));
- if (Groups.size() == 0) {
- remove((fileroot + "rare.list").c_str());
- remove((fileroot + "abund.list").c_str());
-
- outputNames.push_back((fileroot + "rare.list"));
- outputNames.push_back((fileroot + "abund.list"));
- }else{
- for (int i=0; i<Groups.size(); i++) {
- remove((fileroot + Groups[i] + ".rare.list").c_str());
- remove((fileroot + Groups[i] + ".abund.list").c_str());
-
- outputNames.push_back((fileroot + Groups[i] + ".rare.list"));
- outputNames.push_back((fileroot + Groups[i] + ".abund.list"));
- }
- }
//if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
set<string> processedLabels;
if (accnos) { writeAccnos(tag); }
if (fastafile != "") { parseFasta(tag); }
}
-
+
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
}
}//end for
- writeList(thisList);
string tag = thisList->getLabel() + ".";
+
+ writeList(thisList, tag);
+
if (groupfile != "") { parseGroup(tag); }
if (accnos) { writeAccnos(tag); }
if (fastafile != "") { parseFasta(tag); }
}
}
/**********************************************************************************************************************/
-int SplitAbundCommand::writeList(ListVector* thisList) {
+int SplitAbundCommand::writeList(ListVector* thisList, string tag) {
try {
map<string, ofstream*> filehandles;
ofstream aout;
ofstream rout;
- string rare = outputDir + m->getRootName(m->getSimpleName(listfile)) + "rare.list";
- m->openOutputFileAppend(rare, rout);
- //outputNames.push_back(rare);
+ string rare = outputDir + m->getRootName(m->getSimpleName(listfile)) + tag + "rare.list";
+ m->openOutputFile(rare, rout);
+ outputNames.push_back(rare); outputTypes["list"].push_back(rare);
- string abund = outputDir + m->getRootName(m->getSimpleName(listfile)) + "abund.list";
- m->openOutputFileAppend(abund, aout);
- //outputNames.push_back(abund);
+ string abund = outputDir + m->getRootName(m->getSimpleName(listfile)) + tag + "abund.list";
+ m->openOutputFile(abund, aout);
+ outputNames.push_back(abund); outputTypes["list"].push_back(abund);
if (rareNames.size() != 0) { rout << thisList->getLabel() << '\t' << numRareBins << '\t'; }
if (abundNames.size() != 0) { aout << thisList->getLabel() << '\t' << numAbundBins << '\t'; }
temp2 = new ofstream;
filehandles[Groups[i]+".abund"] = temp2;
- m->openOutputFileAppend(fileroot + Groups[i] + ".rare.list", *(filehandles[Groups[i]+".rare"]));
- m->openOutputFileAppend(fileroot + Groups[i] + ".abund.list", *(filehandles[Groups[i]+".abund"]));
+ 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");
}
map<string, string> groupVector;
string rare = outputDir + m->getRootName(m->getSimpleName(namefile)) + "rare.names";
m->openOutputFile(rare, rout);
- outputNames.push_back(rare);
+ outputNames.push_back(rare); outputTypes["name"].push_back(rare);
string abund = outputDir + m->getRootName(m->getSimpleName(namefile)) + "abund.names";
m->openOutputFile(abund, aout);
- outputNames.push_back(abund);
+ outputNames.push_back(abund); outputTypes["name"].push_back(abund);
if (rareNames.size() != 0) {
for (set<string>::iterator itRare = rareNames.begin(); itRare != rareNames.end(); itRare++) {
for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {
(*(filehandles[it3->first])).close();
- outputNames.push_back(fileroot + it3->first + ".names");
+ outputNames.push_back(fileroot + it3->first + ".names"); outputTypes["name"].push_back(fileroot + it3->first + ".names");
delete it3->second;
}
}
string rare = outputDir + m->getRootName(m->getSimpleName(inputFile)) + tag + "rare.accnos";
m->openOutputFile(rare, rout);
- outputNames.push_back(rare);
+ outputNames.push_back(rare); outputTypes["accnos"].push_back(rare);
for (set<string>::iterator itRare = rareNames.begin(); itRare != rareNames.end(); itRare++) {
rout << (*itRare) << endl;
string abund = outputDir + m->getRootName(m->getSimpleName(inputFile)) + tag + "abund.accnos";
m->openOutputFile(abund, aout);
- outputNames.push_back(abund);
+ outputNames.push_back(abund); outputTypes["accnos"].push_back(abund);
for (set<string>::iterator itAbund = abundNames.begin(); itAbund != abundNames.end(); itAbund++) {
aout << (*itAbund) << endl;
//close files
for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {
(*(filehandles[it3->first])).close();
- outputNames.push_back(fileroot + tag + it3->first + ".accnos");
+ outputNames.push_back(fileroot + tag + it3->first + ".accnos"); outputTypes["accnos"].push_back(fileroot + tag + it3->first + ".accnos");
delete it3->second;
}
}
string rare = outputDir + m->getRootName(m->getSimpleName(groupfile)) + tag + "rare.groups";
m->openOutputFile(rare, rout);
- outputNames.push_back(rare);
+ outputNames.push_back(rare); outputTypes["group"].push_back(rare);
string abund = outputDir + m->getRootName(m->getSimpleName(groupfile)) + tag + "abund.groups";
m->openOutputFile(abund, aout);
- outputNames.push_back(abund);
+ outputNames.push_back(abund); outputTypes["group"].push_back(abund);
for (map<string, string>::iterator itName = nameMap.begin(); itName != nameMap.end(); itName++) {
vector<string> names;
for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {
(*(filehandles[it3->first])).close();
- outputNames.push_back(fileroot + tag + it3->first + ".groups");
+ outputNames.push_back(fileroot + tag + it3->first + ".groups"); outputTypes["group"].push_back(fileroot + tag + it3->first + ".groups");
delete it3->second;
}
}
string rare = outputDir + m->getRootName(m->getSimpleName(fastafile)) + tag + "rare.fasta";
m->openOutputFile(rare, rout);
- outputNames.push_back(rare);
+ outputNames.push_back(rare); outputTypes["fasta"].push_back(rare);
string abund = outputDir + m->getRootName(m->getSimpleName(fastafile)) + tag + "abund.fasta";
m->openOutputFile(abund, aout);
- outputNames.push_back(abund);
+ outputNames.push_back(abund); outputTypes["fasta"].push_back(abund);
//open input file
ifstream in;
for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {
(*(filehandles[it3->first])).close();
- outputNames.push_back(fileroot + tag + it3->first + ".fasta");
+ outputNames.push_back(fileroot + tag + it3->first + ".fasta"); outputTypes["fasta"].push_back(fileroot + tag + it3->first + ".fasta");
delete it3->second;
}
}