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 cout << "Standard Error: " << e.what() << " has occurred in the OrderVector class Function OrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
54 cout << "An unknown error has occurred in the OrderVector class function OrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
59 /***********************************************************************/
62 int OrderVector::getNumBins(){
63 if(needToUpdate == 1){ updateStats(); }
67 /***********************************************************************/
69 int OrderVector::getNumSeqs(){
70 if(needToUpdate == 1){ updateStats(); }
74 /***********************************************************************/
76 int OrderVector::getMaxRank(){
77 if(needToUpdate == 1){ updateStats(); }
81 /***********************************************************************/
85 void OrderVector::set(int index, int binNumber){
87 data[index] = binNumber;
92 /***********************************************************************/
94 int OrderVector::get(int index){
98 /***********************************************************************/
100 void OrderVector::push_back(int index){
102 data.push_back(index);
107 /***********************************************************************/
109 void OrderVector::print(ostream& output){
111 output << label << '\t' << numSeqs << '\t';
113 for(int i=0;i<data.size();i++){
114 output << data[i] << '\t';
118 catch(exception& e) {
119 cout << "Standard Error: " << e.what() << " has occurred in the OrderVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
123 cout << "An unknown error has occurred in the OrderVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
128 /***********************************************************************/
130 void OrderVector::print(string prefix, ostream& output){
132 output << prefix << '\t' << numSeqs << '\t';
134 for(int i=0;i<numSeqs;i++){
135 output << data[i] << '\t';
139 catch(exception& e) {
140 cout << "Standard Error: " << e.what() << " has occurred in the OrderVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
144 cout << "An unknown error has occurred in the OrderVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
149 /***********************************************************************/
151 void OrderVector::resize(int){
152 cout << "resize() did nothing in class OrderVector";
155 /***********************************************************************/
157 int OrderVector::size(){
161 /***********************************************************************/
163 vector<int>::iterator OrderVector::begin(){
167 /***********************************************************************/
169 vector<int>::iterator OrderVector::end(){
173 /***********************************************************************/
175 RAbundVector OrderVector::getRAbundVector(){
177 RAbundVector rav(data.size());
179 for(int i=0;i<numSeqs;i++){
180 rav.set(data[i], rav.get(data[i]) + 1);
182 sort(rav.rbegin(), rav.rend());
183 for(int i=numSeqs-1;i>=0;i--){
184 if(rav.get(i) == 0){ rav.pop_back(); }
193 catch(exception& e) {
194 cout << "Standard Error: " << e.what() << " has occurred in the OrderVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
198 cout << "An unknown error has occurred in the OrderVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
203 /***********************************************************************/
205 SAbundVector OrderVector::getSAbundVector(){
207 RAbundVector rav(this->getRAbundVector());
208 return rav.getSAbundVector();
212 /***********************************************************************/
214 OrderVector OrderVector::getOrderVector(map<string,int>* hold = 0){
218 /***********************************************************************/
220 void OrderVector::updateStats(){
223 // int maxBinVectorLength = 0;
228 for(int i=0;i<data.size();i++){
234 vector<int> hold(numSeqs);
236 for(int i=0;i<numSeqs;i++){
238 hold[data[i]] = hold[data[i]]+1;
241 for(int i=0;i<numSeqs;i++){
242 if(hold[i] > 0) { numBins++; }
243 if(hold[i] > maxRank) { maxRank = hold[i]; }
246 catch(exception& e) {
247 cout << "Standard Error: " << e.what() << " has occurred in the OrderVector class Function updateStats. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
251 cout << "An unknown error has occurred in the OrderVector class function updateStats. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
256 /***********************************************************************/