]> git.donarmstrong.com Git - mothur.git/blobdiff - reversecommand.cpp
added count file to cluster.classic and cluster.split. modified splitting classes...
[mothur.git] / reversecommand.cpp
index ea2ddeb8e718b44363409f0b332827feec41d6a9..cde88b71203ac3c5fe364c2d7a7bd112bc8da8f8 100644 (file)
@@ -43,7 +43,27 @@ string ReverseSeqsCommand::getHelpString(){
                exit(1);
        }
 }
-
+//**********************************************************************************************************************
+string ReverseSeqsCommand::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 =  "rc" + m->getExtension(inputName);   }
+            else if (type == "qfile")       {   outputFileName =  "rc" + m->getExtension(inputName);   }
+            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, "ReverseSeqsCommand", "getOutputFileNameTag");
+               exit(1);
+       }
+}
 //**********************************************************************************************************************
 ReverseSeqsCommand::ReverseSeqsCommand(){      
        try {
@@ -162,11 +182,11 @@ int ReverseSeqsCommand::execute(){
                        ofstream outFASTA;
                        string tempOutputDir = outputDir;
                        if (outputDir == "") { tempOutputDir += m->hasPath(fastaFileName); } //if user entered a file with a path then preserve it
-                       fastaReverseFileName = tempOutputDir + m->getRootName(m->getSimpleName(fastaFileName)) + "rc" + m->getExtension(fastaFileName);
+                       fastaReverseFileName = tempOutputDir + m->getRootName(m->getSimpleName(fastaFileName)) + getOutputFileNameTag("fasta", fastaFileName);
                        m->openOutputFile(fastaReverseFileName, outFASTA);
                        
                        while(!inFASTA.eof()){
-                               if (m->control_pressed) {  inFASTA.close();  outFASTA.close(); remove(fastaReverseFileName.c_str()); return 0; }
+                               if (m->control_pressed) {  inFASTA.close();  outFASTA.close(); m->mothurRemove(fastaReverseFileName); return 0; }
                                 
                                Sequence currSeq(inFASTA);  m->gobble(inFASTA);
                                if (currSeq.getName() != "") {
@@ -190,11 +210,11 @@ int ReverseSeqsCommand::execute(){
                        ofstream outQual;
                        string tempOutputDir = outputDir;
                        if (outputDir == "") { tempOutputDir += m->hasPath(qualFileName); } //if user entered a file with a path then preserve it
-                       string qualReverseFileName = tempOutputDir + m->getRootName(m->getSimpleName(qualFileName)) + "rc" + m->getExtension(qualFileName);
-                       m->openOutputFile(qualReverseFileName, outQual);
+                       string qualReverseFileName = tempOutputDir + m->getRootName(m->getSimpleName(qualFileName)) + getOutputFileNameTag("qfile", qualFileName);
+            m->openOutputFile(qualReverseFileName, outQual);
 
                        while(!inQual.eof()){
-                               if (m->control_pressed) {  inQual.close();  outQual.close(); remove(qualReverseFileName.c_str()); return 0; }
+                               if (m->control_pressed) {  inQual.close();  outQual.close(); m->mothurRemove(qualReverseFileName); return 0; }
                                currQual = QualityScores(inQual);  m->gobble(inQual);
                                currQual.flipQScores(); 
                                currQual.printQScores(outQual);
@@ -204,7 +224,7 @@ int ReverseSeqsCommand::execute(){
                        outputNames.push_back(qualReverseFileName); outputTypes["qfile"].push_back(qualReverseFileName);
                }
                
-               if (m->control_pressed) {  remove(qualReverseFileName.c_str()); remove(fastaReverseFileName.c_str()); return 0; }
+               if (m->control_pressed) {  m->mothurRemove(qualReverseFileName); m->mothurRemove(fastaReverseFileName); return 0; }
                
                //set fasta file as new current fastafile
                string current = "";