]> git.donarmstrong.com Git - mothur.git/blobdiff - phylotypecommand.cpp
classify.seqs allows sequences to be in taxonomy file that are not in template. ...
[mothur.git] / phylotypecommand.cpp
index 2d2db08a40ea5e1aa8712902dcd419ddb1ad757a..eddddfa0534f547cfa1802b75211f1c6c9950f65 100644 (file)
@@ -53,7 +53,28 @@ string PhylotypeCommand::getHelpString(){
                exit(1);
        }
 }
-
+//**********************************************************************************************************************
+string PhylotypeCommand::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 == "list") {  outputFileName =  "list"; }
+            else if (type == "rabund") {  outputFileName =  "rabund"; }
+            else if (type == "sabund") {  outputFileName =  "sabund"; }
+            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, "PhylotypeCommand", "getOutputFileNameTag");
+               exit(1);
+       }
+}
 //**********************************************************************************************************************
 PhylotypeCommand::PhylotypeCommand(){  
        try {
@@ -198,13 +219,13 @@ int PhylotypeCommand::execute(){
                string fileroot = outputDir + m->getRootName(m->getSimpleName(taxonomyFileName));
                
                ofstream outList;
-               string outputListFile = fileroot + "tx.list";
+               string outputListFile = fileroot + "tx." + getOutputFileNameTag("list");
                m->openOutputFile(outputListFile, outList);
                ofstream outSabund;
-               string outputSabundFile = fileroot + "tx.sabund";
+               string outputSabundFile = fileroot + "tx." + getOutputFileNameTag("sabund");
                m->openOutputFile(outputSabundFile, outSabund);
                ofstream outRabund;
-               string outputRabundFile = fileroot + "tx.rabund";
+               string outputRabundFile = fileroot + "tx." + getOutputFileNameTag("rabund");
                m->openOutputFile(outputRabundFile, outRabund);
                
                outputNames.push_back(outputListFile); outputTypes["list"].push_back(outputListFile);
@@ -251,11 +272,14 @@ int PhylotypeCommand::execute(){
                                 map<string, string>::iterator itNames = namemap.find(names[i]);  //make sure this name is in namefile
                                 
                                 if (itNames != namemap.end()) {  name += namemap[names[i]] + ",";   } //you found it in namefile
-                                else { m->mothurOut(names[i] + " is not in your namefile, please correct."); m->mothurOutEndLine(); exit(1);  }
+                                else { m->mothurOut("[ERROR]: " + names[i] + " is not in your namefile, please correct."); m->mothurOutEndLine(); m->control_pressed = true;  }
                                 
                             }else{   name += names[i] + ",";   }
                         }
                                        }
+                    
+                    if (m->control_pressed) { break; }
+                    
                                        name = name.substr(0, name.length()-1);  //rip off extra ','
                                        //add bin to list vector
                                        if (name != "") { list.push_back(name); } //caused by unknown