#include "degapseqscommand.h"
#include "sequence.hpp"
+//**********************************************************************************************************************
+vector<string> DegapSeqsCommand::getValidParameters(){
+ try {
+ string Array[] = {"fasta", "outputdir","inputdir"};
+ vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+ return myArray;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "DegapSeqsCommand", "getValidParameters");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+DegapSeqsCommand::DegapSeqsCommand(){
+ try {
+ abort = true; calledHelp = true;
+ vector<string> tempOutNames;
+ outputTypes["fasta"] = tempOutNames;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "DegapSeqsCommand", "DegapSeqsCommand");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+vector<string> DegapSeqsCommand::getRequiredParameters(){
+ try {
+ string Array[] = {"fasta"};
+ vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+ return myArray;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "DegapSeqsCommand", "getRequiredParameters");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+vector<string> DegapSeqsCommand::getRequiredFiles(){
+ try {
+ vector<string> myArray;
+ return myArray;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "DegapSeqsCommand", "getRequiredFiles");
+ exit(1);
+ }
+}
//***************************************************************************************************************
-
DegapSeqsCommand::DegapSeqsCommand(string option) {
try {
- abort = false;
+ abort = false; calledHelp = false;
//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 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 = ""; }
fastafile = validParameter.validFile(parameters, "fasta", false);
if (fastafile == "not found") { fastafile = ""; m->mothurOut("fasta is a required parameter for the degap.seqs command."); m->mothurOutEndLine(); abort = true; }
else {
- splitAtDash(fastafile, fastaFileNames);
+ m->splitAtDash(fastafile, fastaFileNames);
//go through files and make sure they are good, if not, then disregard them
for (int i = 0; i < fastaFileNames.size(); i++) {
if (inputDir != "") {
- string path = hasPath(fastaFileNames[i]);
+ string path = m->hasPath(fastaFileNames[i]);
//if the user has not given a path then, add inputdir. else leave path alone.
if (path == "") { fastaFileNames[i] = inputDir + fastaFileNames[i]; }
}
ifstream in;
- int ableToOpen = openInputFile(fastaFileNames[i], in, "noerror");
+ int ableToOpen = m->openInputFile(fastaFileNames[i], in, "noerror");
//if you can't open it, try default location
if (ableToOpen == 1) {
if (m->getDefaultPath() != "") { //default path is set
- string tryPath = m->getDefaultPath() + getSimpleName(fastaFileNames[i]);
+ string tryPath = m->getDefaultPath() + m->getSimpleName(fastaFileNames[i]);
m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine();
- ableToOpen = openInputFile(tryPath, in, "noerror");
+ ifstream in2;
+ ableToOpen = m->openInputFile(tryPath, in2, "noerror");
+ in2.close();
fastaFileNames[i] = tryPath;
}
}
+
+ //if you can't open it, try default location
+ if (ableToOpen == 1) {
+ if (m->getOutputDir() != "") { //default path is set
+ string tryPath = m->getOutputDir() + m->getSimpleName(fastaFileNames[i]);
+ m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine();
+ ifstream in2;
+ ableToOpen = m->openInputFile(tryPath, in2, "noerror");
+ in2.close();
+ fastaFileNames[i] = tryPath;
+ }
+ }
+
in.close();
if (ableToOpen == 1) {
//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(fastafile); //if user entered a file with a path then preserve it
+ outputDir += m->hasPath(fastafile); //if user entered a file with a path then preserve it
}
}
int DegapSeqsCommand::execute(){
try{
- if (abort == true) { return 0; }
+ if (abort == true) { if (calledHelp) { return 0; } return 2; }
for (int s = 0; s < fastaFileNames.size(); s++) {
m->mothurOut("Degapping sequences from " + fastaFileNames[s] + " ..." ); m->mothurOutEndLine();
ifstream inFASTA;
- openInputFile(fastaFileNames[s], inFASTA);
+ m->openInputFile(fastaFileNames[s], inFASTA);
ofstream outFASTA;
- string degapFile = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + "ng.fasta";
- openOutputFile(degapFile, outFASTA);
+ string tempOutputDir = outputDir;
+ if (outputDir == "") { tempOutputDir = m->hasPath(fastaFileNames[s]); }
+ string degapFile = tempOutputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "ng.fasta";
+ m->openOutputFile(degapFile, outFASTA);
while(!inFASTA.eof()){
- if (m->control_pressed) { inFASTA.close(); outFASTA.close(); remove(degapFile.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } return 0; }
+ if (m->control_pressed) { outputTypes.clear(); inFASTA.close(); outFASTA.close(); remove(degapFile.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } return 0; }
- Sequence currSeq(inFASTA); gobble(inFASTA);
+ Sequence currSeq(inFASTA); m->gobble(inFASTA);
if (currSeq.getName() != "") {
outFASTA << ">" << currSeq.getName() << endl;
outFASTA << currSeq.getUnaligned() << endl;
inFASTA.close();
outFASTA.close();
- outputNames.push_back(degapFile);
+ outputNames.push_back(degapFile); outputTypes["fasta"].push_back(degapFile);
- if (m->control_pressed) { remove(degapFile.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } return 0; }
+ if (m->control_pressed) { outputTypes.clear(); remove(degapFile.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } return 0; }
}
m->mothurOutEndLine();