#include "binsequencecommand.h"
+//**********************************************************************************************************************
+vector<string> BinSeqCommand::getValidParameters(){
+ try {
+ string AlignArray[] = {"fasta","label","name", "group","outputdir","inputdir"};
+ vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+ return myArray;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "BinSeqCommand", "getValidParameters");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+vector<string> BinSeqCommand::getRequiredParameters(){
+ try {
+ string AlignArray[] = {"fasta"};
+ vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+ return myArray;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "BinSeqCommand", "getRequiredParameters");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+vector<string> BinSeqCommand::getRequiredFiles(){
+ try {
+ string AlignArray[] = {"list"};
+ vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+ return myArray;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "BinSeqCommand", "getRequiredFiles");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+BinSeqCommand::BinSeqCommand(){
+ try {
+ abort = true; calledHelp = true;
+ vector<string> tempOutNames;
+ outputTypes["fasta"] = tempOutNames;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "BinSeqCommand", "BinSeqCommand");
+ exit(1);
+ }
+}
//**********************************************************************************************************************
BinSeqCommand::BinSeqCommand(string option) {
try {
globaldata = GlobalData::getInstance();
- abort = false;
+ abort = false; calledHelp = false;
allLines = 1;
labels.clear();
//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
if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
+ //initialize outputTypes
+ vector<string> tempOutNames;
+ outputTypes["fasta"] = tempOutNames;
+
//if the user changes the output directory command factory will send this info to us in the output parameter
outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){
outputDir = "";
- outputDir += hasPath(globaldata->getListFile()); //if user entered a file with a path then preserve it
+ outputDir += m->hasPath(globaldata->getListFile()); //if user entered a file with a path then preserve it
}
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; }
}
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; }
}
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; }
}
label = validParameter.validFile(parameters, "label", false);
if (label == "not found") { label = ""; }
else {
- if(label != "all") { splitAtDash(label, labels); allLines = 0; }
+ if(label != "all") { m->splitAtDash(label, labels); allLines = 0; }
else { allLines = 1; }
}
else if (groupfile == "not found") { groupfile = ""; }
if (abort == false) {
-// openInputFile(fastafile, in);
+// m->openInputFile(fastafile, in);
fasta = new FastaMap();
if (groupfile != "") {
groupMap = new GroupMap(groupfile);
int BinSeqCommand::execute(){
try {
- if (abort == true) { return 0; }
+ if (abort == true) { if (calledHelp) { return 0; } return 2; }
int error = 0;
readNamesFile();
}
-
//read list file
read = new ReadOTUFile(globaldata->getListFile());
read->read(&*globaldata);
userLabels.erase(list->getLabel());
}
- 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;
void BinSeqCommand::readNamesFile() {
try {
vector<string> dupNames;
- openInputFile(namesfile, inNames);
+ m->openInputFile(namesfile, inNames);
string name, names, sequence;
dupNames.clear();
//parse names into vector
- splitAtComma(names, dupNames);
+ m->splitAtComma(names, dupNames);
//store names in fasta map
sequence = fasta->getSequence(name);
fasta->push_back(dupNames[i], sequence);
}
- gobble(inNames);
+ m->gobble(inNames);
}
inNames.close();
try {
string binnames, name, sequence;
- string outputFileName = outputDir + getRootName(getSimpleName(globaldata->getListFile())) + list->getLabel() + ".fasta";
- openOutputFile(outputFileName, out);
+ string outputFileName = outputDir + m->getRootName(m->getSimpleName(globaldata->getListFile())) + list->getLabel() + ".fasta";
+ m->openOutputFile(outputFileName, out);
//save to output list of output file names
- outputNames.push_back(outputFileName);
+ outputNames.push_back(outputFileName); outputTypes["fasta"].push_back(outputFileName);
m->mothurOut(list->getLabel()); m->mothurOutEndLine();