5 * Created by Pat Schloss on 8/8/08.
6 * Copyright 2008 Patrick D. Schloss. All rights resesaved.
11 #include "sabundvector.hpp"
12 #include "calculator.h"
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) {
26 for(int i=0;i<sav.size();i++){
27 if(data[i] != 0){ maxRank = i; }
33 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function SAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
37 cout << "An unknown error has occurred in the SAbundVector class function SAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
42 /***********************************************************************/
44 SAbundVector::SAbundVector(vector <int> dataVec, int mr, int nb, int ns) {
52 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function SAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
56 cout << "An unknown error has occurred in the SAbundVector class function SAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
60 /***********************************************************************/
62 SAbundVector::SAbundVector(ifstream& f): DataVector(), maxRank(0), numBins(0), numSeqs(0) {
67 data.assign(hold+1, 0);
70 for(int i=1;i<=hold;i++){
76 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function SAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
80 cout << "An unknown error has occurred in the SAbundVector class function SAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
86 /***********************************************************************/
88 void SAbundVector::set(int sabund, int abundance){
91 int initSize = data[sabund];
92 data[sabund] = abundance;
95 numBins += (abundance - initSize);
98 numSeqs += sabund * (abundance - initSize);
100 if(sabund > maxRank) { maxRank = sabund; }
102 catch(exception& e) {
103 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
107 cout << "An unknown error has occurred in the SAbundVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
113 /***********************************************************************/
115 int SAbundVector::get(int index){
119 /***********************************************************************/
121 void SAbundVector::push_back(int abundance){
123 data.push_back(abundance);
127 numBins += abundance;
129 numSeqs += (maxRank * abundance);
131 catch(exception& e) {
132 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
136 cout << "An unknown error has occurred in the SAbundVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
140 /***********************************************************************/
142 void SAbundVector::quicksort(){
143 sort(data.rbegin(), data.rend());
146 /***********************************************************************/
148 int SAbundVector::sum(){
150 return vecCalc.sumElements(data);
153 /***********************************************************************/
155 void SAbundVector::resize(int size){
159 /***********************************************************************/
161 int SAbundVector::size(){
165 /***********************************************************************/
166 void SAbundVector::print(string prefix, ostream& output){
168 output << prefix << '\t' << maxRank << '\t';
170 for(int i=1;i<=maxRank;i++){
171 output << data[i] << '\t';
176 /***********************************************************************/
177 void SAbundVector::print(ostream& output){
179 output << label << '\t' << maxRank << '\t';
181 for(int i=1;i<=maxRank;i++){
182 output << data[i] << '\t';
186 catch(exception& e) {
187 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
191 cout << "An unknown error has occurred in the SAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
196 /**********************************************************************/
197 int SAbundVector::getNumBins(){
198 // if(needToUpdate == 1){ updateStats(); }
202 /***********************************************************************/
204 int SAbundVector::getNumSeqs(){
205 // if(needToUpdate == 1){ updateStats(); }
209 /***********************************************************************/
211 int SAbundVector::getMaxRank(){
212 // if(needToUpdate == 1){ updateStats(); }
215 /***********************************************************************/
216 RAbundVector SAbundVector::getRAbundVector(){
220 for(int i=1;i<=data.size();i++){
221 for(int j=0;j<data[i];j++){
225 sort(rav.rbegin(), rav.rend());
230 catch(exception& e) {
231 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
235 cout << "An unknown error has occurred in the SAbundVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
240 /***********************************************************************/
242 SAbundVector SAbundVector::getSAbundVector(){
246 /***********************************************************************/
248 OrderVector SAbundVector::getOrderVector(map<string,int>* hold = NULL){
254 for(int i=1;i<data.size();i++){
255 for(int j=0;j<data[i];j++){
256 for(int k=0;k<i;k++){
257 ov.push_back(binIndex);
263 random_shuffle(ov.begin(), ov.end());
269 catch(exception& e) {
270 cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
274 cout << "An unknown error has occurred in the SAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
279 /***********************************************************************/