]> git.donarmstrong.com Git - mothur.git/blobdiff - removegroupscommand.cpp
added load.logfile command. changed summary.single output for subsample=t.
[mothur.git] / removegroupscommand.cpp
index 801029c06383e7811e5cfb14ea0c5cd629b66b67..05b1170bf4501ebd3131a616fdcd58a9b49e59f2 100644 (file)
@@ -57,7 +57,32 @@ string RemoveGroupsCommand::getHelpString(){
                exit(1);
        }
 }
-
+//**********************************************************************************************************************
+string RemoveGroupsCommand::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 == "shared")      {   outputFileName =  "pick" + m->getExtension(inputName);   }
+            else if (type == "design")      {   outputFileName =  "pick" + 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, "RemoveGroupsCommand", "getOutputFileNameTag");
+               exit(1);
+       }
+}
 //**********************************************************************************************************************
 RemoveGroupsCommand::RemoveGroupsCommand(){    
        try {
@@ -295,7 +320,7 @@ int RemoveGroupsCommand::execute(){
                if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
                
                //get groups you want to remove
-               if (accnosfile != "") { readAccnos(); }
+               if (accnosfile != "") { m->readAccnos(accnosfile, Groups); m->setGroups(Groups);  }
                
                if (groupfile != "") {
                        groupMap = new GroupMap(groupfile);
@@ -385,7 +410,7 @@ int RemoveGroupsCommand::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);
@@ -477,7 +502,7 @@ int RemoveGroupsCommand::readShared(){
                
                while(lookup[0] != NULL) {
                        
-                       string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)) + lookup[0]->getLabel() + ".pick" + m->getExtension(sharedfile);
+                       string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)) + lookup[0]->getLabel() + "." + getOutputFileNameTag("shared", sharedfile);
                        ofstream out;
                        m->openOutputFile(outputFileName, out);
                        outputTypes["shared"].push_back(outputFileName);  outputNames.push_back(outputFileName);
@@ -525,7 +550,7 @@ int RemoveGroupsCommand::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);
@@ -615,8 +640,7 @@ int RemoveGroupsCommand::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);
                
@@ -696,8 +720,7 @@ int RemoveGroupsCommand::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);
                
@@ -743,7 +766,7 @@ int RemoveGroupsCommand::readDesign(){
        try {
                string thisOutputDir = outputDir;
                if (outputDir == "") {  thisOutputDir += m->hasPath(designfile);  }
-               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(designfile)) + "pick" + m->getExtension(designfile);
+               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(designfile)) + getOutputFileNameTag("design", designfile);
                
                ofstream out;
                m->openOutputFile(outputFileName, out);
@@ -791,7 +814,7 @@ int RemoveGroupsCommand::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);
                
@@ -837,32 +860,6 @@ int RemoveGroupsCommand::readTax(){
        }
 }
 //**********************************************************************************************************************
-void RemoveGroupsCommand::readAccnos(){
-       try {
-               Groups.clear();
-               
-               ifstream in;
-               m->openInputFile(accnosfile, in);
-               string name;
-               
-               while(!in.eof()){
-                       in >> name;
-                       
-                       Groups.push_back(name);
-                       
-                       m->gobble(in);
-               }
-               in.close();     
-               
-               m->setGroups(Groups);
-               
-       }
-       catch(exception& e) {
-               m->errorOut(e, "RemoveGroupsCommand", "readAccnos");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
 int RemoveGroupsCommand::fillNames(){
        try {
                vector<string> seqs = groupMap->getNamesSeqs();