]> git.donarmstrong.com Git - mothur.git/blob - tree.h
Revert to previous commit
[mothur.git] / tree.h
1 #ifndef TREE_H
2 #define TREE_H
3
4 /*
5  *  tree.h
6  *  Mothur
7  *
8  *  Created by Sarah Westcott on 1/22/09.
9  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10  *
11  */
12
13 #include "treenode.h"
14 #include "treemap.h"
15 /* This class represents the treefile. */
16
17 class Tree {
18 public: 
19         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.
20         Tree(int, TreeMap*); 
21         Tree(TreeMap*);         //to generate a tree from a file
22     Tree(TreeMap*, vector< vector<double> >&); //create tree from sim matrix
23         ~Tree();
24         
25     TreeMap* getTreeMap() { return tmap; }
26         void getCopy(Tree*);  //makes tree a copy of the one passed in.
27         void getSubTree(Tree*, vector<string>);  //makes tree a that contains only the names passed in.
28     int getSubTree(Tree* originalToCopy, vector<string> seqToInclude, map<string, string> 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. 
29     
30         void assembleRandomTree();
31         void assembleRandomUnifracTree(vector<string>);
32         void assembleRandomUnifracTree(string, string);
33     
34         void createNewickFile(string);
35         int getIndex(string);
36         void setIndex(string, int);
37         int getNumNodes() { return numNodes; }
38         int getNumLeaves(){     return numLeaves; }
39         map<string, int> mergeUserGroups(int, vector<string>);  //returns a map with a groupname and the number of times that group was seen in the children
40         void printTree();
41         void print(ostream&);
42         void print(ostream&, string);
43     void print(ostream&, map<string, string>);
44         int findRoot();  //return index of root node
45         
46         //this function takes the leaf info and populates the non leaf nodes
47         int assembleTree(map<string, string>);  
48         
49         vector<Node> tree;              //the first n nodes are the leaves, where n is the number of sequences.
50         map< string, vector<int> > groupNodeInfo;       //maps group to indexes of leaf nodes with that group, different groups may contain same node because of names file.
51                         
52 private:
53         TreeMap* tmap;
54         int numNodes, numLeaves;
55         ofstream out;
56         string filename;
57         
58     map<string, string> names;
59         map<string, int>::iterator it, it2;
60         map<string, int> mergeGroups(int);  //returns a map with a groupname and the number of times that group was seen in the children
61         map<string,int> mergeGcounts(int);
62         
63         void addNamesToCounts(map<string, string>);
64         void randomTopology();
65         void randomBlengths();
66         void randomLabels(vector<string>);
67         //void randomLabels(string, string);
68         void printBranch(int, ostream&, map<string, string>);  //recursively print out tree
69     void printBranch(int, ostream&, string);
70         void parseTreeFile();   //parses through tree file to find names of nodes and number of them
71                                                         //this is required in case user has sequences in the names file that are
72                                                         //not included in the tree. 
73                                                         //only takes names from the first tree in the tree file and assumes that all trees use the same names.
74         int readTreeString(ifstream&);
75         int populateNewTree(vector<Node>&, int, int&);
76         void printBranch(int, ostream&, string, vector<Node>&);
77                 
78         MothurOut* m;
79                 
80 };
81
82 #endif