]> git.donarmstrong.com Git - mothur.git/blobdiff - sharedordervector.cpp
check in for trip
[mothur.git] / sharedordervector.cpp
index e1ede6d0e8048ee46cdc38b33ef47b76ffa03624..ca26362672e130364f66ed8bd005ae8fa9d68d4c 100644 (file)
@@ -28,10 +28,9 @@ SharedOrderVector::SharedOrderVector(string id, vector<individual>  ov) :
 
 SharedOrderVector::SharedOrderVector(ifstream& f) : DataVector() {  //reads in a shared file
        try {
-               globaldata = GlobalData::getInstance();
                maxRank = 0; numBins = 0; numSeqs = 0;
-               
-               if (globaldata->gGroupmap == NULL) {  groupmap = new GroupMap(); }
+                               
+               groupmap = new GroupMap(); 
                
                int num, inputData, count;
                count = 0;  numSeqs = 0;
@@ -42,11 +41,11 @@ SharedOrderVector::SharedOrderVector(ifstream& f) : DataVector() {  //reads in a
                f >> label >> groupN >> num;
                holdLabel = label;
                
-               if (globaldata->gGroupmap == NULL) { 
-                       //save group in groupmap
-                       groupmap->namesOfGroups.push_back(groupN);
-                       groupmap->groupIndex[groupN] = 0;
-               }
+               vector<string> allGroups;
+               //save group in groupmap
+               allGroups.push_back(groupN);
+               groupmap->groupIndex[groupN] = 0;
+               
                
                for(int i=0;i<num;i++){
                        f >> inputData;
@@ -57,7 +56,7 @@ SharedOrderVector::SharedOrderVector(ifstream& f) : DataVector() {  //reads in a
                        }
                }
                
-               gobble(f); 
+               m->gobble(f); 
                
                if (f.eof() != true) { f >> nextLabel; }
                
@@ -66,11 +65,11 @@ SharedOrderVector::SharedOrderVector(ifstream& f) : DataVector() {  //reads in a
                        f >> groupN >> num;
                        count++;
                        
-                       if (globaldata->gGroupmap == NULL) { 
-                               //save group in groupmap
-                               groupmap->namesOfGroups.push_back(groupN);
-                               groupmap->groupIndex[groupN] = count;
-                       }
+                       
+                       //save group in groupmap
+                       allGroups.push_back(groupN);
+                       groupmap->groupIndex[groupN] = count;
+                       
                        
                        for(int i=0;i<num;i++){
                                f >> inputData;
@@ -81,7 +80,7 @@ SharedOrderVector::SharedOrderVector(ifstream& f) : DataVector() {  //reads in a
                                }
                        }
                        
-                       gobble(f);
+                       m->gobble(f);
                                
                        if (f.eof() != true) { f >> nextLabel; }
 
@@ -89,14 +88,15 @@ SharedOrderVector::SharedOrderVector(ifstream& f) : DataVector() {  //reads in a
                
                //put file pointer back since you are now at a new distance label
                for (int i = 0; i < nextLabel.length(); i++) { f.unget();  }
-       
-               if (globaldata->gGroupmap == NULL) { globaldata->gGroupmap = groupmap; }
+               
+               groupmap->setNamesOfGroups(allGroups);
+               m->setAllGroups(allGroups);
                
                updateStats();
                
        }
        catch(exception& e) {
-               errorOut(e, "SharedOrderVector", "SharedOrderVector");
+               m->errorOut(e, "SharedOrderVector", "SharedOrderVector");
                exit(1);
        }
 }
@@ -166,16 +166,23 @@ void SharedOrderVector::print(ostream& output){
                output << endl;
        }
        catch(exception& e) {
-               errorOut(e, "SharedOrderVector", "print");
+               m->errorOut(e, "SharedOrderVector", "print");
                exit(1);
        }
 }
 
+/***********************************************************************/
 
+void SharedOrderVector::clear(){
+       numBins = 0;
+       maxRank = 0;
+       numSeqs = 0;
+       data.clear();
+}
 /***********************************************************************/
 
 void SharedOrderVector::resize(int){
-       mothurOut("resize() did nothing in class SharedOrderVector");
+       m->mothurOut("resize() did nothing in class SharedOrderVector");
 }
 
 /***********************************************************************/
@@ -218,7 +225,7 @@ RAbundVector SharedOrderVector::getRAbundVector(){
                return rav;
        }
        catch(exception& e) {
-               errorOut(e, "SharedOrderVector", "getRAbundVector");
+               m->errorOut(e, "SharedOrderVector", "getRAbundVector");
                exit(1);
        }
 }
@@ -238,7 +245,7 @@ OrderVector SharedOrderVector::getOrderVector(map<string,int>* nameMap = NULL) {
                return ov;
        }
        catch(exception& e) {
-               errorOut(e, "SharedOrderVector", "getOrderVector");
+               m->errorOut(e, "SharedOrderVector", "getOrderVector");
                exit(1);
        }
 }
@@ -268,7 +275,7 @@ SharedRAbundVector SharedOrderVector::getSharedRAbundVector(string group) {
                return sharedRav;
        }
        catch(exception& e) {
-               errorOut(e, "SharedOrderVector", "getSharedRAbundVector");
+               m->errorOut(e, "SharedOrderVector", "getSharedRAbundVector");
                exit(1);
        }
 }
@@ -279,13 +286,17 @@ vector<SharedRAbundVector*> SharedOrderVector::getSharedRAbundVector() {
                util = new SharedUtil();
                vector<SharedRAbundVector*> lookup;
                
-               util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups);
-               util->getSharedVectors(globaldata->Groups, lookup, this);
+               vector<string> Groups = m->getGroups();
+               vector<string> allGroups = m->getAllGroups();
+               util->setGroups(Groups, allGroups);
+               util->getSharedVectors(Groups, lookup, this);
+               m->setGroups(Groups);
+               m->setAllGroups(allGroups);
                
                return lookup;
        }
        catch(exception& e) {
-               errorOut(e, "SharedOrderVector", "getSharedRAbundVector");
+               m->errorOut(e, "SharedOrderVector", "getSharedRAbundVector");
                exit(1);
        }
 }
@@ -298,7 +309,7 @@ SharedSAbundVector SharedOrderVector::getSharedSAbundVector(string group) {
                                
        }
        catch(exception& e) {
-               errorOut(e, "SharedOrderVector", "getSharedSAbundVector");
+               m->errorOut(e, "SharedOrderVector", "getSharedSAbundVector");
                exit(1);
        }
 }
@@ -333,7 +344,7 @@ void SharedOrderVector::updateStats(){
                
        }
        catch(exception& e) {
-               errorOut(e, "SharedOrderVector", "updateStats");
+               m->errorOut(e, "SharedOrderVector", "updateStats");
                exit(1);
        }
 }