]> git.donarmstrong.com Git - mothur.git/blobdiff - sharedcommand.cpp
fixes while testing 1.33.0
[mothur.git] / sharedcommand.cpp
index 1150e53735481aea3377ec81f78c0d2544f324e6..3be9bb16f6cab3275edf0bbaf5f4372d002ff7b1 100644 (file)
@@ -19,15 +19,15 @@ inline bool compareSharedRabunds(SharedRAbundVector* left, SharedRAbundVector* r
 //**********************************************************************************************************************
 vector<string> SharedCommand::setParameters(){ 
        try {
-        CommandParameter pbiom("biom", "InputTypes", "", "", "BiomListGroup", "BiomListGroup", "none",false,false); parameters.push_back(pbiom);
-               CommandParameter plist("list", "InputTypes", "", "", "BiomListGroup", "BiomListGroup", "ListGroup",false,false); parameters.push_back(plist);
-        CommandParameter pcount("count", "InputTypes", "", "", "", "GroupCount", "",false,false); parameters.push_back(pcount);
-               CommandParameter pgroup("group", "InputTypes", "", "", "none", "GroupCount", "ListGroup",false,false); parameters.push_back(pgroup);
+        CommandParameter pbiom("biom", "InputTypes", "", "", "BiomListGroup", "BiomListGroup", "none","shared",false,false); parameters.push_back(pbiom);
+               CommandParameter plist("list", "InputTypes", "", "", "BiomListGroup", "BiomListGroup", "ListGroup","shared",false,false,true); parameters.push_back(plist);
+        CommandParameter pcount("count", "InputTypes", "", "", "none", "GroupCount", "none","",false,false); parameters.push_back(pcount);
+               CommandParameter pgroup("group", "InputTypes", "", "", "none", "GroupCount", "ListGroup","",false,false,true); parameters.push_back(pgroup);
                //CommandParameter pordergroup("ordergroup", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pordergroup);
-               CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel);
-               CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups);
-               CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
-               CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
+               CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel);
+               CommandParameter pgroups("groups", "String", "", "", "", "", "","group",false,false); parameters.push_back(pgroups);
+               CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
+               CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
                
                vector<string> myArray;
                for (int i = 0; i < parameters.size(); i++) {   myArray.push_back(parameters[i].name);          }
@@ -56,28 +56,22 @@ string SharedCommand::getHelpString(){
        }
 }
 //**********************************************************************************************************************
-string SharedCommand::getOutputFileNameTag(string type, string inputName=""){  
-       try {
-        string outputFileName = "";
-               map<string, vector<string> >::iterator it;
+string SharedCommand::getOutputPattern(string type) {
+    try {
+        string pattern = "";
         
-        //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 == "shared")            {   outputFileName =  "shared";   }
-            else if (type == "rabund")    {   outputFileName =  "rabund";   }
-            else if (type == "group")        {   outputFileName =  "groups";   }
-            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, "SharedCommand", "getOutputFileNameTag");
-               exit(1);
-       }
+        if (type == "shared") {  pattern = "[filename],shared-[filename],[distance],shared"; }
+        else if (type == "rabund") {  pattern = "[filename],[group],rabund"; } 
+        else if (type == "group") {  pattern = "[filename],[group],groups"; }
+        else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true;  }
+        
+        return pattern;
+    }
+    catch(exception& e) {
+        m->errorOut(e, "SharedCommand", "getOutputPattern");
+        exit(1);
+    }
 }
-
 //**********************************************************************************************************************
 SharedCommand::SharedCommand(){        
        try {
@@ -188,7 +182,11 @@ SharedCommand::SharedCommand(string option)  {
              countfile = validParameter.validFile(parameters, "count", true);
              if (countfile == "not open") { countfile = ""; abort = true; }    
              else if (countfile == "not found") { countfile = ""; }
-             else {  m->setCountTableFile(countfile); }
+             else {  
+                 m->setCountTableFile(countfile); 
+                 CountTable temp;
+                 if (!temp.testGroups(countfile)) { m->mothurOut("[ERROR]: Your count file does not have group info, aborting."); m->mothurOutEndLine(); abort=true; }
+             }
                         
             if ((biomfile == "") && (listfile == "")) { 
                                //is there are current file available for either of these?
@@ -251,20 +249,9 @@ int SharedCommand::execute(){
        try {
                
                if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
-                       
-               //getting output filename
-        string filename = "";
-               if (listfile != "") { filename = listfile; }
-        else { filename = biomfile; }
-               
-               if (outputDir == "") { outputDir += m->hasPath(filename); }
-               
-               filename = outputDir + m->getRootName(m->getSimpleName(filename));
-               filename = filename + getOutputFileNameTag("shared");
-               outputNames.push_back(filename); outputTypes["shared"].push_back(filename);
-               
-        if (listfile != "") {  createSharedFromListGroup(filename);  }
-        else {   createSharedFromBiom(filename);  }
+        
+        if (listfile != "") {  createSharedFromListGroup();  }
+        else {   createSharedFromBiom();  }
         
         if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {       m->mothurRemove(outputNames[i]); }  }
         
@@ -298,8 +285,17 @@ int SharedCommand::execute(){
        }
 }
 //**********************************************************************************************************************
-int SharedCommand::createSharedFromBiom(string filename) {
+int SharedCommand::createSharedFromBiom() {
        try {
+        //getting output filename
+        string filename = biomfile;
+               if (outputDir == "") { outputDir += m->hasPath(filename); }
+               
+        map<string, string> variables;
+               variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(filename));
+               filename = getOutputFileName("shared",variables);
+               outputNames.push_back(filename); outputTypes["shared"].push_back(filename);
+        
         ofstream out;
         m->openOutputFile(filename, out);
         
@@ -459,7 +455,7 @@ int SharedCommand::createSharedFromBiom(string filename) {
         if (it == fileLines.end()) { m->mothurOut("[ERROR]: you file does not have a data provided.\n"); }
         else {
             string thisLine = it->second;
-            m->currentBinLabels = otuNames;
+            m->currentSharedBinLabels = otuNames;
             
             //read data
             vector<SharedRAbundVector*> lookup = readData(matrixFormat, thisLine, matrixElementType, groupNames, otuNames.size());
@@ -612,7 +608,7 @@ int SharedCommand::eliminateZeroOTUS(vector<SharedRAbundVector*>& thislookup) {
                     for (int h = 0; h < diff; h++) { binLabel += "0"; }
                 }
                 binLabel += sbinNumber; 
-                if (i < m->currentBinLabels.size()) {  binLabel = m->currentBinLabels[i]; }
+                if (i < m->currentSharedBinLabels.size()) {  binLabel = m->currentSharedBinLabels[i]; }
                 
                 newBinLabels.push_back(binLabel);
             }
@@ -621,7 +617,7 @@ int SharedCommand::eliminateZeroOTUS(vector<SharedRAbundVector*>& thislookup) {
         for (int j = 0; j < thislookup.size(); j++) {  delete thislookup[j];  }
         
         thislookup = newLookup;
-        m->currentBinLabels = newBinLabels;
+        m->currentSharedBinLabels = newBinLabels;
         
         return 0;
         
@@ -751,10 +747,8 @@ string SharedCommand::getTag(string& line) {
        }
 }
 //**********************************************************************************************************************
-int SharedCommand::createSharedFromListGroup(string filename) {
+int SharedCommand::createSharedFromListGroup() {
        try {
-        ofstream out;
-        m->openOutputFile(filename, out);
         
         GroupMap* groupMap = NULL;
         CountTable* countTable = NULL;
@@ -767,7 +761,7 @@ int SharedCommand::createSharedFromListGroup(string filename) {
             m->setAllGroups(allGroups);
         }else{
             countTable = new CountTable();
-            countTable->readTable(countfile);
+            countTable->readTable(countfile, true, false);
         }
         
         if (m->control_pressed) { return 0; }
@@ -781,6 +775,20 @@ int SharedCommand::createSharedFromListGroup(string filename) {
             m->setGroups(Groups);
         }else { pickedGroups = true; }
         
+        
+        ofstream out;
+        string filename = "";
+        if (!pickedGroups) {
+            string filename = listfile;
+            if (outputDir == "") { outputDir += m->hasPath(filename); }
+            
+            map<string, string> variables;
+            variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(filename));
+            filename = getOutputFileName("shared",variables);
+            outputNames.push_back(filename); outputTypes["shared"].push_back(filename);
+            m->openOutputFile(filename, out);
+        }
+        
         //fill filehandles with neccessary ofstreams
         int i;
         ofstream* temp;
@@ -791,12 +799,15 @@ int SharedCommand::createSharedFromListGroup(string filename) {
         
         //set fileroot
         fileroot = outputDir + m->getRootName(m->getSimpleName(listfile));
-        
+        map<string, string> variables; 
+               variables["[filename]"] = fileroot;
         //clears file before we start to write to it below
         for (int i=0; i<Groups.size(); i++) {
-            m->mothurRemove((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund")));
-            outputNames.push_back((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund")));
-            outputTypes["rabund"].push_back((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund")));
+            variables["[group]"] = Groups[i];
+            string rabundFIleName = getOutputFileName("rabund",variables);
+            m->mothurRemove(rabundFIleName);
+            outputNames.push_back(rabundFIleName);
+            outputTypes["rabund"].push_back(rabundFIleName);
         }
         
         string errorOff = "no error";
@@ -812,8 +823,10 @@ int SharedCommand::createSharedFromListGroup(string filename) {
         if (m->control_pressed) { 
             delete SharedList; if (groupMap != NULL) { delete groupMap; } if (countTable != NULL) { delete countTable; }
             for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {  delete it3->second;  }
-            out.close(); m->mothurRemove(filename); 
-            for (int i=0; i<Groups.size(); i++) {  m->mothurRemove((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund")));             }
+            out.close(); if (!pickedGroups) { m->mothurRemove(filename); }
+            for (int i=0; i<Groups.size(); i++) {  variables["[group]"] = Groups[i];
+                string rabundFIleName = getOutputFileName("rabund",variables);
+                m->mothurRemove(rabundFIleName);               }
             return 0; 
         }
         
@@ -825,9 +838,9 @@ int SharedCommand::createSharedFromListGroup(string filename) {
         int error = ListGroupSameSeqs(namesSeqs, SharedList);
         
         if ((!pickedGroups) && (SharedList->getNumSeqs() != numGroupNames)) {  //if the user has not specified any groups and their files don't match exit with error
-            m->mothurOut("Your group file contains " + toString(numGroupNames) + " sequences and list file contains " + toString(SharedList->getNumSeqs()) + " sequences. Please correct."); m->mothurOutEndLine(); 
+            m->mothurOut("Your group file contains " + toString(numGroupNames) + " sequences and list file contains " + toString(SharedList->getNumSeqs()) + " sequences. Please correct."); m->mothurOutEndLine(); m->control_pressed = true;
             
-            out.close(); m->mothurRemove(filename); //remove blank shared file you made
+            out.close(); if (!pickedGroups) { m->mothurRemove(filename); } //remove blank shared file you made
             
             //delete memory
             for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; }
@@ -841,12 +854,15 @@ int SharedCommand::createSharedFromListGroup(string filename) {
         if ((pickedGroups) && (m->groupMode == "group")) { //make new group file
             string groups = "";
             if (m->getNumGroups() < 4) {
-                for (int i = 0; i < m->getNumGroups(); i++) {
+                for (int i = 0; i < m->getNumGroups()-1; i++) {
                     groups += (m->getGroups())[i] + ".";
                 }
+                groups+=(m->getGroups())[m->getNumGroups()-1];
             }else { groups = "merge"; }
-            
-            string newGroupFile = outputDir + m->getRootName(m->getSimpleName(listfile)) + groups + getOutputFileNameTag("group");
+            map<string, string> variables; 
+            variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(listfile));
+            variables["[group]"] = groups;
+            string newGroupFile = getOutputFileName("group",variables);
             outputTypes["group"].push_back(newGroupFile); 
             outputNames.push_back(newGroupFile);
             ofstream outGroups;
@@ -871,8 +887,10 @@ int SharedCommand::createSharedFromListGroup(string filename) {
             if (m->control_pressed) { 
                 delete SharedList; if (groupMap != NULL) { delete groupMap; } if (countTable != NULL) { delete countTable; }
                 for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {  delete it3->second;  }
-                out.close(); m->mothurRemove(filename); 
-                for (int i=0; i<Groups.size(); i++) {  m->mothurRemove((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund")));         }
+                if (!pickedGroups) { out.close(); m->mothurRemove(filename); }
+                for (int i=0; i<Groups.size(); i++) {  variables["[group]"] = Groups[i];
+                    string rabundFIleName = getOutputFileName("rabund",variables);
+                    m->mothurRemove(rabundFIleName);           }
                 return 0; 
             }
             
@@ -881,21 +899,42 @@ int SharedCommand::createSharedFromListGroup(string filename) {
                 lookup = SharedList->getSharedRAbundVector();
                 
                 m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
-                if (pickedGroups) { //check for otus with no seqs in them
-                    eliminateZeroOTUS(lookup);
-                }
                 
                 if (m->control_pressed) { 
                     delete SharedList; if (groupMap != NULL) { delete groupMap; } if (countTable != NULL) { delete countTable; }
                     for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }
                     for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {  delete it3->second;  }
-                    out.close(); m->mothurRemove(filename); 
-                    for (int i=0; i<Groups.size(); i++) {  m->mothurRemove((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund")));             }
+                    if (!pickedGroups) { out.close(); m->mothurRemove(filename); }
+                    for (int i=0; i<Groups.size(); i++) {  variables["[group]"] = Groups[i];
+                        string rabundFIleName = getOutputFileName("rabund",variables);
+                        m->mothurRemove(rabundFIleName);               }
                     return 0; 
                 }
                 
-                if (!m->printedHeaders) { lookup[0]->printHeaders(out); }
-                printSharedData(lookup, out); //prints info to the .shared file
+                //if picked groups must split the shared file by label
+                if (pickedGroups) {
+                    string filename = listfile;
+                    if (outputDir == "") { outputDir += m->hasPath(filename); }
+                    
+                    map<string, string> variables;
+                    variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(filename));
+                    variables["[distance]"] = lookup[0]->getLabel();
+                    filename = getOutputFileName("shared",variables);
+                    outputNames.push_back(filename); outputTypes["shared"].push_back(filename);
+                    ofstream out2;
+                    m->openOutputFile(filename, out2);
+                    
+                    vector<string> savedLabels = m->currentSharedBinLabels;
+                    eliminateZeroOTUS(lookup);
+                    lookup[0]->printHeaders(out2);
+                    printSharedData(lookup, out2);
+                    out2.close();
+                    m->currentSharedBinLabels = savedLabels; //restore old labels
+
+                }else {
+                    if (!m->printedSharedHeaders) { lookup[0]->printHeaders(out); }
+                    printSharedData(lookup, out); //prints info to the .shared file
+                }
                 for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }
                 
                 processedLabels.insert(SharedList->getLabel());
@@ -910,22 +949,43 @@ int SharedCommand::createSharedFromListGroup(string filename) {
                 
                 lookup = SharedList->getSharedRAbundVector();
                 m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
-                if (pickedGroups) { //check for otus with no seqs in them
-                    eliminateZeroOTUS(lookup);
-                }
-                
                 
                 if (m->control_pressed) { 
                     delete SharedList; if (groupMap != NULL) { delete groupMap; } if (countTable != NULL) { delete countTable; }
                     for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }
                     for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {  delete it3->second;  }
-                    out.close(); m->mothurRemove(filename); 
-                    for (int i=0; i<Groups.size(); i++) {  m->mothurRemove((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund")));             }
+                    if (!pickedGroups) { out.close(); m->mothurRemove(filename); }
+                    for (int i=0; i<Groups.size(); i++) {  variables["[group]"] = Groups[i];
+                        string rabundFIleName = getOutputFileName("rabund",variables);
+                        m->mothurRemove(rabundFIleName);               }
                     return 0; 
                 }
                 
-                if (!m->printedHeaders) { lookup[0]->printHeaders(out); }
-                printSharedData(lookup, out); //prints info to the .shared file
+                //if picked groups must split the shared file by label
+                if (pickedGroups) {
+                    string filename = listfile;
+                    if (outputDir == "") { outputDir += m->hasPath(filename); }
+                    
+                    map<string, string> variables;
+                    variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(filename));
+                    variables["[distance]"] = lookup[0]->getLabel();
+                    filename = getOutputFileName("shared",variables);
+                    outputNames.push_back(filename); outputTypes["shared"].push_back(filename);
+                    ofstream out2;
+                    m->openOutputFile(filename, out2);
+                    
+                    vector<string> savedLabels = m->currentSharedBinLabels;
+                    eliminateZeroOTUS(lookup);
+                    lookup[0]->printHeaders(out2);
+                    printSharedData(lookup, out2);
+                    out2.close();
+                    m->currentSharedBinLabels = savedLabels; //restore old labels
+                    
+                }else {
+                    if (!m->printedSharedHeaders) { lookup[0]->printHeaders(out); }
+                    printSharedData(lookup, out); //prints info to the .shared file
+                }
+
                 for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }
                 
                 processedLabels.insert(SharedList->getLabel());
@@ -958,25 +1018,46 @@ int SharedCommand::createSharedFromListGroup(string filename) {
             
             lookup = SharedList->getSharedRAbundVector();
             m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
-            if (pickedGroups) { //check for otus with no seqs in them
-                eliminateZeroOTUS(lookup);
-            }
             
             if (m->control_pressed) { 
                 if (groupMap != NULL) { delete groupMap; } if (countTable != NULL) { delete countTable; }
                 for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {  delete it3->second;   }
-                out.close(); m->mothurRemove(filename); 
-                for (int i=0; i<Groups.size(); i++) {  m->mothurRemove((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund")));         }
+                if (!pickedGroups) { out.close(); m->mothurRemove(filename); }
+                for (int i=0; i<Groups.size(); i++) {  variables["[group]"] = Groups[i];
+                    string rabundFIleName = getOutputFileName("rabund",variables);
+                    m->mothurRemove(rabundFIleName);           }
                 return 0; 
             }
             
-            if (!m->printedHeaders) { lookup[0]->printHeaders(out); }
-            printSharedData(lookup, out); //prints info to the .shared file
+            //if picked groups must split the shared file by label
+            if (pickedGroups) {
+                string filename = listfile;
+                if (outputDir == "") { outputDir += m->hasPath(filename); }
+                
+                map<string, string> variables;
+                variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(filename));
+                variables["[distance]"] = lookup[0]->getLabel();
+                filename = getOutputFileName("shared",variables);
+                outputNames.push_back(filename); outputTypes["shared"].push_back(filename);
+                ofstream out2;
+                m->openOutputFile(filename, out2);
+                
+                vector<string> savedLabels = m->currentSharedBinLabels;
+                eliminateZeroOTUS(lookup);
+                lookup[0]->printHeaders(out2);
+                printSharedData(lookup, out2);
+                out2.close();
+                m->currentSharedBinLabels = savedLabels; //restore old labels
+                
+            }else {
+                if (!m->printedSharedHeaders) { lookup[0]->printHeaders(out); }
+                printSharedData(lookup, out); //prints info to the .shared file
+            }
             for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }
             delete SharedList;
         }
         
-        out.close();
+        if (!pickedGroups) { out.close(); }
         
         for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {
             delete it3->second;
@@ -985,8 +1066,10 @@ int SharedCommand::createSharedFromListGroup(string filename) {
         if (groupMap != NULL) { delete groupMap; } if (countTable != NULL) { delete countTable; }
                
         if (m->control_pressed) { 
-            m->mothurRemove(filename); 
-            for (int i=0; i<Groups.size(); i++) {  m->mothurRemove((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund")));             }
+            if (!pickedGroups) { m->mothurRemove(filename); }
+            for (int i=0; i<Groups.size(); i++) {  variables["[group]"] = Groups[i];
+                string rabundFIleName = getOutputFileName("rabund",variables);
+                m->mothurRemove(rabundFIleName);               }
             return 0; 
         }
 
@@ -1015,7 +1098,10 @@ void SharedCommand::printSharedData(vector<SharedRAbundVector*> thislookup, ofst
                                Groups.push_back(thislookup[i]->getGroup());
                                
                                RAbundVector rav = thislookup[i]->getRAbundVector();
-                               m->openOutputFileAppend(fileroot + thislookup[i]->getGroup() + "." + getOutputFileNameTag("rabund"), *(filehandles[thislookup[i]->getGroup()]));
+                map<string, string> variables; 
+                variables["[filename]"] = fileroot;
+                variables["[group]"] = thislookup[i]->getGroup();
+                               m->openOutputFileAppend(getOutputFileName("rabund",variables), *(filehandles[thislookup[i]->getGroup()]));
                                rav.print(*(filehandles[thislookup[i]->getGroup()]));
                                (*(filehandles[thislookup[i]->getGroup()])).close();
                        }
@@ -1043,7 +1129,10 @@ void SharedCommand::printSharedData(vector<SharedRAbundVector*> thislookup, ofst
                                        Groups.push_back((myIt->second)->getGroup());
                                
                                        RAbundVector rav = (myIt->second)->getRAbundVector();
-                                       m->openOutputFileAppend(fileroot + (myIt->second)->getGroup() + "." + getOutputFileNameTag("rabund"), *(filehandles[(myIt->second)->getGroup()]));
+                    map<string, string> variables; 
+                    variables["[filename]"] = fileroot;
+                    variables["[group]"] = (myIt->second)->getGroup();
+                                       m->openOutputFileAppend(getOutputFileName("rabund",variables), *(filehandles[(myIt->second)->getGroup()]));
                                        rav.print(*(filehandles[(myIt->second)->getGroup()]));
                                        (*(filehandles[(myIt->second)->getGroup()])).close();
                                }else{
@@ -1083,8 +1172,12 @@ int SharedCommand::ListGroupSameSeqs(vector<string>& groupMapsSeqs, SharedListVe
                        for (int j = 0; j < listNames.size(); j++) {
                                int num = groupNamesSeqs.count(listNames[j]);
                                
-                               if (num == 0) { error = 1; m->mothurOut("[ERROR]: " + listNames[j] + " is in your listfile and not in your groupfile. Please correct."); m->mothurOutEndLine(); }
-                               else { groupNamesSeqs.erase(listNames[j]); }
+                               if (num == 0) { 
+                    error = 1; 
+                    if (groupfile != "") { 
+                        m->mothurOut("[ERROR]: " + listNames[j] + " is in your listfile and not in your groupfile. Please correct."); m->mothurOutEndLine();   } 
+                    else{ m->mothurOut("[ERROR]: " + listNames[j] + " is in your listfile and not in your count file. Please correct."); m->mothurOutEndLine();        }
+                }else { groupNamesSeqs.erase(listNames[j]); }
                        }
                }