5 * Created by Sarah Westcott on 11/18/08.
6 * Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved.
12 /***********************************************************************/
14 int Collect::getCurve(float percentFreq = 0.01){
16 RAbundVector* lookup = new RAbundVector(order->getNumBins());
17 SAbundVector* rank = new SAbundVector(order->getMaxRank()+1);
19 CollectorsCurveData* ccd = new CollectorsCurveData();
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
26 //convert freq percentage to number
28 if (percentFreq < 1.0) { increment = numSeqs * percentFreq; }
29 else { increment = percentFreq; }
31 for(int i=0;i<numSeqs;i++){
33 if (m->control_pressed) { delete lookup; delete rank; delete ccd; return 1; }
35 int binNumber = order->get(i);
36 int abundance = lookup->get(binNumber);
38 rank->set(abundance, rank->get(abundance)-1);
42 lookup->set(binNumber, abundance);
43 rank->set(abundance, rank->get(abundance)+1); //increment rank(abundance)
45 if((i == 0) || (i+1) % increment == 0){
46 ccd->updateRankData(rank);
50 if(numSeqs % increment != 0){
51 ccd->updateRankData(rank);
54 for(int i=0;i<displays.size();i++){
65 m->errorOut(e, "Collect", "getCurve");
70 /***********************************************************************/
71 int Collect::getSharedCurve(float percentFreq = 0.01){
73 vector<SharedRAbundVector*> lookup;
74 vector<SharedRAbundVector*> subset;
76 //create and initialize vector of sharedvectors, one for each group
77 for (int i = 0; i < m->Groups.size(); i++) {
78 SharedRAbundVector* temp = new SharedRAbundVector(sharedorder->getNumBins());
79 temp->setLabel(sharedorder->getLabel());
80 temp->setGroup(m->Groups[i]);
81 lookup.push_back(temp);
84 SharedCollectorsCurveData* ccd = new SharedCollectorsCurveData();
86 //initialize labels for output
87 //makes 'uniqueAB uniqueAC uniqueBC' if your groups are A, B, C
90 for(int i=0;i<displays.size();i++){
91 ccd->registerDisplay(displays[i]); //adds a display[i] to cdd
92 bool hasLciHci = displays[i]->hasLciHci();
94 for (int s = 0; s < groupComb.size(); s++) {
95 if (hasLciHci) { groupLabel = groupLabel + label + groupComb[s] + "\t" + label + groupComb[s] + "lci\t" + label + groupComb[s] + "hci\t"; }
96 else{ groupLabel = groupLabel + label + groupComb[s] + "\t"; }
99 string groupLabelAll = groupLabel + label + "all\t";
100 if ((displays[i]->isCalcMultiple() == true) && (displays[i]->getAll() == true)) { displays[i]->init(groupLabelAll); }
101 else { displays[i]->init(groupLabel); }
104 //convert freq percentage to number
106 if (percentFreq < 1.0) { increment = numSeqs * percentFreq; }
107 else { increment = percentFreq; }
109 //sample all the members
110 for(int i=0;i<numSeqs;i++){
112 if (m->control_pressed) { for (int j = 0; j < lookup.size(); j++) { delete lookup[j]; } delete ccd; return 1; }
115 individual chosen = sharedorder->get(i);
118 //set info for sharedvector in chosens group
119 for (int j = 0; j < lookup.size(); j++) {
120 if (chosen.group == lookup[j]->getGroup()) {
121 abundance = lookup[j]->getAbundance(chosen.bin);
122 lookup[j]->set(chosen.bin, (abundance + 1), chosen.group);
127 //calculate at 0 and the given increment
128 if((i == 0) || (i+1) % increment == 0){
130 //how many comparisons to make i.e. for group a, b, c = ab, ac, bc.
134 for (int k = 0; k < (lookup.size() - 1); k++) { // pass cdd each set of groups to commpare
135 for (int l = n; l < lookup.size(); l++) {
136 subset.clear(); //clear out old pair of sharedrabunds
137 //add new pair of sharedrabund vectors
138 subset.push_back(lookup[k]); subset.push_back(lookup[l]);
140 //load subset with rest of lookup for those calcs that need everyone to calc for a pair
141 for (int w = 0; w < lookup.size(); w++) {
142 if ((w != k) && (w != l)) { subset.push_back(lookup[w]); }
145 ccd->updateSharedData(subset, i+1, m->Groups.size(), pair);
150 //if this is a calculator that can do multiples then do them
152 ccd->updateSharedData(lookup, i+1, m->Groups.size(), pair);
158 //calculate last label if you haven't already
159 if(numSeqs % increment != 0){
160 //how many comparisons to make i.e. for group a, b, c = ab, ac, bc.
163 for (int k = 0; k < (lookup.size() - 1); k++) { // pass cdd each set of groups to commpare
164 for (int l = n; l < lookup.size(); l++) {
165 subset.clear(); //clear out old pair of sharedrabunds
166 //add new pair of sharedrabund vectors
167 subset.push_back(lookup[k]); subset.push_back(lookup[l]);
169 //load subset with rest of lookup for those calcs that need everyone to calc for a pair
170 for (int w = 0; w < lookup.size(); w++) {
171 if ((w != k) && (w != l)) { subset.push_back(lookup[w]); }
174 ccd->updateSharedData(subset, totalNumSeq, m->Groups.size(), pair);
178 //if this is a calculator that can do multiples then do them
180 ccd->updateSharedData(lookup, totalNumSeq, m->Groups.size(), pair);
183 //resets output files
184 for(int i=0;i<displays.size();i++){
185 displays[i]->reset();
190 for (int i = 0; i < lookup.size(); i++) {
197 catch(exception& e) {
198 m->errorOut(e, "Collect", "getSharedCurve");
203 /**************************************************************************************/
205 void Collect::getGroupComb() {
211 for (int i = 0; i < (m->Groups.size() - 1); i++) {
212 for (int l = n; l < m->Groups.size(); l++) {
213 group = m->Groups[i] + m->Groups[l];
214 groupComb.push_back(group);
222 /**************************************************************************************/