]> git.donarmstrong.com Git - mothur.git/commitdiff
changed heatmap and venn command to use vector of sharedrabunds instead of order...
authorwestcott <westcott>
Wed, 22 Apr 2009 15:47:04 +0000 (15:47 +0000)
committerwestcott <westcott>
Wed, 22 Apr 2009 15:47:04 +0000 (15:47 +0000)
20 files changed:
datavector.hpp
globaldata.hpp
heatmap.cpp
heatmap.h
heatmapcommand.cpp
heatmapcommand.h
inputdata.cpp
inputdata.h
readotu.cpp
readotu.h
sharedlistvector.cpp
sharedlistvector.h
sharedordervector.cpp
sharedordervector.h
sharedutilities.cpp
sharedutilities.h
venn.cpp
venn.h
venncommand.cpp
venncommand.h

index 73058a992a53e3da313cae4ca595c77797058e94..18ac6958e09b64f209a39ff51098406021f5022b 100644 (file)
@@ -37,7 +37,7 @@ public:
        void setLabel(string l)         {       label = l;                      }
        string getLabel()                       {       return label;           }
 
-       //virtual RAbundVector getRAbundVector() = 0;
+       virtual RAbundVector getRAbundVector() = 0;
        virtual SAbundVector getSAbundVector() = 0;
        virtual OrderVector getOrderVector(map<string,int>* hold = NULL) = 0;
        
index be5b0087abdb7ee546e3d9f081a9091c95ee2b8c..cc13bae137577dc28e554c39d9088725114740f3 100644 (file)
@@ -35,6 +35,7 @@ public:
        vector<Tree*> gTree;
        SharedListVector* gSharedList;
        SAbundVector* sabund;
+       RAbundVector* rabund;
        GroupMap* gGroupmap;
        FullMatrix* gMatrix;
        TreeMap* gTreemap;
index 187c953fcaf49501f9985d669cfd7645d7294355..0b1a80e6e9dca67a794653ce171d1b4011287b4a 100644 (file)
@@ -15,8 +15,6 @@ HeatMap::HeatMap(){
                globaldata = GlobalData::getInstance();
                format = globaldata->getFormat();
                sorted = globaldata->getSorted();
-               util = new SharedUtil();
-               
        }
        catch(exception& e) {
                cout << "Standard Error: " << e.what() << " has occurred in the HeatMap class Function HeatMap. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
@@ -30,29 +28,26 @@ HeatMap::HeatMap(){
 
 //**********************************************************************************************************************
 
-void HeatMap::getPic(OrderVector* order) {
+void HeatMap::getPic(RAbundVector* rabund) {
        try {
-               
-               RAbundVector rabund = order->getRAbundVector();
-               
                //get users scaling method
                scaler = globaldata->getScale();
                
                float maxRelAbund = 0.0;                
                
-               for(int i=0;i<rabund.size();i++){                               
-                       float relAbund = rabund.get(i) / (float)rabund.getNumSeqs();
+               for(int i=0;i<rabund->size();i++){                              
+                       float relAbund = rabund->get(i) / (float)rabund->getNumSeqs();
                        if(relAbund > maxRelAbund){     maxRelAbund = relAbund; }
                }
                
                scaler = globaldata->getScale();
                
-               vector<string> scaleRelAbund(rabund.size(), "");
+               vector<string> scaleRelAbund(rabund->size(), "");
                
-               for(int i=0;i<rabund.size();i++){
-                       float relAbund = rabund.get(i) / (float)rabund.getNumSeqs();
+               for(int i=0;i<rabund->size();i++){
+                       float relAbund = rabund->get(i) / (float)rabund->getNumSeqs();
                        
-                       if (rabund.get(i) != 0) { //don't want log value of 0.
+                       if (rabund->get(i) != 0) { //don't want log value of 0.
                                if (scaler == "log10") {
                                        scaleRelAbund[i] = toHex(int(255 * log10(relAbund) / log10(maxRelAbund))) + "0000";  
                                }else if (scaler == "log2") {
@@ -67,21 +62,21 @@ void HeatMap::getPic(OrderVector* order) {
                }
                
                
-               string filenamesvg = getRootName(globaldata->inputFileName) + rabund.getLabel() + ".heatmap.svg";
+               string filenamesvg = getRootName(globaldata->inputFileName) + rabund->getLabel() + ".heatmap.svg";
                openOutputFile(filenamesvg, outsvg);
                
                //svg image
-               outsvg << "<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 " + toString(300) + " " + toString((rabund.getNumBins()*5 + 120))  + "\">\n";
+               outsvg << "<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 " + toString(300) + " " + toString((rabund->getNumBins()*5 + 120))  + "\">\n";
                outsvg << "<g>\n";
                
                //white backround
-               outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" + toString(300) + "\" height=\"" + toString((rabund.getNumBins()*5 + 120))  + "\"/>"; 
-               outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString((150) - 40) + "\" y=\"25\">Heatmap at distance " + rabund.getLabel() + "</text>\n";
+               outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" + toString(300) + "\" height=\"" + toString((rabund->getNumBins()*5 + 120))  + "\"/>"; 
+               outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString((150) - 40) + "\" y=\"25\">Heatmap at distance " + rabund->getLabel() + "</text>\n";
                                
                //output legend and color labels
                string color;
                int x = 0;
-               int y = 103 + (rabund.getNumBins()*5);
+               int y = 103 + (rabund->getNumBins()*5);
                printLegend(y, maxRelAbund);
                
                y = 70;
@@ -108,14 +103,9 @@ void HeatMap::getPic(OrderVector* order) {
 
 //**********************************************************************************************************************
 
-void HeatMap::getPic(SharedOrderVector* sharedorder) {
+void HeatMap::getPic(vector<SharedRAbundVector*> lookup) {
        try {
                
-               //fills vector of sharedsabunds - lookup
-               vector<SharedRAbundVector*> lookup;
-
-               util->getSharedVectors(globaldata->Groups, lookup, sharedorder);  //fills group vectors from order vector.
-               
                //sort lookup so shared bins are on top
                if (sorted == "T") {  sortSharedVectors(lookup);  }
                
@@ -155,7 +145,7 @@ void HeatMap::getPic(SharedOrderVector* sharedorder) {
                        }
                }
                
-               string filenamesvg = getRootName(globaldata->inputFileName) + sharedorder->getLabel() + ".heatmap.svg";
+               string filenamesvg = getRootName(globaldata->inputFileName) + lookup[0]->getLabel() + ".heatmap.svg";
                openOutputFile(filenamesvg, outsvg);
                
                //svg image
@@ -164,7 +154,7 @@ void HeatMap::getPic(SharedOrderVector* sharedorder) {
                
                //white backround
                outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" + toString(lookup.size() * 300) + "\" height=\"" + toString((lookup[0]->getNumBins()*5 + 120))  + "\"/>"; 
-               outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString((lookup.size() * 150) - 40) + "\" y=\"25\">Heatmap at distance " + sharedorder->getLabel() + "</text>\n";
+               outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString((lookup.size() * 150) - 40) + "\" y=\"25\">Heatmap at distance " + lookup[0]->getLabel() + "</text>\n";
                
                //column labels
                for (int h = 0; h < lookup.size(); h++) {
@@ -309,7 +299,7 @@ void HeatMap::printLegend(int y, float maxbin) {
                        else if(scaler== "log2")        {       label = maxbin * log2(51*i) / log2(255);        }
                        else if(scaler== "linear")      {       label = maxbin * 51 * i / 255;                          }
                        else                                            {       label = maxbin * log10(51*i) / log10(255);      }
-                       
+                       file://localhost/Users/westcott/Desktop/c.amazon.fn.0.19.rep.fasta
                        label = int(label * 1000 + 0.5);
                        label /= 1000.0;
                        string text = toString(label, 3);
index 528c96416211a223e710467dd6baeb4cdb063c8f..29b6b9af302cf24b079f153eb75f993e0e83be21 100644 (file)
--- a/heatmap.h
+++ b/heatmap.h
 
 using namespace std;
 
-#include "ordervector.hpp"
 #include "rabundvector.hpp"
 #include "sharedrabundvector.h"
-#include "sharedordervector.h"
 #include "datavector.hpp"
 #include "globaldata.hpp"
-#include "sharedutilities.h"
 
 /***********************************************************************/
 
@@ -25,17 +22,16 @@ class HeatMap {
        
        public:
                HeatMap();
-               ~HeatMap(){ delete util; };
+               ~HeatMap(){};
        
-               void getPic(OrderVector*);
-               void getPic(SharedOrderVector*);
+               void getPic(RAbundVector*);
+               void getPic(vector<SharedRAbundVector*>);
 
        private:
                void sortSharedVectors(vector<SharedRAbundVector*>& );
                void printLegend(int, float);
 
                GlobalData* globaldata;
-               SharedUtil* util;
                string format, sorted, groupComb, scaler;
                ofstream outsvg;
                        
@@ -47,3 +43,4 @@ class HeatMap {
 
 
 
+
index b8b38207277789ae9181e688f5a648e96ffe337c..be25f091516022e5a6414184c7ecb58518e60a94 100644 (file)
@@ -17,8 +17,6 @@ HeatMapCommand::HeatMapCommand(){
                globaldata = GlobalData::getInstance();
                heatmap = new HeatMap();
                format = globaldata->getFormat();
-               util = new SharedUtil();
-               
        }
        catch(exception& e) {
                cout << "Standard Error: " << e.what() << " has occurred in the HeatMapCommand class Function HeatMapCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
@@ -35,7 +33,6 @@ HeatMapCommand::~HeatMapCommand(){
        delete input;
        delete read;
        delete heatmap;
-       delete util;
 }
 
 //**********************************************************************************************************************
@@ -50,7 +47,7 @@ int HeatMapCommand::execute(){
                        read->read(&*globaldata); 
                        
                        input = globaldata->ginput;
-                       order = input->getSharedOrderVector();
+                       lookup = input->getSharedRAbundVectors();
                }else if (format == "shared") {
                        //you are using a list and a groupfile
                        read = new ReadOTUFile(globaldata->inputFileName);      
@@ -58,43 +55,28 @@ int HeatMapCommand::execute(){
                
                        input = globaldata->ginput;
                        SharedList = globaldata->gSharedList;
-                       order = SharedList->getSharedOrderVector();
+                       lookup = SharedList->getSharedRAbundVector();
                }else if (format == "list") {
                        //you are using just a list file and have only one group
                        read = new ReadOTUFile(globaldata->inputFileName);      
                        read->read(&*globaldata); 
                        
-                       ordersingle = globaldata->gorder;
-                       input = globaldata->ginput;
+                       rabund = globaldata->rabund;
+                       input = globaldata->ginput;             
                }
                
                if (format != "list") { 
                
-                       util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "heat");
-                       globaldata->setGroups("");
-
-
-                       while(order != NULL){
+                       while(lookup[0] != NULL){
                
-                               if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){                       
+                               if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(lookup[0]->getLabel()) == 1){                   
        
-                                       cout << order->getLabel() << '\t' << count << endl;
-                                       heatmap->getPic(order);
-
+                                       cout << lookup[0]->getLabel() << '\t' << count << endl;
+                                       heatmap->getPic(lookup);
                                }
                                                
                                //get next line to process
-                               if (format == "sharedfile") {
-                                       order = input->getSharedOrderVector();
-                               }else {
-                                       //you are using a list and a groupfile
-                                       SharedList = input->getSharedListVector(); //get new list vector to process
-                                       if (SharedList != NULL) {
-                                               order = SharedList->getSharedOrderVector(); //gets new order vector with group info.
-                                       }else {
-                                               break;
-                                       }
-                               }
+                               lookup = input->getSharedRAbundVectors();                               
                                count++;
                        }
                        
@@ -102,20 +84,21 @@ int HeatMapCommand::execute(){
                        globaldata->Groups.clear();  
                        
                }else{
-                       while(ordersingle != NULL){
                
-                               if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(ordersingle->getLabel()) == 1){                 
+                       while(rabund != NULL){
+               
+                               if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(rabund->getLabel()) == 1){                      
        
-                                       cout << ordersingle->getLabel() << '\t' << count << endl;
-                                       heatmap->getPic(ordersingle);
-                                       
+                                       cout << rabund->getLabel() << '\t' << count << endl;
+                                       heatmap->getPic(rabund);
                                }
                                
-                               ordersingle = (input->getOrderVector());
+                               rabund = input->getRAbundVector();
                                count++;
                        }
                }
                
+               globaldata->setGroups("");
                return 0;
        }
        catch(exception& e) {
index edb346021ec9effb6669029e7835be3d98e93e41..fc50554c601c3c897f949775de7743c94cf33c9a 100644 (file)
 #include "readotu.h"
 #include "sharedlistvector.h"
 #include "heatmap.h"
-#include "sharedutilities.h"
-
+#include "rabundvector.hpp"
 
 class GlobalData;
 
-
 class HeatMapCommand : public Command {
 
 public:
@@ -32,11 +30,10 @@ public:
 private:
        GlobalData* globaldata;
        ReadOTUFile* read;
-       SharedUtil* util;
        InputData* input;
        SharedListVector* SharedList;
-       SharedOrderVector* order;
-       OrderVector* ordersingle;
+       RAbundVector* rabund;
+       vector<SharedRAbundVector*> lookup;
        HeatMap* heatmap;
        string format;
 
index c8259d90850c7d1c9f0ca0e2ba3a8f763e52f2e6..2c249e6a4a42b89a93b48a4252c60613f40fae9f 100644 (file)
@@ -10,6 +10,7 @@
 #include "inputdata.h"
 #include "ordervector.hpp"
 #include "listvector.hpp"
+#include "rabundvector.hpp"
 
 /***********************************************************************/
 
@@ -181,6 +182,39 @@ OrderVector* InputData::getOrderVector(){
                exit(1);
        }       
 }
+/***********************************************************************/
+
+vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(){
+       try {
+               if(fileHandle){
+                       if (format == "sharedfile")  {
+                               SharedOrder = new SharedOrderVector(fileHandle);
+                               if (SharedOrder != NULL) {
+                                       return SharedOrder->getSharedRAbundVector();
+                               }
+                       }else if (format == "shared") {
+                               SharedList = new SharedListVector(fileHandle);
+                               if (SharedList != NULL) {
+                                       return SharedList->getSharedRAbundVector();
+                               }
+                       }
+                       gobble(fileHandle);
+               }
+                               
+               //this is created to signal to calling function that the input file is at eof
+               vector<SharedRAbundVector*> null;  null.push_back(NULL);
+               return null;
+               
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSharedRAbundVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the InputData class function getSharedRAbundVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
 
 /***********************************************************************/
 
@@ -225,3 +259,46 @@ SAbundVector* InputData::getSAbundVector(){
 }
 
 /***********************************************************************/
+RAbundVector* InputData::getRAbundVector(){
+       try {
+               if(fileHandle){
+                       if (format == "list") {
+                               input = new ListVector(fileHandle);
+                       }
+                       else if (format == "shared")  {
+                               input = new SharedListVector(fileHandle);
+                       }
+                       else if(format == "rabund"){
+                               input = new RAbundVector(fileHandle);
+                       }
+                       else if(format == "order"){                     
+                               input = new OrderVector(fileHandle);
+                       }
+                       else if(format == "sabund"){
+                               input = new SAbundVector(fileHandle);
+                       }
+                                       
+                       gobble(fileHandle);
+
+                       rabund = new RAbundVector();
+                       *rabund = (input->getRAbundVector());
+
+                       return rabund;
+               }
+               else{
+                       return NULL;
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the InputData class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+
+
+
index 1352e94c760469b071a3b56363c932f3be901004..f21daec045d67d9bf710ee6dce5e26ab018e1d51 100644 (file)
@@ -21,6 +21,8 @@ public:
        OrderVector* getOrderVector();
        SharedOrderVector* getSharedOrderVector();
        SAbundVector* getSAbundVector();
+       RAbundVector* getRAbundVector();
+       vector<SharedRAbundVector*> getSharedRAbundVectors();
        
 private:
        string format;
@@ -31,6 +33,7 @@ private:
        OrderVector* output;
        SharedOrderVector* SharedOrder;
        SAbundVector* sabund;
+       RAbundVector* rabund;
        map<string,int> orderMap;
 };
 
index 0bcfd320cade47901ac89cbf9e86c7b8ad142b29..971ed31ae005e15b3ec0785a9728311ef6ca12f8 100644 (file)
@@ -26,6 +26,7 @@ void ReadOTUFile::read(GlobalData* globaldata){
                        input = new InputData(philFile, globaldata->getFormat()); //format tells you whether philFile is list, rabund, sabund.
                        inputList = new InputData(philFile, globaldata->getFormat()); //format tells you whether philFile is list, rabund, sabund.
                        inputSabund = new InputData(philFile, globaldata->getFormat()); //format tells you whether philFile is list, rabund, sabund or shared.
+                       inputRabund = new InputData(philFile, globaldata->getFormat());
                }else {//there is an orderfile
                        input = new InputData(philFile, globaldata->getOrderFile(), globaldata->getFormat());
                }
@@ -41,6 +42,8 @@ void ReadOTUFile::read(GlobalData* globaldata){
                        globaldata->gorder = order;     //saving to be used by collect and rarefact commands.
                        sabund = inputSabund->getSAbundVector(); 
                        globaldata->sabund = sabund; //saving to be used by summary command.
+                       rabund = inputRabund->getRAbundVector(); 
+                       globaldata->rabund = rabund; //saving to be used by heatmap command.
                        list = inputList->getListVector();
                        globaldata->gListVector = list;
                }else if (globaldata->getFormat() == "shared") {
index e954cbdf10aca58bf271da4d25d1782871051eb7..e318af4b872e36eb243900d9de10f5b3fe9092fd 100644 (file)
--- a/readotu.h
+++ b/readotu.h
@@ -31,11 +31,13 @@ private:
        string philFile;
        InputData* input;
        InputData* inputSabund;
+       InputData* inputRabund;
        InputData* inputList;
        ListVector* list;
        SharedListVector* SharedList;
        OrderVector* order;
        SAbundVector* sabund;
+       RAbundVector* rabund;
        GlobalData* globaldata;
        // InputData* getInput()                        {       return input;   }
 };
index 06c8effdb66b4ea1bbf64b899e5918461134ea60..b5624508ac792aa82d367ed04ed1fbaf571d4cd6 100644 (file)
@@ -16,6 +16,7 @@ using namespace std;
 #include "ordervector.hpp"
 #include "sharedlistvector.h"
 #include "sharedordervector.h"
+#include "sharedutilities.h"
 
 /***********************************************************************/
 
@@ -284,6 +285,28 @@ SharedRAbundVector SharedListVector::getSharedRAbundVector(string groupName) {
                exit(1);
        }
 }
+/***********************************************************************/
+vector<SharedRAbundVector*> SharedListVector::getSharedRAbundVector() {
+       try {
+               SharedUtil* util;
+               util = new SharedUtil();
+               vector<SharedRAbundVector*> lookup;
+               
+               util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups);
+               util->getSharedVectors(globaldata->Groups, lookup, this->getSharedOrderVector());
+               
+               return lookup;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedListVector class Function getSharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedListVector class function getSharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       
+}
 
 /***********************************************************************/
 SharedSAbundVector SharedListVector::getSharedSAbundVector(string groupName) {
index 53fe1b1edd280bd6184766cbdf1d67cc2778cf91..8cfb7e000a9427921ce9e951c040c06c50cc71d8 100644 (file)
@@ -54,6 +54,7 @@ public:
        SharedOrderVector* getSharedOrderVector();
        SharedRAbundVector getSharedRAbundVector(string);  //get sharedrabundvector for a certain group
        SharedSAbundVector getSharedSAbundVector(string);                       //get sharedsabundvector for a certain group
+       vector<SharedRAbundVector*> getSharedRAbundVector(); //returns sharedRabundVectors for all the users groups
        
 private:
        vector<string> data;  //data[i] is a list of names of sequences in the ith OTU.
index 41daa8024713190e997fcb845c144731252386ed..0a6f095a0345a9865553b2189585b85629bf4697 100644 (file)
@@ -11,7 +11,7 @@ using namespace std;
 
 
 #include "sharedordervector.h"
-
+#include "sharedutilities.h"
 
 /***********************************************************************/
 
@@ -296,6 +296,28 @@ SharedRAbundVector SharedOrderVector::getSharedRAbundVector(string group) {
                exit(1);
        }
        
+}
+/***********************************************************************/
+vector<SharedRAbundVector*> SharedOrderVector::getSharedRAbundVector() {
+       try {
+               SharedUtil* util;
+               util = new SharedUtil();
+               vector<SharedRAbundVector*> lookup;
+               
+               util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups);
+               util->getSharedVectors(globaldata->Groups, lookup, this);
+               
+               return lookup;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedOrderVector class Function getSharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedOrderVector class function getSharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       
 }
 /***********************************************************************/
 SharedSAbundVector SharedOrderVector::getSharedSAbundVector(string group) {
index c315c44b5468479a813b25922e54baca48841bac..e941c7e5f860b770c5a766027d3cc658c94e3259 100644 (file)
@@ -69,6 +69,7 @@ public:
        SharedOrderVector getSharedOrderVector();
        SharedRAbundVector getSharedRAbundVector(string);  //get the sharedRabundvector for a sepecific group
        SharedSAbundVector getSharedSAbundVector(string);       //get the sharedSabundvector for a sepecific group
+       vector<SharedRAbundVector*> getSharedRAbundVector(); //returns sharedRabundVectors for all the users groups
        
 private:
        GlobalData* globaldata;
index 454b7d4073396f74c804ad1bba68cbea57ac5f57..fc1b3350599ebb6db17da3d6f02f977a1f793bb1 100644 (file)
@@ -109,7 +109,7 @@ void SharedUtil::getSharedVectorswithReplacement(vector<string> Groups, vector<S
 
 /**************************************************************************************************/
 //need to have mode because different commands require different number of valid groups
-void SharedUtil::setGroups(vector<string>& userGroups, vector<string>& allGroups, string mode) {
+void SharedUtil::setGroups(vector<string>& userGroups, vector<string>& allGroups) {
        try {
                if (userGroups.size() != 0) {
                        if (userGroups[0] != "all") {
@@ -122,6 +122,14 @@ void SharedUtil::setGroups(vector<string>& userGroups, vector<string>& allGroups
                                                i--;
                                        }
                                }
+                               
+                               //if the user only entered invalid groups
+                               if (userGroups.size() == 0) { 
+                                       cout << "When using the groups parameter you must have at least 1 valid groups. I will run the command using all the groups in your groupfile." << endl; 
+                                       for (int i = 0; i < allGroups.size(); i++) {
+                                               userGroups.push_back(allGroups[i]);
+                                       }
+                               }
 
                        }else{//user has enter "all" and wants the default groups
                                userGroups.clear();
@@ -135,38 +143,46 @@ void SharedUtil::setGroups(vector<string>& userGroups, vector<string>& allGroups
                        }
                }
                        
-               if (mode == "venn")  {
-                               //if the user only entered invalid groups
-                               if (userGroups.size() == 0) { 
-                                       if (allGroups.size() > 4) {
-                                               cout << "When using the groups parameter you must have at least 1 valid group. I will run the command using the first four groups in your groupfile." << endl; 
-                                               for (int i = 0; i < 4; i++) {
-                                                       userGroups.push_back(allGroups[i]);
-                                               }
-                                       }else {
-                                               cout << "When using the groups parameter you must have at least 1 valid group. I will run the command using all the groups in your groupfile." << endl; 
-                                               for (int i = 0; i < allGroups.size(); i++) {
-                                                       userGroups.push_back(allGroups[i]);
-                                               }
-                                       }
-                               }
-                               
-                               //check to make sure their are only 4 groups
-                               if (userGroups.size() > 4) {
-                                       cout << "You may only use up to 4 groups at a time with this command.  I will choose the first four and disregard the rest." << endl;
-                                       for (int i = 4; i < userGroups.size(); i++) {
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedUtil class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedUtil class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+
+}
+/**************************************************************************************************/
+//need to have mode because different commands require different number of valid groups
+void SharedUtil::setGroups(vector<string>& userGroups, vector<string>& allGroups, string mode) {
+       try {
+               if (userGroups.size() != 0) {
+                       if (userGroups[0] != "all") {
+                               //check that groups are valid
+                               for (int i = 0; i < userGroups.size(); i++) {
+                                       if (isValidGroup(userGroups[i], allGroups) != true) {
+                                               cout << userGroups[i] << " is not a valid group, and will be disregarded." << endl;
+                                               // erase the invalid group from userGroups
                                                userGroups.erase(userGroups.begin()+i);
+                                               i--;
                                        }
                                }
-               }else if (mode == "heat") {
-                               //if the user only entered invalid groups
-                               if (userGroups.size() == 0) { 
-                                       cout << "When using the groups parameter you must have at least 1 valid groups. I will run the command using all the groups in your groupfile." << endl; 
-                                       for (int i = 0; i < allGroups.size(); i++) {
-                                               userGroups.push_back(allGroups[i]);
-                                       }
+
+                       }else{//user has enter "all" and wants the default groups
+                               userGroups.clear();
+                               for (int i = 0; i < allGroups.size(); i++) {
+                                       userGroups.push_back(allGroups[i]);
                                }
-               }else if ((mode == "collect") || (mode == "rarefact") || (mode == "summary") || (mode == "treegroup")) {
+                       }
+               }else { //the user has not entered groups
+                       for (int i = 0; i < allGroups.size(); i++) {
+                               userGroups.push_back(allGroups[i]);
+                       }
+               }
+                       
+               if ((mode == "collect") || (mode == "rarefact") || (mode == "summary") || (mode == "treegroup")) {
                                //if the user only entered invalid groups
                                if ((userGroups.size() == 0) || (userGroups.size() == 1)) { 
                                        cout << "When using the groups parameter you must have at least 2 valid groups. I will run the command using all the groups in your groupfile." << endl; 
@@ -188,6 +204,7 @@ void SharedUtil::setGroups(vector<string>& userGroups, vector<string>& allGroups
 
 }
 
+
 /**************************************************************************************/
 //for parsimony and unifrac commands you set pairwise groups as well as an allgroups in calc
 void SharedUtil::setGroups(vector<string>& userGroups, vector<string>& allGroups, string& label, int& numGroups, string mode){  //globaldata->Groups, your tree or group map, allgroups, mode
index d43d2b6982d95ef36e5c5814b6d3f4767f3a717e..fa00933f197dee90428a62011903c1be84989c1a 100644 (file)
@@ -23,6 +23,7 @@ class SharedUtil {
                
                void getSharedVectors(vector<string>, vector<SharedRAbundVector*>&, SharedOrderVector*);
                void getSharedVectorswithReplacement(vector<string>, vector<SharedRAbundVector*>&, SharedOrderVector*);
+               void setGroups(vector<string>&, vector<string>&);  //globaldata->Groups, your tree or group map
                void setGroups(vector<string>&, vector<string>&, string);  //globaldata->Groups, your tree or group map, mode
                void setGroups(vector<string>&, vector<string>&, string&, int&, string);  //globaldata->Groups, your tree or group map, allgroups, numGroups, mode
                void getCombos(vector<string>&, vector<string>, int&); //groupcomb, globaldata->Groups, numcomb
index 3c0d797b4a246246af19a664b032017745e9f546..7c33dd7a7bb1237480c4e5d95b28187832a7b71d 100644 (file)
--- a/venn.cpp
+++ b/venn.cpp
@@ -18,7 +18,6 @@ Venn::Venn(){
        try {
                globaldata = GlobalData::getInstance();
                format = globaldata->getFormat();
-               util = new SharedUtil();
        }
        catch(exception& e) {
                cout << "Standard Error: " << e.what() << " has occurred in the Venn class Function Venn. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
@@ -30,13 +29,11 @@ Venn::Venn(){
        }
 }
 //**********************************************************************************************************************
-void Venn::getPic(OrderVector* order, vector<Calculator*> vCalcs) {
+void Venn::getPic(SAbundVector* sabund, vector<Calculator*> vCalcs) {
        try {
-               SAbundVector s;
-               s = order->getSAbundVector();  sabund = &s;
-               
+                               
                for(int i=0;i<vCalcs.size();i++){
-                       string filenamesvg = globaldata->inputFileName + ".venn." + order->getLabel() + vCalcs[i]->getName() + ".svg";
+                       string filenamesvg = globaldata->inputFileName + ".venn." + sabund->getLabel() + vCalcs[i]->getName() + ".svg";
                        openOutputFile(filenamesvg, outsvg);
 
                        vector<double> data = vCalcs[i]->getValues(sabund);
@@ -46,7 +43,7 @@ void Venn::getPic(OrderVector* order, vector<Calculator*> vCalcs) {
                        outsvg << "<g>\n";
                                
                        outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>"; 
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + order->getLabel() + "</text>\n";
+                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + sabund->getLabel() + "</text>\n";
                        outsvg << "<circle fill=\"red\" opacity=\".5\" stroke=\"black\" cx=\"350\" cy=\"200\" r=\"150\"/>"; 
                        outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(data[0]).length() / 2)) + "\" y=\"195\">" + toString(data[0]) + "</text>\n";  
                        
@@ -69,21 +66,21 @@ void Venn::getPic(OrderVector* order, vector<Calculator*> vCalcs) {
        }
 }
 //**********************************************************************************************************************
-void Venn::getPic(SharedOrderVector* sharedorder, vector<Calculator*> vCalcs) {
+void Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*> vCalcs) {
        try {
                
                //fills vector of sharedsabunds - lookup
-               util->getSharedVectors(globaldata->Groups, lookup, sharedorder);  //fills group vectors from order vector.
+               //util->getSharedVectors(globaldata->Groups, lookup, sharedorder);  //fills group vectors from order vector.
                
                /******************* 1 Group **************************/
                if (lookup.size() == 1) {
                                        
                        SAbundVector s;
-                       s = lookup[0]->getSAbundVector();  sabund = &s;
+                       s = lookup[0]->getSAbundVector();  SAbundVector* sabund = &s;
                        
                        //make a file for each calculator
                        for(int i=0;i<vCalcs.size();i++){
-                               string filenamesvg = getRootName(globaldata->inputFileName) + sharedorder->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
+                               string filenamesvg = getRootName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
                                openOutputFile(filenamesvg, outsvg);
                        
                                //in essence you want to run it like a single 
@@ -102,7 +99,7 @@ void Venn::getPic(SharedOrderVector* sharedorder, vector<Calculator*> vCalcs) {
                                outsvg << "<g>\n";
                                
                                outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>"; 
-                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + sharedorder->getLabel() + "</text>\n";
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
                                outsvg << "<circle fill=\"red\" opacity=\".5\" stroke=\"black\" cx=\"350\" cy=\"200\" r=\"150\"/>"; 
                                outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"165\">" + lookup[0]->getGroup() + "</text>\n";
                                outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(data[0]).length() / 2)) + "\" y=\"195\">" + toString(data[0]) + "</text>\n";  
@@ -130,7 +127,7 @@ void Venn::getPic(SharedOrderVector* sharedorder, vector<Calculator*> vCalcs) {
                        
                        //make a file for each calculator
                        for(int i=0;i<vCalcs.size();i++){
-                               string filenamesvg = getRootName(globaldata->inputFileName) + sharedorder->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
+                               string filenamesvg = getRootName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
                                openOutputFile(filenamesvg, outsvg);
                                
                                //get estimates for sharedAB
@@ -157,7 +154,7 @@ void Venn::getPic(SharedOrderVector* sharedorder, vector<Calculator*> vCalcs) {
 
                                //draw circles
                                outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>"; 
-                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + sharedorder->getLabel() + "</text>\n";
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
                                outsvg << "<circle fill=\"rgb(255,0,0)\" opacity=\".3\" stroke=\"black\" cx=\"250\" cy=\"200\" r=\"150\"/>"; 
                                outsvg << "<circle fill=\"rgb(0,255,0)\" opacity=\".3\" stroke=\"black\" cx=\"435\" cy=\"200\" r=\"150\"/>"; 
                                outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)toString(numA[0]).length() / 2)) + "\" y=\"195\">" + toString(numA[0] - shared[0]) + "</text>\n";
@@ -200,7 +197,7 @@ void Venn::getPic(SharedOrderVector* sharedorder, vector<Calculator*> vCalcs) {
                        
                        //make a file for each calculator
                        for(int i=0;i<vCalcs.size();i++){
-                               string filenamesvg = getRootName(globaldata->inputFileName) + sharedorder->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
+                               string filenamesvg = getRootName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
                                openOutputFile(filenamesvg, outsvg);
                                
                                //get estimates for sharedAB, sharedAC and sharedBC
@@ -276,7 +273,7 @@ void Venn::getPic(SharedOrderVector* sharedorder, vector<Calculator*> vCalcs) {
 
                                //draw circles
                                outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"800\" height=\"800\"/>"; 
-                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + sharedorder->getLabel() + "</text>\n";
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
                                outsvg << "<circle fill=\"rgb(255,0,0)\" opacity=\".3\" stroke=\"black\" cx=\"230\" cy=\"200\" r=\"150\"/>"; 
                                outsvg << "<circle fill=\"rgb(0,255,0)\" opacity=\".3\" stroke=\"black\" cx=\"455\" cy=\"200\" r=\"150\"/>"; 
                                outsvg << "<circle fill=\"rgb(0,0,255)\" opacity=\".3\" stroke=\"black\" cx=\"343\" cy=\"400\" r=\"150\"/>"; 
@@ -360,7 +357,7 @@ void Venn::getPic(SharedOrderVector* sharedorder, vector<Calculator*> vCalcs) {
                                if ((lookup[0]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) != 0) && (lookup[2]->getAbundance(i) != 0) && (lookup[3]->getAbundance(i) != 0)) { sharedABCD++; }
                        }
                                
-                       string filenamesvg = getRootName(globaldata->inputFileName) + sharedorder->getLabel() + ".venn.sharedsobs.svg";
+                       string filenamesvg = getRootName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn.sharedsobs.svg";
                        openOutputFile(filenamesvg, outsvg);
                
                        //image window
@@ -369,7 +366,7 @@ void Venn::getPic(SharedOrderVector* sharedorder, vector<Calculator*> vCalcs) {
 
                        //draw circles
                        outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>"; 
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + sharedorder->getLabel() + "</text>\n";
+                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
                        outsvg << "<ellipse fill=\"red\" stroke=\"black\" opacity=\".35\" transform=\"rotate(-45 355 215) \" cx=\"355\" cy=\"215\" rx=\"200\" ry=\"115\"/>\n "; 
                        outsvg << "<ellipse fill=\"green\" stroke=\"black\" opacity=\".35\" transform=\"rotate(+45 355 215) \" cx=\"355\" cy=\"215\" rx=\"200\" ry=\"115\"/>\n ";
                        outsvg << "<ellipse fill=\"blue\" stroke=\"black\" opacity=\".35\" transform=\"rotate(-40 440 315) \" cx=\"440\" cy=\"315\" rx=\"200\" ry=\"115\"/>\n ";
diff --git a/venn.h b/venn.h
index 748723e85dd068722d09179dab76ee1dd2968390..35c1d1cbbe6d71663fa345bc97856c6194a6fda5 100644 (file)
--- a/venn.h
+++ b/venn.h
 
 using namespace std;
 
-#include "ordervector.hpp"
 #include "sabundvector.hpp"
 #include "sharedrabundvector.h"
-#include "sharedordervector.h"
 #include "datavector.hpp"
 #include "globaldata.hpp"
 #include "calculator.h"
-#include "sharedutilities.h"
+
 
 /***********************************************************************/
 
@@ -28,15 +26,12 @@ class Venn {
                Venn();
                ~Venn(){};
        
-               void getPic(OrderVector*, vector<Calculator*>);
-               void getPic(SharedOrderVector*, vector<Calculator*>);
+               void getPic(SAbundVector*, vector<Calculator*>);
+               void getPic(vector<SharedRAbundVector*>, vector<Calculator*>);
 
        private:
-               SharedUtil* util;
-               SAbundVector* sabund;
                GlobalData* globaldata;
                Calculator* singleCalc;
-               vector<SharedRAbundVector*> lookup;
                string format, groupComb;
                ofstream outsvg;
 
index 5357c2560a7c75fe82f3238d482a443744b6a6f5..e9cb47aca2c0b6291cbf57902ceb56808137704e 100644 (file)
@@ -24,7 +24,6 @@ VennCommand::VennCommand(){
                globaldata = GlobalData::getInstance();
                format = globaldata->getFormat();
                validCalculator = new ValidCalculators();
-               util = new SharedUtil();
                
                int i;
                
@@ -81,7 +80,6 @@ VennCommand::~VennCommand(){
        delete input;
        delete read;
        delete venn;
-       delete util;
 }
 
 //**********************************************************************************************************************
@@ -99,7 +97,7 @@ int VennCommand::execute(){
                        read->read(&*globaldata); 
                        
                        input = globaldata->ginput;
-                       order = input->getSharedOrderVector();
+                       lookup = input->getSharedRAbundVectors();
                }else if (format == "shared") {
                        //you are using a list and a groupfile
                        read = new ReadOTUFile(globaldata->inputFileName);      
@@ -107,43 +105,36 @@ int VennCommand::execute(){
                
                        input = globaldata->ginput;
                        SharedList = globaldata->gSharedList;
-                       order = SharedList->getSharedOrderVector();
+                       lookup = SharedList->getSharedRAbundVector();
                }else if (format == "list") {
                        //you are using just a list file and have only one group
                        read = new ReadOTUFile(globaldata->inputFileName);      
                        read->read(&*globaldata); 
                
-                       ordersingle = globaldata->gorder;
+                       sabund = globaldata->sabund;
                        input = globaldata->ginput;
                }
 
                
                if (format != "list") { 
                        
-                       util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "venn");
-                       globaldata->setGroups("");
-                       
-                       while(order != NULL){
+                       while(lookup[0] != NULL){
                
-                               if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){                       
+                               if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(lookup[0]->getLabel()) == 1){                   
        
-                                       cout << order->getLabel() << '\t' << count << endl;
-                                       venn->getPic(order, vennCalculators);
-
+                                       cout << lookup[0]->getLabel() << '\t' << count << endl;
+                                       
+                                       if (lookup.size() > 4) {
+                                               cout << "Error: Too many groups chosen.  You may use up to 4 groups with the venn command.  I will use the first four groups in your groupfile." << endl;
+                                               for (int i = lookup.size(); i > 3; i--) { delete lookup[i]; lookup.pop_back(); }
+                                       }
+                                       
+                                       //util->getSharedVectors(globaldata->Groups, lookup, order);  //fills group vectors from order vector.
+                                       venn->getPic(lookup, vennCalculators);
                                }
                                                
                                //get next line to process
-                               if (format == "sharedfile") {
-                                       order = input->getSharedOrderVector();
-                               }else {
-                                       //you are using a list and a groupfile
-                                       SharedList = input->getSharedListVector(); //get new list vector to process
-                                       if (SharedList != NULL) {
-                                               order = SharedList->getSharedOrderVector(); //gets new order vector with group info.
-                                       }else {
-                                               break;
-                                       }
-                               }
+                               lookup = input->getSharedRAbundVectors();
                                count++;
                        }
                        
@@ -151,20 +142,21 @@ int VennCommand::execute(){
                        globaldata->Groups.clear();  
                        
                }else{
-                       while(ordersingle != NULL){
                
-                               if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(ordersingle->getLabel()) == 1){                 
+                       while(sabund != NULL){
+               
+                               if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(sabund->getLabel()) == 1){                      
        
-                                       cout << ordersingle->getLabel() << '\t' << count << endl;
-                                       venn->getPic(ordersingle, vennCalculators);
-                                       
+                                       cout << sabund->getLabel() << '\t' << count << endl;
+                                       venn->getPic(sabund, vennCalculators);
                                }
                                
-                               ordersingle = (input->getOrderVector());
+                               sabund = input->getSAbundVector();
                                count++;
                        }
                }
                
+               globaldata->setGroups("");
                return 0;
        }
        catch(exception& e) {
@@ -177,5 +169,4 @@ int VennCommand::execute(){
        }               
 }
 
-//**********************************************************************************************************************
-
+//**********************************************************************************************************************
\ No newline at end of file
index 063b8afdfbf4f733c6e537b6c245dc6f17aca516..663839c92ca560e8b5f657a775b634c83ef8af6d 100644 (file)
@@ -15,7 +15,6 @@
 #include "sharedlistvector.h"
 #include "venn.h"
 #include "validcalculator.h"
-#include "sharedutilities.h"
 
 
 class GlobalData;
@@ -31,15 +30,14 @@ public:
 private:
        GlobalData* globaldata;
        ReadOTUFile* read;
-       SharedUtil* util;
        InputData* input;
        SharedListVector* SharedList;
-       SharedOrderVector* order;
-       OrderVector* ordersingle;
        Venn* venn;
        string format;
        vector<Calculator*> vennCalculators;    
        ValidCalculators* validCalculator;
+       vector<SharedRAbundVector*> lookup;
+       SAbundVector* sabund;
        int abund;
 
 };