From 60fdefb3a300b59c3bbeffdca8a5f1f30c6a43af Mon Sep 17 00:00:00 2001 From: westcott Date: Mon, 26 Jan 2009 15:31:55 +0000 Subject: [PATCH] fixed summary.shared bug and set jumble default to 1. --- Mothur.xcodeproj/project.pbxproj | 18 +++ commandfactory.cpp | 2 + errorchecking.cpp | 45 ++++++ errorchecking.h | 3 +- globaldata.cpp | 32 ++-- globaldata.hpp | 9 +- groupmap.cpp | 3 +- groupmap.h | 7 +- nocommand.cpp | 2 +- readtree.cpp | 247 +++++++++++++++++++++++++++++++ readtree.h | 41 ++++- readtreecommand.cpp | 63 ++++++++ readtreecommand.h | 42 ++++++ sharedsabundvector.cpp | 52 ------- summarysharedcommand.cpp | 2 +- tree.cpp | 152 +++++++++++++++++++ tree.h | 38 +++-- treemap.cpp | 116 +++++++++++++++ treemap.h | 51 +++++++ treenode.cpp | 71 +++++++++ treenode.h | 56 +++++++ validcommands.cpp | 3 +- validparameter.cpp | 1 + 23 files changed, 959 insertions(+), 97 deletions(-) create mode 100644 readtreecommand.cpp create mode 100644 readtreecommand.h create mode 100644 treemap.cpp create mode 100644 treemap.h create mode 100644 treenode.cpp create mode 100644 treenode.h diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj index e8d32aa..04ae10a 100644 --- a/Mothur.xcodeproj/project.pbxproj +++ b/Mothur.xcodeproj/project.pbxproj @@ -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 */ @@ -104,6 +107,8 @@ 372E12940F263D5A0095CF7E /* readdistcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readdistcommand.h; sourceTree = ""; }; 372E12950F263D5A0095CF7E /* readdistcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readdistcommand.cpp; sourceTree = ""; }; 372E12EC0F264D320095CF7E /* commandfactory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = commandfactory.cpp; sourceTree = ""; }; + 379293C10F2DE73400B9034A /* treemap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = treemap.h; sourceTree = ""; }; + 379293C20F2DE73400B9034A /* treemap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = treemap.cpp; sourceTree = ""; }; 37AD4CE20F28AEA300AA2D49 /* sharedlistvector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedlistvector.h; sourceTree = ""; }; 37AD4CE30F28AEA300AA2D49 /* sharedlistvector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedlistvector.cpp; sourceTree = ""; }; 37AD4DB90F28E2FE00AA2D49 /* tree.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tree.h; sourceTree = ""; }; @@ -256,6 +261,10 @@ 37D928520F21331F001D4494 /* validcommands.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = validcommands.h; sourceTree = ""; }; 37D928530F21331F001D4494 /* validparameter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = validparameter.cpp; sourceTree = ""; }; 37D928540F21331F001D4494 /* validparameter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = validparameter.h; sourceTree = ""; }; + 37E5F3E10F29FD4200F8D827 /* treenode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = treenode.h; sourceTree = ""; }; + 37E5F3E20F29FD4200F8D827 /* treenode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = treenode.cpp; sourceTree = ""; }; + 37E5F4900F2A3DA800F8D827 /* readtreecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readtreecommand.h; sourceTree = ""; }; + 37E5F4910F2A3DA800F8D827 /* readtreecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readtreecommand.cpp; sourceTree = ""; }; 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 = ""; }; /* End PBXFileReference section */ @@ -430,6 +439,8 @@ 372E12950F263D5A0095CF7E /* readdistcommand.cpp */, 372E126E0F26365B0095CF7E /* readotucommand.h */, 372E126F0F26365B0095CF7E /* readotucommand.cpp */, + 37E5F4900F2A3DA800F8D827 /* readtreecommand.h */, + 37E5F4910F2A3DA800F8D827 /* readtreecommand.cpp */, 37D928270F21331F001D4494 /* sharedcommand.h */, 37D928260F21331F001D4494 /* sharedcommand.cpp */, 37D928470F21331F001D4494 /* summarycommand.h */, @@ -466,6 +477,10 @@ 37D928320F21331F001D4494 /* sharedsabundvector.cpp */, 37AD4DB90F28E2FE00AA2D49 /* tree.h */, 37AD4DBA0F28E2FE00AA2D49 /* tree.cpp */, + 379293C10F2DE73400B9034A /* treemap.h */, + 379293C20F2DE73400B9034A /* treemap.cpp */, + 37E5F3E10F29FD4200F8D827 /* treenode.h */, + 37E5F3E20F29FD4200F8D827 /* treenode.cpp */, ); name = containers; sourceTree = ""; @@ -611,6 +626,9 @@ 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; }; diff --git a/commandfactory.cpp b/commandfactory.cpp index 6e62995..2419369 100644 --- a/commandfactory.cpp +++ b/commandfactory.cpp @@ -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(); } diff --git a/errorchecking.cpp b/errorchecking.cpp index 41c1db9..121a012 100644 --- a/errorchecking.cpp +++ b/errorchecking.cpp @@ -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); + } +} /*******************************************************/ diff --git a/errorchecking.h b/errorchecking.h index f7ddfa7..756f676 100644 --- a/errorchecking.h +++ b/errorchecking.h @@ -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; diff --git a/globaldata.cpp b/globaldata.cpp index f09ea35..87f1cca 100644 --- a/globaldata.cpp +++ b/globaldata.cpp @@ -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 = ""; diff --git a/globaldata.hpp b/globaldata.hpp index 5a1572c..f513d52 100644 --- a/globaldata.hpp +++ b/globaldata.hpp @@ -5,15 +5,18 @@ #include #include #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 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&); 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; + }; //********************************************************************************************************************** diff --git a/groupmap.cpp b/groupmap.cpp index 9cf5d7a..ef262a3 100644 --- a/groupmap.cpp +++ b/groupmap.cpp @@ -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 diff --git a/groupmap.h b/groupmap.h index 75e0fdc..263fc84 100644 --- a/groupmap.h +++ b/groupmap.h @@ -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 #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 namesOfGroups; - - + private: ifstream fileHandle; string groupFileName; diff --git a/nocommand.cpp b/nocommand.cpp index b585318..b9cb61a 100644 --- a/nocommand.cpp +++ b/nocommand.cpp @@ -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; } diff --git a/readtree.cpp b/readtree.cpp index 3a9aa51..9b96861 100644 --- a/readtree.cpp +++ b/readtree.cpp @@ -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 diff --git a/readtree.h b/readtree.h index 41d0305..d363cd6 100644 --- a/readtree.h +++ b/readtree.h @@ -13,18 +13,51 @@ using namespace std; #include #include +#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 index 0000000..452c0ec --- /dev/null +++ b/readtreecommand.cpp @@ -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 index 0000000..0810ab0 --- /dev/null +++ b/readtreecommand.h @@ -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 +#include +#include +#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 diff --git a/sharedsabundvector.cpp b/sharedsabundvector.cpp index b262484..c581d93 100644 --- a/sharedsabundvector.cpp +++ b/sharedsabundvector.cpp @@ -30,60 +30,8 @@ SharedSAbundVector::SharedSAbundVector(int size) : DataVector(), maxRank(0), num newGuy.abundance = 0; data.push_back(newGuy); } - // for(int i=0;i sav) : DataVector(id), data(sav) { - try { - - for(int i=0;i> 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){ diff --git a/summarysharedcommand.cpp b/summarysharedcommand.cpp index 347ed04..139b74e 100644 --- a/summarysharedcommand.cpp +++ b/summarysharedcommand.cpp @@ -30,7 +30,7 @@ SummarySharedCommand::SummarySharedCommand(){ for (i=0; isharedSummaryEstimators.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()); diff --git a/tree.cpp b/tree.cpp index 1aba4ed..03eb171 100644 --- 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 9dee24d..63c7d5f 100644 --- a/tree.h +++ b/tree.h @@ -15,37 +15,33 @@ using namespace std; #include #include #include +#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 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 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 index 0000000..58379da --- /dev/null +++ b/treemap.cpp @@ -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; ifirst << '\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 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 +#include +#include +#include +#include +#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 namesOfGroups; + vector namesOfSeqs; + void print(ostream&); + +private: + ifstream fileHandle; + string groupFileName; + int numGroups; + map::iterator it; + void setNamesOfGroups(string); + map treemap; //sequence name and groupname +}; + +#endif \ No newline at end of file diff --git a/treenode.cpp b/treenode.cpp new file mode 100644 index 0000000..6cd99f9 --- /dev/null +++ b/treenode.cpp @@ -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 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 index 0000000..d17e7b3 --- /dev/null +++ b/treenode.h @@ -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 +#include +#include +#include +#include + +/* 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 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 group; + float branchLength; + int parent; + int lchild; + int rchild; + int vectorIndex; +}; + +#endif \ No newline at end of file diff --git a/validcommands.cpp b/validcommands.cpp index bd9d80e..3a72a2b 100644 --- a/validcommands.cpp +++ b/validcommands.cpp @@ -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"; diff --git a/validparameter.cpp b/validparameter.cpp index b58a8ff..13976a4 100644 --- a/validparameter.cpp +++ b/validparameter.cpp @@ -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"; -- 2.39.2