]> git.donarmstrong.com Git - mothur.git/blob - parsimonycommand.cpp
added getCommandInfoCommand for gui
[mothur.git] / parsimonycommand.cpp
1 /*
2  *  parsimonycommand.cpp
3  *  Mothur
4  *
5  *  Created by Sarah Westcott on 1/26/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "parsimonycommand.h"
11
12 //**********************************************************************************************************************
13 vector<string> ParsimonyCommand::setParameters(){       
14         try {
15                 CommandParameter ptree("tree", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptree);
16                 CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pgroup);
17                 CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname);
18                 CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups);
19                 CommandParameter prandom("random", "String", "", "", "", "", "",false,false); parameters.push_back(prandom);
20                 CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters);
21                 CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors);
22                 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
23                 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
24                 
25                 vector<string> myArray;
26                 for (int i = 0; i < parameters.size(); i++) {   myArray.push_back(parameters[i].name);          }
27                 return myArray;
28         }
29         catch(exception& e) {
30                 m->errorOut(e, "ParsimonyCommand", "setParameters");
31                 exit(1);
32         }
33 }
34 //**********************************************************************************************************************
35 string ParsimonyCommand::getHelpString(){       
36         try {
37                 string helpString = "";
38                 helpString += "The parsimony command parameters are tree, group, name, random, groups, processors and iters.  tree parameter is required unless you have valid current tree file or are using random.\n";
39                 helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like analyzed.  You must enter at least 1 valid group.\n";
40                 helpString += "The group names are separated by dashes.  The iters parameter allows you to specify how many random trees you would like compared to your tree.\n";
41                 helpString += "The parsimony command should be in the following format: parsimony(random=yourOutputFilename, groups=yourGroups, iters=yourIters).\n";
42                 helpString += "The processors parameter allows you to specify the number of processors to use. The default is 1.\n";
43                 helpString += "Example parsimony(random=out, iters=500).\n";
44                 helpString += "The default value for random is "" (meaning you want to use the trees in your inputfile, randomtree=out means you just want the random distribution of trees outputted to out.rd_parsimony),\n";
45                 helpString += "and iters is 1000.  The parsimony command output two files: .parsimony and .psummary their descriptions are in the manual.\n";
46                 helpString += "Note: No spaces between parameter labels (i.e. random), '=' and parameters (i.e.yourOutputFilename).\n";
47                 return helpString;
48         }
49         catch(exception& e) {
50                 m->errorOut(e, "ParsimonyCommand", "getHelpString");
51                 exit(1);
52         }
53 }
54
55 //**********************************************************************************************************************
56 ParsimonyCommand::ParsimonyCommand(){   
57         try {
58                 abort = true; calledHelp = true; 
59                 setParameters();
60                 vector<string> tempOutNames;
61                 outputTypes["parsimony"] = tempOutNames;
62                 outputTypes["psummary"] = tempOutNames;
63         }
64         catch(exception& e) {
65                 m->errorOut(e, "ParsimonyCommand", "ParsimonyCommand");
66                 exit(1);
67         }
68 }
69 /***********************************************************/
70 ParsimonyCommand::ParsimonyCommand(string option)  {
71         try {
72                 abort = false; calledHelp = false;   
73                 Groups.clear();
74                         
75                 //allow user to run help
76                 if(option == "help") { help(); abort = true; calledHelp = true; }
77                 
78                 else {
79                         vector<string> myArray = setParameters();
80                         
81                         OptionParser parser(option);
82                         map<string, string> parameters = parser.getParameters();
83                         map<string,string>::iterator it;
84                         
85                         ValidParameters validParameter;
86                 
87                         //check to make sure all parameters are valid for command
88                         for (it = parameters.begin(); it != parameters.end(); it++) { 
89                                 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
90                         }
91                         
92                         //initialize outputTypes
93                         vector<string> tempOutNames;
94                         outputTypes["parsimony"] = tempOutNames;
95                         outputTypes["psummary"] = tempOutNames;
96                         
97                         //if the user changes the input directory command factory will send this info to us in the output parameter 
98                         string inputDir = validParameter.validFile(parameters, "inputdir", false);              
99                         if (inputDir == "not found"){   inputDir = "";          }
100                         else {
101                                 string path;
102                                 it = parameters.find("tree");
103                                 //user has given a template file
104                                 if(it != parameters.end()){ 
105                                         path = m->hasPath(it->second);
106                                         //if the user has not given a path then, add inputdir. else leave path alone.
107                                         if (path == "") {       parameters["tree"] = inputDir + it->second;             }
108                                 }
109                                 
110                                 it = parameters.find("group");
111                                 //user has given a template file
112                                 if(it != parameters.end()){ 
113                                         path = m->hasPath(it->second);
114                                         //if the user has not given a path then, add inputdir. else leave path alone.
115                                         if (path == "") {       parameters["group"] = inputDir + it->second;            }
116                                 }
117                                 
118                                 it = parameters.find("name");
119                                 //user has given a template file
120                                 if(it != parameters.end()){ 
121                                         path = m->hasPath(it->second);
122                                         //if the user has not given a path then, add inputdir. else leave path alone.
123                                         if (path == "") {       parameters["name"] = inputDir + it->second;             }
124                                 }
125                         }
126                         
127                         m->runParse = true;
128                         
129                         outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = ""; }
130                         
131                         randomtree = validParameter.validFile(parameters, "random", false);             if (randomtree == "not found") { randomtree = ""; }
132                         
133                         //are you trying to use parsimony without reading a tree or saying you want random distribution
134                         if (randomtree == "")  {
135                                 //check for required parameters
136                                 treefile = validParameter.validFile(parameters, "tree", true);
137                                 if (treefile == "not open") { abort = true; }
138                                 else if (treefile == "not found") {                             //if there is a current design file, use it
139                                         treefile = m->getTreeFile(); 
140                                         if (treefile != "") { m->mothurOut("Using " + treefile + " as input file for the tree parameter."); m->mothurOutEndLine(); }
141                                         else {  m->mothurOut("You have no current tree file and the tree parameter is required."); m->mothurOutEndLine(); abort = true; }                                                               
142                                 }       
143                                 
144                                 //check for required parameters
145                                 groupfile = validParameter.validFile(parameters, "group", true);
146                                 if (groupfile == "not open") { abort = true; }
147                                 else if (groupfile == "not found") { groupfile = ""; }
148                                 
149                                 namefile = validParameter.validFile(parameters, "name", true);
150                                 if (namefile == "not open") { abort = true; }
151                                 else if (namefile == "not found") { namefile = ""; }
152                         }
153                         
154                         //if the user changes the output directory command factory will send this info to us in the output parameter 
155                         string outputDir = validParameter.validFile(parameters, "outputdir", false);            if (outputDir == "not found"){  outputDir = ""; if (randomtree == "")  { outputDir += m->hasPath(treefile); } }
156                         
157                         //check for optional parameter and set defaults
158                         // ...at some point should added some additional type checking...
159                         groups = validParameter.validFile(parameters, "groups", false);                 
160                         if (groups == "not found") { groups = ""; m->Groups.clear(); }
161                         else { 
162                                 m->splitAtDash(groups, Groups);
163                                 m->Groups = Groups;
164                         }
165                                 
166                         itersString = validParameter.validFile(parameters, "iters", false);                     if (itersString == "not found") { itersString = "1000"; }
167                         convert(itersString, iters); 
168                         
169                         string temp = validParameter.validFile(parameters, "processors", false);        if (temp == "not found"){       temp = m->getProcessors();      }
170                         m->setProcessors(temp);
171                         convert(temp, processors);
172                         
173                 }
174
175         }
176         catch(exception& e) {
177                 m->errorOut(e, "ParsimonyCommand", "ParsimonyCommand");
178                 exit(1);
179         }
180 }
181 /***********************************************************/
182 int ParsimonyCommand::execute() {
183         try {
184         
185                 if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
186                 
187                 
188                 //randomtree will tell us if user had their own treefile or if they just want the random distribution
189                 //user has entered their own tree
190                 if (randomtree == "") { 
191                         if (groupfile != "") {
192                                 //read in group map info.
193                                 tmap = new TreeMap(groupfile);
194                                 tmap->readMap();
195                         }else{ //fake out by putting everyone in one group
196                                 Tree* tree = new Tree(treefile); delete tree;  //extracts names from tree to make faked out groupmap
197                                 tmap = new TreeMap();
198                                 
199                                 for (int i = 0; i < m->Treenames.size(); i++) { tmap->addSeq(m->Treenames[i], "Group1"); }
200                         }
201                         
202                         if (namefile != "") { readNamesFile(); }
203                         
204                         read = new ReadNewickTree(treefile);
205                         int readOk = read->read(tmap); 
206                         
207                         if (readOk != 0) { m->mothurOut("Read Terminated."); m->mothurOutEndLine(); delete tmap; delete read; return 0; }
208                         
209                         read->AssembleTrees();
210                         T = read->getTrees();
211                         delete read;
212                         
213                         //make sure all files match
214                         //if you provide a namefile we will use the numNames in the namefile as long as the number of unique match the tree names size.
215                         int numNamesInTree;
216                         if (namefile != "")  {  
217                                 if (numUniquesInName == m->Treenames.size()) {  numNamesInTree = nameMap.size();  }
218                                 else {   numNamesInTree = m->Treenames.size();  }
219                         }else {  numNamesInTree = m->Treenames.size();  }
220                         
221                         
222                         //output any names that are in group file but not in tree
223                         if (numNamesInTree < tmap->getNumSeqs()) {
224                                 for (int i = 0; i < tmap->namesOfSeqs.size(); i++) {
225                                         //is that name in the tree?
226                                         int count = 0;
227                                         for (int j = 0; j < m->Treenames.size(); j++) {
228                                                 if (tmap->namesOfSeqs[i] == m->Treenames[j]) { break; } //found it
229                                                 count++;
230                                         }
231                                         
232                                         if (m->control_pressed) { 
233                                                 delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; }
234                                                 for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); } outputTypes.clear();
235                                                 m->Groups.clear();
236                                                 return 0;
237                                         }
238                                         
239                                         //then you did not find it so report it 
240                                         if (count == m->Treenames.size()) { 
241                                                 //if it is in your namefile then don't remove
242                                                 map<string, string>::iterator it = nameMap.find(tmap->namesOfSeqs[i]);
243                                                 
244                                                 if (it == nameMap.end()) {
245                                                         m->mothurOut(tmap->namesOfSeqs[i] + " is in your groupfile and not in your tree. It will be disregarded."); m->mothurOutEndLine();
246                                                         tmap->removeSeq(tmap->namesOfSeqs[i]);
247                                                         i--; //need this because removeSeq removes name from namesOfSeqs
248                                                 }
249                                         }
250                                 }
251                         }
252                                 
253                         if(outputDir == "") { outputDir += m->hasPath(treefile); }
254                         output = new ColumnFile(outputDir + m->getSimpleName(treefile)  +  ".parsimony", itersString);
255                         outputNames.push_back(outputDir + m->getSimpleName(treefile)  +  ".parsimony");
256                         outputTypes["parsimony"].push_back(outputDir + m->getSimpleName(treefile)  +  ".parsimony");
257                                 
258                         sumFile = outputDir + m->getSimpleName(treefile) + ".psummary";
259                         m->openOutputFile(sumFile, outSum);
260                         outputNames.push_back(sumFile);
261                         outputTypes["psummary"].push_back(sumFile);
262                 }else { //user wants random distribution
263                         getUserInput();
264                                 
265                         if(outputDir == "") { outputDir += m->hasPath(randomtree); }
266                         output = new ColumnFile(outputDir+ m->getSimpleName(randomtree), itersString);
267                         outputNames.push_back(outputDir+ m->getSimpleName(randomtree));
268                         outputTypes["parsimony"].push_back(outputDir+ m->getSimpleName(randomtree));
269                 }
270                         
271                 //set users groups to analyze
272                 util = new SharedUtil();
273                 util->setGroups(m->Groups, tmap->namesOfGroups, allGroups, numGroups, "parsimony");     //sets the groups the user wants to analyze
274                 util->getCombos(groupComb, m->Groups, numComp);
275                 delete util;
276                         
277                 if (numGroups == 1) { numComp++; groupComb.push_back(allGroups); }
278                         
279                 pars = new Parsimony(tmap);
280                 counter = 0;
281         
282                 Progress* reading;
283                 reading = new Progress("Comparing to random:", iters);
284                 
285                 if (m->control_pressed) { 
286                         delete reading; delete pars; delete output;
287                         delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; }
288                         if (randomtree == "") {  outSum.close();  }
289                         for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); } outputTypes.clear();
290                         m->Groups.clear();
291                         return 0;
292                 }
293                         
294                 
295                 //get pscore for users tree
296                 userData.resize(numComp,0);  //data = AB, AC, BC, ABC.
297                 randomData.resize(numComp,0);  //data = AB, AC, BC, ABC.
298                 rscoreFreq.resize(numComp);  
299                 uscoreFreq.resize(numComp);  
300                 rCumul.resize(numComp);  
301                 uCumul.resize(numComp);  
302                 userTreeScores.resize(numComp);  
303                 UScoreSig.resize(numComp); 
304                                 
305                 if (randomtree == "") {
306                         //get pscores for users trees
307                         for (int i = 0; i < T.size(); i++) {
308                                 userData = pars->getValues(T[i], processors, outputDir);  //data = AB, AC, BC, ABC.
309                                 
310                                 if (m->control_pressed) { 
311                                         delete reading; delete pars; delete output;
312                                         delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; }
313                                         if (randomtree == "") {  outSum.close();  }
314                                         for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); } outputTypes.clear();
315                                         m->Groups.clear();
316                                         return 0;
317                                 }
318
319
320                                 //output scores for each combination
321                                 for(int k = 0; k < numComp; k++) {
322
323                                         //update uscoreFreq
324                                         map<int,double>::iterator it = uscoreFreq[k].find(userData[k]);
325                                         if (it == uscoreFreq[k].end()) {//new score
326                                                 uscoreFreq[k][userData[k]] = 1;
327                                         }else{ uscoreFreq[k][userData[k]]++; }
328                                         
329                                         //add users score to valid scores
330                                         validScores[userData[k]] = userData[k];
331                                         
332                                         //save score for summary file
333                                         userTreeScores[k].push_back(userData[k]);
334                                 }
335                         }
336                         
337                         //get pscores for random trees
338                         for (int j = 0; j < iters; j++) {
339                                                                 
340                                 //create new tree with same num nodes and leaves as users
341                                 randT = new Tree(tmap);
342
343                                 //create random relationships between nodes
344                                 randT->assembleRandomTree();
345
346                                 //get pscore of random tree
347                                 randomData = pars->getValues(randT, processors, outputDir);
348                                 
349                                 if (m->control_pressed) { 
350                                         delete reading; delete pars; delete output; delete randT;
351                                         if (randomtree == "") {  outSum.close();  }
352                                         for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); } outputTypes.clear();
353                                         delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; }
354                                         m->Groups.clear();
355                                         return 0;
356                                 }
357                                         
358                                 for(int r = 0; r < numComp; r++) {
359                                         //add trees pscore to map of scores
360                                         map<int,double>::iterator it = rscoreFreq[r].find(randomData[r]);
361                                         if (it != rscoreFreq[r].end()) {//already have that score
362                                                 rscoreFreq[r][randomData[r]]++;
363                                         }else{//first time we have seen this score
364                                                 rscoreFreq[r][randomData[r]] = 1;
365                                         }
366                         
367                                         //add randoms score to validscores
368                                         validScores[randomData[r]] = randomData[r];
369                                 }
370                                 
371                                 //update progress bar
372                                 reading->update(j);
373                                 
374                                 delete randT;
375                         }
376
377                 }else {
378                         //get pscores for random trees
379                         for (int j = 0; j < iters; j++) {
380                                                                 
381                                 //create new tree with same num nodes and leaves as users
382                                 randT = new Tree(tmap);
383                                 //create random relationships between nodes
384
385                                 randT->assembleRandomTree();
386                                 
387                                 if (m->control_pressed) { 
388                                         delete reading; delete pars; delete output; delete randT;
389                                         delete tmap; 
390                                         for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); } outputTypes.clear();
391                                         m->Groups.clear();
392                                         return 0;
393                                 }
394
395
396                                 //get pscore of random tree
397                                 randomData = pars->getValues(randT, processors, outputDir);
398                                 
399                                 if (m->control_pressed) { 
400                                         delete reading; delete pars;  delete output; delete randT;
401                                         delete tmap; 
402                                         for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); } outputTypes.clear();
403                                         m->Groups.clear();
404                                         return 0;
405                                 }
406                         
407                                 for(int r = 0; r < numComp; r++) {
408                                         //add trees pscore to map of scores
409                                         map<int,double>::iterator it = rscoreFreq[r].find(randomData[r]);
410                                         if (it != rscoreFreq[r].end()) {//already have that score
411                                                 rscoreFreq[r][randomData[r]]++;
412                                         }else{//first time we have seen this score
413                                                 rscoreFreq[r][randomData[r]] = 1;
414                                         }
415                         
416                                         //add randoms score to validscores
417                                         validScores[randomData[r]] = randomData[r];
418                                 }
419                                 
420                                 //update progress bar
421                                 reading->update(j);
422                                 
423                                 delete randT;
424                         }
425                 }
426
427                 for(int a = 0; a < numComp; a++) {
428                         float rcumul = 0.0000;
429                         float ucumul = 0.0000;
430                         //this loop fills the cumulative maps and put 0.0000 in the score freq map to make it easier to print.
431                         for (map<int,double>::iterator it = validScores.begin(); it != validScores.end(); it++) { 
432                                 if (randomtree == "") {
433                                         map<int,double>::iterator it2 = uscoreFreq[a].find(it->first);
434                                         //user data has that score 
435                                         if (it2 != uscoreFreq[a].end()) { uscoreFreq[a][it->first] /= T.size(); ucumul+= it2->second;  }
436                                         else { uscoreFreq[a][it->first] = 0.0000; } //no user trees with that score
437                                         //make uCumul map
438                                         uCumul[a][it->first] = ucumul;
439                                 }
440                         
441                                 //make rscoreFreq map and rCumul
442                                 map<int,double>::iterator it2 = rscoreFreq[a].find(it->first);
443                                 //get percentage of random trees with that info
444                                 if (it2 != rscoreFreq[a].end()) {  rscoreFreq[a][it->first] /= iters; rcumul+= it2->second;  }
445                                 else { rscoreFreq[a][it->first] = 0.0000; } //no random trees with that score
446                                 rCumul[a][it->first] = rcumul;
447                         }
448                         
449                         //find the signifigance of each user trees score when compared to the random trees and save for printing the summary file
450                         for (int h = 0; h < userTreeScores[a].size(); h++) {
451                                 UScoreSig[a].push_back(rCumul[a][userTreeScores[a][h]]);
452                         }
453                 }
454                 
455                 if (m->control_pressed) { 
456                                 delete reading; delete pars; delete output;
457                                 delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; }
458                                 if (randomtree == "") {  outSum.close();  }
459                                 for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); } outputTypes.clear();
460                                 m->Groups.clear();
461                                 return 0;
462                 }
463                 
464                 //finish progress bar
465                 reading->finish();
466                 delete reading;
467
468                 
469                 printParsimonyFile();
470                 if (randomtree == "") { printUSummaryFile(); }
471                 
472                 //reset groups parameter
473                 m->Groups.clear(); 
474                 
475                 delete pars; delete output; 
476                 delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; }
477                 
478                 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {        remove(outputNames[i].c_str()); } outputTypes.clear(); return 0;}
479                 
480                 m->mothurOutEndLine();
481                 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
482                 for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }
483                 m->mothurOutEndLine();
484
485                 
486                 return 0;
487                 
488         }
489         catch(exception& e) {
490                 m->errorOut(e, "ParsimonyCommand", "execute");
491                 exit(1);
492         }
493 }
494
495 /***********************************************************/
496 void ParsimonyCommand::printParsimonyFile() {
497         try {
498                 vector<double> data;
499                 vector<string> tags;
500                 
501                 if (randomtree == "") {
502                         tags.push_back("Score"); tags.push_back("UserFreq"); tags.push_back("UserCumul"); tags.push_back("RandFreq"); tags.push_back("RandCumul");
503                 }else {
504                         tags.push_back("Score"); tags.push_back("RandFreq"); tags.push_back("RandCumul");
505                 }
506
507                 for(int a = 0; a < numComp; a++) {
508                         output->initFile(groupComb[a], tags);
509                         //print each line
510                         for (map<int,double>::iterator it = validScores.begin(); it != validScores.end(); it++) { 
511                                 if (randomtree == "") {
512                                         data.push_back(it->first);  data.push_back(uscoreFreq[a][it->first]); data.push_back(uCumul[a][it->first]); data.push_back(rscoreFreq[a][it->first]); data.push_back(rCumul[a][it->first]); 
513                                 }else{
514                                         data.push_back(it->first);  data.push_back(rscoreFreq[a][it->first]); data.push_back(rCumul[a][it->first]); 
515                                 }
516                                 output->output(data);
517                                 data.clear();
518                         } 
519                         output->resetFile();
520                 }
521         }
522         catch(exception& e) {
523                 m->errorOut(e, "ParsimonyCommand", "printParsimonyFile");
524                 exit(1);
525         }
526 }
527 /***********************************************************/
528 int ParsimonyCommand::printUSummaryFile() {
529         try {
530                 //column headers
531                 outSum << "Tree#" << '\t' << "Groups" << '\t'  <<  "ParsScore" << '\t' << "ParsSig" <<  endl;
532                 m->mothurOut("Tree#\tGroups\tParsScore\tParsSig"); m->mothurOutEndLine();
533                 
534                 //format output
535                 outSum.setf(ios::fixed, ios::floatfield); outSum.setf(ios::showpoint);
536                 
537                 
538                 //print each line
539                 for (int i = 0; i< T.size(); i++) {
540                         for(int a = 0; a < numComp; a++) {
541                                 if (m->control_pressed) {  outSum.close(); return 0; }
542                                 if (UScoreSig[a][i] > (1/(float)iters)) {
543                                         outSum << setprecision(6) << i+1 << '\t' << groupComb[a]  << '\t' << userTreeScores[a][i] << setprecision(itersString.length()) << '\t' << UScoreSig[a][i] << endl;
544                                         cout << setprecision(6) << i+1 << '\t' << groupComb[a]  << '\t' << userTreeScores[a][i] << setprecision(itersString.length()) << '\t' << UScoreSig[a][i] << endl;
545                                         m->mothurOutJustToLog(toString(i+1) + "\t" + groupComb[a] + "\t" + toString(userTreeScores[a][i]) + "\t" + toString(UScoreSig[a][i])); m->mothurOutEndLine();
546                                 }else {
547                                         outSum << setprecision(6) << i+1 << '\t' << groupComb[a] << '\t' << userTreeScores[a][i] << setprecision(itersString.length())  << '\t' << "<" << (1/float(iters)) << endl;
548                                         cout << setprecision(6) << i+1 << '\t' << groupComb[a] << '\t' << userTreeScores[a][i] << setprecision(itersString.length()) << '\t' << "<" << (1/float(iters)) << endl;
549                                         m->mothurOutJustToLog(toString(i+1) + "\t" + groupComb[a] + "\t" + toString(userTreeScores[a][i]) + "\t" + toString((1/float(iters)))); m->mothurOutEndLine();
550                                 }
551                         }
552                 }
553                 
554                 outSum.close();
555                 return 0;
556         }
557         catch(exception& e) {
558                 m->errorOut(e, "ParsimonyCommand", "printUSummaryFile");
559                 exit(1);
560         }
561 }
562
563 /***********************************************************/
564 void ParsimonyCommand::getUserInput() {
565         try {
566         
567                 //create treemap
568                 tmap = new TreeMap();
569
570                 m->mothurOut("Please enter the number of groups you would like to analyze: ");
571                 cin >> numGroups;
572                 m->mothurOutJustToLog(toString(numGroups)); m->mothurOutEndLine();
573                                 
574                 int num, count;
575                 count = 1;
576                 numEachGroup.resize(numGroups, 0);  
577                 
578                 for (int i = 1; i <= numGroups; i++) {
579                         m->mothurOut("Please enter the number of sequences in group " + toString(i) +  ": ");
580                         cin >> num;
581                         m->mothurOutJustToLog(toString(num)); m->mothurOutEndLine();
582                                 
583                         //set tmaps seqsPerGroup
584                         tmap->seqsPerGroup[toString(i)] = num;
585                         tmap->namesOfGroups.push_back(toString(i));
586                         
587                         //set tmaps namesOfSeqs
588                         for (int j = 0; j < num; j++) {
589                                 tmap->namesOfSeqs.push_back(toString(count));
590                                 tmap->treemap[toString(count)].groupname = toString(i);
591                                 count++;
592                         }
593                 }
594                 
595                 //clears buffer so next command doesn't have error
596                 string s;       
597                 getline(cin, s);
598                 
599                 m->Treenames = tmap->namesOfSeqs; 
600                 
601         }
602         catch(exception& e) {
603                 m->errorOut(e, "ParsimonyCommand", "getUserInput");
604                 exit(1);
605         }
606 }
607 /*****************************************************************/
608 int ParsimonyCommand::readNamesFile() {
609         try {
610                 m->names.clear();
611                 numUniquesInName = 0;
612                 
613                 ifstream in;
614                 m->openInputFile(namefile, in);
615                 
616                 string first, second;
617                 map<string, string>::iterator itNames;
618                 
619                 while(!in.eof()) {
620                         in >> first >> second; m->gobble(in);
621                         
622                         numUniquesInName++;
623                         
624                         itNames = m->names.find(first);
625                         if (itNames == m->names.end()) {  
626                                 m->names[first] = second; 
627                                 
628                                 //we need a list of names in your namefile to use above when removing extra seqs above so we don't remove them
629                                 vector<string> dupNames;
630                                 m->splitAtComma(second, dupNames);
631                                 
632                                 for (int i = 0; i < dupNames.size(); i++) {     
633                                         nameMap[dupNames[i]] = dupNames[i]; 
634                                         if ((groupfile == "") && (i != 0)) { tmap->addSeq(dupNames[i], "Group1"); } 
635                                 }
636                         }else {  m->mothurOut(first + " has already been seen in namefile, disregarding names file."); m->mothurOutEndLine(); in.close(); m->names.clear(); namefile = ""; return 1; }                  
637                 }
638                 in.close();
639                 
640                 return 0;
641         }
642         catch(exception& e) {
643                 m->errorOut(e, "ParsimonyCommand", "readNamesFile");
644                 exit(1);
645         }
646 }
647 /***********************************************************/
648
649