]> git.donarmstrong.com Git - mothur.git/commitdiff
worked on parselist and shared commands, removing memory leaks and allowing any numbe...
authorwestcott <westcott>
Mon, 22 Jun 2009 18:47:04 +0000 (18:47 +0000)
committerwestcott <westcott>
Mon, 22 Jun 2009 18:47:04 +0000 (18:47 +0000)
Mothur.xcodeproj/project.pbxproj
fileoutput.h
parselistcommand.cpp
parselistcommand.h
shared.cpp [deleted file]
shared.h [deleted file]
sharedcommand.cpp
sharedcommand.h
sharedlistvector.cpp
sharedlistvector.h

index 14071540ef2d94503de27fffe13bba2779fcbbb9..9da05bcabafbada3ea826ebc5b4e29486a42c9a7 100644 (file)
                37D928840F21331F001D4494 /* sabundvector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D9281A0F21331F001D4494 /* sabundvector.cpp */; };
                37D928850F21331F001D4494 /* sequence.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D9281C0F21331F001D4494 /* sequence.cpp */; };
                37D928860F21331F001D4494 /* shannon.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D9281E0F21331F001D4494 /* shannon.cpp */; };
-               37D928870F21331F001D4494 /* shared.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928200F21331F001D4494 /* shared.cpp */; };
                37D928880F21331F001D4494 /* sharedace.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928220F21331F001D4494 /* sharedace.cpp */; };
                37D928890F21331F001D4494 /* sharedchao1.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928240F21331F001D4494 /* sharedchao1.cpp */; };
                37D9288A0F21331F001D4494 /* sharedcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928260F21331F001D4494 /* sharedcommand.cpp */; };
                37D9281D0F21331F001D4494 /* sequence.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = sequence.hpp; sourceTree = SOURCE_ROOT; };
                37D9281E0F21331F001D4494 /* shannon.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = shannon.cpp; sourceTree = SOURCE_ROOT; };
                37D9281F0F21331F001D4494 /* shannon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = shannon.h; sourceTree = SOURCE_ROOT; };
-               37D928200F21331F001D4494 /* shared.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = shared.cpp; sourceTree = SOURCE_ROOT; };
-               37D928210F21331F001D4494 /* shared.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = shared.h; sourceTree = SOURCE_ROOT; };
                37D928220F21331F001D4494 /* sharedace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedace.cpp; sourceTree = SOURCE_ROOT; };
                37D928230F21331F001D4494 /* sharedace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedace.h; sourceTree = SOURCE_ROOT; };
                37D928240F21331F001D4494 /* sharedchao1.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedchao1.cpp; sourceTree = SOURCE_ROOT; };
                                37D928050F21331F001D4494 /* rarefact.cpp */,
                                37D928090F21331F001D4494 /* rarefactioncurvedata.h */,
                                3796441D0FB9B9650081FDB6 /* read */,
-                               37D928210F21331F001D4494 /* shared.h */,
-                               37D928200F21331F001D4494 /* shared.cpp */,
                                211C38310F961DD400FEE541 /* sharedutilities.h */,
                                211C38300F961DD400FEE541 /* sharedutilities.cpp */,
                                37D928420F21331F001D4494 /* singlelinkage.cpp */,
                                37D928840F21331F001D4494 /* sabundvector.cpp in Sources */,
                                37D928850F21331F001D4494 /* sequence.cpp in Sources */,
                                37D928860F21331F001D4494 /* shannon.cpp in Sources */,
-                               37D928870F21331F001D4494 /* shared.cpp in Sources */,
                                37D928880F21331F001D4494 /* sharedace.cpp in Sources */,
                                37D928890F21331F001D4494 /* sharedchao1.cpp in Sources */,
                                37D9288A0F21331F001D4494 /* sharedcommand.cpp in Sources */,
index a047a20cffd5cb9c4ac50fbf2cf0b1bb335180cb..0c7999d2c901cc3c3c28357837e467dabb4a990a 100644 (file)
@@ -145,6 +145,6 @@ private:
        string iters;
 };
 
-/***********************************************************************/
+
 
 #endif
index f0403078d2a1b0c7c96c5e65c576c9beba3c981b..8173bdc3086ccd5cc88da03aabef294411d98f07 100644 (file)
@@ -15,24 +15,31 @@ ParseListCommand::ParseListCommand(){
                globaldata = GlobalData::getInstance();
                
                //read in group map info.
-               groupMap = new GroupMap(globaldata->getGroupFile());
-               groupMap->readMap();
+               //groupMap = new GroupMap(globaldata->getGroupFile());
+               //groupMap->readMap();
+               groupMap = globaldata->gGroupmap;
 
                //fill filehandles with neccessary ofstreams
                int i;
                ofstream* temp;
+               SharedListVector* templist;
                for (i=0; i<groupMap->getNumGroups(); i++) {
                        temp = new ofstream;
+                       templist = new SharedListVector();
                        filehandles[groupMap->namesOfGroups[i]] = temp;
+                       mapOfLists[groupMap->namesOfGroups[i]] = templist;
                }
                
                //set fileroot
                fileroot = getRootName(globaldata->getListFile());
                
-               //open output list files
-               for (i=0; i<groupMap->getNumGroups(); i++) {//opens an output file for each group
+               //clears file before we start to write to it below
+               for (int i=0; i<groupMap->getNumGroups(); i++) {
                        openOutputFile(fileroot + groupMap->namesOfGroups[i] + ".list", *(filehandles[groupMap->namesOfGroups[i]]));
+                       (*(filehandles[groupMap->namesOfGroups[i]])).close();
                }
+
+               
        }
        catch(exception& e) {
                cout << "Standard Error: " << e.what() << " has occurred in the ParseListCommand class Function ParseListCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
@@ -46,29 +53,29 @@ ParseListCommand::ParseListCommand(){
 /***********************************************************************/
 void ParseListCommand::parse(int index, SharedListVector* list) {
        try {
-               string prefix, suffix, groupsName;
-               suffix = list->get(index);
-       
-               while (suffix.find_first_of(',') != -1) {//while you still have sequences
-                       prefix = suffix.substr(0,suffix.find_first_of(','));
-                       if ((suffix.find_first_of(',')+1) <= suffix.length()) {  //checks to make sure you don't have comma at end of string
-                               suffix = suffix.substr(suffix.find_first_of(',')+1, suffix.length());
+               string member, bin, groupName;
+               bin = list->get(index);
+               
+               while (bin.find_first_of(',') != -1) {//while you still have sequences
+                       member = bin.substr(0,bin.find_first_of(','));
+                       if ((bin.find_first_of(',')+1) <= bin.length()) {  //checks to make sure you don't have comma at end of string
+                               bin = bin.substr(bin.find_first_of(',')+1, bin.length());
                        }
                        
-                       groupsName = groupMap->getGroup(prefix);
-                       if (groupsName != "not found") {
-                               listGroups[groupsName] = listGroups[groupsName] + "," + prefix; //adds prefix to the correct group.
+                       groupName = groupMap->getGroup(member);
+                       if (groupName != "not found") {
+                               listGroups[groupName] = listGroups[groupName] + "," + member; //adds prefix to the correct group.
                        }else {
-                               cerr << "Error: Sequence '" << prefix << "' was not found in the group file, please correct\n";
+                               cerr << "Error: Sequence '" << member << "' was not found in the group file, please correct\n";
                        }
                }
                
                //save last name after comma
-               groupsName = groupMap->getGroup(suffix);
-               if (groupsName != "not found") {
-                       listGroups[groupsName] = listGroups[groupsName] + "," + suffix; //adds prefix to the correct group.
+               groupName = groupMap->getGroup(bin);
+               if (groupName != "not found") {
+                       listGroups[groupName] = listGroups[groupName] + "," + bin; //adds prefix to the correct group.
                }else {
-                       cerr << "Error: Sequence '" << suffix << "' was not found in the group file, please correct\n";
+                       cerr << "Error: Sequence '" << bin << "' was not found in the group file, please correct\n";
                }
        }
        catch(exception& e) {
@@ -85,6 +92,7 @@ void ParseListCommand::parse(int index, SharedListVector* list) {
 
 int ParseListCommand::execute(){
        try{
+               
                        int count = 1;
                        
                        //read in listfile
@@ -99,12 +107,6 @@ int ParseListCommand::execute(){
                        set<string> userLabels = globaldata->labels;
                        set<int> userLines = globaldata->lines;
                        
-                       //create new list vectors to fill with parsed data
-                       for (int i=0; i<groupMap->getNumGroups(); i++) {
-                               groupOfLists[groupMap->namesOfGroups[i]] = new SharedListVector();
-                       }
-                       
-                                               
                        //parses and sets each groups listvector
                        //as long as you are not at the end of the file or done wih the lines you want
                        while((list != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0) || (userLines.size() != 0))) {
@@ -151,24 +153,20 @@ int ParseListCommand::execute(){
                                cout << lastList->getLabel() << '\t' << count << endl;
                                process(lastList);
                        }
-                       delete lastList;
-
-                       //set groupmap for .shared commands
-                       if (globaldata->gGroupmap != NULL) { delete globaldata->gGroupmap; }
-                       globaldata->gGroupmap = groupMap; 
-                       
-                       //close files
-                       for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { 
-                               ofstream* temp = it3->second;
-                               (*temp).close(); 
-                               delete it3->second;
-                       }
                        
+                       delete lastList;  globaldata->gSharedList = NULL;
                        //delete list vectors to fill with parsed data
-                       for (it2 = groupOfLists.begin(); it2 != groupOfLists.end(); it2++) {
+                       for (it2 = mapOfLists.begin(); it2 != mapOfLists.end(); it2++) {
+                               delete it2->second;
+                       }
+                       for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {
                                delete it2->second;
                        }
+                       
+                       delete input;  globaldata->ginput = NULL;
+                       delete read;
 
+                       
                        return 0;
        }
        catch(exception& e) {
@@ -184,11 +182,8 @@ int ParseListCommand::execute(){
 //**********************************************************************************************************************
 
 ParseListCommand::~ParseListCommand(){
-       
-               globaldata->gSharedList = NULL;
-               delete input;  globaldata->ginput = NULL;
-               delete read;
-       
+
+                       
 }
 //**********************************************************************************************************************
 void ParseListCommand::process(SharedListVector* thisList) {
@@ -200,15 +195,17 @@ void ParseListCommand::process(SharedListVector* thisList) {
                                for (it=listGroups.begin(); it != listGroups.end(); it++) {  //loop through map and set new list vectors
                                        seq = it->second;
                                        seq = seq.substr(1, seq.length()); //rips off extra comma
-                                       groupOfLists[it->first]->push_back(seq); //sets new listvector for each group
+                                       mapOfLists[it->first]->push_back(seq); //sets new listvector for each group
                                }
                                listGroups.clear();
                        }
                        //prints each new list file
                        for (int i=0; i<groupMap->getNumGroups(); i++) {
-                               groupOfLists[groupMap->namesOfGroups[i]]->setLabel(thisList->getLabel());
-                               groupOfLists[groupMap->namesOfGroups[i]]->print(*(filehandles[groupMap->namesOfGroups[i]]));
-                               groupOfLists[groupMap->namesOfGroups[i]]->clear();
+                               openOutputFileAppend(fileroot + groupMap->namesOfGroups[i] + ".list", *(filehandles[groupMap->namesOfGroups[i]]));
+                               mapOfLists[groupMap->namesOfGroups[i]]->setLabel(thisList->getLabel());
+                               mapOfLists[groupMap->namesOfGroups[i]]->print(*(filehandles[groupMap->namesOfGroups[i]]));
+                               mapOfLists[groupMap->namesOfGroups[i]]->clear();
+                               (*(filehandles[groupMap->namesOfGroups[i]])).close();
                        }
 
        }
index b3a2f9c71c5a5657c5cef0ccb17c13e43dd673d5..9e9e968077bc4394b6c82f60bef91b18fe19ca1b 100644 (file)
@@ -40,7 +40,7 @@ private:
        InputData* input;
        ReadOTUFile* read;
        map<string, ofstream*> filehandles;
-       map<string, SharedListVector*> groupOfLists;
+       map<string, SharedListVector*> mapOfLists;
        SharedListVector* list;
        map<string, string> listGroups; //maps group name to sequences from that group in a specific OTU
        map<string, string>::iterator it;
diff --git a/shared.cpp b/shared.cpp
deleted file mode 100644 (file)
index b15ef93..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- *  shared.cpp
- *  Dotur
- *
- *  Created by Sarah Westcott on 12/5/08.
- *  Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved.
- *
- */
-
-#include "shared.h"
-
-/**************************************************************************************************/
-
-Shared::Shared(){
-   globaldata = GlobalData::getInstance();
-}
-
-/**************************************************************************************************/
-void Shared::getSharedVectors(SharedListVector* list) {
-               string label, group;
-               int i,j;
-               label = list->getLabel();
-               
-               for (it = sharedGroups.begin(); it != sharedGroups.end(); it++) {  delete it->second;  }
-               sharedGroups.clear();  //removes old info.
-               
-               //initalize sharedGroups 
-               for (j=0; j<globaldata->gGroupmap->getNumGroups(); j++) {//for each group
-                       group = globaldata->gGroupmap->namesOfGroups[j];
-                       sharedGroups[group] = new SharedRAbundVector();
-                       sharedGroups[group]->setLabel(label);
-                       for (i = 0; i<list->size(); i++) { //for each otu
-                               sharedGroups[group]->push_back(0, i, group); //initialize to 0.
-                       }
-               }
-                       
-               //fills sharedGroups
-               for (i = 0; i<list->size(); i++) {
-                       parse(i, list);
-               }
-               
-               //updates sharedVector
-               //sharedRAbund.push_back(sharedGroups);
-}
-
-
-
-/***********************************************************************/
-void Shared::parse(int index, SharedListVector* list) {
-
-               string prefix, suffix, groupsName;
-               suffix = list->get(index);
-       
-               while (suffix.find_first_of(',') != -1) {//while you still have sequences
-                       prefix = suffix.substr(0,suffix.find_first_of(','));
-                       if ((suffix.find_first_of(',')+1) <= suffix.length()) {  //checks to make sure you don't have comma at end of string
-                               suffix = suffix.substr(suffix.find_first_of(',')+1, suffix.length());
-                       }
-                       groupsName = globaldata->gGroupmap->getGroup(prefix);
-                       if (groupsName != "not found") {
-                               sharedGroups[groupsName]->set(index, (sharedGroups[groupsName]->getAbundance(index) + 1), groupsName); //increment shared vector for that group
-                       }else {
-                               cerr << "Error: Sequence '" << prefix << "' was not found in the group file, please correct\n";
-                       }
-               }
-               
-               //save last name after comma
-               groupsName = globaldata->gGroupmap->getGroup(suffix);
-               if (groupsName != "not found") {
-                       sharedGroups[groupsName]->set(index, ((sharedGroups[groupsName]->getAbundance(index)) + 1), groupsName); //increment shared vector for that group
-               }else {
-                       cerr << "Error: Sequence '" << suffix << "' was not found in the group file, please correct\n";
-               }
-       }
diff --git a/shared.h b/shared.h
deleted file mode 100644 (file)
index 515c2a0..0000000
--- a/shared.h
+++ /dev/null
@@ -1,32 +0,0 @@
-#ifndef SHARED_H
-#define SHARED_H
-
-/*
- *  shared.h
- *  Dotur
- *
- *  Created by Sarah Westcott on 12/5/08.
- *  Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved.
- *
- */
-
-#include "mothur.h"
-#include "sharedrabundvector.h"
-#include "sharedlistvector.h"
-#include "globaldata.hpp"
-
-class Shared {
-       public:
-               Shared();
-               ~Shared() {};
-               void getSharedVectors(SharedListVector*);
-               map<string, SharedRAbundVector*> sharedGroups; //string is groupname, SharedVector* is out info for that group
-               
-       private:
-               GlobalData* globaldata;
-               map<string, SharedRAbundVector*>::iterator it;
-               void parse(int, SharedListVector*);
-               //vector< map<string, SharedRAbundVector*> > sharedRAbund;  //contains all the info needed to create the .shared file not sure if we will need 
-};
-
-#endif
index 42601f48ead5e872d000e35c9b64852ddccd5eb8..439cdf13101b183aebd2cb6e112e1b92ace9ee74 100644 (file)
@@ -35,7 +35,8 @@ SharedCommand::SharedCommand(){
 
 int SharedCommand::execute(){
        try {
-               globaldata = GlobalData::getInstance();
+               
+               cout << "creating sharedfile...";
                //lookup.clear();
                int count = 1;
                string errorOff = "no error";
@@ -47,23 +48,21 @@ int SharedCommand::execute(){
                input = globaldata->ginput;
                SharedList = globaldata->gSharedList;
                SharedListVector* lastList = SharedList;
-               //lookup = SharedList->getSharedRAbundVector();
-               //vector<SharedRAbundVector*> lastLookup = lookup;
-               
+               vector<SharedRAbundVector*> lookup; 
+                               
                //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
                set<string> processedLabels;
                set<string> userLabels = globaldata->labels;
                set<int> userLines = globaldata->lines;
                
-               shared = new Shared();
                
                while((SharedList != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0) || (userLines.size() != 0))) {
                        
 
                        if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(SharedList->getLabel()) == 1){
-                                       
-                                       shared->getSharedVectors(SharedList); //fills sharedGroups with new info and updates sharedVector
-                                       printSharedData(); //prints info to the .shared file
+                                       lookup = SharedList->getSharedRAbundVector();
+                                       printSharedData(lookup); //prints info to the .shared file
+                                       for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }
                                
                                        processedLabels.insert(SharedList->getLabel());
                                        userLabels.erase(SharedList->getLabel());
@@ -71,21 +70,20 @@ int SharedCommand::execute(){
                        }
                        
                        if ((anyLabelsToProcess(SharedList->getLabel(), userLabels, errorOff) == true) && (processedLabels.count(lastList->getLabel()) != 1)) {
-                                       shared->getSharedVectors(lastList); //fills sharedGroups with new info and updates sharedVector
-                                       printSharedData(); //prints info to the .shared file
-
+                                       lookup = lastList->getSharedRAbundVector();
+                                       printSharedData(lookup); //prints info to the .shared file
+                                       for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }
+                                       
                                        processedLabels.insert(lastList->getLabel());
                                        userLabels.erase(lastList->getLabel());
                        }
                        
                        if (count != 1) { delete lastList; }
-                       lastList = SharedList;                  
+                       lastList = SharedList;  
+                                                               
                        SharedList = input->getSharedListVector(); //get new list vector to process
-                       count++;
                        
-                       //if (count != 1) { for (int i = 0; i < lastLookup.size(); i++) {  delete lastLookup[i];  } }
-                       //lastLookup = lookup; 
-                       //if (SharedList != NULL) { lookup = SharedList->getSharedRAbundVector(); }
+                       count++;                
                }
                
                //output error messages about any remaining user labels
@@ -103,14 +101,18 @@ int SharedCommand::execute(){
                
                //run last line if you need to
                if (needToRun == true)  {
-                       shared->getSharedVectors(lastList); //fills sharedGroups with new info and updates sharedVector
-                       printSharedData(); //prints info to the .shared file
+                       lookup = lastList->getSharedRAbundVector();
+                       printSharedData(lookup); //prints info to the .shared file
+                       for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }
+
                }
                
                delete lastList; globaldata->gSharedList = NULL;
-               delete shared;
+               delete read;
+               
                out.close();
                
+               cout << "complete." << endl;
                return 0;
        }
        catch(exception& e) {
@@ -124,19 +126,15 @@ int SharedCommand::execute(){
 
 }
 //**********************************************************************************************************************
-void SharedCommand::printSharedData() {
+void SharedCommand::printSharedData(vector<SharedRAbundVector*> thislookup) {
        try {
-       
-               ///for (int i = 0; i < thislookup.size(); i++) {
-               //      out << thislookup[i]->getLabel() << '\t' << thislookup[i]->getGroup() << '\t';
-//cout << thislookup[i]->getLabel() << '\t' << thislookup[i]->getGroup() << endl;                      
-               //      thislookup[i]->print(out);
-       //      }
-               //prints out horizontally
-               for (it = shared->sharedGroups.begin(); it != shared->sharedGroups.end(); it++) {
-                       out << it->second->getLabel() << "\t" << it->first << "\t"; //prints out label and groupname
-                       it->second->print(out); // prints sharedrabundvector
+               
+               //initialize bin values
+               for (int i = 0; i < thislookup.size(); i++) {
+                       out << thislookup[i]->getLabel() << '\t' << thislookup[i]->getGroup() << '\t';
+                       thislookup[i]->print(out);
                }
        }
        catch(exception& e) {
                cout << "Standard Error: " << e.what() << " has occurred in the SharedCommand class Function printSharedData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
@@ -153,7 +151,7 @@ void SharedCommand::printSharedData() {
 
 SharedCommand::~SharedCommand(){
        //delete list;
-       delete read;
+       
        
 }
 
index e5be50a8b9f80488449db640e65721d32f395a5d..ca0ddd833636e6550cb48832517cdc96f912977e 100644 (file)
@@ -12,7 +12,6 @@
 #include "command.hpp"
 #include "sharedlistvector.h"
 #include "inputdata.h"
-#include "shared.h"
 #include "readotu.h"
 
 /* The shared() command:
@@ -33,16 +32,16 @@ public:
        void help() {}
        
 private:
-       void printSharedData();
+       void printSharedData(vector<SharedRAbundVector*>);
        GlobalData* globaldata;
        ReadOTUFile* read;
        SharedListVector* SharedList;
        InputData* input;
-       Shared* shared;
-       map<string, SharedRAbundVector*>::iterator it;
+       //map<string, SharedRAbundVector*>::iterator it;
        //vector<SharedRAbundVector*> lookup;
        ofstream out;
        string filename;
+       bool firsttime;
 
 };
 
index 4774180dd6032c0de1b87597360af6d14e7c2a2d..3cb3e9e57c4da06f0589272cff4b3e97bd92eea4 100644 (file)
 
 /***********************************************************************/
 
-SharedListVector::SharedListVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){globaldata = GlobalData::getInstance();}
+SharedListVector::SharedListVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){globaldata = GlobalData::getInstance(); groupmap = NULL; }
 
 /***********************************************************************/
 
-SharedListVector::SharedListVector(int n):     DataVector(), data(n, "") , maxRank(0), numBins(0), numSeqs(0){globaldata = GlobalData::getInstance();}
+SharedListVector::SharedListVector(int n):     DataVector(), data(n, "") , maxRank(0), numBins(0), numSeqs(0){globaldata = GlobalData::getInstance(); groupmap = NULL; }
 
 /***********************************************************************/
 SharedListVector::SharedListVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) {
@@ -291,17 +291,38 @@ vector<SharedRAbundVector*> SharedListVector::getSharedRAbundVector() {
                SharedUtil* util;
                util = new SharedUtil();
                vector<SharedRAbundVector*> lookup;
+               map<string, SharedRAbundVector*> finder;
+               string group, names, name;
                
                util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups);
                
                delete util;
 
                for (int i = 0; i < globaldata->Groups.size(); i++) {
-                       SharedRAbundVector* temp = new SharedRAbundVector();
-                       *temp = getSharedRAbundVector(globaldata->Groups[i]);
-                       lookup.push_back(temp);
+                       SharedRAbundVector* temp = new SharedRAbundVector(data.size());
+                       finder[globaldata->Groups[i]] = temp;
+                       finder[globaldata->Groups[i]]->setLabel(label);
+                       finder[globaldata->Groups[i]]->setGroup(globaldata->Groups[i]);
+                       //*temp = getSharedRAbundVector(globaldata->Groups[i]);
+                       lookup.push_back(finder[globaldata->Groups[i]]);
                }
-
+               
+               //fill vectors
+               for(int i=0;i<numBins;i++){
+                       names = get(i);  
+                       while (names.find_first_of(',') != -1) { 
+                               name = names.substr(0,names.find_first_of(','));
+                               names = names.substr(names.find_first_of(',')+1, names.length());
+                               group = groupmap->getGroup(name);
+                               finder[group]->set(i, finder[group]->getAbundance(i) + 1, group);  //i represents what bin you are in
+                       }
+                       
+                       //get last name
+                       group = groupmap->getGroup(names);
+                       finder[group]->set(i, finder[group]->getAbundance(i) + 1, group);  //i represents what bin you are in
+                       
+               }
+               
                return lookup;
        }
        catch(exception& e) {
index 2c8d01bf4c257a715f789412a4391169138af9b6..0586dfff3ce56dbaae588639f14331c312b3fb84 100644 (file)
@@ -33,8 +33,8 @@ public:
        SharedListVector();
        SharedListVector(int);
        SharedListVector(ifstream&);
-       SharedListVector(const SharedListVector& lv) : DataVector(lv.label), data(lv.data), maxRank(lv.maxRank), numBins(lv.numBins), numSeqs(lv.numSeqs){globaldata = GlobalData::getInstance();};
-       ~SharedListVector(){};
+       SharedListVector(const SharedListVector& lv) : DataVector(lv.label), data(lv.data), maxRank(lv.maxRank), numBins(lv.numBins), numSeqs(lv.numSeqs){globaldata = GlobalData::getInstance(); groupmap = NULL; };
+       ~SharedListVector(){ if (groupmap != NULL) { delete groupmap; } };
        
        int getNumBins()                                                        {       return numBins;         }
        int getNumSeqs()                                                        {       return numSeqs;         }