5 * Created by Pat Schloss on 8/8/08.
6 * Copyright 2008 Patrick D. Schloss. All rights reserved.
10 #include "ordervector.hpp"
13 /***********************************************************************/
15 OrderVector::OrderVector() : DataVector() {}
17 /***********************************************************************/
19 //OrderVector::OrderVector(int ns) : DataVector(), data(ns, -1) {}
21 /***********************************************************************/
23 OrderVector::OrderVector(string id, vector<int> ov) :
24 DataVector(id), data(ov)
29 /***********************************************************************/
31 OrderVector::OrderVector(ifstream& f) : DataVector() {
38 data.assign(hold, -1);
42 for(int i=0;i<hold;i++){
50 m->errorOut(e, "OrderVector", "OrderVector");
55 /***********************************************************************/
58 int OrderVector::getNumBins(){
59 if(needToUpdate == 1){ updateStats(); }
63 /***********************************************************************/
65 int OrderVector::getNumSeqs(){
66 if(needToUpdate == 1){ updateStats(); }
70 /***********************************************************************/
72 int OrderVector::getMaxRank(){
73 if(needToUpdate == 1){ updateStats(); }
76 /***********************************************************************/
78 void OrderVector::clear(){
84 /***********************************************************************/
88 void OrderVector::set(int index, int binNumber){
90 data[index] = binNumber;
95 /***********************************************************************/
97 int OrderVector::get(int index){
101 /***********************************************************************/
103 void OrderVector::push_back(int index){
105 data.push_back(index);
110 /***********************************************************************/
112 void OrderVector::print(ostream& output){
114 output << label << '\t' << numSeqs << '\t';
116 for(int i=0;i<data.size();i++){
117 output << data[i] << '\t';
121 catch(exception& e) {
122 m->errorOut(e, "OrderVector", "print");
127 /***********************************************************************/
129 void OrderVector::print(string prefix, ostream& output){
131 output << prefix << '\t' << numSeqs << '\t';
133 for(int i=0;i<numSeqs;i++){
134 output << data[i] << '\t';
138 catch(exception& e) {
139 m->errorOut(e, "OrderVector", "print");
144 /***********************************************************************/
146 void OrderVector::resize(int){
147 m->mothurOut("resize() did nothing in class OrderVector");
150 /***********************************************************************/
152 int OrderVector::size(){
156 /***********************************************************************/
158 vector<int>::iterator OrderVector::begin(){
162 /***********************************************************************/
164 vector<int>::iterator OrderVector::end(){
168 /***********************************************************************/
170 RAbundVector OrderVector::getRAbundVector(){
172 RAbundVector rav(data.size());
174 for(int i=0;i<numSeqs;i++){
175 rav.set(data[i], rav.get(data[i]) + 1);
177 sort(rav.rbegin(), rav.rend());
178 for(int i=numSeqs-1;i>=0;i--){
179 if(rav.get(i) == 0){ rav.pop_back(); }
188 catch(exception& e) {
189 m->errorOut(e, "OrderVector", "getRAbundVector");
194 /***********************************************************************/
196 SAbundVector OrderVector::getSAbundVector(){
198 RAbundVector rav(this->getRAbundVector());
199 return rav.getSAbundVector();
203 /***********************************************************************/
205 OrderVector OrderVector::getOrderVector(map<string,int>* hold = 0){
209 /***********************************************************************/
211 void OrderVector::updateStats(){
214 // int maxBinVectorLength = 0;
219 for(int i=0;i<data.size();i++){
225 vector<int> hold(numSeqs);
227 for(int i=0;i<numSeqs;i++){
229 hold[data[i]] = hold[data[i]]+1;
232 for(int i=0;i<numSeqs;i++){
233 if(hold[i] > 0) { numBins++; }
234 if(hold[i] > maxRank) { maxRank = hold[i]; }
237 catch(exception& e) {
238 m->errorOut(e, "OrderVector", "updateStats");
243 /***********************************************************************/