]> git.donarmstrong.com Git - mothur.git/blobdiff - collectsharedcommand.cpp
added nseqs and sharednseqs calculators, removed excess tabs in output files.
[mothur.git] / collectsharedcommand.cpp
index 217045a4a1fc5dc0c83986f3b3a0345b755e1f6c..e989233c7b86c3efae39d5a7f1b5b0541a365bd5 100644 (file)
@@ -19,6 +19,7 @@
 #include "sharedsorest.h"
 #include "sharedthetayc.h"
 #include "sharedthetan.h"
+#include "sharednseqs.h"
 
 
 //**********************************************************************************************************************
@@ -56,7 +57,10 @@ CollectSharedCommand::CollectSharedCommand(){
                                        cDisplays.push_back(new CollectDisplay(new SharedThetaYC(), new SharedOneColumnFile(fileNameRoot+"shared.thetayc")));
                                }else if (globaldata->Estimators[i] == "sharedthetan") { 
                                        cDisplays.push_back(new CollectDisplay(new SharedThetaN(), new SharedOneColumnFile(fileNameRoot+"shared.thetan")));
+                               }else if (globaldata->Estimators[i] == "sharednseqs") { 
+                                       cDisplays.push_back(new CollectDisplay(new SharedNSeqs(), new SharedOneColumnFile(fileNameRoot+"shared.nseqs")));
                                }
+
                        }
                }
                
@@ -108,9 +112,13 @@ int CollectSharedCommand::execute(){
                        SharedList = globaldata->gSharedList;
                        order = SharedList->getSharedOrderVector();
                }
+               set<string> orderList;
                
+               //set users groups
+               setGroups();
+
                while(order != NULL){
-               
+                       orderList.insert(order->getLabel());
                        if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
                                //create collectors curve
                                cCurve = new Collect(order, cDisplays);
@@ -137,8 +145,15 @@ int CollectSharedCommand::execute(){
                        
                        count++;
                }
-       
+               set<string>::iterator i;
+               for(i = globaldata->labels.begin(); i != globaldata->labels.end(); ++i)
+                       if(orderList.count(*i) == 0)
+                               cout << "'" << *i << "'" << " is not a valid label.\n";
                for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }       
+               
+               //reset groups parameter
+               globaldata->Groups.clear();  globaldata->setGroups("");
+               
                return 0;
        }
        catch(exception& e) {
@@ -153,3 +168,50 @@ int CollectSharedCommand::execute(){
 
 
 //**********************************************************************************************************************
+void CollectSharedCommand::setGroups() {
+       try {
+               //if the user has not entered specific groups to analyze then do them all
+               if (globaldata->Groups.size() != 0) {
+                       if (globaldata->Groups[0] != "all") {
+                               //check that groups are valid
+                               for (int i = 0; i < globaldata->Groups.size(); i++) {
+                                       if (globaldata->gGroupmap->isValidGroup(globaldata->Groups[i]) != true) {
+                                               cout << globaldata->Groups[i] << " is not a valid group, and will be disregarded." << endl;
+                                               // erase the invalid group from globaldata->Groups
+                                               globaldata->Groups.erase(globaldata->Groups.begin()+i);
+                                       }
+                               }
+                       
+                               //if the user only entered invalid groups
+                               if ((globaldata->Groups.size() == 0) || (globaldata->Groups.size() == 1)) { 
+                                       cout << "When using the groups parameter you must have at least 2 valid groups. I will run the command using all the groups in your groupfile." << endl; 
+                                       for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
+                                               globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
+                                       }
+                               }
+                       }else{//user has enter "all" and wants the default groups
+                               globaldata->Groups.clear();
+                               for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
+                                       globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
+                               }
+                               globaldata->setGroups("");
+                       }
+               }else {
+                       for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
+                               globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
+                       }
+               }
+               
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the CollectSharedCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }               
+
+}
+/***********************************************************/
+