From: westcott Date: Thu, 12 Feb 2009 14:52:49 +0000 (+0000) Subject: fixed bug with displaying info for collect.shared() and summary.shared(). X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=44c1323a88b2a697c7047df1b3bb8c59eadd15b1 fixed bug with displaying info for collect.shared() and summary.shared(). --- diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj index 1e47346..d678294 100644 --- a/Mothur.xcodeproj/project.pbxproj +++ b/Mothur.xcodeproj/project.pbxproj @@ -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 */; }; @@ -134,6 +135,8 @@ 37AD4DBA0F28E2FE00AA2D49 /* tree.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = tree.cpp; sourceTree = ""; }; 37AD4DC80F28F3DD00AA2D49 /* readtree.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readtree.h; sourceTree = ""; }; 37AD4DC90F28F3DD00AA2D49 /* readtree.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readtree.cpp; sourceTree = ""; }; + 37AFC71D0F445386005F492D /* sharedsobscollectsummary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedsobscollectsummary.h; sourceTree = ""; }; + 37AFC71E0F445386005F492D /* sharedsobscollectsummary.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedsobscollectsummary.cpp; sourceTree = ""; }; 37B28F660F27590100808A62 /* deconvolutecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = deconvolutecommand.h; sourceTree = ""; }; 37B28F670F27590100808A62 /* deconvolutecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = deconvolutecommand.cpp; sourceTree = ""; }; 37D927B80F21331F001D4494 /* ace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ace.cpp; sourceTree = ""; }; @@ -414,6 +417,8 @@ 37D9282C0F21331F001D4494 /* sharedjest.cpp */, 37D928350F21331F001D4494 /* sharedsobs.h */, 37D928340F21331F001D4494 /* sharedsobs.cpp */, + 37AFC71D0F445386005F492D /* sharedsobscollectsummary.h */, + 37AFC71E0F445386005F492D /* sharedsobscollectsummary.cpp */, 37D928370F21331F001D4494 /* sharedsorabund.h */, 37D928360F21331F001D4494 /* sharedsorabund.cpp */, 37D928390F21331F001D4494 /* sharedsorclass.h */, @@ -667,6 +672,7 @@ 3746107E0F4064D100460C57 /* weighted.cpp in Sources */, 374610830F40652400460C57 /* unweighted.cpp in Sources */, 3746109D0F40657600460C57 /* unifracunweightedcommand.cpp in Sources */, + 37AFC71F0F445386005F492D /* sharedsobscollectsummary.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/collect.cpp b/collect.cpp index a06c320..2ed5ca7 100644 --- a/collect.cpp +++ b/collect.cpp @@ -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++; } diff --git a/collectdisplay.h b/collectdisplay.h index 367a188..fc405df 100644 --- a/collectdisplay.h +++ b/collectdisplay.h @@ -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 data; vector groupData; }; diff --git a/collectsharedcommand.cpp b/collectsharedcommand.cpp index 1f5ed55..a6479da 100644 --- a/collectsharedcommand.cpp +++ b/collectsharedcommand.cpp @@ -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") { diff --git a/globaldata.cpp b/globaldata.cpp index d4eb998..e58d191 100644 --- a/globaldata.cpp +++ b/globaldata.cpp @@ -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){ diff --git a/groupmap.cpp b/groupmap.cpp index ef262a3..27302db 100644 --- a/groupmap.cpp +++ b/groupmap.cpp @@ -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++; } } diff --git a/groupmap.h b/groupmap.h index a3b923c..a6b6fd7 100644 --- a/groupmap.h +++ b/groupmap.h @@ -26,11 +26,12 @@ public: int getNumGroups(); string getGroup(string); vector namesOfGroups; + map groupIndex; //groupname, vectorIndex in namesOfGroups. - used by collectdisplays. private: ifstream fileHandle; string groupFileName; - int numGroups; + int numGroups, index; map::iterator it; void setNamesOfGroups(string); map groupmap; //sequence name and groupname diff --git a/sharedrabundvector.cpp b/sharedrabundvector.cpp index ba8f94d..a703e55 100644 --- a/sharedrabundvector.cpp +++ b/sharedrabundvector.cpp @@ -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; diff --git a/sharedrabundvector.h b/sharedrabundvector.h index 5547f89..41a5798 100644 --- a/sharedrabundvector.h +++ b/sharedrabundvector.h @@ -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; }; diff --git a/sharedsobs.h b/sharedsobs.h index a4c5b9b..5166201 100644 --- a/sharedsobs.h +++ b/sharedsobs.h @@ -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 index 0000000..d39e66e --- /dev/null +++ b/sharedsobscollectsummary.cpp @@ -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 index 0000000..3ff35b1 --- /dev/null +++ b/sharedsobscollectsummary.h @@ -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 diff --git a/summarysharedcommand.cpp b/summarysharedcommand.cpp index 139b74e..c451ef7 100644 --- a/summarysharedcommand.cpp +++ b/summarysharedcommand.cpp @@ -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; isharedSummaryEstimators.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;igetValues(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); - } - -} - +//********************************************************************************************************************** diff --git a/summarysharedcommand.h b/summarysharedcommand.h index 9ce3b69..ab1d7ac 100644 --- a/summarysharedcommand.h +++ b/summarysharedcommand.h @@ -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 groupComb; };