]> git.donarmstrong.com Git - mothur.git/commitdiff
started shared utilities, updates to venn and heatmap added tree.groups command
authorwestcott <westcott>
Tue, 14 Apr 2009 12:04:57 +0000 (12:04 +0000)
committerwestcott <westcott>
Tue, 14 Apr 2009 12:04:57 +0000 (12:04 +0000)
103 files changed:
Mothur.xcodeproj/project.pbxproj
averagelinkage.cpp
bergerparker.cpp
binsequencecommand.h
bstick.cpp
calculator.h
cluster.cpp
cluster.hpp
collect.cpp
collect.h
collectcommand.h
collectdisplay.h
collectsharedcommand.cpp
collectsharedcommand.h
commandfactory.cpp
commandfactory.hpp
commandoptionparser.cpp
commandoptionparser.hpp
database.cpp
database.hpp
deconvolutecommand.h
engine.cpp
engine.hpp
errorchecking.cpp
errorchecking.h
fastamap.h
fileoutput.cpp
fileoutput.h
geom.cpp
getoturepcommand.h
globaldata.cpp
globaldata.hpp
groupmap.h
heatmap.cpp
heatmap.h
heatmapcommand.cpp
heatmapcommand.h
helpcommand.cpp
inputdata.cpp
kmer.cpp
kmer.hpp
kmerdb.cpp
kmerdb.hpp
listvector.cpp
logsd.cpp
mothur.cpp
mothur.h
nameassignment.hpp
ordervector.cpp
parsimonycommand.cpp
parsimonycommand.h
qstat.cpp
rabundvector.cpp
rabundvector.hpp
raredisplay.cpp
raredisplay.h
rarefact.cpp
rarefact.h
rarefactsharedcommand.cpp
rarefactsharedcommand.h
readmatrix.cpp
readmatrix.hpp
readtree.h
sabundvector.cpp
shared.h
sharedbdiversity.cpp
sharedkstest.cpp
sharedlistvector.cpp
sharednseqs.h
sharedordervector.cpp
sharedordervector.h
sharedrabundvector.cpp
sharedrabundvector.h
sharedsabundvector.cpp
sharedutilities.cpp [new file with mode: 0644]
sharedutilities.h [new file with mode: 0644]
singlelinkage.cpp
sparsematrix.cpp
sparsematrix.hpp
summarysharedcommand.cpp
summarysharedcommand.h
tree.cpp
treecalculator.h
treegroupscommand.cpp [new file with mode: 0644]
treegroupscommand.h [new file with mode: 0644]
treemap.cpp
treemap.h
treenode.cpp
treenode.h
unifracunweightedcommand.cpp
unifracunweightedcommand.h
unifracweightedcommand.cpp
unifracweightedcommand.h
utilities.hpp [deleted file]
validcalculator.cpp
validcalculator.h
validcommands.cpp
validparameter.cpp
validparameter.h
venn.cpp
venn.h
venncommand.cpp
venncommand.h

index b63f1088509f56feac3399ebf925a6f095d69af3..967e8e4be3fc714d822fed1b36f591d3aa1f15e0 100644 (file)
@@ -11,6 +11,7 @@
                372E12700F26365B0095CF7E /* readotucommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 372E126F0F26365B0095CF7E /* readotucommand.cpp */; };
                372E12960F263D5A0095CF7E /* readdistcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 372E12950F263D5A0095CF7E /* readdistcommand.cpp */; };
                372E12ED0F264D320095CF7E /* commandfactory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 372E12EC0F264D320095CF7E /* commandfactory.cpp */; };
+               3731C1F30F8CFC0A0065A2AD /* treegroupscommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3731C1F20F8CFC0A0065A2AD /* treegroupscommand.cpp */; };
                374610780F40645300460C57 /* unifracweightedcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 374610770F40645300460C57 /* unifracweightedcommand.cpp */; };
                3746107E0F4064D100460C57 /* weighted.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3746107D0F4064D100460C57 /* weighted.cpp */; };
                374610830F40652400460C57 /* unweighted.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 374610820F40652400460C57 /* unweighted.cpp */; };
@@ -39,6 +40,7 @@
                37AFC71F0F445386005F492D /* sharedsobscollectsummary.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37AFC71E0F445386005F492D /* sharedsobscollectsummary.cpp */; };
                37B28F680F27590100808A62 /* deconvolutecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37B28F670F27590100808A62 /* deconvolutecommand.cpp */; };
                37C1D9730F86506E0059E3F0 /* binsequencecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37C1D9720F86506E0059E3F0 /* binsequencecommand.cpp */; };
+               37C7F3A90F8E90AD00E91C2B /* sharedutilities.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37C7F3A80F8E90AD00E91C2B /* sharedutilities.cpp */; };
                37D928550F21331F001D4494 /* ace.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927B80F21331F001D4494 /* ace.cpp */; };
                37D928560F21331F001D4494 /* averagelinkage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927BA0F21331F001D4494 /* averagelinkage.cpp */; };
                37D928570F21331F001D4494 /* bootstrap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927BB0F21331F001D4494 /* bootstrap.cpp */; };
                372E12940F263D5A0095CF7E /* readdistcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readdistcommand.h; sourceTree = "<group>"; };
                372E12950F263D5A0095CF7E /* readdistcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readdistcommand.cpp; sourceTree = "<group>"; };
                372E12EC0F264D320095CF7E /* commandfactory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = commandfactory.cpp; sourceTree = "<group>"; };
+               3731C1F10F8CFC0A0065A2AD /* treegroupscommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = treegroupscommand.h; sourceTree = "<group>"; };
+               3731C1F20F8CFC0A0065A2AD /* treegroupscommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = treegroupscommand.cpp; sourceTree = "<group>"; };
                374610760F40645300460C57 /* unifracweightedcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = unifracweightedcommand.h; sourceTree = "<group>"; };
                374610770F40645300460C57 /* unifracweightedcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = unifracweightedcommand.cpp; sourceTree = "<group>"; };
                3746107C0F4064D100460C57 /* weighted.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = weighted.h; sourceTree = "<group>"; };
                37B28F670F27590100808A62 /* deconvolutecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = deconvolutecommand.cpp; sourceTree = "<group>"; };
                37C1D9710F86506E0059E3F0 /* binsequencecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = binsequencecommand.h; sourceTree = "<group>"; };
                37C1D9720F86506E0059E3F0 /* binsequencecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = binsequencecommand.cpp; sourceTree = "<group>"; };
+               37C7F3A70F8E90AD00E91C2B /* sharedutilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedutilities.h; sourceTree = "<group>"; };
+               37C7F3A80F8E90AD00E91C2B /* sharedutilities.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedutilities.cpp; sourceTree = "<group>"; };
                37D927B80F21331F001D4494 /* ace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ace.cpp; sourceTree = "<group>"; };
                37D927B90F21331F001D4494 /* ace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ace.h; sourceTree = "<group>"; };
                37D927BA0F21331F001D4494 /* averagelinkage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = averagelinkage.cpp; sourceTree = "<group>"; };
                37D928490F21331F001D4494 /* summarydisplay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = summarydisplay.h; sourceTree = "<group>"; };
                37D9284A0F21331F001D4494 /* summarysharedcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = summarysharedcommand.cpp; sourceTree = "<group>"; };
                37D9284B0F21331F001D4494 /* summarysharedcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = summarysharedcommand.h; sourceTree = "<group>"; };
-               37D9284C0F21331F001D4494 /* utilities.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = utilities.hpp; sourceTree = "<group>"; };
                37D9284D0F21331F001D4494 /* uvest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = uvest.cpp; sourceTree = "<group>"; };
                37D9284E0F21331F001D4494 /* uvest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = uvest.h; sourceTree = "<group>"; };
                37D9284F0F21331F001D4494 /* validcalculator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = validcalculator.cpp; sourceTree = "<group>"; };
                                37D9281C0F21331F001D4494 /* sequence.cpp */,
                                37D928210F21331F001D4494 /* shared.h */,
                                37D928200F21331F001D4494 /* shared.cpp */,
+                               37C7F3A70F8E90AD00E91C2B /* sharedutilities.h */,
+                               37C7F3A80F8E90AD00E91C2B /* sharedutilities.cpp */,
                                37D928420F21331F001D4494 /* singlelinkage.cpp */,
                                37D928480F21331F001D4494 /* summarydata.h */,
                                37D928490F21331F001D4494 /* summarydisplay.h */,
-                               37D9284C0F21331F001D4494 /* utilities.hpp */,
                                37519AB30F810FAE00FED5E8 /* venn.h */,
                                37519AB40F810FAE00FED5E8 /* venn.cpp */,
                        );
                                37D928460F21331F001D4494 /* summarycommand.cpp */,
                                37D9284B0F21331F001D4494 /* summarysharedcommand.h */,
                                37D9284A0F21331F001D4494 /* summarysharedcommand.cpp */,
+                               3731C1F10F8CFC0A0065A2AD /* treegroupscommand.h */,
+                               3731C1F20F8CFC0A0065A2AD /* treegroupscommand.cpp */,
                                3746109B0F40657600460C57 /* unifracunweightedcommand.h */,
                                3746109C0F40657600460C57 /* unifracunweightedcommand.cpp */,
                                374610760F40645300460C57 /* unifracweightedcommand.h */,
                                37519AB50F810FAE00FED5E8 /* venn.cpp in Sources */,
                                37C1D9730F86506E0059E3F0 /* binsequencecommand.cpp in Sources */,
                                370B88070F8A4EE4005AB382 /* getoturepcommand.cpp in Sources */,
+                               3731C1F30F8CFC0A0065A2AD /* treegroupscommand.cpp in Sources */,
+                               37C7F3A90F8E90AD00E91C2B /* sharedutilities.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index ec619cae3a5e373d7cd482c4bc25667e552a6687..54f380353c6d97f018218c74e7667b3df1f89637 100644 (file)
@@ -1,10 +1,11 @@
 #ifndef AVERAGE_H
 #define AVERAGE_H
 
+
+#include "mothur.h"
 #include "cluster.hpp"
 #include "rabundvector.hpp"
 #include "sparsematrix.hpp"
-#include "mothur.h"
 
 /* This class implements the average UPGMA, average neighbor clustering algorithm */
 
index c8c25ea71f2a87ef8d975b0843a7a7929cd6b9b9..41e6e9fe97d193b4491fb33e3c5074b817516c8c 100644 (file)
@@ -8,7 +8,6 @@
  */
 
 #include "bergerparker.h"
-#include "calculator.h"
 
 /***************************************************************/
 
index 22847dce9b45604515c97fab55a2673813324ec2..25f52160e6c314e300e0abd6f303c378881cf2af 100644 (file)
@@ -9,6 +9,7 @@
  *
  */
 
+/* The bin.seqs command outputs a .fasta file for each distance you specify appending the OTU number to each name. */
 
 #include "command.hpp"
 #include "inputdata.h"
index 3a0e0e91a873f6692b585463ec324e33d3b2cd82..0dc67b9b07e3a8bde26300ba1b8b5233e0af099e 100644 (file)
@@ -8,7 +8,7 @@
  */
 
 #include "bstick.h"
-#include "calculator.h"
+
 
 /***********************************************************************/
 double BStick::invSum(int index, double numSpec)
index c87d5c7ca305dc229110f8c81577a5af7c98fd40..53e5c5a52578e7babcff8c487329cf320a5aa360 100644 (file)
@@ -4,7 +4,6 @@
 using namespace std;
 
 #include "mothur.h"
-#include "utilities.hpp"
 #include "sabundvector.hpp"
 #include "sharedsabundvector.h"
 #include "rabundvector.hpp"
index 81360b4f945ac4c011f6ed5f3a0686e7b04b6516..1ccb34943d32b907b656fd6fc6272a11501f549f 100644 (file)
@@ -10,6 +10,7 @@
 #include "cluster.hpp"
 #include "rabundvector.hpp"
 #include "listvector.hpp"
+#include "sparsematrix.hpp"
 
 /***********************************************************************/
 
index 208ccbfe1ba45ba70d152ba4c5ff12b50182d4dc..5f010381f2fbb536a7ac96774523cbf39bc5b98d 100644 (file)
@@ -4,9 +4,7 @@
 using namespace std;
 
 #include "mothur.h"
-#include "utilities.hpp"
 #include "sparsematrix.hpp"
-#include "rabundvector.hpp"
 
 class RAbundVector;
 class ListVector;
index 7397d24ab30cbb968d4c02ae5522aa3d111ca05a..8043dc14f90f0828d2138f34b10424c878c58545 100644 (file)
@@ -9,7 +9,6 @@
 
 #include "collect.h"
 
-
 /***********************************************************************/
 
 void Collect::getCurve(int increment = 1){
index aca4ccd40069cf5fdcdb9fed05b17cabe447f567..295673eca402f1f82558e3f8cf2667607cadd2d1 100644 (file)
--- a/collect.h
+++ b/collect.h
@@ -4,6 +4,7 @@
 using namespace std;
 
 
+
 #include "collectorscurvedata.h"
 #include "display.h"
 #include "ordervector.hpp"
index 9c24339d3d3745a1b2a6591af023c0fbb7ab3901..93b56073dee7955dc60d410347da82b4bf6d2dc2 100644 (file)
@@ -12,7 +12,7 @@
 #include "command.hpp"
 #include "ordervector.hpp"
 #include "inputdata.h"
-//#include "groupmap.h"
+#include "groupmap.h"
 #include "collect.h"
 #include "display.h"
 #include "readmatrix.hpp"
index fc405dfa0d7dbfd8885d5c21ec9b1d879f2f4126..af97c756d6a813959cabf5ce8f13f9e70f206806 100644 (file)
@@ -6,7 +6,7 @@
 #include "calculator.h"
 #include "fileoutput.h"
 #include "display.h"
-#include <vector>
+
 
 using namespace std;
 
index ec35dd601e75abd3ea7b65e32aabcaa1c13b1c90..6c47f2d5a6b2e4ac178d61128e4e0739a7c41666 100644 (file)
@@ -41,6 +41,7 @@ CollectSharedCommand::CollectSharedCommand(){
                fileNameRoot = getRootName(globaldata->inputFileName);
                format = globaldata->getFormat();
                validCalculator = new ValidCalculators();
+               util = new SharedUtil();
                
                int i;
                for (i=0; i<globaldata->Estimators.size(); i++) {
@@ -113,6 +114,7 @@ CollectSharedCommand::~CollectSharedCommand(){
        delete input;
        delete cCurve;
        delete read;
+       delete util;
 }
 
 //**********************************************************************************************************************
@@ -142,7 +144,8 @@ int CollectSharedCommand::execute(){
                set<string> orderList;
                
                //set users groups
-               setGroups();
+               util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "collect");
+               util->updateGroupIndex(globaldata->Groups, globaldata->gGroupmap->groupIndex);
 
                while(order != NULL){
                        orderList.insert(order->getLabel());
@@ -193,52 +196,5 @@ int CollectSharedCommand::execute(){
        }       
 }
 
-
-//**********************************************************************************************************************
-void CollectSharedCommand::setGroups() {
-       try {
-               //if the user has not entered specific groups to analyze then do them all
-               if (globaldata->Groups.size() != 0) {
-                       if (globaldata->Groups[0] != "all") {
-                               //check that groups are valid
-                               for (int i = 0; i < globaldata->Groups.size(); i++) {
-                                       if (globaldata->gGroupmap->isValidGroup(globaldata->Groups[i]) != true) {
-                                               cout << globaldata->Groups[i] << " is not a valid group, and will be disregarded." << endl;
-                                               // erase the invalid group from globaldata->Groups
-                                               globaldata->Groups.erase(globaldata->Groups.begin()+i);
-                                       }
-                               }
-                       
-                               //if the user only entered invalid groups
-                               if ((globaldata->Groups.size() == 0) || (globaldata->Groups.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; 
-                                       for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
-                                               globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
-                                       }
-                               }
-                       }else{//user has enter "all" and wants the default groups
-                               globaldata->Groups.clear();
-                               for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
-                                       globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
-                               }
-                               globaldata->setGroups("");
-                       }
-               }else {
-                       for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
-                               globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
-                       }
-               }
-               
-       }
-       catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the CollectSharedCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }               
-
-}
 /***********************************************************/
 
index c5c24b2f974e504e5c8ef079d15a89026291b992..8c7aa009ca346670482679ac17b4c9f75d58fa82 100644 (file)
@@ -19,6 +19,7 @@
 #include "display.h"
 #include "readmatrix.hpp"
 #include "validcalculator.h"
+#include "sharedutilities.h"
 
 /* The collect.shared() command:
        The collect command generates a collector's curve from the given file representing several groups.  
@@ -44,6 +45,7 @@ public:
        
 private:
        GlobalData* globaldata;
+       SharedUtil* util;
        GroupMap* groupmap;
        SharedListVector* SharedList;
        ReadMatrix* read;
@@ -54,7 +56,6 @@ private:
        vector<Display*> cDisplays;
        int freq;
        string format;
-       void setGroups();
 
 };
 
index 5155095526d1a3d08f4b72ec5236c882400ba5ec..b4e68e4cd67de88de0198251f2d595c9e000a498 100644 (file)
 #include "libshuffcommand.h"
 #include "heatmapcommand.h"
 #include "venncommand.h"
-#include "mothur.h"
 #include "nocommands.h"
 #include "binsequencecommand.h"
 #include "getoturepcommand.h"
+#include "treegroupscommand.h"
 
 
 /***********************************************************/
@@ -83,6 +83,7 @@ Command* CommandFactory::getCommand(string commandName){
                else if(commandName == "venn")                                  {   command = new VennCommand();                                }
                else if(commandName == "bin.seqs")                              {   command = new BinSeqCommand();                              }
                else if(commandName == "get.oturep")                    {   command = new GetOTURepCommand();                   }
+               else if(commandName == "tree.groups")                   {   command = new TreeGroupCommand();                   }
                else                                                                                    {       command = new NoCommand();                                      }
 
                return command;
index 9bbba573057e23c820e24a5c1d6d8c62e7fc5d5b..f715b8488c626e1de22e46b6e624d04d599f76d1 100644 (file)
@@ -10,6 +10,8 @@
  *
  */
 
+#include "mothur.h"
+
 class Command;
 
 class CommandFactory {
index dcfcf435cbb5d896cc41f9e20c07e54ca44c6a4d..a46c0a6ccfc47859d06ae6cae21e87a441be460c 100644 (file)
 
 using namespace std;
 
+
 #include "globaldata.hpp"
 #include "commandoptionparser.hpp"
-#include "mothur.h"
+
 
 //**********************************************************************************************************************
 //This Function parses through the command line and pulls out the command then sends the options to  the parseGlobalData
index 6a616289e024cb0656e338e0a73f7aed31c98c1c..f83f60e0064519f3e2c79ed63bb5e78fddf7065a 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef COMMANDOPTIONPARSER_HPP
 #define COMMANDOPTIONPARSER_HPP
 
+#include "mothur.h"
+
 //**********************************************************************************************************************
 
 class CommandOptionParser {
index b661d41402fc715b8073266d11c23224ad65a781..933bed4769f9d79ff3ba7acd0ce26f472566be23 100644 (file)
@@ -9,7 +9,7 @@
 
 using namespace std;
 
-#include "mothur.h"
+
 #include "sequence.hpp"
 #include "database.hpp"
 
index e497fa42fea869d84502387638279a8a9896bbab..e80bfb5949a3ce9584ae15a136a255284b9f740f 100644 (file)
@@ -10,6 +10,8 @@
  *
  */
 
+#include "mothur.h"
+
 class Database {
 public:
        Database(string);
index c80bb360533a8b08e819d820d72f431f722c9e1b..fe5c0db5587d9909fdad12d1f65cb916f5901043 100644 (file)
@@ -10,7 +10,6 @@
  */
 
 #include "command.hpp"
-#include "utilities.hpp"
 #include "fastamap.h"
 #include "globaldata.hpp"
 
index 5e56479f2851f89e324f8c62dc54250324da7d66..68a75005f1521411227b20fe9ed253ec0b902e1c 100644 (file)
  */
 using namespace std;
 
-
-#include "utilities.hpp"
-#include "globaldata.hpp"
-#include "commandoptionparser.hpp"
-#include "command.hpp"
-#include "commandfactory.hpp"
-#include "errorchecking.h"
 #include "engine.hpp"
 
 /***********************************************************************/
index c04cd4ed69306116f7eb72e64bf5fd2e01d92015..a35b616e6cce63d541684e057a76248481af29ca 100644 (file)
 
 
 #include "mothur.h"
+#include "globaldata.hpp"
+#include "commandoptionparser.hpp"
+#include "command.hpp"
+#include "commandfactory.hpp"
+#include "errorchecking.h"
+
 
 using namespace std;
 
index abd2a9ffeca07f4f11e9d69f283f09afc535a056..841cad2ddddea905faaf91dca54f193b0221a6ea 100644 (file)
@@ -111,6 +111,8 @@ bool ErrorCheck::checkInput(string input) {
                                if (parameter == "abund" )          { abund = value; }
                                if (parameter == "random" )                     { randomtree = value;   }
                                if (parameter == "sorted" )                     { sorted = value;       }
+                               if (parameter == "scaler" )                     { scaler = value;       }
+                               
                        }
                        
                        //gets the last parameter and value
@@ -144,6 +146,7 @@ bool ErrorCheck::checkInput(string input) {
                                if (parameter == "random" )                     { randomtree = value;   }
                                if (parameter == "abund" )          { abund = value; }
                                if (parameter == "sorted" )                     { sorted = value;       }
+                               if (parameter == "scaler" )                     { scaler = value;       }
                        }
                }
                
@@ -216,10 +219,10 @@ bool ErrorCheck::checkInput(string input) {
                        if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { cout << "You must read a list, sabund or rabund before you can use the collect.single, rarefaction.single or summary.single commands." << endl; return false; }
                }
                
-               if ((commandName == "collect.shared") || (commandName == "rarefaction.shared") || (commandName == "summary.shared") ){ 
+               if ((commandName == "collect.shared") || (commandName == "rarefaction.shared") || (commandName == "summary.shared") || (commandName == "tree.groups") ){ 
                        if (globaldata->getSharedFile() == "") {
-                               if (globaldata->getListFile() == "") { cout << "You must read a list and a group, or a shared before you can use the collect.shared, rarefaction.shared or summary.shared commands." << endl; return false; }
-                               else if (globaldata->getGroupFile() == "") { cout << "You must read a list and a group, or a shared before you can use the collect.shared, rarefaction.shared or summary.shared commands." << endl; return false; }
+                               if (globaldata->getListFile() == "") { cout << "You must read a list and a group, or a shared before you can use the collect.shared, rarefaction.shared, summary.shared or tree.groups commands." << endl; return false; }
+                               else if (globaldata->getGroupFile() == "") { cout << "You must read a list and a group, or a shared before you can use the collect.shared, rarefaction.shared, summary.shared or tree.groups commands." << endl; return false; }
                        }
                }
                
index 0d6da746edaf0d7d5aad0158aaf8fd41c7656572..3ddc65c962cbe35ec8e0d7acb0389e113efdc12f 100644 (file)
@@ -13,7 +13,7 @@
 #include "globaldata.hpp"
 #include "validcommands.h"
 #include "validparameter.h"
-#include "utilities.hpp"
+
 
 class ErrorCheck {
        public:
@@ -34,7 +34,7 @@ class ErrorCheck {
                void clear();
                void refresh();
                string phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, orderfile, fastafile, treefile, sharedfile, cutoff, format; 
-               string precision, method, fileroot, label, line, iters, jumble, freq, single, rarefaction, shared, summary, randomtree, abund, sorted;
+               string precision, method, fileroot, label, line, iters, jumble, freq, single, rarefaction, shared, summary, randomtree, abund, sorted, scaler;
                string commandName, optionText;
                bool errorFree;
 
index 6dd4cba381c08e4f0717f996beeb762ee146aaa4..355a8df51786bdac9c229aed9d4233bd46d41c3e 100644 (file)
@@ -13,7 +13,6 @@
 using namespace std;
  
 #include "mothur.h"
-#include "utilities.hpp"
 
 
 /* This class represents the fasta file.  It reads a fasta file a populates the internal data structure "data".
index 2f7639fbbcfec3233f5388e66e2e34637e4d90fe..e6f069dd894e7fe5702b63e5fe6e4c3ce85bc25e 100644 (file)
@@ -85,8 +85,13 @@ void ThreeColumnFile::resetFile(){
                        outFile.close();
                }
                counter = 1;
+               
                remove(inName.c_str());
-               rename(outName.c_str(), inName.c_str());
+               renameOk = rename(outName.c_str(), inName.c_str());
+               
+               //checks to make sure user was able to rename and remove successfully
+               if ((renameOk != 0)) { cout << "Unable to rename necessary files." << endl; }
+
        }
        catch(exception& e) {
                cout << "Standard Error: " << e.what() << " has occurred in the ThreeColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
@@ -101,6 +106,112 @@ void ThreeColumnFile::resetFile(){
 /***********************************************************************/
 /***********************************************************************/
 
+ThreeColumnFile2::~ThreeColumnFile2(){
+       
+       inFile.close();
+       outFile.close();
+       remove(outName.c_str());
+};
+
+/***********************************************************************/
+
+void ThreeColumnFile2::initFile(string label, vector<string> tags){
+       try {
+               if(counter != 0){
+                       openOutputFile(outName, outFile);
+                       openInputFile(inName, inFile);
+
+                       string inputBuffer;
+                       getline(inFile, inputBuffer);
+               
+                       outFile <<  inputBuffer << '\t'; 
+                       for(int i = 1; i < tags.size(); i++) {
+                               outFile << label + tags[i] << '\t';
+                       }
+                       outFile << endl;
+               }
+               else{
+                       openOutputFile(outName, outFile);
+                       for(int i = 0; i < tags.size(); i++) {
+                               outFile << label + tags[i] << '\t';
+                       }
+                       outFile << endl;
+
+               }
+
+               outFile.setf(ios::fixed, ios::floatfield);
+               outFile.setf(ios::showpoint);
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ThreeColumnFile class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ThreeColumnFile class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+void ThreeColumnFile2::output(vector<double> data){
+       try {
+       
+               if(counter != 0){               
+                       string inputBuffer;
+                       getline(inFile, inputBuffer);
+
+                       outFile << inputBuffer << '\t' << setprecision(6) << data[0] << setprecision(globaldata->getIters().length())  << '\t' << data[1] << '\t' << data[2] << endl;
+               }
+               else{
+                       outFile << setprecision(6) << data[0] << setprecision(globaldata->getIters().length())  << '\t' << data[1] << '\t' << data[2] << endl;
+
+               }
+
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ThreeColumnFile2 class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ThreeColumnFile2 class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+};
+
+/***********************************************************************/
+
+void ThreeColumnFile2::resetFile(){
+       try {
+               if(counter != 0){
+                       outFile.close();
+                       inFile.close();
+               }
+               else{
+                       outFile.close();
+               }
+               counter = 1;
+               
+               remove(inName.c_str());
+               renameOk = rename(outName.c_str(), inName.c_str());
+               
+               //checks to make sure user was able to rename and remove successfully
+               if ((renameOk != 0)) { cout << "Unable to rename necessary files." << endl; }
+
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ThreeColumnFile2 class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ThreeColumnFile2 class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
+/***********************************************************************/
+
 SharedThreeColumnFile::~SharedThreeColumnFile(){
        
        inFile.close();
@@ -177,7 +288,11 @@ void SharedThreeColumnFile::resetFile(){
                }
                counter = 1;
                remove(inName.c_str());
-               rename(outName.c_str(), inName.c_str());
+               renameOk = rename(outName.c_str(), inName.c_str());
+               
+               //checks to make sure user was able to rename and remove successfully
+               if ((renameOk != 0)) { cout << "Unable to rename necessary files." << endl; }
+
        }
        catch(exception& e) {
                cout << "Standard Error: " << e.what() << " has occurred in the SharedThreeColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
@@ -268,7 +383,11 @@ void OneColumnFile::resetFile(){
                }       
                counter = 1;
                remove(inName.c_str());
-               rename(outName.c_str(), inName.c_str());
+               renameOk = rename(outName.c_str(), inName.c_str());
+               
+               //checks to make sure user was able to rename and remove successfully
+               if ((renameOk != 0)) { cout << "Unable to rename necessary files." << endl; }
+
        }
        catch(exception& e) {
                cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
@@ -366,8 +485,14 @@ void SharedOneColumnFile::resetFile(){
                        outFile.close();
                }       
                counter = 1;
+               
                remove(inName.c_str());
-               rename(outName.c_str(), inName.c_str());
+               renameOk = rename(outName.c_str(), inName.c_str());
+               
+               //checks to make sure user was able to rename and remove successfully
+               if ((renameOk != 0)) { cout << "Unable to rename necessary files." << endl; }
+
+               
        }
        catch(exception& e) {
                cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
index b5784210d0b734ccdf34dabf1b98259f2ec73499..7e9d8d26144be2150d75358e67da2a72a6dafb32 100644 (file)
@@ -2,7 +2,6 @@
 #define FILEOUTPUT_H
 
 #include "mothur.h"
-#include "utilities.hpp"
 #include "globaldata.hpp"
 
 using namespace std;
@@ -18,6 +17,12 @@ public:
        virtual void initFile(string) = 0;
        virtual void resetFile() = 0;
        virtual string getFileName() = 0;
+       virtual void initFile(string, vector<string>) = 0;
+       virtual void output(vector<double>) = 0;
+
+protected:
+       GlobalData* globaldata;
+       int renameOk;
 
 };     
        
@@ -32,6 +37,10 @@ public:
        void output(int, vector<double>);
        void resetFile();
        string getFileName()    { return inName;        };
+       
+       void initFile(string, vector<string>) {};
+       void output(vector<double>) {};
+
 private:
        string inName;
        string outName;
@@ -52,6 +61,10 @@ public:
        void initFile(string);
        void resetFile();
        string getFileName()    { return inName;        };
+       
+       void initFile(string, vector<string>) {};
+       void output(vector<double>) {};
+
 
 private:
        string outName;
@@ -72,6 +85,10 @@ public:
        void initFile(string);
        void resetFile();
        string getFileName()    { return inName;        };
+       
+       void initFile(string, vector<string>) {};
+       void output(vector<double>) {};
+
 
 private:
        string outName;
@@ -93,6 +110,11 @@ public:
        void output(int, vector<double>);
        void resetFile();
        string getFileName()    { return inName;        };
+       
+       
+       void initFile(string, vector<string>) {};
+       void output(vector<double>) {};
+
 private:
        string inName, groupLabel;
        string outName;
@@ -101,6 +123,30 @@ private:
        int counter, numGroup;
 };
 
+/***********************************************************************/
+
+class ThreeColumnFile2 : public FileOutput {
+       
+public:
+       ThreeColumnFile2(string n) : FileOutput(), inName(n), counter(0), outName(getPathName(n) + ".temp." + getSimpleName(n)) { globaldata = GlobalData::getInstance(); };
+       ~ThreeColumnFile2();
+       
+       //to make compatible with parent class
+       void output(int, vector<double>){};
+       void initFile(string){};
+       
+       void initFile(string, vector<string>);
+       void output(vector<double>);
+       void resetFile();
+       string getFileName()    { return inName;        };
+private:
+       string inName;
+       string outName;
+       ifstream inFile;
+       ofstream outFile;
+       int counter;
+};
 
+/***********************************************************************/
 
 #endif
index 8b484de49bcd27c772ead83f10cbf77aa14adf91..1a7c2bfd601340c85cf5b73b06b280550b8f1f60 100644 (file)
--- a/geom.cpp
+++ b/geom.cpp
@@ -8,7 +8,6 @@
  */
 
 #include "geom.h"
-#include "calculator.h"
 
 /***********************************************************************/
 
index d0343daa3cb647957e694cfa101ec5406edf3304..4e2b3a0e685aec843624613df7bda5c7e184b4c1 100644 (file)
@@ -8,6 +8,8 @@
  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
  *
  */
+ /* The get.oturep command outputs a .fastarep file for each distance you specify, selecting one OTU representative for each bin. */
 
 #include "command.hpp"
 #include "globaldata.hpp"
index 67c49bd28c942d5c432538b6f965406c0b592ae6..2c02ca9ad560f73ecea8277420fb569b04844d82 100644 (file)
@@ -1,9 +1,6 @@
 #include "globaldata.hpp"
-#include "sparsematrix.hpp"
 #include "tree.h"
-#include "rabundvector.hpp"
-#include "sabundvector.hpp"
-#include "listvector.hpp"
+#include "sparsematrix.hpp"
 
 /*******************************************************/
 
@@ -76,6 +73,7 @@ void GlobalData::parseGlobalData(string commandString, string optionText){
                                if (key == "step")                      { step = value;                 }
                                if (key == "form")                      { form = value;                 }
                                if (key == "sorted")            { sorted = value;               }
+                               if (key == "scaler")            { scaler = value;               }
                                
 
                                
@@ -131,6 +129,8 @@ void GlobalData::parseGlobalData(string commandString, string optionText){
                        if (key == "step")                      { step = value;                 }
                        if (key == "form")                      { form = value;                 }
                        if (key == "sorted")            { sorted = value;               }
+                       if (key == "scaler")            { scaler = value;               }
+                       
 
                        if (key == "line") {//stores lines to be used in a vector
                                lines.clear();
@@ -140,6 +140,7 @@ void GlobalData::parseGlobalData(string commandString, string optionText){
                                if (line != "all") {  splitAtDash(value, lines);  allLines = 0;  }
                                else { allLines = 1;  }
                        }
+                       
                        if (key == "label") {//stores lines to be used in a vector
                                labels.clear();
                                lines.clear();
@@ -199,6 +200,13 @@ void GlobalData::parseGlobalData(string commandString, string optionText){
                        Estimators.clear();
                        splitAtDash(calc, Estimators); 
                }
+               if (commandName == "tree.groups") {
+                       if (calc != "") { 
+                               Estimators.clear();
+                               splitAtDash(calc, Estimators);                  
+                       }else { cout << "You have not specified any calculators." << endl; }
+               }
+
 
                //if you have done a read.otu with a groupfile but don't want to use it anymore because you want to do single commands
                if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single")) {
@@ -245,6 +253,7 @@ string GlobalData::getGroups()                      {       return groups;          }
 string GlobalData::getStep()                   {       return step;            }
 string GlobalData::getForm()                   {       return form;            }
 string GlobalData::getSorted()                 {       return sorted;          }
+string GlobalData::getScaler()                 {       return scaler;          }
 void GlobalData::setListFile(string file)      {       listfile = file;        inputFileName = file;}
 void GlobalData::setRabundFile(string file)    {       rabundfile = file;      inputFileName = file;}
 void GlobalData::setSabundFile(string file)    {       sabundfile = file;      inputFileName = file;}
@@ -296,6 +305,7 @@ void GlobalData::clear() {
        step                    =       "0.01";
        form                    =       "integral";
        sorted                  =       "1";  //0 means don't sort, 1 means sort.
+       scaler                  =       "log2";
 }
 
 //*******************************************************/
index 0abdd28cd18bcfc617ab105069cf15db5ead241b..3b688b43457d318c8f73471bb088d7ad5de1affb 100644 (file)
@@ -5,6 +5,11 @@
 #include "groupmap.h"
 #include "treemap.h"
 
+#include "rabundvector.hpp"
+#include "sabundvector.hpp"
+#include "listvector.hpp"
+
+
 using namespace std;
 
 class ListVector;
@@ -17,6 +22,7 @@ class InputData;
 class GroupMap;
 class TreeMap;
 class SAbundVector;
+class RAbundVector;
 
 class GlobalData {
 public:
@@ -64,6 +70,7 @@ public:
        string getStep();
        string getForm();
        string getSorted();
+       string getScaler();
 
        void setListFile(string);
        void setPhylipFile(string);
@@ -90,7 +97,7 @@ public:
                
 private:
        string phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, orderfile, fastafile, treefile, sharedfile, line, label, randomtree, groups;
-       string cutoff, format, precision, method, fileroot, iters, jumble, freq, calc, abund, step, form, sorted;
+       string cutoff, format, precision, method, fileroot, iters, jumble, freq, calc, abund, step, form, sorted, scaler;
 
        static GlobalData* _uniqueInstance;
        GlobalData( const GlobalData& ); // Disable copy constructor
index 20048a59a5f5aaa3658dd5697f26e3f255a978e1..d69699d382530f688a0f6023f90b1ffed1bdfffe 100644 (file)
@@ -10,7 +10,6 @@
  */
 
 #include "mothur.h"
-#include "utilities.hpp"
 
 /* This class is a representation of the groupfile.  It is used by all the shared commands to determine what group a 
        certain sequence belongs to. */
index 4ce6f2c2e6cc01a376cb4c56d9a222d33e55de50..75a2b873f917dfc872d443f73bb17e7d21dbb2db 100644 (file)
@@ -15,6 +15,7 @@ HeatMap::HeatMap(){
                globaldata = GlobalData::getInstance();
                format = globaldata->getFormat();
                sorted = globaldata->getSorted();
+               util = new SharedUtil();
                
        }
        catch(exception& e) {
@@ -45,7 +46,7 @@ void HeatMap::getPic(OrderVector* order) {
                        if(it->second.length() == 1) {  it->second = "0" + it->second;  }
                }
 
-               string filenamesvg = globaldata->inputFileName + ".heatmap." + order->getLabel() + ".svg";
+               string filenamesvg = getRootName(globaldata->inputFileName) + order->getLabel() + ".heatmap.svg";
                
                openOutputFile(filenamesvg, outsvg);
                
@@ -86,50 +87,104 @@ void HeatMap::getPic(SharedOrderVector* sharedorder) {
                colorScale.clear();
                
                //fills vector of sharedsabunds - lookup
-               getSharedVectors(sharedorder);
+               util->getSharedVectors(globaldata->Groups, lookup, sharedorder);  //fills group vectors from order vector.
                
                //sort lookup so shared bins are on top
                if (sorted == "1") {  sortSharedVectors();  }
                
-               //get maxBin
+               //get users scaling method
+               scaler = globaldata->getScaler();
+               
+               int maxbin = 0;
                for (int i = 0; i < lookup.size(); i++) {
                        for (int j = 0; j < lookup[i]->size(); j++) {
-                               colorScale[lookup[i]->getAbundance(j)] = "";
+                               //if (lookup[i]->getAbundance(j) != 0) { //don't want log value of 0.
+                                       //if (scaler == "log10") {
+                                       //      colorScale[-log((log10(lookup[i]->getAbundance(j)) / (float)lookup[i]->getNumSeqs()))] = "";  
+       //cout << "abundance  = " << lookup[i]->getAbundance(j) << '\t' << " relative adundance = " << (lookup[i]->getAbundance(j) / (float)lookup[i]->getNumSeqs()) << '\t';
+       //cout << -log((log10(lookup[i]->getAbundance(j)) / lookup[i]->getNumSeqs())) << endl;
+                                       //}else if (scaler == "log2") {
+                                               //colorScale[-log((log2(lookup[i]->getAbundance(j)) / (float)lookup[i]->getNumSeqs()))] = "";  //cout << (int)log2(lookup[i]->getAbundance(j)) << endl;
+       //cout << "abundance  = " << lookup[i]->getAbundance(j) << '\t' << " relative adundance = " << lookup[i]->getAbundance(j) / (float)lookup[i]->getNumSeqs() << '\t';
+       //cout << -log((log2(lookup[i]->getAbundance(j)) / lookup[i]->getNumSeqs())) << endl;
+                               //      }else if (scaler == "linear") {
+                                               colorScale[lookup[i]->getAbundance(j)] = "";
+                                               if (maxbin < lookup[i]->getAbundance(j)) { maxbin = lookup[i]->getAbundance(j); }
+       //cout << "abundance  = " << lookup[i]->getAbundance(j) << '\t' << " relative adundance = " << lookup[i]->getAbundance(j) / (float)lookup[i]->getNumSeqs() << '\t';
+       //cout << lookup[i]->getAbundance(j) /(float) lookup[i]->getNumSeqs() << endl;
+                                       //}else {  //if user enters invalid scaler option.
+                                       //      cout << scaler << " is not a valid scaler option. I will use log10." << endl;
+                                       //      colorScale[-log(log10(lookup[i]->getAbundance(j) / lookup[i]->getNumSeqs()))] = "";   
+                                       //} 
+                               //}else { colorScale[0] = "00";  }
+                               
                        }
                }
                
                //get scaler
-               float scaler = 255 / (float) colorScale.size();
+               float scalers = 255 / (float) maxbin;
                
                //go through map and give each score a color value
                for (it = colorScale.begin(); it != colorScale.end(); it++) {
-                       it->second = toHex(int(float(it->first) * scaler));
+                       it->second = toHex(int(float(it->first) * scalers));
                        if(it->second.length() == 1) {  it->second = "0" + it->second;  }
+//cout << it->first << " " << it->second << endl;
                }
                
-               string filenamesvg = globaldata->inputFileName + ".heatmap." + sharedorder->getLabel() + "." + groupComb + ".svg";
+               string filenamesvg = getRootName(globaldata->inputFileName) + sharedorder->getLabel() + ".heatmap.svg";
                openOutputFile(filenamesvg, outsvg);
                
                //svg image
-               outsvg << "<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 " + toString(lookup.size() * 300) + " " + toString((lookup[0]->getNumBins()*5 + 15))  + "\">\n";
+               outsvg << "<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 " + toString(lookup.size() * 300) + " " + toString((lookup[0]->getNumBins()*5 + 120))  + "\">\n";
                outsvg << "<g>\n";
                
-               int x = 15;
-               int y = 15;
+               //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";
+               
+               //column labels
+               for (int h = 0; h < lookup.size(); h++) {
+                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(((300 * (h+1)) - 150) - ((int)lookup[h]->getGroup().length() / 2)) + "\" y=\"50\">" + lookup[h]->getGroup() + "</text>\n"; 
+               }
+               
+               
+               //output legend and color labels
+               //go through map and give each score a color value
                string color;
-
-               for (int i = 0; i <= lookup[0]->getNumBins(); i++) {
+               int x = 0;
+               int y = 90 + (lookup[0]->getNumBins()*5);
+               for (it = colorScale.begin(); it != colorScale.end(); it++) {
+                       color = it->second;     
+                       outsvg << "<rect fill=\"#" + color + "0000\" stroke=\"#" + color + "0000\" x=\"" + toString(x) + "\" y=\"" + toString(y) + "\" width=\"25\" height=\"10\"/>\n";
+                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(x) + "\" y=\"" + toString(y) + "\">" + toString(it->first) + "</text>\n";
+                       x += 25;
+               }
+               
+               x = 0;
+               y = 70;
                
+               //start at 1 since bin 0 is nothing
+               for (int i = 1; i <= lookup[0]->getNumBins(); i++) {
                        for (int j = 0; j < lookup.size(); j++) {
-                       
-                               color = colorScale[lookup[j]->getAbundance(i)]; 
-                                               
+                               
+                               //if (lookup[j]->getAbundance(i) != 0) { //don't want log value of 0.
+                                       //if (scaler == "log10") {
+                                       //      color = colorScale[(int)log10(lookup[j]->getAbundance(i))];  
+                                       //}else if (scaler == "log2") {
+                                       //      color = colorScale[(int)log2(lookup[j]->getAbundance(i))];  
+                               //      }else if (scaler == "linear") {
+                                               color = colorScale[lookup[j]->getAbundance(i)]; 
+                                       //}else {  color = colorScale[(int)log10(lookup[j]->getAbundance(i))];  } 
+                               //}else { color = "OO";  }
+
+                               
                                outsvg << "<rect fill=\"#" + color + "0000\" stroke=\"#" + color + "0000\" x=\"" + toString(x) + "\" y=\"" + toString(y) + "\" width=\"300\" height=\"5\"/>\n";
                                x += 300;
                        }
-                       x = 15;
+                       x = 0;
                        y += 5;
                }
+               
                outsvg << "</g>\n</svg>\n";
                
                outsvg.close();
@@ -146,57 +201,6 @@ void HeatMap::getPic(SharedOrderVector* sharedorder) {
                exit(1);
        }
 }
-//**********************************************************************************************************************
-void HeatMap::getSharedVectors(SharedOrderVector* order){
-       try {
-       
-               //delete lookup
-               for (int j = 0; j < lookup.size(); j++) {
-                       delete lookup[j];
-               }
-
-               lookup.clear();
-               
-               groupComb = "";
-               
-               //create and initialize vector of sharedvectors, one for each group
-               for (int i = 0; i < globaldata->Groups.size(); i++) { 
-                       SharedRAbundVector* temp = new SharedRAbundVector(order->getNumBins());
-                       temp->setLabel(order->getLabel());
-                       temp->setGroup(globaldata->Groups[i]);
-                       groupComb += globaldata->Groups[i];
-                       lookup.push_back(temp);
-               }
-               
-               int numSeqs = order->size();
-               //sample all the members
-               for(int i=0;i<numSeqs;i++){
-                       //get first sample
-                       individual chosen = order->get(i);
-                       int abundance; 
-                                       
-                       //set info for sharedvector in chosens group
-                       for (int j = 0; j < lookup.size(); j++) { 
-                               if (chosen.group == lookup[j]->getGroup()) {
-                                        abundance = lookup[j]->getAbundance(chosen.bin);
-                                        lookup[j]->set(chosen.bin, (abundance + 1), chosen.group);
-                                        break;
-                               }
-                       }
-               }
-               
-       }
-       catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the HeatMap class Function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the HeatMap class function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-
-}
-
 
 //**********************************************************************************************************************
 void HeatMap::sortSharedVectors(){
@@ -206,8 +210,10 @@ void HeatMap::sortSharedVectors(){
                //if they are then insert in the front
                //if not push to back
                
-               bool shared;
                vector<SharedRAbundVector*> looktemp;
+               map<int, int> place; //spot in lookup where you insert shared by, ie, 3 -> 2 if they are shared by 3 inset into location 2.
+               map<int, int>::iterator it;
+               int count;
                
                //create and initialize looktemp as a copy of lookup
                for (int i = 0; i < lookup.size(); i++) { 
@@ -227,22 +233,37 @@ void HeatMap::sortSharedVectors(){
                //create and initialize lookup to empty vectors
                for (int i = 0; i < looktemp.size(); i++) { 
                        SharedRAbundVector* temp = new SharedRAbundVector();
-                       lookup.push_back(temp);
+                       temp->setLabel(looktemp[i]->getLabel());
+                       temp->setGroup(looktemp[i]->getGroup());
+                       lookup.push_back(temp); 
+                       
+                       //initialize place map
+                       place[i] = 0;
                }
                
+               
                //for each bin
                for (int i = 0; i < looktemp[0]->size(); i++) {
-                       shared = true;
+                       count = 0;
+                       bool updatePlace = false;
                        //for each group
                        for (int j = 0; j < looktemp.size(); j++) {
-                               if (looktemp[j]->getAbundance(i) == 0) { shared = false; }
+                               if (looktemp[j]->getAbundance(i) != 0) { count++; }
                        }
                        
                        //fill lookup
                        for (int j = 0; j < looktemp.size(); j++) {
                                //if they are not shared then push to back, if they are not insert in front
-                               if (shared == false)  { lookup[j]->push_back(looktemp[j]->getAbundance(i), i, looktemp[j]->getGroup()); }
-                               else { lookup[j]->push_front(looktemp[j]->getAbundance(i), i, looktemp[j]->getGroup()); }
+                               if (count < 2)  { lookup[j]->push_back(looktemp[j]->getAbundance(i), i, looktemp[j]->getGroup()); }
+                               //they are shared by some
+                               else {  lookup[j]->insert(looktemp[j]->getAbundance(i), place[count], looktemp[j]->getGroup());   updatePlace = true; }
+                       }
+                       
+                       if (updatePlace == true) {
+                               //move place holders below where you entered up to "make space" for you entry
+                               for (it = place.begin(); it!= place.end(); it++) {  
+                                       if (it->first < count) { it->second++; }
+                               }
                        }
                }
                
index e236ce389795e00e20fce97cd645377e83657c1b..a89500c004c9b61e2a73a37407c26b98979e5da0 100644 (file)
--- a/heatmap.h
+++ b/heatmap.h
@@ -17,6 +17,7 @@ using namespace std;
 #include "sharedordervector.h"
 #include "datavector.hpp"
 #include "globaldata.hpp"
+#include "sharedutilities.h"
 
 /***********************************************************************/
 
@@ -24,22 +25,22 @@ class HeatMap {
        
        public:
                HeatMap();
-               ~HeatMap(){};
+               ~HeatMap(){ delete util; };
        
                void getPic(OrderVector*);
                void getPic(SharedOrderVector*);
 
        private:
-               void getSharedVectors(SharedOrderVector*);
                void sortSharedVectors();
                
                GlobalData* globaldata;
+               SharedUtil* util;
                vector<SharedRAbundVector*> lookup;
                RAbundVector rabund;
-               string format, sorted, groupComb;
+               string format, sorted, groupComb, scaler;
                ofstream outsvg;
-               map<int, string> colorScale;
-               map<int, string>::iterator it;
+               map<float, string> colorScale;
+               map<float, string>::iterator it;
 
                        
 };
index 10264c87951668a890b92903d87073fed2b0aa03..82aa12ce66821443c9cedce4628fad3e43d01674 100644 (file)
@@ -17,6 +17,7 @@ HeatMapCommand::HeatMapCommand(){
                globaldata = GlobalData::getInstance();
                heatmap = new HeatMap();
                format = globaldata->getFormat();
+               util = new SharedUtil();
                
        }
        catch(exception& e) {
@@ -34,6 +35,7 @@ HeatMapCommand::~HeatMapCommand(){
        delete input;
        delete read;
        delete heatmap;
+       delete util;
 }
 
 //**********************************************************************************************************************
@@ -65,12 +67,14 @@ int HeatMapCommand::execute(){
                        ordersingle = globaldata->gorder;
                        input = globaldata->ginput;
                }
-
                
+                               
                if (format != "list") { 
-                       
-                       setGroups();
-                       
+               
+                       util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "heat");
+                       globaldata->setGroups("");
+
+
                        while(order != NULL){
                
                                if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){                       
@@ -96,7 +100,7 @@ int HeatMapCommand::execute(){
                        }
                        
                        //reset groups parameter
-                       globaldata->Groups.clear();  globaldata->setGroups("");
+                       globaldata->Groups.clear();  
                        
                }else{
                        while(ordersingle != NULL){
@@ -126,50 +130,5 @@ int HeatMapCommand::execute(){
 }
 
 //**********************************************************************************************************************
-void HeatMapCommand::setGroups() {
-       try {
-               //if the user has not entered specific groups to analyze then do them all
-               if (globaldata->Groups.size() != 0) {
-                       if (globaldata->Groups[0] != "all") {
-                               //check that groups are valid
-                               for (int i = 0; i < globaldata->Groups.size(); i++) {
-                                       if (globaldata->gGroupmap->isValidGroup(globaldata->Groups[i]) != true) {
-                                               cout << globaldata->Groups[i] << " is not a valid group, and will be disregarded." << endl;
-                                               // erase the invalid group from globaldata->Groups
-                                               globaldata->Groups.erase(globaldata->Groups.begin()+i);
-                                       }
-                               }
-                       
-                               //if the user only entered invalid groups
-                               if (globaldata->Groups.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 < globaldata->gGroupmap->namesOfGroups.size(); i++) {
-                                               globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
-                                       }
-                               }
-                       }else{//user has enter "all" and wants the default groups
-                               globaldata->Groups.clear();
-                               for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
-                                       globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
-                               }
-                               globaldata->setGroups("");
-                       }
-               }else {
-                       for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
-                               globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
-                       }
-               }
-               
-       }
-       catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the HeatMapCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the HeatMapCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }               
 
-}
-/***********************************************************/
 
index 5eeae265471785c8d582e7b250c76046554711e7..f75c06425e7b6af1232809fb8a2f1f98c20d98aa 100644 (file)
@@ -16,6 +16,7 @@
 #include "readmatrix.hpp"
 #include "sharedlistvector.h"
 #include "heatmap.h"
+#include "sharedutilities.h"
 
 
 class GlobalData;
@@ -31,14 +32,13 @@ public:
 private:
        GlobalData* globaldata;
        ReadMatrix* read;
+       SharedUtil* util;
        InputData* input;
        SharedListVector* SharedList;
        SharedOrderVector* order;
        OrderVector* ordersingle;
        HeatMap* heatmap;
        string format;
-       
-       void setGroups();
 
 };
 
index 05aaff0b0d58a46b380223b5b52ed84812e38c57..7ac616feb6cc82be610c73a7e853d50a17693998 100644 (file)
@@ -194,14 +194,16 @@ int HelpCommand::execute(){
                cout << "Note: No spaces between parameter labels (i.e. iters), '=' and parameters (i.e.yourIters)." << "\n" << "\n";
        }else if (globaldata->helpRequest == "heatmap") { 
                cout << "The heatmap command can only be executed after a successful read.otu command." << "\n";
-               cout << "The heatmap command parameters are groups, sorted, line and label.  No parameters are required, but you may not use line and label at the same time." << "\n";
+               cout << "The heatmap command parameters are groups, sorted, scaler, line and label.  No parameters are required, but you may not use line and label at the same time." << "\n";
                cout << "The groups parameter allows you to specify which of the groups in your groupfile you would like included in your heatmap." << "\n";
-               cout << "The sorted parameter allows you to choose to see the file with the shared otus at the top or the exact representation of your input file. " << "\n";
+               cout << "The sorted parameter allows you to choose to see the file with the shared otus at the top or the otus in the order they appear in your input file. " << "\n";
+               cout << "The scaler parameter allows you to choose the range of color your bin information will be displayed with." << "\n";
                cout << "The group names are separated by dashes. The line and label allow you to select what distance levels you would like a heatmap created for, and are also separated by dashes." << "\n";
                cout << "The heatmap command should be in the following format: heatmap(groups=yourGroups, sorted=yourSorted, line=yourLines, label=yourLabels)." << "\n";
-               cout << "Example heatmap(groups=A-B-C, line=1-3-5, sorted=0)." << "\n";
+               cout << "Example heatmap(groups=A-B-C, line=1-3-5, sorted=0, scaler=log10)." << "\n";
                cout << "The default value for groups is all the groups in your groupfile, and all lines in your inputfile will be used." << "\n";
                cout << "The default value for sorted is 1 meaning you want the shared otus on top, you may change it to 0 meaning the exact representation of your input file." << "\n";
+               cout << "The default value for scaler is log2; your other options are log10 and linear." << "\n";
                cout << "The heatmap command outputs a .svg file for each line or label you specify." << "\n";
                cout << "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups)." << "\n" << "\n";
        }else if (globaldata->helpRequest == "venn") { 
@@ -213,6 +215,8 @@ int HelpCommand::execute(){
                cout << "Example venn(groups=A-B-C, line=1-3-5, calc=sharedsobs-sharedchao)." << "\n";
                cout << "The default value for groups is all the groups in your groupfile up to 4, and all lines in your inputfile will be used." << "\n";
                cout << "The default value for calc is sobs if you have only read a list file or if you have selected only one group, and sharedsobs if you have multiple groups." << "\n";
+               cout << "The default available estimators for calc are sobs, chao and ace if you have only read a list file, and sharedsobs, sharedchao and sharedace if you have read a list and group file or a shared file." << "\n";
+               cout << "The only estmiator available four 4 groups is sharedsobs." << "\n";
                cout << "The venn command outputs a .svg file for each calculator you specify at each distance you choose." << "\n";
                cout << "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups)." << "\n" << "\n";
        }else if (globaldata->helpRequest == "bin.seqs") { 
index 592367a5fbf0c07f0587a577551654173eb5e15a..c8259d90850c7d1c9f0ca0e2ba3a8f763e52f2e6 100644 (file)
@@ -10,7 +10,6 @@
 #include "inputdata.h"
 #include "ordervector.hpp"
 #include "listvector.hpp"
-#include "utilities.hpp"
 
 /***********************************************************************/
 
index 5f962a63412ea042904a4ce8397a6ae4da9d3ad6..875cec54e9a8547341f060de8cba73eca1517a4d 100644 (file)
--- a/kmer.cpp
+++ b/kmer.cpp
@@ -9,7 +9,7 @@
 
 using namespace std;
 
-#include "mothur.h"
+
 #include "kmer.hpp"
 
 /**************************************************************************************************/
index 75ec5384ad2d3724bc61688616a7eb2ca6c9d252..21a18e3ab801a9c07a3aa18f5a16e0481f65eb6b 100644 (file)
--- a/kmer.hpp
+++ b/kmer.hpp
@@ -10,6 +10,8 @@
  *
  */
 
+#include "mothur.h"
+
 /**************************************************************************************************/
 
 class Kmer {
index a5094f0a862b057c571798180b6c064dc77509bf..ee8168a328a07bd8dbed1da1f6b4fa3ab0aebca7 100644 (file)
@@ -9,7 +9,7 @@
 
 using namespace std;
 
-#include "mothur.h"
+
 #include "sequence.hpp"
 #include "kmer.hpp"
 #include "database.hpp"
index 0088efdb27e06c0768367d1b387e518ff7ff684c..af52789dedc231eb5495f4a2f10cbc0efe73a37c 100644 (file)
@@ -10,6 +10,8 @@
  *
  */
 
+#include "mothur.h"
+
 class KmerDB : public Database {
        
 public:
index 9005dc0ad450161c580a2ed2dc5074afb8e53912..205fe607eadaf8c15a9e93e3c10b8ecda62629a7 100644 (file)
@@ -13,7 +13,6 @@ using namespace std;
 #include "sabundvector.hpp"
 #include "rabundvector.hpp"
 #include "ordervector.hpp"
-#include "utilities.hpp"
 #include "listvector.hpp"
 
 
index 94fa4590d79eeac44ee5b1019dc5fb2daf512001..7b63e5bf8c7fdd84b253e68e1b11aebbcd019527 100644 (file)
--- a/logsd.cpp
+++ b/logsd.cpp
@@ -8,7 +8,6 @@
  */
 
 #include "logsd.h"
-#include "calculator.h"
 
 /***********************************************************************/
 
index 8c55240965b5481bae5a551488c6e3ac957ee494..c60644d027d7fee1f1e18ce90b5a4458c411ef3b 100644 (file)
@@ -13,6 +13,8 @@
 
 using namespace std;
 
+/**************************************************************************************************/
+
 GlobalData* GlobalData::_uniqueInstance = 0;
 
 int main(int argc, char *argv[]){
@@ -46,3 +48,5 @@ int main(int argc, char *argv[]){
        }
 }
 
+/**************************************************************************************************/
+
index e5c389005df83b47e45504433269ac7735f6a8c4..36d7b28ebf45dd3f4bf1d0555c74f4e99c841fe9 100644 (file)
--- a/mothur.h
+++ b/mothur.h
@@ -13,7 +13,7 @@ using namespace std;
  *
  */
 
-/* This file contains all the standard incudes we use in the project. */
+/* This file contains all the standard incudes we use in the project as well as some common utilities. */
 
 
 //io libraries
@@ -40,5 +40,392 @@ using namespace std;
 #include <math.h>
 #include <algorithm>
 
+typedef unsigned long long ull;
+
+
+/***********************************************************************/
+
+// snagged from http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.2
+// works for now, but there should be a way to do it without killing the whole program
+
+class BadConversion : public runtime_error {
+public:
+       BadConversion(const string& s) : runtime_error(s){ }
+};
+
+//**********************************************************************************************************************
+
+template<typename T>
+inline void convert(const string& s, T& x, bool failIfLeftoverChars = true){
+       istringstream i(s);
+       char c;
+       if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
+               throw BadConversion(s);
+}
+//**********************************************************************************************************************
+
+template<typename T>
+inline bool convertTest(const string& s, T& x, bool failIfLeftoverChars = true){
+       istringstream i(s);
+       char c;
+       if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
+       {
+               cout << "'" << s << "' is unable to be converted into an integer.\n";
+               return false;
+       } 
+       return true;
+}
+
+//**********************************************************************************************************************
+
+template<typename T>
+string toString(const T&x){
+    stringstream output;
+    output << x;
+    return output.str();
+}
+
+//**********************************************************************************************************************
+
+template<typename T>
+string toHex(const T&x){
+       stringstream output;
+       
+       output << hex << x;
+
+    return output.str();
+}
+
+//**********************************************************************************************************************
+
+template<typename T>
+string toString(const T&x, int i){
+       stringstream output;
+       
+       output.precision(i);
+    output << fixed << x;
+       
+    return output.str();
+}
+
+
+/***********************************************************************/
+
+inline void gobble(istream& f){
+       
+       char d;
+    while(isspace(d=f.get()))          {;}
+       f.putback(d);
+       
+}
+
+/***********************************************************************/
+
+inline float roundDist(float dist, int precision){
+       
+       return int(dist * precision + 0.5)/float(precision);
+       
+}
+
+/***********************************************************************/
+
+inline int getNumNames(string names){
+       
+       int count = 0;
+       
+       if(names != ""){
+               count = 1;
+               for(int i=0;i<names.size();i++){
+                       if(names[i] == ','){
+                               count++;
+                       }
+               }
+       }
+       
+       return count;
+       
+}
+
+/**************************************************************************************************/
+
+inline vector<vector<double> > binomial(int maxOrder){
+       
+       vector<vector<double> > binomial(maxOrder+1);
+       
+    for(int i=0;i<=maxOrder;i++){
+               binomial[i].resize(maxOrder+1);
+               binomial[i][0]=1;
+               binomial[0][i]=0;
+    }
+    binomial[0][0]=1;
+       
+    binomial[1][0]=1;
+    binomial[1][1]=1;
+       
+    for(int i=2;i<=maxOrder;i++){
+               binomial[1][i]=0;
+    }
+       
+    for(int i=2;i<=maxOrder;i++){
+               for(int j=1;j<=maxOrder;j++){
+                       if(i==j){       binomial[i][j]=1;                                                                       }
+                       if(j>i) {       binomial[i][j]=0;                                                                       }
+                       else    {       binomial[i][j]=binomial[i-1][j-1]+binomial[i-1][j];     }
+               }
+    }
+       
+       return binomial;
+}
+
+/***********************************************************************/
+
+inline string getRootName(string longName){
+       string rootName = longName;
+       
+       if(longName.find_last_of(".") != longName.npos){
+               int pos = longName.find_last_of('.')+1;
+               rootName = longName.substr(0, pos);
+       }
+
+       return rootName;
+}
+/***********************************************************************/
+
+inline string getSimpleName(string longName){
+       string simpleName = longName;
+       
+       if(longName.find_last_of("/") != longName.npos){
+               int pos = longName.find_last_of('/')+1;
+               simpleName = longName.substr(pos, longName.length());
+       }
+
+       return simpleName;
+}
+
+/***********************************************************************/
+
+inline string getPathName(string longName){
+       string rootPathName = longName;
+       
+       if(longName.find_last_of("/") != longName.npos){
+               int pos = longName.find_last_of('/')+1;
+               rootPathName = longName.substr(0, pos);
+       }
+
+       return rootPathName;
+}
+
+/***********************************************************************/
+
+inline int openInputFile(string fileName, ifstream& fileHandle){
+
+       fileHandle.open(fileName.c_str());
+       if(!fileHandle) {
+               cerr << "Error: Could not open " << fileName << endl;
+               return 1;
+       }
+       else {
+               return 0;
+       }
+       
+}
+
+/***********************************************************************/
+
+inline int openOutputFile(string fileName, ofstream& fileHandle){
+       
+       fileHandle.open(fileName.c_str(), ios::trunc);
+       if(!fileHandle) {
+               cerr << "Error: Could not open " << fileName << endl;
+               return 1;
+       }
+       else {
+               return 0;
+       }
+
+}
+
+/***********************************************************************/
+
+//This function parses the estimator options and puts them in a vector
+inline void splitAtDash(string& estim, vector<string>& container) {
+       try {
+               string individual;
+               
+               while (estim.find_first_of('-') != -1) {
+                       individual = estim.substr(0,estim.find_first_of('-'));
+                       if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
+                               estim = estim.substr(estim.find_first_of('-')+1, estim.length());
+                               container.push_back(individual);
+                       }
+               }
+               //get last one
+               container.push_back(estim);
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the mothur class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the mothur class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+
+}
+
+/***********************************************************************/
+//This function parses the label options and puts them in a set
+inline void splitAtDash(string& estim, set<string>& container) {
+       try {
+               string individual;
+               
+               while (estim.find_first_of('-') != -1) {
+                       individual = estim.substr(0,estim.find_first_of('-'));
+                       if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
+                               estim = estim.substr(estim.find_first_of('-')+1, estim.length());
+                               container.insert(individual);
+                       }
+               }
+               //get last one
+               container.insert(estim);
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the mothur class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the mothur class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+
+}
+/***********************************************************************/
+//This function parses the line options and puts them in a set
+inline void splitAtDash(string& estim, set<int>& container) {
+       try {
+               string individual;
+               int lineNum;
+               
+               while (estim.find_first_of('-') != -1) {
+                       individual = estim.substr(0,estim.find_first_of('-'));
+                       if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
+                               estim = estim.substr(estim.find_first_of('-')+1, estim.length());
+                               convert(individual, lineNum); //convert the string to int
+                               container.insert(lineNum);
+                       }
+               }
+               //get last one
+               convert(estim, lineNum); //convert the string to int
+               container.insert(lineNum);
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the mothur class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the mothur class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+
+}
+/***********************************************************************/
+//This function parses the a string and puts peices in a vector
+inline void splitAtComma(string& estim, vector<string>& container) {
+       try {
+               string individual;
+               
+               while (estim.find_first_of(',') != -1) {
+                       individual = estim.substr(0,estim.find_first_of(','));
+                       if ((estim.find_first_of(',')+1) <= estim.length()) { //checks to make sure you don't have comma at end of string
+                               estim = estim.substr(estim.find_first_of(',')+1, estim.length());
+                               container.push_back(individual);
+                       }
+               }
+               //get last one
+               container.push_back(estim);
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the mothur class Function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the mothur class function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+/***********************************************************************/
+
+//This function splits up the various option parameters
+inline void splitAtComma(string& prefix, string& suffix){
+       try {
+               prefix = suffix.substr(0,suffix.find_first_of(','));
+               if ((suffix.find_first_of(',')+2) <= suffix.length()) {  //checks to make sure you don't have comma at end of string
+                       suffix = suffix.substr(suffix.find_first_of(',')+1, suffix.length());
+                       string space = " ";
+                       while(suffix.at(0) == ' ')
+                               suffix = suffix.substr(1, suffix.length());
+               }
+
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the mothur class Function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the mothur class function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+
+}
+/***********************************************************************/
+
+//This function separates the key value from the option value i.e. dist=96_...
+inline void splitAtEquals(string& key, string& value){         
+       try {
+               if(value.find_first_of('=') != -1){
+                       key = value.substr(0,value.find_first_of('='));
+                       if ((value.find_first_of('=')+1) <= value.length()) {
+                               value = value.substr(value.find_first_of('=')+1, value.length());
+                       }
+               }else{
+                       key = value;
+                       value = 1;
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the mothur class Function splitAtEquals. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the mothur class function splitAtEquals. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+
+}
+/**************************************************************************************************/
+
+inline bool inUsersGroups(string groupname, vector<string> Groups) {
+       try {
+               for (int i = 0; i < Groups.size(); i++) {
+                       if (groupname == Groups[i]) { return true; }
+               }
+               return false;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the mothur class Function inUsersGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the mothur class function inUsersGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/**************************************************************************************************/
+
+
 #endif
 
index 3d21e322542b29ff0502987444de77f44045f73d..77b772bfcd130ea0f30d6e3b572fd55a20604239 100644 (file)
@@ -4,7 +4,6 @@
 using namespace std;
 
 #include "mothur.h"
-#include "utilities.hpp"
 #include "listvector.hpp"
 
 class NameAssignment : public map<string,int> {
index 333c280278d3cfa97d2a39373932018ba1d4b918..ccbfa666bac044cd6eeaa639719938d571bad2ea 100644 (file)
@@ -10,7 +10,6 @@
 using namespace std;
 
 #include "ordervector.hpp"
-#include "utilities.hpp"
 
 
 /***********************************************************************/
index 86f8d013c59449b96009ba07859be7e0985cc141..4fa4ec5ed0943614bf4da9d5a1f03b5d8f706a42 100644 (file)
@@ -33,7 +33,17 @@ ParsimonyCommand::ParsimonyCommand() {
                }
                
                //set users groups to analyze
-               setGroups();
+               util = new SharedUtil();
+               util->setGroups(globaldata->Groups, tmap->namesOfGroups, allGroups, numGroups, "unweighted");   //sets the groups the user wants to analyze
+               util->getCombos(groupComb, globaldata->Groups, numComp);
+               globaldata->setGroups("");
+               
+               //ABC
+               if (numComp != 1) {
+                       groupComb.push_back(allGroups);
+                       numComp++;
+               }
+
                convert(globaldata->getIters(), iters);  //how many random trees to generate
                pars = new Parsimony(tmap);
                counter = 0;
@@ -194,7 +204,7 @@ int ParsimonyCommand::execute() {
                //reset randomTree parameter to ""
                globaldata->setRandomTree("");
                //reset groups parameter
-               globaldata->Groups.clear();  globaldata->setGroups("");
+               globaldata->Groups.clear(); 
                
                return 0;
                
@@ -330,90 +340,6 @@ void ParsimonyCommand::getUserInput() {
                exit(1);
        }
 }
-/***********************************************************/
-
-void ParsimonyCommand::setGroups() {
-       try {
-               string allGroups = "";
-               numGroups = 0;
-               //if the user has not entered specific groups to analyze then do them all
-               if (globaldata->Groups.size() != 0) {
-                       if (globaldata->Groups[0] != "all") {
-                               //check that groups are valid
-                               for (int i = 0; i < globaldata->Groups.size(); i++) {
-                                       if (tmap->isValidGroup(globaldata->Groups[i]) != true) {
-                                               cout << globaldata->Groups[i] << " is not a valid group, and will be disregarded." << endl;
-                                               // erase the invalid group from globaldata->Groups
-                                               globaldata->Groups.erase(globaldata->Groups.begin()+i);
-                                       }
-                               }
-                       
-                               //if the user only entered invalid groups
-                               if (globaldata->Groups.size() == 0) { 
-                                       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 < tmap->namesOfGroups.size(); i++) {
-                                               if (tmap->namesOfGroups[i] != "xxx") {
-                                                       allGroups += tmap->namesOfGroups[i] + "-";
-                                                       globaldata->Groups.push_back(tmap->namesOfGroups[i]);
-                                                       numGroups++;
-                                               }
-                                       }
-                                       allGroups = allGroups.substr(0, allGroups.length()-1);
-                               }else {
-                                       for (int i = 0; i < globaldata->Groups.size(); i++) {
-                                               allGroups += globaldata->Groups[i] + "-";
-                                               numGroups++;
-                                       }
-                                       allGroups = allGroups.substr(0, allGroups.length()-1);
-                               }
-                       }else{//user has enter "all" and wants the default groups
-                               globaldata->Groups.clear();
-                               for (int i = 0; i < tmap->namesOfGroups.size(); i++) {
-                                       if (tmap->namesOfGroups[i] != "xxx") {
-                                               globaldata->Groups.push_back(tmap->namesOfGroups[i]);
-                                               numGroups++;
-                                               allGroups += tmap->namesOfGroups[i] + "-";
-                                       }
-                               }
-                               allGroups = allGroups.substr(0, allGroups.length()-1);
-                               globaldata->setGroups("");
-                       }
-               }else {
-                       for (int i = 0; i < tmap->namesOfGroups.size(); i++) {
-                               if (tmap->namesOfGroups[i] != "xxx") {
-                                       allGroups += tmap->namesOfGroups[i] + "-";
-                               }
-                       }
-                       allGroups = allGroups.substr(0, allGroups.length()-1);
-                       numGroups = 1;
-               }
-               
-               //calculate number of comparsions
-               numComp = 0;
-               for (int r=0; r<numGroups; r++) { 
-                       for (int l = r+1; l < numGroups; l++) {
-                               groupComb.push_back(globaldata->Groups[r]+ "-" +globaldata->Groups[l]);
-                               numComp++;
-                       }
-               }
-               
-               //ABC
-               if (numComp != 1) {
-                       groupComb.push_back(allGroups);
-                       numComp++;
-               }
-               
-       }
-       catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the ParsimonyCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the ParsimonyCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }               
-
-}
 /*****************************************************************/
 
 void ParsimonyCommand::initFile(string label){
index e093ceb2de8efbbacf2d58e4d46257563b0797c3..dd4e2377e93a0708d7722d13c19068e3db578bf8 100644 (file)
@@ -13,6 +13,7 @@
 #include "parsimony.h"
 #include "treemap.h"
 #include "progress.hpp"
+#include "sharedutilities.h"
 
 using namespace std;
 
@@ -22,11 +23,12 @@ class ParsimonyCommand : public Command {
        
        public:
                ParsimonyCommand();     
-               ~ParsimonyCommand() { delete pars; }
+               ~ParsimonyCommand() { delete pars; delete util; }
                int execute();  
        
        private:
                GlobalData* globaldata;
+               SharedUtil* util;
                vector<Tree*> T;           //user trees
                Tree* randT;  //random tree
                Tree* copyUserTree; 
@@ -34,7 +36,7 @@ class ParsimonyCommand : public Command {
                TreeMap* savetmap;
                Parsimony* pars;
                vector<string> groupComb; // AB. AC, BC...
-               string parsFile, parsFileout, sumFile, randomtree;
+               string parsFile, parsFileout, sumFile, randomtree, allGroups;
                int iters, numGroups, numComp, counter;
                vector<int> numEachGroup; //vector containing the number of sequences in each group the users wants for random distrib.
                vector< vector<float> > userTreeScores; //scores for users trees for each comb.
@@ -55,7 +57,6 @@ class ParsimonyCommand : public Command {
                void printParsimonyFile();  
                void printUSummaryFile();
                void getUserInput();
-               void setGroups();
                void initFile(string);
                void output(vector<double>);
                void resetFile();
index 591c36af19637184d9f43c6e23eeb6f4b47863d8..cac06be7289d3a96913bd65abbc2b94e0c798f41 100644 (file)
--- a/qstat.cpp
+++ b/qstat.cpp
@@ -8,7 +8,7 @@
  */
 
 #include "qstat.h"
-#include "calculator.h"
+
 
 /***********************************************************************/
 
index 6b0a048cabd5748107c070405efe8df7c09cdafa..1613f0a16c3c868680a637b405e546abb2031932 100644 (file)
@@ -8,8 +8,6 @@
  */
 using namespace std;
  
-
-#include "utilities.hpp"
 #include "rabundvector.hpp"
 #include "sabundvector.hpp"
 #include "ordervector.hpp"
index 2a866bcbc4a39cf76c99885763f801e837d3570c..62520e6f12ba0530c5fea7c6db4c7f9b52222ea3 100644 (file)
@@ -12,6 +12,9 @@
                         sabundvector   =       2               1               1               0               0               1
                         ordervector    =       1       1       1       1       1       1       2       2       2       3       3       4       5 */
 
+//class SAbundVector;
+//class OrderVector;
+
 class RAbundVector : public DataVector {
        
 public:
index 0b8030795f09e0ab774f4016101c646f516b49e4..983ed102adc08f5629e061013b9d19c1fa49a28a 100644 (file)
@@ -115,7 +115,10 @@ void RareDisplay::reset(){
                nIters++;
        
                remove(tempInName.c_str());
-               rename(tempOutName.c_str(), tempInName.c_str());        
+               renameOk = rename(tempOutName.c_str(), tempInName.c_str());     
+               
+               //checks to make sure user was able to rename and remove successfully
+               if (renameOk != 0) { cout << "Unable to rename the necessary temp files." << endl; }
        }
        catch(exception& e) {
                cout << "Standard Error: " << e.what() << " has occurred in the RareDisplay class Function reset. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
@@ -157,7 +160,7 @@ void RareDisplay::close(){
        
                remove(tempInName.c_str());
                remove(tempOutName.c_str());
-       
+               
                nIters = 1;
                output->resetFile();
        }
index 50e212168893a17cd3f017d2081d3c9e3a43b925..ff7de73f24146a3b9d8401712c330adabcd8288d 100644 (file)
@@ -31,6 +31,7 @@ private:
        string tempInName, tempOutName;
        ifstream tempInFile;
        ofstream tempOutFile;
+       int renameOk;
 
 };
 
index c064125c37e846c538075f04d652eca6ec336708..2f5f5067a388f1c9c6026a32cff81f003fec1106 100644 (file)
@@ -8,7 +8,7 @@
  */
 
 #include "rarefact.h"
-#include "ordervector.hpp"
+//#include "ordervector.hpp"
 
 /***********************************************************************/
 
index b4a4cfee88a1c9d4dfc1abe58eaa59594002d108..fc1e8d13e4b289851c65e72a1ebd1804edfbd44d 100644 (file)
@@ -6,7 +6,7 @@ using namespace std;
 #include "rarefactioncurvedata.h"
 #include "raredisplay.h"
 #include "ordervector.hpp"
-
+#include "mothur.h"
 
 
 class Rarefact {
index 6a4fe85b76b56dd5903b98155f0b01121f0f0002..dc71b22b3cab606d13f1e86a743aee1b5bf104a5 100644 (file)
@@ -20,6 +20,7 @@ RareFactSharedCommand::RareFactSharedCommand(){
                fileNameRoot = getRootName(globaldata->inputFileName);
                format = globaldata->getFormat();
                validCalculator = new ValidCalculators();
+               util = new SharedUtil();
                                
                int i;
                for (i=0; i<globaldata->Estimators.size(); i++) {
@@ -55,6 +56,7 @@ RareFactSharedCommand::~RareFactSharedCommand(){
        delete input;
        delete rCurve;
        delete read;
+       delete util;
 }
 
 //**********************************************************************************************************************
@@ -83,7 +85,7 @@ int RareFactSharedCommand::execute(){
                }
                
                //set users groups
-               setGroups();
+               util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "rarefact");
                
                while(order != NULL){
                
@@ -134,51 +136,3 @@ int RareFactSharedCommand::execute(){
 
 
 //**********************************************************************************************************************
-
-void RareFactSharedCommand::setGroups() {
-       try {
-               //if the user has not entered specific groups to analyze then do them all
-               if (globaldata->Groups.size() != 0) {
-                       if (globaldata->Groups[0] != "all") {
-                               //check that groups are valid
-                               for (int i = 0; i < globaldata->Groups.size(); i++) {
-                                       if (globaldata->gGroupmap->isValidGroup(globaldata->Groups[i]) != true) {
-                                               cout << globaldata->Groups[i] << " is not a valid group, and will be disregarded." << endl;
-                                               // erase the invalid group from globaldata->Groups
-                                               globaldata->Groups.erase(globaldata->Groups.begin()+i);
-                                       }
-                               }
-                       
-                               //if the user only entered invalid groups
-                               if ((globaldata->Groups.size() == 0) || (globaldata->Groups.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; 
-                                       for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
-                                               globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
-                                       }
-                               }
-                       }else{//user has enter "all" and wants the default groups
-                               globaldata->Groups.clear();
-                               for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
-                                       globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
-                               }
-                               globaldata->setGroups("");
-                       }
-               }else {
-                       for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
-                               globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
-                       }
-               }
-               
-       }
-       catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the RareFactSharedCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the RareFactSharedCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }               
-
-}
-/***********************************************************/
-
index b5b638fc3b7a408ef8198f55d5309e64afa2b3f5..2f7920e922cf8509487aa2ae7a3060075b0e90cd 100644 (file)
@@ -17,6 +17,7 @@
 #include "display.h"
 #include "readmatrix.hpp"
 #include "validcalculator.h"
+#include "sharedutilities.h"
 
 /* The rarefaction.shared() command:
        The rarefaction command generates a rarefaction curve from a given file representing several groups.  
@@ -40,8 +41,8 @@ public:
        int execute();  
        
 private:
-       void setGroups();
        GlobalData* globaldata;
+       SharedUtil* util;
        SharedListVector* SharedList;
        ReadMatrix* read;
        SharedOrderVector* order;
index 70774d7e06819705a77b51bd38dedc69815ab240..4cf39fa85a9ad829f1db81bd17b3d260dd5a9543 100644 (file)
@@ -9,7 +9,6 @@
 
 using namespace std;
 
-#include "utilities.hpp"
 #include "sparsematrix.hpp"
 #include "progress.hpp"
 #include "listvector.hpp"
index 4e26881d1c883d34b4262bb1c38935525cc6f565..cfa7731b45dd5b37f2b39365fc0c22a19a9534d5 100644 (file)
@@ -10,6 +10,7 @@
  *
  */
 
+#include "mothur.h"
 #include "rabundvector.hpp"
 #include "listvector.hpp"
 #include "sharedlistvector.h"
index 15597bafbfd64eb88c2f4304aff0fb9b78ac60ea..3df0e0a5f1312aaf3be2ee1f0c35bc5c93afb695 100644 (file)
@@ -11,8 +11,8 @@
 
 using namespace std;
 
+#include "mothur.h"
 #include "globaldata.hpp"
-#include "utilities.hpp"
 #include "tree.h"
 
 #define MAX_LINE               513
index b29313260df9429f3149a161c4d8e8fbdb976a6a..04476c7aba114f599826de57cce67e852c5f8df5 100644 (file)
@@ -9,7 +9,6 @@
 using namespace std;
 
 #include "sabundvector.hpp"
-#include "utilities.hpp"
 #include "calculator.h"
 
 /***********************************************************************/
index fd9179ebce0ed7a7b27cd47eb68ac95c06c3dfe8..7445b5ad52c0c69d0548e65b8438681e95430ad9 100644 (file)
--- a/shared.h
+++ b/shared.h
@@ -12,6 +12,7 @@
  
 using namespace std;
 
+#include "mothur.h"
 #include "sharedrabundvector.h"
 #include "sharedlistvector.h"
 #include "globaldata.hpp"
index d45a11f6680571c5d174502ebb3915cc46bf91e8..3d314c35d0cbdddf6ece3c5d28b41ad5b69945ab 100644 (file)
@@ -8,7 +8,6 @@
  */
 
 #include "sharedbdiversity.h"
-#include "calculator.h"
 
 /***********************************************************************/
 
index 897432d57a20973cae256a14839b56a209c5ab0d..8daa0eba3287bb27e529bb0549eba25681a9aed2 100644 (file)
@@ -8,8 +8,6 @@
  */
 
 #include "sharedkstest.h"
-#include "calculator.h"
-#include <algorithm>
 
 /***********************************************************************/
 
index 00aef79584951ca468249648bd574ad1c7d42af0..06c8effdb66b4ea1bbf64b899e5918461134ea60 100644 (file)
@@ -14,7 +14,6 @@ using namespace std;
 #include "sabundvector.hpp"
 #include "rabundvector.hpp"
 #include "ordervector.hpp"
-#include "utilities.hpp"
 #include "sharedlistvector.h"
 #include "sharedordervector.h"
 
index f2ac5a7ee180152473d4233b52bdfd4fe3bd336c..6f38054a2a4110a5123160567f87c8018bee69d9 100644 (file)
@@ -10,9 +10,6 @@
  *
  */
 
-
-
-
 #include "calculator.h"
 
 /***********************************************************************/
index 2092706d8cf5a5c429fb937820663ff0a5738be1..4cc1d18fd80179af4ce8c5069a4e8144ca95dd81 100644 (file)
@@ -11,7 +11,6 @@ using namespace std;
 
 
 #include "sharedordervector.h"
-#include "utilities.hpp"
 
 
 /***********************************************************************/
index a530ad65289a67a9c92cbeeb55c0ce661ef1ac8c..c315c44b5468479a813b25922e54baca48841bac 100644 (file)
@@ -2,7 +2,7 @@
 #define SHAREDORDER_H
 /*
  *  sharedorder.h
- *  Dotur
+ *  Mothur
  *
  *  Created by Sarah Westcott on 12/9/08.
  *  Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved.
@@ -34,6 +34,9 @@ struct individual {
 #include "sharedsabundvector.h"
 #include "globaldata.hpp"
 #include "groupmap.h"
+//#include "globaldata.hpp"
+
+class GlobalData;
 
 class SharedOrderVector : public DataVector {
        
index 3d6a2debbc05540cb5d4cb38cba1dab5638c7346..4683c59b63050de20e6bb79e2103563478066a71 100644 (file)
 using namespace std;
 
 #include "sharedrabundvector.h" 
-#include "utilities.hpp"
 #include "sabundvector.hpp"
 #include "ordervector.hpp"
-#include <algorithm>
 
 
 /***********************************************************************/
@@ -186,6 +184,33 @@ 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);
+       }
+}
 
 /***********************************************************************/
 
index ab0c26ad807928a13fbf7c7a6c256c82a7efa719..5cc92a3b0904d7e685d89b8160c396f249164d1e 100644 (file)
@@ -49,6 +49,7 @@ public:
        int numNZ();
        void sortD();  //Sorts the data in descending order.
        void push_front(int, int, string); //abundance, otu, groupname
+       void insert(int, int, string); //abundance, otu, groupname
        void push_back(int, int, string);  //abundance, otu, groupname
        void pop_back();
        void resize(int);
index 7babf1c1f519dc28aa45fab6ec7c378f217499db..3cc80f75fbf08728ca793f0f5147b7e043c85f41 100644 (file)
@@ -9,7 +9,6 @@
 
 #include "sharedsabundvector.h"
 #include "sabundvector.hpp"
-#include "utilities.hpp"
 
 using namespace std;
 
diff --git a/sharedutilities.cpp b/sharedutilities.cpp
new file mode 100644 (file)
index 0000000..4e35ff3
--- /dev/null
@@ -0,0 +1,292 @@
+/*
+ *  sharedutilities.cpp
+ *  Mothur
+ *
+ *  Created by Sarah Westcott on 4/9/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "sharedutilities.h"
+#include "sharedrabundvector.h"
+#include "sharedordervector.h"
+
+/**************************************************************************************************/
+
+void SharedUtil::getSharedVectors(vector<string> Groups, vector<SharedRAbundVector*>& lookup, SharedOrderVector* order) {
+       try {
+       
+               //delete each sharedrabundvector in lookup
+               for (int j = 0; j < lookup.size(); j++) {
+                       delete lookup[j];
+               }
+               
+               lookup.clear();
+               
+               //create and initialize vector of sharedvectors, one for each group
+               for (int i = 0; i < Groups.size(); i++) { 
+                       SharedRAbundVector* temp = new SharedRAbundVector(order->getNumBins());
+                       temp->setLabel(order->getLabel());
+                       temp->setGroup(Groups[i]);
+                       lookup.push_back(temp);
+               }
+               
+               int numSeqs = order->size();
+               //sample all the members
+               for(int i=0;i<numSeqs;i++){
+                       //get first sample
+                       individual chosen = order->get(i);
+                       int abundance; 
+                                       
+                       //set info for sharedvector in chosens group
+                       for (int j = 0; j < lookup.size(); j++) { 
+                               if (chosen.group == lookup[j]->getGroup()) {
+                                        abundance = lookup[j]->getAbundance(chosen.bin);
+                                        lookup[j]->set(chosen.bin, (abundance + 1), chosen.group);
+                                        break;
+                               }
+                       }
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedUtil class Function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedUtil class function getSharedVectors. 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{//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 { //the user has not entered groups
+                       for (int i = 0; i < allGroups.size(); i++) {
+                               userGroups.push_back(allGroups[i]);
+                       }
+               }
+                       
+               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++) {
+                                               userGroups.erase(userGroups.begin()+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 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; 
+                                       for (int i = 0; i < allGroups.size(); i++) {
+                                               userGroups.push_back(allGroups[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);
+       }
+
+}
+
+/**************************************************************************************/
+//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
+       try {
+               numGroups = 0;
+               label = "";
+               //if the user has not entered specific groups to analyze then do them all
+               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 globaldata->Groups
+                                               userGroups.erase(userGroups.begin()+i);
+                                               i--;
+                                       }
+                               }
+                       }else { //users wants all groups
+                               userGroups.clear();
+                               for (int i=0; i < allGroups.size(); i++) { 
+                                       if (allGroups[i] != "xxx") {
+                                               userGroups.push_back(allGroups[i]);
+                                               label += allGroups[i] + "-";
+                                       }
+                               }
+                       }
+               }else { //the user has not entered groups
+                       for (int i=0; i < allGroups.size(); i++) { 
+                               if (allGroups[i] != "xxx") {
+                                       label += allGroups[i] + "-";
+                                       if (mode == "weighted") {
+                                               userGroups.push_back(allGroups[i]);
+                                       }else {
+                                               numGroups = 1;
+                                       }
+                               }
+                       }
+               }
+               
+               
+               if (mode == "weighted") {
+                       //if the user only entered invalid groups
+                       if (userGroups.size() == 0) { 
+                               for (int i=0; i < allGroups.size(); i++) { 
+                                       if (allGroups[i] != "xxx") {
+                                               userGroups.push_back(allGroups[i]);
+                                       }
+                               }
+                               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; 
+                       }else if (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;
+                               userGroups.clear();
+                               for (int i=0; i < allGroups.size(); i++) { 
+                                       if (allGroups[i] != "xxx") {
+                                               userGroups.push_back(allGroups[i]);
+                                       }
+                               }
+                       }
+                       numGroups = userGroups.size();
+                       
+               }else if ((mode == "unweighted") || (mode == "parsimony")) {
+                               //if the user only entered invalid groups
+                               if ((userGroups.size() == 0) && (numGroups == 0)) { 
+                                       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++) {
+                                               if (allGroups[i] != "xxx") {
+                                                       userGroups.push_back(allGroups[i]);
+                                                       label += allGroups[i] + "-";
+                                               }
+                                       }
+                               }else {
+                                       for (int i = 0; i < userGroups.size(); i++) {
+                                               label += userGroups[i] + "-";
+                                       }
+                               }
+                               
+                               //rip extra - off allgroups 
+                               label = label.substr(0, label.length()-1);
+                               
+                               if (numGroups != 1) { numGroups = userGroups.size(); }
+               
+               }
+       }
+       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);
+       }
+}
+/**************************************************************************************/
+void SharedUtil::getCombos(vector<string>& groupComb, vector<string> userGroups, int& numComp) { //groupcomb, globaldata->Groups, numcomb
+       try {
+               //calculate number of comparisons i.e. with groups A,B,C = AB, AC, BC = 3;
+               numComp = 0;
+               for (int i=0; i< userGroups.size(); i++) { 
+                       numComp += i; 
+                       for (int l = i+1; l < userGroups.size(); l++) {
+                               //set group comparison labels
+                               groupComb.push_back(userGroups[i] + "-" + userGroups[l]);
+                       }
+               } 
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedUtil class Function getCombos. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedUtil class function getCombos. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+/**************************************************************************************/
+bool SharedUtil::isValidGroup(string groupname, vector<string> groups) {
+       try {
+               for (int i = 0; i < groups.size(); i++) {
+                       if (groupname == groups[i]) { return true; }
+               }
+               
+               return false;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedUtil class Function isValidGroup. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedUtil class function isValidGroup. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/**************************************************************************************/
+void SharedUtil::updateGroupIndex(vector<string>& userGroups, map<string, int>& index) {
+       try {
+               index.clear();
+               for (int i = 0; i < userGroups.size(); i++) {
+                       index[userGroups[i]] = i;
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedUtil class Function updateGroupIndex. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedUtil class function updateGroupIndex. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
diff --git a/sharedutilities.h b/sharedutilities.h
new file mode 100644 (file)
index 0000000..f4e4631
--- /dev/null
@@ -0,0 +1,39 @@
+#ifndef SHAREDUTIL_H
+#define SHAREDUTIL_H
+/*
+ *  sharedutilities.h
+ *  Mothur
+ *
+ *  Created by Sarah Westcott on 4/9/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "mothur.h"
+
+class SharedRAbundVector;
+class SharedOrderVector;
+
+/**************************************************************************************************/
+
+class SharedUtil {
+       public:
+               SharedUtil() {};
+               ~SharedUtil() {};
+               
+               void getSharedVectors(vector<string>, vector<SharedRAbundVector*>&, SharedOrderVector*);
+               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
+               void updateGroupIndex(vector<string>&, map<string, int>&); //globaldata->Groups, groupmap->groupIndex
+               
+       private:
+       
+               bool isValidGroup(string, vector<string>);
+};
+
+/**************************************************************************************************/
+
+
+
+#endif
\ No newline at end of file
index 1b0aed227754118eeef8c40c7482642c8778c25c..a024453cf43f5a999703b9e649a99913f5f4d27f 100644 (file)
@@ -1,4 +1,5 @@
 
+#include "mothur.h"
 #include "cluster.hpp"
 
 
index 0b210c66565324ea85e8fcb4b4dd45634199573e..fc10d27e4193dfcce4ecde200416157876c9ad14 100644 (file)
@@ -1,4 +1,4 @@
-#include "utilities.hpp"
+
 #include "sparsematrix.hpp"
 #include "listvector.hpp"
 
index bcd78997bc3e2450da6373cc3bb760effdbeb4e1..d65771e75a4d8a2785535fd2ae9cd493f2c1aa1f 100644 (file)
@@ -1,7 +1,6 @@
 #ifndef SPARSEMATRIX_H
 #define SPARSEMATRIX_H
 
-#include "utilities.hpp"
 #include "mothur.h"
 
 
index 526cd8292e2082eccf96c2c25f82c8a4709267e5..bebdf2637edad951b4b766760d4d96ee86281f69 100644 (file)
@@ -40,6 +40,7 @@ SummarySharedCommand::SummarySharedCommand(){
                openOutputFile(outputFileName, outputFileHandle);
                format = globaldata->getFormat();
                validCalculator = new ValidCalculators();
+               util = new SharedUtil();
                
                int i;
                for (i=0; i<globaldata->Estimators.size(); i++) {
@@ -109,6 +110,7 @@ SummarySharedCommand::SummarySharedCommand(){
 SummarySharedCommand::~SummarySharedCommand(){
        delete input;
        delete read;
+       delete util;
 }
 
 //**********************************************************************************************************************
@@ -137,7 +139,7 @@ int SummarySharedCommand::execute(){
                }
                
                //set users groups
-               setGroups();
+               util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "summary");
                
                //output estimator names as column headers
                outputFileHandle << "label" <<'\t' << "comparison" << '\t'; 
@@ -151,7 +153,7 @@ int SummarySharedCommand::execute(){
                        if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){                       
        
                                cout << order->getLabel() << '\t' << count << endl;
-                               getSharedVectors();  //fills group vectors from order vector.
+                               util->getSharedVectors(globaldata->Groups, lookup, order);  //fills group vectors from order vector.  //fills group vectors from order vector.
                                
                                //randomize group order
                                if (globaldata->getJumble() == "1") { random_shuffle(lookup.begin(), lookup.end()); }
@@ -159,7 +161,7 @@ int SummarySharedCommand::execute(){
                                int n = 1; 
                                for (int k = 0; k < (lookup.size() - 1); k++) { // pass cdd each set of groups to commpare
                                        for (int l = n; l < lookup.size(); l++) {
-                                               outputFileHandle << order->getLabel() << '\t' << (lookup[k]->getGroup() + lookup[l]->getGroup()) << '\t' << '\t'; //print out label and group
+                                               
                                                outputFileHandle << order->getLabel() << '\t';
                                                
                                                //sort groups to be alphanumeric
@@ -210,91 +212,4 @@ int SummarySharedCommand::execute(){
        }               
 }
 
-//**********************************************************************************************************************
-
-void SummarySharedCommand::getSharedVectors(){
-try {
-               lookup.clear();
-               //create and initialize vector of sharedvectors, one for each group
-               for (int i = 0; i < globaldata->Groups.size(); i++) { 
-                       SharedRAbundVector* temp = new SharedRAbundVector(order->getNumBins());
-                       temp->setLabel(order->getLabel());
-                       temp->setGroup(globaldata->Groups[i]);
-                       lookup.push_back(temp);
-               }
-               
-               int numSeqs = order->size();
-               //sample all the members
-               for(int i=0;i<numSeqs;i++){
-                       //get first sample
-                       individual chosen = order->get(i);
-                       int abundance; 
-                                       
-                       //set info for sharedvector in chosens group
-                       for (int j = 0; j < lookup.size(); j++) { 
-                               if (chosen.group == lookup[j]->getGroup()) {
-                                        abundance = lookup[j]->getAbundance(chosen.bin);
-                                        lookup[j]->set(chosen.bin, (abundance + 1), chosen.group);
-                                        break;
-                               }
-                       }
-               }
-       }
-       catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the SummarySharedCommand class function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-
-}
-
-//**********************************************************************************************************************
-void SummarySharedCommand::setGroups() {
-       try {
-               //if the user has not entered specific groups to analyze then do them all
-               if (globaldata->Groups.size() != 0) {
-                       if (globaldata->Groups[0] != "all") {
-                               //check that groups are valid
-                               for (int i = 0; i < globaldata->Groups.size(); i++) {
-                                       if (globaldata->gGroupmap->isValidGroup(globaldata->Groups[i]) != true) {
-                                               cout << globaldata->Groups[i] << " is not a valid group, and will be disregarded." << endl;
-                                               // erase the invalid group from globaldata->Groups
-                                               globaldata->Groups.erase(globaldata->Groups.begin()+i);
-                                       }
-                               }
-                       
-                               //if the user only entered invalid groups
-                               if ((globaldata->Groups.size() == 0) || (globaldata->Groups.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; 
-                                       for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
-                                               globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
-                                       }
-                               }
-                       }else{//user has enter "all" and wants the default groups
-                               globaldata->Groups.clear();
-                               for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
-                                       globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
-                               }
-                               globaldata->setGroups("");
-                       }
-               }else {
-                       for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
-                               globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
-                       }
-               }
-               
-       }
-       catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the SummarySharedCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }               
-
-}
 /***********************************************************/
index 248c1c8ecb81f2bbc069b25151c3908e05330907..9e4a8c87963289644f17a10ce07c3a55f7cfbb7b 100644 (file)
@@ -17,6 +17,7 @@
 #include "readmatrix.hpp"
 #include "sharedlistvector.h"
 #include "validcalculator.h"
+#include "sharedutilities.h"
 
 /*The summary.shared() command
        The summary.shared command can only be executed after a successful read.shared command. 
@@ -43,18 +44,15 @@ public:
        int execute();
        
 private:
-       void getSharedVectors();
-       void setGroups();
-       
        GlobalData* globaldata;
        ReadMatrix* read;
+       SharedUtil* util;
        vector<Calculator*> sumCalculators;     
        InputData* input;
        ValidCalculators* validCalculator;
        SharedListVector* SharedList;
        SharedOrderVector* order;
        vector<SharedRAbundVector*> lookup;
-       SharedRAbundVector* shared1, shared2;
        string outputFileName, format;
        ofstream outputFileHandle;
 
index 6aa1b829c91d59bcee681b906c6c31ab07f1c168..f93b9335749b4e79bb8c3e3c1be58684efc1cf65 100644 (file)
--- a/tree.cpp
+++ b/tree.cpp
@@ -511,8 +511,16 @@ void Tree::printBranch(int node) {
                        out << ",";
                        printBranch(tree[node].getRChild());
                        out << ")";
+                       //if there is a branch length then print it
+                       if (tree[node].getBranchLength() != -1) {
+                               out << ":" << tree[node].getBranchLength();
+                       }
                }else { //you are a leaf
-                       out << tree[node].getGroup() << ":" << tree[node].getBranchLength();
+                       out << tree[node].getGroup(); 
+                       //if there is a branch length then print it
+                       if (tree[node].getBranchLength() != -1) {
+                               out << ":" << tree[node].getBranchLength();
+                       }
                }
                
        }
index 9ee47748d817c9255ab1aaf41dd23918f7d0a980..cfd648e09386e81cb1dffacdd605f274700d765e 100644 (file)
@@ -13,7 +13,6 @@
 using namespace std;
 
 #include "mothur.h"
-#include "utilities.hpp"
 #include "tree.h"
 
 /* The tree calculator class is the parent class for tree calculators in mothur. */ 
diff --git a/treegroupscommand.cpp b/treegroupscommand.cpp
new file mode 100644 (file)
index 0000000..bdd664a
--- /dev/null
@@ -0,0 +1,292 @@
+/*
+ *  treegroupscommand.cpp
+ *  Mothur
+ *
+ *  Created by Sarah Westcott on 4/8/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "treegroupscommand.h"
+#include "sharedjabund.h"
+#include "sharedsorabund.h"
+#include "sharedjclass.h"
+#include "sharedsorclass.h"
+#include "sharedjest.h"
+#include "sharedsorest.h"
+#include "sharedthetayc.h"
+#include "sharedthetan.h"
+#include "sharedmorisitahorn.h"
+
+
+//**********************************************************************************************************************
+
+TreeGroupCommand::TreeGroupCommand(){
+       try {
+               globaldata = GlobalData::getInstance();
+               format = globaldata->getFormat();
+               validCalculator = new ValidCalculators();
+               util = new SharedUtil();
+               
+               int i;
+               for (i=0; i<globaldata->Estimators.size(); i++) {
+                       if (validCalculator->isValidCalculator("treegroup", globaldata->Estimators[i]) == true) { 
+                               if (globaldata->Estimators[i] == "sharedjabund") {      
+                                       treeCalculators.push_back(new SharedJAbund());
+                               }else if (globaldata->Estimators[i] == "sharedsorensonabund") { 
+                                       treeCalculators.push_back(new SharedSorAbund());
+                               }else if (globaldata->Estimators[i] == "sharedjclass") { 
+                                       treeCalculators.push_back(new SharedJclass());
+                               }else if (globaldata->Estimators[i] == "sharedsorclass") { 
+                                       treeCalculators.push_back(new SharedSorClass());
+                               }else if (globaldata->Estimators[i] == "sharedjest") { 
+                                       treeCalculators.push_back(new SharedJest());
+                               }else if (globaldata->Estimators[i] == "sharedsorest") { 
+                                       treeCalculators.push_back(new SharedSorEst());
+                               }else if (globaldata->Estimators[i] == "sharedthetayc") { 
+                                       treeCalculators.push_back(new SharedThetaYC());
+                               }else if (globaldata->Estimators[i] == "sharedthetan") { 
+                                       treeCalculators.push_back(new SharedThetaN());
+                               }else if (globaldata->Estimators[i] == "sharedmorisitahorn") { 
+                                       treeCalculators.push_back(new SharedMorHorn());
+                               }
+                       }
+               }
+               
+               //reset calc for next command
+               globaldata->setCalc("");
+
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the TreeGroupCommand class Function TreeGroupCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the TreeGroupCommand class function TreeGroupCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+//**********************************************************************************************************************
+
+TreeGroupCommand::~TreeGroupCommand(){
+       delete input;
+       delete read;
+       delete util;
+}
+
+//**********************************************************************************************************************
+
+int TreeGroupCommand::execute(){
+       try {
+               int count = 1;  
+               EstOutput data;
+       
+               //if the users entered no valid calculators don't execute command
+               if (treeCalculators.size() == 0) { return 0; }
+
+               if (format == "sharedfile") {
+                       read = new ReadPhilFile(globaldata->inputFileName);     
+                       read->read(&*globaldata); 
+                       
+                       input = globaldata->ginput;
+                       order = input->getSharedOrderVector();
+               }else {
+                       //you are using a list and a groupfile
+                       read = new ReadPhilFile(globaldata->inputFileName);     
+                       read->read(&*globaldata); 
+               
+                       input = globaldata->ginput;
+                       SharedList = globaldata->gSharedList;
+                       order = SharedList->getSharedOrderVector();
+               }
+               
+               //set users groups
+               util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "treegroup");
+               numGroups = globaldata->Groups.size();
+               groupNames = "";
+               for (int i = 0; i < numGroups; i++) { groupNames += globaldata->Groups[i]; }
+               
+               //clear globaldatas old tree names if any
+               globaldata->Treenames.clear();
+               
+               //fills globaldatas tree names
+               globaldata->Treenames = globaldata->Groups;
+               
+               //create treemap class from groupmap for tree class to use
+               tmap = new TreeMap();
+               tmap->makeSim(globaldata->gGroupmap);
+               globaldata->gTreemap = tmap;
+                       
+               while(order != NULL){
+               
+                       if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){                       
+                               
+                               cout << order->getLabel() << '\t' << count << endl;
+                               util->getSharedVectors(globaldata->Groups, lookup, order);  //fills group vectors from order vector.
+                               
+                               //for each calculator                                                                                           
+                               for(int i = 0 ; i < treeCalculators.size(); i++) {
+                                       
+                                       //initialize simMatrix
+                                       simMatrix.clear();
+                                       simMatrix.resize(numGroups);
+                                       for (int m = 0; m < simMatrix.size(); m++)      {
+                                               for (int j = 0; j < simMatrix.size(); j++)      {
+                                                       simMatrix[m].push_back(0.0);
+                                               }
+                                       }
+                               
+                                       //initialize index
+                                       index.clear();
+                                       for (int g = 0; g < numGroups; g++) {   index[g] = g;   }
+               
+                                       //create a new filename
+                                       outputFile = getRootName(globaldata->inputFileName) + treeCalculators[i]->getName() + "." + order->getLabel() + groupNames + ".tre";
+                                                       
+                                       for (int k = 0; k < lookup.size(); k++) { // pass cdd each set of groups to commpare
+                                               for (int l = k; l < lookup.size(); l++) {
+                                                       if (k != l) { //we dont need to similiarity of a groups to itself
+                                                               //get estimated similarity between 2 groups
+                                                               data = treeCalculators[i]->getValues(lookup[k], lookup[l]); //saves the calculator outputs
+                                                               //save values in similarity matrix
+                                                               simMatrix[k][l] = data[0];
+                                                               simMatrix[l][k] = data[0];
+                                                       }
+                                               }
+                                       }
+                                       
+                                       //creates tree from similarity matrix and write out file
+                                       createTree();
+                               }
+                       }
+               
+                       //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;
+                               }
+                       }
+                       count++;
+               }
+               
+               //reset groups parameter
+               globaldata->Groups.clear();  globaldata->setGroups("");
+
+               return 0;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the TreeGroupCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the TreeGroupCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+//**********************************************************************************************************************
+
+void TreeGroupCommand::createTree(){
+       try {
+               //create tree
+               t = new Tree();
+               
+               //do merges and create tree structure by setting parents and children
+               //there are numGroups - 1 merges to do
+               for (int i = 0; i < (numGroups - 1); i++) {
+                       
+                       float largest = 0.0;
+                       int row, column;
+                       //find largest value in sims matrix by searching lower triangle
+                       for (int j = 1; j < simMatrix.size(); j++) {
+                               for (int k = 0; k < j; k++) {
+                                       if (simMatrix[j][k] > largest) {  largest = simMatrix[j][k]; row = j; column = k;  }
+                               }
+                       }
+
+                       //set non-leaf node info and update leaves to know their parents
+                       //non-leaf
+                       t->tree[numGroups + i].setChildren(index[row], index[column]);
+                       
+                       //parents
+                       t->tree[index[row]].setParent(numGroups + i);
+                       t->tree[index[column]].setParent(numGroups + i);
+                       
+                       //blength = distance / 2;
+                       float blength = ((1.0 - largest) / 2);
+                       
+                       //branchlengths
+                       t->tree[index[row]].setBranchLength(blength - t->tree[index[row]].getLengthToLeaves());
+                       t->tree[index[column]].setBranchLength(blength - t->tree[index[column]].getLengthToLeaves());
+                       
+                       //set your length to leaves to your childs length plus branchlength
+                       t->tree[numGroups + i].setLengthToLeaves(t->tree[index[row]].getLengthToLeaves() + t->tree[index[row]].getBranchLength());
+                       
+                       
+                       //update index 
+                       index[row] = numGroups+i;
+                       index[column] = numGroups+i;
+                       
+                       //zero out highest value that caused the merge.
+                       simMatrix[row][column] = 0.0;
+                       simMatrix[column][row] = 0.0;
+                       
+                       //merge values in simsMatrix
+                       for (int n = 0; n < simMatrix.size(); n++)      {
+                               //row becomes merge of 2 groups
+                               simMatrix[row][n] = (simMatrix[row][n] + simMatrix[column][n]) / 2;
+                               simMatrix[n][row] = simMatrix[row][n];
+                               //delete column
+                               simMatrix[column][n] = 0.0;
+                               simMatrix[n][column] = 0.0;
+                       }
+               }
+       
+               //assemble tree
+               t->assembleTree();
+               
+               //print newick file
+               t->createNewickFile(outputFile);
+               
+               //delete tree
+               delete t;
+       
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the TreeGroupCommand class Function createTree. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the TreeGroupCommand class function createTree. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+/***********************************************************/
+void TreeGroupCommand::printSims() {
+       try {
+               cout << "simsMatrix" << endl;
+               for (int m = 0; m < simMatrix.size(); m++)      {
+                       for (int n = 0; n < simMatrix.size(); n++)      {
+                               cout << simMatrix[m][n] << '\t'; 
+                       }
+                       cout << endl;
+               }
+
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the TreeGroupCommand class Function printSims. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the TreeGroupCommand class function printSims. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+/***********************************************************/
+
+
diff --git a/treegroupscommand.h b/treegroupscommand.h
new file mode 100644 (file)
index 0000000..4c3b842
--- /dev/null
@@ -0,0 +1,63 @@
+#ifndef TREEGROUPCOMMAND_H
+#define TREEGROUPCOMMAND_H
+
+/*
+ *  treegroupscommand.h
+ *  Mothur
+ *
+ *  Created by Sarah Westcott on 4/8/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+#include "command.hpp"
+#include "sharedordervector.h"
+#include "sharedlistvector.h"
+#include "inputdata.h"
+#include "groupmap.h"
+#include "readmatrix.hpp"
+#include "validcalculator.h"
+#include "tree.h"
+#include "treemap.h"
+#include "sharedutilities.h"
+
+
+/* This command create a tree file for each similarity calculator at distance level, using various calculators to find the similiarity between groups. 
+       The user can select the lines or labels they wish to use as well as the groups they would like included.
+       They can also use as many or as few calculators as they wish. */
+       
+class GlobalData;
+
+class TreeGroupCommand : public Command {
+       
+public:
+       TreeGroupCommand();     
+       ~TreeGroupCommand();
+       int execute();  
+       
+private:
+       void createTree();
+       void printSims();
+       
+       GlobalData* globaldata;
+       SharedUtil* util;
+       ReadMatrix* read;
+       TreeMap* tmap;
+       Tree* t;
+       vector<Calculator*> treeCalculators;
+       vector< vector<float> > simMatrix;
+       map<int, int> index;  //maps row in simMatrix to vector index in the tree       
+       InputData* input;
+       ValidCalculators* validCalculator;
+       SharedListVector* SharedList;
+       SharedOrderVector* order;
+       vector<SharedRAbundVector*> lookup;
+       string format, outputFile, groupNames;
+       int numGroups;
+
+};
+       
+       
+#endif
+
+
index fee309c5877138039c2ecdff8f54428a8060bc24..5880b0c593fdd0dc96808e485921d96871e865d6 100644 (file)
@@ -144,3 +144,31 @@ void TreeMap::print(ostream& output){
 }
 
 /************************************************************/
+void TreeMap::makeSim(GroupMap* groupmap) {
+       try {
+               //set names of groups
+               namesOfGroups = groupmap->namesOfGroups;
+               
+               //set names of seqs to names of groups
+               namesOfSeqs = groupmap->namesOfGroups;
+               
+               // make map where key and value are both the group name since that what the tree.groups command wants
+               for (int i = 0; i < namesOfGroups.size(); i++) {
+                       treemap[namesOfGroups[i]].groupname = namesOfGroups[i];
+                       seqsPerGroup[namesOfGroups[i]] = 1;
+               }
+               
+               numGroups = namesOfGroups.size();
+               
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the TreeMap class Function make. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the TreeMap class function make. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+/************************************************************/
+
index 941ca9a8f79e4de463f99719d6ffd37fe7733961..12299731f89e10741926cd797fad2a02ed267c2d 100644 (file)
--- a/treemap.h
+++ b/treemap.h
@@ -10,7 +10,7 @@
  */
 
 #include "mothur.h"
-#include "utilities.hpp"
+#include "groupmap.h"
 
 /* This class is used by the read.tree command to build the tree container. */
 
@@ -19,7 +19,7 @@ struct GroupIndex {
        int             vectorIndex;
 };
 
-
+class GroupMap;
 
 class TreeMap {
 public:
@@ -38,6 +38,7 @@ public:
     map<string,int> seqsPerGroup;      //groupname, number of seqs in that group.
        map<string, GroupIndex> treemap; //sequence name and <groupname, vector index>
        void print(ostream&);
+       void makeSim(GroupMap*);  //takes groupmap info and fills treemap for use by tree.groups command.
        
        
 private:
index cf7192e12e8c0d4e3b435b80e6cdefe8663f471c..59fb630ef11373b671f48dfc72459dbc1fa78ad7 100644 (file)
@@ -18,6 +18,7 @@ Node::Node() {
        parent = -1;
        lchild = -1;
        rchild = -1;
+       length2leaf = 0.0;
        
 }
 /****************************************************************/
@@ -27,6 +28,8 @@ void Node::setGroup(string groups)  { group =groups; }
 /****************************************************************/
 void Node::setBranchLength(float l) { branchLength = l; }
 /****************************************************************/
+void Node::setLengthToLeaves(float l) { length2leaf = l; }
+/****************************************************************/
 void Node::setParent(int p)  { parent = p; }
 /****************************************************************/
 void Node::setIndex(int i)  { vectorIndex = i; }
@@ -39,6 +42,8 @@ string Node::getGroup() { return group; }
 /****************************************************************/
 float Node::getBranchLength() { return branchLength; }
 /****************************************************************/
+float Node::getLengthToLeaves() { return length2leaf; }
+/****************************************************************/
 int Node::getParent() { return parent; }
 /****************************************************************/
 int Node::getLChild() { return lchild; }
index a83bbca615d6300e113e4fdf402e64934adb189c..58d967d5cf297bbcd82e3839822e201a0aed121f 100644 (file)
@@ -28,10 +28,12 @@ class Node  {
                void setParent(int);
                void setChildren(int, int);             //leftchild, rightchild
                void setIndex(int);
+               void setLengthToLeaves(float);
                
                string getName();
                string getGroup();  
                float getBranchLength();
+               float getLengthToLeaves();
                int getParent();
                int getLChild();
                int getRChild();
@@ -51,7 +53,7 @@ class Node  {
        private:
                string                  name;
                string                  group;
-               float                   branchLength;
+               float                   branchLength, length2leaf;
                int                             parent;
                int                             lchild;
                int                             rchild;
index 2b93df782bccc4d2dbc8533e7cdc38169059d6a7..9d170631592cc9faf9c54fbd5bde5c710efe05f6 100644 (file)
@@ -19,7 +19,18 @@ UnifracUnweightedCommand::UnifracUnweightedCommand() {
                sumFile = globaldata->getTreeFile() + ".uwsummary";
                openOutputFile(sumFile, outSum);
 
-               setGroups(); //sets users groups to analyze
+               util = new SharedUtil();
+               util->setGroups(globaldata->Groups, tmap->namesOfGroups, allGroups, numGroups, "unweighted");   //sets the groups the user wants to analyze
+               util->getCombos(groupComb, globaldata->Groups, numComp);
+               globaldata->setGroups("");
+               
+               //ABC
+               if (numComp != 1) {
+                       groupComb.push_back(allGroups);
+                       numComp++;
+               }
+
+               
                convert(globaldata->getIters(), iters);  //how many random trees to generate
                unweighted = new Unweighted(tmap);
 
@@ -114,7 +125,7 @@ int UnifracUnweightedCommand::execute() {
                UWScoreSig.clear(); 
        }
                //reset groups parameter
-               globaldata->Groups.clear(); globaldata->setGroups("");
+               globaldata->Groups.clear(); 
                outSum.close();
                
                return 0;
@@ -189,89 +200,6 @@ void UnifracUnweightedCommand::printUWSummaryFile() {
                exit(1);
        }
 }
-/***********************************************************/
-
-void UnifracUnweightedCommand::setGroups() {
-       try {
-               string allGroups = "";
-               numGroups = 0;
-               //if the user has not entered specific groups to analyze then do them all
-               if (globaldata->Groups.size() != 0) {
-                       if (globaldata->Groups[0] != "all") {
-                               //check that groups are valid
-                               for (int i = 0; i < globaldata->Groups.size(); i++) {
-                                       if (tmap->isValidGroup(globaldata->Groups[i]) != true) {
-                                               cout << globaldata->Groups[i] << " is not a valid group, and will be disregarded." << endl;
-                                               // erase the invalid group from globaldata->Groups
-                                               globaldata->Groups.erase(globaldata->Groups.begin()+i);
-                                       }
-                               }
-                       
-                               //if the user only entered invalid groups
-                               if (globaldata->Groups.size() == 0) { 
-                                       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 < tmap->namesOfGroups.size(); i++) {
-                                               if (tmap->namesOfGroups[i] != "xxx") {
-                                                       globaldata->Groups.push_back(tmap->namesOfGroups[i]);
-                                                       numGroups++;
-                                                       allGroups += tmap->namesOfGroups[i] + "-";
-                                               }
-                                       }
-                                       allGroups = allGroups.substr(0, allGroups.length()-1);
-                               }else {
-                                       for (int i = 0; i < globaldata->Groups.size(); i++) {
-                                               allGroups += globaldata->Groups[i] + "-";
-                                               numGroups++;
-                                       }
-                                       allGroups = allGroups.substr(0, allGroups.length()-1);
-                               }
-                       }else{//user has enter "all" and wants the default groups
-                               globaldata->Groups.clear();
-                               for (int i = 0; i < tmap->namesOfGroups.size(); i++) {
-                                       if (tmap->namesOfGroups[i] != "xxx") {
-                                               globaldata->Groups.push_back(tmap->namesOfGroups[i]);
-                                               numGroups++;
-                                               allGroups += tmap->namesOfGroups[i] + "-";
-                                       }
-                               }
-                               allGroups = allGroups.substr(0, allGroups.length()-1);
-                               globaldata->setGroups("");
-                       }
-               }else {
-                       for (int i = 0; i < tmap->namesOfGroups.size(); i++) {
-                               if (tmap->namesOfGroups[i] != "xxx") {
-                                       allGroups += tmap->namesOfGroups[i] + "-";
-                               }
-                       }
-                       allGroups = allGroups.substr(0, allGroups.length()-1);
-                       numGroups = 1;
-               }
-               
-               //calculate number of comparsions
-               numComp = 0;
-               for (int r=0; r<numGroups; r++) { 
-                       for (int l = r+1; l < numGroups; l++) {
-                               groupComb.push_back(globaldata->Groups[r]+ "-" + globaldata->Groups[l]);
-                               numComp++;
-                       }
-               }
-               
-               //ABC
-               if (numComp != 1) {
-                       groupComb.push_back(allGroups);
-                       numComp++;
-               }
-       }
-       catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the UnifracUnweightedCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the UnifracUnweightedCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }               
-
-}
 /*****************************************************************/
 
 void UnifracUnweightedCommand::initFile(string label){
index 3c250db030b04740e59df7ce24ba6b2752dc2023..3bd9a0db8915eb36c2e66174e8750c0fb1fab52a 100644 (file)
@@ -13,6 +13,7 @@
 #include "command.hpp"
 #include "unweighted.h"
 #include "treemap.h"
+#include "sharedutilities.h"
 
 
 using namespace std;
@@ -23,15 +24,16 @@ class UnifracUnweightedCommand : public Command {
        
        public:
                UnifracUnweightedCommand();     
-               ~UnifracUnweightedCommand() { delete unweighted; }
+               ~UnifracUnweightedCommand() { delete unweighted; delete util; }
                int execute();  
        
        private:
                GlobalData* globaldata;
+               SharedUtil* util;
                vector<Tree*> T;           //user trees
                TreeMap* tmap;
                Unweighted* unweighted;
-               string sumFile, unweightedFile, unweightedFileout;
+               string sumFile, unweightedFile, unweightedFileout, allGroups;
                vector<string> groupComb; // AB. AC, BC...
                int iters, numGroups, numComp, counter;
                EstOutput userData;                     //unweighted score info for user tree
@@ -49,7 +51,6 @@ class UnifracUnweightedCommand : public Command {
                
                void printUWSummaryFile();
                void printUnweightedFile();
-               void setGroups();  
                void initFile(string);
                void output(vector<double>);
                void resetFile();
index c2584eabfe07975d103c17c6d93e96e2ae1770e2..5f7b4ad5363a2660aa2df7ac9ecb8f3fa998a13d 100644 (file)
@@ -19,7 +19,12 @@ UnifracWeightedCommand::UnifracWeightedCommand() {
                sumFile = globaldata->getTreeFile() + ".wsummary";
                openOutputFile(sumFile, outSum);
                                
-               setGroups();    //sets the groups the user wants to analyze                     
+               util = new SharedUtil();
+               string s; //to make work with setgroups
+               util->setGroups(globaldata->Groups, tmap->namesOfGroups, s, numGroups, "weighted");     //sets the groups the user wants to analyze
+               util->getCombos(groupComb, globaldata->Groups, numComp);
+               globaldata->setGroups("");
+                               
                convert(globaldata->getIters(), iters);  //how many random trees to generate
                weighted = new Weighted(tmap);
 
@@ -51,8 +56,9 @@ int UnifracWeightedCommand::execute() {
                        counter = 0;
                        rScores.resize(numComp);  //data[0] = weightedscore AB, data[1] = weightedscore AC...
                        uScores.resize(numComp);  //data[0] = weightedscore AB, data[1] = weightedscore AC...
-                       weightedFile = globaldata->getTreeFile()  + toString(i+1) + ".weighted";
-                       weightedFileout = globaldata->getTreeFile() + "temp." + toString(i+1) + ".weighted";
+                       //weightedFile = globaldata->getTreeFile()  + toString(i+1) + ".weighted";
+                       //weightedFileout = globaldata->getTreeFile() + "temp." + toString(i+1) + ".weighted";
+                       output = new ThreeColumnFile2(globaldata->getTreeFile()  + toString(i+1) + ".weighted");
 
                        userData = weighted->getValues(T[i]);  //userData[0] = weightedscore
                        
@@ -109,6 +115,8 @@ int UnifracWeightedCommand::execute() {
                        calculateFreqsCumuls();
                        printWeightedFile();
                        
+                       delete output;
+                       
                        //clear data
                        rScores.clear();
                        uScores.clear();
@@ -142,21 +150,23 @@ int UnifracWeightedCommand::execute() {
 void UnifracWeightedCommand::printWeightedFile() {
        try {
                vector<double> data;
+               vector<string> tags;
+               tags.push_back("Score"); tags.push_back("RandFreq"); tags.push_back("RandCumul");
                
                for(int a = 0; a < numComp; a++) {
-                       initFile(groupComb[a]);
+                       output->initFile(groupComb[a], tags);
                        //print each line
                        for (it = validScores.begin(); it != validScores.end(); it++) { 
                                data.push_back(it->first);  data.push_back(rScoreFreq[a][it->first]); data.push_back(rCumul[a][it->first]); 
-                               output(data);
+                               output->output(data);
                                data.clear();
                        } 
-                       resetFile();
+                       output->resetFile();
                }
                
-               out.close();
-               inFile.close();
-               remove(weightedFileout.c_str());
+               //out.close();
+               //inFile.close();
+               //remove(weightedFileout.c_str());
                
        }
        catch(exception& e) {
@@ -224,80 +234,6 @@ int UnifracWeightedCommand::findIndex(float score, int index) {
        }
 }
 
-/***********************************************************/
-void UnifracWeightedCommand::setGroups() {
-       try {
-               numGroups = 0;
-               //if the user has not entered specific groups to analyze then do them all
-               if (globaldata->Groups.size() == 0) {
-                       for (int i=0; i < tmap->getNumGroups(); i++) { 
-                               if (tmap->namesOfGroups[i] != "xxx") {
-                                       globaldata->Groups.push_back(tmap->namesOfGroups[i]);
-                                       numGroups++;
-                               }
-                       }
-               }else {
-                       if (globaldata->getGroups() != "all") {
-                               //check that groups are valid
-                               for (int i = 0; i < globaldata->Groups.size(); i++) {
-                                       if (tmap->isValidGroup(globaldata->Groups[i]) != true) {
-                                               cout << globaldata->Groups[i] << " is not a valid group, and will be disregarded." << endl;
-                                               // erase the invalid group from globaldata->Groups
-                                               globaldata->Groups.erase (globaldata->Groups.begin()+i);
-                                       }
-                               }
-                       
-                               //if the user only entered invalid groups
-                               if (globaldata->Groups.size() == 0) { 
-                                       for (int i=0; i < tmap->getNumGroups(); i++) { 
-                                               if (tmap->namesOfGroups[i] != "xxx") {
-                                                       globaldata->Groups.push_back(tmap->namesOfGroups[i]);
-                                                       numGroups++;
-                                               }
-                                       }
-                                       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; 
-                               }else if (globaldata->Groups.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;
-                                       globaldata->Groups.clear();
-                                       for (int i=0; i < tmap->getNumGroups(); i++) { 
-                                               if (tmap->namesOfGroups[i] != "xxx") {
-                                                       globaldata->Groups.push_back(tmap->namesOfGroups[i]);
-                                                       numGroups++;
-                                               }
-                                       }
-                               }else { numGroups = globaldata->Groups.size(); }
-                       }else { //users wants all groups
-                               globaldata->Groups.clear();
-                               globaldata->setGroups("");
-                               for (int i=0; i < tmap->getNumGroups(); i++) { 
-                                       if (tmap->namesOfGroups[i] != "xxx") {
-                                               globaldata->Groups.push_back(tmap->namesOfGroups[i]);
-                                               numGroups++;
-                                       }
-                               }
-                       }
-               }
-               
-               //calculate number of comparisons i.e. with groups A,B,C = AB, AC, BC = 3;
-               numComp = 0;
-               for (int i=0; i<numGroups; i++) { 
-                       numComp += i; 
-                       for (int l = i+1; l < numGroups; l++) {
-                               //set group comparison labels
-                               groupComb.push_back(globaldata->Groups[i] + "-" + globaldata->Groups[l]);
-                       }
-               }
-       }
-       catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the UnifracWeightedCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the UnifracWeightedCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-}
-
 /***********************************************************/
 
 void UnifracWeightedCommand::calculateFreqsCumuls() {
@@ -348,7 +284,7 @@ void UnifracWeightedCommand::calculateFreqsCumuls() {
 
 }
 
-/*****************************************************************/
+/*****************************************************************
 
 void UnifracWeightedCommand::initFile(string label){
        try {
@@ -378,7 +314,7 @@ void UnifracWeightedCommand::initFile(string label){
        }
 }
 
-/***********************************************************************/
+/***********************************************************************
 
 void UnifracWeightedCommand::output(vector<double> data){
        try {
@@ -404,7 +340,7 @@ void UnifracWeightedCommand::output(vector<double> data){
        }
 };
 
-/***********************************************************************/
+/***********************************************************************
 
 void UnifracWeightedCommand::resetFile(){
        try {
@@ -427,6 +363,14 @@ void UnifracWeightedCommand::resetFile(){
        catch(...) {
                cout << "An unknown error has occurred in the UnifracWeightedCommand class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
                exit(1);
-       }       
+       }
+       
+       
+                       
 }
 
+*/
+
+
+
+
index ea2c41814ac1940a61bd8c48995ecebcff30f324..751343b3f641d29799c8704d71f6684c04d504ac 100644 (file)
@@ -14,6 +14,8 @@
 #include "weighted.h"
 #include "treemap.h"
 #include "progress.hpp"
+#include "sharedutilities.h"
+#include "fileoutput.h"
 
 using namespace std;
 
@@ -23,11 +25,13 @@ class UnifracWeightedCommand : public Command {
        
        public:
                UnifracWeightedCommand();       
-               ~UnifracWeightedCommand() { delete weighted; }
+               ~UnifracWeightedCommand() { delete weighted; delete util; }
                int execute();  
        
        private:
                GlobalData* globaldata;
+               SharedUtil* util;
+               FileOutput* output;
                vector<Tree*> T;           //user trees
                vector<double> utreeScores;  //user tree unweighted scores
                vector<double> WScoreSig;  //tree weighted score signifigance when compared to random trees - percentage of random trees with that score or lower.
@@ -54,11 +58,10 @@ class UnifracWeightedCommand : public Command {
                void printWeightedFile();  
                //void removeValidScoresDuplicates();
                int findIndex(float, int);
-               void setGroups(); 
                void calculateFreqsCumuls();
-               void initFile(string);
-               void output(vector<double>);
-               void resetFile();
+               //void initFile(string);
+               //void output(vector<double>);
+               //void resetFile();
 
 };
 
diff --git a/utilities.hpp b/utilities.hpp
deleted file mode 100644 (file)
index eea96bf..0000000
+++ /dev/null
@@ -1,392 +0,0 @@
-#ifndef UTILITIES_H
-#define UTILITIES_H
-
-using namespace std;
-
-#include "mothur.h"
-#include "treemap.h"
-
-typedef unsigned long long ull;
-
-/***********************************************************************/
-
-// snagged from http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.2
-// works for now, but there should be a way to do it without killing the whole program
-
-class BadConversion : public runtime_error {
-public:
-       BadConversion(const string& s) : runtime_error(s){ }
-};
-
-//**********************************************************************************************************************
-
-template<typename T>
-inline void convert(const string& s, T& x, bool failIfLeftoverChars = true){
-       istringstream i(s);
-       char c;
-       if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
-               throw BadConversion(s);
-}
-//**********************************************************************************************************************
-
-template<typename T>
-inline bool convertTest(const string& s, T& x, bool failIfLeftoverChars = true){
-       istringstream i(s);
-       char c;
-       if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
-       {
-               cout << "'" << s << "' is unable to be converted into an integer.\n";
-               return false;
-       } 
-       return true;
-}
-
-//**********************************************************************************************************************
-
-template<typename T>
-string toString(const T&x){
-    stringstream output;
-    output << x;
-    return output.str();
-}
-
-//**********************************************************************************************************************
-
-template<typename T>
-string toHex(const T&x){
-       stringstream output;
-       
-       output << hex << x;
-
-    return output.str();
-}
-
-//**********************************************************************************************************************
-
-template<typename T>
-string toString(const T&x, int i){
-       stringstream output;
-       
-       output.precision(i);
-    output << fixed << x;
-       
-    return output.str();
-}
-
-
-/***********************************************************************/
-
-inline void gobble(istream& f){
-       
-       char d;
-    while(isspace(d=f.get()))          {;}
-       f.putback(d);
-       
-}
-
-/***********************************************************************/
-
-inline float roundDist(float dist, int precision){
-       
-       return int(dist * precision + 0.5)/float(precision);
-       
-}
-
-/***********************************************************************/
-
-inline int getNumNames(string names){
-       
-       int count = 0;
-       
-       if(names != ""){
-               count = 1;
-               for(int i=0;i<names.size();i++){
-                       if(names[i] == ','){
-                               count++;
-                       }
-               }
-       }
-       
-       return count;
-       
-}
-
-/**************************************************************************************************/
-
-inline vector<vector<double> > binomial(int maxOrder){
-       
-       vector<vector<double> > binomial(maxOrder+1);
-       
-    for(int i=0;i<=maxOrder;i++){
-               binomial[i].resize(maxOrder+1);
-               binomial[i][0]=1;
-               binomial[0][i]=0;
-    }
-    binomial[0][0]=1;
-       
-    binomial[1][0]=1;
-    binomial[1][1]=1;
-       
-    for(int i=2;i<=maxOrder;i++){
-               binomial[1][i]=0;
-    }
-       
-    for(int i=2;i<=maxOrder;i++){
-               for(int j=1;j<=maxOrder;j++){
-                       if(i==j){       binomial[i][j]=1;                                                                       }
-                       if(j>i) {       binomial[i][j]=0;                                                                       }
-                       else    {       binomial[i][j]=binomial[i-1][j-1]+binomial[i-1][j];     }
-               }
-    }
-       
-       return binomial;
-}
-
-/***********************************************************************/
-
-inline string getRootName(string longName){
-       string rootName = longName;
-       
-       if(longName.find_last_of(".") != longName.npos){
-               int pos = longName.find_last_of('.')+1;
-               rootName = longName.substr(0, pos);
-       }
-
-       return rootName;
-}
-/***********************************************************************/
-
-inline string getSimpleName(string longName){
-       string simpleName = longName;
-       
-       if(longName.find_last_of("/") != longName.npos){
-               int pos = longName.find_last_of('/')+1;
-               simpleName = longName.substr(pos, longName.length());
-       }
-
-       return simpleName;
-}
-
-/***********************************************************************/
-
-inline string getPathName(string longName){
-       string rootPathName = longName;
-       
-       if(longName.find_last_of("/") != longName.npos){
-               int pos = longName.find_last_of('/')+1;
-               rootPathName = longName.substr(0, pos);
-       }
-
-       return rootPathName;
-}
-
-/***********************************************************************/
-
-inline int openInputFile(string fileName, ifstream& fileHandle){
-
-       fileHandle.open(fileName.c_str());
-       if(!fileHandle) {
-               cerr << "Error: Could not open " << fileName << endl;
-               return 1;
-       }
-       else {
-               return 0;
-       }
-       
-}
-
-/***********************************************************************/
-
-inline int openOutputFile(string fileName, ofstream& fileHandle){
-       
-       fileHandle.open(fileName.c_str(), ios::trunc);
-       if(!fileHandle) {
-               cerr << "Error: Could not open " << fileName << endl;
-               return 1;
-       }
-       else {
-               return 0;
-       }
-
-}
-
-/***********************************************************************/
-
-//This function parses the estimator options and puts them in a vector
-inline void splitAtDash(string& estim, vector<string>& container) {
-       try {
-               string individual;
-               
-               while (estim.find_first_of('-') != -1) {
-                       individual = estim.substr(0,estim.find_first_of('-'));
-                       if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
-                               estim = estim.substr(estim.find_first_of('-')+1, estim.length());
-                               container.push_back(individual);
-                       }
-               }
-               //get last one
-               container.push_back(estim);
-       }
-       catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the utilities class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the utilities class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-
-}
-
-/***********************************************************************/
-//This function parses the label options and puts them in a set
-inline void splitAtDash(string& estim, set<string>& container) {
-       try {
-               string individual;
-               
-               while (estim.find_first_of('-') != -1) {
-                       individual = estim.substr(0,estim.find_first_of('-'));
-                       if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
-                               estim = estim.substr(estim.find_first_of('-')+1, estim.length());
-                               container.insert(individual);
-                       }
-               }
-               //get last one
-               container.insert(estim);
-       }
-       catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the utilities class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the utilities class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-
-}
-/***********************************************************************/
-//This function parses the line options and puts them in a set
-inline void splitAtDash(string& estim, set<int>& container) {
-       try {
-               string individual;
-               int lineNum;
-               
-               while (estim.find_first_of('-') != -1) {
-                       individual = estim.substr(0,estim.find_first_of('-'));
-                       if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
-                               estim = estim.substr(estim.find_first_of('-')+1, estim.length());
-                               convert(individual, lineNum); //convert the string to int
-                               container.insert(lineNum);
-                       }
-               }
-               //get last one
-               convert(estim, lineNum); //convert the string to int
-               container.insert(lineNum);
-       }
-       catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the utilities class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the utilities class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-
-}
-/***********************************************************************/
-//This function parses the a string and puts peices in a vector
-inline void splitAtComma(string& estim, vector<string>& container) {
-       try {
-               string individual;
-               
-               while (estim.find_first_of(',') != -1) {
-                       individual = estim.substr(0,estim.find_first_of(','));
-                       if ((estim.find_first_of(',')+1) <= estim.length()) { //checks to make sure you don't have comma at end of string
-                               estim = estim.substr(estim.find_first_of(',')+1, estim.length());
-                               container.push_back(individual);
-                       }
-               }
-               //get last one
-               container.push_back(estim);
-       }
-       catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the utilities class Function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the utilities class function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-}
-/***********************************************************************/
-
-//This function splits up the various option parameters
-inline void splitAtComma(string& prefix, string& suffix){
-       try {
-               prefix = suffix.substr(0,suffix.find_first_of(','));
-               if ((suffix.find_first_of(',')+2) <= suffix.length()) {  //checks to make sure you don't have comma at end of string
-                       suffix = suffix.substr(suffix.find_first_of(',')+1, suffix.length());
-                       string space = " ";
-                       while(suffix.at(0) == ' ')
-                               suffix = suffix.substr(1, suffix.length());
-               }
-
-       }
-       catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the utilities class Function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the utilities class function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-
-}
-/***********************************************************************/
-
-//This function separates the key value from the option value i.e. dist=96_...
-inline void splitAtEquals(string& key, string& value){         
-       try {
-               if(value.find_first_of('=') != -1){
-                       key = value.substr(0,value.find_first_of('='));
-                       if ((value.find_first_of('=')+1) <= value.length()) {
-                               value = value.substr(value.find_first_of('=')+1, value.length());
-                       }
-               }else{
-                       key = value;
-                       value = 1;
-               }
-       }
-       catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the utilities class Function splitAtEquals. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the utilities class function splitAtEquals. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-
-}
-/**************************************************************************************************/
-
-inline bool inUsersGroups(string groupname, vector<string> Groups) {
-       try {
-               for (int i = 0; i < Groups.size(); i++) {
-                       if (groupname == Groups[i]) { return true; }
-               }
-               return false;
-       }
-       catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the utilities class Function inUsersGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the utilities class function inUsersGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-}
-
-#endif
index a875900411bd5b5b3678927e07acbd4e9cd9b9e6..90257c77eefbc1218698ebcc808e66d4c7bd34e9 100644 (file)
@@ -20,6 +20,7 @@ ValidCalculators::ValidCalculators() {
                 initialSharedSummary();
                 initialVennSingle();
                 initialVennShared();
+                initialTreeGroups();
        }
        catch(exception& e) {
                cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function ValidCalculator. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
@@ -132,6 +133,18 @@ bool ValidCalculators::isValidCalculator(string parameter, string calculator) {
                                }
                                cout << endl;
                                return false; }
+               }else if (parameter == "treegroup") {
+                       //is it valid
+                       if ((treegroup.find(calculator)) != (treegroup.end())) {
+                               return true;
+                       }else { 
+                               cout << calculator << " is not a valid estimator for the tree.groups command in shared mode and will be disregarded. Valid estimators are ";
+                               for (it = treegroup.begin(); it != treegroup.end(); it++) {
+                                       cout << it->first << ", ";
+                               }
+                               cout << endl;
+                               return false; }
+
                //not a valid parameter
                }else { return false; }
                
@@ -359,6 +372,31 @@ void ValidCalculators::initialVennShared() {
 }
 
 /********************************************************************/
+void ValidCalculators::initialTreeGroups() {
+       try {   
+               treegroup["sharedjabund"]                       = "sharedjabund";
+               treegroup["sharedsorensonabund"]        = "sharedsorensonabund";
+               treegroup["sharedjclass"]                       = "sharedjclass";
+               treegroup["sharedsorclass"]                     = "sharedsorclass";
+               treegroup["sharedjest"]                         = "sharedjest";
+               treegroup["sharedsorest"]                       = "sharedsorest";
+               treegroup["sharedthetayc"]                      = "sharedthetayc";
+               treegroup["sharedthetan"]                       = "sharedthetan";
+               treegroup["sharedmorisitahorn"]         = "sharedmorisitahorn";
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialTreeGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ValidCalculator class function initialTreeGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+
+/********************************************************************/
+
 
 
 
index 1c39d49253f6f138cbd27523a2fbb86b675e02a5..6cf37924144906276a9aa39c491ffed301c35510 100644 (file)
@@ -33,6 +33,7 @@ class ValidCalculators {
                map<string, string> sharedsummary;
                map<string, string> vennsingle;
                map<string, string> vennshared;
+               map<string, string> treegroup;
                map<string, string>::iterator it;
                
                void initialSingle();
@@ -43,7 +44,7 @@ class ValidCalculators {
                void initialSharedSummary();
                void initialVennSingle();
                void initialVennShared();
-
+               void initialTreeGroups();
 };
 
 #endif
index fed10caf2f62808bc0747a272dcf818989c5fb38..bc9f62c089bdfdded2181dcb53be18e7d37e71c4 100644 (file)
@@ -31,6 +31,7 @@ ValidCommands::ValidCommands() {
                commands["unifrac.weighted"]    = "unifrac.weighted"; 
                commands["unifrac.unweighted"]  = "unifrac.unweighted"; 
                commands["libshuff"]                    = "libshuff";
+               commands["tree.groups"]                 = "tree.groups";
                commands["heatmap"]                             = "heatmap";
                commands["venn"]                                = "venn";
                commands["get.group"]           = "get.group";
index f4780a710a40a0c9ea5d621f6f354c2503f6196a..41ea7cfc32020c5fb977c9e7f1d188c8bdd94f1b 100644 (file)
@@ -283,7 +283,7 @@ void ValidParameters::initCommandParameters() {
                string unifracUnweightedArray[] =  {"groups","iters"};
                commandParameters["unifrac.unweighted"] = addParameters(unifracUnweightedArray, sizeof(unifracUnweightedArray)/sizeof(string));
 
-               string heatmapArray[] =  {"groups","line","label","sorted"};
+               string heatmapArray[] =  {"groups","line","label","sorted","scaler"};
                commandParameters["heatmap"] = addParameters(heatmapArray, sizeof(heatmapArray)/sizeof(string));
 
                string vennArray[] =  {"groups","line","label","calc"};
@@ -295,6 +295,9 @@ void ValidParameters::initCommandParameters() {
                string getOTURepArray[] =  {"fasta","list","line","label","name"};
                commandParameters["get.oturep"] = addParameters(getOTURepArray, sizeof(getOTURepArray)/sizeof(string));
                
+               string treeGroupsArray[] =  {"line","label","calc","groups"};
+               commandParameters["tree.groups"] = addParameters(treeGroupsArray, sizeof(treeGroupsArray)/sizeof(string));
+               
                string quitArray[] = {};
                commandParameters["quit"] = addParameters(quitArray, sizeof(quitArray)/sizeof(string));
 
index 61b1c5b2d90ee0e805bc205c5fe8b19b5a4a5c97..30ba46105cc4fc0585283493878f2bab8931bffd 100644 (file)
@@ -12,7 +12,6 @@
 using namespace std;
 
 #include "mothur.h"
-#include "utilities.hpp"
 
 //This class contains a list of all valid parameters in Mothur.  
 //It has a function which will tell you if your parameter is valid.
index 6da78bb20c895f70b5e17157ac8281bdd16a8d10..9b3d760f66f702512553ddd140a20b4671e2e6ef 100644 (file)
--- a/venn.cpp
+++ b/venn.cpp
@@ -18,6 +18,7 @@ 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";
@@ -72,7 +73,7 @@ void Venn::getPic(SharedOrderVector* sharedorder, vector<Calculator*> vCalcs) {
        try {
                
                //fills vector of sharedsabunds - lookup
-               getSharedVectors(sharedorder);
+               util->getSharedVectors(globaldata->Groups, lookup, sharedorder);  //fills group vectors from order vector.
                
                /******************* 1 Group **************************/
                if (lookup.size() == 1) {
@@ -82,7 +83,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 = globaldata->inputFileName + ".venn." + sharedorder->getLabel() + vCalcs[i]->getName() + "." + groupComb + ".svg";
+                               string filenamesvg = getRootName(globaldata->inputFileName) + sharedorder->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
                                openOutputFile(filenamesvg, outsvg);
                        
                                //in essence you want to run it like a single 
@@ -106,6 +107,7 @@ void Venn::getPic(SharedOrderVector* sharedorder, vector<Calculator*> vCalcs) {
                                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 << "<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";  
                        
                                if (data.size() == 3) { 
@@ -129,7 +131,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 = globaldata->inputFileName + ".venn." + sharedorder->getLabel() + vCalcs[i]->getName() + "." + groupComb + ".svg";
+                               string filenamesvg = getRootName(globaldata->inputFileName) + sharedorder->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
                                openOutputFile(filenamesvg, outsvg);
                                
                                //get estimates for sharedAB
@@ -165,11 +167,22 @@ void Venn::getPic(SharedOrderVector* sharedorder, vector<Calculator*> vCalcs) {
                                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";
                                outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(490 - ((int)toString(numB[0]).length() / 2)) + "\" y=\"195\">" + toString(numB[0] - shared[0]) + "</text>\n"; 
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"175\">" + lookup[0]->getGroup() + "</text>\n";
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(490 - ((int)lookup[1]->getGroup().length() / 2)) + "\" y=\"175\">" + lookup[1]->getGroup() + "</text>\n"; 
                                outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(shared[0]).length() / 2)) + "\" y=\"195\">" + toString(shared[0]) + "</text>\n";  
-                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"460\">The number of species in group " + globaldata->Groups[0] + " is " + toString(numA[0]) + "</text>\n";
-                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"480\">The number of species in group " + globaldata->Groups[1] + " is " + toString(numB[0]) + "</text>\n";
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"460\">The number of species in group " + globaldata->Groups[0] + " is " + toString(numA[0]);
+                               if (numA.size() == 3) { 
+                                       outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]) + "</text>\n";
+                               }else { outsvg << "</text>\n"; }
+               
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"480\">The number of species in group " + globaldata->Groups[1] + " is " + toString(numB[0]);
+                               if (numB.size() == 3) { 
+                                       outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]) + "</text>\n";
+                               }else { outsvg << "</text>\n"; }
+
                                outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"500\">The number of sepecies shared between groups " + globaldata->Groups[0] + " and " + globaldata->Groups[1] + " is " + toString(shared[0]) + "</text>\n";
                                outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"520\">Percentage of species that are shared in groups " + globaldata->Groups[0] + " and " + globaldata->Groups[1] + " is " + toString((shared[0] / (float)(numA[0] + numB[0] - shared[0]))) + "</text>\n";
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"540\">The total richness for all groups is " + toString((float)(numA[0] + numB[0] - shared[0])) + "</text>\n";
                                
                                //close file
                                outsvg << "</g>\n</svg>\n";
@@ -190,7 +203,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 = globaldata->inputFileName + ".venn." + sharedorder->getLabel() + vCalcs[i]->getName() + "." + groupComb + ".svg";
+                               string filenamesvg = getRootName(globaldata->inputFileName) + sharedorder->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
                                openOutputFile(filenamesvg, outsvg);
                                
                                //get estimates for sharedAB, sharedAC and sharedBC
@@ -275,11 +288,14 @@ void Venn::getPic(SharedOrderVector* sharedorder, vector<Calculator*> vCalcs) {
                                outsvg << "<circle fill=\"rgb(0,0,255)\" opacity=\".3\" stroke=\"black\" cx=\"343\" cy=\"400\" r=\"150\"/>"; 
                        
                                //place labels within overlaps
-                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)toString(numA[0]-sharedAwithBC[0]).length() / 2)) + "\" y=\"170\">" + toString(numA[0]-sharedAwithBC[0]) + "</text>\n";  
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)toString(numA[0]-sharedAwithBC[0]).length() / 2)) + "\" y=\"170\">" + toString(numA[0]-sharedAwithBC[0]) + "</text>\n"; 
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"150\">" + lookup[0]->getGroup() + "</text>\n";  
                                outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(sharedAB[0] - sharedABC).length() / 2)) + "\"  y=\"170\">" + toString(sharedAB[0] - sharedABC) + "</text>\n";  
-                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(485 - ((int)toString(numB[0]-sharedBwithAC[0]).length() / 2)) + "\"  y=\"170\">" + toString(numB[0]-sharedBwithAC[0]) + "</text>\n";  
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(485 - ((int)toString(numB[0]-sharedBwithAC[0]).length() / 2)) + "\"  y=\"170\">" + toString(numB[0]-sharedBwithAC[0]) + "</text>\n";
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(485 - ((int)lookup[1]->getGroup().length() / 2)) + "\"  y=\"150\">" + lookup[1]->getGroup() + "</text>\n";  
                                outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(268 - ((int)toString(sharedAC[0] - sharedABC).length() / 2)) + "\"  y=\"305\">" + toString(sharedAC[0] - sharedABC) + "</text>\n";  
-                               outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(343 - ((int)toString(numC[0]-sharedCwithAB[0]).length() / 2)) + "\"   y=\"430\">" + toString(numC[0]-sharedCwithAB[0]) + "</text>\n";  
+                               outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(343 - ((int)toString(numC[0]-sharedCwithAB[0]).length() / 2)) + "\"   y=\"430\">" + toString(numC[0]-sharedCwithAB[0]) + "</text>\n"; 
+                               outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(343 - ((int)lookup[2]->getGroup().length() / 2)) + "\"   y=\"410\">" + lookup[2]->getGroup() + "</text>\n"; 
                                outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(408 - ((int)toString(sharedBC[0] - sharedABC).length() / 2)) + "\" y=\"305\">" + toString(sharedBC[0] - sharedABC) + "</text>\n";  
                                outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(sharedABC).length() / 2)) + "\"  y=\"280\">" + toString(sharedABC) + "</text>\n"; 
                        
@@ -289,10 +305,22 @@ void Venn::getPic(SharedOrderVector* sharedorder, vector<Calculator*> vCalcs) {
                                outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"720\">The number of sepecies shared between groups " + globaldata->Groups[0] + " and combined groups " + globaldata->Groups[1] + globaldata->Groups[2] + " is " + toString(sharedAwithBC[0]) + "</text>\n";
                                outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"740\">The number of sepecies shared between groups " + globaldata->Groups[1] + " and combined groups " + globaldata->Groups[0] + globaldata->Groups[2] + " is " + toString(sharedBwithAC[0]) + "</text>\n";
                                outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"760\">The number of sepecies shared between groups " + globaldata->Groups[2] + " and combined groups " + globaldata->Groups[0] + globaldata->Groups[1] + " is " + toString(sharedCwithAB[0]) + "</text>\n";
-                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"580\">The number of species in group " + globaldata->Groups[0] + " is " + toString(numA[0]) + "</text>\n";
-                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"600\">The number of species in group " + globaldata->Groups[1] + " is " + toString(numB[0]) + "</text>\n";
-                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"620\">The number of species in group " + globaldata->Groups[2] + " is " + toString(numC[0]) + "</text>\n";
-                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"640\">The total number of species in all groups is " + toString(numA[0] + numB[0] + numC[0] - sharedAB[0] - sharedAC[0] - sharedBC[0] + sharedABC) + "</text>\n";
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"580\">The number of species in group " + globaldata->Groups[0] + " is " + toString(numA[0]);
+                               if (numA.size() == 3) { 
+                                       outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]) + "</text>\n";
+                               }else { outsvg << "</text>\n"; }
+               
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"600\">The number of species in group " + globaldata->Groups[1] + " is " + toString(numB[0]);
+                               if (numB.size() == 3) { 
+                                       outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]) + "</text>\n";
+                               }else { outsvg << "</text>\n"; }
+                               
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"620\">The number of species in group " + globaldata->Groups[2] + " is " + toString(numC[0]);
+                               if (numC.size() == 3) { 
+                                       outsvg << " the lci is " + toString(numC[1]) + " and the hci is " + toString(numC[2]) + "</text>\n";
+                               }else { outsvg << "</text>\n"; }
+
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"640\">The total richness of all the groups is " + toString(numA[0] + numB[0] + numC[0] - sharedAB[0] - sharedAC[0] - sharedBC[0] + sharedABC) + "</text>\n";
                                
                                //close file
                                outsvg << "</g>\n</svg>\n";
@@ -335,7 +363,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 = globaldata->inputFileName + ".venn." + sharedorder->getLabel() + "." + groupComb + ".svg";
+                       string filenamesvg = getRootName(globaldata->inputFileName) + sharedorder->getLabel() + ".venn.SharedSobs.svg";
                        openOutputFile(filenamesvg, outsvg);
                
                        //image window
@@ -353,13 +381,17 @@ void Venn::getPic(SharedOrderVector* sharedorder, vector<Calculator*> vCalcs) {
                        //A = red, B = green, C = blue, D = yellow
                        
                        //place labels within overlaps
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(460 - ((int)toString(numA).length() / 2)) + "\" y=\"110\">" + toString(numA) + "</text>\n";  
+                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(460 - ((int)toString(numA).length() / 2)) + "\" y=\"110\">" + toString(numA) + "</text>\n"; 
+                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(460 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"90\">" + lookup[0]->getGroup() + "</text>\n";  
                        outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(350 - ((int)toString(sharedAB).length() / 2)) + "\"  y=\"160\">" + toString(sharedAB) + "</text>\n";  
                        outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(250 - ((int)toString(numB).length() / 2)) + "\"  y=\"110\">" + toString(numB) + "</text>\n";  
+                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(250 - ((int)lookup[1]->getGroup().length() / 2)) + "\"  y=\"90\">" + lookup[1]->getGroup() + "</text>\n"; 
                        outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(490 - ((int)toString(sharedAC).length() / 2)) + "\"  y=\"190\">" + toString(sharedAC) + "</text>\n";  
                        outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(550 - ((int)toString(numC).length() / 2)) + "\"   y=\"230\">" + toString(numC) + "</text>\n";  
+                       outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(550 - ((int)lookup[2]->getGroup().length() / 2)) + "\"   y=\"210\">" + lookup[2]->getGroup() + "</text>\n";
                        outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(215 - ((int)toString(sharedBC).length() / 2)) + "\" y=\"190\">" + toString(sharedBC) + "</text>\n";  
-                       outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(150 - ((int)toString(numC).length() / 2)) + "\"   y=\"230\">" + toString(numD) + "</text>\n";  
+                       outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(150 - ((int)toString(numD).length() / 2)) + "\"   y=\"230\">" + toString(numD) + "</text>\n";  
+                       outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(150 - ((int)lookup[3]->getGroup().length() / 2)) + "\"   y=\"210\">" + lookup[3]->getGroup() + "</text>\n"; 
                        outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(240 - ((int)toString(sharedBC).length() / 2)) + "\" y=\"325\">" + toString(sharedAD) + "</text>\n"; 
                        outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(470 - ((int)toString(sharedBC).length() / 2)) + "\" y=\"325\">" + toString(sharedBD) + "</text>\n";
                        outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(350 - ((int)toString(sharedCD).length() / 2)) + "\" y=\"430\">" + toString(sharedCD) + "</text>\n"; 
@@ -368,8 +400,8 @@ void Venn::getPic(SharedOrderVector* sharedorder, vector<Calculator*> vCalcs) {
                        outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(305 - ((int)toString(sharedACD).length() / 2)) + "\" y=\"360\">" + toString(sharedACD) + "</text>\n"; 
                        outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(440 - ((int)toString(sharedABC).length() / 2)) + "\"  y=\"240\">" + toString(sharedABC) + "</text>\n"; 
                        outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(350 - ((int)toString(sharedABCD).length() / 2)) + "\"  y=\"320\">" + toString(sharedABCD) + "</text>\n"; 
+                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"250\" y=\"490\">The total richness of all the groups is " + toString((float)(numA + numB + numC + numD + sharedAB + sharedAC + sharedAD + sharedBC + sharedBD + sharedCD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD)) + "</text>\n";
                        
-                       //outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"490\">Percentage of species that are shared in groups " + globaldata->Groups[0] + " and " + globaldata->Groups[1] + " is " + toString(((sharedAB + sharedABD + sharedABC + sharedABCD) / (float)(numA + numB + sharedAB + sharedAC + sharedAD + sharedBC + sharedBD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
                        //outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"510\">Percentage of species that are shared in groups " + globaldata->Groups[0] + " and " + globaldata->Groups[2] + " is " + toString(((sharedAC + sharedACD + sharedABC + sharedABCD) / (float)(numA + numC + sharedAB + sharedAC + sharedAD + sharedBC + sharedCD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
                        //outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"530\">Percentage of species that are shared in groups " + globaldata->Groups[0] + " and " + globaldata->Groups[3] + " is " + toString(((sharedAD + sharedACD + sharedABD + sharedABCD) / (float)(numA + numD + sharedAB + sharedAC + sharedAD + sharedBD + sharedCD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
                        //outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"550\">Percentage of species that are shared in groups " + globaldata->Groups[1] + " and " + globaldata->Groups[2] + " is " + toString(((sharedBC + sharedABC + sharedBCD + sharedABCD) / (float)(numB + numC + sharedAB + sharedAC + sharedCD + sharedBD + sharedBC + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
@@ -385,10 +417,6 @@ void Venn::getPic(SharedOrderVector* sharedorder, vector<Calculator*> vCalcs) {
                        outsvg.close();
 
                }
-
-               
-               
-               
                
        }
        catch(exception& e) {
@@ -400,54 +428,5 @@ void Venn::getPic(SharedOrderVector* sharedorder, vector<Calculator*> vCalcs) {
                exit(1);
        }
 }
-//**********************************************************************************************************************
-void Venn::getSharedVectors(SharedOrderVector* order){
-       try {
-       
-               //delete lookup
-               for (int j = 0; j < lookup.size(); j++) {
-                       delete lookup[j];
-               }
-
-               lookup.clear();
-               
-               groupComb = "";
-               
-               //create and initialize vector of sharedvectors, one for each group
-               for (int i = 0; i < globaldata->Groups.size(); i++) { 
-                       SharedRAbundVector* temp = new SharedRAbundVector(order->getNumBins());
-                       temp->setLabel(order->getLabel());
-                       temp->setGroup(globaldata->Groups[i]);
-                       groupComb += globaldata->Groups[i];
-                       lookup.push_back(temp);
-               }
-               
-               int numSeqs = order->size();
-               //sample all the members
-               for(int i=0;i<numSeqs;i++){
-                       //get first sample
-                       individual chosen = order->get(i);
-                       int abundance; 
-                                       
-                       //set info for sharedvector in chosens group
-                       for (int j = 0; j < lookup.size(); j++) { 
-                               if (chosen.group == lookup[j]->getGroup()) {
-                                        abundance = lookup[j]->getAbundance(chosen.bin);
-                                        lookup[j]->set(chosen.bin, (abundance + 1), chosen.group);
-                                        break;
-                               }
-                       }
-               }
-               
-       }
-       catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the Venn class Function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the Venn class function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
 
-}
 
diff --git a/venn.h b/venn.h
index ceb52fda7a5447f812133aea9c343d7ccf8e71b5..398f20bb1872832aed6ab89240ce120a0405f623 100644 (file)
--- a/venn.h
+++ b/venn.h
@@ -18,6 +18,7 @@ using namespace std;
 #include "datavector.hpp"
 #include "globaldata.hpp"
 #include "calculator.h"
+#include "sharedutilities.h"
 
 /***********************************************************************/
 
@@ -31,8 +32,7 @@ class Venn {
                void getPic(SharedOrderVector*, vector<Calculator*>);
 
        private:
-               void getSharedVectors(SharedOrderVector*);
-               
+               SharedUtil* util;
                SAbundVector* sabund;
                GlobalData* globaldata;
                vector<SharedRAbundVector*> lookup;
index 56284811af853a6504cac1adf026d6b6e67f3214..e305f2203b52a11d0ac809be3f35dfaf578ab1b3 100644 (file)
@@ -11,7 +11,7 @@
 #include "ace.h"
 #include "sobs.h"
 #include "chao1.h"
-#include "jackknife.h"
+//#include "jackknife.h"
 #include "sharedsobscollectsummary.h"
 #include "sharedchao1.h"
 #include "sharedace.h"
@@ -24,6 +24,7 @@ VennCommand::VennCommand(){
                globaldata = GlobalData::getInstance();
                format = globaldata->getFormat();
                validCalculator = new ValidCalculators();
+               util = new SharedUtil();
                
                int i;
                
@@ -39,8 +40,8 @@ VennCommand::VennCommand(){
                                                if(abund < 5)
                                                        abund = 10;
                                                vennCalculators.push_back(new Ace(abund));
-                                       }else if (globaldata->Estimators[i] == "jack") {        
-                                               vennCalculators.push_back(new Jackknife());
+                                       //}else if (globaldata->Estimators[i] == "jack") {      
+                                               //vennCalculators.push_back(new Jackknife());
                                        }
                                }
                        }
@@ -80,6 +81,7 @@ VennCommand::~VennCommand(){
        delete input;
        delete read;
        delete venn;
+       delete util;
 }
 
 //**********************************************************************************************************************
@@ -118,7 +120,8 @@ int VennCommand::execute(){
                
                if (format != "list") { 
                        
-                       setGroups();
+                       util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "venn");
+                       globaldata->setGroups("");
                        
                        while(order != NULL){
                
@@ -145,7 +148,7 @@ int VennCommand::execute(){
                        }
                        
                        //reset groups parameter
-                       globaldata->Groups.clear();  globaldata->setGroups("");
+                       globaldata->Groups.clear();  
                        
                }else{
                        while(ordersingle != NULL){
@@ -175,67 +178,4 @@ int VennCommand::execute(){
 }
 
 //**********************************************************************************************************************
-void VennCommand::setGroups() {
-       try {
-               //if the user has not entered specific groups to analyze then do them all
-               if (globaldata->Groups.size() != 0) {
-                       if (globaldata->Groups[0] != "all") {
-                               //check that groups are valid
-                               for (int i = 0; i < globaldata->Groups.size(); i++) {
-                                       if (globaldata->gGroupmap->isValidGroup(globaldata->Groups[i]) != true) {
-                                               cout << globaldata->Groups[i] << " is not a valid group, and will be disregarded." << endl;
-                                               // erase the invalid group from globaldata->Groups
-                                               globaldata->Groups.erase(globaldata->Groups.begin()+i);
-                                       }
-                               }
-                       
-                               //if the user only entered invalid groups
-                               if (globaldata->Groups.size() == 0) { 
-                                       if (globaldata->gGroupmap->namesOfGroups.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++) {
-                                                       globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[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 < globaldata->gGroupmap->namesOfGroups.size(); i++) {
-                                                       globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
-                                               }
-                                       }
-
-                               }
-                       }else{//user has enter "all" and wants the default groups
-                               globaldata->Groups.clear();
-                               for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
-                                       globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
-                               }
-                               globaldata->setGroups("");
-                       }
-               }else {
-                       for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
-                               globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
-                       }
-               }
-               
-               
-               //check to make sure their are only 3 groups
-               if (globaldata->Groups.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 < globaldata->Groups.size(); i++) {
-                               globaldata->Groups.erase(globaldata->Groups.begin()+i);
-                       }
-               }
-               
-       }
-       catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the VennCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the VennCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }               
-
-}
-/***********************************************************/
 
index d91aaef1c7e47185862cf1a681976a31c47ebb75..30ff74eb0433240b784ef221e2e0bdc22d1f4066 100644 (file)
@@ -15,6 +15,7 @@
 #include "sharedlistvector.h"
 #include "venn.h"
 #include "validcalculator.h"
+#include "sharedutilities.h"
 
 
 class GlobalData;
@@ -30,6 +31,7 @@ public:
 private:
        GlobalData* globaldata;
        ReadMatrix* read;
+       SharedUtil* util;
        InputData* input;
        SharedListVector* SharedList;
        SharedOrderVector* order;
@@ -39,8 +41,6 @@ private:
        vector<Calculator*> vennCalculators;    
        ValidCalculators* validCalculator;
        int abund;
-       
-       void setGroups();
 
 };