]> git.donarmstrong.com Git - mothur.git/blob - sharedsobscollectsummary.cpp
d39e66e58a7bb79b9d4cc5f326b53d169778d181
[mothur.git] / sharedsobscollectsummary.cpp
1 /*
2  *  sharedsobscollectsummary.cpp
3  *  Mothur
4  *
5  *  Created by Sarah Westcott on 2/12/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "sharedsobscollectsummary.h"
11
12 /***********************************************************************/
13 //This returns the number of shared species observed in several groups.  
14 //The shared vector is each groups sharedrabundvector.
15
16 EstOutput SharedSobsCS::getValues(SharedRAbundVector* shared1, SharedRAbundVector* shared2){
17         try {
18                 data.resize(1,0);
19                 int observed = 0;
20                 int tempA, tempB;
21
22                 //loop through the species in each group
23                 for (int k = 0; k < shared1->size(); k++) {
24                         tempA = shared1->getAbundance(k); //store in temps to avoid calling getAbundance multiple times
25                         tempB = shared2->getAbundance(k);
26
27                         //if you have found a new species
28                         if ((tempA != 0) && (tempB != 0)) {//they are shared
29                                 observed++;
30                         }
31                 }
32
33                 data[0] = observed;
34                 return data;
35         }
36         catch(exception& e) {
37                 cout << "Standard Error: " << e.what() << " has occurred in the SharedSobsCS class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
38                 exit(1);
39         }
40         catch(...) {
41                 cout << "An unknown error has occurred in the SharedSobsCS class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
42                 exit(1);
43         }       
44 }
45
46 /***********************************************************************/