#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 "sharedbdiversity.h"
+#include "sharedochiai.h"
+#include "sharedanderbergs.h"
+#include "sharedkulczynski.h"
+#include "sharedkulczynskicody.h"
+#include "sharedlennon.h"
+#include "sharedmorisitahorn.h"
+#include "sharedbraycurtis.h"
+
//**********************************************************************************************************************
SummarySharedCommand::SummarySharedCommand(){
try {
globaldata = GlobalData::getInstance();
+ outputFileName = ((getRootName(globaldata->inputFileName)) + "shared.summary");
+ openOutputFile(outputFileName, outputFileHandle);
+ format = globaldata->getFormat();
+ validCalculator = new ValidCalculators();
int i;
- for (i=0; i<globaldata->sharedSummaryEstimators.size(); i++) {
- if (globaldata->sharedSummaryEstimators[i] == "sharedSobs") {
- sumCalculators.push_back(new SharedSobsCS());
- }else if (globaldata->sharedSummaryEstimators[i] == "sharedChao") {
- sumCalculators.push_back(new SharedChao1());
- }else if (globaldata->sharedSummaryEstimators[i] == "sharedAce") {
- sumCalculators.push_back(new SharedAce());
- }else if (globaldata->sharedSummaryEstimators[i] == "sharedJabund") {
- sumCalculators.push_back(new SharedJAbund());
- }else if (globaldata->sharedSummaryEstimators[i] == "sharedSorensonAbund") {
- sumCalculators.push_back(new SharedSorAbund());
- }else if (globaldata->sharedSummaryEstimators[i] == "sharedJclass") {
- sumCalculators.push_back(new SharedJclass());
- }else if (globaldata->sharedSummaryEstimators[i] == "sharedSorClass") {
- sumCalculators.push_back(new SharedSorClass());
- }else if (globaldata->sharedSummaryEstimators[i] == "sharedJest") {
- sumCalculators.push_back(new SharedJest());
- }else if (globaldata->sharedSummaryEstimators[i] == "sharedSorEst") {
- sumCalculators.push_back(new SharedSorEst());
- }else if (globaldata->sharedSummaryEstimators[i] == "SharedThetaYC") {
- sumCalculators.push_back(new SharedThetaYC());
- }else if (globaldata->sharedSummaryEstimators[i] == "SharedThetaN") {
- sumCalculators.push_back(new SharedThetaN());
+ for (i=0; i<globaldata->Estimators.size(); i++) {
+ if (validCalculator->isValidCalculator("sharedsummary", globaldata->Estimators[i]) == true) {
+ if (globaldata->Estimators[i] == "sharedsobs") {
+ sumCalculators.push_back(new SharedSobsCS());
+ }else if (globaldata->Estimators[i] == "sharedchao") {
+ sumCalculators.push_back(new SharedChao1());
+ }else if (globaldata->Estimators[i] == "sharedace") {
+ sumCalculators.push_back(new SharedAce());
+ }else if (globaldata->Estimators[i] == "sharedjabund") {
+ sumCalculators.push_back(new SharedJAbund());
+ }else if (globaldata->Estimators[i] == "sharedsorensonabund") {
+ sumCalculators.push_back(new SharedSorAbund());
+ }else if (globaldata->Estimators[i] == "sharedjclass") {
+ sumCalculators.push_back(new SharedJclass());
+ }else if (globaldata->Estimators[i] == "sharedsorclass") {
+ sumCalculators.push_back(new SharedSorClass());
+ }else if (globaldata->Estimators[i] == "sharedjest") {
+ sumCalculators.push_back(new SharedJest());
+ }else if (globaldata->Estimators[i] == "sharedsorest") {
+ sumCalculators.push_back(new SharedSorEst());
+ }else if (globaldata->Estimators[i] == "sharedthetayc") {
+ sumCalculators.push_back(new SharedThetaYC());
+ }else if (globaldata->Estimators[i] == "sharedthetan") {
+ sumCalculators.push_back(new SharedThetaN());
+ }else if (globaldata->Estimators[i] == "sharedkstest") {
+ sumCalculators.push_back(new SharedKSTest());
+ }else if (globaldata->Estimators[i] == "sharednseqs") {
+ sumCalculators.push_back(new SharedNSeqs());
+ }else if (globaldata->Estimators[i] == "sharedochiai") {
+ sumCalculators.push_back(new SharedOchiai());
+ }else if (globaldata->Estimators[i] == "sharedanderberg") {
+ sumCalculators.push_back(new SharedAnderberg());
+ }else if (globaldata->Estimators[i] == "sharedkulczynski") {
+ sumCalculators.push_back(new SharedKulczynski());
+ }else if (globaldata->Estimators[i] == "sharedkulczynskicody") {
+ sumCalculators.push_back(new SharedKulczynskiCody());
+ }else if (globaldata->Estimators[i] == "sharedlennon") {
+ sumCalculators.push_back(new SharedLennon());
+ }else if (globaldata->Estimators[i] == "sharedmorisitahorn") {
+ sumCalculators.push_back(new SharedMorHorn());
+ }else if (globaldata->Estimators[i] == "sharedbraycurtis") {
+ sumCalculators.push_back(new SharedBrayCurtis());
+ }
+ else if (globaldata->Estimators[i] == "sharedbdiversity") {
+ sumCalculators.push_back(new SharedBDiversity());
+ }
+
}
}
+ //reset calc for next command
+ globaldata->setCalc("");
+
}
catch(exception& e) {
cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function SummarySharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
int SummarySharedCommand::execute(){
try {
- outputFileName = ((getRootName(globaldata->inputFileName)) + "shared.summary");
- openOutputFile(outputFileName, outputFileHandle);
-
- read = new ReadPhilFile(globaldata->inputFileName);
- read->read(&*globaldata);
+ int count = 1;
+
+ //if the users entered no valid calculators don't execute command
+ if (sumCalculators.size() == 0) { return 0; }
+
+ if (format == "sharedfile") {
+ read = new ReadPhilFile(globaldata->inputFileName);
+ read->read(&*globaldata);
+
+ input = globaldata->ginput;
+ order = input->getSharedOrderVector();
+ }else {
+ //you are using a list and a groupfile
+ read = new ReadPhilFile(globaldata->inputFileName);
+ read->read(&*globaldata);
+
+ input = globaldata->ginput;
+ SharedList = globaldata->gSharedList;
+ order = SharedList->getSharedOrderVector();
+ }
+
+ //set users groups
+ setGroups();
+ //output estimator names as column headers
outputFileHandle << "label" <<'\t' << "comparison" << '\t';
for(int i=0;i<sumCalculators.size();i++){
outputFileHandle << '\t' << sumCalculators[i]->getName();
}
outputFileHandle << endl;
- SharedList = globaldata->gSharedList;
- input = globaldata->ginput;
- order = SharedList->getSharedOrderVector();
-
- int count = 1;
while(order != NULL){
if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
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' << (lookup[k]->getGroup() + lookup[l]->getGroup()) << '\t' << '\t'; //print out label and group
+ outputFileHandle << order->getLabel() << '\t';
+
+ //sort groups to be alphanumeric
+ if (lookup[k]->getGroup() > lookup[l]->getGroup()) {
+ outputFileHandle << (lookup[l]->getGroup() +'\t' + lookup[k]->getGroup()) << '\t'; //print out groups
+ }else{
+ 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
outputFileHandle << '\t';
}
}
- SharedList = input->getSharedListVector(); //get new list vector to process
- if (SharedList != NULL) {
- order = SharedList->getSharedOrderVector(); //gets new order vector with group info.
- count++;
+ //get next line to process
+ if (format == "sharedfile") {
+ order = input->getSharedOrderVector();
}else {
- break;
+ //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;
+ }
}
+ count++;
}
-
+
+ //reset groups parameter
+ globaldata->Groups.clear(); globaldata->setGroups("");
+
return 0;
}
catch(exception& e) {
try {
lookup.clear();
//create and initialize vector of sharedvectors, one for each group
- for (int i = 0; i < globaldata->gGroupmap->getNumGroups(); i++) {
+ for (int i = 0; i < globaldata->Groups.size(); i++) {
SharedRAbundVector* temp = new SharedRAbundVector(order->getNumBins());
temp->setLabel(order->getLabel());
- temp->setGroup(globaldata->gGroupmap->namesOfGroups[i]);
+ temp->setGroup(globaldata->Groups[i]);
lookup.push_back(temp);
}
break;
}
}
-
}
}
catch(exception& e) {
}
//**********************************************************************************************************************
+void SummarySharedCommand::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 SummarySharedCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the SummarySharedCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+
+}
+/***********************************************************/