5 * Created by Pat Schloss on 8/8/08.
6 * Copyright 2008 Patrick D. Schloss. All rights resesaved.
11 #include "sabundvector.hpp"
12 #include "utilities.hpp"
14 /***********************************************************************/
16 SAbundVector::SAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){};
18 /***********************************************************************/
20 SAbundVector::SAbundVector(int size) : DataVector(), data(size, 0), maxRank(0), numBins(0), numSeqs(0) {};
22 /***********************************************************************/
24 SAbundVector::SAbundVector(string id, vector<int> sav) : DataVector(id), data(sav) {
27 for(int i=0;i<sav.size();i++){
28 if(data[i] != 0){ maxRank = i; }
34 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function SAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
38 cout << "An unknown error has occurred in the SAbundVector class function SAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
43 /***********************************************************************/
45 SAbundVector::SAbundVector(ifstream& f): DataVector(), maxRank(0), numBins(0), numSeqs(0) {
50 data.assign(hold+1, 0);
53 for(int i=1;i<=hold;i++){
59 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function SAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
63 cout << "An unknown error has occurred in the SAbundVector class function SAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
68 /***********************************************************************/
70 void SAbundVector::set(int sabund, int abundance){
73 int initSize = data[sabund];
74 data[sabund] = abundance;
77 numBins += (abundance - initSize);
80 numSeqs += sabund * (abundance - initSize);
82 if(sabund > maxRank) { maxRank = sabund; }
85 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
89 cout << "An unknown error has occurred in the SAbundVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
94 /***********************************************************************/
96 int SAbundVector::get(int index){
100 /***********************************************************************/
102 void SAbundVector::push_back(int abundance){
104 data.push_back(abundance);
108 numBins += abundance;
110 numSeqs += (maxRank * abundance);
112 catch(exception& e) {
113 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
117 cout << "An unknown error has occurred in the SAbundVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
122 /***********************************************************************/
124 void SAbundVector::resize(int size){
128 /***********************************************************************/
130 int SAbundVector::size(){
134 /***********************************************************************/
135 void SAbundVector::print(string prefix, ostream& output){
137 output << prefix << '\t' << maxRank << '\t';
139 for(int i=1;i<=maxRank;i++){
140 output << data[i] << '\t';
145 /***********************************************************************/
146 void SAbundVector::print(ostream& output){
148 output << label << '\t' << maxRank << '\t';
150 for(int i=1;i<=maxRank;i++){
151 output << data[i] << '\t';
155 catch(exception& e) {
156 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
160 cout << "An unknown error has occurred in the SAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
165 /**********************************************************************/
166 int SAbundVector::getNumBins(){
167 // if(needToUpdate == 1){ updateStats(); }
171 /***********************************************************************/
173 int SAbundVector::getNumSeqs(){
174 // if(needToUpdate == 1){ updateStats(); }
178 /***********************************************************************/
180 int SAbundVector::getMaxRank(){
181 // if(needToUpdate == 1){ updateStats(); }
184 /***********************************************************************/
185 RAbundVector SAbundVector::getRAbundVector(){
189 for(int i=1;i<=data.size();i++){
190 for(int j=0;j<data[i];j++){
194 sort(rav.rbegin(), rav.rend());
199 catch(exception& e) {
200 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
204 cout << "An unknown error has occurred in the SAbundVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
209 /***********************************************************************/
211 SAbundVector SAbundVector::getSAbundVector(){
215 /***********************************************************************/
217 OrderVector SAbundVector::getOrderVector(map<string,int>* hold = NULL){
223 for(int i=1;i<data.size();i++){
224 for(int j=0;j<data[i];j++){
225 for(int k=0;k<i;k++){
226 ov.push_back(binIndex);
232 random_shuffle(ov.begin(), ov.end());
238 catch(exception& e) {
239 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
243 cout << "An unknown error has occurred in the SAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
248 /***********************************************************************/