X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=rabundvector.cpp;fp=rabundvector.cpp;h=fd7f3acecf930dbb39c822748c34c7420da19826;hb=20a2d0350a737a434c89f303662d64a8eeea7b05;hp=0000000000000000000000000000000000000000;hpb=bbb5879a7e566935c23d63d42bb945072424b939;p=mothur.git diff --git a/rabundvector.cpp b/rabundvector.cpp new file mode 100644 index 0000000..fd7f3ac --- /dev/null +++ b/rabundvector.cpp @@ -0,0 +1,289 @@ +/* + * rabundvector.cpp + * + * + * Created by Pat Schloss on 8/8/08. + * Copyright 2008 Patrick D. Schloss. All rights reserved. + * + */ +using namespace std; + +#include "datavector.hpp" +#include "utilities.hpp" +#include +#include "rabundvector.hpp" +#include "sabundvector.hpp" +#include "ordervector.hpp" + + +/***********************************************************************/ + +RAbundVector::RAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0) {}; + +/***********************************************************************/ + +RAbundVector::RAbundVector(int n) : DataVector(), data(n,0) , maxRank(0), numBins(0), numSeqs(0) {}; + +/***********************************************************************/ + +//RAbundVector::RAbundVector(const RAbundVector& rav) : DataVector(rav), data(rav.data), (rav.label), (rav.maxRank), (rav.numBins), (rav.numSeqs){}; + + +/***********************************************************************/ + +RAbundVector::RAbundVector(string id, vector rav) : DataVector(id), data(rav) { + try { + numBins = 0; + maxRank = 0; + numSeqs = 0; + + for(int i=0;i maxRank) { maxRank = data[i]; } + numSeqs += data[i]; + } + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the RAbundVector class function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} + + +/***********************************************************************/ + + +RAbundVector::RAbundVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) { + try { + int hold; + f >> label >> hold; + + data.assign(hold, 0); + int inputData; + + for(int i=0;i> inputData; + set(i, inputData); + } + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the RAbundVector class function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} + +/***********************************************************************/ + +RAbundVector::~RAbundVector() { + +} + +/***********************************************************************/ + +void RAbundVector::set(int binNumber, int newBinSize){ + try { + int oldBinSize = data[binNumber]; + data[binNumber] = newBinSize; + + if(oldBinSize == 0) { numBins++; } + if(newBinSize == 0) { numBins--; } + if(newBinSize > maxRank) { maxRank = newBinSize; } + + numSeqs += (newBinSize - oldBinSize); + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the RAbundVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} + +/***********************************************************************/ + +int RAbundVector::get(int index){ + return data[index]; + +} + +/***********************************************************************/ + +void RAbundVector::push_back(int binSize){ + try { + data.push_back(binSize); + numBins++; + + if(binSize > maxRank){ + maxRank = binSize; + } + + numSeqs += binSize; + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the RAbundVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} + +/***********************************************************************/ + +void RAbundVector::pop_back(){ + + return data.pop_back(); +} + +/***********************************************************************/ + +void RAbundVector::resize(int size){ + + data.resize(size); +} + +/***********************************************************************/ + +int RAbundVector::size(){ + return data.size(); +} + +/***********************************************************************/ + +vector::reverse_iterator RAbundVector::rbegin(){ + return data.rbegin(); +} + +/***********************************************************************/ + +vector::reverse_iterator RAbundVector::rend(){ + return data.rend(); +} + +/***********************************************************************/ +void RAbundVector::print(string prefix, ostream& output){ + try { + output << prefix << '\t' << numBins << '\t'; + + vector hold = data; + sort(hold.rbegin(), hold.rend()); + + for(int i=0;i hold = data; + sort(hold.rbegin(), hold.rend()); + + for(int i=0;i* nameMap = NULL) { + try { + OrderVector ov; + + for(int i=0;i