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 "utilities.hpp"
17 /***********************************************************************/
19 SharedSAbundVector::SharedSAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){};
21 /***********************************************************************/
23 SharedSAbundVector::SharedSAbundVector(int size) : DataVector(), maxRank(0), numBins(0), numSeqs(0) {
26 for (int i=0; i< size; i++) {
29 data.push_back(newGuy);
33 /***********************************************************************/
35 void SharedSAbundVector::set(int bin, int abundance, string groupName){
38 int initSize = data[bin].abundance;
39 data[bin].abundance = abundance;
40 data[bin].group = groupName;
43 numBins += (abundance - initSize);
46 numSeqs += bin * (abundance - initSize);
48 if(bin > maxRank) { maxRank = bin; }
51 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
55 cout << "An unknown error has occurred in the SharedSAbundVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
60 /***********************************************************************/
62 individual SharedSAbundVector::get(int index){
65 /***********************************************************************/
67 int SharedSAbundVector::getAbundance(int index){
68 return data[index].abundance;
71 /***********************************************************************/
73 void SharedSAbundVector::push_back(int abundance, int bin, string groupName){
76 newGuy.abundance = abundance;
78 newGuy.group = groupName;
80 data.push_back(newGuy);
86 numSeqs += (maxRank * abundance);
89 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
93 cout << "An unknown error has occurred in the SharedSAbundVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
98 /***********************************************************************/
100 void SharedSAbundVector::resize(int size){
104 /***********************************************************************/
106 int SharedSAbundVector::size(){
110 /***********************************************************************/
111 void SharedSAbundVector::print(ostream& output){
113 output << label << '\t' << maxRank << '\t';
115 for(int i=1;i<=maxRank;i++){
116 output << data[i].abundance << '\t';
120 catch(exception& e) {
121 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
125 cout << "An unknown error has occurred in the SharedSAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
129 /***********************************************************************/
130 string SharedSAbundVector::getGroup(){
134 /***********************************************************************/
136 void SharedSAbundVector::setGroup(string groupName){
140 /**********************************************************************/
141 int SharedSAbundVector::getNumBins(){
145 /***********************************************************************/
147 int SharedSAbundVector::getNumSeqs(){
151 /***********************************************************************/
153 int SharedSAbundVector::getMaxRank(){
156 /***********************************************************************/
157 RAbundVector SharedSAbundVector::getRAbundVector(){
161 for(int i=1;i<=data.size();i++){
162 for(int j=0;j<data[i].abundance;j++){
166 sort(rav.rbegin(), rav.rend());
171 catch(exception& e) {
172 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
176 cout << "An unknown error has occurred in the SharedSAbundVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
180 /***********************************************************************/
181 SAbundVector SharedSAbundVector::getSAbundVector(){
186 rav = getRAbundVector();
187 sav = rav.getSAbundVector();
191 catch(exception& e) {
192 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
196 cout << "An unknown error has occurred in the SharedSAbundVector class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
201 /***********************************************************************/
203 bool compareMembers (individual member, individual member2){
205 if(member.abundance < member2.abundance){
212 /***********************************************************************/
213 SharedRAbundVector SharedSAbundVector::getSharedRAbundVector(){
215 SharedRAbundVector rav;
218 for(int i=1;i<=data.size();i++){
219 for(int j=0;j<data[i].abundance;j++){
220 rav.push_back(i, binNumber, data[i].group);
224 sort(rav.rbegin(), rav.rend(), compareMembers);
231 catch(exception& e) {
232 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function getSharedVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
236 cout << "An unknown error has occurred in the SharedSAbundVector class function getSharedVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
242 /***********************************************************************/
244 SharedSAbundVector SharedSAbundVector::getSharedSAbundVector(){
248 /***********************************************************************/
249 SharedOrderVector SharedSAbundVector::getSharedOrderVector() {
251 SharedRAbundVector rav;
252 SharedOrderVector ov;
254 rav = this->getSharedRAbundVector();
255 ov = rav.getSharedOrderVector();
259 catch(exception& e) {
260 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function getSharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
264 cout << "An unknown error has occurred in the SharedSAbundVector class function getSharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
268 /***********************************************************************/
269 OrderVector SharedSAbundVector::getOrderVector(map<string,int>* hold = NULL){
275 for(int i=1;i<data.size();i++){
276 for(int j=0;j<data[i].abundance;j++){
277 for(int k=0;k<i;k++){
278 ov.push_back(binIndex);
284 random_shuffle(ov.begin(), ov.end());
290 catch(exception& e) {
291 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
295 cout << "An unknown error has occurred in the SharedSAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
300 /***********************************************************************/