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 void 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 int binNumber = order->get(i);
35 int abundance = lookup->get(binNumber);
37 rank->set(abundance, rank->get(abundance)-1);
40 lookup->set(binNumber, abundance);
41 rank->set(abundance, rank->get(abundance)+1);
43 if((i == 0) || (i+1) % increment == 0){
44 rcd->updateRankData(rank);
48 if(numSeqs % increment != 0){
49 rcd->updateRankData(rank);
52 for(int i=0;i<displays.size();i++){
60 for(int i=0;i<displays.size();i++){
66 cout << "Standard Error: " << e.what() << " has occurred in the Rarefact class Function getCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
70 cout << "An unknown error has occurred in the Rarefact class function getCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
75 /***********************************************************************/
77 void Rarefact::getSharedCurve(int increment = 1, int nIters = 1000){
79 globaldata = GlobalData::getInstance();
80 SharedRarefactionCurveData* rcd = new SharedRarefactionCurveData();
82 //register the displays
83 for(int i=0;i<displays.size();i++){
84 rcd->registerDisplay(displays[i]);
87 for(int iter=0;iter<nIters;iter++){
88 //clear out old values for new iter
91 //create and initialize vector of sharedvectors, one for each group
92 for (int i = 0; i < globaldata->Groups.size(); i++) {
93 SharedRAbundVector* temp = new SharedRAbundVector(sharedorder->getNumBins());
94 temp->setLabel(sharedorder->getLabel());
95 temp->setGroup(globaldata->Groups[i]);
96 lookup.push_back(temp);
99 for(int i=0;i<displays.size();i++){
100 displays[i]->init(label);
103 //sample all the members
104 for(int i=0;i<numSeqs;i++){
106 individual chosen = sharedorder->get(i);
109 //set info for sharedvector in chosens group
110 for (int j = 0; j < lookup.size(); j++) {
111 if (chosen.group == lookup[j]->getGroup()) {
112 abundance = lookup[j]->getAbundance(chosen.bin);
113 lookup[j]->set(chosen.bin, (abundance + 1), chosen.group);
119 //randomize the groups
120 random_shuffle(lookup.begin(), lookup.end());
122 vector<SharedRAbundVector*> subset;
123 //send each group one at a time
124 for (int k = 0; k < lookup.size(); k++) {
125 subset.clear(); //clears out old pair of sharedrabunds
126 //add in new pair of sharedrabunds
127 subset.push_back(lookup[0]); subset.push_back(lookup[k]);
129 rcd->updateSharedData(subset, k+1, numGroupComb);
130 mergeVectors(lookup[0], lookup[k]);
133 //resets output files
134 for(int i=0;i<displays.size();i++){
135 displays[i]->reset();
138 for (int i = 0; i < lookup.size(); i++) {
143 for(int i=0;i<displays.size();i++){
144 displays[i]->close();
149 catch(exception& e) {
150 cout << "Standard Error: " << e.what() << " has occurred in the Rarefact class Function getSharedCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
154 cout << "An unknown error has occurred in the Rarefact class function getSharedCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
160 /**************************************************************************************/
161 void Rarefact::mergeVectors(SharedRAbundVector* shared1, SharedRAbundVector* shared2) {
163 for (int k = 0; k < shared1->size(); k++) {
164 //merge new species into shared1
165 if ((shared1->getAbundance(k) == 0) && (shared2->getAbundance(k) != 0)) {
166 shared1->set(k, shared2->getAbundance(k), "combo"); //set to 'combo' since this vector now contains multiple groups
170 catch(exception& e) {
171 cout << "Standard Error: " << e.what() << " has occurred in the Rarefact class Function mergeVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
175 cout << "An unknown error has occurred in the Rarefact class function mergeVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";