5 * Created by Pat Schloss on 8/8/08.
6 * Copyright 2008 Patrick D. Schloss. All rights reserved.
12 #include "ordervector.hpp"
15 /***********************************************************************/
17 OrderVector::OrderVector() : DataVector() {}
19 /***********************************************************************/
21 //OrderVector::OrderVector(int ns) : DataVector(), data(ns, -1) {};
23 /***********************************************************************/
25 OrderVector::OrderVector(string id, vector<int> ov) :
26 DataVector(id), data(ov)
31 /***********************************************************************/
33 OrderVector::OrderVector(ifstream& f) : DataVector() {
40 data.assign(hold, -1);
44 for(int i=0;i<hold;i++){
52 cout << "Standard Error: " << e.what() << " has occurred in the OrderVector class Function OrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
56 cout << "An unknown error has occurred in the OrderVector class function OrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
61 /***********************************************************************/
64 int OrderVector::getNumBins(){
65 if(needToUpdate == 1){ updateStats(); }
69 /***********************************************************************/
71 int OrderVector::getNumSeqs(){
72 if(needToUpdate == 1){ updateStats(); }
76 /***********************************************************************/
78 int OrderVector::getMaxRank(){
79 if(needToUpdate == 1){ updateStats(); }
83 /***********************************************************************/
87 void OrderVector::set(int index, int binNumber){
89 data[index] = binNumber;
94 /***********************************************************************/
96 int OrderVector::get(int index){
100 /***********************************************************************/
102 void OrderVector::push_back(int index){
104 data.push_back(index);
109 /***********************************************************************/
111 void OrderVector::print(ostream& output){
113 output << label << '\t' << numSeqs << '\t';
115 for(int i=0;i<data.size();i++){
116 output << data[i] << '\t';
120 catch(exception& e) {
121 cout << "Standard Error: " << e.what() << " has occurred in the OrderVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
125 cout << "An unknown error has occurred in the OrderVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
130 /***********************************************************************/
132 void OrderVector::print(string prefix, ostream& output){
134 output << prefix << '\t' << numSeqs << '\t';
136 for(int i=0;i<numSeqs;i++){
137 output << data[i] << '\t';
141 catch(exception& e) {
142 cout << "Standard Error: " << e.what() << " has occurred in the OrderVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
146 cout << "An unknown error has occurred in the OrderVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
151 /***********************************************************************/
153 void OrderVector::resize(int){
154 cout << "resize() did nothing in class OrderVector";
157 /***********************************************************************/
159 int OrderVector::size(){
163 /***********************************************************************/
165 vector<int>::iterator OrderVector::begin(){
169 /***********************************************************************/
171 vector<int>::iterator OrderVector::end(){
175 /***********************************************************************/
177 RAbundVector OrderVector::getRAbundVector(){
179 RAbundVector rav(data.size());
181 for(int i=0;i<numSeqs;i++){
182 rav.set(data[i], rav.get(data[i]) + 1);
184 sort(rav.rbegin(), rav.rend());
185 for(int i=numSeqs-1;i>=0;i--){
186 if(rav.get(i) == 0){ rav.pop_back(); }
195 catch(exception& e) {
196 cout << "Standard Error: " << e.what() << " has occurred in the OrderVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
200 cout << "An unknown error has occurred in the OrderVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
205 /***********************************************************************/
207 SAbundVector OrderVector::getSAbundVector(){
209 RAbundVector rav(this->getRAbundVector());
210 return rav.getSAbundVector();
214 /***********************************************************************/
216 OrderVector OrderVector::getOrderVector(map<string,int>* hold = 0){
220 /***********************************************************************/
222 void OrderVector::updateStats(){
225 // int maxBinVectorLength = 0;
230 for(int i=0;i<data.size();i++){
236 vector<int> hold(numSeqs);
238 for(int i=0;i<numSeqs;i++){
240 hold[data[i]] = hold[data[i]]+1;
243 for(int i=0;i<numSeqs;i++){
244 if(hold[i] > 0) { numBins++; }
245 if(hold[i] > maxRank) { maxRank = hold[i]; }
248 catch(exception& e) {
249 cout << "Standard Error: " << e.what() << " has occurred in the OrderVector class Function updateStats. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
253 cout << "An unknown error has occurred in the OrderVector class function updateStats. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
258 /***********************************************************************/