#include "sequence.hpp"
//**********************************************************************************************************************
-
+vector<string> ChopSeqsCommand::getValidParameters(){
+ try {
+ string AlignArray[] = {"fasta","numbases","countgaps","keep","outputdir","inputdir"};
+ vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+ return myArray;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "ChopSeqsCommand", "getValidParameters");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+ChopSeqsCommand::ChopSeqsCommand(){
+ try {
+ //initialize outputTypes
+ vector<string> tempOutNames;
+ outputTypes["fasta"] = tempOutNames;
+ outputTypes["accnos"] = tempOutNames;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "ChopSeqsCommand", "ChopSeqsCommand");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+vector<string> ChopSeqsCommand::getRequiredParameters(){
+ try {
+ string Array[] = {"fasta","numbases"};
+ vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+ return myArray;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "ChopSeqsCommand", "getRequiredParameters");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+vector<string> ChopSeqsCommand::getRequiredFiles(){
+ try {
+ vector<string> myArray;
+ return myArray;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "ChopSeqsCommand", "getRequiredFiles");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
ChopSeqsCommand::ChopSeqsCommand(string option) {
try {
abort = false;
if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
- //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 = ""; }
-
+ //initialize outputTypes
+ vector<string> tempOutNames;
+ outputTypes["fasta"] = tempOutNames;
+ outputTypes["accnos"] = 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 = ""; }
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; }
}
if (fastafile == "not open") { abort = true; }
else if (fastafile == "not found") { m->mothurOut("You must provide a fasta file."); m->mothurOutEndLine(); abort = true; }
+ //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 = m->hasPath(fastafile); }
+
string temp = validParameter.validFile(parameters, "numbases", false); if (temp == "not found") { temp = "0"; }
convert(temp, numbases);
temp = validParameter.validFile(parameters, "countgaps", false); if (temp == "not found") { temp = "f"; }
- countGaps = isTrue(temp);
+ countGaps = m->isTrue(temp);
keep = validParameter.validFile(parameters, "keep", false); if (keep == "not found") { keep = "front"; }
if (abort == true) { return 0; }
- string outputFileName = outputDir + getRootName(getSimpleName(fastafile)) + "chop.fasta";
- string outputFileNameAccnos = outputDir + getRootName(getSimpleName(fastafile)) + "chop.accnos";
+ string outputFileName = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "chop.fasta";
+ string outputFileNameAccnos = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "chop.accnos";
ofstream out;
- openOutputFile(outputFileName, out);
+ m->openOutputFile(outputFileName, out);
ofstream outAcc;
- openOutputFile(outputFileNameAccnos, outAcc);
+ m->openOutputFile(outputFileNameAccnos, outAcc);
ifstream in;
- openInputFile(fastafile, in);
+ m->openInputFile(fastafile, in);
bool wroteAccnos = false;
Sequence seq(in);
- if (m->control_pressed) { in.close(); out.close(); outAcc.close(); remove(outputFileName.c_str()); remove(outputFileNameAccnos.c_str()); return 0; }
+ if (m->control_pressed) { outputTypes.clear(); in.close(); out.close(); outAcc.close(); remove(outputFileName.c_str()); remove(outputFileNameAccnos.c_str()); return 0; }
if (seq.getName() != "") {
string newSeqString = getChopped(seq);
m->mothurOutEndLine();
m->mothurOut("Output File Name: "); m->mothurOutEndLine();
- m->mothurOut(outputFileName); m->mothurOutEndLine();
+ m->mothurOut(outputFileName); m->mothurOutEndLine(); outputNames.push_back(outputFileName); outputTypes["fasta"].push_back(outputFileName);
- if (wroteAccnos) { m->mothurOut(outputFileNameAccnos); m->mothurOutEndLine(); }
+ if (wroteAccnos) { m->mothurOut(outputFileNameAccnos); m->mothurOutEndLine(); outputNames.push_back(outputFileNameAccnos); outputTypes["accnos"].push_back(outputFileNameAccnos); }
else { remove(outputFileNameAccnos.c_str()); }
m->mothurOutEndLine();