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 errorOut(e, "SAbundVector", "SAbundVector");
37 /***********************************************************************/
39 SAbundVector::SAbundVector(vector <int> dataVec, int mr, int nb, int ns) {
47 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++){
67 errorOut(e, "SAbundVector", "SAbundVector");
73 /***********************************************************************/
75 void SAbundVector::set(int sabund, int abundance){
78 int initSize = data[sabund];
79 data[sabund] = abundance;
82 numBins += (abundance - initSize);
85 numSeqs += sabund * (abundance - initSize);
87 if(sabund > maxRank) { maxRank = sabund; }
90 errorOut(e, "SAbundVector", "set");
96 /***********************************************************************/
98 int SAbundVector::get(int index){
102 /***********************************************************************/
104 void SAbundVector::push_back(int abundance){
106 data.push_back(abundance);
110 numBins += abundance;
112 numSeqs += (maxRank * abundance);
114 catch(exception& e) {
115 errorOut(e, "SAbundVector", "push_back");
119 /***********************************************************************/
121 void SAbundVector::quicksort(){
122 sort(data.rbegin(), data.rend());
125 /***********************************************************************/
127 int SAbundVector::sum(){
129 return vecCalc.sumElements(data);
132 /***********************************************************************/
134 void SAbundVector::resize(int size){
138 /***********************************************************************/
140 int SAbundVector::size(){
144 /***********************************************************************/
145 void SAbundVector::print(string prefix, ostream& output){
147 output << prefix << '\t' << maxRank << '\t';
149 for(int i=1;i<=maxRank;i++){
150 output << data[i] << '\t';
155 /***********************************************************************/
156 void SAbundVector::print(ostream& output){
158 output << label << '\t' << maxRank << '\t';
160 for(int i=1;i<=maxRank;i++){
161 output << data[i] << '\t';
165 catch(exception& e) {
166 errorOut(e, "SAbundVector", "print");
171 /**********************************************************************/
172 int SAbundVector::getNumBins(){
173 // if(needToUpdate == 1){ updateStats(); }
177 /***********************************************************************/
179 int SAbundVector::getNumSeqs(){
180 // if(needToUpdate == 1){ updateStats(); }
184 /***********************************************************************/
186 int SAbundVector::getMaxRank(){
187 // if(needToUpdate == 1){ updateStats(); }
190 /***********************************************************************/
191 RAbundVector SAbundVector::getRAbundVector(){
195 for(int i=1;i<=data.size();i++){
196 for(int j=0;j<data[i];j++){
200 sort(rav.rbegin(), rav.rend());
205 catch(exception& e) {
206 errorOut(e, "SAbundVector", "getRAbundVector");
211 /***********************************************************************/
213 SAbundVector SAbundVector::getSAbundVector(){
217 /***********************************************************************/
219 OrderVector SAbundVector::getOrderVector(map<string,int>* hold = NULL){
225 for(int i=1;i<data.size();i++){
226 for(int j=0;j<data[i];j++){
227 for(int k=0;k<i;k++){
228 ov.push_back(binIndex);
234 random_shuffle(ov.begin(), ov.end());
240 catch(exception& e) {
241 errorOut(e, "SAbundVector", "getOrderVector");
246 /***********************************************************************/