2 * sharedSharedOrderVector.cpp
5 * Created by Sarah Westcott on 12/9/08.
6 * Copyright 2008 __MyCompanyName__. All rights reserved.
13 #include "sharedordervector.h"
14 #include "datavector.hpp"
15 #include "utilities.hpp"
18 /***********************************************************************/
20 SharedOrderVector::SharedOrderVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0) {}
22 /***********************************************************************/
24 SharedOrderVector::SharedOrderVector(string id, vector<individual> ov) :
25 DataVector(id), data(ov)
30 /***********************************************************************
32 SharedOrderVector::SharedOrderVector(ifstream& f) : DataVector() {
39 data.assign(hold, -1);
43 for(int i=0;i<hold;i++){
51 cout << "Standard Error: " << e.what() << " has occurred in the SharedOrderVector class Function SharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
55 cout << "An unknown error has occurred in the SharedOrderVector class function SharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
60 /***********************************************************************/
63 int SharedOrderVector::getNumBins(){
64 if(needToUpdate == 1){ updateStats(); }
68 /***********************************************************************/
70 int SharedOrderVector::getNumSeqs(){
71 if(needToUpdate == 1){ updateStats(); }
75 /***********************************************************************/
77 int SharedOrderVector::getMaxRank(){
78 if(needToUpdate == 1){ updateStats(); }
83 /***********************************************************************/
87 void SharedOrderVector::set(int index, int binNumber, int abund, string groupName){
89 data[index].group = groupName;
90 data[index].bin = binNumber;
91 data[index].abundance = abund;
96 /***********************************************************************/
98 individual SharedOrderVector::get(int index){
103 /***********************************************************************/
105 void SharedOrderVector::push_back(int binNumber, int abund, string groupName){
107 newGuy.group = groupName;
108 newGuy.abundance = abund;
109 newGuy.bin = binNumber;
110 data.push_back(newGuy);
115 /***********************************************************************/
117 void SharedOrderVector::print(ostream& output){
119 output << label << '\t' << numSeqs << '\t';
121 for(int i=0;i<data.size();i++){
122 output << data[i].bin << '\t';
126 catch(exception& e) {
127 cout << "Standard Error: " << e.what() << " has occurred in the SharedOrderVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
131 cout << "An unknown error has occurred in the SharedOrderVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
137 /***********************************************************************/
139 void SharedOrderVector::resize(int){
140 cout << "resize() did nothing in class SharedOrderVector";
143 /***********************************************************************/
146 vector<individual>::iterator SharedOrderVector::begin(){
150 /***********************************************************************/
152 vector<individual>::iterator SharedOrderVector::end(){
156 /***********************************************************************/
158 int SharedOrderVector::size(){
162 /***********************************************************************/
164 RAbundVector SharedOrderVector::getRAbundVector(){
166 RAbundVector rav(data.size());
168 for(int i=0;i<numSeqs;i++){
169 rav.set(data[i].bin, rav.get(data[i].bin) + 1);
171 sort(rav.rbegin(), rav.rend());
172 for(int i=numSeqs-1;i>=0;i--){
173 if(rav.get(i) == 0){ rav.pop_back(); }
182 catch(exception& e) {
183 cout << "Standard Error: " << e.what() << " has occurred in the SharedOrderVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
187 cout << "An unknown error has occurred in the SharedOrderVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
191 /***********************************************************************/
193 OrderVector SharedOrderVector::getOrderVector(map<string,int>* nameMap = NULL) {
197 for (int i = 0; i < data.size(); i++) {
198 ov.push_back(data[i].bin);
201 random_shuffle(ov.begin(), ov.end());
206 catch(exception& e) {
207 cout << "Standard Error: " << e.what() << " has occurred in the SharedOrderVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
211 cout << "An unknown error has occurred in the SharedOrderVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
217 /***********************************************************************/
219 SAbundVector SharedOrderVector::getSAbundVector(){
221 RAbundVector rav(this->getRAbundVector());
222 return rav.getSAbundVector();
226 /***********************************************************************/
228 SharedOrderVector SharedOrderVector::getSharedOrderVector(){
232 /***********************************************************************/
234 void SharedOrderVector::updateStats(){
241 for(int i=0;i<data.size();i++){
242 if(data[i].bin != -1){
247 vector<individual> hold(numSeqs);
249 for(int i=0;i<numSeqs;i++){
250 if(data[i].bin != -1){
251 hold[data[i].bin].bin = hold[data[i].bin].bin+1;
255 for(int i=0;i<numSeqs;i++){
256 if(data[i].bin > numBins) { numBins = data[i].bin; }
257 if(data[i].abundance > maxRank) { maxRank = data[i].abundance; }
259 numBins++; //if you have 10 bins largest .bin is 9 since we start at 0.
261 catch(exception& e) {
262 cout << "Standard Error: " << e.what() << " has occurred in the SharedOrderVector class Function updateStats. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
266 cout << "An unknown error has occurred in the SharedOrderVector class function updateStats. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
271 /***********************************************************************/