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 "utilities.hpp"
15 #include "sabundvector.hpp"
16 #include "ordervector.hpp"
19 /***********************************************************************/
21 SharedRAbundVector::SharedRAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0) {};
23 /***********************************************************************/
25 SharedRAbundVector::SharedRAbundVector(int n) : DataVector(), maxRank(0), numBins(n), numSeqs(0) {
28 for (int i=0; i< n; i++) {
31 data.push_back(newGuy);
35 /***********************************************************************
37 SharedRAbundVector::SharedRAbundVector(string id, vector<individual> rav) : DataVector(id), data(rav) {
43 for(int i=0;i<data.size();i++){
44 if(data[i].abundance != 0) { numBins = i+1; }
45 if(data[i].abundance > maxRank) { maxRank = data[i].abundance; }
46 numSeqs += data[i].abundance;
50 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function SharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
54 cout << "An unknown error has occurred in the SharedRAbundVector class function SharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
60 /***********************************************************************
63 SharedRAbundVector::SharedRAbundVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) {
66 string holdLabel, group
69 f >> label >> group >> num;
72 for (i=0; i<hold; i++) {
73 newGuy = new individual;
76 data.push_back(newGuy);
80 for(int i=0;i<hold;i++){
86 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function SharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
90 cout << "An unknown error has occurred in the SharedRAbundVector class function SharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
95 /***********************************************************************/
97 SharedRAbundVector::~SharedRAbundVector() {
101 /***********************************************************************/
103 void SharedRAbundVector::set(int binNumber, int newBinSize, string groupname){
105 int oldBinSize = data[binNumber].abundance;
106 data[binNumber].abundance = newBinSize;
107 data[binNumber].group = groupname;
109 if(newBinSize > maxRank) { maxRank = newBinSize; }
111 numSeqs += (newBinSize - oldBinSize);
113 catch(exception& e) {
114 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
118 cout << "An unknown error has occurred in the SharedRAbundVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
123 /***********************************************************************/
125 int SharedRAbundVector::getAbundance(int index){
126 return data[index].abundance;
130 /***********************************************************************/
132 individual SharedRAbundVector::get(int index){
137 /***********************************************************************/
139 void SharedRAbundVector::push_back(int binSize, int otu, string groupName){
142 newGuy.abundance = binSize;
143 newGuy.group = groupName;
146 data.push_back(newGuy);
149 if(binSize > maxRank){
155 catch(exception& e) {
156 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
160 cout << "An unknown error has occurred in the SharedRAbundVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
165 /***********************************************************************/
167 void SharedRAbundVector::pop_back(){
169 return data.pop_back();
172 /***********************************************************************/
175 vector<individual>::reverse_iterator SharedRAbundVector::rbegin(){
176 return data.rbegin();
179 /***********************************************************************/
181 vector<individual>::reverse_iterator SharedRAbundVector::rend(){
185 /***********************************************************************/
186 void SharedRAbundVector::resize(int size){
191 /***********************************************************************/
193 int SharedRAbundVector::size(){
197 /***********************************************************************/
198 void SharedRAbundVector::print(ostream& output){
200 output << numBins << '\t';
202 for(int i=0;i<numBins;i++){ output << data[i].abundance << '\t'; }
205 catch(exception& e) {
206 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
210 cout << "An unknown error has occurred in the SharedRAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
214 /***********************************************************************/
215 string SharedRAbundVector::getGroup(){
219 /***********************************************************************/
221 void SharedRAbundVector::setGroup(string groupName){
224 /***********************************************************************/
225 int SharedRAbundVector::getGroupIndex() { return index; }
226 /***********************************************************************/
227 void SharedRAbundVector::setGroupIndex(int vIndex) { index = vIndex; }
228 /***********************************************************************/
229 int SharedRAbundVector::getNumBins(){
233 /***********************************************************************/
235 int SharedRAbundVector::getNumSeqs(){
239 /***********************************************************************/
241 int SharedRAbundVector::getMaxRank(){
245 /***********************************************************************/
247 SharedRAbundVector SharedRAbundVector::getSharedRAbundVector(){
250 /***********************************************************************/
252 RAbundVector SharedRAbundVector::getRAbundVector() {
254 RAbundVector rav(data.size());
256 for (int i = 0; i < data.size(); i++) {
257 rav.set(i, data[i].abundance);
262 catch(exception& e) {
263 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
267 cout << "An unknown error has occurred in the SharedRAbundVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
272 /***********************************************************************/
274 SharedSAbundVector SharedRAbundVector::getSharedSAbundVector(){
276 SharedSAbundVector sav(maxRank+1);
278 for(int i=0;i<data.size();i++){
279 int abund = data[i].abundance;
280 sav.set(abund, sav.getAbundance(abund) + 1, group);
283 sav.set(0, 0, group);
289 catch(exception& e) {
290 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getSharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
294 cout << "An unknown error has occurred in the SharedRAbundVector class function getSharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
298 /***********************************************************************/
300 SAbundVector SharedRAbundVector::getSAbundVector() {
302 SAbundVector sav(maxRank+1);
304 for(int i=0;i<data.size();i++){
305 int abund = data[i].abundance;
306 sav.set(abund, sav.get(abund) + 1);
312 catch(exception& e) {
313 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
317 cout << "An unknown error has occurred in the SharedRAbundVector class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
322 /***********************************************************************/
324 SharedOrderVector SharedRAbundVector::getSharedOrderVector() {
326 SharedOrderVector ov;
328 for(int i=0;i<data.size();i++){
329 for(int j=0;j<data[i].abundance;j++){
330 ov.push_back(data[i].bin, data[i].abundance, data[i].group);
333 random_shuffle(ov.begin(), ov.end());
338 catch(exception& e) {
339 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
343 cout << "An unknown error has occurred in the SharedRAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
347 /***********************************************************************/
349 OrderVector SharedRAbundVector::getOrderVector(map<string,int>* nameMap = NULL) {
353 for(int i=0;i<data.size();i++){
354 for(int j=0;j<data[i].abundance;j++){
358 random_shuffle(ov.begin(), ov.end());
363 catch(exception& e) {
364 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
368 cout << "An unknown error has occurred in the SharedRAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
373 /***********************************************************************/