5 * Created by Pat Schloss on 8/8/08.
6 * Copyright 2008 Patrick D. Schloss. All rights reserved.
12 #include "ordervector.hpp"
13 #include "datavector.hpp"
14 #include "utilities.hpp"
17 /***********************************************************************/
19 OrderVector::OrderVector() : DataVector() {}
21 /***********************************************************************/
23 //OrderVector::OrderVector(int ns) : DataVector(), data(ns, -1) {};
25 /***********************************************************************/
27 OrderVector::OrderVector(string id, vector<int> ov) :
28 DataVector(id), data(ov)
33 /***********************************************************************/
35 OrderVector::OrderVector(ifstream& f) : DataVector() {
42 data.assign(hold, -1);
46 for(int i=0;i<hold;i++){
54 cout << "Standard Error: " << e.what() << " has occurred in the OrderVector class Function OrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
58 cout << "An unknown error has occurred in the OrderVector class function OrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
63 /***********************************************************************/
66 int OrderVector::getNumBins(){
67 if(needToUpdate == 1){ updateStats(); }
71 /***********************************************************************/
73 int OrderVector::getNumSeqs(){
74 if(needToUpdate == 1){ updateStats(); }
78 /***********************************************************************/
80 int OrderVector::getMaxRank(){
81 if(needToUpdate == 1){ updateStats(); }
85 /***********************************************************************/
89 void OrderVector::set(int index, int binNumber){
91 data[index] = binNumber;
96 /***********************************************************************/
98 int OrderVector::get(int index){
102 /***********************************************************************/
104 void OrderVector::push_back(int index){
106 data.push_back(index);
111 /***********************************************************************/
113 void OrderVector::print(ostream& output){
115 output << label << '\t' << numSeqs << '\t';
117 for(int i=0;i<data.size();i++){
118 output << data[i] << '\t';
122 catch(exception& e) {
123 cout << "Standard Error: " << e.what() << " has occurred in the OrderVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
127 cout << "An unknown error has occurred in the OrderVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
132 /***********************************************************************/
134 void OrderVector::print(string prefix, ostream& output){
136 output << prefix << '\t' << numSeqs << '\t';
138 for(int i=0;i<numSeqs;i++){
139 output << data[i] << '\t';
143 catch(exception& e) {
144 cout << "Standard Error: " << e.what() << " has occurred in the OrderVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
148 cout << "An unknown error has occurred in the OrderVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
153 /***********************************************************************/
155 void OrderVector::resize(int){
156 cout << "resize() did nothing in class OrderVector";
159 /***********************************************************************/
161 int OrderVector::size(){
165 /***********************************************************************/
167 vector<int>::iterator OrderVector::begin(){
171 /***********************************************************************/
173 vector<int>::iterator OrderVector::end(){
177 /***********************************************************************/
179 RAbundVector OrderVector::getRAbundVector(){
181 RAbundVector rav(data.size());
183 for(int i=0;i<numSeqs;i++){
184 rav.set(data[i], rav.get(data[i]) + 1);
186 sort(rav.rbegin(), rav.rend());
187 for(int i=numSeqs-1;i>=0;i--){
188 if(rav.get(i) == 0){ rav.pop_back(); }
197 catch(exception& e) {
198 cout << "Standard Error: " << e.what() << " has occurred in the OrderVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
202 cout << "An unknown error has occurred in the OrderVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
207 /***********************************************************************/
209 SAbundVector OrderVector::getSAbundVector(){
211 RAbundVector rav(this->getRAbundVector());
212 return rav.getSAbundVector();
216 /***********************************************************************/
218 OrderVector OrderVector::getOrderVector(map<string,int>* hold = 0){
222 /***********************************************************************/
224 void OrderVector::updateStats(){
227 // int maxBinVectorLength = 0;
232 for(int i=0;i<data.size();i++){
238 vector<int> hold(numSeqs);
240 for(int i=0;i<numSeqs;i++){
242 hold[data[i]] = hold[data[i]]+1;
245 for(int i=0;i<numSeqs;i++){
246 if(hold[i] > 0) { numBins++; }
247 if(hold[i] > maxRank) { maxRank = hold[i]; }
250 catch(exception& e) {
251 cout << "Standard Error: " << e.what() << " has occurred in the OrderVector class Function updateStats. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
255 cout << "An unknown error has occurred in the OrderVector class function updateStats. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
260 /***********************************************************************/