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 errorOut(e, "RAbundVector", "RAbundVector");
49 /***********************************************************************/
51 RAbundVector::RAbundVector(vector<int> rav, int mr, int nb, int ns) {
59 errorOut(e, "RAbundVector", "RAbundVector");
64 /***********************************************************************/
67 RAbundVector::RAbundVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) {
75 for(int i=0;i<hold;i++){
81 errorOut(e, "RAbundVector", "RAbundVector");
86 /***********************************************************************/
88 RAbundVector::~RAbundVector() {
92 /***********************************************************************/
94 void RAbundVector::set(int binNumber, int newBinSize){
96 int oldBinSize = data[binNumber];
97 data[binNumber] = newBinSize;
99 if(oldBinSize == 0) { numBins++; }
100 if(newBinSize == 0) { numBins--; }
101 if(newBinSize > maxRank) { maxRank = newBinSize; }
103 numSeqs += (newBinSize - oldBinSize);
105 catch(exception& e) {
106 errorOut(e, "RAbundVector", "set");
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 errorOut(e, "RAbundVector", "push_back");
137 /***********************************************************************/
139 void RAbundVector::pop_back(){
141 return data.pop_back();
144 /***********************************************************************/
146 void RAbundVector::resize(int size){
151 /***********************************************************************/
153 int RAbundVector::size(){
157 /***********************************************************************/
159 void RAbundVector::quicksort(){
160 sort(data.rbegin(), data.rend());
163 /***********************************************************************/
165 int RAbundVector::sum(){
167 return vecCalc.sumElements(data);
170 /***********************************************************************/
172 int RAbundVector::sum(int index){
174 return vecCalc.sumElements(data, index);
177 /***********************************************************************/
179 int RAbundVector::numNZ(){
181 return vecCalc.numNZ(data);
184 /***********************************************************************/
186 vector<int>::reverse_iterator RAbundVector::rbegin(){
187 return data.rbegin();
190 /***********************************************************************/
192 vector<int>::reverse_iterator RAbundVector::rend(){
196 /***********************************************************************/
197 void RAbundVector::nonSortedPrint(ostream& output){
199 output << label << '\t' << numBins << '\t';
201 for(int i=0;i<numBins;i++){ output << data[i] << '\t'; }
204 catch(exception& e) {
205 errorOut(e, "RAbundVector", "nonSortedPrint");
209 /***********************************************************************/
210 void RAbundVector::print(string prefix, ostream& output){
212 output << prefix << '\t' << numBins << '\t';
214 vector<int> hold = data;
215 sort(hold.rbegin(), hold.rend());
217 for(int i=0;i<numBins;i++){ output << hold[i] << '\t'; }
220 catch(exception& e) {
221 errorOut(e, "RAbundVector", "print");
227 /***********************************************************************/
228 void RAbundVector::print(ostream& output){
230 output << label << '\t' << numBins << '\t';
232 vector<int> hold = data;
233 sort(hold.rbegin(), hold.rend());
235 for(int i=0;i<numBins;i++){ output << hold[i] << '\t'; }
238 catch(exception& e) {
239 errorOut(e, "RAbundVector", "print");
244 /***********************************************************************/
245 int RAbundVector::getNumBins(){
249 /***********************************************************************/
251 int RAbundVector::getNumSeqs(){
255 /***********************************************************************/
257 int RAbundVector::getMaxRank(){
261 /***********************************************************************/
263 RAbundVector RAbundVector::getRAbundVector(){
267 /***********************************************************************/
269 SAbundVector RAbundVector::getSAbundVector() {
271 SAbundVector sav(maxRank+1);
273 for(int i=0;i<data.size();i++){
275 sav.set(abund, sav.get(abund) + 1);
281 catch(exception& e) {
282 errorOut(e, "RAbundVector", "getSAbundVector");
287 /***********************************************************************/
289 OrderVector RAbundVector::getOrderVector(map<string,int>* nameMap = NULL) {
293 for(int i=0;i<data.size();i++){
294 for(int j=0;j<data[i];j++){
298 random_shuffle(ov.begin(), ov.end());
303 catch(exception& e) {
304 errorOut(e, "RAbundVector", "getOrderVector");
309 /***********************************************************************/