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"
16 /***********************************************************************/
18 SharedSAbundVector::SharedSAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){};
20 /***********************************************************************/
22 SharedSAbundVector::SharedSAbundVector(int size) : DataVector(), maxRank(0), numBins(0), numSeqs(0) {
25 for (int i=0; i< size; i++) {
28 data.push_back(newGuy);
32 /***********************************************************************/
34 void SharedSAbundVector::set(int bin, int abundance, string groupName){
37 int initSize = data[bin].abundance;
38 data[bin].abundance = abundance;
39 data[bin].group = groupName;
42 numBins += (abundance - initSize);
45 numSeqs += bin * (abundance - initSize);
47 if(bin > maxRank) { maxRank = bin; }
50 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
54 cout << "An unknown error has occurred in the SharedSAbundVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
59 /***********************************************************************/
61 individual SharedSAbundVector::get(int index){
64 /***********************************************************************/
66 int SharedSAbundVector::getAbundance(int index){
67 return data[index].abundance;
70 /***********************************************************************/
72 void SharedSAbundVector::push_back(int abundance, int bin, string groupName){
75 newGuy.abundance = abundance;
77 newGuy.group = groupName;
79 data.push_back(newGuy);
85 numSeqs += (maxRank * abundance);
88 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
92 cout << "An unknown error has occurred in the SharedSAbundVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
97 /***********************************************************************/
99 void SharedSAbundVector::resize(int size){
103 /***********************************************************************/
105 int SharedSAbundVector::size(){
109 /***********************************************************************/
110 void SharedSAbundVector::print(ostream& output){
112 output << label << '\t' << maxRank << '\t';
114 for(int i=1;i<=maxRank;i++){
115 output << data[i].abundance << '\t';
119 catch(exception& e) {
120 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
124 cout << "An unknown error has occurred in the SharedSAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
128 /***********************************************************************/
129 string SharedSAbundVector::getGroup(){
133 /***********************************************************************/
135 void SharedSAbundVector::setGroup(string groupName){
139 /**********************************************************************/
140 int SharedSAbundVector::getNumBins(){
144 /***********************************************************************/
146 int SharedSAbundVector::getNumSeqs(){
150 /***********************************************************************/
152 int SharedSAbundVector::getMaxRank(){
155 /***********************************************************************/
156 RAbundVector SharedSAbundVector::getRAbundVector(){
160 for(int i=1;i<=data.size();i++){
161 for(int j=0;j<data[i].abundance;j++){
165 sort(rav.rbegin(), rav.rend());
170 catch(exception& e) {
171 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
175 cout << "An unknown error has occurred in the SharedSAbundVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
179 /***********************************************************************/
180 SAbundVector SharedSAbundVector::getSAbundVector(){
185 rav = getRAbundVector();
186 sav = rav.getSAbundVector();
190 catch(exception& e) {
191 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
195 cout << "An unknown error has occurred in the SharedSAbundVector class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
200 /***********************************************************************/
202 bool compareMembers (individual member, individual member2){
204 if(member.abundance < member2.abundance){
211 /***********************************************************************/
212 SharedRAbundVector SharedSAbundVector::getSharedRAbundVector(){
214 SharedRAbundVector rav;
217 for(int i=1;i<=data.size();i++){
218 for(int j=0;j<data[i].abundance;j++){
219 rav.push_back(i, binNumber, data[i].group);
223 sort(rav.rbegin(), rav.rend(), compareMembers);
230 catch(exception& e) {
231 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function getSharedVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
235 cout << "An unknown error has occurred in the SharedSAbundVector class function getSharedVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
241 /***********************************************************************/
243 SharedSAbundVector SharedSAbundVector::getSharedSAbundVector(){
247 /***********************************************************************/
248 SharedOrderVector SharedSAbundVector::getSharedOrderVector() {
250 SharedRAbundVector rav;
251 SharedOrderVector ov;
253 rav = this->getSharedRAbundVector();
254 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 /***********************************************************************/