5 * Created by Sarah Westcott on 1/23/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "readtreecommand.h"
12 //**********************************************************************************************************************
13 ReadTreeCommand::ReadTreeCommand(string option){
15 globaldata = GlobalData::getInstance();
18 //allow user to run help
19 if(option == "help") { help(); abort = true; }
22 //valid paramters for this command
23 string Array[] = {"tree","group"};
24 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
26 OptionParser parser(option);
27 map<string, string> parameters = parser.getParameters();
29 ValidParameters validParameter;
31 //check to make sure all parameters are valid for command
32 for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
33 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
36 globaldata->newRead();
38 //check for required parameters
39 treefile = validParameter.validFile(parameters, "tree", true);
40 if (treefile == "not open") { abort = true; }
41 else if (treefile == "not found") { treefile = ""; cout << "tree is a required parameter for the read.tree command." << endl; abort = true; }
42 else { globaldata->setTreeFile(treefile); globaldata->setFormat("tree"); }
44 groupfile = validParameter.validFile(parameters, "group", true);
45 if (groupfile == "not open") { abort = true; }
46 else if (groupfile == "not found") { groupfile = ""; cout << "group is a required parameter for the read.tree command." << endl; abort = true; }
48 globaldata->setGroupFile(groupfile);
49 //read in group map info.
50 treeMap = new TreeMap(groupfile);
52 globaldata->gTreemap = treeMap;
57 read = new ReadNewickTree(filename);
63 cout << "Standard Error: " << e.what() << " has occurred in the ReadTreeCommand class Function ReadTreeCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
67 cout << "An unknown error has occurred in the ReadTreeCommand class function ReadTreeCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
71 //**********************************************************************************************************************
73 void ReadTreeCommand::help(){
75 cout << "The read.tree command must be run before you execute a unifrac.weighted, unifrac.unweighted. " << "\n";
76 cout << "It also must be run before using the parsimony command, unless you are using the randomtree parameter." << "\n";
77 cout << "The read.tree command should be in the following format: read.tree(tree=yourTreeFile, group=yourGroupFile)." << "\n";
78 cout << "The tree and group parameters are both required." << "\n";
79 cout << "Note: No spaces between parameter labels (i.e. tree), '=' and parameters (i.e.yourTreefile)." << "\n" << "\n";
82 cout << "Standard Error: " << e.what() << " has occurred in the ReadTreeCommand class Function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
86 cout << "An unknown error has occurred in the ReadTreeCommand class function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
91 //**********************************************************************************************************************
93 ReadTreeCommand::~ReadTreeCommand(){
97 //**********************************************************************************************************************
99 int ReadTreeCommand::execute(){
102 if (abort == true) { return 0; }
106 readOk = read->read();
108 if (readOk != 0) { cout << "Read Terminated." << endl; globaldata->gTree.clear(); delete globaldata->gTreemap; return 0; }
110 vector<Tree*> T = globaldata->gTree;
112 //assemble users trees
113 for (int i = 0; i < T.size(); i++) {
114 T[i]->assembleTree();
117 //output any names that are in names file but not in tree
118 if (globaldata->Treenames.size() < treeMap->getNumSeqs()) {
119 for (int i = 0; i < treeMap->namesOfSeqs.size(); i++) {
120 //is that name in the tree?
122 for (int j = 0; j < globaldata->Treenames.size(); j++) {
123 if (treeMap->namesOfSeqs[i] == globaldata->Treenames[j]) { break; } //found it
127 //then you did not find it so report it
128 if (count == globaldata->Treenames.size()) {
129 cout << treeMap->namesOfSeqs[i] << " is in your namefile and not in your tree. It will be disregarded." << endl;
136 catch(exception& e) {
137 cout << "Standard Error: " << e.what() << " has occurred in the ReadTreeCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
141 cout << "An unknown error has occurred in the ReadTreeCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
146 //**********************************************************************************************************************