5 * Created by Pat Schloss on 8/8/08.
6 * Copyright 2008 Patrick D. Schloss. All rights resesaved.
10 #include "sabundvector.hpp"
11 #include "calculator.h"
13 /***********************************************************************/
15 SAbundVector::SAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){}
17 /***********************************************************************/
19 SAbundVector::SAbundVector(int size) : DataVector(), data(size, 0), maxRank(0), numBins(0), numSeqs(0) {}
21 /***********************************************************************/
23 SAbundVector::SAbundVector(string id, vector<int> sav) : DataVector(id), data(sav) {
25 for(int i=0;i<sav.size();i++){
26 if(data[i] != 0){ maxRank = i; }
32 m->errorOut(e, "SAbundVector", "SAbundVector");
37 /***********************************************************************/
39 SAbundVector::SAbundVector(vector <int> dataVec, int mr, int nb, int ns) {
47 m->errorOut(e, "SAbundVector", "SAbundVector");
51 /***********************************************************************/
53 SAbundVector::SAbundVector(ifstream& f): DataVector(), maxRank(0), numBins(0), numSeqs(0) {
58 data.assign(hold+1, 0);
61 for(int i=1;i<=hold;i++){
69 m->errorOut(e, "SAbundVector", "SAbundVector");
75 /***********************************************************************/
77 void SAbundVector::set(int sabund, int abundance){
80 int initSize = data[sabund];
81 data[sabund] = abundance;
84 numBins += (abundance - initSize);
87 numSeqs += sabund * (abundance - initSize);
89 if(sabund > maxRank) { maxRank = sabund; }
92 m->errorOut(e, "SAbundVector", "set");
98 /***********************************************************************/
100 int SAbundVector::get(int index){
104 /***********************************************************************/
106 void SAbundVector::push_back(int abundance){
108 data.push_back(abundance);
112 numBins += abundance;
114 numSeqs += (maxRank * abundance);
116 catch(exception& e) {
117 m->errorOut(e, "SAbundVector", "push_back");
121 /***********************************************************************/
123 void SAbundVector::quicksort(){
124 sort(data.rbegin(), data.rend());
127 /***********************************************************************/
129 int SAbundVector::sum(){
131 return vecCalc.sumElements(data);
134 /***********************************************************************/
136 void SAbundVector::resize(int size){
140 /***********************************************************************/
142 int SAbundVector::size(){
146 /***********************************************************************/
147 void SAbundVector::print(string prefix, ostream& output){
149 output << prefix << '\t' << maxRank << '\t';
151 for(int i=1;i<=maxRank;i++){
152 output << data[i] << '\t';
156 /***********************************************************************/
157 void SAbundVector::clear(){
163 /***********************************************************************/
164 void SAbundVector::print(ostream& output){
166 output << label << '\t' << maxRank << '\t';
168 for(int i=1;i<=maxRank;i++){
169 output << data[i] << '\t';
173 catch(exception& e) {
174 m->errorOut(e, "SAbundVector", "print");
179 /**********************************************************************/
180 int SAbundVector::getNumBins(){
181 // if(needToUpdate == 1){ updateStats(); }
185 /***********************************************************************/
187 int SAbundVector::getNumSeqs(){
188 // if(needToUpdate == 1){ updateStats(); }
192 /***********************************************************************/
194 int SAbundVector::getMaxRank(){
195 // if(needToUpdate == 1){ updateStats(); }
198 /***********************************************************************/
199 RAbundVector SAbundVector::getRAbundVector(){
203 for(int i=1;i < data.size();i++){
204 for(int j=0;j<data[i];j++){
208 sort(rav.rbegin(), rav.rend());
213 catch(exception& e) {
214 m->errorOut(e, "SAbundVector", "getRAbundVector");
219 /***********************************************************************/
221 SAbundVector SAbundVector::getSAbundVector(){
225 /***********************************************************************/
227 OrderVector SAbundVector::getOrderVector(map<string,int>* hold = NULL){
233 for(int i=1;i<data.size();i++){
234 for(int j=0;j<data[i];j++){
235 for(int k=0;k<i;k++){
236 ov.push_back(binIndex);
242 random_shuffle(ov.begin(), ov.end());
248 catch(exception& e) {
249 m->errorOut(e, "SAbundVector", "getOrderVector");
254 /***********************************************************************/