2 * sharedSharedSAbundVector.cpp
5 * Created by Sarah Westcott on 12/10/08.
6 * Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "sharedsabundvector.h"
11 #include "sabundvector.hpp"
14 /***********************************************************************/
16 SharedSAbundVector::SharedSAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){ }
18 /***********************************************************************/
20 SharedSAbundVector::SharedSAbundVector(int size) : DataVector(), maxRank(0), numBins(0), numSeqs(0) {
23 for (int i=0; i< size; i++) {
26 data.push_back(newGuy);
30 /***********************************************************************/
32 void SharedSAbundVector::set(int bin, int abundance, string groupName){
35 int initSize = data[bin].abundance;
36 data[bin].abundance = abundance;
37 data[bin].group = groupName;
40 numBins += (abundance - initSize);
43 numSeqs += bin * (abundance - initSize);
45 if(bin > maxRank) { maxRank = bin; }
48 m->errorOut(e, "SharedSAbundVector", "set");
53 /***********************************************************************/
55 individual SharedSAbundVector::get(int index){
58 /***********************************************************************/
60 int SharedSAbundVector::getAbundance(int index){
61 return data[index].abundance;
64 /***********************************************************************/
66 void SharedSAbundVector::push_back(int abundance, int bin, string groupName){
69 newGuy.abundance = abundance;
71 newGuy.group = groupName;
73 data.push_back(newGuy);
79 numSeqs += (maxRank * abundance);
82 m->errorOut(e, "SharedSAbundVector", "push_back");
87 /***********************************************************************/
89 void SharedSAbundVector::resize(int size){
93 /***********************************************************************/
95 int SharedSAbundVector::size(){
99 /***********************************************************************/
100 void SharedSAbundVector::print(ostream& output){
102 output << label << '\t' << maxRank << '\t';
104 for(int i=1;i<=maxRank;i++){
105 output << data[i].abundance << '\t';
109 catch(exception& e) {
110 m->errorOut(e, "SharedSAbundVector", "print");
114 /***********************************************************************/
115 string SharedSAbundVector::getGroup(){
119 /***********************************************************************/
121 void SharedSAbundVector::setGroup(string groupName){
125 /**********************************************************************/
126 int SharedSAbundVector::getNumBins(){
130 /***********************************************************************/
132 int SharedSAbundVector::getNumSeqs(){
136 /***********************************************************************/
138 int SharedSAbundVector::getMaxRank(){
141 /***********************************************************************/
142 RAbundVector SharedSAbundVector::getRAbundVector(){
146 for(int i=1;i<data.size();i++){
147 for(int j=0;j<data[i].abundance;j++){
151 sort(rav.rbegin(), rav.rend());
156 catch(exception& e) {
157 m->errorOut(e, "SharedSAbundVector", "getRAbundVector");
161 /***********************************************************************/
162 SAbundVector SharedSAbundVector::getSAbundVector(){
167 rav = getRAbundVector();
168 sav = rav.getSAbundVector();
172 catch(exception& e) {
173 m->errorOut(e, "SharedSAbundVector", "getSAbundVector");
178 /***********************************************************************/
180 bool compareMembers (individual member, individual member2){
182 if(member.abundance < member2.abundance){
189 /***********************************************************************/
190 SharedRAbundVector SharedSAbundVector::getSharedRAbundVector(){
192 SharedRAbundVector rav;
194 for(int i=1;i<data.size();i++){
195 for(int j=0;j<data[i].abundance;j++){
196 rav.push_back(i, data[i].group);
199 sort(rav.rbegin(), rav.rend(), compareMembers);
206 catch(exception& e) {
207 m->errorOut(e, "SharedSAbundVector", "getSharedRAbundVector");
213 /***********************************************************************/
215 SharedSAbundVector SharedSAbundVector::getSharedSAbundVector(){
219 /***********************************************************************/
220 SharedOrderVector SharedSAbundVector::getSharedOrderVector() {
222 SharedRAbundVector rav;
223 SharedOrderVector ov;
225 rav = this->getSharedRAbundVector();
226 ov = rav.getSharedOrderVector();
232 catch(exception& e) {
233 m->errorOut(e, "SharedSAbundVector", "getSharedOrderVector");
237 /***********************************************************************/
239 void SharedSAbundVector::clear(){
246 /***********************************************************************/
247 OrderVector SharedSAbundVector::getOrderVector(map<string,int>* hold = NULL){
253 for(int i=1;i<data.size();i++){
254 for(int j=0;j<data[i].abundance;j++){
255 for(int k=0;k<i;k++){
256 ov.push_back(binIndex);
262 random_shuffle(ov.begin(), ov.end());
268 catch(exception& e) {
269 m->errorOut(e, "SharedSAbundVector", "getOrderVector");
274 /***********************************************************************/