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++){
82 m->errorOut(e, "RAbundVector", "RAbundVector");
87 /***********************************************************************/
89 RAbundVector::~RAbundVector() {
93 /***********************************************************************/
95 void RAbundVector::set(int binNumber, int newBinSize){
97 int oldBinSize = data[binNumber];
98 data[binNumber] = newBinSize;
100 if(oldBinSize == 0) { numBins++; }
101 if(newBinSize == 0) { numBins--; }
102 if(newBinSize > maxRank) { maxRank = newBinSize; }
104 numSeqs += (newBinSize - oldBinSize);
106 catch(exception& e) {
107 m->errorOut(e, "RAbundVector", "set");
112 /***********************************************************************/
114 int RAbundVector::get(int index){
118 /***********************************************************************/
120 void RAbundVector::clear(){
127 /***********************************************************************/
129 void RAbundVector::push_back(int binSize){
131 data.push_back(binSize);
134 if(binSize > maxRank){
140 catch(exception& e) {
141 m->errorOut(e, "RAbundVector", "push_back");
146 /***********************************************************************/
148 void RAbundVector::pop_back(){
150 return data.pop_back();
153 /***********************************************************************/
155 void RAbundVector::resize(int size){
160 /***********************************************************************/
162 int RAbundVector::size(){
166 /***********************************************************************/
168 void RAbundVector::quicksort(){
169 sort(data.rbegin(), data.rend());
172 /***********************************************************************/
174 int RAbundVector::sum(){
176 return vecCalc.sumElements(data);
179 /***********************************************************************/
181 int RAbundVector::sum(int index){
183 return vecCalc.sumElements(data, index);
186 /***********************************************************************/
188 int RAbundVector::numNZ(){
190 return vecCalc.numNZ(data);
193 /***********************************************************************/
195 vector<int>::reverse_iterator RAbundVector::rbegin(){
196 return data.rbegin();
199 /***********************************************************************/
201 vector<int>::reverse_iterator RAbundVector::rend(){
205 /***********************************************************************/
206 void RAbundVector::nonSortedPrint(ostream& output){
208 output << label << '\t' << numBins << '\t';
210 for(int i=0;i<numBins;i++){ output << data[i] << '\t'; }
213 catch(exception& e) {
214 m->errorOut(e, "RAbundVector", "nonSortedPrint");
218 /***********************************************************************/
219 void RAbundVector::print(string prefix, ostream& output){
221 output << prefix << '\t' << numBins << '\t';
223 vector<int> hold = data;
224 sort(hold.rbegin(), hold.rend());
226 for(int i=0;i<numBins;i++){ output << hold[i] << '\t'; }
229 catch(exception& e) {
230 m->errorOut(e, "RAbundVector", "print");
236 /***********************************************************************/
237 void RAbundVector::print(ostream& output){
239 output << label << '\t' << numBins << '\t';
241 vector<int> hold = data;
242 sort(hold.rbegin(), hold.rend());
244 for(int i=0;i<numBins;i++){ output << hold[i] << '\t'; }
247 catch(exception& e) {
248 m->errorOut(e, "RAbundVector", "print");
253 /***********************************************************************/
254 int RAbundVector::getNumBins(){
258 /***********************************************************************/
260 int RAbundVector::getNumSeqs(){
264 /***********************************************************************/
266 int RAbundVector::getMaxRank(){
270 /***********************************************************************/
272 RAbundVector RAbundVector::getRAbundVector(){
276 /***********************************************************************/
278 SAbundVector RAbundVector::getSAbundVector() {
280 SAbundVector sav(maxRank+1);
282 for(int i=0;i<data.size();i++){
284 sav.set(abund, sav.get(abund) + 1);
290 catch(exception& e) {
291 m->errorOut(e, "RAbundVector", "getSAbundVector");
296 /***********************************************************************/
298 OrderVector RAbundVector::getOrderVector(map<string,int>* nameMap = NULL) {
302 for(int i=0;i<data.size();i++){
303 for(int j=0;j<data[i];j++){
307 random_shuffle(ov.begin(), ov.end());
313 catch(exception& e) {
314 m->errorOut(e, "RAbundVector", "getOrderVector");
319 /***********************************************************************/