5 * Created by Pat Schloss on 8/8/08.
6 * Copyright 2008 Patrick D. Schloss. All rights reserved.
12 #include "utilities.hpp"
13 #include "rabundvector.hpp"
14 #include "sabundvector.hpp"
15 #include "ordervector.hpp"
16 #include "calculator.h"
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";
56 /***********************************************************************/
58 RAbundVector::RAbundVector(vector<int> rav, int mr, int nb, int ns) {
66 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
70 cout << "An unknown error has occurred in the RAbundVector class function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
77 /***********************************************************************/
80 RAbundVector::RAbundVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) {
88 for(int i=0;i<hold;i++){
94 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
98 cout << "An unknown error has occurred in the RAbundVector class function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
103 /***********************************************************************/
105 RAbundVector::~RAbundVector() {
109 /***********************************************************************/
111 void RAbundVector::set(int binNumber, int newBinSize){
113 int oldBinSize = data[binNumber];
114 data[binNumber] = newBinSize;
116 if(oldBinSize == 0) { numBins++; }
117 if(newBinSize == 0) { numBins--; }
118 if(newBinSize > maxRank) { maxRank = newBinSize; }
120 numSeqs += (newBinSize - oldBinSize);
122 catch(exception& e) {
123 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
127 cout << "An unknown error has occurred in the RAbundVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
132 /***********************************************************************/
134 int RAbundVector::get(int index){
139 /***********************************************************************/
141 void RAbundVector::push_back(int binSize){
143 data.push_back(binSize);
146 if(binSize > maxRank){
152 catch(exception& e) {
153 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
157 cout << "An unknown error has occurred in the RAbundVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
162 /***********************************************************************/
164 void RAbundVector::pop_back(){
166 return data.pop_back();
169 /***********************************************************************/
171 void RAbundVector::resize(int size){
176 /***********************************************************************/
178 int RAbundVector::size(){
182 /***********************************************************************/
184 void RAbundVector::quicksort(){
185 sort(data.rbegin(), data.rend());
188 /***********************************************************************/
190 int RAbundVector::sum(){
192 return vecCalc.sumElements(data);
195 /***********************************************************************/
197 int RAbundVector::sum(int index){
199 return vecCalc.sumElements(data, index);
202 /***********************************************************************/
204 int RAbundVector::numNZ(){
206 return vecCalc.numNZ(data);
209 /***********************************************************************/
211 vector<int>::reverse_iterator RAbundVector::rbegin(){
212 return data.rbegin();
215 /***********************************************************************/
217 vector<int>::reverse_iterator RAbundVector::rend(){
221 /***********************************************************************/
222 void RAbundVector::print(string prefix, ostream& output){
224 output << prefix << '\t' << numBins << '\t';
226 vector<int> hold = data;
227 sort(hold.rbegin(), hold.rend());
229 for(int i=0;i<numBins;i++){ output << hold[i] << '\t'; }
232 catch(exception& e) {
233 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
237 cout << "An unknown error has occurred in the RAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
242 /***********************************************************************/
243 void RAbundVector::print(ostream& output){
245 output << label << '\t' << numBins << '\t';
247 vector<int> hold = data;
248 sort(hold.rbegin(), hold.rend());
250 for(int i=0;i<numBins;i++){ output << hold[i] << '\t'; }
253 catch(exception& e) {
254 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
258 cout << "An unknown error has occurred in the RAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
263 /***********************************************************************/
264 int RAbundVector::getNumBins(){
268 /***********************************************************************/
270 int RAbundVector::getNumSeqs(){
274 /***********************************************************************/
276 int RAbundVector::getMaxRank(){
280 /***********************************************************************/
282 RAbundVector RAbundVector::getRAbundVector(){
286 /***********************************************************************/
288 SAbundVector RAbundVector::getSAbundVector() {
290 SAbundVector sav(maxRank+1);
292 for(int i=0;i<data.size();i++){
294 sav.set(abund, sav.get(abund) + 1);
300 catch(exception& e) {
301 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
305 cout << "An unknown error has occurred in the RAbundVector class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
310 /***********************************************************************/
312 OrderVector RAbundVector::getOrderVector(map<string,int>* nameMap = NULL) {
316 for(int i=0;i<data.size();i++){
317 for(int j=0;j<data[i];j++){
321 random_shuffle(ov.begin(), ov.end());
326 catch(exception& e) {
327 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
331 cout << "An unknown error has occurred in the RAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
336 /***********************************************************************/