]> git.donarmstrong.com Git - mothur.git/commitdiff
fixed summary.shared bug and set jumble default to 1.
authorwestcott <westcott>
Mon, 26 Jan 2009 15:31:55 +0000 (15:31 +0000)
committerwestcott <westcott>
Mon, 26 Jan 2009 15:31:55 +0000 (15:31 +0000)
23 files changed:
Mothur.xcodeproj/project.pbxproj
commandfactory.cpp
errorchecking.cpp
errorchecking.h
globaldata.cpp
globaldata.hpp
groupmap.cpp
groupmap.h
nocommand.cpp
readtree.cpp
readtree.h
readtreecommand.cpp [new file with mode: 0644]
readtreecommand.h [new file with mode: 0644]
sharedsabundvector.cpp
summarysharedcommand.cpp
tree.cpp
tree.h
treemap.cpp [new file with mode: 0644]
treemap.h [new file with mode: 0644]
treenode.cpp [new file with mode: 0644]
treenode.h [new file with mode: 0644]
validcommands.cpp
validparameter.cpp

index e8d32aa4a491d48e11ae83d223138908708d34ab..04ae10a3f643989ed037c2d5780da25a8ebf2858 100644 (file)
@@ -10,6 +10,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 */; };
+               379293C30F2DE73400B9034A /* treemap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 379293C20F2DE73400B9034A /* treemap.cpp */; };
                37AD4CE40F28AEA300AA2D49 /* sharedlistvector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37AD4CE30F28AEA300AA2D49 /* sharedlistvector.cpp */; };
                37AD4DBB0F28E2FE00AA2D49 /* tree.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37AD4DBA0F28E2FE00AA2D49 /* tree.cpp */; };
                37AD4DCA0F28F3DD00AA2D49 /* readtree.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37AD4DC90F28F3DD00AA2D49 /* readtree.cpp */; };
@@ -82,6 +83,8 @@
                37D9289D0F21331F001D4494 /* validcalculator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D9284F0F21331F001D4494 /* validcalculator.cpp */; };
                37D9289E0F21331F001D4494 /* validcommands.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928510F21331F001D4494 /* validcommands.cpp */; };
                37D9289F0F21331F001D4494 /* validparameter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928530F21331F001D4494 /* validparameter.cpp */; };
+               37E5F3E30F29FD4200F8D827 /* treenode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37E5F3E20F29FD4200F8D827 /* treenode.cpp */; };
+               37E5F4920F2A3DA800F8D827 /* readtreecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37E5F4910F2A3DA800F8D827 /* readtreecommand.cpp */; };
                8DD76F6A0486A84900D96B5E /* Mothur.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = C6859E8B029090EE04C91782 /* Mothur.1 */; };
 /* End PBXBuildFile section */
 
                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>"; };
+               379293C10F2DE73400B9034A /* treemap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = treemap.h; sourceTree = "<group>"; };
+               379293C20F2DE73400B9034A /* treemap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = treemap.cpp; sourceTree = "<group>"; };
                37AD4CE20F28AEA300AA2D49 /* sharedlistvector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedlistvector.h; sourceTree = "<group>"; };
                37AD4CE30F28AEA300AA2D49 /* sharedlistvector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedlistvector.cpp; sourceTree = "<group>"; };
                37AD4DB90F28E2FE00AA2D49 /* tree.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tree.h; sourceTree = "<group>"; };
                37D928520F21331F001D4494 /* validcommands.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = validcommands.h; sourceTree = "<group>"; };
                37D928530F21331F001D4494 /* validparameter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = validparameter.cpp; sourceTree = "<group>"; };
                37D928540F21331F001D4494 /* validparameter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = validparameter.h; sourceTree = "<group>"; };
+               37E5F3E10F29FD4200F8D827 /* treenode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = treenode.h; sourceTree = "<group>"; };
+               37E5F3E20F29FD4200F8D827 /* treenode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = treenode.cpp; sourceTree = "<group>"; };
+               37E5F4900F2A3DA800F8D827 /* readtreecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readtreecommand.h; sourceTree = "<group>"; };
+               37E5F4910F2A3DA800F8D827 /* readtreecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readtreecommand.cpp; sourceTree = "<group>"; };
                8DD76F6C0486A84900D96B5E /* mothur */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = mothur; sourceTree = BUILT_PRODUCTS_DIR; };
                C6859E8B029090EE04C91782 /* Mothur.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = Mothur.1; sourceTree = "<group>"; };
 /* End PBXFileReference section */
                                372E12950F263D5A0095CF7E /* readdistcommand.cpp */,
                                372E126E0F26365B0095CF7E /* readotucommand.h */,
                                372E126F0F26365B0095CF7E /* readotucommand.cpp */,
+                               37E5F4900F2A3DA800F8D827 /* readtreecommand.h */,
+                               37E5F4910F2A3DA800F8D827 /* readtreecommand.cpp */,
                                37D928270F21331F001D4494 /* sharedcommand.h */,
                                37D928260F21331F001D4494 /* sharedcommand.cpp */,
                                37D928470F21331F001D4494 /* summarycommand.h */,
                                37D928320F21331F001D4494 /* sharedsabundvector.cpp */,
                                37AD4DB90F28E2FE00AA2D49 /* tree.h */,
                                37AD4DBA0F28E2FE00AA2D49 /* tree.cpp */,
+                               379293C10F2DE73400B9034A /* treemap.h */,
+                               379293C20F2DE73400B9034A /* treemap.cpp */,
+                               37E5F3E10F29FD4200F8D827 /* treenode.h */,
+                               37E5F3E20F29FD4200F8D827 /* treenode.cpp */,
                        );
                        name = containers;
                        sourceTree = "<group>";
                                37AD4CE40F28AEA300AA2D49 /* sharedlistvector.cpp in Sources */,
                                37AD4DBB0F28E2FE00AA2D49 /* tree.cpp in Sources */,
                                37AD4DCA0F28F3DD00AA2D49 /* readtree.cpp in Sources */,
+                               37E5F3E30F29FD4200F8D827 /* treenode.cpp in Sources */,
+                               37E5F4920F2A3DA800F8D827 /* readtreecommand.cpp in Sources */,
+                               379293C30F2DE73400B9034A /* treemap.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 6e62995c32306cbcd0c9c9259ae0317a8ff706f9..2419369ef4524f984464f4385734de66e4795d31 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "command.hpp"
 #include "readdistcommand.h"
+#include "readtreecommand.h"
 #include "readotucommand.h"
 #include "clustercommand.h"
 #include "parselistcommand.h"
@@ -50,6 +51,7 @@ Command* CommandFactory::getCommand(string commandName){
 
                         if(commandName == "read.dist")                         {       command = new ReadDistCommand();                }
                else if(commandName == "read.otu")                              {       command = new ReadOtuCommand();                 }
+               else if(commandName == "read.tree")                             {       command = new ReadTreeCommand();                }
                else if(commandName == "cluster")                               {       command = new ClusterCommand();                 }
                else if(commandName == "deconvolute")                   {       command = new DeconvoluteCommand();             }
                else if(commandName == "help")                                  {       command = new HelpCommand();                    }
index 41c1db9e678c5890472d9259017a16f6d6b84dc3..121a0120a17fb1410901a219a95d0361911d7187 100644 (file)
@@ -27,6 +27,7 @@ ErrorCheck::ErrorCheck() {
        groupfile = globaldata->getGroupFile();
        orderfile = globaldata->getOrderFile();
        fastafile = globaldata->getFastaFile();
+       treefile = globaldata->getTreeFile();
        cutoff = globaldata->getCutOff();
        format = globaldata->getFormat();
        method = globaldata->getMethod();
@@ -79,6 +80,7 @@ bool ErrorCheck::checkInput(string input) {
                                if (parameter == "namefile" )           { namefile = value; }
                                if (parameter == "orderfile" )          { orderfile = value; }
                                if (parameter == "fastafile" )          { fastafile = value; }
+                               if (parameter == "treefile" )           { treefile = value; }
                                if (parameter == "groupfile" )          { groupfile = value; }
                                if (parameter == "cutoff" )                     { cutoff = value; }
                                if (parameter == "precision" )          { precision = value; }
@@ -148,6 +150,7 @@ bool ErrorCheck::checkInput(string input) {
                                if (parameter == "orderfile" )          { orderfile = value; }
                                if (parameter == "groupfile" )          { groupfile = value; }
                                if (parameter == "fastafile" )          { fastafile = value; }
+                               if (parameter == "treefile" )           { treefile = value; }
                                if (parameter == "cutoff" )                     { cutoff = value; }
                                if (parameter == "precision" )          { precision = value; }
                                if (parameter == "iters" )                      { iters = value; }
@@ -217,6 +220,8 @@ bool ErrorCheck::checkInput(string input) {
                                validateReadFiles();
                                validateReadPhil();
                        }
+               }else if (commandName == "read.tree") { 
+                       validateTreeFiles(); //checks the treefile and groupfile parameters
                }else if (commandName == "deconvolute") {
                        validateReadFiles();
                }
@@ -387,6 +392,46 @@ void ErrorCheck::validateParseFiles() {
                exit(1);
        }
 }
+/*******************************************************/
+
+/******************************************************/
+//This function checks to make sure the user entered appropriate
+// format parameters on a parselistcommand
+void ErrorCheck::validateTreeFiles() {
+       try {
+               ifstream filehandle;
+               int ableToOpen;
+               
+               //checks for valid files
+       
+               if (treefile == "") { cout << "When executing a read.tree you must enter a treefile and a groupfile." << endl; errorFree = false; }
+               else if (groupfile == "") { cout << "When executing a read.tree you must enter a treefile and a groupfile." << endl; errorFree = false; }
+       
+               //checks parameters on the read command
+               if (treefile != "") {
+                       ableToOpen = openInputFile(treefile, filehandle);
+                       filehandle.close();
+                       if (ableToOpen == 1) { //unable to open
+                               errorFree = false;
+                       }
+                       if (groupfile != "") {
+                               ableToOpen = openInputFile(groupfile, filehandle);
+                               filehandle.close();
+                               if (ableToOpen == 1) { //unable to open
+                                       errorFree = false;;
+                               }
+                       }
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateTreeFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ErrorCheck class function validateTreeFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
 
 /*******************************************************/
 
index f7ddfa7f8cb4aa6ddf7d2d967e77bd7a8c23bc7e..756f676d5b3363887ebf553c956e194420c097d6 100644 (file)
@@ -35,8 +35,9 @@ class ErrorCheck {
                void validateReadDist();
                void validateReadPhil();
                void validateParseFiles();
+               void validateTreeFiles();
                void clear();
-               string phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, orderfile, fastafile, cutoff, format; 
+               string phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, orderfile, fastafile, treefile, cutoff, format; 
                string precision, method, fileroot, label, line, iters, jumble, freq, single, rarefaction, shared, summary;
                string commandName, optionText;
                bool errorFree;
index f09ea358b61c3e30b6880937a9f606969bfca63b..87f1ccae776b9e435c00189ed63317e1595cc374 100644 (file)
@@ -9,6 +9,7 @@ using namespace std;
 
 #include "globaldata.hpp"
 #include "sparsematrix.hpp"
+#include "tree.h"
 #include "rabundvector.hpp"
 #include "sabundvector.hpp"
 #include "listvector.hpp"
@@ -80,7 +81,7 @@ void GlobalData::parseGlobalData(string commandString, string optionText){
                commandName = commandString; //save command name to be used by other classes
                
                //clears out data from previous read
-               if ((commandName == "read.dist") || (commandName == "read.otu") || (commandName == "read.list")) { 
+               if ((commandName == "read.dist") || (commandName == "read.otu") || (commandName == "read.tree")) { 
                        clear();
                }
                
@@ -102,6 +103,7 @@ void GlobalData::parseGlobalData(string commandString, string optionText){
                                if (key == "rabundfile" )       { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund";       }
                                if (key == "sabundfile" )       { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund";       } 
                                if (key == "fastafile" )        { fastafile = value; inputFileName = value; fileroot = value; format = "fasta";         } 
+                               if (key == "treefile" )         { treefile = value; inputFileName = value; fileroot = value; format = "tree";           }
                                if (key == "namefile" )         { namefile = value;             }
                                if (key == "orderfile" )        { orderfile = value;    }
                                if (key == "groupfile" )        { groupfile = value;    }
@@ -165,7 +167,8 @@ void GlobalData::parseGlobalData(string commandString, string optionText){
                        if (key == "listfile" )         { listfile = value; inputFileName = value; fileroot = value; format = "list";           }
                        if (key == "rabundfile" )       { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund";       }
                        if (key == "sabundfile" )       { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund";       }
-                       if (key == "fastafile" )        { fastafile = value; inputFileName = value; fileroot = value; format = "fasta";         } 
+                       if (key == "fastafile" )        { fastafile = value; inputFileName = value; fileroot = value; format = "fasta";         }
+                       if (key == "treefile" )         { treefile = value; inputFileName = value; fileroot = value; format = "tree";           }  
                        if (key == "namefile" )         { namefile = value;             }
                        if (key == "orderfile" )        { orderfile = value;    }
                        if (key == "groupfile" )        { groupfile = value;    }
@@ -226,25 +229,32 @@ void GlobalData::parseGlobalData(string commandString, string optionText){
                if ((listfile != "") && (groupfile != "")) { format = "shared"; }
                                
                //input defaults
-               if (commandString == "collect.single") {
-                       if (singleEstimators.size() == 0) { splitAtDash(single, singleEstimators); }    
+               if (commandName == "collect.single") {
+                       if (singleEstimators.size() == 0) { splitAtDash(single, singleEstimators); }
                }
-               if (commandString == "rarefaction.single") {
+               if (commandName == "rarefaction.single") {
                        if (rareEstimators.size() == 0) { splitAtDash(rarefaction, rareEstimators);  }  
                }
-               if (commandString == "collect.shared") {
+               if (commandName == "collect.shared") {
                        if (sharedEstimators.size() == 0) { splitAtDash(shared, sharedEstimators); }    
                }
-               if (commandString == "summary.single") {
+               if (commandName == "summary.single") {
                        if (summaryEstimators.size() == 0) { splitAtDash(summary, summaryEstimators); }
                }
-               if (commandString == "summary.shared") {
+               if (commandName == "summary.shared") {
                        if (sharedSummaryEstimators.size() == 0) { splitAtDash(sharedsummary, sharedSummaryEstimators); }
                }
-               if (commandString == "rarefaction.shared") {
+               if (commandName == "rarefaction.shared") {
                        if (sharedRareEstimators.size() == 0) { splitAtDash(sharedrarefaction, sharedRareEstimators); }
                }
 
+
+               //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")) {
+                       if (listfile != "") { format = "list"; }
+                       else if (sabundfile != "") { format = "sabund"; }
+                       else if (rabundfile != "") { format = "rabund"; }
+               }
                                
        }
        catch(exception& e) {
@@ -269,6 +279,7 @@ string GlobalData::getSabundFile()          {       return sabundfile;      }
 string GlobalData::getNameFile()               {       return namefile;        }
 string GlobalData::getGroupFile()              {       return groupfile;       }
 string GlobalData::getOrderFile()              {       return orderfile;       }
+string GlobalData::getTreeFile()               {       return treefile;        }
 string GlobalData::getFastaFile()              {       return fastafile;       }
 string GlobalData::getCutOff()                 {       return cutoff;          }
 string GlobalData::getFormat()                 {       return format;          }
@@ -312,13 +323,14 @@ void GlobalData::clear() {
        groupfile               =       ""; 
        orderfile               =       "";
        fastafile               =   "";
+       treefile                =       "";
        cutoff                  =       "10.00";
        format                  =       "";
        precision               =       "100";
        iters                   =       "1000"; 
        line                    =   "";
        label                   =       "";
-       jumble                  =       "0";
+       jumble                  =       "1";
        freq                    =       "100";
        method                  =       "furthest";
        fileroot                =       "";
index 5a1572c26f582a02ae82dcfb729d4be2068ec6f5..f513d526c478e9b2160c51e42f9ce9bac6f58fdb 100644 (file)
@@ -5,15 +5,18 @@
 #include <vector>
 #include <set>
 #include "groupmap.h"
+#include "treemap.h"
 
 using namespace std;
 
 class ListVector;
 class SharedListVector;
 class SparseMatrix;
+class Tree;
 class OrderVector;
 class InputData;
 class GroupMap;
+class TreeMap;
 class SAbundVector;
 
 class GlobalData {
@@ -24,9 +27,11 @@ public:
        InputData* ginput;
        OrderVector* gorder;
        ListVector* glist;
+       Tree* gTree;
        SharedListVector* gSharedList;
        SAbundVector* sabund;
        GroupMap* gGroupmap;
+       TreeMap* gTreemap;
        string inputFileName, helpRequest, commandName;
        bool allLines;
        vector<string> singleEstimators, summaryEstimators, sharedEstimators, rareEstimators, sharedRareEstimators, sharedSummaryEstimators; //holds estimators to be used
@@ -42,6 +47,7 @@ public:
        string getGroupFile();
        string getOrderFile();
        string getFastaFile();
+       string getTreeFile();
        string getCutOff();
        string getFormat();
        string getPrecision();
@@ -71,7 +77,7 @@ public:
        void splitAtDash(string&, set<string>&);
        
 private:
-       string phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, orderfile, fastafile,line, label;
+       string phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, orderfile, fastafile, treefile, line, label;
        string cutoff, format, precision, method, fileroot, iters, jumble, freq, single, rarefaction, shared, summary, sharedsummary, sharedrarefaction;
        static GlobalData* _uniqueInstance;
        GlobalData( const GlobalData& ); // Disable copy constructor
@@ -81,6 +87,7 @@ private:
        ListVector* gListVector;
        SparseMatrix* gSparseMatrix;
        
+       
 };
 
 //**********************************************************************************************************************
index 9cf5d7a53acf2f421bea5aeb7601a3efe674aee3..ef262a37cd5f0bc273b6d07ddfe62574a4aac5fd 100644 (file)
@@ -3,7 +3,7 @@
  *  Dotur
  *
  *  Created by Sarah Westcott on 12/1/08.
- *  Copyright 2008 __MyCompanyName__. All rights reserved.
+ *  Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved.
  *
  */
 
@@ -71,4 +71,3 @@ void GroupMap::setNamesOfGroups(string seqGroup) {
                                namesOfGroups.push_back(seqGroup); //new group
                        }
 }
-/************************************************************/
\ No newline at end of file
index 75e0fdcf8a7f9f69df01245f6e09e1e9038bde93..263fc845b00f535d6d5db76e79d07470851b4481 100644 (file)
@@ -5,7 +5,7 @@
  *  Dotur
  *
  *  Created by Sarah Westcott on 12/1/08.
- *  Copyright 2008 __MyCompanyName__. All rights reserved.
+ *  Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved.
  *
  */
 
@@ -16,6 +16,8 @@
 #include <fstream>
 #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. */
 
 class GroupMap {
 public:
@@ -25,8 +27,7 @@ public:
        int getNumGroups();
        string getGroup(string);
        vector<string> namesOfGroups;
-       
-       
+               
 private:
        ifstream fileHandle;
        string groupFileName;
index b58531871a2237e5e7e142beea477ab1a7e835b4..b9cb61a7c6ea3cacbf8f9fd64d3041ffd2c7ec3b 100644 (file)
@@ -21,7 +21,7 @@ NoCommand::~NoCommand(){}
 
 int NoCommand::execute(){
        //Could choose to give more help here?fdsah
-       cout << "Invalid command - choices are read.phylip(), read.column(), read.list(), read.rabund(), read.sabund(), cluster(), collect(), collect.shared(), parselist(), shared(), rarefaction(), summary(), summary.shared(), quit(), help()." << "\n";
+       cout << "Invalid command - choices are read.dist(), read.otu(), read.tree(), cluster(), deconvolute(), collect.single(), collect.shared(), rarefaction.single(), summary.single(), summary.shared(), quit(), help()." << "\n";
        cout << "For more information on command parameters use the help() command." << "\n";
        return 0;
 }
index 3a9aa51c5052ea331592f4e9ee51164b69f1170c..9b96861a661a6a794120f2d47899222f3664e33b 100644 (file)
@@ -9,3 +9,250 @@
 
 #include "readtree.h"
 
+/***********************************************************************/
+//Parent Class
+// The following functions are used by all reading formats.
+/***********************************************************************/
+ReadTree::ReadTree() { 
+       try {
+               globaldata = GlobalData::getInstance(); 
+               T = new Tree(); 
+               numNodes = T->getNumNodes();
+               numLeaves = T->getNumLeaves();
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ReadTree class Function ReadTree. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ReadTree class function ReadTree. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+/***********************************************************************/
+int ReadTree::readSpecialChar(istream& f, char c, string name) {
+    try {
+               char d;
+       
+               while(isspace(d=f.get()))               {;}
+               if(d == EOF){
+                       cerr << "Error: Input file ends prematurely, expecting a " << name << "\n";
+                       exit(1);
+               }
+               if(d != c){
+                       cerr << "Error: Expected " << name << " in input file.  Found " << d << ".\n";
+                       exit(1);
+               }
+               if(d == ')' && f.peek() == '\n'){
+                       while(isspace(d=f.get()))               {;}
+                       f.putback(d);
+               }       
+       
+               return d;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ReadTree class Function readSpecialChar. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ReadTree class function readSpecialChar. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+/**************************************************************************************************/
+
+int ReadTree::readNodeChar(istream& f) {
+       try {
+               char d;
+               while(isspace(d=f.get()))               {;}
+               if(d == EOF){
+                       cerr << "Error: Input file ends prematurely, expecting a left parenthesis\n";
+                       exit(1);
+               }
+               return d;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ReadTree class Function readNodeChar. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ReadTree class function readNodeChar. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+
+/**************************************************************************************************/
+
+float ReadTree::readBranchLength(istream& f) {
+    try {
+               float b;
+       
+               if(!(f >> b)){
+                       cerr << "Error: Missing branch length in input tree.\n";
+                       exit(1);
+               }
+    
+               return b;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ReadTree class Function readBranchLength. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ReadTree class function readBranchLength. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+
+
+/***********************************************************************/
+/***********************************************************************/
+
+
+//Child Classes Below
+
+/***********************************************************************/
+/***********************************************************************/
+//This class reads a file in Newick form and stores it in a tree.
+
+void ReadNewickTree::read() {
+       try {
+               int n = 0;
+               int lc, rc; 
+               
+               int rooted = 0;
+       
+               int ch = filehandle.peek();     
+               
+               if(ch == '('){
+                       n = numLeaves;  //number of leaves / sequences, we want node 1 to start where the leaves left off
+                       lc = readNewickInt(filehandle, n, T);
+               
+                       if(filehandle.peek()==','){                                                     
+                               readSpecialChar(filehandle,',',"comma");
+                       }
+                       // ';' means end of tree.                                                                                               
+                       else if((ch=filehandle.peek())==';' || ch=='['){                
+                               rooted = 1;                                                                     
+                       }                                                                                               
+                       if(rooted != 1){                                                                
+                               rc = readNewickInt(filehandle, n, T);
+                               if(filehandle.peek() == ')'){                                   
+                                       readSpecialChar(filehandle,')',"right parenthesis");
+                               }                                                                                       
+                       }                                                                                               
+               }
+               //note: treeclimber had the code below added - not sure why?
+                else{
+                       filehandle.putback(ch);
+                       char name[MAX_LINE];
+                       filehandle.get(name, MAX_LINE,'\n');
+                       SKIPLINE(filehandle, ch);
+               
+               
+                       n = T->getIndex(name);
+                       if(n!=0){
+                               cerr << "Internal error: The only taxon is not taxon 0.\n";
+                               exit(1);
+                       }
+                       lc = rc = -1;
+               } 
+               
+               while((ch=filehandle.get())!=';'){;}                                            
+                       if(rooted != 1){                                                                        
+                       T->tree[n].setChildren(lc,rc);
+                       T->tree[n].setBranchLength(0);
+                       T->tree[n].setParent(-1);
+                       if(lc!=-1){             T->tree[lc].setParent(n);               }
+                       if(rc!=-1){             T->tree[rc].setParent(n);               }
+               }
+               
+               //save tree for later commands
+               globaldata->gTree = T;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ReadNewickTree class Function read. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ReadNewickTree class function read. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+/**************************************************************************************************/
+
+int ReadNewickTree::readNewickInt(istream& f, int& n, Tree* T) {
+       try {
+               int c = readNodeChar(f);
+    
+               if(c == '('){
+                       int lc = readNewickInt(f, n, T);
+                       readSpecialChar(f,',',"comma");
+               
+                       int rc = readNewickInt(f, n, T);                
+                       if(f.peek()==')'){      
+                               readSpecialChar(f,')',"right parenthesis");                                     
+                       }                       
+               
+                       if(f.peek() == ':'){                                                                          
+                               readSpecialChar(f,':',"colon");                                                 
+                               if(n >= numNodes){      cerr << "Error: Too many nodes in input tree\n";  exit(1); }
+                               T->tree[n].setBranchLength(readBranchLength(f));
+                       }else{T->tree[n].setBranchLength(0.0); }                                                
+               
+                       T->tree[n].setChildren(lc,rc);
+                       T->tree[lc].setParent(n);
+                       T->tree[rc].setParent(n);
+               
+                       return n++;
+               }else{
+                       f.putback(c);
+                       string name = "";
+                       char d=f.get();
+                       while(d != ':' && d != ',' && d!=')' && d!='\n'){                                       
+                               name += d;
+                               d=f.get();
+                       }
+               
+                       int blen = 0;
+                       if(d == ':')    {               blen = 1;                       }               
+               
+                       f.putback(d);
+               
+                       //set group info
+                       string group = globaldata->gTreemap->getGroup(name);
+                       
+                       //find index in tree of name
+                       int n1 = T->getIndex(name);
+                       
+                       if(n1 == -1){cerr << "Name: " << name << " not found\n"; exit(1);}
+                       
+                       else T->tree[n1].setGroup(group);
+               
+                       T->tree[n1].setChildren(-1,-1);
+               
+                       if(blen == 1){  
+                               f.get();                
+                               T->tree[n1].setBranchLength(readBranchLength(f));
+                       }else{
+                               T->tree[n1].setBranchLength(0.0);
+                       }
+               
+                       while((c=f.get())!=0 && (c != ':' && c != ',' && c!=')') )              {;}             
+                       f.putback(c);
+               
+                       return n1;
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ReadNewickTree class Function readNewickInt. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ReadNewickTree class function readNewickInt. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+/**************************************************************************************************/
+/**************************************************************************************************/
+    
\ No newline at end of file
index 41d03058d6478cb371737dbc385c8bb5d0a1c999..d363cd6884835558fba84e9ebaad678c4efe21b5 100644 (file)
@@ -13,18 +13,51 @@ using namespace std;
 
 #include <string>
 #include <iostream>
+#include "globaldata.hpp"
+#include "tree.h"
 
+#define MAX_LINE               513
+#define SKIPLINE(f,c)  {while((c=f.get())!=EOF && ((c) != '\n')){}}
+
+class Tree;
+
+/****************************************************************************/
 
 class ReadTree {
        public:
-               ReadTree();
-               ~ReadTree();
+               ReadTree(); 
+               ~ReadTree() {};
+               
+               virtual void read() {};
+               int readSpecialChar(istream&, char, string);
+               int readNodeChar(istream& f);
+               float readBranchLength(istream& f);
+
+                               
+               Tree* getTree()  { return T; }
+               
+               int numNodes, numLeaves;
+               GlobalData* globaldata;
                
+       protected:
+               Tree* T;
+};
+
+/****************************************************************************/
+
+class ReadNewickTree : public ReadTree {
        
-       private:
+public:
+       ReadNewickTree(string file) : treeFile(file) { openInputFile(file, filehandle); }
+       ~ReadNewickTree() {};
+       void read();
        
-
+private:
+       int readNewickInt(istream&, int&, Tree*);
+       ifstream filehandle;
+       string treeFile;
 };
 
+/****************************************************************************/
 
 #endif
\ No newline at end of file
diff --git a/readtreecommand.cpp b/readtreecommand.cpp
new file mode 100644 (file)
index 0000000..452c0ec
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ *  readtreecommand.cpp
+ *  Mothur
+ *
+ *  Created by Sarah Westcott on 1/23/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "readtreecommand.h"
+
+//**********************************************************************************************************************
+ReadTreeCommand::ReadTreeCommand(){
+       try {
+               globaldata = GlobalData::getInstance();
+               filename = globaldata->inputFileName;
+               
+               //read in group map info.
+               treeMap = new TreeMap(globaldata->getGroupFile());
+               treeMap->readMap();
+               globaldata->gTreemap = treeMap;
+
+               read = new ReadNewickTree(filename);
+               
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ReadTreeCommand class Function ReadTreeCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ReadTreeCommand class function ReadTreeCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+//**********************************************************************************************************************
+
+ReadTreeCommand::~ReadTreeCommand(){
+       delete read;
+}
+
+//**********************************************************************************************************************
+
+int ReadTreeCommand::execute(){
+       try {
+       
+               read->read(); 
+               
+               Tree* T = globaldata->gTree;
+//             T->createNewickFile();
+               
+               return 0;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ReadTreeCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ReadTreeCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
\ No newline at end of file
diff --git a/readtreecommand.h b/readtreecommand.h
new file mode 100644 (file)
index 0000000..0810ab0
--- /dev/null
@@ -0,0 +1,42 @@
+#ifndef READTREECOMMAND_H
+#define READTREECOMMAND_H
+
+/*
+ *  readtreecommand.h
+ *  Mothur
+ *
+ *  Created by Sarah Westcott on 1/23/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include <Carbon/Carbon.h>
+#include <iostream>
+#include <fstream>
+#include "command.hpp"
+#include "readtree.h"
+#include "treemap.h"
+
+class GlobalData;
+
+class ReadTreeCommand : public Command {
+public:
+       ReadTreeCommand();
+       ~ReadTreeCommand();
+       int execute();
+       
+private:
+       GlobalData* globaldata;
+       ReadTree* read;
+       TreeMap* treeMap;
+       string filename;
+};
+
+
+
+
+
+
+
+
+#endif
\ No newline at end of file
index b2624840e568d5d90715db1d662bc0ee5d8e7567..c581d939870abeb8f880824c6df263c60e021a72 100644 (file)
@@ -30,60 +30,8 @@ SharedSAbundVector::SharedSAbundVector(int size) :   DataVector(), maxRank(0), num
                        newGuy.abundance = 0;
                        data.push_back(newGuy);
                }
-       //      for(int i=0;i<data.size();i++){
-       //              if(data[i].abundance != 0){     maxRank = i;    }
-       //              numSeqs += i*data[i].abundance;
-       //              numBins += data[i].abundance;
-       //      }
-
 };
 
-/***********************************************************************
-
-SharedSAbundVector::SharedSAbundVector(string id, vector<int> sav) : DataVector(id), data(sav) {
-       try {
-               
-               for(int i=0;i<sav.size();i++){
-                       if(data[i] != 0){       maxRank = i;    }
-                       numSeqs += i*data[i];
-                       numBins += data[i];
-               }
-       }
-       catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function SharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the SharedSAbundVector class function SharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-}
-
-/***********************************************************************
-
-SharedSAbundVector::SharedSAbundVector(ifstream& f): DataVector(), maxRank(0), numBins(0), numSeqs(0) {
-       try {
-               int hold;
-               f >> label >> hold;
-       
-               data.assign(hold+1, 0);
-               int inputData;
-       
-               for(int i=1;i<=hold;i++){
-                       f >> inputData;
-                       set(i, inputData);
-               }
-       }
-       catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the SharedSAbundVector class Function SharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the SharedSAbundVector class function SharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-}
-
 /***********************************************************************/
 
 void SharedSAbundVector::set(int bin, int abundance, string groupName){
index 347ed0446c5e7c72cba1fac4dbab452b2992a606..139b74e762734957c95ccb659434e32068289162 100644 (file)
@@ -30,7 +30,7 @@ SummarySharedCommand::SummarySharedCommand(){
                for (i=0; i<globaldata->sharedSummaryEstimators.size(); i++) {
                        if (globaldata->sharedSummaryEstimators[i] == "sharedSobs") { 
                                sumCalculators.push_back(new SharedSobs());
-                       }else if (globaldata->sharedEstimators[i] == "sharedChao") { 
+                       }else if (globaldata->sharedSummaryEstimators[i] == "sharedChao") { 
                                sumCalculators.push_back(new SharedChao1());
                        }else if (globaldata->sharedSummaryEstimators[i] == "sharedAce") { 
                                sumCalculators.push_back(new SharedAce());
index 1aba4ede5e3d810d603d4f21a869b90fa26f76fc..03eb17127d5ebc174c8c3018452eb36290fb9346 100644 (file)
--- a/tree.cpp
+++ b/tree.cpp
@@ -9,3 +9,155 @@
 
 #include "tree.h"
 
+
+/*****************************************************************/
+Tree::Tree() {
+       try {
+               globaldata = GlobalData::getInstance();
+
+               numLeaves = globaldata->gTreemap->getNumSeqs();
+               numNodes = 2*numLeaves - 1;
+               
+               tree.resize(numNodes);
+
+               //initialize tree with correct number of nodes, name and group info.
+               for (int i = 0; i < numNodes; i++) {
+
+                       //initialize leaf nodes
+                       if (i <= (numLeaves-1)) {
+                               tree[i].setName(globaldata->gTreemap->namesOfSeqs[i]);
+                               tree[i].setGroup(globaldata->gTreemap->getGroup(globaldata->gTreemap->namesOfSeqs[i]));
+                               //the node knows its index
+                               tree[i].setIndex(i);
+                               //Treemap knows name, group and index to speed up search
+                               globaldata->gTreemap->setIndex(globaldata->gTreemap->namesOfSeqs[i], i);
+                       //intialize non leaf nodes
+                       }else if (i > (numLeaves-1)) {
+                               tree[i].setName("");
+                               tree[i].setGroup("");
+                               //the node knows its index
+                               tree[i].setIndex(i);
+                       }
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the Tree class Function Tree. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the Tree class function Tree. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+
+/*****************************************************************/
+
+int Tree::getIndex(string searchName) {
+       try {
+               //Treemap knows name, group and index to speed up search
+               // getIndex function will return the vector index or -1 if seq is not found.
+               int index = globaldata->gTreemap->getIndex(searchName);
+               return index;
+               
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the Tree class Function getIndex. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the Tree class function getIndex. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+/*****************************************************************/
+
+void Tree::setIndex(string searchName, int index) {
+       try {
+               //set index in treemap
+               globaldata->gTreemap->setIndex(searchName, index);
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the Tree class Function setIndex. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the Tree class function setIndex. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+
+
+/*****************************************************************/
+// This prints out the tree in Newick form.
+void Tree::createNewickFile() {
+       try {
+               int root = findRoot();
+               filename = getRootName(globaldata->getTreeFile()) + "newick";
+               openOutputFile(filename, out);
+               
+               printBranch(root);
+               
+               // you are at the end of the tree
+               out << ";" << endl;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the Tree class Function createNewickFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the Tree class function createNewickFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+
+/*****************************************************************/
+//This function finds the index of the root node.
+
+int Tree::findRoot() {
+       try {
+               for (int i = 0; i < numNodes; i++) {
+                       //you found the root
+                       if (tree[i].getParent() == -1) { return i; }
+               }
+               return -1;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the Tree class Function findRoot. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the Tree class function findRoot. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+
+/*****************************************************************/
+void Tree::printBranch(int node) {
+       try {
+               
+               // you are not a leaf
+               if (tree[node].getLChild() != -1) {
+                       out << "(";
+                       printBranch(tree[node].getLChild());
+                       out << ",";
+                       printBranch(tree[node].getRChild());
+                       out << ")";
+               }else { //you are a leaf
+                       tree[node].printNode(out);  //prints out name and branch length
+               }
+               
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the Tree class Function printBranch. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the Tree class function printBranch. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+
+/*****************************************************************/
+
+
+
diff --git a/tree.h b/tree.h
index 9dee24d2eec051428b9cbb977042a91195cca5f5..63c7d5f5cdc2a170e2eef909565842dcbf1fcef2 100644 (file)
--- a/tree.h
+++ b/tree.h
@@ -15,37 +15,33 @@ using namespace std;
 #include <string>
 #include <iostream>
 #include <vector>
+#include "treenode.h"
+#include "globaldata.hpp"
 
-struct Node  {
-               string  name;
-               string  group;
-               float   branchLength;
-               Node*   parent;
-               Node*   lchild;
-               Node*   rchild;
-};             
+/* This class represents the treefile. */
 
 
 
 class Tree {
        public: 
-               Tree();
-               ~Tree();
-               
-               Node* getParent(Node);
-               Node* getLChild(Node);
-               Node* getRChild(Node);
-               
-               void setParent(Node);
-               void setLChild(Node);
-               void setRChild(Node);
-               
+               Tree();  
+               ~Tree() {};
                
                Tree generateRandomTree();
-               
-               vector<Node> leaves;            //gives you easy access to the leaves of the tree to generate the parsimony score
+               void createNewickFile();
+               int getIndex(string);
+               void setIndex(string, int);
+               int getNumNodes() { return numNodes; }
+               int getNumLeaves(){     return numLeaves;}
+               vector<Node> tree;              //the first n nodes are the leaves, where n is the number of sequences.
                
        private:
+               GlobalData* globaldata;
+               int findRoot();  //return index of root node
+               void printBranch(int);  //recursively print out tree
+               int numNodes, numLeaves;
+               ofstream out;
+               string filename;
 };
 
 
diff --git a/treemap.cpp b/treemap.cpp
new file mode 100644 (file)
index 0000000..58379da
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ *  treemap.cpp
+ *  Mothur
+ *
+ *  Created by Sarah Westcott on 1/26/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "treemap.h"
+
+/************************************************************/
+
+ TreeMap::TreeMap(string filename) {
+       groupFileName = filename;
+       openInputFile(filename, fileHandle);
+}
+
+/************************************************************/
+ TreeMap::~TreeMap(){};
+
+/************************************************************/
+void TreeMap::readMap() {
+               string seqName, seqGroup;
+       
+               while(fileHandle){
+                       fileHandle >> seqName;                  //read from first column
+                       fileHandle >> seqGroup;                 //read from second column
+                       
+                       namesOfSeqs.push_back(seqName);
+                       setNamesOfGroups(seqGroup);
+                                               
+                       treemap[seqName].groupname = seqGroup;  //store data in map
+               
+                       gobble(fileHandle);
+               }
+               fileHandle.close();
+}
+/************************************************************/
+
+int TreeMap::getNumGroups() {
+                       
+       return namesOfGroups.size();    
+               
+}
+/************************************************************/
+
+int TreeMap::getNumSeqs() {
+                       
+       return namesOfSeqs.size();      
+               
+}
+
+/************************************************************/
+
+string TreeMap::getGroup(string sequenceName) {
+                       
+       it = treemap.find(sequenceName);
+       if (it != treemap.end()) { //sequence name was in group file
+               return it->second.groupname;    
+       }else {
+               return "not found";
+       }
+               
+}
+/************************************************************/
+void TreeMap::setIndex(string seq, int index) {
+       treemap[seq].vectorIndex = index;
+}
+/************************************************************/
+int TreeMap::getIndex(string seq) {
+       
+       it = treemap.find(seq);
+       // if it is a valid sequence name then return index
+       if (it != treemap.end()) { return treemap[seq].vectorIndex; }
+       // if not return error code
+       else { return -1; }
+       
+}
+/************************************************************/
+
+void TreeMap::setNamesOfGroups(string seqGroup) {
+                       int i, count;
+                       count = 0;
+                       for (i=0; i<namesOfGroups.size(); i++) {
+                               if (namesOfGroups[i] != seqGroup) {
+                                       count++; //you have not found this group
+                               }else {
+                                       break; //you already have it
+                               }
+                       }
+                       if (count == namesOfGroups.size()) {
+                               namesOfGroups.push_back(seqGroup); //new group
+                       }
+}
+
+/***********************************************************************/
+
+void TreeMap::print(ostream& output){
+       try {
+               
+               for(it = treemap.begin(); it != treemap.end(); it++){
+                       output << it->first << '\t' << it->second.groupname << '\t' << it->second.vectorIndex << endl;
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the TreeMap class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the TreeMap class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/************************************************************/
\ No newline at end of file
diff --git a/treemap.h b/treemap.h
new file mode 100644 (file)
index 0000000..20bbcfe
--- /dev/null
+++ b/treemap.h
@@ -0,0 +1,51 @@
+#ifndef TREEMAP_H
+#define TREEMAP_H
+/*
+ *  treemap.h
+ *  Mothur
+ *
+ *  Created by Sarah Westcott on 1/26/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include <Carbon/Carbon.h>
+#include <map>
+#include <string>
+#include <iostream>
+#include <fstream>
+#include "utilities.hpp"
+
+/* This class is used by the read.tree command to build the tree container. */
+
+struct GroupIndex {
+       string  groupname;
+       int             vectorIndex;
+};
+
+
+
+class TreeMap {
+public:
+       TreeMap(string);
+       ~TreeMap();
+       void readMap();
+       int getNumGroups();
+       int getNumSeqs();
+       void setIndex(string, int);  //sequencename, index
+       int getIndex(string);           //returns vector index of sequence
+       string getGroup(string);
+       vector<string> namesOfGroups;
+       vector<string> namesOfSeqs;
+       void print(ostream&);
+       
+private:
+       ifstream fileHandle;
+       string groupFileName;
+       int numGroups;
+       map<string, GroupIndex>::iterator it;
+       void setNamesOfGroups(string); 
+       map<string, GroupIndex> treemap; //sequence name and groupname
+};
+
+#endif
\ No newline at end of file
diff --git a/treenode.cpp b/treenode.cpp
new file mode 100644 (file)
index 0000000..6cd99f9
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ *  treenode.cpp
+ *  Mothur
+ *
+ *  Created by Sarah Westcott on 1/23/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "treenode.h"
+
+
+/****************************************************************/     
+Node::Node() {
+       //initialize node
+       name = "";
+       branchLength = -1;
+       parent = -1;
+       lchild = -1;
+       rchild = -1;
+       
+}
+/****************************************************************/
+void Node::setName(string Name) {  name = Name; }
+/****************************************************************/
+//non leaf nodes will belong to multiple groups, leaf nodes will only belong to one.
+void Node::setGroup(string groups)  { group.push_back(groups); }
+/****************************************************************/
+void Node::setBranchLength(float l) { branchLength = l; }
+/****************************************************************/
+void Node::setParent(int p)  { parent = p; }
+/****************************************************************/
+void Node::setIndex(int i)  { vectorIndex = i; }
+/****************************************************************/
+void Node::setChildren(int lc, int rc) { lchild = lc; rchild = rc; }   //leftchild, rightchild
+/****************************************************************/
+string Node::getName() { return name; }
+/****************************************************************/
+vector<string> Node::getGroup() { return group; }
+/****************************************************************/
+float Node::getBranchLength() { return branchLength; }
+/****************************************************************/
+int Node::getParent() { return parent; }
+/****************************************************************/
+int Node::getLChild() { return lchild; }
+/****************************************************************/
+int Node::getRChild() { return rchild; }
+/****************************************************************/
+int Node::getIndex() { return vectorIndex; }
+/****************************************************************/
+//to be used by printTree in the Tree class to print the leaf info                     
+void Node::printNode(ostream& out) {
+       try{
+               out << name;
+               
+               //there is a branch length
+               if (branchLength != -1) { 
+                       out << ":" << setprecision(4) << branchLength; 
+               }
+               
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the Node class Function printNode. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the Node class function printNode. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+/****************************************************************/     
\ No newline at end of file
diff --git a/treenode.h b/treenode.h
new file mode 100644 (file)
index 0000000..d17e7b3
--- /dev/null
@@ -0,0 +1,56 @@
+#ifndef TREENODE_H
+#define TREENODE_H
+
+/*
+ *  treenode.h
+ *  Mothur
+ *
+ *  Created by Sarah Westcott on 1/23/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+using namespace std;
+
+#include <string>
+#include <iostream>
+#include <fstream>
+#include <iomanip>
+#include <vector>
+
+/* This class represents a node on a tree. */
+
+
+class Node  {
+       public:
+               Node();  //pass it the sequence name
+               ~Node() {};
+               
+               void setName(string);
+               void setGroup(string);  //non leaf nodes will belong to multiple groups, leaf nodes will only belong to one.
+               void setBranchLength(float);
+               void setParent(int);
+               void setChildren(int, int);             //leftchild, rightchild
+               void setIndex(int);
+               
+               string getName();
+               vector<string> getGroup();    //leaf nodes will only have 1 group, but branch nodes may have multiple groups.
+               float getBranchLength();
+               int getParent();
+               int getLChild();
+               int getRChild();
+               int getIndex();
+               
+               void printNode(ostream&);   //prints out the name and the branch length
+               
+       private:
+               string                  name;
+               vector<string>  group;
+               float                   branchLength;
+               int                             parent;
+               int                             lchild;
+               int                             rchild;
+               int                             vectorIndex;
+};             
+
+#endif
\ No newline at end of file
index bd9d80eb9efb960fcb8bec4218a30be7e198b04a..3a72a2ba3eb64c6c23a5ae7ebdf7b4b4a5cd8ad7 100644 (file)
@@ -15,7 +15,8 @@ ValidCommands::ValidCommands() {
        try {
        
                commands["read.dist"]                   = "read.dist"; 
-               commands["read.otu"]                    = "read.otu"; 
+               commands["read.otu"]                    = "read.otu";
+       //      commands["read.tree"]                   = "read.tree"; 
                commands["cluster"]                             = "cluster"; 
                commands["deconvolute"]                 = "deconvolute"; 
                commands["help"]                                = "help"; 
index b58a8ff8878b76da789a0f2a1ebc1784a11781bf..13976a4eb8955347cf42db74dc957fd8b329bf1e 100644 (file)
@@ -23,6 +23,7 @@ ValidParameters::ValidParameters() {
                parameters["groupfile"]                 = "groupfile"; 
                parameters["orderfile"]                 = "orderfile"; 
                parameters["fastafile"]                 = "fastafile"; 
+               parameters["treefile"]                  = "treefile";
                parameters["fileroot"]                  = "fileroot";
                parameters["cutoff"]                    = "cutoff"; 
                parameters["method"]                    = "method";