]> git.donarmstrong.com Git - mothur.git/commitdiff
added ability for user to select which groups to analyze with the collect.shared...
authorwestcott <westcott>
Mon, 9 Mar 2009 14:33:50 +0000 (14:33 +0000)
committerwestcott <westcott>
Mon, 9 Mar 2009 14:33:50 +0000 (14:33 +0000)
collect.cpp
collectsharedcommand.cpp
collectsharedcommand.h
groupmap.cpp
groupmap.h
rarefact.cpp
rarefactsharedcommand.cpp
rarefactsharedcommand.h
summarysharedcommand.cpp
summarysharedcommand.h

index 80ad9183337260d83301ced05c99e6934eaf9991..7397d24ab30cbb968d4c02ae5522aa3d111ca05a 100644 (file)
@@ -66,11 +66,11 @@ try {
                 vector<SharedRAbundVector*> lookup; 
 
                 //create and initialize vector of sharedvectors, one for each group
-                for (int i = 0; i < globaldata->gGroupmap->getNumGroups(); i++) { 
+                for (int i = 0; i < globaldata->Groups.size(); i++) { 
                         SharedRAbundVector* temp = new SharedRAbundVector(sharedorder->getNumBins());
                         temp->setLabel(sharedorder->getLabel());
-                        temp->setGroup(globaldata->gGroupmap->namesOfGroups[i]);
-                        temp->setGroupIndex(globaldata->gGroupmap->groupIndex[globaldata->gGroupmap->namesOfGroups[i]]);
+                        temp->setGroup(globaldata->Groups[i]);
+                        temp->setGroupIndex(globaldata->gGroupmap->groupIndex[globaldata->Groups[i]]);
                         lookup.push_back(temp);
                 }
 
@@ -97,13 +97,14 @@ try {
                                         
                         //set info for sharedvector in chosens group
                         for (int j = 0; j < lookup.size(); j++) { 
-                                if (chosen.group == lookup[j]->getGroup()) {
-                                         abundance = lookup[j]->getAbundance(chosen.bin);
-                                         lookup[j]->set(chosen.bin, (abundance + 1), chosen.group);
-                                         break;
-                                }
+                                                       if (chosen.group == lookup[j]->getGroup()) {
+                                                               abundance = lookup[j]->getAbundance(chosen.bin);
+                                                               lookup[j]->set(chosen.bin, (abundance + 1), chosen.group);
+                                                               break;
+                                                       }
                         }
                         
+       
                         //calculate at 0 and the given increment
                         if((i == 0) || (i+1) % increment == 0){
                                 //randomize group order
@@ -112,7 +113,7 @@ try {
                                 int n = 1;
                                 for (int k = 0; k < (lookup.size() - 1); k++) { // pass cdd each set of groups to commpare
                                         for (int l = n; l < lookup.size(); l++) {
-                                                ccd->updateSharedData(lookup[k], lookup[l], i+1, globaldata->gGroupmap->namesOfGroups.size());
+                                                ccd->updateSharedData(lookup[k], lookup[l], i+1, globaldata->Groups.size());
                                         }
                                         n++;
                                 }
@@ -126,7 +127,7 @@ try {
                         int n = 1;
                         for (int k = 0; k < (lookup.size() - 1); k++) { // pass cdd each set of groups to commpare
                                 for (int l = n; l < lookup.size(); l++) {
-                                        ccd->updateSharedData(lookup[k], lookup[l], totalNumSeq, globaldata->gGroupmap->namesOfGroups.size());
+                                        ccd->updateSharedData(lookup[k], lookup[l], totalNumSeq, globaldata->Groups.size());
                                 }
                                 n++;
                         }
@@ -151,19 +152,19 @@ try {
 /**************************************************************************************/
 
 void Collect::getGroupComb() {
-                string group;
+       string group;
                 
-                numGroupComb = 0;
+       numGroupComb = 0;
                 
-                int n = 1;
-                for (int i = 0; i < (globaldata->gGroupmap->getNumGroups() - 1); i++) {
-                        for (int l = n; l < globaldata->gGroupmap->getNumGroups(); l++) {
-                                group = globaldata->gGroupmap->namesOfGroups[i] + globaldata->gGroupmap->namesOfGroups[l];
-                                groupComb.push_back(group);        
-                                numGroupComb++;
-                        }
-                        n++;
-                }
+       int n = 1;
+       for (int i = 0; i < (globaldata->Groups.size() - 1); i++) {
+               for (int l = n; l < globaldata->Groups.size(); l++) {
+                       group = globaldata->Groups[i] + globaldata->Groups[l];
+                       groupComb.push_back(group);        
+                       numGroupComb++;
+               }
+               n++;
+       }
 
 }
 
index 8c04545d61fc321382122526bc53e4c2892321eb..c473c2d77e819164d62799095ea6bf849d27c42a 100644 (file)
@@ -31,6 +31,9 @@ CollectSharedCommand::CollectSharedCommand(){
                format = globaldata->getFormat();
                validCalculator = new ValidCalculators();
                
+               //set users groups
+               setGroups();
+               
                int i;
                for (i=0; i<globaldata->Estimators.size(); i++) {
                        if (validCalculator->isValidCalculator("shared", globaldata->Estimators[i]) == true) { 
@@ -143,6 +146,10 @@ int CollectSharedCommand::execute(){
                        if(orderList.count(*i) == 0)
                                cout << "'" << *i << "'" << " is not a valid label.\n";
                for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }       
+               
+               //reset groups parameter
+               globaldata->Groups.clear();  globaldata->setGroups("");
+               
                return 0;
        }
        catch(exception& e) {
@@ -157,3 +164,50 @@ int CollectSharedCommand::execute(){
 
 
 //**********************************************************************************************************************
+void CollectSharedCommand::setGroups() {
+       try {
+               //if the user has not entered specific groups to analyze then do them all
+               if (globaldata->Groups.size() != 0) {
+                       if (globaldata->Groups[0] != "all") {
+                               //check that groups are valid
+                               for (int i = 0; i < globaldata->Groups.size(); i++) {
+                                       if (globaldata->gGroupmap->isValidGroup(globaldata->Groups[i]) != true) {
+                                               cout << globaldata->Groups[i] << " is not a valid group, and will be disregarded." << endl;
+                                               // erase the invalid group from globaldata->Groups
+                                               globaldata->Groups.erase(globaldata->Groups.begin()+i);
+                                       }
+                               }
+                       
+                               //if the user only entered invalid groups
+                               if ((globaldata->Groups.size() == 0) || (globaldata->Groups.size() == 1)) { 
+                                       cout << "When using the groups parameter you must have at least 2 valid groups. I will run the command using all the groups in your groupfile." << endl; 
+                                       for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
+                                               globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
+                                       }
+                               }
+                       }else{//user has enter "all" and wants the default groups
+                               globaldata->Groups.clear();
+                               for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
+                                       globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
+                               }
+                               globaldata->setGroups("");
+                       }
+               }else {
+                       for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
+                               globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
+                       }
+               }
+               
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the CollectSharedCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+
+}
+/***********************************************************/
+
index 6e9d5cc3f498c96574d93321ecf2823edb0fa004..c5c24b2f974e504e5c8ef079d15a89026291b992 100644 (file)
@@ -54,6 +54,7 @@ private:
        vector<Display*> cDisplays;
        int freq;
        string format;
+       void setGroups();
 
 };
 
index 1f22013699014c6afa0b6de5b7ce1722c43acbc0..63fb4655da35529a694609dbb368094d9585a194 100644 (file)
@@ -71,3 +71,21 @@ void GroupMap::setNamesOfGroups(string seqGroup) {
                                index++;
                        }
 }
+/************************************************************/
+bool GroupMap::isValidGroup(string groupname) {
+       try {
+               for (int i = 0; i < namesOfGroups.size(); i++) {
+                       if (groupname == namesOfGroups[i]) { return true; }
+               }
+               
+               return false;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the GroupMap class Function isValidGroup. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the GroupMap class function isValidGroup. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
index d03880d9814fac255613daa381f6d63b4ccfba4a..20048a59a5f5aaa3658dd5697f26e3f255a978e1 100644 (file)
@@ -22,6 +22,7 @@ public:
        ~GroupMap();
        void readMap();
        int getNumGroups();
+       bool isValidGroup(string);  //return true if string is a valid group
        string getGroup(string);
        void setGroup(string, string);
        vector<string> namesOfGroups;
index e776393b47318e8a7f9b79016433f75a8ba049d9..c064125c37e846c538075f04d652eca6ec336708 100644 (file)
@@ -85,10 +85,10 @@ try {
                        lookup.clear();
                
                        //create and initialize vector of sharedvectors, one for each group
-                       for (int i = 0; i < globaldata->gGroupmap->getNumGroups(); i++) { 
+                       for (int i = 0; i < globaldata->Groups.size(); i++) { 
                                SharedRAbundVector* temp = new SharedRAbundVector(sharedorder->getNumBins());
                                temp->setLabel(sharedorder->getLabel());
-                               temp->setGroup(globaldata->gGroupmap->namesOfGroups[i]);
+                               temp->setGroup(globaldata->Groups[i]);
                                lookup.push_back(temp);
                        }
                        
index 45c2e2ebbdfc0004a8e1d6acb551649fe82b1239..9bd8805f4867a6e445b42324d8b13d406471eace 100644 (file)
@@ -19,6 +19,8 @@ RareFactSharedCommand::RareFactSharedCommand(){
                fileNameRoot = getRootName(globaldata->inputFileName);
                format = globaldata->getFormat();
                validCalculator = new ValidCalculators();
+               
+               setGroups();
                                
                int i;
                for (i=0; i<globaldata->Estimators.size(); i++) {
@@ -109,6 +111,10 @@ int RareFactSharedCommand::execute(){
                }
        
                for(int i=0;i<rDisplays.size();i++){    delete rDisplays[i];    }       
+               
+               //reset groups parameter
+               globaldata->Groups.clear();  globaldata->setGroups("");
+
                return 0;
        }
        catch(exception& e) {
@@ -123,3 +129,51 @@ int RareFactSharedCommand::execute(){
 
 
 //**********************************************************************************************************************
+
+void RareFactSharedCommand::setGroups() {
+       try {
+               //if the user has not entered specific groups to analyze then do them all
+               if (globaldata->Groups.size() != 0) {
+                       if (globaldata->Groups[0] != "all") {
+                               //check that groups are valid
+                               for (int i = 0; i < globaldata->Groups.size(); i++) {
+                                       if (globaldata->gGroupmap->isValidGroup(globaldata->Groups[i]) != true) {
+                                               cout << globaldata->Groups[i] << " is not a valid group, and will be disregarded." << endl;
+                                               // erase the invalid group from globaldata->Groups
+                                               globaldata->Groups.erase(globaldata->Groups.begin()+i);
+                                       }
+                               }
+                       
+                               //if the user only entered invalid groups
+                               if ((globaldata->Groups.size() == 0) || (globaldata->Groups.size() == 1)) { 
+                                       cout << "When using the groups parameter you must have at least 2 valid groups. I will run the command using all the groups in your groupfile." << endl; 
+                                       for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
+                                               globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
+                                       }
+                               }
+                       }else{//user has enter "all" and wants the default groups
+                               globaldata->Groups.clear();
+                               for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
+                                       globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
+                               }
+                               globaldata->setGroups("");
+                       }
+               }else {
+                       for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
+                               globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
+                       }
+               }
+               
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the RareFactSharedCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the RareFactSharedCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+
+}
+/***********************************************************/
+
index 54a6a95024d0fd97f279be2e50f3e31906f308a4..b5b638fc3b7a408ef8198f55d5309e64afa2b3f5 100644 (file)
@@ -40,6 +40,7 @@ public:
        int execute();  
        
 private:
+       void setGroups();
        GlobalData* globaldata;
        SharedListVector* SharedList;
        ReadMatrix* read;
index f31f7e10e1f19e47781d2d47dd9db09ebafa05cf..fcd2b00ea28805a54646524d831dd90d9784100e 100644 (file)
@@ -20,6 +20,7 @@
 #include "sharedthetayc.h"
 #include "sharedthetan.h"
 
+
 //**********************************************************************************************************************
 
 SummarySharedCommand::SummarySharedCommand(){
@@ -30,6 +31,9 @@ SummarySharedCommand::SummarySharedCommand(){
                format = globaldata->getFormat();
                validCalculator = new ValidCalculators();
                
+               //set users groups
+               setGroups();
+               
                int i;
                for (i=0; i<globaldata->Estimators.size(); i++) {
                        if (validCalculator->isValidCalculator("sharedsummary", globaldata->Estimators[i]) == true) { 
@@ -150,7 +154,10 @@ int SummarySharedCommand::execute(){
                        }
                        count++;
                }
-       
+               
+               //reset groups parameter
+               globaldata->Groups.clear();  globaldata->setGroups("");
+
                return 0;
        }
        catch(exception& e) {
@@ -191,8 +198,15 @@ try {
                                         break;
                                }
                        }
-                       
                }
+               
+               //get rid of vectors from groups you don't want to analyze
+               for (int r = 0; r < lookup.size(); r++) { 
+                       if (inUsersGroups(lookup[r]->getGroup(), globaldata->Groups) != true) {
+                               lookup.erase(lookup.begin()+r);
+                       }
+               }
+               
        }
        catch(exception& e) {
                cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
@@ -206,3 +220,49 @@ try {
 }
 
 //**********************************************************************************************************************
+void SummarySharedCommand::setGroups() {
+       try {
+               //if the user has not entered specific groups to analyze then do them all
+               if (globaldata->Groups.size() != 0) {
+                       if (globaldata->Groups[0] != "all") {
+                               //check that groups are valid
+                               for (int i = 0; i < globaldata->Groups.size(); i++) {
+                                       if (globaldata->gGroupmap->isValidGroup(globaldata->Groups[i]) != true) {
+                                               cout << globaldata->Groups[i] << " is not a valid group, and will be disregarded." << endl;
+                                               // erase the invalid group from globaldata->Groups
+                                               globaldata->Groups.erase(globaldata->Groups.begin()+i);
+                                       }
+                               }
+                       
+                               //if the user only entered invalid groups
+                               if ((globaldata->Groups.size() == 0) || (globaldata->Groups.size() == 1)) { 
+                                       cout << "When using the groups parameter you must have at least 2 valid groups. I will run the command using all the groups in your groupfile." << endl; 
+                                       for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
+                                               globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
+                                       }
+                               }
+                       }else{//user has enter "all" and wants the default groups
+                               globaldata->Groups.clear();
+                               for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
+                                       globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
+                               }
+                               globaldata->setGroups("");
+                       }
+               }else {
+                       for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
+                               globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
+                       }
+               }
+               
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SummarySharedCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+
+}
+/***********************************************************/
index 0e3428d35721d19573153f04a4e19cd693cca6f3..248c1c8ecb81f2bbc069b25151c3908e05330907 100644 (file)
@@ -44,6 +44,7 @@ public:
        
 private:
        void getSharedVectors();
+       void setGroups();
        
        GlobalData* globaldata;
        ReadMatrix* read;