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"
13 #include "calculator.h"
15 /***********************************************************************/
17 SAbundVector::SAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){};
19 /***********************************************************************/
21 SAbundVector::SAbundVector(int size) : DataVector(), data(size, 0), maxRank(0), numBins(0), numSeqs(0) {};
23 /***********************************************************************/
25 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(vector <int> dataVec, int mr, int nb, int ns) {
53 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function SAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
57 cout << "An unknown error has occurred in the SAbundVector class function SAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
61 /***********************************************************************/
63 SAbundVector::SAbundVector(ifstream& f): DataVector(), maxRank(0), numBins(0), numSeqs(0) {
68 data.assign(hold+1, 0);
71 for(int i=1;i<=hold;i++){
77 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function SAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
81 cout << "An unknown error has occurred in the SAbundVector class function SAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
87 /***********************************************************************/
89 void SAbundVector::set(int sabund, int abundance){
92 int initSize = data[sabund];
93 data[sabund] = abundance;
96 numBins += (abundance - initSize);
99 numSeqs += sabund * (abundance - initSize);
101 if(sabund > maxRank) { maxRank = sabund; }
103 catch(exception& e) {
104 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
108 cout << "An unknown error has occurred in the SAbundVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
114 /***********************************************************************/
116 int SAbundVector::get(int index){
120 /***********************************************************************/
122 void SAbundVector::push_back(int abundance){
124 data.push_back(abundance);
128 numBins += abundance;
130 numSeqs += (maxRank * abundance);
132 catch(exception& e) {
133 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
137 cout << "An unknown error has occurred in the SAbundVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
141 /***********************************************************************/
143 void SAbundVector::quicksort(){
144 sort(data.rbegin(), data.rend());
147 /***********************************************************************/
149 int SAbundVector::sum(){
151 return vecCalc.sumElements(data);
154 /***********************************************************************/
156 void SAbundVector::resize(int size){
160 /***********************************************************************/
162 int SAbundVector::size(){
166 /***********************************************************************/
167 void SAbundVector::print(string prefix, ostream& output){
169 output << prefix << '\t' << maxRank << '\t';
171 for(int i=1;i<=maxRank;i++){
172 output << data[i] << '\t';
177 /***********************************************************************/
178 void SAbundVector::print(ostream& output){
180 output << label << '\t' << maxRank << '\t';
182 for(int i=1;i<=maxRank;i++){
183 output << data[i] << '\t';
187 catch(exception& e) {
188 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
192 cout << "An unknown error has occurred in the SAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
197 /**********************************************************************/
198 int SAbundVector::getNumBins(){
199 // if(needToUpdate == 1){ updateStats(); }
203 /***********************************************************************/
205 int SAbundVector::getNumSeqs(){
206 // if(needToUpdate == 1){ updateStats(); }
210 /***********************************************************************/
212 int SAbundVector::getMaxRank(){
213 // if(needToUpdate == 1){ updateStats(); }
216 /***********************************************************************/
217 RAbundVector SAbundVector::getRAbundVector(){
221 for(int i=1;i<=data.size();i++){
222 for(int j=0;j<data[i];j++){
226 sort(rav.rbegin(), rav.rend());
231 catch(exception& e) {
232 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
236 cout << "An unknown error has occurred in the SAbundVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
241 /***********************************************************************/
243 SAbundVector SAbundVector::getSAbundVector(){
247 /***********************************************************************/
249 OrderVector SAbundVector::getOrderVector(map<string,int>* hold = NULL){
255 for(int i=1;i<data.size();i++){
256 for(int j=0;j<data[i];j++){
257 for(int k=0;k<i;k++){
258 ov.push_back(binIndex);
264 random_shuffle(ov.begin(), ov.end());
270 catch(exception& e) {
271 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
275 cout << "An unknown error has occurred in the SAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
280 /***********************************************************************/