]> git.donarmstrong.com Git - mothur.git/blob - treegroupscommand.cpp
fixed phylo.diversity
[mothur.git] / treegroupscommand.cpp
1 /*
2  *  treegroupscommand.cpp
3  *  Mothur
4  *
5  *  Created by Sarah Westcott on 4/8/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "treegroupscommand.h"
11 #include "sharedjabund.h"
12 #include "sharedsorabund.h"
13 #include "sharedjclass.h"
14 #include "sharedsorclass.h"
15 #include "sharedjest.h"
16 #include "sharedsorest.h"
17 #include "sharedthetayc.h"
18 #include "sharedthetan.h"
19 #include "sharedmorisitahorn.h"
20 #include "sharedbraycurtis.h"
21
22
23 //**********************************************************************************************************************
24
25 TreeGroupCommand::TreeGroupCommand(string option)  {
26         try {
27                 globaldata = GlobalData::getInstance();
28                 abort = false;
29                 allLines = 1;
30                 labels.clear();
31                 Groups.clear();
32                 Estimators.clear();
33                 
34                 //allow user to run help
35                 if(option == "help") { validCalculator = new ValidCalculators(); help(); abort = true; }
36                 
37                 else {
38                         //valid paramters for this command
39                         string Array[] =  {"label","calc","groups", "phylip", "column", "name", "precision","cutoff","outputdir","inputdir"};
40                         vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
41                         
42                         OptionParser parser(option);
43                         map<string, string> parameters = parser. getParameters();
44                         
45                         ValidParameters validParameter;
46                         map<string, string>::iterator it;
47                 
48                         //check to make sure all parameters are valid for command
49                         for (it = parameters.begin(); it != parameters.end(); it++) { 
50                                 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
51                         }
52                         
53                         //if the user changes the input directory command factory will send this info to us in the output parameter 
54                         string inputDir = validParameter.validFile(parameters, "inputdir", false);              
55                         if (inputDir == "not found"){   inputDir = "";          }
56                         else {
57                                 string path;
58                                 it = parameters.find("phylip");
59                                 //user has given a template file
60                                 if(it != parameters.end()){ 
61                                         path = m->hasPath(it->second);
62                                         //if the user has not given a path then, add inputdir. else leave path alone.
63                                         if (path == "") {       parameters["phylip"] = inputDir + it->second;           }
64                                 }
65                                 
66                                 it = parameters.find("column");
67                                 //user has given a template file
68                                 if(it != parameters.end()){ 
69                                         path = m->hasPath(it->second);
70                                         //if the user has not given a path then, add inputdir. else leave path alone.
71                                         if (path == "") {       parameters["column"] = inputDir + it->second;           }
72                                 }
73                                 
74                                 it = parameters.find("name");
75                                 //user has given a template file
76                                 if(it != parameters.end()){ 
77                                         path = m->hasPath(it->second);
78                                         //if the user has not given a path then, add inputdir. else leave path alone.
79                                         if (path == "") {       parameters["name"] = inputDir + it->second;             }
80                                 }
81                         }
82                         
83                         format = globaldata->getFormat();
84                         
85                         //required parameters
86                         phylipfile = validParameter.validFile(parameters, "phylip", true);
87                         if (phylipfile == "not open") { abort = true; }
88                         else if (phylipfile == "not found") { phylipfile = ""; }        
89                         else {  format = "phylip";  globaldata->setPhylipFile(phylipfile);      }
90                         
91                         columnfile = validParameter.validFile(parameters, "column", true);
92                         if (columnfile == "not open") { abort = true; } 
93                         else if (columnfile == "not found") { columnfile = ""; }
94                         else {  format = "column"; globaldata->setColumnFile(columnfile);       }
95                         
96                         namefile = validParameter.validFile(parameters, "name", true);
97                         if (namefile == "not open") { abort = true; }   
98                         else if (namefile == "not found") { namefile = ""; }
99                         else {  globaldata->setNameFile(namefile);      }
100                         
101                         //error checking on files                       
102                         if ((globaldata->getSharedFile() == "") && ((phylipfile == "") && (columnfile == "")))  { m->mothurOut("You must run the read.otu command or provide a distance file before running the tree.shared command."); m->mothurOutEndLine(); abort = true; }
103                         else if ((phylipfile != "") && (columnfile != "")) { m->mothurOut("When running the tree.shared command with a distance file you may not use both the column and the phylip parameters."); m->mothurOutEndLine(); abort = true; }
104                         
105                         if (columnfile != "") {
106                                 if (namefile == "") {  m->mothurOut("You need to provide a namefile if you are going to use the column format."); m->mothurOutEndLine(); abort = true; }
107                         }
108
109                         //check for optional parameter and set defaults
110                         // ...at some point should added some additional type checking...
111                         label = validParameter.validFile(parameters, "label", false);                   
112                         if (label == "not found") { label = ""; }
113                         else { 
114                                 if(label != "all") {  m->splitAtDash(label, labels);  allLines = 0;  }
115                                 else { allLines = 1;  }
116                         }
117                         
118                         //if the user has not specified any labels use the ones from read.otu
119                         if(label == "") {  
120                                 allLines = globaldata->allLines; 
121                                 labels = globaldata->labels; 
122                         }
123                                 
124                         groups = validParameter.validFile(parameters, "groups", false);                 
125                         if (groups == "not found") { groups = ""; }
126                         else { 
127                                 m->splitAtDash(groups, Groups);
128                                 globaldata->Groups = Groups;
129                         }
130                                 
131                         calc = validParameter.validFile(parameters, "calc", false);                     
132                         if (calc == "not found") { calc = "jclass-thetayc";  }
133                         else { 
134                                  if (calc == "default")  {  calc = "jclass-thetayc";  }
135                         }
136                         m->splitAtDash(calc, Estimators);
137
138                         string temp;
139                         temp = validParameter.validFile(parameters, "precision", false);                        if (temp == "not found") { temp = "100"; }
140                         convert(temp, precision); 
141                         
142                         temp = validParameter.validFile(parameters, "cutoff", false);                   if (temp == "not found") { temp = "10"; }
143                         convert(temp, cutoff); 
144                         cutoff += (5 / (precision * 10.0));
145                         
146                         //if the user changes the output directory command factory will send this info to us in the output parameter 
147                         outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
148                                 outputDir = ""; 
149                                 outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it       
150                         }
151
152                                 
153                         if (abort == false) {
154                         
155                                 validCalculator = new ValidCalculators();
156                                 
157                                 if (format == "sharedfile") {
158                                         int i;
159                                         for (i=0; i<Estimators.size(); i++) {
160                                                 if (validCalculator->isValidCalculator("treegroup", Estimators[i]) == true) { 
161                                                         if (Estimators[i] == "jabund") {        
162                                                                 treeCalculators.push_back(new JAbund());
163                                                         }else if (Estimators[i] == "sorabund") { 
164                                                                 treeCalculators.push_back(new SorAbund());
165                                                         }else if (Estimators[i] == "jclass") { 
166                                                                 treeCalculators.push_back(new Jclass());
167                                                         }else if (Estimators[i] == "sorclass") { 
168                                                                 treeCalculators.push_back(new SorClass());
169                                                         }else if (Estimators[i] == "jest") { 
170                                                                 treeCalculators.push_back(new Jest());
171                                                         }else if (Estimators[i] == "sorest") { 
172                                                                 treeCalculators.push_back(new SorEst());
173                                                         }else if (Estimators[i] == "thetayc") { 
174                                                                 treeCalculators.push_back(new ThetaYC());
175                                                         }else if (Estimators[i] == "thetan") { 
176                                                                 treeCalculators.push_back(new ThetaN());
177                                                         }else if (Estimators[i] == "morisitahorn") { 
178                                                                 treeCalculators.push_back(new MorHorn());
179                                                         }else if (Estimators[i] == "braycurtis") { 
180                                                                 treeCalculators.push_back(new BrayCurtis());
181                                                         }
182                                                 }
183                                         }
184                                 }
185                         }       
186                 }
187
188         }
189         catch(exception& e) {
190                 m->errorOut(e, "TreeGroupCommand", "TreeGroupCommand");
191                 exit(1);
192         }
193 }
194
195 //**********************************************************************************************************************
196
197 void TreeGroupCommand::help(){
198         try {
199                 m->mothurOut("The tree.shared command creates a .tre to represent the similiarity between groups or sequences.\n");
200                 m->mothurOut("The tree.shared command can only be executed after a successful read.otu command or by providing a distance file.\n");
201                 m->mothurOut("The tree.shared command parameters are groups, calc, phylip, column, name, cutoff, precision and label.\n");
202                 m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like included used.\n");
203                 m->mothurOut("The group names are separated by dashes. The label allow you to select what distance levels you would like trees created for, and are also separated by dashes.\n");
204                 m->mothurOut("The phylip or column parameter are required if you do not run the read.otu command first, and only one may be used.  If you use a column file the name filename is required. \n");
205                 m->mothurOut("If you do not provide a cutoff value 10.00 is assumed. If you do not provide a precision value then 100 is assumed.\n");
206                 m->mothurOut("The tree.shared command should be in the following format: tree.shared(groups=yourGroups, calc=yourCalcs, label=yourLabels).\n");
207                 m->mothurOut("Example tree.shared(groups=A-B-C, calc=jabund-sorabund).\n");
208                 m->mothurOut("The default value for groups is all the groups in your groupfile.\n");
209                 m->mothurOut("The default value for calc is jclass-thetayc.\n");
210                 m->mothurOut("The tree.shared command outputs a .tre file for each calculator you specify at each distance you choose.\n");
211                 validCalculator->printCalc("treegroup", cout);
212                 m->mothurOut("Or the tree.shared command can be in the following format: tree.shared(phylip=yourPhylipFile).\n");
213                 m->mothurOut("Example tree.shared(phylip=abrecovery.dist).\n");
214                 m->mothurOut("Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n");
215         }
216         catch(exception& e) {
217                 m->errorOut(e, "TreeGroupCommand", "help");
218                 exit(1);
219         }
220 }
221
222
223 //**********************************************************************************************************************
224
225 TreeGroupCommand::~TreeGroupCommand(){
226         globaldata->Groups.clear();  
227         if (abort == false) {
228                 
229                 if (format == "sharedfile") { delete read;  delete input; globaldata->ginput = NULL; }
230                 else { delete readMatrix;  delete matrix; delete list; }
231                 delete tmap;  globaldata->gTreemap = NULL;
232                 delete validCalculator;
233         }
234         
235 }
236
237 //**********************************************************************************************************************
238
239 int TreeGroupCommand::execute(){
240         try {
241         
242                 if (abort == true) { return 0; }
243                 
244                 if (format == "sharedfile") {
245                         //if the users entered no valid calculators don't execute command
246                         if (treeCalculators.size() == 0) { m->mothurOut("You have given no valid calculators."); m->mothurOutEndLine(); return 0; }
247                         
248                         if (globaldata->gGroupmap != NULL) {  delete globaldata->gGroupmap;   globaldata->gGroupmap = NULL;  }
249                         //you have groups
250                         read = new ReadOTUFile(globaldata->inputFileName);      
251                         read->read(&*globaldata); 
252                         
253                         input = globaldata->ginput;
254                         lookup = input->getSharedRAbundVectors();
255                         lastLabel = lookup[0]->getLabel();
256                         
257                         if (lookup.size() < 2) { m->mothurOut("You have not provided enough valid groups.  I cannot run the command."); m->mothurOutEndLine(); return 0; }
258                         
259                         //used in tree constructor 
260                         globaldata->runParse = false;
261                         
262                         //create treemap class from groupmap for tree class to use
263                         tmap = new TreeMap();
264                         tmap->makeSim(globaldata->gGroupmap);
265                         globaldata->gTreemap = tmap;
266                         
267                         //clear globaldatas old tree names if any
268                         globaldata->Treenames.clear();
269                         
270                         //fills globaldatas tree names
271                         globaldata->Treenames = globaldata->Groups;
272                 
273                         if (m->control_pressed) { return 0; }
274                         
275                         //create tree file
276                         makeSimsShared();
277                         
278                         if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {        remove(outputNames[i].c_str());  } return 0; }
279                 }else{
280                         //read in dist file
281                         filename = globaldata->inputFileName;
282                 
283                         if (format == "column") { readMatrix = new ReadColumnMatrix(filename); }        
284                         else if (format == "phylip") { readMatrix = new ReadPhylipMatrix(filename); }
285                                 
286                         readMatrix->setCutoff(cutoff);
287         
288                         if(namefile != ""){     
289                                 nameMap = new NameAssignment(namefile);
290                                 nameMap->readMap();
291                         }
292                         else{
293                                 nameMap = NULL;
294                         }
295         
296                         readMatrix->read(nameMap);
297                         list = readMatrix->getListVector();
298                         matrix = readMatrix->getMatrix();
299
300                         //make treemap
301                         tmap = new TreeMap();
302                         
303                         if (m->control_pressed) { return 0; }
304                         
305                         tmap->makeSim(list);
306                         globaldata->gTreemap = tmap;
307                         
308                         globaldata->Groups = tmap->namesOfGroups;
309                 
310                         //clear globaldatas old tree names if any
311                         globaldata->Treenames.clear();
312                 
313                         //fills globaldatas tree names
314                         globaldata->Treenames = globaldata->Groups;
315                         
316                         //used in tree constructor 
317                         globaldata->runParse = false;
318                         
319                         if (m->control_pressed) { return 0; }
320                         
321                         makeSimsDist();
322                         
323                         if (m->control_pressed) { return 0; }
324
325                         //create a new filename
326                         outputFile = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + "tre";   
327                         outputNames.push_back(outputFile);
328                                 
329                         createTree();
330                         
331                         if (m->control_pressed) { return 0; }
332
333                         m->mothurOut("Tree complete. "); m->mothurOutEndLine();
334                         
335                 }
336                                 
337                 //reset groups parameter
338                 globaldata->Groups.clear();  
339                 
340                 m->mothurOutEndLine();
341                 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
342                 for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }
343                 m->mothurOutEndLine();
344
345                 return 0;
346         }
347         catch(exception& e) {
348                 m->errorOut(e, "TreeGroupCommand", "execute");
349                 exit(1);
350         }
351 }
352 //**********************************************************************************************************************
353
354 int TreeGroupCommand::createTree(){
355         try {
356                 //create tree
357                 t = new Tree();
358                 
359                 //do merges and create tree structure by setting parents and children
360                 //there are numGroups - 1 merges to do
361                 for (int i = 0; i < (numGroups - 1); i++) {
362                         float largest = -1000.0;
363                         
364                         if (m->control_pressed) { delete t; return 1; }
365                         
366                         int row, column;
367                         //find largest value in sims matrix by searching lower triangle
368                         for (int j = 1; j < simMatrix.size(); j++) {
369                                 for (int k = 0; k < j; k++) {
370                                         if (simMatrix[j][k] > largest) {  largest = simMatrix[j][k]; row = j; column = k;  }
371                                 }
372                         }
373
374                         //set non-leaf node info and update leaves to know their parents
375                         //non-leaf
376                         t->tree[numGroups + i].setChildren(index[row], index[column]);
377                         
378                         //parents
379                         t->tree[index[row]].setParent(numGroups + i);
380                         t->tree[index[column]].setParent(numGroups + i);
381                         
382                         //blength = distance / 2;
383                         float blength = ((1.0 - largest) / 2);
384                         
385                         //branchlengths
386                         t->tree[index[row]].setBranchLength(blength - t->tree[index[row]].getLengthToLeaves());
387                         t->tree[index[column]].setBranchLength(blength - t->tree[index[column]].getLengthToLeaves());
388                         
389                         //set your length to leaves to your childs length plus branchlength
390                         t->tree[numGroups + i].setLengthToLeaves(t->tree[index[row]].getLengthToLeaves() + t->tree[index[row]].getBranchLength());
391                         
392                         
393                         //update index 
394                         index[row] = numGroups+i;
395                         index[column] = numGroups+i;
396                         
397                         //remove highest value that caused the merge.
398                         simMatrix[row][column] = -1000.0;
399                         simMatrix[column][row] = -1000.0;
400                         
401                         //merge values in simsMatrix
402                         for (int n = 0; n < simMatrix.size(); n++)      {
403                                 //row becomes merge of 2 groups
404                                 simMatrix[row][n] = (simMatrix[row][n] + simMatrix[column][n]) / 2;
405                                 simMatrix[n][row] = simMatrix[row][n];
406                                 //delete column
407                                 simMatrix[column][n] = -1000.0;
408                                 simMatrix[n][column] = -1000.0;
409                         }
410                 }
411                 
412                 //adjust tree to make sure root to tip length is .5
413                 int root = t->findRoot();
414                 t->tree[root].setBranchLength((0.5 - t->tree[root].getLengthToLeaves()));
415                 
416                 //assemble tree
417                 t->assembleTree();
418                 
419                 if (m->control_pressed) { delete t; return 1; }
420                 
421                 //print newick file
422                 t->createNewickFile(outputFile);
423                 
424                 //delete tree
425                 delete t;
426                 
427                 if (m->control_pressed) { remove(outputFile.c_str()); outputNames.pop_back(); return 1; }
428                 
429                 return 0;
430         
431         }
432         catch(exception& e) {
433                 m->errorOut(e, "TreeGroupCommand", "createTree");
434                 exit(1);
435         }
436 }
437 /***********************************************************/
438 void TreeGroupCommand::printSims(ostream& out) {
439         try {
440                 
441                 //output column headers
442                 //out << '\t';
443                 //for (int i = 0; i < lookup.size(); i++) {     out << lookup[i]->getGroup() << '\t';           }
444                 //out << endl;
445                 
446                 
447                 for (int m = 0; m < simMatrix.size(); m++)      {
448                         //out << lookup[m]->getGroup() << '\t';
449                         for (int n = 0; n < simMatrix.size(); n++)      {
450                                 out << simMatrix[m][n] << '\t'; 
451                         }
452                         out << endl;
453                 }
454
455         }
456         catch(exception& e) {
457                 m->errorOut(e, "TreeGroupCommand", "printSims");
458                 exit(1);
459         }
460 }
461 /***********************************************************/
462 int TreeGroupCommand::makeSimsDist() {
463         try {
464                 numGroups = list->size();
465                 
466                 //initialize index
467                 index.clear();
468                 for (int g = 0; g < numGroups; g++) {   index[g] = g;   }
469                 
470                 //initialize simMatrix
471                 simMatrix.clear();
472                 simMatrix.resize(numGroups);
473                 for (int k = 0; k < simMatrix.size(); k++)      {
474                         for (int j = 0; j < simMatrix.size(); j++)      {
475                                 simMatrix[k].push_back(0.0);
476                         }
477                 }
478                 
479                 //go through sparse matrix and fill sims
480                 //go through each cell in the sparsematrix
481                 for(MatData currentCell = matrix->begin(); currentCell != matrix->end(); currentCell++){
482                         //similairity = -(distance-1)
483                         simMatrix[currentCell->row][currentCell->column] = -(currentCell->dist -1.0);   
484                         simMatrix[currentCell->column][currentCell->row] = -(currentCell->dist -1.0);   
485                         
486                         if (m->control_pressed) { return 1; }
487                         
488                 }
489
490                 return 0;
491         }
492         catch(exception& e) {
493                 m->errorOut(e, "TreeGroupCommand", "makeSimsDist");
494                 exit(1);
495         }
496 }
497
498 /***********************************************************/
499 int TreeGroupCommand::makeSimsShared() {
500         try {
501                 set<string> processedLabels;
502                 set<string> userLabels = labels;
503                 
504                 //as long as you are not at the end of the file or done wih the lines you want
505                 while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
506                         if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } for(int i = 0 ; i < treeCalculators.size(); i++) {  delete treeCalculators[i]; } return 1; }
507                 
508                         if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){                  
509                                 m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
510                                 process(lookup);
511                                 
512                                 processedLabels.insert(lookup[0]->getLabel());
513                                 userLabels.erase(lookup[0]->getLabel());
514                         }
515                         
516                         if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
517                                 string saveLabel = lookup[0]->getLabel();
518                         
519                                 for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } 
520                                 lookup = input->getSharedRAbundVectors(lastLabel);
521
522                                 m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
523                                 process(lookup);
524                                         
525                                 processedLabels.insert(lookup[0]->getLabel());
526                                 userLabels.erase(lookup[0]->getLabel());
527                                 
528                                 //restore real lastlabel to save below
529                                 lookup[0]->setLabel(saveLabel);
530                         }
531
532                         lastLabel = lookup[0]->getLabel();                      
533                         
534                         //get next line to process
535                         for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } 
536                         lookup = input->getSharedRAbundVectors();
537                 }
538                 
539                 if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } for(int i = 0 ; i < treeCalculators.size(); i++) {  delete treeCalculators[i]; } return 1; }
540
541                 //output error messages about any remaining user labels
542                 set<string>::iterator it;
543                 bool needToRun = false;
544                 for (it = userLabels.begin(); it != userLabels.end(); it++) {  
545                         m->mothurOut("Your file does not include the label " + *it); 
546                         if (processedLabels.count(lastLabel) != 1) {
547                                 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
548                                 needToRun = true;
549                         }else {
550                                 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
551                         }
552                 }
553                 
554                 //run last label if you need to
555                 if (needToRun == true)  {
556                         for (int i = 0; i < lookup.size(); i++) {  if (lookup[i] != NULL) {             delete lookup[i]; }             } 
557                         lookup = input->getSharedRAbundVectors(lastLabel);
558
559                         m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
560                         process(lookup);
561                         for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }         
562                 }
563                 
564                 for(int i = 0 ; i < treeCalculators.size(); i++) {  delete treeCalculators[i]; }
565                 
566                 return 0;
567         }
568         catch(exception& e) {
569                 m->errorOut(e, "TreeGroupCommand", "makeSimsShared");
570                 exit(1);
571         }
572 }
573
574 /***********************************************************/
575 int TreeGroupCommand::process(vector<SharedRAbundVector*> thisLookup) {
576         try{
577                                 EstOutput data;
578                                 vector<SharedRAbundVector*> subset;
579                                 numGroups = thisLookup.size();
580                                 
581                                 //for each calculator                                                                                           
582                                 for(int i = 0 ; i < treeCalculators.size(); i++) {
583                                         //initialize simMatrix
584                                         simMatrix.clear();
585                                         simMatrix.resize(numGroups);
586                                         for (int k = 0; k < simMatrix.size(); k++)      {
587                                                 for (int j = 0; j < simMatrix.size(); j++)      {
588                                                         simMatrix[k].push_back(0.0);
589                                                 }
590                                         }
591                 
592                                         //initialize index
593                                         index.clear();
594                                         for (int g = 0; g < numGroups; g++) {   index[g] = g;   }
595                 
596                                         //create a new filename
597                                         outputFile = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".tre";                                
598                                         outputNames.push_back(outputFile);
599                                                                                                 
600                                         for (int k = 0; k < thisLookup.size(); k++) { 
601                                                 for (int l = k; l < thisLookup.size(); l++) {
602                                                         if (k != l) { //we dont need to similiarity of a groups to itself
603                                                                 //get estimated similarity between 2 groups
604                                                                 
605                                                                 subset.clear(); //clear out old pair of sharedrabunds
606                                                                 //add new pair of sharedrabunds
607                                                                 subset.push_back(thisLookup[k]); subset.push_back(thisLookup[l]); 
608                                                                 
609                                                                 data = treeCalculators[i]->getValues(subset); //saves the calculator outputs
610                                                 //cout << thisLookup[k]->getGroup() << '\t' << thisLookup[l]->getGroup() << '\t' << (1.0 - data[0]) << endl;
611                                                                 if (m->control_pressed) { return 1; }
612                                                                 
613                                                                 //save values in similarity matrix
614                                                                 simMatrix[k][l] = data[0];
615                                                                 simMatrix[l][k] = data[0];
616                                                         }
617                                                 }
618                                         }
619                                         
620                                         if (m->control_pressed) { return 1; }
621                                         //creates tree from similarity matrix and write out file
622                                         createTree();
623                                         
624                                         if (m->control_pressed) { return 1; }
625                                 }
626                                 
627                                 return 0;
628
629         }
630         catch(exception& e) {
631                 m->errorOut(e, "TreeGroupCommand", "process");
632                 exit(1);
633         }
634 }
635 /***********************************************************/
636
637         
638