5 * Created by Sarah Westcott on 1/22/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
13 /*****************************************************************/
16 globaldata = GlobalData::getInstance();
18 numLeaves = globaldata->gTreemap->getNumSeqs();
19 numNodes = 2*numLeaves - 1;
21 tree.resize(numNodes);
23 //initialize tree with correct number of nodes, name and group info.
24 for (int i = 0; i < numNodes; i++) {
26 //initialize leaf nodes
27 if (i <= (numLeaves-1)) {
28 tree[i].setName(globaldata->gTreemap->namesOfSeqs[i]);
29 tree[i].setGroup(globaldata->gTreemap->getGroup(globaldata->gTreemap->namesOfSeqs[i]));
30 //the node knows its index
32 //Treemap knows name, group and index to speed up search
33 globaldata->gTreemap->setIndex(globaldata->gTreemap->namesOfSeqs[i], i);
34 //intialize non leaf nodes
35 }else if (i > (numLeaves-1)) {
38 //the node knows its index
44 cout << "Standard Error: " << e.what() << " has occurred in the Tree class Function Tree. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
48 cout << "An unknown error has occurred in the Tree class function Tree. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
53 /*****************************************************************/
55 int Tree::getIndex(string searchName) {
57 //Treemap knows name, group and index to speed up search
58 // getIndex function will return the vector index or -1 if seq is not found.
59 int index = globaldata->gTreemap->getIndex(searchName);
64 cout << "Standard Error: " << e.what() << " has occurred in the Tree class Function getIndex. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
68 cout << "An unknown error has occurred in the Tree class function getIndex. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
72 /*****************************************************************/
74 void Tree::setIndex(string searchName, int index) {
76 //set index in treemap
77 globaldata->gTreemap->setIndex(searchName, index);
80 cout << "Standard Error: " << e.what() << " has occurred in the Tree class Function setIndex. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
84 cout << "An unknown error has occurred in the Tree class function setIndex. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
90 /*****************************************************************/
91 // This prints out the tree in Newick form.
92 void Tree::createNewickFile() {
94 int root = findRoot();
95 filename = getRootName(globaldata->getTreeFile()) + "newick";
96 openOutputFile(filename, out);
100 // you are at the end of the tree
103 catch(exception& e) {
104 cout << "Standard Error: " << e.what() << " has occurred in the Tree class Function createNewickFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
108 cout << "An unknown error has occurred in the Tree class function createNewickFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
113 /*****************************************************************/
114 //This function finds the index of the root node.
116 int Tree::findRoot() {
118 for (int i = 0; i < numNodes; i++) {
120 if (tree[i].getParent() == -1) { return i; }
124 catch(exception& e) {
125 cout << "Standard Error: " << e.what() << " has occurred in the Tree class Function findRoot. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
129 cout << "An unknown error has occurred in the Tree class function findRoot. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
134 /*****************************************************************/
135 void Tree::printBranch(int node) {
138 // you are not a leaf
139 if (tree[node].getLChild() != -1) {
141 printBranch(tree[node].getLChild());
143 printBranch(tree[node].getRChild());
145 }else { //you are a leaf
146 tree[node].printNode(out); //prints out name and branch length
150 catch(exception& e) {
151 cout << "Standard Error: " << e.what() << " has occurred in the Tree class Function printBranch. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
155 cout << "An unknown error has occurred in the Tree class function printBranch. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
160 /*****************************************************************/