]> git.donarmstrong.com Git - mothur.git/blob - collect.cpp
started shared utilities, updates to venn and heatmap added tree.groups command
[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 void Collect::getCurve(int increment = 1){
15         try {
16                 RAbundVector* lookup = new RAbundVector(order->getNumBins());
17                 SAbundVector* rank        = new SAbundVector(order->getMaxRank()+1);
18
19                 CollectorsCurveData* ccd = new CollectorsCurveData();
20         
21                 for(int i=0;i<displays.size();i++){
22                         ccd->registerDisplay(displays[i]); //adds a display[i] to cdd
23                         displays[i]->init(label);                   //sets displays label
24                 }                                                                           
25                 for(int i=0;i<numSeqs;i++){
26
27                         int binNumber = order->get(i);
28                         int abundance = lookup->get(binNumber);
29                 
30                         rank->set(abundance, rank->get(abundance)-1); 
31                 
32                         abundance++;
33                 
34                         lookup->set(binNumber, abundance);
35                         rank->set(abundance, rank->get(abundance)+1); //increment rank(abundance)
36
37                         if((i == 0) || (i+1) % increment == 0){
38                                 ccd->updateRankData(rank);
39                         }
40                 }
41         
42                 if(numSeqs % increment != 0){
43                         ccd->updateRankData(rank);
44                 }
45         
46                 for(int i=0;i<displays.size();i++){
47                         displays[i]->reset();
48                 }
49         }
50         catch(exception& e) {
51                 cout << "Standard Error: " << e.what() << " has occurred in the Collect class Function getCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
52                 exit(1);
53         }
54         catch(...) {
55                 cout << "An unknown error has occurred in the Collect class function getCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
56                 exit(1);
57         }
58
59 }
60
61 /***********************************************************************/
62 void Collect::getSharedCurve(int increment = 1){
63 try {
64                 globaldata = GlobalData::getInstance();
65                 vector<SharedRAbundVector*> lookup; 
66
67                 //create and initialize vector of sharedvectors, one for each group
68                 for (int i = 0; i < globaldata->Groups.size(); i++) { 
69                         SharedRAbundVector* temp = new SharedRAbundVector(sharedorder->getNumBins());
70                         temp->setLabel(sharedorder->getLabel());
71                         temp->setGroup(globaldata->Groups[i]);
72                         temp->setGroupIndex(globaldata->gGroupmap->groupIndex[globaldata->Groups[i]]);
73                         lookup.push_back(temp);
74                 }
75
76                 SharedCollectorsCurveData* ccd = new SharedCollectorsCurveData();
77         
78                 //initialize labels for output
79                 //makes  'uniqueAB         uniqueAC  uniqueBC' if your groups are A, B, C
80                 getGroupComb();
81                 groupLabel = "";
82                 for (int s = 0; s < groupComb.size(); s++) {
83                         groupLabel = groupLabel + label + groupComb[s] + "\t";
84                 }
85
86                 for(int i=0;i<displays.size();i++){
87                         ccd->registerDisplay(displays[i]); //adds a display[i] to cdd
88                         displays[i]->init(groupLabel);                  
89                 }
90                 
91                 //sample all the members
92                 for(int i=0;i<numSeqs;i++){
93                         //get first sample
94                         individual chosen = sharedorder->get(i);
95                         int abundance; 
96                                         
97                         //set info for sharedvector in chosens group
98                         for (int j = 0; j < lookup.size(); j++) { 
99                                                         if (chosen.group == lookup[j]->getGroup()) {
100                                                                 abundance = lookup[j]->getAbundance(chosen.bin);
101                                                                 lookup[j]->set(chosen.bin, (abundance + 1), chosen.group);
102                                                                 break;
103                                                         }
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->Groups.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->Groups.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->Groups.size() - 1); i++) {
160                 for (int l = n; l < globaldata->Groups.size(); l++) {
161                         group = globaldata->Groups[i] + globaldata->Groups[l];
162                         groupComb.push_back(group);        
163                         numGroupComb++;
164                 }
165                 n++;
166         }
167
168 }
169
170 /**************************************************************************************/