]> git.donarmstrong.com Git - mothur.git/blobdiff - sharedlistvector.cpp
fixed bug in cluster.split
[mothur.git] / sharedlistvector.cpp
index 6cac9b1d9512a16d15eef553d351de0b16771b6e..cc3cd8df4205e2f37182a8a80037bc02bb37ca45 100644 (file)
@@ -44,7 +44,7 @@ SharedListVector::SharedListVector(ifstream& f) : DataVector(), maxRank(0), numB
        
        }
        catch(exception& e) {
-               errorOut(e, "SharedListVector", "SharedListVector");
+               m->errorOut(e, "SharedListVector", "SharedListVector");
                exit(1);
        }
 }
@@ -63,7 +63,7 @@ void SharedListVector::set(int binNumber, string seqNames){
                numSeqs += (nNames_new - nNames_old);
        }
        catch(exception& e) {
-               errorOut(e, "SharedListVector", "set");
+               m->errorOut(e, "SharedListVector", "set");
                exit(1);
        }
 }
@@ -88,7 +88,7 @@ void SharedListVector::push_back(string seqNames){
                numSeqs += nNames;
        }
        catch(exception& e) {
-               errorOut(e, "SharedListVector", "push_back");
+               m->errorOut(e, "SharedListVector", "push_back");
                exit(1);
        }
 }
@@ -128,7 +128,7 @@ void SharedListVector::print(ostream& output){
                output << endl;
        }
        catch(exception& e) {
-               errorOut(e, "SharedListVector", "print");
+               m->errorOut(e, "SharedListVector", "print");
                exit(1);
        }
 }
@@ -159,7 +159,7 @@ RAbundVector SharedListVector::getRAbundVector(){
                return rav;
        }
        catch(exception& e) {
-               errorOut(e, "SharedListVector", "getRAbundVector");
+               m->errorOut(e, "SharedListVector", "getRAbundVector");
                exit(1);
        }
 }
@@ -180,7 +180,7 @@ SAbundVector SharedListVector::getSAbundVector(){
                return sav;
        }
        catch(exception& e) {
-               errorOut(e, "SharedListVector", "getSAbundVector");
+               m->errorOut(e, "SharedListVector", "getSAbundVector");
                exit(1);
        }
 }
@@ -201,13 +201,13 @@ SharedOrderVector* SharedListVector::getSharedOrderVector(){
                                names = names.substr(names.find_first_of(',')+1, names.length());
                                groupName = groupmap->getGroup(name);
                                
-                               if(groupName == "not found") {  mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); mothurOutEndLine();  exit(1); }
+                               if(groupName == "not found") {  m->mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); m->mothurOutEndLine();  exit(1); }
                                
                                order->push_back(i, binSize, groupName);  //i represents what bin you are in
                        }
                        //get last name
                        groupName = groupmap->getGroup(names);
-                       if(groupName == "not found") {  mothurOut("Error: Sequence '" + names + "' was not found in the group file, please correct."); mothurOutEndLine();  exit(1); }
+                       if(groupName == "not found") {  m->mothurOut("Error: Sequence '" + names + "' was not found in the group file, please correct."); m->mothurOutEndLine();  exit(1); }
                        order->push_back(i, binSize, groupName);
                }
 
@@ -217,7 +217,7 @@ SharedOrderVector* SharedListVector::getSharedOrderVector(){
                return order;
        }
        catch(exception& e) {
-               errorOut(e, "SharedListVector", "getSharedOrderVector");
+               m->errorOut(e, "SharedListVector", "getSharedOrderVector");
                exit(1);
        }
 }
@@ -233,7 +233,7 @@ SharedRAbundVector SharedListVector::getSharedRAbundVector(string groupName) {
                                name = names.substr(0,names.find_first_of(','));
                                names = names.substr(names.find_first_of(',')+1, names.length());
                                group = groupmap->getGroup(name);
-                               if(group == "not found") {      mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); mothurOutEndLine();  exit(1); }
+                               if(group == "not found") {      m->mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); m->mothurOutEndLine();  exit(1); }
                                if (group == groupName) { //this name is in the group you want the vector for.
                                        rav.set(i, rav.getAbundance(i) + 1, group);  //i represents what bin you are in
                                }
@@ -241,7 +241,7 @@ SharedRAbundVector SharedListVector::getSharedRAbundVector(string groupName) {
                        
                        //get last name
                        groupName = groupmap->getGroup(names);
-                       if(groupName == "not found") {  mothurOut("Error: Sequence '" + names + "' was not found in the group file, please correct."); mothurOutEndLine();  exit(1); }
+                       if(groupName == "not found") {  m->mothurOut("Error: Sequence '" + names + "' was not found in the group file, please correct."); m->mothurOutEndLine();  exit(1); }
                        if (group == groupName) { //this name is in the group you want the vector for.
                                        rav.set(i, rav.getAbundance(i) + 1, group);  //i represents what bin you are in
                        }
@@ -254,7 +254,7 @@ SharedRAbundVector SharedListVector::getSharedRAbundVector(string groupName) {
                
        }
        catch(exception& e) {
-               errorOut(e, "SharedListVector", "getSharedRAbundVector");
+               m->errorOut(e, "SharedListVector", "getSharedRAbundVector");
                exit(1);
        }
 }
@@ -263,10 +263,8 @@ vector<SharedRAbundVector*> SharedListVector::getSharedRAbundVector() {
        try {
                SharedUtil* util;
                util = new SharedUtil();
-               vector<SharedRAbundVector*> lookup;
-               vector<SharedRAbundVector*> lookup2;
-               map<string, SharedRAbundVector*> finder;
-               map<string, SharedRAbundVector*>::iterator it;
+               vector<SharedRAbundVector*> lookup;  //contains just the groups the user selected
+               map<string, SharedRAbundVector*> finder;  //contains all groups in groupmap
                string group, names, name;
        
                util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups);
@@ -277,10 +275,11 @@ vector<SharedRAbundVector*> SharedListVector::getSharedRAbundVector() {
                        finder[globaldata->gGroupmap->namesOfGroups[i]] = temp;
                        finder[globaldata->gGroupmap->namesOfGroups[i]]->setLabel(label);
                        finder[globaldata->gGroupmap->namesOfGroups[i]]->setGroup(globaldata->gGroupmap->namesOfGroups[i]);
-                       //*temp = getSharedRAbundVector(globaldata->Groups[i]);
-                       lookup.push_back(finder[globaldata->gGroupmap->namesOfGroups[i]]);
+                       if (inVector(globaldata->gGroupmap->namesOfGroups[i], globaldata->Groups)) {  //if this group is in user groups
+                               lookup.push_back(finder[globaldata->gGroupmap->namesOfGroups[i]]);
+                       }
                }
-//cout << "after blanks" << endl;              
+       
                //fill vectors
                for(int i=0;i<numBins;i++){
                        names = get(i);  
@@ -288,33 +287,21 @@ vector<SharedRAbundVector*> SharedListVector::getSharedRAbundVector() {
                                name = names.substr(0,names.find_first_of(','));
                                names = names.substr(names.find_first_of(',')+1, names.length());
                                group = groupmap->getGroup(name);
-//cout << i << '\t' << name << '\t' << group << endl;
-                               if(group == "not found") {      mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); mothurOutEndLine();  exit(1); }
+                               if(group == "not found") {      m->mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); m->mothurOutEndLine();  exit(1); }
                                finder[group]->set(i, finder[group]->getAbundance(i) + 1, group);  //i represents what bin you are in
                        }
                        
                        //get last name
                        group = groupmap->getGroup(names);
-//cout << i << '\t' << names << '\t' << group << endl;
-                       if(group == "not found") {      mothurOut("Error: Sequence '" + names + "' was not found in the group file, please correct."); mothurOutEndLine();  exit(1); }
+                       if(group == "not found") {      m->mothurOut("Error: Sequence '" + names + "' was not found in the group file, please correct."); m->mothurOutEndLine();  exit(1); }
                        finder[group]->set(i, finder[group]->getAbundance(i) + 1, group);  //i represents what bin you are in
                        
                }
                
-               if (globaldata->Groups.size() == globaldata->gGroupmap->namesOfGroups.size()) { //no groups specified
-                       lookup2 = lookup;
-               }else{ //delete unwanted groups
-                       for (int i = 0; i < globaldata->Groups.size(); i++) {
-                               SharedRAbundVector* temp = new SharedRAbundVector(*finder[globaldata->Groups[i]]);
-                               lookup2.push_back(temp);
-                               delete finder[globaldata->Groups[i]];  //so we don't get dup memory
-                       }
-               }
-               
-               return lookup2;
+               return lookup;
        }
        catch(exception& e) {
-               errorOut(e, "SharedListVector", "getSharedRAbundVector");
+               m->errorOut(e, "SharedListVector", "getSharedRAbundVector");
                exit(1);
        }
 }
@@ -331,7 +318,7 @@ SharedSAbundVector SharedListVector::getSharedSAbundVector(string groupName) {
                return sav;
        }
        catch(exception& e) {
-               errorOut(e, "SharedListVector", "getSharedSAbundVector");
+               m->errorOut(e, "SharedListVector", "getSharedSAbundVector");
                exit(1);
        }
 }
@@ -372,7 +359,7 @@ OrderVector SharedListVector::getOrderVector(map<string,int>* orderMap = NULL){
                                        }
                                        else{
                                                if(orderMap->count(seqName) == 0){
-                                                       mothurOut(seqName + " not found, check *.names file\n");
+                                                       m->mothurOut(seqName + " not found, check *.names file\n");
                                                        exit(1);
                                                }
                                        
@@ -382,7 +369,7 @@ OrderVector SharedListVector::getOrderVector(map<string,int>* orderMap = NULL){
                                }
                        
                                if(orderMap->count(seqName) == 0){
-                                       mothurOut(seqName + " not found, check *.names file\n");
+                                       m->mothurOut(seqName + " not found, check *.names file\n");
                                        exit(1);
                                }
                                ov.set((*orderMap)[seqName], i);        
@@ -395,7 +382,7 @@ OrderVector SharedListVector::getOrderVector(map<string,int>* orderMap = NULL){
                }
        }
        catch(exception& e) {
-               errorOut(e, "SharedListVector", "getOrderVector");
+               m->errorOut(e, "SharedListVector", "getOrderVector");
                exit(1);
        }
 }