5 * Created by Pat Schloss on 8/8/08.
6 * Copyright 2008 Patrick D. Schloss. All rights reserved.
12 #include "ordervector.hpp"
13 #include "utilities.hpp"
16 /***********************************************************************/
18 OrderVector::OrderVector() : DataVector() {}
20 /***********************************************************************/
22 //OrderVector::OrderVector(int ns) : DataVector(), data(ns, -1) {};
24 /***********************************************************************/
26 OrderVector::OrderVector(string id, vector<int> ov) :
27 DataVector(id), data(ov)
32 /***********************************************************************/
34 OrderVector::OrderVector(ifstream& f) : DataVector() {
41 data.assign(hold, -1);
45 for(int i=0;i<hold;i++){
53 cout << "Standard Error: " << e.what() << " has occurred in the OrderVector class Function OrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
57 cout << "An unknown error has occurred in the OrderVector class function OrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
62 /***********************************************************************/
65 int OrderVector::getNumBins(){
66 if(needToUpdate == 1){ updateStats(); }
70 /***********************************************************************/
72 int OrderVector::getNumSeqs(){
73 if(needToUpdate == 1){ updateStats(); }
77 /***********************************************************************/
79 int OrderVector::getMaxRank(){
80 if(needToUpdate == 1){ updateStats(); }
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 cout << "Standard Error: " << e.what() << " has occurred in the OrderVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
126 cout << "An unknown error has occurred in the OrderVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
131 /***********************************************************************/
133 void OrderVector::print(string prefix, ostream& output){
135 output << prefix << '\t' << numSeqs << '\t';
137 for(int i=0;i<numSeqs;i++){
138 output << data[i] << '\t';
142 catch(exception& e) {
143 cout << "Standard Error: " << e.what() << " has occurred in the OrderVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
147 cout << "An unknown error has occurred in the OrderVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
152 /***********************************************************************/
154 void OrderVector::resize(int){
155 cout << "resize() did nothing in class OrderVector";
158 /***********************************************************************/
160 int OrderVector::size(){
164 /***********************************************************************/
166 vector<int>::iterator OrderVector::begin(){
170 /***********************************************************************/
172 vector<int>::iterator OrderVector::end(){
176 /***********************************************************************/
178 RAbundVector OrderVector::getRAbundVector(){
180 RAbundVector rav(data.size());
182 for(int i=0;i<numSeqs;i++){
183 rav.set(data[i], rav.get(data[i]) + 1);
185 sort(rav.rbegin(), rav.rend());
186 for(int i=numSeqs-1;i>=0;i--){
187 if(rav.get(i) == 0){ rav.pop_back(); }
196 catch(exception& e) {
197 cout << "Standard Error: " << e.what() << " has occurred in the OrderVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
201 cout << "An unknown error has occurred in the OrderVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
206 /***********************************************************************/
208 SAbundVector OrderVector::getSAbundVector(){
210 RAbundVector rav(this->getRAbundVector());
211 return rav.getSAbundVector();
215 /***********************************************************************/
217 OrderVector OrderVector::getOrderVector(map<string,int>* hold = 0){
221 /***********************************************************************/
223 void OrderVector::updateStats(){
226 // int maxBinVectorLength = 0;
231 for(int i=0;i<data.size();i++){
237 vector<int> hold(numSeqs);
239 for(int i=0;i<numSeqs;i++){
241 hold[data[i]] = hold[data[i]]+1;
244 for(int i=0;i<numSeqs;i++){
245 if(hold[i] > 0) { numBins++; }
246 if(hold[i] > maxRank) { maxRank = hold[i]; }
249 catch(exception& e) {
250 cout << "Standard Error: " << e.what() << " has occurred in the OrderVector class Function updateStats. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
254 cout << "An unknown error has occurred in the OrderVector class function updateStats. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
259 /***********************************************************************/