]> git.donarmstrong.com Git - mothur.git/blobdiff - sharedrabundvector.cpp
started shared utilities, updates to venn and heatmap added tree.groups command
[mothur.git] / sharedrabundvector.cpp
index 6bdeed0753e767de6616930a6cdc560c6e0f2610..4683c59b63050de20e6bb79e2103563478066a71 100644 (file)
 using namespace std;
 
 #include "sharedrabundvector.h" 
-#include "datavector.hpp"
-#include "utilities.hpp"
-#include <exception>
-#include "sharedrabundvector.h"
 #include "sabundvector.hpp"
 #include "ordervector.hpp"
 
@@ -65,10 +61,11 @@ SharedRAbundVector::SharedRAbundVector(string id, vector<individual> rav) : Data
 
 SharedRAbundVector::SharedRAbundVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) {
        try {
-               int i, hold;
+               int i, num;
+               string holdLabel, group
                individual newGuy;
                
-               f >> label >> hold;
+               f >> label >> group >> num;
                
                //initialize data
                for (i=0; i<hold; i++) {
@@ -121,6 +118,11 @@ void SharedRAbundVector::set(int binNumber, int newBinSize, string groupname){
                exit(1);
        }
 }
+/***********************************************************************/
+
+void SharedRAbundVector::setData(vector <individual> newData){
+       data = newData;
+}
 
 /***********************************************************************/
 
@@ -128,14 +130,32 @@ int SharedRAbundVector::getAbundance(int index){
        return data[index].abundance;
        
 }
+/***********************************************************************/
+
+int SharedRAbundVector::numNZ(){
+       int sum = 0;
+       for(int i = 1; i < numBins; i++)
+               if(data[i].abundance > 0)
+                       sum++;
+       return sum;
+}
+/***********************************************************************/
 
+void SharedRAbundVector::sortD(){
+       struct individual indObj;
+       sort(data.begin()+1, data.end(), indObj);
+}
 /***********************************************************************/
 
 individual SharedRAbundVector::get(int index){
        return data[index];
        
 }
+/***********************************************************************/
 
+vector <individual> SharedRAbundVector::getData(){
+       return data;
+}
 /***********************************************************************/
 
 void SharedRAbundVector::push_back(int binSize, int otu, string groupName){
@@ -166,6 +186,61 @@ void SharedRAbundVector::push_back(int binSize, int otu, string groupName){
 
 /***********************************************************************/
 
+void SharedRAbundVector::insert(int binSize, int otu, string groupName){
+       try {
+               individual newGuy;
+               newGuy.abundance = binSize;
+               newGuy.group = groupName;
+               newGuy.bin = otu;
+               
+               data.insert(data.begin()+otu, newGuy);
+               numBins++;
+       
+               if(binSize > maxRank){
+                       maxRank = binSize;
+               }
+       
+               numSeqs += binSize;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function insert. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedRAbundVector class function insert. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+void SharedRAbundVector::push_front(int binSize, int otu, string groupName){
+       try {
+               individual newGuy;
+               newGuy.abundance = binSize;
+               newGuy.group = groupName;
+               newGuy.bin = otu;
+               
+               data.insert(data.begin(), newGuy);
+               numBins++;
+       
+               if(binSize > maxRank){
+                       maxRank = binSize;
+               }
+       
+               numSeqs += binSize;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function push_front. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedRAbundVector class function push_front. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
 void SharedRAbundVector::pop_back(){
 
        return data.pop_back();
@@ -223,8 +298,10 @@ string SharedRAbundVector::getGroup(){
 void SharedRAbundVector::setGroup(string groupName){
        group = groupName;
 }
-
-
+/***********************************************************************/
+int SharedRAbundVector::getGroupIndex()  { return index; }
+/***********************************************************************/
+void SharedRAbundVector::setGroupIndex(int vIndex)     { index = vIndex; }
 /***********************************************************************/
 int SharedRAbundVector::getNumBins(){
        return numBins;
@@ -241,13 +318,77 @@ int SharedRAbundVector::getNumSeqs(){
 int SharedRAbundVector::getMaxRank(){
        return maxRank;
 }
-
 /***********************************************************************/
 
 SharedRAbundVector SharedRAbundVector::getSharedRAbundVector(){
        return *this;                   
 }
+/***********************************************************************/
+
+RAbundVector SharedRAbundVector::getRAbundVector() {
+       try {
+               RAbundVector rav(data.size());
+               
+               for (int i = 0; i < data.size(); i++) {
+                       rav.set(i, data[i].abundance);
+               }
+       
+               return rav;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedRAbundVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+/***********************************************************************/
+
+RAbundVector SharedRAbundVector::getRAbundVector2() {
+       try {
+               RAbundVector rav;
+               for(int i = 0; i < numBins; i++)
+                       if(data[i].abundance != 0)
+                               rav.push_back(data[i].abundance-1);
+               return rav;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedRAbundVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+/***********************************************************************/
 
+SharedSAbundVector SharedRAbundVector::getSharedSAbundVector(){
+       try {
+               SharedSAbundVector sav(maxRank+1);
+               
+               for(int i=0;i<data.size();i++){
+                       int abund = data[i].abundance;
+                       sav.set(abund, sav.getAbundance(abund) + 1, group);
+               }
+               
+               sav.set(0, 0, group);
+               sav.setLabel(label);
+               sav.setGroup(group);
+               
+               return sav;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getSharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedRAbundVector class function getSharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
 /***********************************************************************/
 
 SAbundVector SharedRAbundVector::getSAbundVector() {