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){
226 /***********************************************************************/
227 int SharedRAbundVector::getGroupIndex() { return index; }
228 /***********************************************************************/
229 void SharedRAbundVector::setGroupIndex(int vIndex) { index = vIndex; }
230 /***********************************************************************/
231 int SharedRAbundVector::getNumBins(){
235 /***********************************************************************/
237 int SharedRAbundVector::getNumSeqs(){
241 /***********************************************************************/
243 int SharedRAbundVector::getMaxRank(){
247 /***********************************************************************/
249 SharedRAbundVector SharedRAbundVector::getSharedRAbundVector(){
252 /***********************************************************************/
254 RAbundVector SharedRAbundVector::getRAbundVector() {
256 RAbundVector rav(data.size());
258 for (int i = 0; i < data.size(); i++) {
259 rav.set(i, data[i].abundance);
264 catch(exception& e) {
265 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
269 cout << "An unknown error has occurred in the SharedRAbundVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
274 /***********************************************************************/
276 SharedSAbundVector SharedRAbundVector::getSharedSAbundVector(){
278 SharedSAbundVector sav(maxRank+1);
280 for(int i=0;i<data.size();i++){
281 int abund = data[i].abundance;
282 sav.set(abund, sav.getAbundance(abund) + 1, group);
285 sav.set(0, 0, group);
291 catch(exception& e) {
292 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getSharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
296 cout << "An unknown error has occurred in the SharedRAbundVector class function getSharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
300 /***********************************************************************/
302 SAbundVector SharedRAbundVector::getSAbundVector() {
304 SAbundVector sav(maxRank+1);
306 for(int i=0;i<data.size();i++){
307 int abund = data[i].abundance;
308 sav.set(abund, sav.get(abund) + 1);
314 catch(exception& e) {
315 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
319 cout << "An unknown error has occurred in the SharedRAbundVector class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
324 /***********************************************************************/
326 SharedOrderVector SharedRAbundVector::getSharedOrderVector() {
328 SharedOrderVector ov;
330 for(int i=0;i<data.size();i++){
331 for(int j=0;j<data[i].abundance;j++){
332 ov.push_back(data[i].bin, data[i].abundance, data[i].group);
335 random_shuffle(ov.begin(), ov.end());
340 catch(exception& e) {
341 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
345 cout << "An unknown error has occurred in the SharedRAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
349 /***********************************************************************/
351 OrderVector SharedRAbundVector::getOrderVector(map<string,int>* nameMap = NULL) {
355 for(int i=0;i<data.size();i++){
356 for(int j=0;j<data[i].abundance;j++){
360 random_shuffle(ov.begin(), ov.end());
365 catch(exception& e) {
366 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
370 cout << "An unknown error has occurred in the SharedRAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
375 /***********************************************************************/