5 * Created by Pat Schloss on 8/8/08.
6 * Copyright 2008 Patrick D. Schloss. All rights reserved.
11 #include "datavector.hpp"
12 #include "utilities.hpp"
14 #include "rabundvector.hpp"
15 #include "sabundvector.hpp"
16 #include "ordervector.hpp"
19 /***********************************************************************/
21 RAbundVector::RAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0) {};
23 /***********************************************************************/
25 RAbundVector::RAbundVector(int n) : DataVector(), data(n,0) , maxRank(0), numBins(0), numSeqs(0) {};
27 /***********************************************************************/
29 //RAbundVector::RAbundVector(const RAbundVector& rav) : DataVector(rav), data(rav.data), (rav.label), (rav.maxRank), (rav.numBins), (rav.numSeqs){};
32 /***********************************************************************/
34 RAbundVector::RAbundVector(string id, vector<int> rav) : DataVector(id), data(rav) {
40 for(int i=0;i<data.size();i++){
41 if(data[i] != 0) { numBins = i+1; }
42 if(data[i] > maxRank) { maxRank = data[i]; }
47 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
51 cout << "An unknown error has occurred in the RAbundVector class function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
57 /***********************************************************************/
60 RAbundVector::RAbundVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) {
68 for(int i=0;i<hold;i++){
74 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
78 cout << "An unknown error has occurred in the RAbundVector class function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
83 /***********************************************************************/
85 RAbundVector::~RAbundVector() {
89 /***********************************************************************/
91 void RAbundVector::set(int binNumber, int newBinSize){
93 int oldBinSize = data[binNumber];
94 data[binNumber] = newBinSize;
96 if(oldBinSize == 0) { numBins++; }
97 if(newBinSize == 0) { numBins--; }
98 if(newBinSize > maxRank) { maxRank = newBinSize; }
100 numSeqs += (newBinSize - oldBinSize);
102 catch(exception& e) {
103 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
107 cout << "An unknown error has occurred in the RAbundVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
112 /***********************************************************************/
114 int RAbundVector::get(int index){
119 /***********************************************************************/
121 void RAbundVector::push_back(int binSize){
123 data.push_back(binSize);
126 if(binSize > maxRank){
132 catch(exception& e) {
133 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
137 cout << "An unknown error has occurred in the RAbundVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
142 /***********************************************************************/
144 void RAbundVector::pop_back(){
146 return data.pop_back();
149 /***********************************************************************/
151 void RAbundVector::resize(int size){
156 /***********************************************************************/
158 int RAbundVector::size(){
162 /***********************************************************************/
164 vector<int>::reverse_iterator RAbundVector::rbegin(){
165 return data.rbegin();
168 /***********************************************************************/
170 vector<int>::reverse_iterator RAbundVector::rend(){
174 /***********************************************************************/
175 void RAbundVector::print(string prefix, ostream& output){
177 output << prefix << '\t' << numBins << '\t';
179 vector<int> hold = data;
180 sort(hold.rbegin(), hold.rend());
182 for(int i=0;i<numBins;i++){ output << hold[i] << '\t'; }
185 catch(exception& e) {
186 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
190 cout << "An unknown error has occurred in the RAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
195 /***********************************************************************/
196 void RAbundVector::print(ostream& output){
198 output << label << '\t' << numBins << '\t';
200 vector<int> hold = data;
201 sort(hold.rbegin(), hold.rend());
203 for(int i=0;i<numBins;i++){ output << hold[i] << '\t'; }
206 catch(exception& e) {
207 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
211 cout << "An unknown error has occurred in the RAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
216 /***********************************************************************/
217 int RAbundVector::getNumBins(){
221 /***********************************************************************/
223 int RAbundVector::getNumSeqs(){
227 /***********************************************************************/
229 int RAbundVector::getMaxRank(){
233 /***********************************************************************/
235 RAbundVector RAbundVector::getRAbundVector(){
239 /***********************************************************************/
241 SAbundVector RAbundVector::getSAbundVector() {
243 SAbundVector sav(maxRank+1);
245 for(int i=0;i<data.size();i++){
247 sav.set(abund, sav.get(abund) + 1);
253 catch(exception& e) {
254 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
258 cout << "An unknown error has occurred in the RAbundVector class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
263 /***********************************************************************/
265 OrderVector RAbundVector::getOrderVector(map<string,int>* nameMap = NULL) {
269 for(int i=0;i<data.size();i++){
270 for(int j=0;j<data[i];j++){
274 random_shuffle(ov.begin(), ov.end());
279 catch(exception& e) {
280 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
284 cout << "An unknown error has occurred in the RAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
289 /***********************************************************************/