]> git.donarmstrong.com Git - mothur.git/blob - collect.cpp
removed line option
[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                                 delete lookup;
51                                 delete rank;
52                                 delete ccd;
53         }
54         catch(exception& e) {
55                         errorOut(e, "Collect", "getCurve");
56                         exit(1);
57         }
58 }
59
60 /***********************************************************************/
61 void Collect::getSharedCurve(int increment = 1){
62 try {
63                 globaldata = GlobalData::getInstance();
64                 vector<SharedRAbundVector*> lookup; 
65                                 vector<SharedRAbundVector*> subset;
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 multi displays
87                                 string groupLabelAll = groupLabel + label + "all\t";
88                                 
89                 for(int i=0;i<displays.size();i++){
90                         ccd->registerDisplay(displays[i]); //adds a display[i] to cdd
91                                                 if (displays[i]->isCalcMultiple() == true)  {   displays[i]->init(groupLabelAll); }
92                                                 else {  displays[i]->init(groupLabel);  }           
93                 }
94                 
95                 //sample all the members
96                 for(int i=0;i<numSeqs;i++){
97                         //get first sample
98                         individual chosen = sharedorder->get(i);
99                         int abundance; 
100                                         
101                         //set info for sharedvector in chosens group
102                         for (int j = 0; j < lookup.size(); j++) { 
103                                                         if (chosen.group == lookup[j]->getGroup()) {
104                                                                 abundance = lookup[j]->getAbundance(chosen.bin);
105                                                                 lookup[j]->set(chosen.bin, (abundance + 1), chosen.group);
106                                                                 break;
107                                                         }
108                         }
109                         
110         
111                         //calculate at 0 and the given increment
112                         if((i == 0) || (i+1) % increment == 0){
113
114                                                                 //how many comparisons to make i.e. for group a, b, c = ab, ac, bc.
115
116                                 int n = 1;
117                                 for (int k = 0; k < (lookup.size() - 1); k++) { // pass cdd each set of groups to commpare
118                                         for (int l = n; l < lookup.size(); l++) {
119                                                                                                 subset.clear(); //clear out old pair of sharedrabunds
120                                                                                                 //add new pair of sharedrabund vectors
121                                                                                                 subset.push_back(lookup[k]); subset.push_back(lookup[l]);
122                                                 ccd->updateSharedData(subset, i+1, globaldata->Groups.size());
123                                         }
124                                         n++;
125                                 }
126                                                                 //if this is a calculator that can do multiples then do them
127                                                                 ccd->updateSharedData(lookup, i+1, globaldata->Groups.size()); 
128                         }
129                         totalNumSeq = i+1;
130                 }
131                 
132                 //calculate last label if you haven't already
133                 if(numSeqs % increment != 0){
134                         //how many comparisons to make i.e. for group a, b, c = ab, ac, bc.
135                         int n = 1;
136                         for (int k = 0; k < (lookup.size() - 1); k++) { // pass cdd each set of groups to commpare
137                                 for (int l = n; l < lookup.size(); l++) {
138                                                                                 subset.clear(); //clear out old pair of sharedrabunds
139                                                                                 //add new pair of sharedrabund vectors
140                                                                                 subset.push_back(lookup[k]); subset.push_back(lookup[l]);
141                                                                                 ccd->updateSharedData(subset, totalNumSeq, globaldata->Groups.size());
142                                 }
143                                 n++;
144                         }
145                                                 //if this is a calculator that can do multiples then do them
146                                                 ccd->updateSharedData(lookup, totalNumSeq, globaldata->Groups.size()); 
147                 }
148                 
149                 //resets output files
150                 for(int i=0;i<displays.size();i++){
151                         displays[i]->reset();
152                 }
153                                 
154                                 //memory cleanup
155                                 delete ccd;
156                                 for (int i = 0; i < lookup.size(); i++) {
157                                         delete lookup[i];
158                                 }
159
160         }
161         catch(exception& e) {
162                 errorOut(e, "Collect", "getSharedCurve");
163                                 exit(1);
164         }
165 }
166
167 /**************************************************************************************/
168
169 void Collect::getGroupComb() {
170         string group;
171                 
172         numGroupComb = 0;
173                 
174         int n = 1;
175         for (int i = 0; i < (globaldata->Groups.size() - 1); i++) {
176                 for (int l = n; l < globaldata->Groups.size(); l++) {
177                         group = globaldata->Groups[i] + globaldata->Groups[l];
178                         groupComb.push_back(group);        
179                         numGroupComb++;
180                 }
181                 n++;
182         }
183
184 }
185
186 /**************************************************************************************/