]> git.donarmstrong.com Git - mothur.git/commitdiff
fixed bug with displaying info for collect.shared() and summary.shared().
authorwestcott <westcott>
Thu, 12 Feb 2009 14:52:49 +0000 (14:52 +0000)
committerwestcott <westcott>
Thu, 12 Feb 2009 14:52:49 +0000 (14:52 +0000)
14 files changed:
Mothur.xcodeproj/project.pbxproj
collect.cpp
collectdisplay.h
collectsharedcommand.cpp
globaldata.cpp
groupmap.cpp
groupmap.h
sharedrabundvector.cpp
sharedrabundvector.h
sharedsobs.h
sharedsobscollectsummary.cpp [new file with mode: 0644]
sharedsobscollectsummary.h [new file with mode: 0644]
summarysharedcommand.cpp
summarysharedcommand.h

index 1e473468b4ac8e88d11435958e464b8e88909932..d678294bcf11674e75ccdc40dd068df8300c7750 100644 (file)
@@ -20,6 +20,7 @@
                37AD4CE40F28AEA300AA2D49 /* sharedlistvector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37AD4CE30F28AEA300AA2D49 /* sharedlistvector.cpp */; };
                37AD4DBB0F28E2FE00AA2D49 /* tree.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37AD4DBA0F28E2FE00AA2D49 /* tree.cpp */; };
                37AD4DCA0F28F3DD00AA2D49 /* readtree.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37AD4DC90F28F3DD00AA2D49 /* readtree.cpp */; };
+               37AFC71F0F445386005F492D /* sharedsobscollectsummary.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37AFC71E0F445386005F492D /* sharedsobscollectsummary.cpp */; };
                37B28F680F27590100808A62 /* deconvolutecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37B28F670F27590100808A62 /* deconvolutecommand.cpp */; };
                37D928550F21331F001D4494 /* ace.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927B80F21331F001D4494 /* ace.cpp */; };
                37D928560F21331F001D4494 /* averagelinkage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927BA0F21331F001D4494 /* averagelinkage.cpp */; };
                37AD4DBA0F28E2FE00AA2D49 /* tree.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = tree.cpp; sourceTree = "<group>"; };
                37AD4DC80F28F3DD00AA2D49 /* readtree.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readtree.h; sourceTree = "<group>"; };
                37AD4DC90F28F3DD00AA2D49 /* readtree.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readtree.cpp; sourceTree = "<group>"; };
+               37AFC71D0F445386005F492D /* sharedsobscollectsummary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedsobscollectsummary.h; sourceTree = "<group>"; };
+               37AFC71E0F445386005F492D /* sharedsobscollectsummary.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedsobscollectsummary.cpp; sourceTree = "<group>"; };
                37B28F660F27590100808A62 /* deconvolutecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = deconvolutecommand.h; sourceTree = "<group>"; };
                37B28F670F27590100808A62 /* deconvolutecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = deconvolutecommand.cpp; sourceTree = "<group>"; };
                37D927B80F21331F001D4494 /* ace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ace.cpp; sourceTree = "<group>"; };
                                37D9282C0F21331F001D4494 /* sharedjest.cpp */,
                                37D928350F21331F001D4494 /* sharedsobs.h */,
                                37D928340F21331F001D4494 /* sharedsobs.cpp */,
+                               37AFC71D0F445386005F492D /* sharedsobscollectsummary.h */,
+                               37AFC71E0F445386005F492D /* sharedsobscollectsummary.cpp */,
                                37D928370F21331F001D4494 /* sharedsorabund.h */,
                                37D928360F21331F001D4494 /* sharedsorabund.cpp */,
                                37D928390F21331F001D4494 /* sharedsorclass.h */,
                                3746107E0F4064D100460C57 /* weighted.cpp in Sources */,
                                374610830F40652400460C57 /* unweighted.cpp in Sources */,
                                3746109D0F40657600460C57 /* unifracunweightedcommand.cpp in Sources */,
+                               37AFC71F0F445386005F492D /* sharedsobscollectsummary.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index a06c320f37f952c527533abae162e13af5a438b1..2ed5ca7f10eeefdb860ae9fc7b5859b5eb239c0e 100644 (file)
@@ -70,6 +70,7 @@ try {
                        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]]);
                        lookup.push_back(temp);
                }
 
@@ -111,7 +112,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, numGroupComb);
+                                               ccd->updateSharedData(lookup[k], lookup[l], i+1, globaldata->gGroupmap->namesOfGroups.size());
                                        }
                                        n++;
                                }
@@ -125,7 +126,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, numGroupComb);
+                                       ccd->updateSharedData(lookup[k], lookup[l], totalNumSeq, globaldata->gGroupmap->namesOfGroups.size());
                                }
                                n++;
                        }
index 367a188dfb8de90c2e464cb70cc4a7b1b826ccfe..fc405dfa0d7dbfd8885d5c21ec9b1d879f2f4126 100644 (file)
@@ -23,17 +23,40 @@ public:
                output->output(nSeqs, data);    
        };
        
-       void update(SharedRAbundVector* shared1, SharedRAbundVector* shared2, int numSeqs, int numGroupComb){
+       void update(SharedRAbundVector* shared1, SharedRAbundVector* shared2, int numSeqs, int numGroups){
                timesCalled++;
                data = estimate->getValues(shared1, shared2);  //passes estimators a shared vector from each group to be compared
+               
+               //figure out what groups are being compared in getValues
+               //because the jumble parameter randomizes the order we need to put the results in the correct column in the output file
+               int group1Index, group2Index, pos;
+               group1Index = shared1->getGroupIndex();
+               group2Index = shared2->getGroupIndex();
+               
+               numGroupComb = 0;
+               int n = 1;
+               for (int i = 0; i < (numGroups - 1); i++) {
+                       for (int l = n; l < numGroups; l++) {
+                               if ((group1Index == i) && (group2Index == l)) {
+                                       pos = numGroupComb;  //pos tells you which column in the output file you are in
+                               }else if ((group1Index == l) && (group2Index == i)) {
+                                       pos = numGroupComb;
+                               }
+                               numGroupComb++;
+                       }
+                       n++;
+               }
+
+               groupData.resize((numGroupComb*data.size()), 0);
+               
                //fills groupdata with datas info
                for (int i = 0; i < data.size(); i++) {
-                       groupData.push_back(data[i]);
+                       groupData[pos+i] = data[i];
                }
+               
                //when you get all your groups info then output
                if ((timesCalled % numGroupComb) == 0) {
                        output->output(numSeqs, groupData);     
-                       groupData.clear();
                }
        };
        
@@ -44,7 +67,7 @@ public:
 private:
        Calculator* estimate;
        FileOutput* output;
-       int nSeqs, timesCalled;
+       int nSeqs, timesCalled, numGroupComb;
        vector<double> data;
        vector<double> groupData;
 };
index 1f5ed558985d4361a4145b9811d19f508b79a630..a6479da20d4e5b52a09cdb06d76676f26ed583e4 100644 (file)
@@ -8,7 +8,7 @@
  */
 
 #include "collectsharedcommand.h"
-#include "sharedsobs.h"
+#include "sharedsobscollectsummary.h"
 #include "sharedchao1.h"
 #include "sharedace.h"
 #include "sharedjabund.h"
@@ -35,7 +35,7 @@ CollectSharedCommand::CollectSharedCommand(){
                        if (globaldata->sharedEstimators[i] == "sharedChao") { 
                                cDisplays.push_back(new CollectDisplay(new SharedChao1(), new SharedOneColumnFile(fileNameRoot+"shared.chao")));
                        }else if (globaldata->sharedEstimators[i] == "sharedSobs") { 
-                               cDisplays.push_back(new CollectDisplay(new SharedSobs(), new SharedOneColumnFile(fileNameRoot+"shared.sobs")));
+                               cDisplays.push_back(new CollectDisplay(new SharedSobsCS(), new SharedOneColumnFile(fileNameRoot+"shared.sobs")));
                        }else if (globaldata->sharedEstimators[i] == "sharedAce") { 
                                cDisplays.push_back(new CollectDisplay(new SharedAce(), new SharedOneColumnFile(fileNameRoot+"shared.ace")));
                        }else if (globaldata->sharedEstimators[i] == "sharedJabund") {  
index d4eb9980c9051919eecb25e18a0c7b685dae65a1..e58d19181d156e00dff0190388552858a32dbbde 100644 (file)
@@ -488,7 +488,7 @@ void GlobalData::splitAtComma(string& prefix, string& suffix){
 /*******************************************************/
 
 /******************************************************/
-//This function separates the key value from the option value i.e. distfile = "96_..."
+//This function separates the key value from the option value i.e. dist=96_...
 void GlobalData::splitAtEquals(string& key, string& value){            
        try {
                if(value.find_first_of('=') != -1){
index ef262a37cd5f0bc273b6d07ddfe62574a4aac5fd..27302dbce43f02a008fa54aaeb5e84bda8a8b003 100644 (file)
@@ -14,6 +14,7 @@
  GroupMap::GroupMap(string filename) {
        groupFileName = filename;
        openInputFile(filename, fileHandle);
+       index = 0;
 }
 
 /************************************************************/
@@ -69,5 +70,7 @@ void GroupMap::setNamesOfGroups(string seqGroup) {
                        }
                        if (count == namesOfGroups.size()) {
                                namesOfGroups.push_back(seqGroup); //new group
+                               groupIndex[seqGroup] = index;
+                               index++;
                        }
 }
index a3b923cd4da60ce601c58d1553e2a95f6b9f4ab9..a6b6fd7c25158a4ee7195d0f8e0432dfdecd078a 100644 (file)
@@ -26,11 +26,12 @@ public:
        int getNumGroups();
        string getGroup(string);
        vector<string> namesOfGroups;
+       map<string, int> groupIndex;  //groupname, vectorIndex in namesOfGroups. - used by collectdisplays.
                
 private:
        ifstream fileHandle;
        string groupFileName;
-       int numGroups;
+       int numGroups, index;
        map<string, string>::iterator it;
        void setNamesOfGroups(string); 
        map<string, string> groupmap; //sequence name and groupname
index ba8f94d2e03b85589c62238748bc1b4fa8e01676..a703e5577bbfa12cec108ade6c7e0e98b50ba7b5 100644 (file)
@@ -223,7 +223,10 @@ string SharedRAbundVector::getGroup(){
 void SharedRAbundVector::setGroup(string groupName){
        group = groupName;
 }
-
+/***********************************************************************/
+int SharedRAbundVector::getGroupIndex()  { return index; }
+/***********************************************************************/
+void SharedRAbundVector::setGroupIndex(int vIndex)     { index = vIndex; }
 /***********************************************************************/
 int SharedRAbundVector::getNumBins(){
        return numBins;
index 5547f89dabeafdf59554e4c8d2144e5375b38fe8..41a5798ed295489a0d786fd52a400407104e8a6a 100644 (file)
@@ -37,7 +37,9 @@ public:
        int getNumSeqs();                                                       
        int getMaxRank();
        string getGroup();
-       void setGroup(string);                                                  
+       void setGroup(string);
+       int getGroupIndex();
+       void setGroupIndex(int);                                                                
 
        void set(int, int, string);                     //OTU, abundance, groupname
        individual get(int);
@@ -63,7 +65,8 @@ private:
        int maxRank;
        int numBins;
        int numSeqs;
-       string group;   
+       string group;
+       int index;      
 };
 
 
index a4c5b9bd92e43eb3497eaea24f3a660f2e0c396a..51662015ab7c7bd5ea1209e24b34fc92a06d22f7 100644 (file)
@@ -9,7 +9,7 @@
  *
  */
 
-/* This class implements the SharedSobs estimator on two groups. 
+/* This class implements the SharedSobs estimator on two groups for the shared rarefaction command
 It is a child of the calculator class. */
 
 
diff --git a/sharedsobscollectsummary.cpp b/sharedsobscollectsummary.cpp
new file mode 100644 (file)
index 0000000..d39e66e
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ *  sharedsobscollectsummary.cpp
+ *  Mothur
+ *
+ *  Created by Sarah Westcott on 2/12/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "sharedsobscollectsummary.h"
+
+/***********************************************************************/
+//This returns the number of shared species observed in several groups.  
+//The shared vector is each groups sharedrabundvector.
+
+EstOutput SharedSobsCS::getValues(SharedRAbundVector* shared1, SharedRAbundVector* shared2){
+       try {
+               data.resize(1,0);
+               int observed = 0;
+               int tempA, tempB;
+
+               //loop through the species in each group
+               for (int k = 0; k < shared1->size(); k++) {
+                       tempA = shared1->getAbundance(k); //store in temps to avoid calling getAbundance multiple times
+                       tempB = shared2->getAbundance(k);
+
+                       //if you have found a new species
+                       if ((tempA != 0) && (tempB != 0)) {//they are shared
+                               observed++;
+                       }
+               }
+
+               data[0] = observed;
+               return data;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedSobsCS class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedSobsCS class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
\ No newline at end of file
diff --git a/sharedsobscollectsummary.h b/sharedsobscollectsummary.h
new file mode 100644 (file)
index 0000000..3ff35b1
--- /dev/null
@@ -0,0 +1,27 @@
+#ifndef SHAREDSOBSCOLLECTSUMMARY_H
+#define SHAREDSOBSCOLLECTSUMMARY_H
+
+/*
+ *  sharedsobscollectsummary.h
+ *  Mothur
+ *
+ *  Created by Sarah Westcott on 2/12/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+
+#include "calculator.h"
+
+/***********************************************************************/
+class SharedSobsCS : public Calculator {
+
+public:
+       SharedSobsCS() : Calculator("SharedSobs", 1) {};
+       EstOutput getValues(SAbundVector* rank){ return data; };
+       EstOutput getValues(SharedRAbundVector* shared1, SharedRAbundVector* shared2);
+};
+
+/***********************************************************************/
+
+#endif
index 139b74e762734957c95ccb659434e32068289162..c451ef7aeb6ead4065f55a18bea99cb1840b530f 100644 (file)
@@ -8,7 +8,7 @@
  */
 
 #include "summarysharedcommand.h"
-#include "sharedsobs.h"
+#include "sharedsobscollectsummary.h"
 #include "sharedchao1.h"
 #include "sharedace.h"
 #include "sharedjabund.h"
@@ -29,7 +29,7 @@ SummarySharedCommand::SummarySharedCommand(){
                int i;
                for (i=0; i<globaldata->sharedSummaryEstimators.size(); i++) {
                        if (globaldata->sharedSummaryEstimators[i] == "sharedSobs") { 
-                               sumCalculators.push_back(new SharedSobs());
+                               sumCalculators.push_back(new SharedSobsCS());
                        }else if (globaldata->sharedSummaryEstimators[i] == "sharedChao") { 
                                sumCalculators.push_back(new SharedChao1());
                        }else if (globaldata->sharedSummaryEstimators[i] == "sharedAce") { 
@@ -88,7 +88,6 @@ int SummarySharedCommand::execute(){
                SharedList = globaldata->gSharedList;
                input = globaldata->ginput;
                order = SharedList->getSharedOrderVector();
-               getGroupComb();
                
                int count = 1;
                while(order != NULL){
@@ -104,7 +103,7 @@ int SummarySharedCommand::execute(){
                                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++) {
-                                               outputFileHandle << order->getLabel() << '\t' << groupComb[n-1] << '\t' << '\t'; //print out label and group
+                                               outputFileHandle << order->getLabel() << '\t' << (lookup[k]->getGroup() + lookup[l]->getGroup()) << '\t' << '\t'; //print out label and group
                                                for(int i=0;i<sumCalculators.size();i++){
                                                        sumCalculators[i]->getValues(lookup[k], lookup[l]); //saves the calculator outputs
                                                        outputFileHandle << '\t';
@@ -179,28 +178,4 @@ try {
 
 }
 
-/**************************************************************************************/
-void SummarySharedCommand::getGroupComb() {
-       try {
-               string group;
-               
-               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);     
-                       }
-                       n++;
-               }
-       }
-       catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function getGroupComb. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the SummarySharedCommand class function getGroupComb. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-
-}
-
+//**********************************************************************************************************************
index 9ce3b69b65fab19c845b9344f9fe192d70e88ae0..ab1d7ac4d8af610748c5dab7c26f42e2ff320da5 100644 (file)
@@ -44,7 +44,6 @@ public:
        int execute();
        
 private:
-       void getGroupComb();
        void getSharedVectors();
        
        GlobalData* globaldata;
@@ -57,7 +56,6 @@ private:
        SharedRAbundVector* shared1, shared2;
        string outputFileName;
        ofstream outputFileHandle;
-       vector<string> groupComb;
 
 };