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(){
245 numSeqs -= data[data.size()-1].abundance;
247 return data.pop_back();
250 /***********************************************************************/
253 vector<individual>::reverse_iterator SharedRAbundVector::rbegin(){
254 return data.rbegin();
257 /***********************************************************************/
259 vector<individual>::reverse_iterator SharedRAbundVector::rend(){
263 /***********************************************************************/
264 void SharedRAbundVector::resize(int size){
269 /***********************************************************************/
271 int SharedRAbundVector::size(){
275 /***********************************************************************/
276 void SharedRAbundVector::print(ostream& output){
278 output << numBins << '\t';
280 for(int i=0;i<data.size();i++){ output << data[i].abundance << '\t'; }
283 catch(exception& e) {
284 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
288 cout << "An unknown error has occurred in the SharedRAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
292 /***********************************************************************/
293 string SharedRAbundVector::getGroup(){
297 /***********************************************************************/
299 void SharedRAbundVector::setGroup(string groupName){
302 /***********************************************************************/
303 int SharedRAbundVector::getGroupIndex() { return index; }
304 /***********************************************************************/
305 void SharedRAbundVector::setGroupIndex(int vIndex) { index = vIndex; }
306 /***********************************************************************/
307 int SharedRAbundVector::getNumBins(){
311 /***********************************************************************/
313 int SharedRAbundVector::getNumSeqs(){
317 /***********************************************************************/
319 int SharedRAbundVector::getMaxRank(){
322 /***********************************************************************/
324 SharedRAbundVector SharedRAbundVector::getSharedRAbundVector(){
327 /***********************************************************************/
329 RAbundVector SharedRAbundVector::getRAbundVector() {
331 RAbundVector rav(data.size());
333 for (int i = 0; i < data.size(); i++) {
334 rav.set(i, data[i].abundance);
339 catch(exception& e) {
340 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
344 cout << "An unknown error has occurred in the SharedRAbundVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
348 /***********************************************************************/
350 RAbundVector SharedRAbundVector::getRAbundVector2() {
353 for(int i = 0; i < numBins; i++)
354 if(data[i].abundance != 0)
355 rav.push_back(data[i].abundance-1);
358 catch(exception& e) {
359 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
363 cout << "An unknown error has occurred in the SharedRAbundVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
367 /***********************************************************************/
369 SharedSAbundVector SharedRAbundVector::getSharedSAbundVector(){
371 SharedSAbundVector sav(maxRank+1);
373 for(int i=0;i<data.size();i++){
374 int abund = data[i].abundance;
375 sav.set(abund, sav.getAbundance(abund) + 1, group);
378 sav.set(0, 0, group);
384 catch(exception& e) {
385 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getSharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
389 cout << "An unknown error has occurred in the SharedRAbundVector class function getSharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
393 /***********************************************************************/
395 SAbundVector SharedRAbundVector::getSAbundVector() {
397 SAbundVector sav(maxRank+1);
399 for(int i=0;i<data.size();i++){
400 int abund = data[i].abundance;
401 sav.set(abund, sav.get(abund) + 1);
407 catch(exception& e) {
408 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
412 cout << "An unknown error has occurred in the SharedRAbundVector class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
417 /***********************************************************************/
419 SharedOrderVector SharedRAbundVector::getSharedOrderVector() {
421 SharedOrderVector ov;
423 for(int i=0;i<data.size();i++){
424 for(int j=0;j<data[i].abundance;j++){
425 ov.push_back(data[i].bin, data[i].abundance, data[i].group);
428 random_shuffle(ov.begin(), ov.end());
433 catch(exception& e) {
434 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
438 cout << "An unknown error has occurred in the SharedRAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
442 /***********************************************************************/
444 OrderVector SharedRAbundVector::getOrderVector(map<string,int>* nameMap = NULL) {
448 for(int i=0;i<data.size();i++){
449 for(int j=0;j<data[i].abundance;j++){
453 random_shuffle(ov.begin(), ov.end());
458 catch(exception& e) {
459 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
463 cout << "An unknown error has occurred in the SharedRAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
468 /***********************************************************************/