]> git.donarmstrong.com Git - mothur.git/blob - readtreecommand.cpp
19ab67531dc96e8929b258eef2a41b4d24538bc4
[mothur.git] / readtreecommand.cpp
1 /*
2  *  readtreecommand.cpp
3  *  Mothur
4  *
5  *  Created by Sarah Westcott on 1/23/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "readtreecommand.h"
11
12 //**********************************************************************************************************************
13 ReadTreeCommand::ReadTreeCommand(){
14         try {
15                 globaldata = GlobalData::getInstance();
16                 filename = globaldata->inputFileName;
17                 
18                 //read in group map info.
19                 treeMap = new TreeMap(globaldata->getGroupFile());
20                 treeMap->readMap();
21                 
22                 //memory leak prevention
23                 //if (globaldata->gTreemap != NULL) { delete globaldata->gTreemap;  }
24                 globaldata->gTreemap = treeMap;
25                 
26                 //get names in tree
27                 globaldata->parseTreeFile();
28
29                 read = new ReadNewickTree(filename);
30                 
31         }
32         catch(exception& e) {
33                 cout << "Standard Error: " << e.what() << " has occurred in the ReadTreeCommand class Function ReadTreeCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
34                 exit(1);
35         }
36         catch(...) {
37                 cout << "An unknown error has occurred in the ReadTreeCommand class function ReadTreeCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
38                 exit(1);
39         }
40 }
41
42 //**********************************************************************************************************************
43
44 ReadTreeCommand::~ReadTreeCommand(){
45         delete read;
46 }
47
48 //**********************************************************************************************************************
49
50 int ReadTreeCommand::execute(){
51         try {
52                 int readOk;
53                 
54                 readOk = read->read(); 
55                 
56                 if (readOk != 0) { cout << "Read Terminated." << endl; globaldata->gTree.clear(); delete globaldata->gTreemap; return 0; }
57                 
58                 vector<Tree*> T = globaldata->gTree;
59                 
60                 //assemble users trees
61                 for (int i = 0; i < T.size(); i++) {
62                         T[i]->assembleTree();
63                 }
64
65                 //output any names that are in names file but not in tree
66                 if (globaldata->Treenames.size() < treeMap->getNumSeqs()) {
67                         for (int i = 0; i < treeMap->namesOfSeqs.size(); i++) {
68                                 //is that name in the tree?
69                                 int count = 0;
70                                 for (int j = 0; j < globaldata->Treenames.size(); j++) {
71                                         if (treeMap->namesOfSeqs[i] == globaldata->Treenames[j]) { break; } //found it
72                                         count++;
73                                 }
74                                 
75                                 //then you did not find it so report it 
76                                 if (count == globaldata->Treenames.size()) { 
77                                         cout << treeMap->namesOfSeqs[i] << " is in your namefile and not in your tree. It will be disregarded." << endl;
78                                 }
79                         }
80                 }
81                 
82                 return 0;
83         }
84         catch(exception& e) {
85                 cout << "Standard Error: " << e.what() << " has occurred in the ReadTreeCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
86                 exit(1);
87         }
88         catch(...) {
89                 cout << "An unknown error has occurred in the ReadTreeCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
90                 exit(1);
91         }
92 }
93
94 //**********************************************************************************************************************