5 * Created by Pat Schloss on 8/8/08.
6 * Copyright 2008 Patrick D. Schloss. All rights reserved.
11 #include "rabundvector.hpp"
12 #include "sabundvector.hpp"
13 #include "ordervector.hpp"
14 #include "calculator.h"
17 /***********************************************************************/
19 RAbundVector::RAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0) {};
21 /***********************************************************************/
23 RAbundVector::RAbundVector(int n) : DataVector(), data(n,0) , maxRank(0), numBins(0), numSeqs(0) {};
25 /***********************************************************************/
27 //RAbundVector::RAbundVector(const RAbundVector& rav) : DataVector(rav), data(rav.data), (rav.label), (rav.maxRank), (rav.numBins), (rav.numSeqs){};
30 /***********************************************************************/
32 RAbundVector::RAbundVector(string id, vector<int> rav) : DataVector(id), data(rav) {
38 for(int i=0;i<data.size();i++){
39 if(data[i] != 0) { numBins = i+1; }
40 if(data[i] > maxRank) { maxRank = data[i]; }
45 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
49 cout << "An unknown error has occurred in the RAbundVector class function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
54 /***********************************************************************/
56 RAbundVector::RAbundVector(vector<int> rav, int mr, int nb, int ns) {
64 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
68 cout << "An unknown error has occurred in the RAbundVector class function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
75 /***********************************************************************/
78 RAbundVector::RAbundVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) {
86 for(int i=0;i<hold;i++){
92 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
96 cout << "An unknown error has occurred in the RAbundVector class function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
101 /***********************************************************************/
103 RAbundVector::~RAbundVector() {
107 /***********************************************************************/
109 void RAbundVector::set(int binNumber, int newBinSize){
111 int oldBinSize = data[binNumber];
112 data[binNumber] = newBinSize;
114 if(oldBinSize == 0) { numBins++; }
115 if(newBinSize == 0) { numBins--; }
116 if(newBinSize > maxRank) { maxRank = newBinSize; }
118 numSeqs += (newBinSize - oldBinSize);
120 catch(exception& e) {
121 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
125 cout << "An unknown error has occurred in the RAbundVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
130 /***********************************************************************/
132 int RAbundVector::get(int index){
137 /***********************************************************************/
139 void RAbundVector::push_back(int binSize){
141 data.push_back(binSize);
144 if(binSize > maxRank){
150 catch(exception& e) {
151 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
155 cout << "An unknown error has occurred in the RAbundVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
160 /***********************************************************************/
162 void RAbundVector::pop_back(){
164 return data.pop_back();
167 /***********************************************************************/
169 void RAbundVector::resize(int size){
174 /***********************************************************************/
176 int RAbundVector::size(){
180 /***********************************************************************/
182 void RAbundVector::quicksort(){
183 sort(data.rbegin(), data.rend());
186 /***********************************************************************/
188 int RAbundVector::sum(){
190 return vecCalc.sumElements(data);
193 /***********************************************************************/
195 int RAbundVector::sum(int index){
197 return vecCalc.sumElements(data, index);
200 /***********************************************************************/
202 int RAbundVector::numNZ(){
204 return vecCalc.numNZ(data);
207 /***********************************************************************/
209 vector<int>::reverse_iterator RAbundVector::rbegin(){
210 return data.rbegin();
213 /***********************************************************************/
215 vector<int>::reverse_iterator RAbundVector::rend(){
219 /***********************************************************************/
220 void RAbundVector::print(string prefix, ostream& output){
222 output << prefix << '\t' << numBins << '\t';
224 vector<int> hold = data;
225 sort(hold.rbegin(), hold.rend());
227 for(int i=0;i<numBins;i++){ output << hold[i] << '\t'; }
230 catch(exception& e) {
231 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
235 cout << "An unknown error has occurred in the RAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
240 /***********************************************************************/
241 void RAbundVector::print(ostream& output){
243 output << label << '\t' << numBins << '\t';
245 vector<int> hold = data;
246 sort(hold.rbegin(), hold.rend());
248 for(int i=0;i<numBins;i++){ output << hold[i] << '\t'; }
251 catch(exception& e) {
252 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
256 cout << "An unknown error has occurred in the RAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
261 /***********************************************************************/
262 int RAbundVector::getNumBins(){
266 /***********************************************************************/
268 int RAbundVector::getNumSeqs(){
272 /***********************************************************************/
274 int RAbundVector::getMaxRank(){
278 /***********************************************************************/
280 RAbundVector RAbundVector::getRAbundVector(){
284 /***********************************************************************/
286 SAbundVector RAbundVector::getSAbundVector() {
288 SAbundVector sav(maxRank+1);
290 for(int i=0;i<data.size();i++){
292 sav.set(abund, sav.get(abund) + 1);
298 catch(exception& e) {
299 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
303 cout << "An unknown error has occurred in the RAbundVector class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
308 /***********************************************************************/
310 OrderVector RAbundVector::getOrderVector(map<string,int>* nameMap = NULL) {
314 for(int i=0;i<data.size();i++){
315 for(int j=0;j<data[i];j++){
319 random_shuffle(ov.begin(), ov.end());
324 catch(exception& e) {
325 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
329 cout << "An unknown error has occurred in the RAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
334 /***********************************************************************/