]> git.donarmstrong.com Git - mothur.git/blobdiff - degapseqscommand.cpp
cleaned up code2
[mothur.git] / degapseqscommand.cpp
index c90064f190af3421a2f3f6ebc673b1265a1f202a..318a05ec0bee7765f835cce4301d2b7a97d16978 100644 (file)
@@ -46,6 +46,26 @@ string DegapSeqsCommand::getHelpString(){
        }
 }
 //**********************************************************************************************************************
+string DegapSeqsCommand::getOutputFileNameTag(string type, string inputName=""){       
+       try {
+        string outputFileName = "";
+               map<string, vector<string> >::iterator it;
+        
+        //is this a type this command creates
+        it = outputTypes.find(type);
+        if (it == outputTypes.end()) {  m->mothurOut("[ERROR]: this command doesn't create a " + type + " output file.\n"); }
+        else {
+            if (type == "fasta") {  outputFileName =  "ng.fasta"; }
+            else { m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true;  }
+        }
+        return outputFileName;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "DegapSeqsCommand", "getOutputFileNameTag");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
 DegapSeqsCommand::DegapSeqsCommand(){  
        try {
                abort = true; calledHelp = true; 
@@ -65,6 +85,7 @@ DegapSeqsCommand::DegapSeqsCommand(string option)  {
                
                //allow user to run help
                if(option == "help") { help(); abort = true; calledHelp = true; }
+               else if(option == "citation") { citation(); abort = true; calledHelp = true;}
                
                else {
                        vector<string> myArray = setParameters();
@@ -155,7 +176,7 @@ DegapSeqsCommand::DegapSeqsCommand(string option)  {
                                                        //erase from file list
                                                        fastaFileNames.erase(fastaFileNames.begin()+i);
                                                        i--;
-                                               }
+                                               }else { m->setFastaFile(fastaFileNames[i]); }
                                        }
                                }
                                
@@ -192,11 +213,11 @@ int DegapSeqsCommand::execute(){
                        ofstream outFASTA;
                        string tempOutputDir = outputDir;
                        if (outputDir == "") { tempOutputDir = m->hasPath(fastaFileNames[s]); }
-                       string degapFile = tempOutputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "ng.fasta";
+                       string degapFile = tempOutputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + getOutputFileNameTag("fasta");
                        m->openOutputFile(degapFile, outFASTA);
                        
                        while(!inFASTA.eof()){
-                               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; }
+                               if (m->control_pressed) {   outputTypes.clear(); inFASTA.close();  outFASTA.close(); m->mothurRemove(degapFile); for (int j = 0; j < outputNames.size(); j++) { m->mothurRemove(outputNames[j]);        } return 0; }
                                 
                                Sequence currSeq(inFASTA);  m->gobble(inFASTA);
                                if (currSeq.getName() != "") {
@@ -209,7 +230,7 @@ int DegapSeqsCommand::execute(){
                        
                        outputNames.push_back(degapFile); outputTypes["fasta"].push_back(degapFile);
                        
-                       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; }
+                       if (m->control_pressed) {  outputTypes.clear(); m->mothurRemove(degapFile); for (int j = 0; j < outputNames.size(); j++) {      m->mothurRemove(outputNames[j]);        } return 0; }
                }
                
                //set fasta file as new current fastafile