X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=sharedsobscollectsummary.cpp;h=b53b09afc0091e91baf6609aa9c8d5b0ab528b63;hp=d39e66e58a7bb79b9d4cc5f326b53d169778d181;hb=70491a12902e89b85cfa6b44a7b7fbe066ee2ac1;hpb=44c1323a88b2a697c7047df1b3bb8c59eadd15b1 diff --git a/sharedsobscollectsummary.cpp b/sharedsobscollectsummary.cpp index d39e66e..b53b09a 100644 --- a/sharedsobscollectsummary.cpp +++ b/sharedsobscollectsummary.cpp @@ -13,34 +13,60 @@ //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){ +EstOutput SharedSobsCS::getValues(vector shared){ try { data.resize(1,0); - int observed = 0; - int tempA, tempB; + double observed = 0; + int numGroups = shared.size(); - //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++; + for (int i = 0; i < shared[0]->getNumBins(); i++) { + //get bin values and set sharedByAll + bool sharedByAll = true; + for (int j = 0; j < numGroups; j++) { + if (shared[j]->getAbundance(i) == 0) { sharedByAll = false; } } + + //they are shared + if (sharedByAll == true) { 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"; + m->errorOut(e, "SharedSobsCS", "getValues"); 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"; +} +/***********************************************************************/ +//This returns the number of shared species observed in several groups. +//The shared vector is each groups sharedrabundvector. + +EstOutput SharedSobsCS::getValues(vector shared, vector& labels){ + try { + data.resize(1,0); + double observed = 0; + int numGroups = shared.size(); + labels.clear(); + + for (int i = 0; i < shared[0]->getNumBins(); i++) { + //get bin values and set sharedByAll + bool sharedByAll = true; + for (int j = 0; j < numGroups; j++) { + if (shared[j]->getAbundance(i) == 0) { sharedByAll = false; } + } + + //they are shared + if (sharedByAll == true) { observed++; labels.push_back(m->currentBinLabels[i]); } + } + + data[0] = observed; + return data; + } + catch(exception& e) { + m->errorOut(e, "SharedSobsCS", "getValues"); exit(1); - } + } } -/***********************************************************************/ \ No newline at end of file +/***********************************************************************/