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++){
68 m->errorOut(e, "SAbundVector", "SAbundVector");
74 /***********************************************************************/
76 void SAbundVector::set(int sabund, int abundance){
79 int initSize = data[sabund];
80 data[sabund] = abundance;
83 numBins += (abundance - initSize);
86 numSeqs += sabund * (abundance - initSize);
88 if(sabund > maxRank) { maxRank = sabund; }
91 m->errorOut(e, "SAbundVector", "set");
97 /***********************************************************************/
99 int SAbundVector::get(int index){
103 /***********************************************************************/
105 void SAbundVector::push_back(int abundance){
107 data.push_back(abundance);
111 numBins += abundance;
113 numSeqs += (maxRank * abundance);
115 catch(exception& e) {
116 m->errorOut(e, "SAbundVector", "push_back");
120 /***********************************************************************/
122 void SAbundVector::quicksort(){
123 sort(data.rbegin(), data.rend());
126 /***********************************************************************/
128 int SAbundVector::sum(){
130 return vecCalc.sumElements(data);
133 /***********************************************************************/
135 void SAbundVector::resize(int size){
139 /***********************************************************************/
141 int SAbundVector::size(){
145 /***********************************************************************/
146 void SAbundVector::print(string prefix, ostream& output){
148 output << prefix << '\t' << maxRank << '\t';
150 for(int i=1;i<=maxRank;i++){
151 output << data[i] << '\t';
155 /***********************************************************************/
156 void SAbundVector::clear(){
162 /***********************************************************************/
163 void SAbundVector::print(ostream& output){
165 output << label << '\t' << maxRank << '\t';
167 for(int i=1;i<=maxRank;i++){
168 output << data[i] << '\t';
172 catch(exception& e) {
173 m->errorOut(e, "SAbundVector", "print");
178 /**********************************************************************/
179 int SAbundVector::getNumBins(){
180 // if(needToUpdate == 1){ updateStats(); }
184 /***********************************************************************/
186 int SAbundVector::getNumSeqs(){
187 // if(needToUpdate == 1){ updateStats(); }
191 /***********************************************************************/
193 int SAbundVector::getMaxRank(){
194 // if(needToUpdate == 1){ updateStats(); }
197 /***********************************************************************/
198 RAbundVector SAbundVector::getRAbundVector(){
202 for(int i=1;i < data.size();i++){
203 for(int j=0;j<data[i];j++){
207 sort(rav.rbegin(), rav.rend());
212 catch(exception& e) {
213 m->errorOut(e, "SAbundVector", "getRAbundVector");
218 /***********************************************************************/
220 SAbundVector SAbundVector::getSAbundVector(){
224 /***********************************************************************/
226 OrderVector SAbundVector::getOrderVector(map<string,int>* hold = NULL){
232 for(int i=1;i<data.size();i++){
233 for(int j=0;j<data[i];j++){
234 for(int k=0;k<i;k++){
235 ov.push_back(binIndex);
241 random_shuffle(ov.begin(), ov.end());
247 catch(exception& e) {
248 m->errorOut(e, "SAbundVector", "getOrderVector");
253 /***********************************************************************/