2 * sharedSharedSAbundVector.cpp
5 * Created by Sarah Westcott on 12/10/08.
6 * Copyright 2008 __MyCompanyName__. 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);
33 // for(int i=0;i<data.size();i++){
34 // if(data[i].abundance != 0){ maxRank = i; }
35 // numSeqs += i*data[i].abundance;
36 // numBins += data[i].abundance;
41 /***********************************************************************
43 SharedSAbundVector::SharedSAbundVector(string id, vector<int> sav) : DataVector(id), data(sav) {
46 for(int i=0;i<sav.size();i++){
47 if(data[i] != 0){ maxRank = i; }
53 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function SharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
57 cout << "An unknown error has occurred in the SharedSAbundVector class function SharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
62 /***********************************************************************
64 SharedSAbundVector::SharedSAbundVector(ifstream& f): DataVector(), maxRank(0), numBins(0), numSeqs(0) {
69 data.assign(hold+1, 0);
72 for(int i=1;i<=hold;i++){
78 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function SharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
82 cout << "An unknown error has occurred in the SharedSAbundVector class function SharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
87 /***********************************************************************/
89 void SharedSAbundVector::set(int bin, int abundance, string groupName){
92 int initSize = data[bin].abundance;
93 data[bin].abundance = abundance;
94 data[bin].group = groupName;
97 numBins += (abundance - initSize);
100 numSeqs += bin * (abundance - initSize);
102 if(bin > maxRank) { maxRank = bin; }
104 catch(exception& e) {
105 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
109 cout << "An unknown error has occurred in the SharedSAbundVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
114 /***********************************************************************/
116 individual SharedSAbundVector::get(int index){
119 /***********************************************************************/
121 int SharedSAbundVector::getAbundance(int index){
122 return data[index].abundance;
125 /***********************************************************************/
127 void SharedSAbundVector::push_back(int abundance, int bin, string groupName){
130 newGuy.abundance = abundance;
132 newGuy.group = groupName;
134 data.push_back(newGuy);
138 numBins += abundance;
140 numSeqs += (maxRank * abundance);
142 catch(exception& e) {
143 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
147 cout << "An unknown error has occurred in the SharedSAbundVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
152 /***********************************************************************/
154 void SharedSAbundVector::resize(int size){
158 /***********************************************************************/
160 int SharedSAbundVector::size(){
164 /***********************************************************************/
165 void SharedSAbundVector::print(ostream& output){
167 output << label << '\t' << maxRank << '\t';
169 for(int i=1;i<=maxRank;i++){
170 output << data[i].abundance << '\t';
174 catch(exception& e) {
175 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
179 cout << "An unknown error has occurred in the SharedSAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
183 /***********************************************************************/
184 string SharedSAbundVector::getGroup(){
188 /***********************************************************************/
190 void SharedSAbundVector::setGroup(string groupName){
194 /**********************************************************************/
195 int SharedSAbundVector::getNumBins(){
199 /***********************************************************************/
201 int SharedSAbundVector::getNumSeqs(){
205 /***********************************************************************/
207 int SharedSAbundVector::getMaxRank(){
210 /***********************************************************************/
211 RAbundVector SharedSAbundVector::getRAbundVector(){
215 for(int i=1;i<=data.size();i++){
216 for(int j=0;j<data[i].abundance;j++){
220 sort(rav.rbegin(), rav.rend());
225 catch(exception& e) {
226 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
230 cout << "An unknown error has occurred in the SharedSAbundVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
234 /***********************************************************************/
235 SAbundVector SharedSAbundVector::getSAbundVector(){
240 rav = getRAbundVector();
241 sav = rav.getSAbundVector();
245 catch(exception& e) {
246 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
250 cout << "An unknown error has occurred in the SharedSAbundVector class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
255 /***********************************************************************/
257 bool compareMembers (individual member, individual member2){
259 if(member.abundance < member2.abundance){
266 /***********************************************************************/
267 SharedRAbundVector SharedSAbundVector::getSharedVector(){
269 SharedRAbundVector rav;
272 for(int i=1;i<=data.size();i++){
273 for(int j=0;j<data[i].abundance;j++){
274 rav.push_back(i, binNumber, data[i].group);
278 sort(rav.rbegin(), rav.rend(), compareMembers);
285 catch(exception& e) {
286 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function getSharedVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
290 cout << "An unknown error has occurred in the SharedSAbundVector class function getSharedVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
296 /***********************************************************************/
298 SharedSAbundVector SharedSAbundVector::getSharedSAbundVector(){
302 /***********************************************************************/
304 OrderVector SharedSAbundVector::getOrderVector(map<string,int>* hold = NULL){
310 for(int i=1;i<data.size();i++){
311 for(int j=0;j<data[i].abundance;j++){
312 for(int k=0;k<i;k++){
313 ov.push_back(binIndex);
319 random_shuffle(ov.begin(), ov.end());
325 catch(exception& e) {
326 cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
330 cout << "An unknown error has occurred in the SharedSAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
335 /***********************************************************************/