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 m->errorOut(e, "RAbundVector", "RAbundVector");
49 /***********************************************************************/
51 RAbundVector::RAbundVector(vector<int> rav, int mr, int nb, int ns) {
59 m->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 m->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 m->errorOut(e, "RAbundVector", "set");
111 /***********************************************************************/
113 int RAbundVector::get(int index){
117 /***********************************************************************/
119 void RAbundVector::clear(){
126 /***********************************************************************/
128 void RAbundVector::push_back(int binSize){
130 data.push_back(binSize);
133 if(binSize > maxRank){
139 catch(exception& e) {
140 m->errorOut(e, "RAbundVector", "push_back");
145 /***********************************************************************/
147 void RAbundVector::pop_back(){
149 return data.pop_back();
152 /***********************************************************************/
154 void RAbundVector::resize(int size){
159 /***********************************************************************/
161 int RAbundVector::size(){
165 /***********************************************************************/
167 void RAbundVector::quicksort(){
168 sort(data.rbegin(), data.rend());
171 /***********************************************************************/
173 int RAbundVector::sum(){
175 return vecCalc.sumElements(data);
178 /***********************************************************************/
180 int RAbundVector::sum(int index){
182 return vecCalc.sumElements(data, index);
185 /***********************************************************************/
187 int RAbundVector::numNZ(){
189 return vecCalc.numNZ(data);
192 /***********************************************************************/
194 vector<int>::reverse_iterator RAbundVector::rbegin(){
195 return data.rbegin();
198 /***********************************************************************/
200 vector<int>::reverse_iterator RAbundVector::rend(){
204 /***********************************************************************/
205 void RAbundVector::nonSortedPrint(ostream& output){
207 output << label << '\t' << numBins << '\t';
209 for(int i=0;i<numBins;i++){ output << data[i] << '\t'; }
212 catch(exception& e) {
213 m->errorOut(e, "RAbundVector", "nonSortedPrint");
217 /***********************************************************************/
218 void RAbundVector::print(string prefix, ostream& output){
220 output << prefix << '\t' << numBins << '\t';
222 vector<int> hold = data;
223 sort(hold.rbegin(), hold.rend());
225 for(int i=0;i<numBins;i++){ output << hold[i] << '\t'; }
228 catch(exception& e) {
229 m->errorOut(e, "RAbundVector", "print");
235 /***********************************************************************/
236 void RAbundVector::print(ostream& output){
238 output << label << '\t' << numBins << '\t';
240 vector<int> hold = data;
241 sort(hold.rbegin(), hold.rend());
243 for(int i=0;i<numBins;i++){ output << hold[i] << '\t'; }
246 catch(exception& e) {
247 m->errorOut(e, "RAbundVector", "print");
252 /***********************************************************************/
253 int RAbundVector::getNumBins(){
257 /***********************************************************************/
259 int RAbundVector::getNumSeqs(){
263 /***********************************************************************/
265 int RAbundVector::getMaxRank(){
269 /***********************************************************************/
271 RAbundVector RAbundVector::getRAbundVector(){
275 /***********************************************************************/
277 SAbundVector RAbundVector::getSAbundVector() {
279 SAbundVector sav(maxRank+1);
281 for(int i=0;i<data.size();i++){
283 sav.set(abund, sav.get(abund) + 1);
289 catch(exception& e) {
290 m->errorOut(e, "RAbundVector", "getSAbundVector");
295 /***********************************************************************/
297 OrderVector RAbundVector::getOrderVector(map<string,int>* nameMap = NULL) {
301 for(int i=0;i<data.size();i++){
302 for(int j=0;j<data[i];j++){
306 random_shuffle(ov.begin(), ov.end());
312 catch(exception& e) {
313 m->errorOut(e, "RAbundVector", "getOrderVector");
318 /***********************************************************************/