5 * Created by Sarah Westcott on 12/5/08.
6 * Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved.
13 #include "sharedrabundvector.h"
14 #include "datavector.hpp"
15 #include "utilities.hpp"
17 #include "sharedrabundvector.h"
18 #include "sabundvector.hpp"
19 #include "ordervector.hpp"
22 /***********************************************************************/
24 SharedRAbundVector::SharedRAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0) {};
26 /***********************************************************************/
28 SharedRAbundVector::SharedRAbundVector(int n) : DataVector(), maxRank(0), numBins(n), numSeqs(0) {
31 for (int i=0; i< n; i++) {
34 data.push_back(newGuy);
38 /***********************************************************************
40 SharedRAbundVector::SharedRAbundVector(string id, vector<individual> rav) : DataVector(id), data(rav) {
46 for(int i=0;i<data.size();i++){
47 if(data[i].abundance != 0) { numBins = i+1; }
48 if(data[i].abundance > maxRank) { maxRank = data[i].abundance; }
49 numSeqs += data[i].abundance;
53 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function SharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
57 cout << "An unknown error has occurred in the SharedRAbundVector class function SharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
63 /***********************************************************************
66 SharedRAbundVector::SharedRAbundVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) {
74 for (i=0; i<hold; i++) {
75 newGuy = new individual;
78 data.push_back(newGuy);
82 for(int i=0;i<hold;i++){
88 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function SharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
92 cout << "An unknown error has occurred in the SharedRAbundVector class function SharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
97 /***********************************************************************/
99 SharedRAbundVector::~SharedRAbundVector() {
103 /***********************************************************************/
105 void SharedRAbundVector::set(int binNumber, int newBinSize, string groupname){
107 int oldBinSize = data[binNumber].abundance;
108 data[binNumber].abundance = newBinSize;
109 data[binNumber].group = groupname;
111 if(newBinSize > maxRank) { maxRank = newBinSize; }
113 numSeqs += (newBinSize - oldBinSize);
115 catch(exception& e) {
116 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
120 cout << "An unknown error has occurred in the SharedRAbundVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
125 /***********************************************************************/
127 int SharedRAbundVector::getAbundance(int index){
128 return data[index].abundance;
132 /***********************************************************************/
134 individual SharedRAbundVector::get(int index){
139 /***********************************************************************/
141 void SharedRAbundVector::push_back(int binSize, int otu, string groupName){
144 newGuy.abundance = binSize;
145 newGuy.group = groupName;
148 data.push_back(newGuy);
151 if(binSize > maxRank){
157 catch(exception& e) {
158 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
162 cout << "An unknown error has occurred in the SharedRAbundVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
167 /***********************************************************************/
169 void SharedRAbundVector::pop_back(){
171 return data.pop_back();
174 /***********************************************************************/
177 vector<individual>::reverse_iterator SharedRAbundVector::rbegin(){
178 return data.rbegin();
181 /***********************************************************************/
183 vector<individual>::reverse_iterator SharedRAbundVector::rend(){
187 /***********************************************************************/
188 void SharedRAbundVector::resize(int size){
193 /***********************************************************************/
195 int SharedRAbundVector::size(){
199 /***********************************************************************/
200 void SharedRAbundVector::print(ostream& output){
202 output << numBins << '\t';
204 for(int i=0;i<numBins;i++){ output << data[i].abundance << '\t'; }
207 catch(exception& e) {
208 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
212 cout << "An unknown error has occurred in the SharedRAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
216 /***********************************************************************/
217 string SharedRAbundVector::getGroup(){
221 /***********************************************************************/
223 void SharedRAbundVector::setGroup(string groupName){
228 /***********************************************************************/
229 int SharedRAbundVector::getNumBins(){
233 /***********************************************************************/
235 int SharedRAbundVector::getNumSeqs(){
239 /***********************************************************************/
241 int SharedRAbundVector::getMaxRank(){
245 /***********************************************************************/
247 SharedRAbundVector SharedRAbundVector::getSharedRAbundVector(){
251 /***********************************************************************/
253 SAbundVector SharedRAbundVector::getSAbundVector() {
255 SAbundVector sav(maxRank+1);
257 for(int i=0;i<data.size();i++){
258 int abund = data[i].abundance;
259 sav.set(abund, sav.get(abund) + 1);
265 catch(exception& e) {
266 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
270 cout << "An unknown error has occurred in the SharedRAbundVector class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
275 /***********************************************************************/
277 SharedOrderVector SharedRAbundVector::getSharedOrderVector() {
279 SharedOrderVector ov;
281 for(int i=0;i<data.size();i++){
282 for(int j=0;j<data[i].abundance;j++){
283 ov.push_back(data[i].bin, data[i].abundance, data[i].group);
286 random_shuffle(ov.begin(), ov.end());
291 catch(exception& e) {
292 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
296 cout << "An unknown error has occurred in the SharedRAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
300 /***********************************************************************/
302 OrderVector SharedRAbundVector::getOrderVector(map<string,int>* nameMap = NULL) {
306 for(int i=0;i<data.size();i++){
307 for(int j=0;j<data[i].abundance;j++){
311 random_shuffle(ov.begin(), ov.end());
316 catch(exception& e) {
317 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
321 cout << "An unknown error has occurred in the SharedRAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
326 /***********************************************************************/