]> git.donarmstrong.com Git - mothur.git/blobdiff - treegroupscommand.cpp
changed all shared commands so that they read the shared file generated by the read...
[mothur.git] / treegroupscommand.cpp
index 7791d5ecd913c431114a9de5afb2ca651ec1232c..ac82da5e558d2965829de82f170b1514c8972c84 100644 (file)
@@ -17,6 +17,7 @@
 #include "sharedthetayc.h"
 #include "sharedthetan.h"
 #include "sharedmorisitahorn.h"
+#include "sharedbraycurtis.h"
 
 
 //**********************************************************************************************************************
@@ -49,6 +50,8 @@ TreeGroupCommand::TreeGroupCommand(){
                                        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());
                                }
                        }
                }
@@ -80,28 +83,20 @@ 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") {
-                       read = new ReadOTUFile(globaldata->inputFileName);      
-                       read->read(&*globaldata); 
+               //you have groups
+               read = new ReadOTUFile(globaldata->inputFileName);      
+               read->read(&*globaldata); 
                        
-                       input = globaldata->ginput;
-                       order = input->getSharedOrderVector();
-               }else {
-                       //you are using a list and a groupfile
-                       read = new ReadOTUFile(globaldata->inputFileName);      
-                       read->read(&*globaldata); 
-               
-                       input = globaldata->ginput;
-                       SharedList = globaldata->gSharedList;
-                       order = SharedList->getSharedOrderVector();
-               }
+               input = globaldata->ginput;
+               lookup = input->getSharedRAbundVectors();
+                               
+               if (lookup.size() < 2) { cout << "You have not provided enough valid groups.  I cannot run the command." << endl; }
                
-               //set users groups
-               util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "treegroup");
                numGroups = globaldata->Groups.size();
                groupNames = "";
                for (int i = 0; i < numGroups; i++) { groupNames += globaldata->Groups[i]; }
@@ -117,12 +112,11 @@ int TreeGroupCommand::execute(){
                tmap->makeSim(globaldata->gGroupmap);
                globaldata->gTreemap = tmap;
                        
-               while(order != NULL){
+               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.
+                               cout << lookup[0]->getLabel() << '\t' << count << endl;
                                
                                //for each calculator                                                                                           
                                for(int i = 0 ; i < treeCalculators.size(); i++) {
@@ -141,13 +135,18 @@ int TreeGroupCommand::execute(){
                                        for (int g = 0; g < numGroups; g++) {   index[g] = g;   }
                
                                        //create a new filename
-                                       outputFile = getRootName(globaldata->inputFileName) + treeCalculators[i]->getName() + "." + order->getLabel() + ".tre";
+                                       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
-                                                               data = treeCalculators[i]->getValues(lookup[k], lookup[l]); //saves the calculator outputs
+                                                               
+                                                               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];
@@ -161,17 +160,7 @@ int TreeGroupCommand::execute(){
                        }
                
                        //get next line to process
-                       if (format == "sharedfile") {
-                               order = input->getSharedOrderVector();
-                       }else {
-                               //you are using a list and a groupfile
-                               SharedList = input->getSharedListVector(); //get new list vector to process
-                               if (SharedList != NULL) {
-                                       order = SharedList->getSharedOrderVector(); //gets new order vector with group info.
-                               }else {
-                                       break;
-                               }
-                       }
+                       lookup = input->getSharedRAbundVectors();
                        count++;
                }