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 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 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 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 errorOut(e, "SharedSAbundVector", "getRAbundVector");
161 /***********************************************************************/
162 SAbundVector SharedSAbundVector::getSAbundVector(){
167 rav = getRAbundVector();
168 sav = rav.getSAbundVector();
172 catch(exception& e) {
173 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;
195 for(int i=1;i<=data.size();i++){
196 for(int j=0;j<data[i].abundance;j++){
197 rav.push_back(i, binNumber, data[i].group);
201 sort(rav.rbegin(), rav.rend(), compareMembers);
208 catch(exception& e) {
209 errorOut(e, "SharedSAbundVector", "getSharedRAbundVector");
215 /***********************************************************************/
217 SharedSAbundVector SharedSAbundVector::getSharedSAbundVector(){
221 /***********************************************************************/
222 SharedOrderVector SharedSAbundVector::getSharedOrderVector() {
224 SharedRAbundVector rav;
225 SharedOrderVector ov;
227 rav = this->getSharedRAbundVector();
228 ov = rav.getSharedOrderVector();
234 catch(exception& e) {
235 errorOut(e, "SharedSAbundVector", "getSharedOrderVector");
239 /***********************************************************************/
240 OrderVector SharedSAbundVector::getOrderVector(map<string,int>* hold = NULL){
246 for(int i=1;i<data.size();i++){
247 for(int j=0;j<data[i].abundance;j++){
248 for(int k=0;k<i;k++){
249 ov.push_back(binIndex);
255 random_shuffle(ov.begin(), ov.end());
261 catch(exception& e) {
262 errorOut(e, "SharedSAbundVector", "getOrderVector");
267 /***********************************************************************/