5 * Created by Sarah Westcott on 11/18/08.
6 * Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved.
11 //#include "ordervector.hpp"
13 /***********************************************************************/
15 int Rarefact::getCurve(int increment = 1, int nIters = 1000){
17 RarefactionCurveData* rcd = new RarefactionCurveData();
18 for(int i=0;i<displays.size();i++){
19 rcd->registerDisplay(displays[i]);
22 for(int iter=0;iter<nIters;iter++){
24 for(int i=0;i<displays.size();i++){
25 displays[i]->init(label);
28 RAbundVector* lookup = new RAbundVector(order->getNumBins());
29 SAbundVector* rank = new SAbundVector(order->getMaxRank()+1);
30 random_shuffle(order->begin(), order->end());
32 for(int i=0;i<numSeqs;i++){
34 if (m->control_pressed) { delete lookup; delete rank; delete rcd; return 0; }
36 int binNumber = order->get(i);
37 int abundance = lookup->get(binNumber);
39 rank->set(abundance, rank->get(abundance)-1);
42 lookup->set(binNumber, abundance);
43 rank->set(abundance, rank->get(abundance)+1);
45 if((i == 0) || (i+1) % increment == 0){
46 rcd->updateRankData(rank);
50 if(numSeqs % increment != 0){
51 rcd->updateRankData(rank);
54 for(int i=0;i<displays.size();i++){
62 for(int i=0;i<displays.size();i++){
69 m->errorOut(e, "Rarefact", "getCurve");
74 /***********************************************************************/
76 int Rarefact::getSharedCurve(int increment = 1, int nIters = 1000){
78 SharedRarefactionCurveData* rcd = new SharedRarefactionCurveData();
80 label = lookup[0]->getLabel();
82 //register the displays
83 for(int i=0;i<displays.size();i++){
84 rcd->registerDisplay(displays[i]);
87 //if jumble is false all iters will be the same
88 if (globaldata->jumble == false) { nIters = 1; }
90 for(int iter=0;iter<nIters;iter++){
92 for(int i=0;i<displays.size();i++){
93 displays[i]->init(label);
96 if (globaldata->jumble == true) {
97 //randomize the groups
98 random_shuffle(lookup.begin(), lookup.end());
101 //make merge the size of lookup[0]
102 SharedRAbundVector* merge = new SharedRAbundVector(lookup[0]->size());
104 //make copy of lookup zero
105 for(int i = 0; i<lookup[0]->size(); i++) {
106 merge->set(i, lookup[0]->getAbundance(i), "merge");
109 vector<SharedRAbundVector*> subset;
110 //send each group one at a time
111 for (int k = 0; k < lookup.size(); k++) {
112 if (m->control_pressed) { delete merge; delete rcd; return 0; }
114 subset.clear(); //clears out old pair of sharedrabunds
115 //add in new pair of sharedrabunds
116 subset.push_back(merge); subset.push_back(lookup[k]);
118 rcd->updateSharedData(subset, k+1, numGroupComb);
119 mergeVectors(merge, lookup[k]);
122 //resets output files
123 for(int i=0;i<displays.size();i++){
124 displays[i]->reset();
130 for(int i=0;i<displays.size();i++){
131 displays[i]->close();
137 catch(exception& e) {
138 m->errorOut(e, "Rarefact", "getSharedCurve");
143 /**************************************************************************************/
144 void Rarefact::mergeVectors(SharedRAbundVector* shared1, SharedRAbundVector* shared2) {
146 for (int k = 0; k < shared1->size(); k++) {
147 //merge new species into shared1
148 shared1->set(k, (shared1->getAbundance(k) + shared2->getAbundance(k)), "combo"); //set to 'combo' since this vector now contains multiple groups
151 catch(exception& e) {
152 m->errorOut(e, "Rarefact", "mergeVectors");