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"
14 /***********************************************************************/
16 SharedSAbundVector::SharedSAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){}
18 /***********************************************************************/
20 SharedSAbundVector::SharedSAbundVector(int size) : DataVector(), maxRank(0), numBins(0), numSeqs(0) {
23 for (int i=0; i< size; i++) {
26 data.push_back(newGuy);
30 /***********************************************************************/
32 void SharedSAbundVector::set(int bin, int abundance, string groupName){
35 int initSize = data[bin].abundance;
36 data[bin].abundance = abundance;
37 data[bin].group = groupName;
40 numBins += (abundance - initSize);
43 numSeqs += bin * (abundance - initSize);
45 if(bin > maxRank) { maxRank = bin; }
48 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
52 cout << "An unknown error has occurred in the SharedSAbundVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
57 /***********************************************************************/
59 individual SharedSAbundVector::get(int index){
62 /***********************************************************************/
64 int SharedSAbundVector::getAbundance(int index){
65 return data[index].abundance;
68 /***********************************************************************/
70 void SharedSAbundVector::push_back(int abundance, int bin, string groupName){
73 newGuy.abundance = abundance;
75 newGuy.group = groupName;
77 data.push_back(newGuy);
83 numSeqs += (maxRank * abundance);
86 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
90 cout << "An unknown error has occurred in the SharedSAbundVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
95 /***********************************************************************/
97 void SharedSAbundVector::resize(int size){
101 /***********************************************************************/
103 int SharedSAbundVector::size(){
107 /***********************************************************************/
108 void SharedSAbundVector::print(ostream& output){
110 output << label << '\t' << maxRank << '\t';
112 for(int i=1;i<=maxRank;i++){
113 output << data[i].abundance << '\t';
117 catch(exception& e) {
118 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
122 cout << "An unknown error has occurred in the SharedSAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
126 /***********************************************************************/
127 string SharedSAbundVector::getGroup(){
131 /***********************************************************************/
133 void SharedSAbundVector::setGroup(string groupName){
137 /**********************************************************************/
138 int SharedSAbundVector::getNumBins(){
142 /***********************************************************************/
144 int SharedSAbundVector::getNumSeqs(){
148 /***********************************************************************/
150 int SharedSAbundVector::getMaxRank(){
153 /***********************************************************************/
154 RAbundVector SharedSAbundVector::getRAbundVector(){
158 for(int i=1;i<=data.size();i++){
159 for(int j=0;j<data[i].abundance;j++){
163 sort(rav.rbegin(), rav.rend());
168 catch(exception& e) {
169 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
173 cout << "An unknown error has occurred in the SharedSAbundVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
177 /***********************************************************************/
178 SAbundVector SharedSAbundVector::getSAbundVector(){
183 rav = getRAbundVector();
184 sav = rav.getSAbundVector();
188 catch(exception& e) {
189 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
193 cout << "An unknown error has occurred in the SharedSAbundVector class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
198 /***********************************************************************/
200 bool compareMembers (individual member, individual member2){
202 if(member.abundance < member2.abundance){
209 /***********************************************************************/
210 SharedRAbundVector SharedSAbundVector::getSharedRAbundVector(){
212 SharedRAbundVector rav;
215 for(int i=1;i<=data.size();i++){
216 for(int j=0;j<data[i].abundance;j++){
217 rav.push_back(i, binNumber, data[i].group);
221 sort(rav.rbegin(), rav.rend(), compareMembers);
228 catch(exception& e) {
229 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function getSharedVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
233 cout << "An unknown error has occurred in the SharedSAbundVector class function getSharedVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
239 /***********************************************************************/
241 SharedSAbundVector SharedSAbundVector::getSharedSAbundVector(){
245 /***********************************************************************/
246 SharedOrderVector SharedSAbundVector::getSharedOrderVector() {
248 SharedRAbundVector rav;
249 SharedOrderVector ov;
251 rav = this->getSharedRAbundVector();
252 ov = rav.getSharedOrderVector();
258 catch(exception& e) {
259 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function getSharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
263 cout << "An unknown error has occurred in the SharedSAbundVector class function getSharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
267 /***********************************************************************/
268 OrderVector SharedSAbundVector::getOrderVector(map<string,int>* hold = NULL){
274 for(int i=1;i<data.size();i++){
275 for(int j=0;j<data[i].abundance;j++){
276 for(int k=0;k<i;k++){
277 ov.push_back(binIndex);
283 random_shuffle(ov.begin(), ov.end());
289 catch(exception& e) {
290 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
294 cout << "An unknown error has occurred in the SharedSAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
299 /***********************************************************************/