]> git.donarmstrong.com Git - mothur.git/blobdiff - sharedcommand.cpp
bug fixes
[mothur.git] / sharedcommand.cpp
index 2c1b6af3004e7351085e4538f7023e342bc181f9..ec6b1d3828c38019085101abaa4a0599c539f974 100644 (file)
@@ -14,17 +14,70 @@ inline bool compareSharedRabunds(SharedRAbundVector* left, SharedRAbundVector* r
        return (left->getGroup() < right->getGroup());  
 } 
 //**********************************************************************************************************************
+vector<string> SharedCommand::getValidParameters(){    
+       try {
+               vector<string> myArray; 
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "SharedCommand", "getValidParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+SharedCommand::SharedCommand(){        
+       try {           
+               
+               //initialize outputTypes
+               vector<string> tempOutNames;
+               outputTypes["rabund"] = tempOutNames;
+               outputTypes["shared"] = tempOutNames;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "SharedCommand", "SharedCommand");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> SharedCommand::getRequiredParameters(){ 
+       try {
+               vector<string> myArray;
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "SharedCommand", "getRequiredParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> SharedCommand::getRequiredFiles(){      
+       try {
+               vector<string> myArray;
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "SharedCommand", "getRequiredFiles");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
 
 SharedCommand::SharedCommand(string o) : outputDir(o) {
        try {
                globaldata = GlobalData::getInstance();
                
+               //initialize outputTypes
+               vector<string> tempOutNames;
+               outputTypes["rabund"] = tempOutNames;
+               outputTypes["shared"] = tempOutNames;
+               
                //getting output filename
                filename = globaldata->inputFileName;
                if (outputDir == "") { outputDir += m->hasPath(filename); }
                
                filename = outputDir + m->getRootName(m->getSimpleName(filename));
                filename = filename + "shared";
+               outputTypes["shared"].push_back(filename);
                
                m->openOutputFile(filename, out);
                pickedGroups = false;
@@ -54,6 +107,7 @@ SharedCommand::SharedCommand(string o) : outputDir(o) {
                for (int i=0; i<groups.size(); i++) {
                        remove((fileroot + groups[i] + ".rabund").c_str());
                        outputNames.push_back((fileroot + groups[i] + ".rabund"));
+                       outputTypes["rabund"].push_back((fileroot + groups[i] + ".rabund"));
                }
 
        }
@@ -259,6 +313,7 @@ int SharedCommand::execute(){
                globaldata->setGroupFile("");
                globaldata->setSharedFile(filename);
                
+               
                if (m->control_pressed) { 
                                delete input;  globaldata->ginput = NULL; 
                                remove(filename.c_str()); 
@@ -286,11 +341,15 @@ void SharedCommand::printSharedData(vector<SharedRAbundVector*> thislookup) {
                if (order.size() == 0) { //user has not specified an order so do aplabetically
                        sort(thislookup.begin(), thislookup.end(), compareSharedRabunds);
                        
+                       globaldata->Groups.clear();
+                       
                        //initialize bin values
                        for (int i = 0; i < thislookup.size(); i++) {
                                out << thislookup[i]->getLabel() << '\t' << thislookup[i]->getGroup() << '\t';
                                thislookup[i]->print(out);
                                
+                               globaldata->Groups.push_back(thislookup[i]->getGroup());
+                               
                                RAbundVector rav = thislookup[i]->getRAbundVector();
                                m->openOutputFileAppend(fileroot + thislookup[i]->getGroup() + ".rabund", *(filehandles[thislookup[i]->getGroup()]));
                                rav.print(*(filehandles[thislookup[i]->getGroup()]));
@@ -305,6 +364,7 @@ void SharedCommand::printSharedData(vector<SharedRAbundVector*> thislookup) {
                                myMap[thislookup[i]->getGroup()] = thislookup[i];
                        }
                        
+                       globaldata->Groups.clear();
                        
                        //loop through ordered list and print the rabund
                        for (int i = 0; i < order.size(); i++) {
@@ -313,6 +373,8 @@ void SharedCommand::printSharedData(vector<SharedRAbundVector*> thislookup) {
                                if(myIt != myMap.end()) { //we found it
                                        out << (myIt->second)->getLabel() << '\t' << (myIt->second)->getGroup() << '\t';
                                        (myIt->second)->print(out);
+                                       
+                                       globaldata->Groups.push_back((myIt->second)->getGroup());
                                
                                        RAbundVector rav = (myIt->second)->getRAbundVector();
                                        m->openOutputFileAppend(fileroot + (myIt->second)->getGroup() + ".rabund", *(filehandles[(myIt->second)->getGroup()]));