]> git.donarmstrong.com Git - mothur.git/blobdiff - treegroupscommand.cpp
working on pam
[mothur.git] / treegroupscommand.cpp
index 3eeeae292e674dbc7823522ce8e35d8d531ab70e..753b5cbe3cf7f67ed623bb8d866b848c6c96e5be 100644 (file)
 //**********************************************************************************************************************
 vector<string> TreeGroupCommand::setParameters(){      
        try {
-               CommandParameter pshared("shared", "InputTypes", "", "", "PhylipColumnShared", "PhylipColumnShared", "none",false,false); parameters.push_back(pshared);
-               CommandParameter pphylip("phylip", "InputTypes", "", "", "PhylipColumnShared", "PhylipColumnShared", "none",false,false); parameters.push_back(pphylip);
-               CommandParameter pname("name", "InputTypes", "", "", "none", "none", "ColumnName",false,false); parameters.push_back(pname);
-               CommandParameter pcolumn("column", "InputTypes", "", "", "PhylipColumnShared", "PhylipColumnShared", "ColumnName",false,false); parameters.push_back(pcolumn);  
-        CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters);
-        CommandParameter psubsample("subsample", "String", "", "", "", "", "",false,false); parameters.push_back(psubsample);
-        CommandParameter pcutoff("cutoff", "Number", "", "10", "", "", "",false,false); parameters.push_back(pcutoff);
-               CommandParameter pprecision("precision", "Number", "", "100", "", "", "",false,false); parameters.push_back(pprecision);                
-               CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel);
-               CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups);
-               CommandParameter pcalc("calc", "Multiple", "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan-kstest-sharednseqs-ochiai-anderberg-kulczynski-kulczynskicody-lennon-morisitahorn-braycurtis-whittaker-odum-canberra-structeuclidean-structchord-hellinger-manhattan-structpearson-soergel-spearman-structkulczynski-speciesprofile-hamming-structchi2-gower-memchi2-memchord-memeuclidean-mempearson", "jclass-thetayc", "", "", "",true,false); parameters.push_back(pcalc);
+               CommandParameter pshared("shared", "InputTypes", "", "", "PhylipColumnShared", "PhylipColumnShared", "none","tree",false,false,true); parameters.push_back(pshared);
+               CommandParameter pphylip("phylip", "InputTypes", "", "", "PhylipColumnShared", "PhylipColumnShared", "none","tree",false,false); parameters.push_back(pphylip);
+               CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "ColumnName","",false,false); parameters.push_back(pname);
+               CommandParameter pcount("count", "InputTypes", "", "", "NameCount", "none", "countcolumn","",false,false); parameters.push_back(pcount);
+        CommandParameter pcolumn("column", "InputTypes", "", "", "PhylipColumnShared", "PhylipColumnShared", "ColumnName-countcolumn","tree",false,false); parameters.push_back(pcolumn);              
+        CommandParameter piters("iters", "Number", "", "1000", "", "", "","",false,false); parameters.push_back(piters);
+        CommandParameter psubsample("subsample", "String", "", "", "", "", "","",false,false); parameters.push_back(psubsample);
+        CommandParameter pcutoff("cutoff", "Number", "", "10", "", "", "","",false,false); parameters.push_back(pcutoff);
+               CommandParameter pprecision("precision", "Number", "", "100", "", "", "","",false,false); parameters.push_back(pprecision);             
+               CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel);
+               CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups);
+               CommandParameter pcalc("calc", "Multiple", "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan-kstest-sharednseqs-ochiai-anderberg-kulczynski-kulczynskicody-lennon-morisitahorn-braycurtis-whittaker-odum-canberra-structeuclidean-structchord-hellinger-manhattan-structpearson-soergel-spearman-structkulczynski-speciesprofile-hamming-structchi2-gower-memchi2-memchord-memeuclidean-mempearson", "jclass-thetayc", "", "", "","",true,false,true); parameters.push_back(pcalc);
                
-        CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors);
-        CommandParameter poutput("output", "Multiple", "lt-square", "lt", "", "", "",false,false); parameters.push_back(poutput);
-               CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
-               CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
+        CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors);
+//CommandParameter poutput("output", "Multiple", "lt-square", "lt", "", "", "",false,false); parameters.push_back(poutput);
+               CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
+               CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
                
                vector<string> myArray;
                for (int i = 0; i < parameters.size(); i++) {   myArray.push_back(parameters[i].name);          }
@@ -70,6 +71,21 @@ string TreeGroupCommand::getHelpString(){
        }
 }
 //**********************************************************************************************************************
+string TreeGroupCommand::getOutputPattern(string type) {
+    try {
+        string pattern = "";
+        
+        if (type == "tree") {  pattern = "[filename],[calc],[distance],[tag],tre-[filename],tre"; } 
+        else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true;  }
+        
+        return pattern;
+    }
+    catch(exception& e) {
+        m->errorOut(e, "TreeGroupCommand", "getOutputPattern");
+        exit(1);
+    }
+}
+//**********************************************************************************************************************
 TreeGroupCommand::TreeGroupCommand(){  
        try {
                abort = true; calledHelp = true;
@@ -140,6 +156,14 @@ TreeGroupCommand::TreeGroupCommand(string option)  {
                                        //if the user has not given a path then, add inputdir. else leave path alone.
                                        if (path == "") {       parameters["name"] = inputDir + it->second;             }
                                }
+                
+                it = parameters.find("count");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = m->hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["count"] = inputDir + it->second;            }
+                               }
                        }
                        
                        //check for required parameters
@@ -162,6 +186,11 @@ TreeGroupCommand::TreeGroupCommand(string option)  {
                        if (namefile == "not open") { abort = true; }   
                        else if (namefile == "not found") { namefile = ""; }
                        else { m->setNameFile(namefile); }
+            
+            countfile = validParameter.validFile(parameters, "count", true);
+                       if (countfile == "not open") { abort = true; countfile = ""; }  
+                       else if (countfile == "not found") { countfile = ""; }
+                       else { m->setCountTableFile(countfile); }
                        
                        if ((phylipfile == "") && (columnfile == "") && (sharedfile == "")) { 
                                //is there are current file available for either of these?
@@ -184,15 +213,20 @@ TreeGroupCommand::TreeGroupCommand(string option)  {
                        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; }
                        
                        if (columnfile != "") {
-                               if (namefile == "") 
+                               if ((namefile == "") && (countfile == ""))
                                        namefile = m->getNameFile(); 
                                        if (namefile != "") {  m->mothurOut("Using " + namefile + " as input file for the name parameter."); m->mothurOutEndLine(); }
                                        else { 
-                                               m->mothurOut("You need to provide a namefile if you are going to use the column format."); m->mothurOutEndLine(); 
-                                               abort = true; 
+                                               countfile = m->getCountTableFile();
+                        if (countfile != "") {  m->mothurOut("Using " + countfile + " as input file for the count parameter."); m->mothurOutEndLine(); }
+                        else { 
+                            m->mothurOut("You need to provide a namefile or countfile if you are going to use the column format."); m->mothurOutEndLine(); 
+                            abort = true; 
+                        }      
                                        }       
                                }
                        }
+
                        
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
@@ -266,8 +300,8 @@ TreeGroupCommand::TreeGroupCommand(string option)  {
 TreeGroupCommand::~TreeGroupCommand(){
        if (abort == false) {
                if (format == "sharedfile") {  delete input; }
-               else { delete readMatrix;  delete matrix; delete list; }
-               delete tmap;  
+               else { delete list; }
+               delete ct;  
        }
        
 }
@@ -380,14 +414,25 @@ int TreeGroupCommand::execute(){
                        m->runParse = false;
                        
                        //create treemap class from groupmap for tree class to use
-                       tmap = new TreeMap();
-                       tmap->makeSim(m->getAllGroups());
+                       ct = new CountTable();
+            set<string> nameMap;
+            map<string, string> groupMap;
+            set<string> gps;
+            for (int i = 0; i < m->getAllGroups().size(); i++) { 
+                nameMap.insert(m->getAllGroups()[i]); 
+                gps.insert(m->getAllGroups()[i]); 
+                groupMap[m->getAllGroups()[i]] = m->getAllGroups()[i];
+            }
+            ct->createTable(nameMap, groupMap, gps);
                        
                        //clear globaldatas old tree names if any
                        m->Treenames.clear();
                        
                        //fills globaldatas tree names
-                       m->Treenames = m->getGroups();
+                       //m->Treenames = m->getGroups();
+            for (int k = 0; k < lookup.size(); k++) {
+                m->Treenames.push_back(lookup[k]->getGroup());
+            }
                
                        if (m->control_pressed) { return 0; }
                        
@@ -398,51 +443,66 @@ int TreeGroupCommand::execute(){
                }else{
                        //read in dist file
                        filename = inputfile;
-               
+            
+            ReadMatrix* readMatrix;
                        if (format == "column") { readMatrix = new ReadColumnMatrix(filename); }        
                        else if (format == "phylip") { readMatrix = new ReadPhylipMatrix(filename); }
                                
                        readMatrix->setCutoff(cutoff);
        
-                       if(namefile != ""){     
-                               nameMap = new NameAssignment(namefile);
-                               nameMap->readMap();
-                       }
-                       else{
-                               nameMap = NULL;
-                       }
-       
-                       readMatrix->read(nameMap);
-                       list = readMatrix->getListVector();
-                       matrix = readMatrix->getMatrix();
+            ct = NULL;
+            nameMap = NULL;
+            if(namefile != ""){        
+                nameMap = new NameAssignment(namefile);
+                nameMap->readMap();
+                readMatrix->read(nameMap);
+            }else if (countfile != "") {
+                ct = new CountTable();
+                ct->readTable(countfile, true, false);
+                readMatrix->read(ct);
+            }else {
+                readMatrix->read(nameMap);
+            }
 
+                       list = readMatrix->getListVector();
+                       SparseDistanceMatrix* dMatrix = readMatrix->getDMatrix();
+            
+            //clear globaldatas old tree names if any
+                       m->Treenames.clear();
+            
                        //make treemap
-                       tmap = new TreeMap();
-                       
-                       if (m->control_pressed) { return 0; }
-                       
-                       tmap->makeSim(list);
+            if (ct != NULL) { delete ct; }
+                       ct = new CountTable();
+            set<string> nameMap;
+            map<string, string> groupMap;
+            set<string> gps;
+            for (int i = 0; i < list->getNumBins(); i++) {
+                string bin = list->get(i);
+                nameMap.insert(bin); 
+                gps.insert(bin); 
+                groupMap[bin] = bin;
+                m->Treenames.push_back(bin);
+            }
+            ct->createTable(nameMap, groupMap, gps);
                        
-                       vector<string> namesGroups = tmap->getNamesOfGroups();
+                       vector<string> namesGroups = ct->getNamesOfGroups();
                        m->setGroups(namesGroups);
-               
-                       //clear globaldatas old tree names if any
-                       m->Treenames.clear();
-               
-                       //fills globaldatas tree names
-                       m->Treenames = m->getGroups();
                        
                        //used in tree constructor 
                        m->runParse = false;
                        
                        if (m->control_pressed) { return 0; }
                        
-                       vector< vector<double> > matrix = makeSimsDist();
+                       vector< vector<double> > matrix = makeSimsDist(dMatrix);
+            delete readMatrix;
+            delete dMatrix;
                        
                        if (m->control_pressed) { return 0; }
 
                        //create a new filename
-                       string outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + "tre";    
+            map<string, string> variables; 
+            variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputfile));
+                       string outputFile = getOutputFileName("tree",variables);        
                        outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile);
                                
                        Tree* newTree = createTree(matrix);
@@ -482,13 +542,12 @@ int TreeGroupCommand::execute(){
 Tree* TreeGroupCommand::createTree(vector< vector<double> >& simMatrix){
        try {
                //create tree
-               t = new Tree(tmap, simMatrix);
+               t = new Tree(ct, simMatrix);
         
         if (m->control_pressed) { delete t; t = NULL; return t; }
                
         //assemble tree
-        map<string, string> empty;
-               t->assembleTree(empty);
+               t->assembleTree();
 
                return t;
        }
@@ -534,7 +593,7 @@ void TreeGroupCommand::printSims(ostream& out, vector< vector<double> >& simMatr
        }
 }
 /***********************************************************/
-vector< vector<double> > TreeGroupCommand::makeSimsDist() {
+vector< vector<double> > TreeGroupCommand::makeSimsDist(SparseDistanceMatrix* matrix) {
        try {
                numGroups = list->size();
                
@@ -549,13 +608,17 @@ vector< vector<double> > TreeGroupCommand::makeSimsDist() {
                
                //go through sparse matrix and fill sims
                //go through each cell in the sparsematrix
-               for(MatData currentCell = matrix->begin(); currentCell != matrix->end(); currentCell++){
-                       //similairity = -(distance-1)
-                       simMatrix[currentCell->row][currentCell->column] = -(currentCell->dist -1.0);   
-                       simMatrix[currentCell->column][currentCell->row] = -(currentCell->dist -1.0);   
-                       
-                       if (m->control_pressed) { return simMatrix; }
+        for (int i = 0; i < matrix->seqVec.size(); i++) {
+            for (int j = 0; j < matrix->seqVec[i].size(); j++) {
+                
+                //already checked everyone else in row
+                if (i < matrix->seqVec[i][j].index) {   
+                    simMatrix[i][matrix->seqVec[i][j].index] = -(matrix->seqVec[i][j].dist -1.0);      
+                    simMatrix[matrix->seqVec[i][j].index][i] = -(matrix->seqVec[i][j].dist -1.0);      
                        
+                    if (m->control_pressed) { return simMatrix; }
+                }
+            }
                }
 
                return simMatrix;
@@ -570,13 +633,6 @@ vector< vector<double> > TreeGroupCommand::makeSimsDist() {
 int TreeGroupCommand::makeSimsShared() {
        try {
         
-        numGroups = lookup.size();
-               lines.resize(processors);
-               for (int i = 0; i < processors; i++) {
-                       lines[i].start = int (sqrt(float(i)/float(processors)) * numGroups);
-                       lines[i].end = int (sqrt(float(i+1)/float(processors)) * numGroups);
-               }       
-        
         if (subsample) { 
             if (subsampleSize == -1) { //user has not set size, set size = smallest samples size
                 subsampleSize = lookup[0]->getNumSeqs();
@@ -588,6 +644,7 @@ int TreeGroupCommand::makeSimsShared() {
             }else {
                 m->clearGroups();
                 Groups.clear();
+                m->Treenames.clear();
                 vector<SharedRAbundVector*> temp;
                 for (int i = 0; i < lookup.size(); i++) {
                     if (lookup[i]->getNumSeqs() < subsampleSize) { 
@@ -596,12 +653,32 @@ int TreeGroupCommand::makeSimsShared() {
                     }else { 
                         Groups.push_back(lookup[i]->getGroup()); 
                         temp.push_back(lookup[i]);
+                        m->Treenames.push_back(lookup[i]->getGroup());
                     }
                 } 
                 lookup = temp;
                 m->setGroups(Groups);
             }
+            
+            if (lookup.size() < 2) { m->mothurOut("You have not provided enough valid groups.  I cannot run the command."); m->mothurOutEndLine(); m->control_pressed = true; return 0; }
+        }
+        numGroups = lookup.size();
+        
+        //sanity check to make sure processors < numComparisions
+        int numDists = 0;
+        for(int i=0;i<numGroups;i++){
+            for(int j=0;j<i;j++){
+                numDists++;
+                if (numDists > processors) { break; }
+            }
         }
+        if (numDists < processors) { processors = numDists; }
+        
+               lines.resize(processors);
+               for (int i = 0; i < processors; i++) {
+                       lines[i].start = int (sqrt(float(i)/float(processors)) * numGroups);
+                       lines[i].end = int (sqrt(float(i+1)/float(processors)) * numGroups);
+               }       
         
                set<string> processedLabels;
                set<string> userLabels = labels;
@@ -825,6 +902,9 @@ int TreeGroupCommand::process(vector<SharedRAbundVector*> thisLookup) {
                 
                 //Close all thread handles and free memory allocations.
                 for(int i=0; i < pDataArray.size(); i++){
+                    if (pDataArray[i]->count != (pDataArray[i]->end-pDataArray[i]->start)) {
+                        m->mothurOut("[ERROR]: process " + toString(i) + " only processed " + toString(pDataArray[i]->count) + " of " + toString(pDataArray[i]->end-pDataArray[i]->start) + " groups assigned to it, quitting. \n"); m->control_pressed = true; 
+                    }
                     for (int j = 0; j < pDataArray[i]->thisLookup.size(); j++) {  delete pDataArray[i]->thisLookup[j];  } 
                     
                     for (int k = 0; k < calcDists.size(); k++) {
@@ -848,35 +928,17 @@ int TreeGroupCommand::process(vector<SharedRAbundVector*> thisLookup) {
                 thisItersLookup.clear();
                 for (int i = 0; i < calcDists.size(); i++) {  calcDists[i].clear(); }
             }
+            
+            if (m->debug) {  m->mothurOut("[DEBUG]: iter = " + toString(thisIter) + ".\n"); }
                }
-               
+        
+               if (m->debug) {  m->mothurOut("[DEBUG]: done with iters.\n"); }
+            
         if (iters != 1) {
             //we need to find the average distance and standard deviation for each groups distance
+            vector< vector<seqDist>  > calcAverages = m->getAverages(calcDistsTotals);  
             
-            vector< vector<seqDist>  > calcAverages; calcAverages.resize(treeCalculators.size()); 
-            for (int i = 0; i < calcAverages.size(); i++) {  //initialize sums to zero.
-                calcAverages[i].resize(calcDistsTotals[0][i].size());
-                
-                for (int j = 0; j < calcAverages[i].size(); j++) {
-                    calcAverages[i][j].seq1 = calcDists[i][j].seq1;
-                    calcAverages[i][j].seq2 = calcDists[i][j].seq2;
-                    calcAverages[i][j].dist = 0.0;
-                }
-            }
-            
-            for (int thisIter = 0; thisIter < iters; thisIter++) { //sum all groups dists for each calculator
-                for (int i = 0; i < calcAverages.size(); i++) {  //initialize sums to zero.
-                    for (int j = 0; j < calcAverages[i].size(); j++) {
-                        calcAverages[i][j].dist += calcDistsTotals[thisIter][i][j].dist;
-                    }
-                }
-            }
-            
-            for (int i = 0; i < calcAverages.size(); i++) {  //finds average.
-                for (int j = 0; j < calcAverages[i].size(); j++) {
-                    calcAverages[i][j].dist /= (float) iters;
-                }
-            }
+            if (m->debug) {  m->mothurOut("[DEBUG]: found averages.\n"); }
             
             //create average tree for each calc
             for (int i = 0; i < calcDists.size(); i++) {
@@ -894,7 +956,12 @@ int TreeGroupCommand::process(vector<SharedRAbundVector*> thisLookup) {
                 }
                 
                 //create a new filename
-                string outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".ave.tre";                            
+                map<string, string> variables; 
+                variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputfile));
+                variables["[calc]"] = treeCalculators[i]->getName();
+                variables["[distance]"] = thisLookup[0]->getLabel();
+                variables["[tag]"] = "ave";
+                string outputFile = getOutputFileName("tree",variables);                               
                 outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile); 
                 
                 //creates tree from similarity matrix and write out file
@@ -902,12 +969,20 @@ int TreeGroupCommand::process(vector<SharedRAbundVector*> thisLookup) {
                 if (newTree != NULL) { writeTree(outputFile, newTree); }                
             }
             
+            if (m->debug) {  m->mothurOut("[DEBUG]: done averages trees.\n"); }
+            
             //create all trees for each calc and find their consensus tree
             for (int i = 0; i < calcDists.size(); i++) {
                 if (m->control_pressed) { break; }
                 
                 //create a new filename
-                string outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".all.tre";                            
+                //create a new filename
+                map<string, string> variables; 
+                variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputfile));
+                variables["[calc]"] = treeCalculators[i]->getName();
+                variables["[distance]"] = thisLookup[0]->getLabel();
+                variables["[tag]"] = "all";
+                string outputFile = getOutputFileName("tree",variables);                               
                 outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile); 
                 
                 ofstream outAll;
@@ -927,7 +1002,7 @@ int TreeGroupCommand::process(vector<SharedRAbundVector*> thisLookup) {
                         int row = calcDistsTotals[myIter][i][j].seq1;
                         int column = calcDistsTotals[myIter][i][j].seq2;
                         double dist = calcDistsTotals[myIter][i][j].dist;
-                        
+                       
                         matrix[row][column] = dist;
                         matrix[column][row] = dist;
                     }
@@ -942,13 +1017,18 @@ int TreeGroupCommand::process(vector<SharedRAbundVector*> thisLookup) {
                 outAll.close();
                 if (m->control_pressed) { for (int k = 0; k < trees.size(); k++) { delete trees[k]; } }
                 
+                if (m->debug) {  m->mothurOut("[DEBUG]: done all trees.\n"); }
+                
                 Consensus consensus;
                 //clear old tree names if any
                 m->Treenames.clear(); m->Treenames = m->getGroups(); //may have changed if subsample eliminated groups
                 Tree* conTree = consensus.getTree(trees);
                 
+                if (m->debug) {  m->mothurOut("[DEBUG]: done cons tree.\n"); }
+                
                 //create a new filename
-                string conFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".cons.tre";                              
+                variables["[tag]"] = "cons";
+                string conFile = getOutputFileName("tree",variables);                          
                 outputNames.push_back(conFile); outputTypes["tree"].push_back(conFile); 
                 ofstream outTree;
                 m->openOutputFile(conFile, outTree);
@@ -976,7 +1056,12 @@ int TreeGroupCommand::process(vector<SharedRAbundVector*> thisLookup) {
                 }
                 
                 //create a new filename
-                string outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".tre";                                
+                map<string, string> variables; 
+                variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputfile));
+                variables["[calc]"] = treeCalculators[i]->getName();
+                variables["[distance]"] = thisLookup[0]->getLabel();
+                variables["[tag]"] = "";
+                string outputFile = getOutputFileName("tree",variables);                                       
                 outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile); 
                 
                 //creates tree from similarity matrix and write out file