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"
20 /***********************************************************************/
22 SharedRAbundVector::SharedRAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0) {};
24 /***********************************************************************/
26 SharedRAbundVector::SharedRAbundVector(int n) : DataVector(), maxRank(0), numBins(n), numSeqs(0) {
29 for (int i=0; i< n; i++) {
32 data.push_back(newGuy);
36 /***********************************************************************
38 SharedRAbundVector::SharedRAbundVector(string id, vector<individual> rav) : DataVector(id), data(rav) {
44 for(int i=0;i<data.size();i++){
45 if(data[i].abundance != 0) { numBins = i+1; }
46 if(data[i].abundance > maxRank) { maxRank = data[i].abundance; }
47 numSeqs += data[i].abundance;
51 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function SharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
55 cout << "An unknown error has occurred in the SharedRAbundVector class function SharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
61 /***********************************************************************
64 SharedRAbundVector::SharedRAbundVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) {
67 string holdLabel, group
70 f >> label >> group >> num;
73 for (i=0; i<hold; i++) {
74 newGuy = new individual;
77 data.push_back(newGuy);
81 for(int i=0;i<hold;i++){
87 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function SharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
91 cout << "An unknown error has occurred in the SharedRAbundVector class function SharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
96 /***********************************************************************/
98 SharedRAbundVector::~SharedRAbundVector() {
102 /***********************************************************************/
104 void SharedRAbundVector::set(int binNumber, int newBinSize, string groupname){
106 int oldBinSize = data[binNumber].abundance;
107 data[binNumber].abundance = newBinSize;
108 data[binNumber].group = groupname;
110 if(newBinSize > maxRank) { maxRank = newBinSize; }
112 numSeqs += (newBinSize - oldBinSize);
114 catch(exception& e) {
115 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
119 cout << "An unknown error has occurred in the SharedRAbundVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
123 /***********************************************************************/
125 void SharedRAbundVector::setData(vector <individual> newData){
129 /***********************************************************************/
131 int SharedRAbundVector::getAbundance(int index){
132 return data[index].abundance;
135 /***********************************************************************/
137 int SharedRAbundVector::numNZ(){
139 for(int i = 1; i < numBins; i++)
140 if(data[i].abundance > 0)
144 /***********************************************************************/
146 void SharedRAbundVector::sortD(){
147 struct individual indObj;
148 sort(data.begin()+1, data.end(), indObj);
150 /***********************************************************************/
152 individual SharedRAbundVector::get(int index){
156 /***********************************************************************/
158 vector <individual> SharedRAbundVector::getData(){
161 /***********************************************************************/
163 void SharedRAbundVector::push_back(int binSize, int otu, string groupName){
166 newGuy.abundance = binSize;
167 newGuy.group = groupName;
170 data.push_back(newGuy);
173 if(binSize > maxRank){
179 catch(exception& e) {
180 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
184 cout << "An unknown error has occurred in the SharedRAbundVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
190 /***********************************************************************/
192 void SharedRAbundVector::push_front(int binSize, int otu, string groupName){
195 newGuy.abundance = binSize;
196 newGuy.group = groupName;
199 data.insert(data.begin(), newGuy);
202 if(binSize > maxRank){
208 catch(exception& e) {
209 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function push_front. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
213 cout << "An unknown error has occurred in the SharedRAbundVector class function push_front. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
218 /***********************************************************************/
219 void SharedRAbundVector::pop_back(){
221 return data.pop_back();
224 /***********************************************************************/
227 vector<individual>::reverse_iterator SharedRAbundVector::rbegin(){
228 return data.rbegin();
231 /***********************************************************************/
233 vector<individual>::reverse_iterator SharedRAbundVector::rend(){
237 /***********************************************************************/
238 void SharedRAbundVector::resize(int size){
243 /***********************************************************************/
245 int SharedRAbundVector::size(){
249 /***********************************************************************/
250 void SharedRAbundVector::print(ostream& output){
252 output << numBins << '\t';
254 for(int i=0;i<numBins;i++){ output << data[i].abundance << '\t'; }
257 catch(exception& e) {
258 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
262 cout << "An unknown error has occurred in the SharedRAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
266 /***********************************************************************/
267 string SharedRAbundVector::getGroup(){
271 /***********************************************************************/
273 void SharedRAbundVector::setGroup(string groupName){
276 /***********************************************************************/
277 int SharedRAbundVector::getGroupIndex() { return index; }
278 /***********************************************************************/
279 void SharedRAbundVector::setGroupIndex(int vIndex) { index = vIndex; }
280 /***********************************************************************/
281 int SharedRAbundVector::getNumBins(){
285 /***********************************************************************/
287 int SharedRAbundVector::getNumSeqs(){
291 /***********************************************************************/
293 int SharedRAbundVector::getMaxRank(){
296 /***********************************************************************/
298 SharedRAbundVector SharedRAbundVector::getSharedRAbundVector(){
301 /***********************************************************************/
303 RAbundVector SharedRAbundVector::getRAbundVector() {
305 RAbundVector rav(data.size());
307 for (int i = 0; i < data.size(); i++) {
308 rav.set(i, data[i].abundance);
313 catch(exception& e) {
314 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
318 cout << "An unknown error has occurred in the SharedRAbundVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
322 /***********************************************************************/
324 RAbundVector SharedRAbundVector::getRAbundVector2() {
327 for(int i = 0; i < numBins; i++)
328 if(data[i].abundance != 0)
329 rav.push_back(data[i].abundance-1);
332 catch(exception& e) {
333 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
337 cout << "An unknown error has occurred in the SharedRAbundVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
341 /***********************************************************************/
343 SharedSAbundVector SharedRAbundVector::getSharedSAbundVector(){
345 SharedSAbundVector sav(maxRank+1);
347 for(int i=0;i<data.size();i++){
348 int abund = data[i].abundance;
349 sav.set(abund, sav.getAbundance(abund) + 1, group);
352 sav.set(0, 0, group);
358 catch(exception& e) {
359 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getSharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
363 cout << "An unknown error has occurred in the SharedRAbundVector class function getSharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
367 /***********************************************************************/
369 SAbundVector SharedRAbundVector::getSAbundVector() {
371 SAbundVector sav(maxRank+1);
373 for(int i=0;i<data.size();i++){
374 int abund = data[i].abundance;
375 sav.set(abund, sav.get(abund) + 1);
381 catch(exception& e) {
382 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
386 cout << "An unknown error has occurred in the SharedRAbundVector class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
391 /***********************************************************************/
393 SharedOrderVector SharedRAbundVector::getSharedOrderVector() {
395 SharedOrderVector ov;
397 for(int i=0;i<data.size();i++){
398 for(int j=0;j<data[i].abundance;j++){
399 ov.push_back(data[i].bin, data[i].abundance, data[i].group);
402 random_shuffle(ov.begin(), ov.end());
407 catch(exception& e) {
408 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
412 cout << "An unknown error has occurred in the SharedRAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
416 /***********************************************************************/
418 OrderVector SharedRAbundVector::getOrderVector(map<string,int>* nameMap = NULL) {
422 for(int i=0;i<data.size();i++){
423 for(int j=0;j<data[i].abundance;j++){
427 random_shuffle(ov.begin(), ov.end());
432 catch(exception& e) {
433 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
437 cout << "An unknown error has occurred in the SharedRAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
442 /***********************************************************************/