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) {
69 string holdLabel, group
72 f >> label >> group >> num;
75 for (i=0; i<hold; i++) {
76 newGuy = new individual;
79 data.push_back(newGuy);
83 for(int i=0;i<hold;i++){
89 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function SharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
93 cout << "An unknown error has occurred in the SharedRAbundVector class function SharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
98 /***********************************************************************/
100 SharedRAbundVector::~SharedRAbundVector() {
104 /***********************************************************************/
106 void SharedRAbundVector::set(int binNumber, int newBinSize, string groupname){
108 int oldBinSize = data[binNumber].abundance;
109 data[binNumber].abundance = newBinSize;
110 data[binNumber].group = groupname;
112 if(newBinSize > maxRank) { maxRank = newBinSize; }
114 numSeqs += (newBinSize - oldBinSize);
116 catch(exception& e) {
117 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
121 cout << "An unknown error has occurred in the SharedRAbundVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
126 /***********************************************************************/
128 int SharedRAbundVector::getAbundance(int index){
129 return data[index].abundance;
133 /***********************************************************************/
135 individual SharedRAbundVector::get(int index){
140 /***********************************************************************/
142 void SharedRAbundVector::push_back(int binSize, int otu, string groupName){
145 newGuy.abundance = binSize;
146 newGuy.group = groupName;
149 data.push_back(newGuy);
152 if(binSize > maxRank){
158 catch(exception& e) {
159 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
163 cout << "An unknown error has occurred in the SharedRAbundVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
168 /***********************************************************************/
170 void SharedRAbundVector::pop_back(){
172 return data.pop_back();
175 /***********************************************************************/
178 vector<individual>::reverse_iterator SharedRAbundVector::rbegin(){
179 return data.rbegin();
182 /***********************************************************************/
184 vector<individual>::reverse_iterator SharedRAbundVector::rend(){
188 /***********************************************************************/
189 void SharedRAbundVector::resize(int size){
194 /***********************************************************************/
196 int SharedRAbundVector::size(){
200 /***********************************************************************/
201 void SharedRAbundVector::print(ostream& output){
203 output << numBins << '\t';
205 for(int i=0;i<numBins;i++){ output << data[i].abundance << '\t'; }
208 catch(exception& e) {
209 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
213 cout << "An unknown error has occurred in the SharedRAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
217 /***********************************************************************/
218 string SharedRAbundVector::getGroup(){
222 /***********************************************************************/
224 void SharedRAbundVector::setGroup(string groupName){
227 /***********************************************************************/
228 int SharedRAbundVector::getGroupIndex() { return index; }
229 /***********************************************************************/
230 void SharedRAbundVector::setGroupIndex(int vIndex) { index = vIndex; }
231 /***********************************************************************/
232 int SharedRAbundVector::getNumBins(){
236 /***********************************************************************/
238 int SharedRAbundVector::getNumSeqs(){
242 /***********************************************************************/
244 int SharedRAbundVector::getMaxRank(){
248 /***********************************************************************/
250 SharedRAbundVector SharedRAbundVector::getSharedRAbundVector(){
253 /***********************************************************************/
255 RAbundVector SharedRAbundVector::getRAbundVector() {
257 RAbundVector rav(data.size());
259 for (int i = 0; i < data.size(); i++) {
260 rav.set(i, data[i].abundance);
265 catch(exception& e) {
266 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
270 cout << "An unknown error has occurred in the SharedRAbundVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
275 /***********************************************************************/
277 SharedSAbundVector SharedRAbundVector::getSharedSAbundVector(){
279 SharedSAbundVector sav(maxRank+1);
281 for(int i=0;i<data.size();i++){
282 int abund = data[i].abundance;
283 sav.set(abund, sav.getAbundance(abund) + 1, group);
286 sav.set(0, 0, group);
292 catch(exception& e) {
293 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getSharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
297 cout << "An unknown error has occurred in the SharedRAbundVector class function getSharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
301 /***********************************************************************/
303 SAbundVector SharedRAbundVector::getSAbundVector() {
305 SAbundVector sav(maxRank+1);
307 for(int i=0;i<data.size();i++){
308 int abund = data[i].abundance;
309 sav.set(abund, sav.get(abund) + 1);
315 catch(exception& e) {
316 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
320 cout << "An unknown error has occurred in the SharedRAbundVector class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
325 /***********************************************************************/
327 SharedOrderVector SharedRAbundVector::getSharedOrderVector() {
329 SharedOrderVector ov;
331 for(int i=0;i<data.size();i++){
332 for(int j=0;j<data[i].abundance;j++){
333 ov.push_back(data[i].bin, data[i].abundance, data[i].group);
336 random_shuffle(ov.begin(), ov.end());
341 catch(exception& e) {
342 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
346 cout << "An unknown error has occurred in the SharedRAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
350 /***********************************************************************/
352 OrderVector SharedRAbundVector::getOrderVector(map<string,int>* nameMap = NULL) {
356 for(int i=0;i<data.size();i++){
357 for(int j=0;j<data[i].abundance;j++){
361 random_shuffle(ov.begin(), ov.end());
366 catch(exception& e) {
367 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
371 cout << "An unknown error has occurred in the SharedRAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
376 /***********************************************************************/