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"
18 /***********************************************************************/
20 RAbundVector::RAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0) {};
22 /***********************************************************************/
24 RAbundVector::RAbundVector(int n) : DataVector(), data(n,0) , maxRank(0), numBins(0), numSeqs(0) {};
26 /***********************************************************************/
28 //RAbundVector::RAbundVector(const RAbundVector& rav) : DataVector(rav), data(rav.data), (rav.label), (rav.maxRank), (rav.numBins), (rav.numSeqs){};
31 /***********************************************************************/
33 RAbundVector::RAbundVector(string id, vector<int> rav) : DataVector(id), data(rav) {
39 for(int i=0;i<data.size();i++){
40 if(data[i] != 0) { numBins = i+1; }
41 if(data[i] > maxRank) { maxRank = data[i]; }
46 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
50 cout << "An unknown error has occurred in the RAbundVector class function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
56 /***********************************************************************/
59 RAbundVector::RAbundVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) {
67 for(int i=0;i<hold;i++){
73 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
77 cout << "An unknown error has occurred in the RAbundVector class function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
82 /***********************************************************************/
84 RAbundVector::~RAbundVector() {
88 /***********************************************************************/
90 void RAbundVector::set(int binNumber, int newBinSize){
92 int oldBinSize = data[binNumber];
93 data[binNumber] = newBinSize;
95 if(oldBinSize == 0) { numBins++; }
96 if(newBinSize == 0) { numBins--; }
97 if(newBinSize > maxRank) { maxRank = newBinSize; }
99 numSeqs += (newBinSize - oldBinSize);
101 catch(exception& e) {
102 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
106 cout << "An unknown error has occurred in the RAbundVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
111 /***********************************************************************/
113 int RAbundVector::get(int index){
118 /***********************************************************************/
120 void RAbundVector::push_back(int binSize){
122 data.push_back(binSize);
125 if(binSize > maxRank){
131 catch(exception& e) {
132 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
136 cout << "An unknown error has occurred in the RAbundVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
141 /***********************************************************************/
143 void RAbundVector::pop_back(){
145 return data.pop_back();
148 /***********************************************************************/
150 void RAbundVector::resize(int size){
155 /***********************************************************************/
157 int RAbundVector::size(){
161 /***********************************************************************/
163 vector<int>::reverse_iterator RAbundVector::rbegin(){
164 return data.rbegin();
167 /***********************************************************************/
169 vector<int>::reverse_iterator RAbundVector::rend(){
173 /***********************************************************************/
174 void RAbundVector::print(string prefix, ostream& output){
176 output << prefix << '\t' << numBins << '\t';
178 vector<int> hold = data;
179 sort(hold.rbegin(), hold.rend());
181 for(int i=0;i<numBins;i++){ output << hold[i] << '\t'; }
184 catch(exception& e) {
185 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
189 cout << "An unknown error has occurred in the RAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
194 /***********************************************************************/
195 void RAbundVector::print(ostream& output){
197 output << label << '\t' << numBins << '\t';
199 vector<int> hold = data;
200 sort(hold.rbegin(), hold.rend());
202 for(int i=0;i<numBins;i++){ output << hold[i] << '\t'; }
205 catch(exception& e) {
206 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
210 cout << "An unknown error has occurred in the RAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
215 /***********************************************************************/
216 int RAbundVector::getNumBins(){
220 /***********************************************************************/
222 int RAbundVector::getNumSeqs(){
226 /***********************************************************************/
228 int RAbundVector::getMaxRank(){
232 /***********************************************************************/
234 RAbundVector RAbundVector::getRAbundVector(){
238 /***********************************************************************/
240 SAbundVector RAbundVector::getSAbundVector() {
242 SAbundVector sav(maxRank+1);
244 for(int i=0;i<data.size();i++){
246 sav.set(abund, sav.get(abund) + 1);
252 catch(exception& e) {
253 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
257 cout << "An unknown error has occurred in the RAbundVector class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
262 /***********************************************************************/
264 OrderVector RAbundVector::getOrderVector(map<string,int>* nameMap = NULL) {
268 for(int i=0;i<data.size();i++){
269 for(int j=0;j<data[i];j++){
273 random_shuffle(ov.begin(), ov.end());
278 catch(exception& e) {
279 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
283 cout << "An unknown error has occurred in the RAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
288 /***********************************************************************/