]> git.donarmstrong.com Git - mothur.git/blobdiff - getseqscommand.cpp
added load.logfile command. changed summary.single output for subsample=t.
[mothur.git] / getseqscommand.cpp
index 84fe0acab9abc0ec603df10896be1c0fe1e7f47c..ccabafb6d19c008eb6957a35e79b5cd0623021d0 100644 (file)
@@ -76,6 +76,33 @@ GetSeqsCommand::GetSeqsCommand(){
        }
 }
 //**********************************************************************************************************************
+string GetSeqsCommand::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 =  "pick" + m->getExtension(inputName);   }
+            else if (type == "taxonomy")    {   outputFileName =  "pick" + m->getExtension(inputName);   }
+            else if (type == "name")        {   outputFileName =  "pick" + m->getExtension(inputName);   }
+            else if (type == "group")       {   outputFileName =  "pick" + m->getExtension(inputName);   }
+            else if (type == "list")        {   outputFileName =  "pick" + m->getExtension(inputName);   }
+            else if (type == "qfile")       {   outputFileName =  "pick" + m->getExtension(inputName);   }
+            else if (type == "accnosreport"){   outputFileName =  "accnos.report";                       }
+            else if (type == "alignreport") {   outputFileName =  "pick.align.report";                   }
+            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, "GetSeqsCommand", "getOutputFileNameTag");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
 GetSeqsCommand::GetSeqsCommand(string option)  {
        try {
                abort = false; calledHelp = false;   
@@ -270,7 +297,7 @@ int GetSeqsCommand::execute(){
                if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
                
                //get names you want to keep
-               readAccnos();
+               names = m->readAccnos(accnosfile);
                
                if (m->control_pressed) { return 0; }
                
@@ -343,7 +370,7 @@ int GetSeqsCommand::readFasta(){
        try {
                string thisOutputDir = outputDir;
                if (outputDir == "") {  thisOutputDir += m->hasPath(fastafile);  }
-               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + "pick" +  m->getExtension(fastafile);
+               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fasta", fastafile);
                ofstream out;
                m->openOutputFile(outputFileName, out);
                
@@ -399,7 +426,7 @@ int GetSeqsCommand::readQual(){
        try {
                string thisOutputDir = outputDir;
                if (outputDir == "") {  thisOutputDir += m->hasPath(qualfile);  }
-               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(qualfile)) + "pick" +  m->getExtension(qualfile);
+               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(qualfile)) + getOutputFileNameTag("qfile", qualfile);
                ofstream out;
                m->openOutputFile(outputFileName, out);
                
@@ -471,7 +498,7 @@ int GetSeqsCommand::readList(){
        try {
                string thisOutputDir = outputDir;
                if (outputDir == "") {  thisOutputDir += m->hasPath(listfile);  }
-               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + "pick" +  m->getExtension(listfile);
+               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + getOutputFileNameTag("list", listfile);
                ofstream out;
                m->openOutputFile(outputFileName, out);
                
@@ -550,7 +577,7 @@ int GetSeqsCommand::readName(){
        try {
                string thisOutputDir = outputDir;
                if (outputDir == "") {  thisOutputDir += m->hasPath(namefile);  }
-               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + "pick" +  m->getExtension(namefile);
+               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + getOutputFileNameTag("name", namefile);
                ofstream out;
                m->openOutputFile(outputFileName, out);
                
@@ -650,7 +677,7 @@ int GetSeqsCommand::readGroup(){
        try {
                string thisOutputDir = outputDir;
                if (outputDir == "") {  thisOutputDir += m->hasPath(groupfile);  }
-               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "pick" + m->getExtension(groupfile);
+               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + getOutputFileNameTag("group", groupfile);
                ofstream out;
                m->openOutputFile(outputFileName, out);
                
@@ -706,7 +733,7 @@ int GetSeqsCommand::readTax(){
        try {
                string thisOutputDir = outputDir;
                if (outputDir == "") {  thisOutputDir += m->hasPath(taxfile);  }
-               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + "pick" + m->getExtension(taxfile);
+               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + getOutputFileNameTag("taxonomy", taxfile);
                ofstream out;
                m->openOutputFile(outputFileName, out);
                
@@ -760,7 +787,7 @@ int GetSeqsCommand::readAlign(){
        try {
                string thisOutputDir = outputDir;
                if (outputDir == "") {  thisOutputDir += m->hasPath(alignfile);  }
-               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(alignfile)) + "pick.align.report";
+               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(alignfile)) + getOutputFileNameTag("alignreport");
                ofstream out;
                m->openOutputFile(outputFileName, out);
                
@@ -827,32 +854,6 @@ int GetSeqsCommand::readAlign(){
        }
 }
 //**********************************************************************************************************************
-
-int GetSeqsCommand::readAccnos(){
-       try {
-               
-               ifstream in;
-               m->openInputFile(accnosfile, in);
-               string name;
-               
-               while(!in.eof()){
-                       in >> name;
-                                               
-                       names.insert(name);
-                       
-                       m->gobble(in);
-               }
-               in.close();     
-               
-               return 0;
-
-       }
-       catch(exception& e) {
-               m->errorOut(e, "GetSeqsCommand", "readAccnos");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
 //just looking at common mistakes. 
 int GetSeqsCommand::runSanityCheck(){
        try {
@@ -952,7 +953,7 @@ int GetSeqsCommand::compareAccnos(){
                
                string thisOutputDir = outputDir;
                if (outputDir == "") {  thisOutputDir += m->hasPath(accnosfile);  }
-               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(accnosfile)) + "accnos.report";
+               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(accnosfile)) + getOutputFileNameTag("accnosreport");
                ofstream out;
                m->openOutputFile(outputFileName, out);
                
@@ -1045,7 +1046,7 @@ int GetSeqsCommand::compareAccnos(){
                
        }
        catch(exception& e) {
-               m->errorOut(e, "GetSeqsCommand", "readAccnos");
+               m->errorOut(e, "GetSeqsCommand", "compareAccnos");
                exit(1);
        }
 }