2 * sharedSharedOrderVector.cpp
5 * Created by Sarah Westcott on 12/9/08.
6 * Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved.
13 #include "sharedordervector.h"
14 #include "utilities.hpp"
17 /***********************************************************************/
19 SharedOrderVector::SharedOrderVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0) {}
21 /***********************************************************************/
23 SharedOrderVector::SharedOrderVector(string id, vector<individual> ov) :
24 DataVector(id), data(ov)
29 /***********************************************************************
31 //does not work since we don't have a shared order file format yet.
33 SharedOrderVector::SharedOrderVector(ifstream& f) : DataVector() {
40 data.assign(hold, -1);
44 for(int i=0;i<hold;i++){
46 set(i, inputData, inputData, group);
52 cout << "Standard Error: " << e.what() << " has occurred in the SharedOrderVector class Function SharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
56 cout << "An unknown error has occurred in the SharedOrderVector class function SharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
61 /***********************************************************************/
64 int SharedOrderVector::getNumBins(){
65 if(needToUpdate == 1){ updateStats(); }
69 /***********************************************************************/
71 int SharedOrderVector::getNumSeqs(){
72 if(needToUpdate == 1){ updateStats(); }
76 /***********************************************************************/
78 int SharedOrderVector::getMaxRank(){
79 if(needToUpdate == 1){ updateStats(); }
84 /***********************************************************************/
88 void SharedOrderVector::set(int index, int binNumber, int abund, string groupName){
90 data[index].group = groupName;
91 data[index].bin = binNumber;
92 data[index].abundance = abund;
97 /***********************************************************************/
99 individual SharedOrderVector::get(int index){
104 /***********************************************************************/
106 void SharedOrderVector::push_back(int binNumber, int abund, string groupName){
108 newGuy.group = groupName;
109 newGuy.abundance = abund;
110 newGuy.bin = binNumber;
111 data.push_back(newGuy);
116 /***********************************************************************/
118 void SharedOrderVector::print(ostream& output){
120 output << label << '\t' << numSeqs << '\t';
122 for(int i=0;i<data.size();i++){
123 output << data[i].bin << '\t';
127 catch(exception& e) {
128 cout << "Standard Error: " << e.what() << " has occurred in the SharedOrderVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
132 cout << "An unknown error has occurred in the SharedOrderVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
138 /***********************************************************************/
140 void SharedOrderVector::resize(int){
141 cout << "resize() did nothing in class SharedOrderVector";
144 /***********************************************************************/
147 vector<individual>::iterator SharedOrderVector::begin(){
151 /***********************************************************************/
153 vector<individual>::iterator SharedOrderVector::end(){
157 /***********************************************************************/
159 int SharedOrderVector::size(){
163 /***********************************************************************/
165 RAbundVector SharedOrderVector::getRAbundVector(){
167 RAbundVector rav(data.size());
169 for(int i=0;i<numSeqs;i++){
170 rav.set(data[i].bin, rav.get(data[i].bin) + 1);
172 sort(rav.rbegin(), rav.rend());
173 for(int i=numSeqs-1;i>=0;i--){
174 if(rav.get(i) == 0){ rav.pop_back(); }
183 catch(exception& e) {
184 cout << "Standard Error: " << e.what() << " has occurred in the SharedOrderVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
188 cout << "An unknown error has occurred in the SharedOrderVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
192 /***********************************************************************/
194 OrderVector SharedOrderVector::getOrderVector(map<string,int>* nameMap = NULL) {
198 for (int i = 0; i < data.size(); i++) {
199 ov.push_back(data[i].bin);
202 random_shuffle(ov.begin(), ov.end());
207 catch(exception& e) {
208 cout << "Standard Error: " << e.what() << " has occurred in the SharedOrderVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
212 cout << "An unknown error has occurred in the SharedOrderVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
218 /***********************************************************************/
220 SAbundVector SharedOrderVector::getSAbundVector(){
222 RAbundVector rav(this->getRAbundVector());
223 return rav.getSAbundVector();
226 /***********************************************************************/
227 SharedRAbundVector SharedOrderVector::getSharedRAbundVector(string group) {
229 SharedRAbundVector sharedRav(data.size());
231 sharedRav.setLabel(label);
232 sharedRav.setGroup(group);
234 for (int i = 0; i < data.size(); i++) {
235 if (data[i].group == group) {
236 sharedRav.set(data[i].abundance, sharedRav.getAbundance(data[i].abundance) + 1, data[i].group);
241 catch(exception& e) {
242 cout << "Standard Error: " << e.what() << " has occurred in the SharedOrderVector class Function getSharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
246 cout << "An unknown error has occurred in the SharedOrderVector class function getSharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
251 /***********************************************************************/
252 SharedSAbundVector SharedOrderVector::getSharedSAbundVector(string group) {
255 SharedRAbundVector sharedRav(this->getSharedRAbundVector(group));
256 return sharedRav.getSharedSAbundVector();
259 catch(exception& e) {
260 cout << "Standard Error: " << e.what() << " has occurred in the SharedOrderVector class Function getSharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
264 cout << "An unknown error has occurred in the SharedOrderVector class function getSharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
270 /***********************************************************************/
272 SharedOrderVector SharedOrderVector::getSharedOrderVector(){
276 /***********************************************************************/
278 void SharedOrderVector::updateStats(){
285 for(int i=0;i<data.size();i++){
286 if(data[i].bin != -1){
291 vector<individual> hold(numSeqs);
293 for(int i=0;i<numSeqs;i++){
294 if(data[i].bin != -1){
295 hold[data[i].bin].bin = hold[data[i].bin].bin+1;
299 for(int i=0;i<numSeqs;i++){
300 if(data[i].bin > numBins) { numBins = data[i].bin; }
301 if(data[i].abundance > maxRank) { maxRank = data[i].abundance; }
303 numBins++; //if you have 10 bins largest .bin is 9 since we start at 0.
305 catch(exception& e) {
306 cout << "Standard Error: " << e.what() << " has occurred in the SharedOrderVector class Function updateStats. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
310 cout << "An unknown error has occurred in the SharedOrderVector class function updateStats. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
315 /***********************************************************************/