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
27 int increment = numSeqs * percentFreq;
29 for(int i=0;i<numSeqs;i++){
31 if (m->control_pressed) { delete lookup; delete rank; delete ccd; return 1; }
33 int binNumber = order->get(i);
34 int abundance = lookup->get(binNumber);
36 rank->set(abundance, rank->get(abundance)-1);
40 lookup->set(binNumber, abundance);
41 rank->set(abundance, rank->get(abundance)+1); //increment rank(abundance)
43 if((i == 0) || (i+1) % increment == 0){
44 ccd->updateRankData(rank);
48 if(numSeqs % increment != 0){
49 ccd->updateRankData(rank);
52 for(int i=0;i<displays.size();i++){
63 m->errorOut(e, "Collect", "getCurve");
68 /***********************************************************************/
69 int Collect::getSharedCurve(float percentFreq = 0.01){
71 globaldata = GlobalData::getInstance();
72 vector<SharedRAbundVector*> lookup;
73 vector<SharedRAbundVector*> subset;
75 //create and initialize vector of sharedvectors, one for each group
76 for (int i = 0; i < globaldata->Groups.size(); i++) {
77 SharedRAbundVector* temp = new SharedRAbundVector(sharedorder->getNumBins());
78 temp->setLabel(sharedorder->getLabel());
79 temp->setGroup(globaldata->Groups[i]);
80 temp->setGroupIndex(globaldata->gGroupmap->groupIndex[globaldata->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 s = 0; s < groupComb.size(); s++) {
91 groupLabel = groupLabel + label + groupComb[s] + "\t";
95 string groupLabelAll = groupLabel + label + "all\t";
97 for(int i=0;i<displays.size();i++){
98 ccd->registerDisplay(displays[i]); //adds a display[i] to cdd
99 if ((displays[i]->isCalcMultiple() == true) && (displays[i]->getAll() == true)) { displays[i]->init(groupLabelAll); }
100 else { displays[i]->init(groupLabel); }
103 //convert freq percentage to number
104 int increment = numSeqs * percentFreq;
106 //sample all the members
107 for(int i=0;i<numSeqs;i++){
109 if (m->control_pressed) { for (int j = 0; j < lookup.size(); j++) { delete lookup[j]; } delete ccd; return 1; }
112 individual chosen = sharedorder->get(i);
115 //set info for sharedvector in chosens group
116 for (int j = 0; j < lookup.size(); j++) {
117 if (chosen.group == lookup[j]->getGroup()) {
118 abundance = lookup[j]->getAbundance(chosen.bin);
119 lookup[j]->set(chosen.bin, (abundance + 1), chosen.group);
124 //calculate at 0 and the given increment
125 if((i == 0) || (i+1) % increment == 0){
127 //how many comparisons to make i.e. for group a, b, c = ab, ac, bc.
130 for (int k = 0; k < (lookup.size() - 1); k++) { // pass cdd each set of groups to commpare
131 for (int l = n; l < lookup.size(); l++) {
132 subset.clear(); //clear out old pair of sharedrabunds
133 //add new pair of sharedrabund vectors
134 subset.push_back(lookup[k]); subset.push_back(lookup[l]);
135 ccd->updateSharedData(subset, i+1, globaldata->Groups.size());
139 //if this is a calculator that can do multiples then do them
140 ccd->updateSharedData(lookup, i+1, globaldata->Groups.size());
145 //calculate last label if you haven't already
146 if(numSeqs % increment != 0){
147 //how many comparisons to make i.e. for group a, b, c = ab, ac, bc.
149 for (int k = 0; k < (lookup.size() - 1); k++) { // pass cdd each set of groups to commpare
150 for (int l = n; l < lookup.size(); l++) {
151 subset.clear(); //clear out old pair of sharedrabunds
152 //add new pair of sharedrabund vectors
153 subset.push_back(lookup[k]); subset.push_back(lookup[l]);
154 ccd->updateSharedData(subset, totalNumSeq, globaldata->Groups.size());
158 //if this is a calculator that can do multiples then do them
159 ccd->updateSharedData(lookup, totalNumSeq, globaldata->Groups.size());
162 //resets output files
163 for(int i=0;i<displays.size();i++){
164 displays[i]->reset();
169 for (int i = 0; i < lookup.size(); i++) {
176 catch(exception& e) {
177 m->errorOut(e, "Collect", "getSharedCurve");
182 /**************************************************************************************/
184 void Collect::getGroupComb() {
190 for (int i = 0; i < (globaldata->Groups.size() - 1); i++) {
191 for (int l = n; l < globaldata->Groups.size(); l++) {
192 group = globaldata->Groups[i] + globaldata->Groups[l];
193 groupComb.push_back(group);
201 /**************************************************************************************/