]> git.donarmstrong.com Git - mothur.git/blob - collect.cpp
fixed bug with displaying info for collect.shared() and summary.shared().
[mothur.git] / collect.cpp
1 /*
2  *  collect.cpp
3  *  Dotur
4  *
5  *  Created by Sarah Westcott on 11/18/08.
6  *  Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "collect.h"
11
12
13 /***********************************************************************/
14
15 void Collect::getCurve(int increment = 1){
16         try {
17                 RAbundVector* lookup = new RAbundVector(order->getNumBins());
18                 SAbundVector* rank      = new SAbundVector(order->getMaxRank()+1);
19
20                 CollectorsCurveData* ccd = new CollectorsCurveData();
21         
22                 for(int i=0;i<displays.size();i++){
23                         ccd->registerDisplay(displays[i]); //adds a display[i] to cdd
24                         displays[i]->init(label);                  //sets displays label
25                 }                                                                          
26                 for(int i=0;i<numSeqs;i++){
27
28                         int binNumber = order->get(i);
29                         int abundance = lookup->get(binNumber);
30                 
31                         rank->set(abundance, rank->get(abundance)-1); 
32                 
33                         abundance++;
34                 
35                         lookup->set(binNumber, abundance);
36                         rank->set(abundance, rank->get(abundance)+1); //increment rank(abundance)
37
38                         if((i == 0) || (i+1) % increment == 0){
39                                 ccd->updateRankData(rank);
40                         }
41                 }
42         
43                 if(numSeqs % increment != 0){
44                         ccd->updateRankData(rank);
45                 }
46         
47                 for(int i=0;i<displays.size();i++){
48                         displays[i]->reset();
49                 }
50         }
51         catch(exception& e) {
52                 cout << "Standard Error: " << e.what() << " has occurred in the Collect class Function getCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
53                 exit(1);
54         }
55         catch(...) {
56                 cout << "An unknown error has occurred in the Collect class function getCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
57                 exit(1);
58         }
59
60 }
61
62 /***********************************************************************/
63 void Collect::getSharedCurve(int increment = 1){
64 try {
65                 globaldata = GlobalData::getInstance();
66                 vector<SharedRAbundVector*> lookup; 
67
68                 //create and initialize vector of sharedvectors, one for each group
69                 for (int i = 0; i < globaldata->gGroupmap->getNumGroups(); i++) { 
70                         SharedRAbundVector* temp = new SharedRAbundVector(sharedorder->getNumBins());
71                         temp->setLabel(sharedorder->getLabel());
72                         temp->setGroup(globaldata->gGroupmap->namesOfGroups[i]);
73                         temp->setGroupIndex(globaldata->gGroupmap->groupIndex[globaldata->gGroupmap->namesOfGroups[i]]);
74                         lookup.push_back(temp);
75                 }
76
77                 SharedCollectorsCurveData* ccd = new SharedCollectorsCurveData();
78         
79                 //initialize labels for output
80                 //makes  'uniqueAB       uniqueAC  uniqueBC' if your groups are A, B, C
81                 getGroupComb();
82                 groupLabel = "";
83                 for (int s = 0; s < groupComb.size(); s++) {
84                         groupLabel = groupLabel + label + groupComb[s] + "\t";
85                 }
86
87                 for(int i=0;i<displays.size();i++){
88                         ccd->registerDisplay(displays[i]); //adds a display[i] to cdd
89                         displays[i]->init(groupLabel);            
90                 }
91                 
92                 //sample all the members
93                 for(int i=0;i<numSeqs;i++){
94                         //get first sample
95                         individual chosen = sharedorder->get(i);
96                         int abundance; 
97                                         
98                         //set info for sharedvector in chosens group
99                         for (int j = 0; j < lookup.size(); j++) { 
100                                 if (chosen.group == lookup[j]->getGroup()) {
101                                          abundance = lookup[j]->getAbundance(chosen.bin);
102                                          lookup[j]->set(chosen.bin, (abundance + 1), chosen.group);
103                                          break;
104                                 }
105                         }
106                         
107                         //calculate at 0 and the given increment
108                         if((i == 0) || (i+1) % increment == 0){
109                                 //randomize group order
110                                 if (globaldata->getJumble() == "1") { random_shuffle(lookup.begin(), lookup.end()); }
111                                 //how many comparisons to make i.e. for group a, b, c = ab, ac, bc.
112                                 int n = 1;
113                                 for (int k = 0; k < (lookup.size() - 1); k++) { // pass cdd each set of groups to commpare
114                                         for (int l = n; l < lookup.size(); l++) {
115                                                 ccd->updateSharedData(lookup[k], lookup[l], i+1, globaldata->gGroupmap->namesOfGroups.size());
116                                         }
117                                         n++;
118                                 }
119                         }
120                         totalNumSeq = i+1;
121                 }
122                 
123                 //calculate last line if you haven't already
124                 if(numSeqs % increment != 0){
125                         //how many comparisons to make i.e. for group a, b, c = ab, ac, bc.
126                         int n = 1;
127                         for (int k = 0; k < (lookup.size() - 1); k++) { // pass cdd each set of groups to commpare
128                                 for (int l = n; l < lookup.size(); l++) {
129                                         ccd->updateSharedData(lookup[k], lookup[l], totalNumSeq, globaldata->gGroupmap->namesOfGroups.size());
130                                 }
131                                 n++;
132                         }
133                 }
134                 
135                 //resets output files
136                 for(int i=0;i<displays.size();i++){
137                         displays[i]->reset();
138                 }
139         }
140         catch(exception& e) {
141                 cout << "Standard Error: " << e.what() << " has occurred in the Collect class Function getSharedCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
142                 exit(1);
143         }
144         catch(...) {
145                 cout << "An unknown error has occurred in the Collect class function getSharedCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
146                 exit(1);
147         }
148
149 }
150
151 /**************************************************************************************/
152
153 void Collect::getGroupComb() {
154                 string group;
155                 
156                 numGroupComb = 0;
157                 
158                 int n = 1;
159                 for (int i = 0; i < (globaldata->gGroupmap->getNumGroups() - 1); i++) {
160                         for (int l = n; l < globaldata->gGroupmap->getNumGroups(); l++) {
161                                 group = globaldata->gGroupmap->namesOfGroups[i] + globaldata->gGroupmap->namesOfGroups[l];
162                                 groupComb.push_back(group);     
163                                 numGroupComb++;
164                         }
165                         n++;
166                 }
167
168 }
169
170 /**************************************************************************************/