X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=tree.h;h=c8e8478edb8f313ab16d4dbeebf0a3d60a0a2698;hp=9dee24d2eec051428b9cbb977042a91195cca5f5;hb=cf9987b67aa49777a4c91c2d21f96e58bf17aa82;hpb=4761e165b4a196fefa57755d3176d9ced19df6b1 diff --git a/tree.h b/tree.h index 9dee24d..c8e8478 100644 --- a/tree.h +++ b/tree.h @@ -10,45 +10,75 @@ * */ -using namespace std; - -#include -#include -#include - -struct Node { - string name; - string group; - float branchLength; - Node* parent; - Node* lchild; - Node* rchild; -}; - - +#include "treenode.h" +#include "counttable.h" +/* 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); +public: + Tree(string); //do not use tree generated by this constructor its just to extract the treenames, its a chicken before the egg thing that needs to be revisited. + Tree(int, CountTable*); + Tree(CountTable*); //to generate a tree from a file + Tree(CountTable*, vector< vector >&); //create tree from sim matrix + ~Tree(); + + CountTable* getCountTable() { return ct; } + void getCopy(Tree*); //makes tree a copy of the one passed in. + void getCopy(Tree* copy, bool); //makes a copy of the tree structure passed in, (just parents, children and br). Used with the Tree(TreeMap*) constructor. Assumes the tmap already has set seqs groups you want. Used by subsample to reassign seqs you don't want included to group "doNotIncludeMe". + void getSubTree(Tree*, vector); //makes tree a that contains only the names passed in. + //int getSubTree(Tree* originalToCopy, vector seqToInclude, map nameMap); //used with (int, TreeMap) constructor. SeqsToInclude contains subsample wanted - assumes these are unique seqs and size of vector=numLeaves passed into constructor. nameMap is unique -> redundantList can be empty if no namesfile was provided. + + void assembleRandomTree(); + void assembleRandomUnifracTree(vector); + void assembleRandomUnifracTree(string, string); + + void createNewickFile(string); + int getIndex(string); + void setIndex(string, int); + int getNumNodes() { return numNodes; } + int getNumLeaves(){ return numLeaves; } + map mergeUserGroups(int, vector); //returns a map with a groupname and the number of times that group was seen in the children + void printTree(); + void print(ostream&); + void print(ostream&, string); + void print(ostream&, map); + int findRoot(); //return index of root node + + //this function takes the leaf info and populates the non leaf nodes + int assembleTree(); + + vector tree; //the first n nodes are the leaves, where n is the number of sequences. + map< string, vector > groupNodeInfo; //maps group to indexes of leaf nodes with that group, different groups may contain same node because of names file. + +private: + CountTable* ct; + int numNodes, numLeaves; + ofstream out; + string filename; + + //map names; + map::iterator it, it2; + map mergeGroups(int); //returns a map with a groupname and the number of times that group was seen in the children + map mergeGcounts(int); + map indexes; //maps seqName -> index in tree vector + + void addNamesToCounts(map); + void randomTopology(); + void randomBlengths(); + void randomLabels(vector); + //void randomLabels(string, string); + void printBranch(int, ostream&, map); //recursively print out tree + void printBranch(int, ostream&, string); + int parseTreeFile(); //parses through tree file to find names of nodes and number of them + //this is required in case user has sequences in the names file that are + //not included in the tree. + //only takes names from the first tree in the tree file and assumes that all trees use the same names. + int readTreeString(ifstream&); + int populateNewTree(vector&, int, int&); + void printBranch(int, ostream&, string, vector&); + MothurOut* m; - Tree generateRandomTree(); - - vector leaves; //gives you easy access to the leaves of the tree to generate the parsimony score - - private: }; - - - -#endif \ No newline at end of file +#endif