]> git.donarmstrong.com Git - mothur.git/blobdiff - sharedlistvector.cpp
added load.logfile command. changed summary.single output for subsample=t.
[mothur.git] / sharedlistvector.cpp
index a113ebe7e82e93f135541b0bfa0ffc7a3b1d33b1..6dfcb97f0aff013d15c1c641e93a24b0d7b229a3 100644 (file)
 
 /***********************************************************************/
 
-SharedListVector::SharedListVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){globaldata = GlobalData::getInstance(); groupmap = NULL; }
+SharedListVector::SharedListVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){ groupmap = NULL; }
 
 /***********************************************************************/
 
-SharedListVector::SharedListVector(int n):     DataVector(), data(n, "") , maxRank(0), numBins(0), numSeqs(0){globaldata = GlobalData::getInstance(); groupmap = NULL; }
+SharedListVector::SharedListVector(int n):     DataVector(), data(n, "") , maxRank(0), numBins(0), numSeqs(0){ groupmap = NULL; }
 
 /***********************************************************************/
 SharedListVector::SharedListVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) {
        try {
-               globaldata = GlobalData::getInstance();
-
                //set up groupmap for later.
-               groupmap = new GroupMap(globaldata->getGroupFile());
-               groupmap->readMap();
+               groupmap = new GroupMap(m->getGroupFile());
+               groupmap->readMap(); 
 
                int hold;
                string inputData;
                f >> label >> hold;
        
                data.assign(hold, "");
-       
+               
                for(int i=0;i<hold;i++){
                        f >> inputData;
                        set(i, inputData);
                }
-       
+               
        }
        catch(exception& e) {
-               errorOut(e, "SharedListVector", "SharedListVector");
+               m->errorOut(e, "SharedListVector", "SharedListVector");
                exit(1);
        }
 }
@@ -52,18 +50,20 @@ SharedListVector::SharedListVector(ifstream& f) : DataVector(), maxRank(0), numB
 /***********************************************************************/
 void SharedListVector::set(int binNumber, string seqNames){
        try {
-               int nNames_old = getNumNames(data[binNumber]);
+               int nNames_old = m->getNumNames(data[binNumber]);
                data[binNumber] = seqNames;
-               int nNames_new = getNumNames(seqNames);
+               int nNames_new = m->getNumNames(seqNames);
        
                if(nNames_old == 0)                     {       numBins++;                              }
                if(nNames_new == 0)                     {       numBins--;                              }
                if(nNames_new > maxRank)        {       maxRank = nNames_new;   }
        
                numSeqs += (nNames_new - nNames_old);
+               
+                        
        }
        catch(exception& e) {
-               errorOut(e, "SharedListVector", "set");
+               m->errorOut(e, "SharedListVector", "set");
                exit(1);
        }
 }
@@ -79,7 +79,7 @@ string SharedListVector::get(int index){
 void SharedListVector::push_back(string seqNames){
        try {
                data.push_back(seqNames);
-               int nNames = getNumNames(seqNames);
+               int nNames = m->getNumNames(seqNames);
        
                numBins++;
        
@@ -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);
        }
 }
@@ -141,7 +141,7 @@ RAbundVector SharedListVector::getRAbundVector(){
                RAbundVector rav;
        
                for(int i=0;i<data.size();i++){
-                       int binSize = getNumNames(data[i]);
+                       int binSize = m->getNumNames(data[i]);
                        rav.push_back(binSize);
                }
        
@@ -159,7 +159,7 @@ RAbundVector SharedListVector::getRAbundVector(){
                return rav;
        }
        catch(exception& e) {
-               errorOut(e, "SharedListVector", "getRAbundVector");
+               m->errorOut(e, "SharedListVector", "getRAbundVector");
                exit(1);
        }
 }
@@ -171,7 +171,7 @@ SAbundVector SharedListVector::getSAbundVector(){
                SAbundVector sav(maxRank+1);
        
                for(int i=0;i<data.size();i++){
-                       int binSize = getNumNames(data[i]);     
+                       int binSize = m->getNumNames(data[i]);  
                        sav.set(binSize, sav.get(binSize) + 1); 
                }
                sav.set(0, 0);
@@ -180,7 +180,7 @@ SAbundVector SharedListVector::getSAbundVector(){
                return sav;
        }
        catch(exception& e) {
-               errorOut(e, "SharedListVector", "getSAbundVector");
+               m->errorOut(e, "SharedListVector", "getSAbundVector");
                exit(1);
        }
 }
@@ -194,20 +194,20 @@ SharedOrderVector* SharedListVector::getSharedOrderVector(){
                order->setLabel(label);
        
                for(int i=0;i<numBins;i++){
-                       int binSize = getNumNames(get(i));      //find number of individual in given bin        
+                       int binSize = m->getNumNames(get(i));   //find number of individual in given bin        
                        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());
                                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,45 +263,69 @@ vector<SharedRAbundVector*> SharedListVector::getSharedRAbundVector() {
        try {
                SharedUtil* util;
                util = new SharedUtil();
-               vector<SharedRAbundVector*> lookup;
-               map<string, SharedRAbundVector*> finder;
+               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);
-               
+               vector<string> Groups = m->getGroups();
+               vector<string> allGroups = groupmap->getNamesOfGroups();
+               util->setGroups(Groups, allGroups);
+               m->setGroups(Groups);
                delete util;
 
-               for (int i = 0; i < globaldata->Groups.size(); i++) {
+               for (int i = 0; i < allGroups.size(); i++) {
                        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]]);
+                       finder[allGroups[i]] = temp;
+                       finder[allGroups[i]]->setLabel(label);
+                       finder[allGroups[i]]->setGroup(allGroups[i]);
+                       if (m->inUsersGroups(allGroups[i], m->getGroups())) {  //if this group is in user groups
+                               lookup.push_back(finder[allGroups[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);
-                               if(group == "not found") {      mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); mothurOutEndLine();  exit(1); }
-                               finder[group]->set(i, finder[group]->getAbundance(i) + 1, group);  //i represents what bin you are in
+                       int nameLength = names.size();
+                       string seqName = "";
+                       
+                       for(int j=0;j<nameLength;j++){
+                               if(names[j] == ','){
+                                       group = groupmap->getGroup(seqName);
+                                       if(group == "not found") {      m->mothurOut("Error: Sequence '" + seqName + "' 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
+                                       
+                                       seqName = "";
+                               }
+                               else{
+                                       seqName += names[j];
+                               }
                        }
+                       group = groupmap->getGroup(seqName);
+                       if(group == "not found") {      m->mothurOut("Error: Sequence '" + seqName + "' 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
+                       
+                       
+                       
+//                     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);
+//                             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);
-                       if(group == "not found") {      mothurOut("Error: Sequence '" + names + "' was not found in the group file, please correct."); mothurOutEndLine();  exit(1); }
-                       finder[group]->set(i, finder[group]->getAbundance(i) + 1, group);  //i represents what bin you are in
+//                     group = groupmap->getGroup(names);
+//                     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
                        
                }
-               
+
                return lookup;
        }
        catch(exception& e) {
-               errorOut(e, "SharedListVector", "getSharedRAbundVector");
+               m->errorOut(e, "SharedListVector", "getSharedRAbundVector");
                exit(1);
        }
 }
@@ -318,7 +342,7 @@ SharedSAbundVector SharedListVector::getSharedSAbundVector(string groupName) {
                return sav;
        }
        catch(exception& e) {
-               errorOut(e, "SharedListVector", "getSharedSAbundVector");
+               m->errorOut(e, "SharedListVector", "getSharedSAbundVector");
                exit(1);
        }
 }
@@ -331,7 +355,7 @@ OrderVector SharedListVector::getOrderVector(map<string,int>* orderMap = NULL){
                        OrderVector ov;
                
                        for(int i=0;i<data.size();i++){
-                               int binSize = getNumNames(data[i]);             
+                               int binSize = m->getNumNames(data[i]);          
                                for(int j=0;j<binSize;j++){
                                        ov.push_back(i);
                                }
@@ -359,7 +383,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);
                                                }
                                        
@@ -369,7 +393,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);        
@@ -382,7 +406,7 @@ OrderVector SharedListVector::getOrderVector(map<string,int>* orderMap = NULL){
                }
        }
        catch(exception& e) {
-               errorOut(e, "SharedListVector", "getOrderVector");
+               m->errorOut(e, "SharedListVector", "getOrderVector");
                exit(1);
        }
 }