5 * Created by Pat Schloss on 8/8/08.
6 * Copyright 2008 Patrick D. Schloss. All rights resesaved.
11 #include "sabundvector.hpp"
12 #include "datavector.hpp"
13 #include "utilities.hpp"
16 /***********************************************************************/
18 SAbundVector::SAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){};
20 /***********************************************************************/
22 SAbundVector::SAbundVector(int size) : DataVector(), data(size, 0), maxRank(0), numBins(0), numSeqs(0) {};
24 /***********************************************************************/
26 SAbundVector::SAbundVector(string id, vector<int> sav) : DataVector(id), data(sav) {
29 for(int i=0;i<sav.size();i++){
30 if(data[i] != 0){ maxRank = i; }
36 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function SAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
40 cout << "An unknown error has occurred in the SAbundVector class function SAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
45 /***********************************************************************/
47 SAbundVector::SAbundVector(ifstream& f): DataVector(), maxRank(0), numBins(0), numSeqs(0) {
52 data.assign(hold+1, 0);
55 for(int i=1;i<=hold;i++){
61 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function SAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
65 cout << "An unknown error has occurred in the SAbundVector class function SAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
70 /***********************************************************************/
72 void SAbundVector::set(int sabund, int abundance){
75 int initSize = data[sabund];
76 data[sabund] = abundance;
79 numBins += (abundance - initSize);
82 numSeqs += sabund * (abundance - initSize);
84 if(sabund > maxRank) { maxRank = sabund; }
87 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
91 cout << "An unknown error has occurred in the SAbundVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
96 /***********************************************************************/
98 int SAbundVector::get(int index){
102 /***********************************************************************/
104 void SAbundVector::push_back(int abundance){
106 data.push_back(abundance);
110 numBins += abundance;
112 numSeqs += (maxRank * abundance);
114 catch(exception& e) {
115 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
119 cout << "An unknown error has occurred in the SAbundVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
124 /***********************************************************************/
126 void SAbundVector::resize(int size){
130 /***********************************************************************/
132 int SAbundVector::size(){
136 /***********************************************************************/
137 void SAbundVector::print(string prefix, ostream& output){
139 output << prefix << '\t' << maxRank << '\t';
141 for(int i=1;i<=maxRank;i++){
142 output << data[i] << '\t';
147 /***********************************************************************/
148 void SAbundVector::print(ostream& output){
150 output << label << '\t' << maxRank << '\t';
152 for(int i=1;i<=maxRank;i++){
153 output << data[i] << '\t';
157 catch(exception& e) {
158 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
162 cout << "An unknown error has occurred in the SAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
167 /**********************************************************************/
168 int SAbundVector::getNumBins(){
169 // if(needToUpdate == 1){ updateStats(); }
173 /***********************************************************************/
175 int SAbundVector::getNumSeqs(){
176 // if(needToUpdate == 1){ updateStats(); }
180 /***********************************************************************/
182 int SAbundVector::getMaxRank(){
183 // if(needToUpdate == 1){ updateStats(); }
186 /***********************************************************************/
187 RAbundVector SAbundVector::getRAbundVector(){
191 for(int i=1;i<=data.size();i++){
192 for(int j=0;j<data[i];j++){
196 sort(rav.rbegin(), rav.rend());
201 catch(exception& e) {
202 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
206 cout << "An unknown error has occurred in the SAbundVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
211 /***********************************************************************/
213 SAbundVector SAbundVector::getSAbundVector(){
217 /***********************************************************************/
219 OrderVector SAbundVector::getOrderVector(map<string,int>* hold = NULL){
225 for(int i=1;i<data.size();i++){
226 for(int j=0;j<data[i];j++){
227 for(int k=0;k<i;k++){
228 ov.push_back(binIndex);
234 random_shuffle(ov.begin(), ov.end());
240 catch(exception& e) {
241 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
245 cout << "An unknown error has occurred in the SAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
250 /***********************************************************************/