]> git.donarmstrong.com Git - mothur.git/blobdiff - countseqscommand.cpp
added load.logfile command. changed summary.single output for subsample=t.
[mothur.git] / countseqscommand.cpp
index 0d8ddf5440c324b3d7fa12cc4cff92aef4996b3b..8a18fc755e66a04d6013ecbf7dd088821088501a 100644 (file)
@@ -46,7 +46,26 @@ string CountSeqsCommand::getHelpString(){
                exit(1);
        }
 }
-
+//**********************************************************************************************************************
+string CountSeqsCommand::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 == "summary") {  outputFileName =  "seq.count"; }
+            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, "CountSeqsCommand", "getOutputFileNameTag");
+               exit(1);
+       }
+}
 //**********************************************************************************************************************
 CountSeqsCommand::CountSeqsCommand(){  
        try {
@@ -147,7 +166,7 @@ int CountSeqsCommand::execute(){
                if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
                
                ofstream out;
-               string outputFileName = outputDir + m->getRootName(m->getSimpleName(namefile)) + "seq.count";
+               string outputFileName = outputDir + m->getRootName(m->getSimpleName(namefile)) + getOutputFileNameTag("summary");
                m->openOutputFile(outputFileName, out); outputTypes["summary"].push_back(outputFileName);
                out << "Representative_Sequence\ttotal\t";
                
@@ -157,7 +176,8 @@ int CountSeqsCommand::execute(){
                        
                        //make sure groups are valid. takes care of user setting groupNames that are invalid or setting groups=all
                        SharedUtil* util = new SharedUtil();
-                       util->setGroups(Groups, groupMap->namesOfGroups);
+                       vector<string> nameGroups = groupMap->getNamesOfGroups();
+                       util->setGroups(Groups, nameGroups);
                        delete util;
                        
                        //sort groupNames so that the group title match the counts below, this is needed because the map object automatically sorts
@@ -173,7 +193,8 @@ int CountSeqsCommand::execute(){
                //open input file
                ifstream in;
                m->openInputFile(namefile, in);
-               
+        
+               int total = 0;
                while (!in.eof()) {
                        if (m->control_pressed) { break; }
                        
@@ -216,7 +237,7 @@ int CountSeqsCommand::execute(){
                                out << firstCol << '\t' << names.size() << endl;
                        }
                        
-                       
+                       total += names.size();
                }
                in.close();
                
@@ -224,6 +245,8 @@ int CountSeqsCommand::execute(){
                
                if (m->control_pressed) { m->mothurRemove(outputFileName); return 0; }
                
+        m->mothurOutEndLine();
+               m->mothurOut("Total number of sequences: " + toString(total)); m->mothurOutEndLine();
                m->mothurOutEndLine();
                m->mothurOut("Output File Name: "); m->mothurOutEndLine();
                m->mothurOut(outputFileName); m->mothurOutEndLine();