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";
189 /***********************************************************************/
191 void SharedRAbundVector::pop_back(){
193 return data.pop_back();
196 /***********************************************************************/
199 vector<individual>::reverse_iterator SharedRAbundVector::rbegin(){
200 return data.rbegin();
203 /***********************************************************************/
205 vector<individual>::reverse_iterator SharedRAbundVector::rend(){
209 /***********************************************************************/
210 void SharedRAbundVector::resize(int size){
215 /***********************************************************************/
217 int SharedRAbundVector::size(){
221 /***********************************************************************/
222 void SharedRAbundVector::print(ostream& output){
224 output << numBins << '\t';
226 for(int i=0;i<numBins;i++){ output << data[i].abundance << '\t'; }
229 catch(exception& e) {
230 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
234 cout << "An unknown error has occurred in the SharedRAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
238 /***********************************************************************/
239 string SharedRAbundVector::getGroup(){
243 /***********************************************************************/
245 void SharedRAbundVector::setGroup(string groupName){
248 /***********************************************************************/
249 int SharedRAbundVector::getGroupIndex() { return index; }
250 /***********************************************************************/
251 void SharedRAbundVector::setGroupIndex(int vIndex) { index = vIndex; }
252 /***********************************************************************/
253 int SharedRAbundVector::getNumBins(){
257 /***********************************************************************/
259 int SharedRAbundVector::getNumSeqs(){
263 /***********************************************************************/
265 int SharedRAbundVector::getMaxRank(){
268 /***********************************************************************/
270 SharedRAbundVector SharedRAbundVector::getSharedRAbundVector(){
273 /***********************************************************************/
275 RAbundVector SharedRAbundVector::getRAbundVector() {
277 RAbundVector rav(data.size());
279 for (int i = 0; i < data.size(); i++) {
280 rav.set(i, data[i].abundance);
285 catch(exception& e) {
286 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
290 cout << "An unknown error has occurred in the SharedRAbundVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
294 /***********************************************************************/
296 RAbundVector SharedRAbundVector::getRAbundVector2() {
299 for(int i = 0; i < numBins; i++)
300 if(data[i].abundance != 0)
301 rav.push_back(data[i].abundance-1);
304 catch(exception& e) {
305 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
309 cout << "An unknown error has occurred in the SharedRAbundVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
313 /***********************************************************************/
315 SharedSAbundVector SharedRAbundVector::getSharedSAbundVector(){
317 SharedSAbundVector sav(maxRank+1);
319 for(int i=0;i<data.size();i++){
320 int abund = data[i].abundance;
321 sav.set(abund, sav.getAbundance(abund) + 1, group);
324 sav.set(0, 0, group);
330 catch(exception& e) {
331 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getSharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
335 cout << "An unknown error has occurred in the SharedRAbundVector class function getSharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
339 /***********************************************************************/
341 SAbundVector SharedRAbundVector::getSAbundVector() {
343 SAbundVector sav(maxRank+1);
345 for(int i=0;i<data.size();i++){
346 int abund = data[i].abundance;
347 sav.set(abund, sav.get(abund) + 1);
353 catch(exception& e) {
354 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
358 cout << "An unknown error has occurred in the SharedRAbundVector class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
363 /***********************************************************************/
365 SharedOrderVector SharedRAbundVector::getSharedOrderVector() {
367 SharedOrderVector ov;
369 for(int i=0;i<data.size();i++){
370 for(int j=0;j<data[i].abundance;j++){
371 ov.push_back(data[i].bin, data[i].abundance, data[i].group);
374 random_shuffle(ov.begin(), ov.end());
379 catch(exception& e) {
380 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
384 cout << "An unknown error has occurred in the SharedRAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
388 /***********************************************************************/
390 OrderVector SharedRAbundVector::getOrderVector(map<string,int>* nameMap = NULL) {
394 for(int i=0;i<data.size();i++){
395 for(int j=0;j<data[i].abundance;j++){
399 random_shuffle(ov.begin(), ov.end());
404 catch(exception& e) {
405 cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
409 cout << "An unknown error has occurred in the SharedRAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
414 /***********************************************************************/