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