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