5 * Created by Pat Schloss on 8/8/08.
6 * Copyright 2008 Patrick D. Schloss. All rights reserved.
10 #include "rabundvector.hpp"
11 #include "sabundvector.hpp"
12 #include "ordervector.hpp"
13 #include "calculator.h"
16 /***********************************************************************/
18 RAbundVector::RAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0) {}
20 /***********************************************************************/
22 RAbundVector::RAbundVector(int n) : DataVector(), data(n,0) , maxRank(0), numBins(0), numSeqs(0) {}
24 /***********************************************************************/
26 //RAbundVector::RAbundVector(const RAbundVector& rav) : DataVector(rav), data(rav.data), (rav.label), (rav.maxRank), (rav.numBins), (rav.numSeqs){}
29 /***********************************************************************/
31 RAbundVector::RAbundVector(string id, vector<int> rav) : DataVector(id), data(rav) {
37 for(int i=0;i<data.size();i++){
38 if(data[i] != 0) { numBins = i+1; }
39 if(data[i] > maxRank) { maxRank = data[i]; }
44 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
48 cout << "An unknown error has occurred in the RAbundVector class function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
53 /***********************************************************************/
55 RAbundVector::RAbundVector(vector<int> rav, int mr, int nb, int ns) {
63 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
67 cout << "An unknown error has occurred in the RAbundVector class function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
74 /***********************************************************************/
77 RAbundVector::RAbundVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) {
85 for(int i=0;i<hold;i++){
91 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
95 cout << "An unknown error has occurred in the RAbundVector class function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
100 /***********************************************************************/
102 RAbundVector::~RAbundVector() {
106 /***********************************************************************/
108 void RAbundVector::set(int binNumber, int newBinSize){
110 int oldBinSize = data[binNumber];
111 data[binNumber] = newBinSize;
113 if(oldBinSize == 0) { numBins++; }
114 if(newBinSize == 0) { numBins--; }
115 if(newBinSize > maxRank) { maxRank = newBinSize; }
117 numSeqs += (newBinSize - oldBinSize);
119 catch(exception& e) {
120 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
124 cout << "An unknown error has occurred in the RAbundVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
129 /***********************************************************************/
131 int RAbundVector::get(int index){
136 /***********************************************************************/
138 void RAbundVector::push_back(int binSize){
140 data.push_back(binSize);
143 if(binSize > maxRank){
149 catch(exception& e) {
150 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
154 cout << "An unknown error has occurred in the RAbundVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
159 /***********************************************************************/
161 void RAbundVector::pop_back(){
163 return data.pop_back();
166 /***********************************************************************/
168 void RAbundVector::resize(int size){
173 /***********************************************************************/
175 int RAbundVector::size(){
179 /***********************************************************************/
181 void RAbundVector::quicksort(){
182 sort(data.rbegin(), data.rend());
185 /***********************************************************************/
187 int RAbundVector::sum(){
189 return vecCalc.sumElements(data);
192 /***********************************************************************/
194 int RAbundVector::sum(int index){
196 return vecCalc.sumElements(data, index);
199 /***********************************************************************/
201 int RAbundVector::numNZ(){
203 return vecCalc.numNZ(data);
206 /***********************************************************************/
208 vector<int>::reverse_iterator RAbundVector::rbegin(){
209 return data.rbegin();
212 /***********************************************************************/
214 vector<int>::reverse_iterator RAbundVector::rend(){
218 /***********************************************************************/
219 void RAbundVector::print(string prefix, ostream& output){
221 output << prefix << '\t' << numBins << '\t';
223 vector<int> hold = data;
224 sort(hold.rbegin(), hold.rend());
226 for(int i=0;i<numBins;i++){ output << hold[i] << '\t'; }
229 catch(exception& e) {
230 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
234 cout << "An unknown error has occurred in the RAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
239 /***********************************************************************/
240 void RAbundVector::print(ostream& output){
242 output << label << '\t' << numBins << '\t';
244 vector<int> hold = data;
245 sort(hold.rbegin(), hold.rend());
247 for(int i=0;i<numBins;i++){ output << hold[i] << '\t'; }
250 catch(exception& e) {
251 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
255 cout << "An unknown error has occurred in the RAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
260 /***********************************************************************/
261 int RAbundVector::getNumBins(){
265 /***********************************************************************/
267 int RAbundVector::getNumSeqs(){
271 /***********************************************************************/
273 int RAbundVector::getMaxRank(){
277 /***********************************************************************/
279 RAbundVector RAbundVector::getRAbundVector(){
283 /***********************************************************************/
285 SAbundVector RAbundVector::getSAbundVector() {
287 SAbundVector sav(maxRank+1);
289 for(int i=0;i<data.size();i++){
291 sav.set(abund, sav.get(abund) + 1);
297 catch(exception& e) {
298 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
302 cout << "An unknown error has occurred in the RAbundVector class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
307 /***********************************************************************/
309 OrderVector RAbundVector::getOrderVector(map<string,int>* nameMap = NULL) {
313 for(int i=0;i<data.size();i++){
314 for(int j=0;j<data[i];j++){
318 random_shuffle(ov.begin(), ov.end());
323 catch(exception& e) {
324 cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
328 cout << "An unknown error has occurred in the RAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
333 /***********************************************************************/