]> git.donarmstrong.com Git - mothur.git/blobdiff - treegroupscommand.cpp
added [ERROR] flag if command aborts
[mothur.git] / treegroupscommand.cpp
index 64bcd36764e044a911295870025095016be7fcc3..a31c15192f1f27dcc1b84ddf114d0dcf485d41a3 100644 (file)
@@ -8,6 +8,10 @@
  */
 
 #include "treegroupscommand.h"
+#include "sharedsobscollectsummary.h"
+#include "sharedchao1.h"
+#include "sharedace.h"
+#include "sharednseqs.h"
 #include "sharedjabund.h"
 #include "sharedsorabund.h"
 #include "sharedjclass.h"
 #include "sharedsorest.h"
 #include "sharedthetayc.h"
 #include "sharedthetan.h"
+#include "sharedkstest.h"
+#include "whittaker.h"
+#include "sharedochiai.h"
+#include "sharedanderbergs.h"
+#include "sharedkulczynski.h"
+#include "sharedkulczynskicody.h"
+#include "sharedlennon.h"
 #include "sharedmorisitahorn.h"
 #include "sharedbraycurtis.h"
+#include "sharedjackknife.h"
+#include "whittaker.h"
+#include "odum.h"
+#include "canberra.h"
+#include "structeuclidean.h"
+#include "structchord.h"
+#include "hellinger.h"
+#include "manhattan.h"
+#include "structpearson.h"
+#include "soergel.h"
+#include "spearman.h"
+#include "structkulczynski.h"
+#include "structchi2.h"
+#include "speciesprofile.h"
+#include "hamming.h"
+#include "gower.h"
+#include "memchi2.h"
+#include "memchord.h"
+#include "memeuclidean.h"
+#include "mempearson.h"
 
 //**********************************************************************************************************************
 vector<string> TreeGroupCommand::getValidParameters(){ 
@@ -34,7 +65,7 @@ vector<string> TreeGroupCommand::getValidParameters(){
 //**********************************************************************************************************************
 TreeGroupCommand::TreeGroupCommand(){  
        try {
-               abort = true;
+               abort = true; calledHelp = true;
                globaldata = GlobalData::getInstance();
                //initialize outputTypes
                vector<string> tempOutNames;
@@ -73,14 +104,14 @@ vector<string> TreeGroupCommand::getRequiredFiles(){
 TreeGroupCommand::TreeGroupCommand(string option)  {
        try {
                globaldata = GlobalData::getInstance();
-               abort = false;
+               abort = false; calledHelp = false;   
                allLines = 1;
                labels.clear();
                Groups.clear();
                Estimators.clear();
                
                //allow user to run help
-               if(option == "help") { validCalculator = new ValidCalculators(); help(); abort = true; }
+               if(option == "help") { validCalculator = new ValidCalculators(); help(); abort = true; calledHelp = true; }
                
                else {
                        //valid paramters for this command
@@ -210,7 +241,13 @@ TreeGroupCommand::TreeGroupCommand(string option)  {
                                        int i;
                                        for (i=0; i<Estimators.size(); i++) {
                                                if (validCalculator->isValidCalculator("treegroup", Estimators[i]) == true) { 
-                                                       if (Estimators[i] == "jabund") {        
+                                                       if (Estimators[i] == "sharedsobs") { 
+                                                               treeCalculators.push_back(new SharedSobsCS());
+                                                       }else if (Estimators[i] == "sharedchao") { 
+                                                               treeCalculators.push_back(new SharedChao1());
+                                                       }else if (Estimators[i] == "sharedace") { 
+                                                               treeCalculators.push_back(new SharedAce());
+                                                       }else if (Estimators[i] == "jabund") {  
                                                                treeCalculators.push_back(new JAbund());
                                                        }else if (Estimators[i] == "sorabund") { 
                                                                treeCalculators.push_back(new SorAbund());
@@ -226,10 +263,62 @@ TreeGroupCommand::TreeGroupCommand(string option)  {
                                                                treeCalculators.push_back(new ThetaYC());
                                                        }else if (Estimators[i] == "thetan") { 
                                                                treeCalculators.push_back(new ThetaN());
+                                                       }else if (Estimators[i] == "kstest") { 
+                                                               treeCalculators.push_back(new KSTest());
+                                                       }else if (Estimators[i] == "sharednseqs") { 
+                                                               treeCalculators.push_back(new SharedNSeqs());
+                                                       }else if (Estimators[i] == "ochiai") { 
+                                                               treeCalculators.push_back(new Ochiai());
+                                                       }else if (Estimators[i] == "anderberg") { 
+                                                               treeCalculators.push_back(new Anderberg());
+                                                       }else if (Estimators[i] == "kulczynski") { 
+                                                               treeCalculators.push_back(new Kulczynski());
+                                                       }else if (Estimators[i] == "kulczynskicody") { 
+                                                               treeCalculators.push_back(new KulczynskiCody());
+                                                       }else if (Estimators[i] == "lennon") { 
+                                                               treeCalculators.push_back(new Lennon());
                                                        }else if (Estimators[i] == "morisitahorn") { 
                                                                treeCalculators.push_back(new MorHorn());
                                                        }else if (Estimators[i] == "braycurtis") { 
                                                                treeCalculators.push_back(new BrayCurtis());
+                                                       }else if (Estimators[i] == "whittaker") { 
+                                                               treeCalculators.push_back(new Whittaker());
+                                                       }else if (Estimators[i] == "odum") { 
+                                                               treeCalculators.push_back(new Odum());
+                                                       }else if (Estimators[i] == "canberra") { 
+                                                               treeCalculators.push_back(new Canberra());
+                                                       }else if (Estimators[i] == "structeuclidean") { 
+                                                               treeCalculators.push_back(new StructEuclidean());
+                                                       }else if (Estimators[i] == "structchord") { 
+                                                               treeCalculators.push_back(new StructChord());
+                                                       }else if (Estimators[i] == "hellinger") { 
+                                                               treeCalculators.push_back(new Hellinger());
+                                                       }else if (Estimators[i] == "manhattan") { 
+                                                               treeCalculators.push_back(new Manhattan());
+                                                       }else if (Estimators[i] == "structpearson") { 
+                                                               treeCalculators.push_back(new StructPearson());
+                                                       }else if (Estimators[i] == "soergel") { 
+                                                               treeCalculators.push_back(new Soergel());
+                                                       }else if (Estimators[i] == "spearman") { 
+                                                               treeCalculators.push_back(new Spearman());
+                                                       }else if (Estimators[i] == "structkulczynski") { 
+                                                               treeCalculators.push_back(new StructKulczynski());
+                                                       }else if (Estimators[i] == "speciesprofile") { 
+                                                               treeCalculators.push_back(new SpeciesProfile());
+                                                       }else if (Estimators[i] == "hamming") { 
+                                                               treeCalculators.push_back(new Hamming());
+                                                       }else if (Estimators[i] == "structchi2") { 
+                                                               treeCalculators.push_back(new StructChi2());
+                                                       }else if (Estimators[i] == "gower") { 
+                                                               treeCalculators.push_back(new Gower());
+                                                       }else if (Estimators[i] == "memchi2") { 
+                                                               treeCalculators.push_back(new MemChi2());
+                                                       }else if (Estimators[i] == "memchord") { 
+                                                               treeCalculators.push_back(new MemChord());
+                                                       }else if (Estimators[i] == "memeuclidean") { 
+                                                               treeCalculators.push_back(new MemEuclidean());
+                                                       }else if (Estimators[i] == "mempearson") { 
+                                                               treeCalculators.push_back(new MemPearson());
                                                        }
                                                }
                                        }
@@ -291,7 +380,7 @@ TreeGroupCommand::~TreeGroupCommand(){
 int TreeGroupCommand::execute(){
        try {
        
-               if (abort == true) { return 0; }
+               if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
                
                if (format == "sharedfile") {
                        //if the users entered no valid calculators don't execute command
@@ -658,6 +747,14 @@ int TreeGroupCommand::process(vector<SharedRAbundVector*> thisLookup) {
                                                                //add new pair of sharedrabunds
                                                                subset.push_back(thisLookup[k]); subset.push_back(thisLookup[l]); 
                                                                
+                                                               //if this calc needs all groups to calculate the pair load all groups
+                                                               if (treeCalculators[i]->getNeedsAll()) { 
+                                                                       //load subset with rest of lookup for those calcs that need everyone to calc for a pair
+                                                                       for (int w = 0; w < thisLookup.size(); w++) {
+                                                                               if ((w != k) && (w != l)) { subset.push_back(thisLookup[w]); }
+                                                                       }
+                                                               }
+                                                               
                                                                data = treeCalculators[i]->getValues(subset); //saves the calculator outputs
                                                //cout << thisLookup[k]->getGroup() << '\t' << thisLookup[l]->getGroup() << '\t' << (1.0 - data[0]) << endl;
                                                                if (m->control_pressed) { return 1; }
@@ -669,6 +766,21 @@ int TreeGroupCommand::process(vector<SharedRAbundVector*> thisLookup) {
                                                }
                                        }
                                        
+                                       //createdistance file from simMatrix
+                                       /*string o = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".dist";
+                                       ofstream outDist;
+                                       m->openOutputFile(o, outDist);
+                                       outDist << simMatrix.size() << endl;
+                                       for (int k = 0; k < simMatrix.size(); k++) {
+                                               outDist << thisLookup[k]->getGroup() << '\t';
+                                               for (int l = 0; l < k; l++) {
+                                                       outDist << (1.0-simMatrix[k][l]) << '\t';
+                                               }
+                                               outDist << endl;
+                                       }
+                                       outDist.close();*/
+
+                                       
                                        if (m->control_pressed) { return 1; }
                                        //creates tree from similarity matrix and write out file
                                        createTree();