]> git.donarmstrong.com Git - mothur.git/blob - sharedsobscollectsummary.cpp
changed random forest output filename
[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(vector<SharedRAbundVector*> shared){
17         try {
18                 data.resize(1,0);
19                 double observed = 0;
20                 int numGroups = shared.size();
21
22                 for (int i = 0; i < shared[0]->getNumBins(); i++) {
23                         //get bin values and set sharedByAll 
24                         bool sharedByAll = true;
25                         for (int j = 0; j < numGroups; j++) {
26                                 if (shared[j]->getAbundance(i) == 0) { sharedByAll = false; }
27                         }
28                         
29                         //they are shared
30                         if (sharedByAll == true) {  observed++;  }
31                 }
32
33                 data[0] = observed;
34                 return data;
35         }
36         catch(exception& e) {
37                 m->errorOut(e, "SharedSobsCS", "getValues");
38                 exit(1);
39         }
40 }
41 /***********************************************************************/
42 //This returns the number of shared species observed in several groups.  
43 //The shared vector is each groups sharedrabundvector.
44
45 EstOutput SharedSobsCS::getValues(vector<SharedRAbundVector*> shared, vector<string>& labels){
46         try {
47                 data.resize(1,0);
48                 double observed = 0;
49                 int numGroups = shared.size();
50         labels.clear();
51         
52                 for (int i = 0; i < shared[0]->getNumBins(); i++) {
53                         //get bin values and set sharedByAll 
54                         bool sharedByAll = true;
55                         for (int j = 0; j < numGroups; j++) {
56                                 if (shared[j]->getAbundance(i) == 0) { sharedByAll = false; }
57                         }
58                         
59                         //they are shared
60                         if (sharedByAll == true) {  observed++;  labels.push_back(m->currentBinLabels[i]); }
61                 }
62         
63                 data[0] = observed;
64                 return data;
65         }
66         catch(exception& e) {
67                 m->errorOut(e, "SharedSobsCS", "getValues");
68                 exit(1);
69         }
70 }
71
72 /***********************************************************************/