]> git.donarmstrong.com Git - mothur.git/blobdiff - degapseqscommand.cpp
added set.current and get.current commands and modified existing commands to update...
[mothur.git] / degapseqscommand.cpp
index 290d5dc0996a62783ab3365513f7441b1aafd717..7fd2803a4ec6c5e578d7b180a9e08fda1af33385 100644 (file)
@@ -25,7 +25,7 @@ vector<string> DegapSeqsCommand::getValidParameters(){
 //**********************************************************************************************************************
 DegapSeqsCommand::DegapSeqsCommand(){  
        try {
-               //initialize outputTypes
+               abort = true; calledHelp = true; 
                vector<string> tempOutNames;
                outputTypes["fasta"] = tempOutNames;
        }
@@ -60,10 +60,10 @@ vector<string> DegapSeqsCommand::getRequiredFiles(){
 //***************************************************************************************************************
 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
@@ -112,7 +112,9 @@ DegapSeqsCommand::DegapSeqsCommand(string option)  {
                                                if (m->getDefaultPath() != "") { //default path is set
                                                        string tryPath = m->getDefaultPath() + m->getSimpleName(fastaFileNames[i]);
                                                        m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine();
-                                                       ableToOpen = m->openInputFile(tryPath, in, "noerror");
+                                                       ifstream in2;
+                                                       ableToOpen = m->openInputFile(tryPath, in2, "noerror");
+                                                       in2.close();
                                                        fastaFileNames[i] = tryPath;
                                                }
                                        }
@@ -122,7 +124,9 @@ DegapSeqsCommand::DegapSeqsCommand(string option)  {
                                                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();
-                                                       ableToOpen = m->openInputFile(tryPath, in, "noerror");
+                                                       ifstream in2;
+                                                       ableToOpen = m->openInputFile(tryPath, in2, "noerror");
+                                                       in2.close();
                                                        fastaFileNames[i] = tryPath;
                                                }
                                        }
@@ -184,7 +188,7 @@ DegapSeqsCommand::~DegapSeqsCommand(){      /*      do nothing      */      }
 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++) {
                                
@@ -215,6 +219,13 @@ int DegapSeqsCommand::execute(){
                        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; }
                }
                
+               //set fasta file as new current fastafile
+               string current = "";
+               itTypes = outputTypes.find("fasta");
+               if (itTypes != outputTypes.end()) {
+                       if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setFastaFile(current); }
+               }
+               
                m->mothurOutEndLine();
                m->mothurOut("Output File Name: "); m->mothurOutEndLine();
                for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }