5 * Created by Pat Schloss on 8/8/08.
6 * Copyright 2008 Patrick D. Schloss. All rights resesaved.
10 #include "sabundvector.hpp"
11 #include "calculator.h"
13 /***********************************************************************/
15 SAbundVector::SAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){}
17 /***********************************************************************/
19 SAbundVector::SAbundVector(int size) : DataVector(), data(size, 0), maxRank(0), numBins(0), numSeqs(0) {}
21 /***********************************************************************/
23 SAbundVector::SAbundVector(string id, vector<int> sav) : DataVector(id), data(sav) {
25 for(int i=0;i<sav.size();i++){
26 if(data[i] != 0){ maxRank = i; }
32 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function SAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
36 cout << "An unknown error has occurred in the SAbundVector class function SAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
41 /***********************************************************************/
43 SAbundVector::SAbundVector(vector <int> dataVec, int mr, int nb, int ns) {
51 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function SAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
55 cout << "An unknown error has occurred in the SAbundVector class function SAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
59 /***********************************************************************/
61 SAbundVector::SAbundVector(ifstream& f): DataVector(), maxRank(0), numBins(0), numSeqs(0) {
66 data.assign(hold+1, 0);
69 for(int i=1;i<=hold;i++){
75 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function SAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
79 cout << "An unknown error has occurred in the SAbundVector class function SAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
85 /***********************************************************************/
87 void SAbundVector::set(int sabund, int abundance){
90 int initSize = data[sabund];
91 data[sabund] = abundance;
94 numBins += (abundance - initSize);
97 numSeqs += sabund * (abundance - initSize);
99 if(sabund > maxRank) { maxRank = sabund; }
101 catch(exception& e) {
102 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
106 cout << "An unknown error has occurred in the SAbundVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
112 /***********************************************************************/
114 int SAbundVector::get(int index){
118 /***********************************************************************/
120 void SAbundVector::push_back(int abundance){
122 data.push_back(abundance);
126 numBins += abundance;
128 numSeqs += (maxRank * abundance);
130 catch(exception& e) {
131 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
135 cout << "An unknown error has occurred in the SAbundVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
139 /***********************************************************************/
141 void SAbundVector::quicksort(){
142 sort(data.rbegin(), data.rend());
145 /***********************************************************************/
147 int SAbundVector::sum(){
149 return vecCalc.sumElements(data);
152 /***********************************************************************/
154 void SAbundVector::resize(int size){
158 /***********************************************************************/
160 int SAbundVector::size(){
164 /***********************************************************************/
165 void SAbundVector::print(string prefix, ostream& output){
167 output << prefix << '\t' << maxRank << '\t';
169 for(int i=1;i<=maxRank;i++){
170 output << data[i] << '\t';
175 /***********************************************************************/
176 void SAbundVector::print(ostream& output){
178 output << label << '\t' << maxRank << '\t';
180 for(int i=1;i<=maxRank;i++){
181 output << data[i] << '\t';
185 catch(exception& e) {
186 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
190 cout << "An unknown error has occurred in the SAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
195 /**********************************************************************/
196 int SAbundVector::getNumBins(){
197 // if(needToUpdate == 1){ updateStats(); }
201 /***********************************************************************/
203 int SAbundVector::getNumSeqs(){
204 // if(needToUpdate == 1){ updateStats(); }
208 /***********************************************************************/
210 int SAbundVector::getMaxRank(){
211 // if(needToUpdate == 1){ updateStats(); }
214 /***********************************************************************/
215 RAbundVector SAbundVector::getRAbundVector(){
219 for(int i=1;i<=data.size();i++){
220 for(int j=0;j<data[i];j++){
224 sort(rav.rbegin(), rav.rend());
229 catch(exception& e) {
230 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
234 cout << "An unknown error has occurred in the SAbundVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
239 /***********************************************************************/
241 SAbundVector SAbundVector::getSAbundVector(){
245 /***********************************************************************/
247 OrderVector SAbundVector::getOrderVector(map<string,int>* hold = NULL){
253 for(int i=1;i<data.size();i++){
254 for(int j=0;j<data[i];j++){
255 for(int k=0;k<i;k++){
256 ov.push_back(binIndex);
262 random_shuffle(ov.begin(), ov.end());
268 catch(exception& e) {
269 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
273 cout << "An unknown error has occurred in the SAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
278 /***********************************************************************/