]> git.donarmstrong.com Git - mothur.git/blobdiff - summarysharedcommand.cpp
fixed bug in heatmap
[mothur.git] / summarysharedcommand.cpp
index e6a7d9a7363a5d9a71d32fad38d6172248b0934a..486e6c4982b885c82a39e5387b0b987e54f843ec 100644 (file)
@@ -29,6 +29,8 @@
 #include "sharedlennon.h"
 #include "sharedmorisitahorn.h"
 #include "sharedbraycurtis.h"
+#include "sharedjackknife.h"
+#include "sharedwhittaker.h"
 
 
 //**********************************************************************************************************************
@@ -41,6 +43,7 @@ SummarySharedCommand::SummarySharedCommand(){
                format = globaldata->getFormat();
                validCalculator = new ValidCalculators();
                util = new SharedUtil();
+               mult = false;
                
                int i;
                for (i=0; i<globaldata->Estimators.size(); i++) {
@@ -85,11 +88,9 @@ SummarySharedCommand::SummarySharedCommand(){
                                        sumCalculators.push_back(new MorHorn());
                                }else if (globaldata->Estimators[i] == "braycurtis") { 
                                        sumCalculators.push_back(new BrayCurtis());
-                               }
-                               else if (globaldata->Estimators[i] == "whittaker") { 
+                               }else if (globaldata->Estimators[i] == "whittaker") { 
                                        sumCalculators.push_back(new Whittaker());
                                }
-                               
                        }
                }
                //reset calc for next command
@@ -121,23 +122,19 @@ int SummarySharedCommand::execute(){
                
                //if the users entered no valid calculators don't execute command
                if (sumCalculators.size() == 0) { return 0; }
-
-               if (format == "sharedfile") {
-                       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();
+               //check if any calcs can do multiples
+               else{
+                       for (int i = 0; i < sumCalculators.size(); i++) {
+                               if (sumCalculators[i]->getMultiple() == true) { mult = true; }
+                       }
                }
                
+               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");
                
@@ -148,6 +145,20 @@ int SummarySharedCommand::execute(){
                }
                outputFileHandle << endl;
                
+               //create file and put column headers for multiple groups file
+               if (mult = true) {
+                       outAllFileName = ((getRootName(globaldata->inputFileName)) + "sharedmultiple.summary");
+                       openOutputFile(outAllFileName, outAll);
+                       
+                       outAll << "label" <<'\t' << "comparison" << '\t'; 
+                       for(int i=0;i<sumCalculators.size();i++){
+                               if (sumCalculators[i]->getMultiple() == true) { 
+                                       outAll << '\t' << sumCalculators[i]->getName();
+                               }
+                       }
+                       outAll << endl;
+               }
+               
                while(order != NULL){
                
                        if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){                       
@@ -155,15 +166,40 @@ int SummarySharedCommand::execute(){
                                cout << order->getLabel() << '\t' << count << endl;
                                util->getSharedVectors(globaldata->Groups, lookup, order);  //fills group vectors from order vector.  //fills group vectors from order vector.
                                
-                               //randomize group order
-                               if (globaldata->getJumble() == "1") { random_shuffle(lookup.begin(), lookup.end()); }
+                               //loop through calculators and add to file all for all calcs that can do mutiple groups
+                               if (mult = true) {
+                                       //output label
+                                       outAll << order->getLabel() << '\t';
+                                       
+                                       //output groups names
+                                       string outNames = "";
+                                       for (int j = 0; j < lookup.size(); j++) {
+                                               outNames += lookup[j]->getGroup() +  "-";
+                                       }
+                                       outNames = outNames.substr(0, outNames.length()-1); //rip off extra '-';
+                                       outAll << outNames << '\t';
+                                       
+                                       for(int i=0;i<sumCalculators.size();i++){
+                                               if (sumCalculators[i]->getMultiple() == true) { 
+                                                       sumCalculators[i]->getValues(lookup);
+                                                       outAll << '\t';
+                                                       sumCalculators[i]->print(outAll);
+                                               }
+                                       }
+                                       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';
                                                
+                                               subset.clear(); //clear out old pair of sharedrabunds
+                                               //add new pair of sharedrabunds
+                                               subset.push_back(lookup[k]); subset.push_back(lookup[l]); 
+                                               
                                                //sort groups to be alphanumeric
                                                if (lookup[k]->getGroup() > lookup[l]->getGroup()) {
                                                        outputFileHandle << (lookup[l]->getGroup() +'\t' + lookup[k]->getGroup()) << '\t'; //print out groups
@@ -171,8 +207,8 @@ int SummarySharedCommand::execute(){
                                                        outputFileHandle << (lookup[k]->getGroup() +'\t' + lookup[l]->getGroup()) << '\t'; //print out groups
                                                }
                                                
-                                               for(int i=0;i<sumCalculators.size();i++){
-                                                       sumCalculators[i]->getValues(lookup[k], lookup[l]); //saves the calculator outputs
+                                               for(int i=0;i<sumCalculators.size();i++) {
+                                                       sumCalculators[i]->getValues(subset); //saves the calculator outputs
                                                        outputFileHandle << '\t';
                                                        sumCalculators[i]->print(outputFileHandle);
                                                }
@@ -183,17 +219,7 @@ int SummarySharedCommand::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;
-                               }
-                       }
+                       order = input->getSharedOrderVector();
                        count++;
                }