2 * sharedSharedSAbundVector.cpp
5 * Created by Sarah Westcott on 12/10/08.
6 * Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "sharedsabundvector.h"
11 #include "sabundvector.hpp"
12 #include "datavector.hpp"
13 #include "utilities.hpp"
19 /***********************************************************************/
21 SharedSAbundVector::SharedSAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){};
23 /***********************************************************************/
25 SharedSAbundVector::SharedSAbundVector(int size) : DataVector(), maxRank(0), numBins(0), numSeqs(0) {
28 for (int i=0; i< size; i++) {
31 data.push_back(newGuy);
35 /***********************************************************************/
37 void SharedSAbundVector::set(int bin, int abundance, string groupName){
40 int initSize = data[bin].abundance;
41 data[bin].abundance = abundance;
42 data[bin].group = groupName;
45 numBins += (abundance - initSize);
48 numSeqs += bin * (abundance - initSize);
50 if(bin > maxRank) { maxRank = bin; }
53 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
57 cout << "An unknown error has occurred in the SharedSAbundVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
62 /***********************************************************************/
64 individual SharedSAbundVector::get(int index){
67 /***********************************************************************/
69 int SharedSAbundVector::getAbundance(int index){
70 return data[index].abundance;
73 /***********************************************************************/
75 void SharedSAbundVector::push_back(int abundance, int bin, string groupName){
78 newGuy.abundance = abundance;
80 newGuy.group = groupName;
82 data.push_back(newGuy);
88 numSeqs += (maxRank * abundance);
91 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
95 cout << "An unknown error has occurred in the SharedSAbundVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
100 /***********************************************************************/
102 void SharedSAbundVector::resize(int size){
106 /***********************************************************************/
108 int SharedSAbundVector::size(){
112 /***********************************************************************/
113 void SharedSAbundVector::print(ostream& output){
115 output << label << '\t' << maxRank << '\t';
117 for(int i=1;i<=maxRank;i++){
118 output << data[i].abundance << '\t';
122 catch(exception& e) {
123 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
127 cout << "An unknown error has occurred in the SharedSAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
131 /***********************************************************************/
132 string SharedSAbundVector::getGroup(){
136 /***********************************************************************/
138 void SharedSAbundVector::setGroup(string groupName){
142 /**********************************************************************/
143 int SharedSAbundVector::getNumBins(){
147 /***********************************************************************/
149 int SharedSAbundVector::getNumSeqs(){
153 /***********************************************************************/
155 int SharedSAbundVector::getMaxRank(){
158 /***********************************************************************/
159 RAbundVector SharedSAbundVector::getRAbundVector(){
163 for(int i=1;i<=data.size();i++){
164 for(int j=0;j<data[i].abundance;j++){
168 sort(rav.rbegin(), rav.rend());
173 catch(exception& e) {
174 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
178 cout << "An unknown error has occurred in the SharedSAbundVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
182 /***********************************************************************/
183 SAbundVector SharedSAbundVector::getSAbundVector(){
188 rav = getRAbundVector();
189 sav = rav.getSAbundVector();
193 catch(exception& e) {
194 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
198 cout << "An unknown error has occurred in the SharedSAbundVector class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
203 /***********************************************************************/
205 bool compareMembers (individual member, individual member2){
207 if(member.abundance < member2.abundance){
214 /***********************************************************************/
215 SharedRAbundVector SharedSAbundVector::getSharedRAbundVector(){
217 SharedRAbundVector rav;
220 for(int i=1;i<=data.size();i++){
221 for(int j=0;j<data[i].abundance;j++){
222 rav.push_back(i, binNumber, data[i].group);
226 sort(rav.rbegin(), rav.rend(), compareMembers);
233 catch(exception& e) {
234 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function getSharedVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
238 cout << "An unknown error has occurred in the SharedSAbundVector class function getSharedVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
244 /***********************************************************************/
246 SharedSAbundVector SharedSAbundVector::getSharedSAbundVector(){
250 /***********************************************************************/
251 SharedOrderVector SharedSAbundVector::getSharedOrderVector() {
253 SharedRAbundVector rav;
254 SharedOrderVector ov;
256 rav = this->getSharedRAbundVector();
257 ov = rav.getSharedOrderVector();
261 catch(exception& e) {
262 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function getSharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
266 cout << "An unknown error has occurred in the SharedSAbundVector class function getSharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
270 /***********************************************************************/
271 OrderVector SharedSAbundVector::getOrderVector(map<string,int>* hold = NULL){
277 for(int i=1;i<data.size();i++){
278 for(int j=0;j<data[i].abundance;j++){
279 for(int k=0;k<i;k++){
280 ov.push_back(binIndex);
286 random_shuffle(ov.begin(), ov.end());
292 catch(exception& e) {
293 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
297 cout << "An unknown error has occurred in the SharedSAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
302 /***********************************************************************/