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 "sabundvector.hpp"
15 #include "ordervector.hpp"
18 /***********************************************************************/
20 SharedRAbundVector::SharedRAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0) {};
22 /***********************************************************************/
24 SharedRAbundVector::SharedRAbundVector(int n) : DataVector(), maxRank(0), numBins(n), numSeqs(0) {
27 for (int i=0; i< n; i++) {
30 data.push_back(newGuy);
34 /***********************************************************************
36 SharedRAbundVector::SharedRAbundVector(string id, vector<individual> rav) : DataVector(id), data(rav) {
42 for(int i=0;i<data.size();i++){
43 if(data[i].abundance != 0) { numBins = i+1; }
44 if(data[i].abundance > maxRank) { maxRank = data[i].abundance; }
45 numSeqs += data[i].abundance;
49 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function SharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
53 cout << "An unknown error has occurred in the SharedRAbundVector class function SharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
59 /***********************************************************************
62 SharedRAbundVector::SharedRAbundVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) {
65 string holdLabel, group
68 f >> label >> group >> num;
71 for (i=0; i<hold; i++) {
72 newGuy = new individual;
75 data.push_back(newGuy);
79 for(int i=0;i<hold;i++){
85 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function SharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
89 cout << "An unknown error has occurred in the SharedRAbundVector class function SharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
94 /***********************************************************************/
96 SharedRAbundVector::~SharedRAbundVector() {
100 /***********************************************************************/
102 void SharedRAbundVector::set(int binNumber, int newBinSize, string groupname){
104 int oldBinSize = data[binNumber].abundance;
105 data[binNumber].abundance = newBinSize;
106 data[binNumber].group = groupname;
108 if(newBinSize > maxRank) { maxRank = newBinSize; }
110 numSeqs += (newBinSize - oldBinSize);
112 catch(exception& e) {
113 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
117 cout << "An unknown error has occurred in the SharedRAbundVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
121 /***********************************************************************/
123 void SharedRAbundVector::setData(vector <individual> newData){
127 /***********************************************************************/
129 int SharedRAbundVector::getAbundance(int index){
130 return data[index].abundance;
133 /***********************************************************************/
135 int SharedRAbundVector::numNZ(){
137 for(int i = 1; i < numBins; i++)
138 if(data[i].abundance > 0)
142 /***********************************************************************/
144 void SharedRAbundVector::sortD(){
145 struct individual indObj;
146 sort(data.begin()+1, data.end(), indObj);
148 /***********************************************************************/
150 individual SharedRAbundVector::get(int index){
154 /***********************************************************************/
156 vector <individual> SharedRAbundVector::getData(){
159 /***********************************************************************/
161 void SharedRAbundVector::push_back(int binSize, int otu, string groupName){
164 newGuy.abundance = binSize;
165 newGuy.group = groupName;
168 data.push_back(newGuy);
171 if(binSize > maxRank){
177 catch(exception& e) {
178 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
182 cout << "An unknown error has occurred in the SharedRAbundVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
187 /***********************************************************************/
189 void SharedRAbundVector::insert(int binSize, int otu, string groupName){
192 newGuy.abundance = binSize;
193 newGuy.group = groupName;
196 data.insert(data.begin()+otu, newGuy);
199 if(binSize > maxRank){
205 catch(exception& e) {
206 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function insert. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
210 cout << "An unknown error has occurred in the SharedRAbundVector class function insert. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
215 /***********************************************************************/
217 void SharedRAbundVector::push_front(int binSize, int otu, string groupName){
220 newGuy.abundance = binSize;
221 newGuy.group = groupName;
224 data.insert(data.begin(), newGuy);
227 if(binSize > maxRank){
233 catch(exception& e) {
234 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function push_front. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
238 cout << "An unknown error has occurred in the SharedRAbundVector class function push_front. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
243 /***********************************************************************/
244 void SharedRAbundVector::pop_back(){
246 return data.pop_back();
249 /***********************************************************************/
252 vector<individual>::reverse_iterator SharedRAbundVector::rbegin(){
253 return data.rbegin();
256 /***********************************************************************/
258 vector<individual>::reverse_iterator SharedRAbundVector::rend(){
262 /***********************************************************************/
263 void SharedRAbundVector::resize(int size){
268 /***********************************************************************/
270 int SharedRAbundVector::size(){
274 /***********************************************************************/
275 void SharedRAbundVector::print(ostream& output){
277 output << numBins << '\t';
279 for(int i=0;i<numBins;i++){ output << data[i].abundance << '\t'; }
282 catch(exception& e) {
283 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
287 cout << "An unknown error has occurred in the SharedRAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
291 /***********************************************************************/
292 string SharedRAbundVector::getGroup(){
296 /***********************************************************************/
298 void SharedRAbundVector::setGroup(string groupName){
301 /***********************************************************************/
302 int SharedRAbundVector::getGroupIndex() { return index; }
303 /***********************************************************************/
304 void SharedRAbundVector::setGroupIndex(int vIndex) { index = vIndex; }
305 /***********************************************************************/
306 int SharedRAbundVector::getNumBins(){
310 /***********************************************************************/
312 int SharedRAbundVector::getNumSeqs(){
316 /***********************************************************************/
318 int SharedRAbundVector::getMaxRank(){
321 /***********************************************************************/
323 SharedRAbundVector SharedRAbundVector::getSharedRAbundVector(){
326 /***********************************************************************/
328 RAbundVector SharedRAbundVector::getRAbundVector() {
330 RAbundVector rav(data.size());
332 for (int i = 0; i < data.size(); i++) {
333 rav.set(i, data[i].abundance);
338 catch(exception& e) {
339 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
343 cout << "An unknown error has occurred in the SharedRAbundVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
347 /***********************************************************************/
349 RAbundVector SharedRAbundVector::getRAbundVector2() {
352 for(int i = 0; i < numBins; i++)
353 if(data[i].abundance != 0)
354 rav.push_back(data[i].abundance-1);
357 catch(exception& e) {
358 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
362 cout << "An unknown error has occurred in the SharedRAbundVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
366 /***********************************************************************/
368 SharedSAbundVector SharedRAbundVector::getSharedSAbundVector(){
370 SharedSAbundVector sav(maxRank+1);
372 for(int i=0;i<data.size();i++){
373 int abund = data[i].abundance;
374 sav.set(abund, sav.getAbundance(abund) + 1, group);
377 sav.set(0, 0, group);
383 catch(exception& e) {
384 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getSharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
388 cout << "An unknown error has occurred in the SharedRAbundVector class function getSharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
392 /***********************************************************************/
394 SAbundVector SharedRAbundVector::getSAbundVector() {
396 SAbundVector sav(maxRank+1);
398 for(int i=0;i<data.size();i++){
399 int abund = data[i].abundance;
400 sav.set(abund, sav.get(abund) + 1);
406 catch(exception& e) {
407 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
411 cout << "An unknown error has occurred in the SharedRAbundVector class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
416 /***********************************************************************/
418 SharedOrderVector SharedRAbundVector::getSharedOrderVector() {
420 SharedOrderVector ov;
422 for(int i=0;i<data.size();i++){
423 for(int j=0;j<data[i].abundance;j++){
424 ov.push_back(data[i].bin, data[i].abundance, data[i].group);
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";
441 /***********************************************************************/
443 OrderVector SharedRAbundVector::getOrderVector(map<string,int>* nameMap = NULL) {
447 for(int i=0;i<data.size();i++){
448 for(int j=0;j<data[i].abundance;j++){
452 random_shuffle(ov.begin(), ov.end());
457 catch(exception& e) {
458 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
462 cout << "An unknown error has occurred in the SharedRAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
467 /***********************************************************************/