]> git.donarmstrong.com Git - mothur.git/blobdiff - pairwiseseqscommand.cpp
cleaned up code
[mothur.git] / pairwiseseqscommand.cpp
index 98b0fde32dbb4cf9bf86aad283fa1d6ad3a7ea44..1fa96e3e9d4c6cf8ce9a4e99af30d01c5562a009 100644 (file)
@@ -64,7 +64,27 @@ string PairwiseSeqsCommand::getHelpString(){
                exit(1);
        }
 }
-
+//**********************************************************************************************************************
+string PairwiseSeqsCommand::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 == "phylip") {  outputFileName =  "dist"; }
+            else if (type == "column") {  outputFileName =  "dist"; }
+            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, "PairwiseSeqsCommand", "getOutputFileNameTag");
+               exit(1);
+       }
+}
 //**********************************************************************************************************************
 PairwiseSeqsCommand::PairwiseSeqsCommand(){    
        try {
@@ -203,12 +223,15 @@ PairwiseSeqsCommand::PairwiseSeqsCommand(string option)  {
                        
                        temp = validParameter.validFile(parameters, "mismatch", false);         if (temp == "not found"){       temp = "-1.0";                  }
                        m->mothurConvert(temp, misMatch);  
+            if (misMatch > 0) { m->mothurOut("[ERROR]: mismatch must be negative.\n"); abort=true; }
                        
                        temp = validParameter.validFile(parameters, "gapopen", false);          if (temp == "not found"){       temp = "-2.0";                  }
                        m->mothurConvert(temp, gapOpen);  
+            if (gapOpen > 0) { m->mothurOut("[ERROR]: gapopen must be negative.\n"); abort=true; }
                        
                        temp = validParameter.validFile(parameters, "gapextend", false);        if (temp == "not found"){       temp = "-1.0";                  }
                        m->mothurConvert(temp, gapExtend); 
+            if (gapExtend > 0) { m->mothurOut("[ERROR]: gapextend must be negative.\n"); abort=true; }
                        
                        temp = validParameter.validFile(parameters, "processors", false);       if (temp == "not found"){       temp = m->getProcessors();      }
                        m->setProcessors(temp);
@@ -269,14 +292,14 @@ int PairwiseSeqsCommand::execute(){
                        string outputFile = "";
                                
                        if (output == "lt") { //does the user want lower triangle phylip formatted file 
-                               outputFile = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "phylip.dist";
+                               outputFile = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "phylip." + getOutputFileNameTag("phylip");
                                m->mothurRemove(outputFile); outputTypes["phylip"].push_back(outputFile);
                        }else if (output == "column") { //user wants column format
-                               outputFile = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "dist";
+                               outputFile = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + getOutputFileNameTag("column");
                                outputTypes["column"].push_back(outputFile);
                                m->mothurRemove(outputFile);
                        }else { //assume square
-                               outputFile = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "square.dist";
+                               outputFile = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "square." + getOutputFileNameTag("phylip");
                                m->mothurRemove(outputFile);
                                outputTypes["phylip"].push_back(outputFile);
                        }