]> git.donarmstrong.com Git - mothur.git/commitdiff
fixed multiple bugs for 1.4 release
authorwestcott <westcott>
Wed, 27 May 2009 23:17:57 +0000 (23:17 +0000)
committerwestcott <westcott>
Wed, 27 May 2009 23:17:57 +0000 (23:17 +0000)
modified tree.shared to allow using a distance file

16 files changed:
engine.cpp
errorchecking.cpp
getgroupcommand.cpp
getgroupcommand.h
globaldata.cpp
helpcommand.cpp
sharedchao1.cpp
summarysharedcommand.cpp
summarysharedcommand.h
tree.cpp
tree.h
treegroupscommand.cpp
treegroupscommand.h
treemap.cpp
treemap.h
validparameter.cpp

index ac49206040520592a212b68594305cf464494155..11d738dd0f2384b42a26f21349eeaa7bbca80a2a 100644 (file)
@@ -127,6 +127,9 @@ BatchEngine::~BatchEngine(){
 //This Function allows the user to run a batchfile containing several commands on Dotur
 bool BatchEngine::getInput(){
        try {
+               //check if this is a valid batchfile
+               if (openedBatch == 1) {  cout << "unable to open batchfile" << endl;  return 1; }
+       
                string input = "";
                string commandName = "";
                bool errorFree;
index 8b80580a26faf27b8504f55039e494952a9f1be9..e4c1877907e272c89a0be023ec21ad6bf2947f50 100644 (file)
@@ -236,7 +236,7 @@ bool ErrorCheck::checkInput(string input) {
                
                //check for valid method
                if(commandName == "get.group") {
-                       if ((globaldata->getGroupFile() == "")) { cout << "You must read a group before you can use the get.group command." << endl; return false; }
+                       if ((globaldata->getSharedFile() == "")) { cout << "You must read a groupfile or a sharedfile before you can use the get.group command." << endl; return false; }
                }
                if (commandName == "get.label" || commandName == "get.line") {
                        if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { cout << "You must read a list, sabund or rabund before you can use the get.label or get.line command." << endl; return false; }
@@ -250,13 +250,22 @@ bool ErrorCheck::checkInput(string input) {
                        if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { cout << "You must read a list, sabund or rabund before you can use the collect.single, rarefaction.single or summary.single commands." << endl; return false; }
                }
                
-               if ((commandName == "collect.shared") || (commandName == "rarefaction.shared") || (commandName == "summary.shared") || (commandName == "tree.shared") || (commandName == "bootstrap.shared") || (commandName == "dist.shared")){ 
+               if ((commandName == "collect.shared") || (commandName == "rarefaction.shared") || (commandName == "summary.shared") || (commandName == "bootstrap.shared") || (commandName == "dist.shared")){ 
                        if (globaldata->getSharedFile() == "") {
                                if (globaldata->getListFile() == "") { cout << "You must read a list and a group, or a shared before you can use the collect.shared, rarefaction.shared, summary.shared, tree.shared, bootstrap.shared or dist.shared commands." << endl; return false; }
                                else if (globaldata->getGroupFile() == "") { cout << "You must read a list and a group, or a shared before you can use the collect.shared, rarefaction.shared, summary.shared, tree.shared, bootstrap.shared or dist.shared commands." << endl; return false; }
                        }
                }
                
+               if  (commandName == "tree.shared")  {
+                       //given no files                        
+                       if ((globaldata->getSharedFile() == "") && ((phylipfile == "") && (columnfile == "")))  { cout << "You must run the read.otu command or provide a distance file before running the tree.shared command." << endl; return false; }
+                       //you want to do single commands
+                       else if ((globaldata->getSharedFile() == "") && ((phylipfile != "") || (columnfile != ""))) {
+                               validateReadDist();
+                       }
+               }
+               
                if ((commandName == "heatmap") || (commandName == "venn")) { 
                        if ((globaldata->getListFile() == "") && (globaldata->getSharedFile() == "")) {
                                 cout << "You must read a list, or a list and a group, or a shared before you can use the heatmap or venn commands." << endl; return false; 
@@ -354,6 +363,12 @@ void ErrorCheck::validateReadFiles() {
                        //unable to open
                        if (ableToOpen == 1) {  errorFree = false; }
                        else { globaldata->inputFileName = sharedfile; }
+               }else if (groupfile != "") {
+                       ableToOpen = openInputFile(groupfile, filehandle);
+                       filehandle.close();
+                       if (ableToOpen == 1) { //unable to open
+                               errorFree = false;
+                       }
                }else{ //no file given
                        errorFree = false;
                }
@@ -385,8 +400,8 @@ void ErrorCheck::validateReadDist() {
                        if (ableToOpen == 1) {  errorFree = false; }
                }
                
-               if ((phylipfile == "") && (columnfile == "")) { cout << "When executing a read.dist you must enter a phylip or a column." << endl; errorFree = false; }
-               else if ((phylipfile != "") && (columnfile != "")) { cout << "When executing a read.dist you must enter ONLY ONE of the following: phylip or column." << endl; errorFree = false; }
+               if ((phylipfile == "") && (columnfile == "")) { cout << "When executing a read.dist or a tree.shared command with a distance file you must enter a phylip or a column." << endl; errorFree = false; }
+               else if ((phylipfile != "") && (columnfile != "")) { cout << "When executing a read.dist or a tree.shared command with a distance file you must enter ONLY ONE of the following: phylip or column." << endl; errorFree = false; }
                
                if (columnfile != "") {
                        if (namefile == "") {
@@ -435,7 +450,7 @@ void ErrorCheck::validateParseFiles() {
                                ableToOpen = openInputFile(groupfile, filehandle);
                                filehandle.close();
                                if (ableToOpen == 1) { //unable to open
-                                       errorFree = false;;
+                                       errorFree = false;
                                }
                        }
                }
index 3fc67d11612bccfdced922b1a8276b90cfc5b023..4d439592127e53ff8b61fc465ef5e27db238e49e 100644 (file)
 GetgroupCommand::GetgroupCommand(){
        try {
                globaldata = GlobalData::getInstance();
-               groupMap = globaldata->gGroupmap;
-               outputFile = globaldata->inputFileName + ".bootGroups";
+               
+               //open shared file
+               sharedfile = globaldata->getSharedFile();
+               openInputFile(sharedfile, in);
+               
+               //open output file
+               outputFile = getRootName(globaldata->inputFileName) + "bootGroups";
                openOutputFile(outputFile, out);
        }
        catch(exception& e) {
@@ -37,11 +42,42 @@ GetgroupCommand::~GetgroupCommand(){
 
 int GetgroupCommand::execute(){
        try {
-               vector<string> groupNames = groupMap->namesOfGroups;    
-               for(int i = 0; i < groupNames.size(); i++) {
-                       cout << groupNames[i] << "\n";
-                       out << groupNames[i] << "\t" << groupNames[i] << "\n";
+               int num, inputData, count;
+               count = 0;  
+               string holdLabel, nextLabel, groupN, label;
+               
+               //read in first row since you know there is at least 1 group.
+               in >> label >> groupN >> num;
+               holdLabel = label;
+               
+               //output first group
+               cout << groupN << endl;
+               out << groupN << '\t' << groupN << endl;        
+                       
+               //get rest of line
+               for(int i=0;i<num;i++){
+                       in >> inputData;
+               }
+               
+               if (in.eof() != true) { in >> nextLabel; }
+               
+               //read the rest of the groups info in
+               while ((nextLabel == holdLabel) && (in.eof() != true)) {
+                       in >> groupN >> num;
+                       count++;
+                       
+                       //output next group
+                       cout << groupN << endl;
+                       out << groupN << '\t' << groupN << endl;                                
+                       
+                       //fill vector.  
+                       for(int i=0;i<num;i++){
+                               in >> inputData;
+                       }
+                       
+                       if (in.eof() != true) { in >> nextLabel; }
                }
+               
                out.close();
                return 0;       
        }
index 26190b50139745531e2b8ae06201251c73f530aa..496d0c9c91d2970ecbef50977ff78e8795526538 100644 (file)
@@ -11,9 +11,7 @@
  */
 
 #include "command.hpp"
-#include "readmatrix.hpp"
-
-class GlobalData;
+#include "globaldata.hpp"
 
 class GetgroupCommand : public Command {
 public:
@@ -24,8 +22,9 @@ public:
 private:
        GlobalData* globaldata;
        GroupMap* groupMap;
-       string outputFile;
+       string outputFile, sharedfile;
        ofstream out;
+       ifstream in;
 
 };
 
index 1be2c6edb082e8c700f2165349590ed653154eaa..02b9013887308ef118212b2d7fb06d14b0fd6012 100644 (file)
@@ -249,10 +249,12 @@ void GlobalData::parseGlobalData(string commandString, string optionText){
                        Estimators.clear();
                        splitAtDash(calc, Estimators); 
                }
+               
                if(commandName == "filter.seqs"){
                        if(trump == "" && vertical == "" && hard == "" && soft == ""){
                                trump = '.';
                        }
+
                }
 
                //if you have done a read.otu with a groupfile but don't want to use it anymore because you want to do single commands
index b480dcb9e369ec7763ea7eb2902e99c3c5da0c39..731d77eac343fe1fd34504bf7a7f9ddf6607542f 100644 (file)
@@ -121,7 +121,8 @@ int HelpCommand::execute(){
                cout << "The groups parameter allows you to specify which of the groups in your groupfile you would like analyzed.  You must enter at least 2 valid groups." << "\n";
                cout << "Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile)." << "\n" << "\n";
        }else if (globaldata->helpRequest == "get.group") {
-               cout << "The get.group command can only be executed after a successful read.otu command of a group file." << "\n";
+               cout << "The get.group command can only be executed after a successful read.otu command." << "\n";
+//cout << "The get.group command outputs a .bootGroups file to you can use in addition to the tree file generated by the bootstrap.shared command to run the concensus command." << "\n";
                cout << "You may not use any parameters with the get.group command." << "\n";
                cout << "The get.group command should be in the following format: " << "\n";
                cout << "get.group()" << "\n";
index 7c617c5edf24932213545cb3b9d3e84031387d4c..8dff314b2b7ab3d913d73d4437cd3b82cefd863c 100644 (file)
@@ -12,8 +12,7 @@
 /***********************************************************************/
 EstOutput SharedChao1::getValues(vector<SharedRAbundVector*> shared){
        try {
-               data.resize(1,0);
-               
+               data.resize(1,0);               
                vector<int> temp; 
                int numGroups = shared.size();
                float Chao = 0.0; float leftvalue, rightvalue;
index 46055c0f6f9f428db22e258b9f4a28c060ac774f..d1d1be0bf4f21879e20429bc5e292273f1cda59a 100644 (file)
@@ -42,7 +42,6 @@ SummarySharedCommand::SummarySharedCommand(){
                openOutputFile(outputFileName, outputFileHandle);
                format = globaldata->getFormat();
                validCalculator = new ValidCalculators();
-               util = new SharedUtil();
                mult = false;
                
                int i;
@@ -111,7 +110,6 @@ SummarySharedCommand::SummarySharedCommand(){
 SummarySharedCommand::~SummarySharedCommand(){
        delete input;
        delete read;
-       delete util;
 }
 
 //**********************************************************************************************************************
@@ -119,7 +117,7 @@ SummarySharedCommand::~SummarySharedCommand(){
 int SummarySharedCommand::execute(){
        try {
                int count = 1;  
-               
+       
                //if the users entered no valid calculators don't execute command
                if (sumCalculators.size() == 0) { return 0; }
                //check if any calcs can do multiples
@@ -129,14 +127,12 @@ int SummarySharedCommand::execute(){
                        }
                }
                
+               //read first line
                read = new ReadOTUFile(globaldata->inputFileName);      
                read->read(&*globaldata); 
                        
                input = globaldata->ginput;
-               order = input->getSharedOrderVector();
-                               
-               //set users groups
-               util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "summary");
+               lookup = input->getSharedRAbundVectors();
                
                //output estimator names as column headers
                outputFileHandle << "label" <<'\t' << "comparison" << '\t'; 
@@ -146,7 +142,7 @@ int SummarySharedCommand::execute(){
                outputFileHandle << endl;
                
                //create file and put column headers for multiple groups file
-               if (mult = true) {
+               if (mult == true) {
                        outAllFileName = ((getRootName(globaldata->inputFileName)) + "sharedmultiple.summary");
                        openOutputFile(outAllFileName, outAll);
                        
@@ -159,17 +155,27 @@ int SummarySharedCommand::execute(){
                        outAll << endl;
                }
                
-               while(order != NULL){
+               if (lookup.size() < 2) { 
+                       cout << "I cannot run the command without at least 2 valid groups."; 
+                       for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
+                       
+                       //close files and clean up
+                       outputFileHandle.close();  remove(outputFileName.c_str());
+                       if (mult == true) {  outAll.close();  remove(outAllFileName.c_str());  }
+                       return 0;
+               }
+                                       
+               
+               while(lookup[0] != NULL){
                
-                       if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){                       
+                       if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(lookup[0]->getLabel()) == 1){                   
        
-                               cout << order->getLabel() << '\t' << count << endl;
-                               util->getSharedVectors(globaldata->Groups, lookup, order);  //fills group vectors from order vector.  //fills group vectors from order vector.
+                               cout << lookup[0]->getLabel() << '\t' << count << endl;
                                
                                //loop through calculators and add to file all for all calcs that can do mutiple groups
-                               if (mult = true) {
+                               if (mult == true) {
                                        //output label
-                                       outAll << order->getLabel() << '\t';
+                                       outAll << lookup[0]->getLabel() << '\t';
                                        
                                        //output groups names
                                        string outNames = "";
@@ -188,13 +194,13 @@ int SummarySharedCommand::execute(){
                                        }
                                        outAll << endl;
                                }
-
+       
                                int n = 1; 
                                vector<SharedRAbundVector*> subset;
                                for (int k = 0; k < (lookup.size() - 1); k++) { // pass cdd each set of groups to commpare
                                        for (int l = n; l < lookup.size(); l++) {
                                                
-                                               outputFileHandle << order->getLabel() << '\t';
+                                               outputFileHandle << lookup[0]->getLabel() << '\t';
                                                
                                                subset.clear(); //clear out old pair of sharedrabunds
                                                //add new pair of sharedrabunds
@@ -208,6 +214,7 @@ int SummarySharedCommand::execute(){
                                                }
                                                
                                                for(int i=0;i<sumCalculators.size();i++) {
+
                                                        sumCalculators[i]->getValues(subset); //saves the calculator outputs
                                                        outputFileHandle << '\t';
                                                        sumCalculators[i]->print(outputFileHandle);
@@ -218,13 +225,20 @@ int SummarySharedCommand::execute(){
                                }
                        }
                
+                       //prevent memory leak
+                       for (int i = 0; i < lookup.size(); i++) {       delete lookup[i];       }
+                               
                        //get next line to process
-                       order = input->getSharedOrderVector();
+                       lookup = input->getSharedRAbundVectors();
                        count++;
                }
                
                //reset groups parameter
                globaldata->Groups.clear();  globaldata->setGroups("");
+               
+               //close files
+               outputFileHandle.close();
+               if (mult == true) {  outAll.close();  }
 
                return 0;
        }
index ea141d1610c41676cad785690e32b8a16268cbd3..e73714a3e294f0af471838d38beb39b49d8c1938 100644 (file)
@@ -15,9 +15,8 @@
 #include "inputdata.h"
 #include "calculator.h"
 #include "readotu.h"
-#include "sharedlistvector.h"
 #include "validcalculator.h"
-#include "sharedutilities.h"
+
 
 /*The summary.shared() command
        The summary.shared command can only be executed after a successful read.shared command. 
@@ -46,12 +45,10 @@ public:
 private:
        GlobalData* globaldata;
        ReadOTUFile* read;
-       SharedUtil* util;
        vector<Calculator*> sumCalculators;     
        InputData* input;
        ValidCalculators* validCalculator;
        SharedListVector* SharedList;
-       SharedOrderVector* order;
        vector<SharedRAbundVector*> lookup;
        string outputFileName, format, outAllFileName;
        ofstream outputFileHandle, outAll;
index a6c9c07a0714fb850498a3d6f4439d4247602468..30df40927b7cb79b811c6d4ddfdaeb0264bd81d0 100644 (file)
--- a/tree.cpp
+++ b/tree.cpp
@@ -518,7 +518,9 @@ int Tree::findRoot() {
        try {
                for (int i = 0; i < numNodes; i++) {
                        //you found the root
-                       if (tree[i].getParent() == -1) { return i; }  
+                       if (tree[i].getParent() == -1) { return i; }
+                       //cout << "i = " << i << endl;
+                       //cout << "i's parent = " << tree[i].getParent() << endl;  
                }
                return -1;
        }
diff --git a/tree.h b/tree.h
index 8b77d3ddbed48dddb5de57dfa44394118c7a1920..7fc383806c946d8f22efab62c648f19095313feb 100644 (file)
--- a/tree.h
+++ b/tree.h
@@ -36,6 +36,7 @@ public:
        void printTree();
        void print(ostream&);
        void printForBoot(ostream&);
+       int findRoot();  //return index of root node
        
        //this function takes the leaf info and populates the non leaf nodes
        void assembleTree();            
@@ -55,7 +56,6 @@ private:
        void randomBlengths();
        void randomLabels(vector<string>);
        void randomLabels(string, string);
-       int findRoot();  //return index of root node
        void printBranch(int, ostream&, string);  //recursively print out tree
 };
 
index 43e39f52d6447384133c1c566bfa1fcfe9c7179e..a21c47afcb1df45fc858c4877c43cc7fe9a586e2 100644 (file)
@@ -27,30 +27,32 @@ TreeGroupCommand::TreeGroupCommand(){
                globaldata = GlobalData::getInstance();
                format = globaldata->getFormat();
                validCalculator = new ValidCalculators();
-                       
-               int i;
-               for (i=0; i<globaldata->Estimators.size(); i++) {
-                       if (validCalculator->isValidCalculator("treegroup", globaldata->Estimators[i]) == true) { 
-                               if (globaldata->Estimators[i] == "jabund") {    
-                                       treeCalculators.push_back(new JAbund());
-                               }else if (globaldata->Estimators[i] == "sorabund") { 
-                                       treeCalculators.push_back(new SorAbund());
-                               }else if (globaldata->Estimators[i] == "jclass") { 
-                                       treeCalculators.push_back(new Jclass());
-                               }else if (globaldata->Estimators[i] == "sorclass") { 
-                                       treeCalculators.push_back(new SorClass());
-                               }else if (globaldata->Estimators[i] == "jest") { 
-                                       treeCalculators.push_back(new Jest());
-                               }else if (globaldata->Estimators[i] == "sorest") { 
-                                       treeCalculators.push_back(new SorEst());
-                               }else if (globaldata->Estimators[i] == "thetayc") { 
-                                       treeCalculators.push_back(new ThetaYC());
-                               }else if (globaldata->Estimators[i] == "thetan") { 
-                                       treeCalculators.push_back(new ThetaN());
-                               }else if (globaldata->Estimators[i] == "morisitahorn") { 
-                                       treeCalculators.push_back(new MorHorn());
-                               }else if (globaldata->Estimators[i] == "braycurtis") { 
-                                       treeCalculators.push_back(new BrayCurtis());
+               
+               if (format == "sharedfile") {
+                       int i;
+                       for (i=0; i<globaldata->Estimators.size(); i++) {
+                               if (validCalculator->isValidCalculator("treegroup", globaldata->Estimators[i]) == true) { 
+                                       if (globaldata->Estimators[i] == "jabund") {    
+                                               treeCalculators.push_back(new JAbund());
+                                       }else if (globaldata->Estimators[i] == "sorabund") { 
+                                               treeCalculators.push_back(new SorAbund());
+                                       }else if (globaldata->Estimators[i] == "jclass") { 
+                                               treeCalculators.push_back(new Jclass());
+                                       }else if (globaldata->Estimators[i] == "sorclass") { 
+                                               treeCalculators.push_back(new SorClass());
+                                       }else if (globaldata->Estimators[i] == "jest") { 
+                                               treeCalculators.push_back(new Jest());
+                                       }else if (globaldata->Estimators[i] == "sorest") { 
+                                               treeCalculators.push_back(new SorEst());
+                                       }else if (globaldata->Estimators[i] == "thetayc") { 
+                                               treeCalculators.push_back(new ThetaYC());
+                                       }else if (globaldata->Estimators[i] == "thetan") { 
+                                               treeCalculators.push_back(new ThetaN());
+                                       }else if (globaldata->Estimators[i] == "morisitahorn") { 
+                                               treeCalculators.push_back(new MorHorn());
+                                       }else if (globaldata->Estimators[i] == "braycurtis") { 
+                                               treeCalculators.push_back(new BrayCurtis());
+                                       }
                                }
                        }
                }
@@ -72,100 +74,81 @@ TreeGroupCommand::TreeGroupCommand(){
 
 TreeGroupCommand::~TreeGroupCommand(){
        delete input;
-       delete read;
+       if (format == "sharedfile") {delete read;}
+       else { delete readMatrix;  delete matrix; delete list; }
+       delete tmap;
+       
 }
 
 //**********************************************************************************************************************
 
 int TreeGroupCommand::execute(){
        try {
-               int count = 1;  
-               EstOutput data;
-               vector<SharedRAbundVector*> subset;
-               
-               //if the users entered no valid calculators don't execute command
-               if (treeCalculators.size() == 0) { return 0; }
+               if (format == "sharedfile") {
+                       //if the users entered no valid calculators don't execute command
+                       if (treeCalculators.size() == 0) { cout << "You have given no valid calculators." << endl; return 0; }
 
-               //you have groups
-               read = new ReadOTUFile(globaldata->inputFileName);      
-               read->read(&*globaldata); 
+                       //you have groups
+                       read = new ReadOTUFile(globaldata->inputFileName);      
+                       read->read(&*globaldata); 
                        
-               input = globaldata->ginput;
-               lookup = input->getSharedRAbundVectors();
-                               
-               if (lookup.size() < 2) { cout << "You have not provided enough valid groups.  I cannot run the command." << endl; return 0; }
-               
-               numGroups = globaldata->Groups.size();
-               groupNames = "";
-               for (int i = 0; i < numGroups; i++) { groupNames += globaldata->Groups[i]; }
-               
-               //clear globaldatas old tree names if any
-               globaldata->Treenames.clear();
-               
-               //fills globaldatas tree names
-               globaldata->Treenames = globaldata->Groups;
-               
-               //create treemap class from groupmap for tree class to use
-               tmap = new TreeMap();
-               tmap->makeSim(globaldata->gGroupmap);
-               globaldata->gTreemap = tmap;
+                       input = globaldata->ginput;
+                       lookup = input->getSharedRAbundVectors();
                        
-               while(lookup[0] != NULL){
+                       if (lookup.size() < 2) { cout << "You have not provided enough valid groups.  I cannot run the command." << endl; return 0; }
                
-                       if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(lookup[0]->getLabel()) == 1){                   
-                               
-                               cout << lookup[0]->getLabel() << '\t' << count << endl;
-                               
-                               //for each calculator                                                                                           
-                               for(int i = 0 ; i < treeCalculators.size(); i++) {
-                                       
-                                       //initialize simMatrix
-                                       simMatrix.clear();
-                                       simMatrix.resize(numGroups);
-                                       for (int m = 0; m < simMatrix.size(); m++)      {
-                                               for (int j = 0; j < simMatrix.size(); j++)      {
-                                                       simMatrix[m].push_back(0.0);
-                                               }
-                                       }
+                       //create tree file
+                       makeSimsShared();
+               }else{
+                       //read in dist file
+                       filename = globaldata->inputFileName;
+               
+                       if (format == "column") { readMatrix = new ReadColumnMatrix(filename); }        
+                       else if (format == "phylip") { readMatrix = new ReadPhylipMatrix(filename); }
                                
-                                       //initialize index
-                                       index.clear();
-                                       for (int g = 0; g < numGroups; g++) {   index[g] = g;   }
+                       if(globaldata->getPrecision() != ""){
+                               convert(globaldata->getPrecision(), precision); 
+                       }
                
-                                       //create a new filename
-                                       outputFile = getRootName(globaldata->inputFileName) + treeCalculators[i]->getName() + "." + lookup[0]->getLabel() + ".tre";
-                                       
-                                                                                               
-                                       for (int k = 0; k < lookup.size(); k++) { 
-                                               for (int l = k; l < lookup.size(); l++) {
-                                                       if (k != l) { //we dont need to similiarity of a groups to itself
-                                                               //get estimated similarity between 2 groups
-                                                               
-                                                               subset.clear(); //clear out old pair of sharedrabunds
-                                                               //add new pair of sharedrabunds
-                                                               subset.push_back(lookup[k]); subset.push_back(lookup[l]); 
-                                                               
-                                                               data = treeCalculators[i]->getValues(subset); //saves the calculator outputs
-                                                               //save values in similarity matrix
-                                                               simMatrix[k][l] = data[0];
-                                                               simMatrix[l][k] = data[0];
-                                                       }
-                                               }
-                                       }
-                                       
-                                       //creates tree from similarity matrix and write out file
-                                       createTree();
-                               }
+                       if(globaldata->getCutOff() != ""){
+                               convert(globaldata->getCutOff(), cutoff);       
+                               cutoff += (5 / (precision * 10.0));
                        }
+                       readMatrix->setCutoff(cutoff);
+       
+                       if(globaldata->getNameFile() != ""){    
+                               nameMap = new NameAssignment(globaldata->getNameFile());
+                               nameMap->readMap(1,2);
+                       }
+                       else{
+                               nameMap = NULL;
+                       }
+       
+                       readMatrix->read(nameMap);
+                       list = readMatrix->getListVector();
+                       matrix = readMatrix->getMatrix();
+
+                       //make treemap
+                       tmap = new TreeMap();
+                       tmap->makeSim(list);
+                       globaldata->gTreemap = tmap;
                        
-                       //prevent memory leak
-                       for (int i = 0; i < lookup.size(); i++) {       delete lookup[i];       }
-                       
-                       //get next line to process
-                       lookup = input->getSharedRAbundVectors();
-                       count++;
-               }
+                       globaldata->Groups = tmap->namesOfGroups;
+               
+                       //clear globaldatas old tree names if any
+                       globaldata->Treenames.clear();
                
+                       //fills globaldatas tree names
+                       globaldata->Treenames = globaldata->Groups;
+
+                       makeSimsDist();
+
+                       //create a new filename
+                       outputFile = getRootName(globaldata->inputFileName) + "tre";    
+                               
+                       createTree();
+               }
+                               
                //reset groups parameter
                globaldata->Groups.clear();  globaldata->setGroups("");
 
@@ -190,8 +173,8 @@ void TreeGroupCommand::createTree(){
                //do merges and create tree structure by setting parents and children
                //there are numGroups - 1 merges to do
                for (int i = 0; i < (numGroups - 1); i++) {
-                       
-                       float largest = 0.0;
+                       float largest = -1000.0;
+
                        int row, column;
                        //find largest value in sims matrix by searching lower triangle
                        for (int j = 1; j < simMatrix.size(); j++) {
@@ -223,9 +206,9 @@ void TreeGroupCommand::createTree(){
                        index[row] = numGroups+i;
                        index[column] = numGroups+i;
                        
-                       //zero out highest value that caused the merge.
-                       simMatrix[row][column] = 0.0;
-                       simMatrix[column][row] = 0.0;
+                       //remove highest value that caused the merge.
+                       simMatrix[row][column] = -1000.0;
+                       simMatrix[column][row] = -1000.0;
                        
                        //merge values in simsMatrix
                        for (int n = 0; n < simMatrix.size(); n++)      {
@@ -233,11 +216,15 @@ void TreeGroupCommand::createTree(){
                                simMatrix[row][n] = (simMatrix[row][n] + simMatrix[column][n]) / 2;
                                simMatrix[n][row] = simMatrix[row][n];
                                //delete column
-                               simMatrix[column][n] = 0.0;
-                               simMatrix[n][column] = 0.0;
+                               simMatrix[column][n] = -1000.0;
+                               simMatrix[n][column] = -1000.0;
                        }
                }
-       
+               
+               //adjust tree to make sure root to tip length is .5
+               int root = t->findRoot();
+               t->tree[root].setBranchLength((0.5 - t->tree[root].getLengthToLeaves()));
+               
                //assemble tree
                t->assembleTree();
                
@@ -262,13 +249,13 @@ void TreeGroupCommand::printSims(ostream& out) {
        try {
                
                //output column headers
-               out << '\t';
-               for (int i = 0; i < lookup.size(); i++) {       out << lookup[i]->getGroup() << '\t';           }
-               out << endl;
+               //out << '\t';
+               //for (int i = 0; i < lookup.size(); i++) {     out << lookup[i]->getGroup() << '\t';           }
+               //out << endl;
                
                
                for (int m = 0; m < simMatrix.size(); m++)      {
-                       out << lookup[m]->getGroup() << '\t';
+                       //out << lookup[m]->getGroup() << '\t';
                        for (int n = 0; n < simMatrix.size(); n++)      {
                                out << simMatrix[m][n] << '\t'; 
                        }
@@ -286,5 +273,129 @@ void TreeGroupCommand::printSims(ostream& out) {
        }               
 }
 /***********************************************************/
+void TreeGroupCommand::makeSimsDist() {
+       try {
+               numGroups = list->size();
+               
+               //initialize index
+               index.clear();
+               for (int g = 0; g < numGroups; g++) {   index[g] = g;   }
+               
+               //initialize simMatrix
+               simMatrix.clear();
+               simMatrix.resize(numGroups);
+               for (int m = 0; m < simMatrix.size(); m++)      {
+                       for (int j = 0; j < simMatrix.size(); j++)      {
+                               simMatrix[m].push_back(0.0);
+                       }
+               }
+               
+               //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);                           
+               }
+
+
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the TreeGroupCommand class Function makeSimsDist. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the TreeGroupCommand class function makeSimsDist. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+
+/***********************************************************/
+void TreeGroupCommand::makeSimsShared() {
+       try {
+               int count = 1;  
+               EstOutput data;
+               vector<SharedRAbundVector*> subset;
+       
+               numGroups = globaldata->Groups.size();
+               
+               //clear globaldatas old tree names if any
+               globaldata->Treenames.clear();
+               
+               //fills globaldatas tree names
+               globaldata->Treenames = globaldata->Groups;
+               
+               //create treemap class from groupmap for tree class to use
+               tmap = new TreeMap();
+               tmap->makeSim(globaldata->gGroupmap);
+               globaldata->gTreemap = tmap;
+               
+               while(lookup[0] != NULL){
+               
+                       if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(lookup[0]->getLabel()) == 1){                   
+                               
+                               cout << lookup[0]->getLabel() << '\t' << count << endl;
+                               
+                               //for each calculator                                                                                           
+                               for(int i = 0 ; i < treeCalculators.size(); i++) {
+                                       //initialize simMatrix
+                                       simMatrix.clear();
+                                       simMatrix.resize(numGroups);
+                                       for (int m = 0; m < simMatrix.size(); m++)      {
+                                               for (int j = 0; j < simMatrix.size(); j++)      {
+                                                       simMatrix[m].push_back(0.0);
+                                               }
+                                       }
+               
+                                       //initialize index
+                                       index.clear();
+                                       for (int g = 0; g < numGroups; g++) {   index[g] = g;   }
+               
+                                       //create a new filename
+                                       outputFile = getRootName(globaldata->inputFileName) + treeCalculators[i]->getName() + "." + lookup[0]->getLabel() + ".tre";                             
+                                                                                               
+                                       for (int k = 0; k < lookup.size(); k++) { 
+                                               for (int l = k; l < lookup.size(); l++) {
+                                                       if (k != l) { //we dont need to similiarity of a groups to itself
+                                                               //get estimated similarity between 2 groups
+                                                               
+                                                               subset.clear(); //clear out old pair of sharedrabunds
+                                                               //add new pair of sharedrabunds
+                                                               subset.push_back(lookup[k]); subset.push_back(lookup[l]); 
+                                                               
+                                                               data = treeCalculators[i]->getValues(subset); //saves the calculator outputs
+                                                               //save values in similarity matrix
+                                                               simMatrix[k][l] = data[0];
+                                                               simMatrix[l][k] = data[0];
+                                                       }
+                                               }
+                                       }
+                                       
+                                       //creates tree from similarity matrix and write out file
+                                       createTree();
+                               }
+                       }
+                       
+                       //prevent memory leak
+                       for (int i = 0; i < lookup.size(); i++) {       delete lookup[i];       }
+                       
+                       //get next line to process
+                       lookup = input->getSharedRAbundVectors();
+                       count++;
+               }
+               
+               for(int i = 0 ; i < treeCalculators.size(); i++) {  delete treeCalculators[i]; }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the TreeGroupCommand class Function makeSimsShared. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the TreeGroupCommand class function makeSimsShared. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+}
+
+/***********************************************************/
 
 
index 10a2e31c88ea6a177b55a6a2e8f19f99d07e520d..3f145e92b4780fa4f40a45ed1849150dafffc800 100644 (file)
 #include "validcalculator.h"
 #include "tree.h"
 #include "treemap.h"
+#include "readmatrix.hpp"
+#include "readcolumn.h"
+#include "readphylip.h"
+#include "sparsematrix.hpp"
 
 
 /* This command create a tree file for each similarity calculator at distance level, using various calculators to find the similiarity between groups. 
@@ -25,6 +29,8 @@
        
 class GlobalData;
 
+typedef list<PCell>::iterator MatData;
+
 class TreeGroupCommand : public Command {
        
 public:
@@ -35,9 +41,15 @@ public:
 private:
        void createTree();
        void printSims(ostream&);
+       void makeSimsShared();
+       void makeSimsDist();
        
        GlobalData* globaldata;
        ReadOTUFile* read;
+       ReadMatrix* readMatrix;
+       SparseMatrix* matrix;
+       NameAssignment* nameMap;
+       ListVector* list;
        TreeMap* tmap;
        Tree* t;
        vector<Calculator*> treeCalculators;
@@ -46,9 +58,10 @@ private:
        InputData* input;
        ValidCalculators* validCalculator;
        vector<SharedRAbundVector*> lookup;
-       string format, outputFile, groupNames;
+       string format, outputFile, groupNames, filename;
        int numGroups;
        ofstream out;
+       float precision, cutoff;
 
 };
        
index 00ae0e664ff5fb7d289893b445be08b5fd20c89a..8e3fd58b94cbf6e9c16e9b0335fb71cbf5cd68bb 100644 (file)
@@ -162,13 +162,44 @@ void TreeMap::makeSim(GroupMap* groupmap) {
                
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the TreeMap class Function make. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               cout << "Standard Error: " << e.what() << " has occurred in the TreeMap class Function makeSim. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
                exit(1);
        }
        catch(...) {
-               cout << "An unknown error has occurred in the TreeMap class function make. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               cout << "An unknown error has occurred in the TreeMap class function makeSim. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
                exit(1);
        }
 }
 /************************************************************/
+void TreeMap::makeSim(ListVector* list) {
+       try {
+               //set names of groups
+               namesOfGroups.clear();
+               for(int i = 0; i < list->size(); i++) {
+                       namesOfGroups.push_back(list->get(i));
+               }
+               
+               //set names of seqs to names of groups
+               namesOfSeqs = namesOfGroups;
+               
+               // make map where key and value are both the group name since that what the tree.shared command wants
+               for (int i = 0; i < namesOfGroups.size(); i++) {
+                       treemap[namesOfGroups[i]].groupname = namesOfGroups[i];
+                       seqsPerGroup[namesOfGroups[i]] = 1;
+               }
+               
+               numGroups = namesOfGroups.size();
+               
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the TreeMap class Function makeSim. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the TreeMap class function makeSim. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/************************************************************/
 
index 73d02fcc4b0c58f29de00c130e3fa8a197dd3d53..8f744c80a3e92873699aca320032cedeea59a007 100644 (file)
--- a/treemap.h
+++ b/treemap.h
@@ -11,6 +11,7 @@
 
 #include "mothur.h"
 #include "groupmap.h"
+#include "listvector.hpp"
 
 /* This class is used by the read.tree command to build the tree container. */
 
@@ -20,6 +21,7 @@ struct GroupIndex {
 };
 
 class GroupMap;
+class ListVector;
 
 class TreeMap {
 public:
@@ -39,7 +41,7 @@ public:
        map<string, GroupIndex> treemap; //sequence name and <groupname, vector index>
        void print(ostream&);
        void makeSim(GroupMap*);  //takes groupmap info and fills treemap for use by tree.shared command.
-       
+       void makeSim(ListVector*);  //takes listvector info and fills treemap for use by tree.shared command.   
        
 private:
        ifstream fileHandle;
index 650ef1fea0217f1cb4b58d47770b953c4389ddf3..4aad1c22c037515fcb5d6f166aae8af4842d8fd4 100644 (file)
@@ -282,7 +282,7 @@ void ValidParameters::initCommandParameters() {
                string getOTURepArray[] =  {"fasta","list","line","label","name", "group"};
                commandParameters["get.oturep"] = addParameters(getOTURepArray, sizeof(getOTURepArray)/sizeof(string));
                
-               string treeGroupsArray[] =  {"line","label","calc","groups"};
+               string treeGroupsArray[] =  {"line","label","calc","groups", "phylip", "column", "name"};
                commandParameters["tree.shared"] = addParameters(treeGroupsArray, sizeof(treeGroupsArray)/sizeof(string));
                
                string bootstrapArray[] =  {"line","label","calc","groups","iters"};