From d59f91eb1230d2c7867a92cb86138b7003100ab4 Mon Sep 17 00:00:00 2001 From: westcott Date: Wed, 22 Apr 2009 15:47:04 +0000 Subject: [PATCH] changed heatmap and venn command to use vector of sharedrabunds instead of order. Added functions to readotu, inputdata, sharedordervector, sharedlistvector to support that change, as well as modified sharedutilities setGroups. --- datavector.hpp | 2 +- globaldata.hpp | 1 + heatmap.cpp | 42 +++++++++-------------- heatmap.h | 11 +++---- heatmapcommand.cpp | 49 +++++++++------------------ heatmapcommand.h | 9 ++--- inputdata.cpp | 77 +++++++++++++++++++++++++++++++++++++++++++ inputdata.h | 3 ++ readotu.cpp | 3 ++ readotu.h | 2 ++ sharedlistvector.cpp | 23 +++++++++++++ sharedlistvector.h | 1 + sharedordervector.cpp | 24 +++++++++++++- sharedordervector.h | 1 + sharedutilities.cpp | 75 +++++++++++++++++++++++++---------------- sharedutilities.h | 1 + venn.cpp | 33 +++++++++---------- venn.h | 11 ++----- venncommand.cpp | 55 +++++++++++++------------------ venncommand.h | 6 ++-- 20 files changed, 264 insertions(+), 165 deletions(-) diff --git a/datavector.hpp b/datavector.hpp index 73058a9..18ac695 100644 --- a/datavector.hpp +++ b/datavector.hpp @@ -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* hold = NULL) = 0; diff --git a/globaldata.hpp b/globaldata.hpp index be5b008..cc13bae 100644 --- a/globaldata.hpp +++ b/globaldata.hpp @@ -35,6 +35,7 @@ public: vector gTree; SharedListVector* gSharedList; SAbundVector* sabund; + RAbundVector* rabund; GroupMap* gGroupmap; FullMatrix* gMatrix; TreeMap* gTreemap; diff --git a/heatmap.cpp b/heatmap.cpp index 187c953..0b1a80e 100644 --- a/heatmap.cpp +++ b/heatmap.cpp @@ -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;isize();i++){ + float relAbund = rabund->get(i) / (float)rabund->getNumSeqs(); if(relAbund > maxRelAbund){ maxRelAbund = relAbund; } } scaler = globaldata->getScale(); - vector scaleRelAbund(rabund.size(), ""); + vector scaleRelAbund(rabund->size(), ""); - for(int i=0;isize();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 << "\n"; + outsvg << "getNumBins()*5 + 120)) + "\">\n"; outsvg << "\n"; //white backround - outsvg << ""; - outsvg << "Heatmap at distance " + rabund.getLabel() + "\n"; + outsvg << "getNumBins()*5 + 120)) + "\"/>"; + outsvg << "Heatmap at distance " + rabund->getLabel() + "\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 lookup) { try { - //fills vector of sharedsabunds - lookup - vector 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 << "getNumBins()*5 + 120)) + "\"/>"; - outsvg << "Heatmap at distance " + sharedorder->getLabel() + "\n"; + outsvg << "Heatmap at distance " + lookup[0]->getLabel() + "\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); diff --git a/heatmap.h b/heatmap.h index 528c964..29b6b9a 100644 --- a/heatmap.h +++ b/heatmap.h @@ -11,13 +11,10 @@ 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); private: void sortSharedVectors(vector& ); void printLegend(int, float); GlobalData* globaldata; - SharedUtil* util; string format, sorted, groupComb, scaler; ofstream outsvg; @@ -47,3 +43,4 @@ class HeatMap { + diff --git a/heatmapcommand.cpp b/heatmapcommand.cpp index b8b3820..be25f09 100644 --- a/heatmapcommand.cpp +++ b/heatmapcommand.cpp @@ -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) { diff --git a/heatmapcommand.h b/heatmapcommand.h index edb3460..fc50554 100644 --- a/heatmapcommand.h +++ b/heatmapcommand.h @@ -16,12 +16,10 @@ #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 lookup; HeatMap* heatmap; string format; diff --git a/inputdata.cpp b/inputdata.cpp index c8259d9..2c249e6 100644 --- a/inputdata.cpp +++ b/inputdata.cpp @@ -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 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 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); + } +} +/***********************************************************************/ + + + diff --git a/inputdata.h b/inputdata.h index 1352e94..f21daec 100644 --- a/inputdata.h +++ b/inputdata.h @@ -21,6 +21,8 @@ public: OrderVector* getOrderVector(); SharedOrderVector* getSharedOrderVector(); SAbundVector* getSAbundVector(); + RAbundVector* getRAbundVector(); + vector getSharedRAbundVectors(); private: string format; @@ -31,6 +33,7 @@ private: OrderVector* output; SharedOrderVector* SharedOrder; SAbundVector* sabund; + RAbundVector* rabund; map orderMap; }; diff --git a/readotu.cpp b/readotu.cpp index 0bcfd32..971ed31 100644 --- a/readotu.cpp +++ b/readotu.cpp @@ -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") { diff --git a/readotu.h b/readotu.h index e954cbd..e318af4 100644 --- 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; } }; diff --git a/sharedlistvector.cpp b/sharedlistvector.cpp index 06c8eff..b562450 100644 --- a/sharedlistvector.cpp +++ b/sharedlistvector.cpp @@ -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 SharedListVector::getSharedRAbundVector() { + try { + SharedUtil* util; + util = new SharedUtil(); + vector 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) { diff --git a/sharedlistvector.h b/sharedlistvector.h index 53fe1b1..8cfb7e0 100644 --- a/sharedlistvector.h +++ b/sharedlistvector.h @@ -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 getSharedRAbundVector(); //returns sharedRabundVectors for all the users groups private: vector data; //data[i] is a list of names of sequences in the ith OTU. diff --git a/sharedordervector.cpp b/sharedordervector.cpp index 41daa80..0a6f095 100644 --- a/sharedordervector.cpp +++ b/sharedordervector.cpp @@ -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 SharedOrderVector::getSharedRAbundVector() { + try { + SharedUtil* util; + util = new SharedUtil(); + vector 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) { diff --git a/sharedordervector.h b/sharedordervector.h index c315c44..e941c7e 100644 --- a/sharedordervector.h +++ b/sharedordervector.h @@ -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 getSharedRAbundVector(); //returns sharedRabundVectors for all the users groups private: GlobalData* globaldata; diff --git a/sharedutilities.cpp b/sharedutilities.cpp index 454b7d4..fc1b335 100644 --- a/sharedutilities.cpp +++ b/sharedutilities.cpp @@ -109,7 +109,7 @@ void SharedUtil::getSharedVectorswithReplacement(vector Groups, vector& userGroups, vector& allGroups, string mode) { +void SharedUtil::setGroups(vector& userGroups, vector& allGroups) { try { if (userGroups.size() != 0) { if (userGroups[0] != "all") { @@ -122,6 +122,14 @@ void SharedUtil::setGroups(vector& userGroups, vector& 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& userGroups, vector& 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& userGroups, vector& 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& userGroups, vector& allGroups } + /**************************************************************************************/ //for parsimony and unifrac commands you set pairwise groups as well as an allgroups in calc void SharedUtil::setGroups(vector& userGroups, vector& allGroups, string& label, int& numGroups, string mode){ //globaldata->Groups, your tree or group map, allgroups, mode diff --git a/sharedutilities.h b/sharedutilities.h index d43d2b6..fa00933 100644 --- a/sharedutilities.h +++ b/sharedutilities.h @@ -23,6 +23,7 @@ class SharedUtil { void getSharedVectors(vector, vector&, SharedOrderVector*); void getSharedVectorswithReplacement(vector, vector&, SharedOrderVector*); + void setGroups(vector&, vector&); //globaldata->Groups, your tree or group map void setGroups(vector&, vector&, string); //globaldata->Groups, your tree or group map, mode void setGroups(vector&, vector&, string&, int&, string); //globaldata->Groups, your tree or group map, allgroups, numGroups, mode void getCombos(vector&, vector, int&); //groupcomb, globaldata->Groups, numcomb diff --git a/venn.cpp b/venn.cpp index 3c0d797..7c33dd7 100644 --- 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 vCalcs) { +void Venn::getPic(SAbundVector* sabund, vector vCalcs) { try { - SAbundVector s; - s = order->getSAbundVector(); sabund = &s; - + for(int i=0;iinputFileName + ".venn." + order->getLabel() + vCalcs[i]->getName() + ".svg"; + string filenamesvg = globaldata->inputFileName + ".venn." + sabund->getLabel() + vCalcs[i]->getName() + ".svg"; openOutputFile(filenamesvg, outsvg); vector data = vCalcs[i]->getValues(sabund); @@ -46,7 +43,7 @@ void Venn::getPic(OrderVector* order, vector vCalcs) { outsvg << "\n"; outsvg << ""; - outsvg << "Venn Diagram at distance " + order->getLabel() + "\n"; + outsvg << "Venn Diagram at distance " + sabund->getLabel() + "\n"; outsvg << ""; outsvg << "" + toString(data[0]) + "\n"; @@ -69,21 +66,21 @@ void Venn::getPic(OrderVector* order, vector vCalcs) { } } //********************************************************************************************************************** -void Venn::getPic(SharedOrderVector* sharedorder, vector vCalcs) { +void Venn::getPic(vector lookup, vector 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;iinputFileName) + 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 vCalcs) { outsvg << "\n"; outsvg << ""; - outsvg << "Venn Diagram at distance " + sharedorder->getLabel() + "\n"; + outsvg << "Venn Diagram at distance " + lookup[0]->getLabel() + "\n"; outsvg << ""; outsvg << "getGroup().length() / 2)) + "\" y=\"165\">" + lookup[0]->getGroup() + "\n"; outsvg << "" + toString(data[0]) + "\n"; @@ -130,7 +127,7 @@ void Venn::getPic(SharedOrderVector* sharedorder, vector vCalcs) { //make a file for each calculator for(int i=0;iinputFileName) + 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 vCalcs) { //draw circles outsvg << ""; - outsvg << "Venn Diagram at distance " + sharedorder->getLabel() + "\n"; + outsvg << "Venn Diagram at distance " + lookup[0]->getLabel() + "\n"; outsvg << ""; outsvg << ""; outsvg << "" + toString(numA[0] - shared[0]) + "\n"; @@ -200,7 +197,7 @@ void Venn::getPic(SharedOrderVector* sharedorder, vector vCalcs) { //make a file for each calculator for(int i=0;iinputFileName) + 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 vCalcs) { //draw circles outsvg << ""; - outsvg << "Venn Diagram at distance " + sharedorder->getLabel() + "\n"; + outsvg << "Venn Diagram at distance " + lookup[0]->getLabel() + "\n"; outsvg << ""; outsvg << ""; outsvg << ""; @@ -360,7 +357,7 @@ void Venn::getPic(SharedOrderVector* sharedorder, vector 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 vCalcs) { //draw circles outsvg << ""; - outsvg << "Venn Diagram at distance " + sharedorder->getLabel() + "\n"; + outsvg << "Venn Diagram at distance " + lookup[0]->getLabel() + "\n"; outsvg << "\n "; outsvg << "\n "; outsvg << "\n "; diff --git a/venn.h b/venn.h index 748723e..35c1d1c 100644 --- a/venn.h +++ b/venn.h @@ -11,14 +11,12 @@ 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); - void getPic(SharedOrderVector*, vector); + void getPic(SAbundVector*, vector); + void getPic(vector, vector); private: - SharedUtil* util; - SAbundVector* sabund; GlobalData* globaldata; Calculator* singleCalc; - vector lookup; string format, groupComb; ofstream outsvg; diff --git a/venncommand.cpp b/venncommand.cpp index 5357c25..e9cb47a 100644 --- a/venncommand.cpp +++ b/venncommand.cpp @@ -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 diff --git a/venncommand.h b/venncommand.h index 063b8af..663839c 100644 --- a/venncommand.h +++ b/venncommand.h @@ -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 vennCalculators; ValidCalculators* validCalculator; + vector lookup; + SAbundVector* sabund; int abund; }; -- 2.39.2