X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=rabundvector.cpp;fp=rabundvector.cpp;h=6cbaa0d896ad7d47105873c67cdc6d003329b83a;hb=0caf3fbabaa3ece404f8ce77f4c883dc5b1bf1dc;hp=0000000000000000000000000000000000000000;hpb=1b73ff67c83892a025e597dabd9df6fe7b58206a;p=mothur.git diff --git a/rabundvector.cpp b/rabundvector.cpp new file mode 100644 index 0000000..6cbaa0d --- /dev/null +++ b/rabundvector.cpp @@ -0,0 +1,318 @@ +/* + * rabundvector.cpp + * + * + * Created by Pat Schloss on 8/8/08. + * Copyright 2008 Patrick D. Schloss. All rights reserved. + * + */ + +#include "rabundvector.hpp" +#include "sabundvector.hpp" +#include "ordervector.hpp" +#include "calculator.h" + + +/***********************************************************************/ + +RAbundVector::RAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0) {} + +/***********************************************************************/ + +RAbundVector::RAbundVector(int n) : DataVector(), data(n,0) , maxRank(0), numBins(0), numSeqs(0) {} + +/***********************************************************************/ + +//RAbundVector::RAbundVector(const RAbundVector& rav) : DataVector(rav), data(rav.data), (rav.label), (rav.maxRank), (rav.numBins), (rav.numSeqs){} + + +/***********************************************************************/ + +RAbundVector::RAbundVector(string id, vector rav) : DataVector(id), data(rav) { + try { + numBins = 0; + maxRank = 0; + numSeqs = 0; + + for(int i=0;i maxRank) { maxRank = data[i]; } + numSeqs += data[i]; + } + } + catch(exception& e) { + m->errorOut(e, "RAbundVector", "RAbundVector"); + exit(1); + } +} + +/***********************************************************************/ + +RAbundVector::RAbundVector(vector rav, int mr, int nb, int ns) { + try { + numBins = nb; + maxRank = mr; + numSeqs = ns; + data = rav; + } + catch(exception& e) { + m->errorOut(e, "RAbundVector", "RAbundVector"); + exit(1); + } +} + +/***********************************************************************/ + + +RAbundVector::RAbundVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) { + try { + int hold; + f >> label >> hold; + + data.assign(hold, 0); + int inputData; + + for(int i=0;i> inputData; + set(i, inputData); + } + } + catch(exception& e) { + m->errorOut(e, "RAbundVector", "RAbundVector"); + exit(1); + } +} + +/***********************************************************************/ + +RAbundVector::~RAbundVector() { + +} + +/***********************************************************************/ + +void RAbundVector::set(int binNumber, int newBinSize){ + try { + int oldBinSize = data[binNumber]; + data[binNumber] = newBinSize; + + if(oldBinSize == 0) { numBins++; } + if(newBinSize == 0) { numBins--; } + if(newBinSize > maxRank) { maxRank = newBinSize; } + + numSeqs += (newBinSize - oldBinSize); + } + catch(exception& e) { + m->errorOut(e, "RAbundVector", "set"); + exit(1); + } +} + +/***********************************************************************/ + +int RAbundVector::get(int index){ + return data[index]; + +} +/***********************************************************************/ + +void RAbundVector::clear(){ + numBins = 0; + maxRank = 0; + numSeqs = 0; + data.clear(); + +} +/***********************************************************************/ + +void RAbundVector::push_back(int binSize){ + try { + data.push_back(binSize); + numBins++; + + if(binSize > maxRank){ + maxRank = binSize; + } + + numSeqs += binSize; + } + catch(exception& e) { + m->errorOut(e, "RAbundVector", "push_back"); + exit(1); + } +} + +/***********************************************************************/ + +void RAbundVector::pop_back(){ + + return data.pop_back(); +} + +/***********************************************************************/ + +void RAbundVector::resize(int size){ + + data.resize(size); +} + +/***********************************************************************/ + +int RAbundVector::size(){ + return data.size(); +} + +/***********************************************************************/ + +void RAbundVector::quicksort(){ + sort(data.rbegin(), data.rend()); +} + +/***********************************************************************/ + +int RAbundVector::sum(){ + VecCalc vecCalc; + return vecCalc.sumElements(data); +} + +/***********************************************************************/ + +int RAbundVector::sum(int index){ + VecCalc vecCalc; + return vecCalc.sumElements(data, index); +} + +/***********************************************************************/ + +int RAbundVector::numNZ(){ + VecCalc vecCalc; + return vecCalc.numNZ(data); +} + +/***********************************************************************/ + +vector::reverse_iterator RAbundVector::rbegin(){ + return data.rbegin(); +} + +/***********************************************************************/ + +vector::reverse_iterator RAbundVector::rend(){ + return data.rend(); +} + +/***********************************************************************/ +void RAbundVector::nonSortedPrint(ostream& output){ + try { + output << label << '\t' << numBins << '\t'; + + for(int i=0;ierrorOut(e, "RAbundVector", "nonSortedPrint"); + exit(1); + } +} +/***********************************************************************/ +void RAbundVector::print(string prefix, ostream& output){ + try { + output << prefix << '\t' << numBins << '\t'; + + vector hold = data; + sort(hold.rbegin(), hold.rend()); + + for(int i=0;ierrorOut(e, "RAbundVector", "print"); + exit(1); + } +} + + +/***********************************************************************/ +void RAbundVector::print(ostream& output){ + try { + output << label << '\t' << numBins << '\t'; + + vector hold = data; + sort(hold.rbegin(), hold.rend()); + + for(int i=0;ierrorOut(e, "RAbundVector", "print"); + exit(1); + } +} + +/***********************************************************************/ +int RAbundVector::getNumBins(){ + return numBins; +} + +/***********************************************************************/ + +int RAbundVector::getNumSeqs(){ + return numSeqs; +} + +/***********************************************************************/ + +int RAbundVector::getMaxRank(){ + return maxRank; +} + +/***********************************************************************/ + +RAbundVector RAbundVector::getRAbundVector(){ + return *this; +} + +/***********************************************************************/ + +SAbundVector RAbundVector::getSAbundVector() { + try { + SAbundVector sav(maxRank+1); + + for(int i=0;ierrorOut(e, "RAbundVector", "getSAbundVector"); + exit(1); + } +} + +/***********************************************************************/ + +OrderVector RAbundVector::getOrderVector(map* nameMap = NULL) { + try { + OrderVector ov; + + for(int i=0;ierrorOut(e, "RAbundVector", "getOrderVector"); + exit(1); + } +} + +/***********************************************************************/