From 09a01fb51eea9e81409d367410c831394193fd86 Mon Sep 17 00:00:00 2001 From: westcott Date: Fri, 13 Feb 2009 16:49:49 +0000 Subject: [PATCH] added read.shared, broke up globaldata a bit --- Mothur.xcodeproj/project.pbxproj | 6 + averagelinkage.cpp | 6 + collectcommand.cpp | 45 +++-- collectcommand.h | 2 + collectsharedcommand.cpp | 96 +++++++---- collectsharedcommand.h | 3 + commandfactory.cpp | 2 + errorchecking.cpp | 108 +++--------- errorchecking.h | 9 +- globaldata.cpp | 282 ++++++------------------------- globaldata.hpp | 29 ++-- groupmap.cpp | 13 +- groupmap.h | 4 +- helpcommand.cpp | 76 +++++---- helpcommand.h | 2 + inputdata.cpp | 35 +++- inputdata.h | 3 + rarefactcommand.cpp | 48 +++--- rarefactcommand.h | 2 + rarefactsharedcommand.cpp | 55 ++++-- rarefactsharedcommand.h | 3 + readmatrix.cpp | 4 +- readsharedcommand.cpp | 52 ++++++ readsharedcommand.h | 40 +++++ sharedlistvector.cpp | 5 +- sharedordervector.cpp | 79 +++++++-- sharedordervector.h | 6 +- sharedrabundvector.cpp | 5 +- sharedsobscollectsummary.h | 1 + summarycommand.cpp | 46 +++-- summarycommand.h | 2 + summarysharedcommand.cpp | 105 +++++++----- summarysharedcommand.h | 4 +- tree.h | 8 - utilities.hpp | 131 ++++++++++++++ validcalculator.cpp | 93 ++++++---- validcalculator.h | 2 + validcommands.cpp | 28 ++- validcommands.h | 2 + validparameter.cpp | 8 +- validparameter.h | 1 + 41 files changed, 858 insertions(+), 593 deletions(-) create mode 100644 readsharedcommand.cpp create mode 100644 readsharedcommand.h diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj index d678294..c3c2a72 100644 --- a/Mothur.xcodeproj/project.pbxproj +++ b/Mothur.xcodeproj/project.pbxproj @@ -21,6 +21,7 @@ 37AD4DBB0F28E2FE00AA2D49 /* tree.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37AD4DBA0F28E2FE00AA2D49 /* tree.cpp */; }; 37AD4DCA0F28F3DD00AA2D49 /* readtree.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37AD4DC90F28F3DD00AA2D49 /* readtree.cpp */; }; 37AFC71F0F445386005F492D /* sharedsobscollectsummary.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37AFC71E0F445386005F492D /* sharedsobscollectsummary.cpp */; }; + 37AFC7A30F44703E005F492D /* readsharedcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37AFC7A20F44703E005F492D /* readsharedcommand.cpp */; }; 37B28F680F27590100808A62 /* deconvolutecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37B28F670F27590100808A62 /* deconvolutecommand.cpp */; }; 37D928550F21331F001D4494 /* ace.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927B80F21331F001D4494 /* ace.cpp */; }; 37D928560F21331F001D4494 /* averagelinkage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927BA0F21331F001D4494 /* averagelinkage.cpp */; }; @@ -137,6 +138,8 @@ 37AD4DC90F28F3DD00AA2D49 /* readtree.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readtree.cpp; sourceTree = ""; }; 37AFC71D0F445386005F492D /* sharedsobscollectsummary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedsobscollectsummary.h; sourceTree = ""; }; 37AFC71E0F445386005F492D /* sharedsobscollectsummary.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedsobscollectsummary.cpp; sourceTree = ""; }; + 37AFC7A10F44703E005F492D /* readsharedcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readsharedcommand.h; sourceTree = ""; }; + 37AFC7A20F44703E005F492D /* readsharedcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readsharedcommand.cpp; sourceTree = ""; }; 37B28F660F27590100808A62 /* deconvolutecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = deconvolutecommand.h; sourceTree = ""; }; 37B28F670F27590100808A62 /* deconvolutecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = deconvolutecommand.cpp; sourceTree = ""; }; 37D927B80F21331F001D4494 /* ace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ace.cpp; sourceTree = ""; }; @@ -472,6 +475,8 @@ 372E12950F263D5A0095CF7E /* readdistcommand.cpp */, 372E126E0F26365B0095CF7E /* readotucommand.h */, 372E126F0F26365B0095CF7E /* readotucommand.cpp */, + 37AFC7A10F44703E005F492D /* readsharedcommand.h */, + 37AFC7A20F44703E005F492D /* readsharedcommand.cpp */, 37E5F4900F2A3DA800F8D827 /* readtreecommand.h */, 37E5F4910F2A3DA800F8D827 /* readtreecommand.cpp */, 37D928270F21331F001D4494 /* sharedcommand.h */, @@ -673,6 +678,7 @@ 374610830F40652400460C57 /* unweighted.cpp in Sources */, 3746109D0F40657600460C57 /* unifracunweightedcommand.cpp in Sources */, 37AFC71F0F445386005F492D /* sharedsobscollectsummary.cpp in Sources */, + 37AFC7A30F44703E005F492D /* readsharedcommand.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/averagelinkage.cpp b/averagelinkage.cpp index 1ab5160..43b3e5b 100644 --- a/averagelinkage.cpp +++ b/averagelinkage.cpp @@ -1,3 +1,5 @@ +#ifndef AVERAGE_H +#define AVERAGE_H #include "cluster.hpp" #include "rabundvector.hpp" @@ -76,3 +78,7 @@ void AverageLinkage::update(){ } /***********************************************************************/ + +#endif + + diff --git a/collectcommand.cpp b/collectcommand.cpp index 4687c6e..0f622c4 100644 --- a/collectcommand.cpp +++ b/collectcommand.cpp @@ -27,25 +27,32 @@ CollectCommand::CollectCommand(){ string fileNameRoot; fileNameRoot = getRootName(globaldata->inputFileName); int i; - for (i=0; isingleEstimators.size(); i++) { - if (globaldata->singleEstimators[i] == "sobs") { - cDisplays.push_back(new CollectDisplay(new Sobs(), new OneColumnFile(fileNameRoot+"sobs"))); - }else if (globaldata->singleEstimators[i] == "chao") { - cDisplays.push_back(new CollectDisplay(new Chao1(), new ThreeColumnFile(fileNameRoot+"chao"))); - }else if (globaldata->singleEstimators[i] == "ace") { - cDisplays.push_back(new CollectDisplay(new Ace(), new ThreeColumnFile(fileNameRoot+"ace"))); - }else if (globaldata->singleEstimators[i] == "jack") { - cDisplays.push_back(new CollectDisplay(new Jackknife(), new ThreeColumnFile(fileNameRoot+"jack"))); - }else if (globaldata->singleEstimators[i] == "shannon") { - cDisplays.push_back(new CollectDisplay(new Shannon(), new ThreeColumnFile(fileNameRoot+"shannon"))); - }else if (globaldata->singleEstimators[i] == "npshannon") { - cDisplays.push_back(new CollectDisplay(new NPShannon(), new OneColumnFile(fileNameRoot+"np_shannon"))); - }else if (globaldata->singleEstimators[i] == "simpson") { - cDisplays.push_back(new CollectDisplay(new Simpson(), new ThreeColumnFile(fileNameRoot+"simpson"))); - }else if (globaldata->singleEstimators[i] == "bootstrap") { - cDisplays.push_back(new CollectDisplay(new Bootstrap(), new OneColumnFile(fileNameRoot+"bootstrap"))); + validCalculator = new ValidCalculators(); + + for (i=0; iEstimators.size(); i++) { + if (validCalculator->isValidCalculator("single", globaldata->Estimators[i]) == true) { + if (globaldata->Estimators[i] == "sobs") { + cDisplays.push_back(new CollectDisplay(new Sobs(), new OneColumnFile(fileNameRoot+"sobs"))); + }else if (globaldata->Estimators[i] == "chao") { + cDisplays.push_back(new CollectDisplay(new Chao1(), new ThreeColumnFile(fileNameRoot+"chao"))); + }else if (globaldata->Estimators[i] == "ace") { + cDisplays.push_back(new CollectDisplay(new Ace(), new ThreeColumnFile(fileNameRoot+"ace"))); + }else if (globaldata->Estimators[i] == "jack") { + cDisplays.push_back(new CollectDisplay(new Jackknife(), new ThreeColumnFile(fileNameRoot+"jack"))); + }else if (globaldata->Estimators[i] == "shannon") { + cDisplays.push_back(new CollectDisplay(new Shannon(), new ThreeColumnFile(fileNameRoot+"shannon"))); + }else if (globaldata->Estimators[i] == "npshannon") { + cDisplays.push_back(new CollectDisplay(new NPShannon(), new OneColumnFile(fileNameRoot+"np_shannon"))); + }else if (globaldata->Estimators[i] == "simpson") { + cDisplays.push_back(new CollectDisplay(new Simpson(), new ThreeColumnFile(fileNameRoot+"simpson"))); + }else if (globaldata->Estimators[i] == "bootstrap") { + cDisplays.push_back(new CollectDisplay(new Bootstrap(), new OneColumnFile(fileNameRoot+"bootstrap"))); + } } } + + //reset calc for next command + globaldata->setCalc(""); } catch(exception& e) { cout << "Standard Error: " << e.what() << " has occurred in the CollectCommand class Function CollectCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; @@ -72,6 +79,10 @@ CollectCommand::~CollectCommand(){ int CollectCommand::execute(){ try { int count = 1; + + //if the users entered no valid calculators don't execute command + if (cDisplays.size() == 0) { return 0; } + read = new ReadPhilFile(globaldata->inputFileName); read->read(&*globaldata); diff --git a/collectcommand.h b/collectcommand.h index b92b350..686c491 100644 --- a/collectcommand.h +++ b/collectcommand.h @@ -19,6 +19,7 @@ #include "collect.h" #include "display.h" #include "readmatrix.hpp" +#include "validcalculator.h" /*The collect() command: The collect command generates a collector's curve from the given file. @@ -49,6 +50,7 @@ private: OrderVector* order; InputData* input; Collect* cCurve; + ValidCalculators* validCalculator; vector cDisplays; int freq; diff --git a/collectsharedcommand.cpp b/collectsharedcommand.cpp index a6479da..217045a 100644 --- a/collectsharedcommand.cpp +++ b/collectsharedcommand.cpp @@ -28,34 +28,41 @@ CollectSharedCommand::CollectSharedCommand(){ globaldata = GlobalData::getInstance(); string fileNameRoot; fileNameRoot = getRootName(globaldata->inputFileName); - //groupmap = globaldata->gGroupmap; + format = globaldata->getFormat(); + validCalculator = new ValidCalculators(); int i; - for (i=0; isharedEstimators.size(); i++) { - if (globaldata->sharedEstimators[i] == "sharedChao") { - cDisplays.push_back(new CollectDisplay(new SharedChao1(), new SharedOneColumnFile(fileNameRoot+"shared.chao"))); - }else if (globaldata->sharedEstimators[i] == "sharedSobs") { - cDisplays.push_back(new CollectDisplay(new SharedSobsCS(), new SharedOneColumnFile(fileNameRoot+"shared.sobs"))); - }else if (globaldata->sharedEstimators[i] == "sharedAce") { - cDisplays.push_back(new CollectDisplay(new SharedAce(), new SharedOneColumnFile(fileNameRoot+"shared.ace"))); - }else if (globaldata->sharedEstimators[i] == "sharedJabund") { - cDisplays.push_back(new CollectDisplay(new SharedJAbund(), new SharedOneColumnFile(fileNameRoot+"shared.jabund"))); - }else if (globaldata->sharedEstimators[i] == "sharedSorensonAbund") { - cDisplays.push_back(new CollectDisplay(new SharedSorAbund(), new SharedOneColumnFile(fileNameRoot+"shared.sorabund"))); - }else if (globaldata->sharedEstimators[i] == "sharedJclass") { - cDisplays.push_back(new CollectDisplay(new SharedJclass(), new SharedOneColumnFile(fileNameRoot+"shared.jclass"))); - }else if (globaldata->sharedEstimators[i] == "sharedSorClass") { - cDisplays.push_back(new CollectDisplay(new SharedSorClass(), new SharedOneColumnFile(fileNameRoot+"shared.sorclass"))); - }else if (globaldata->sharedEstimators[i] == "sharedJest") { - cDisplays.push_back(new CollectDisplay(new SharedJest(), new SharedOneColumnFile(fileNameRoot+"shared.jest"))); - }else if (globaldata->sharedEstimators[i] == "sharedSorEst") { - cDisplays.push_back(new CollectDisplay(new SharedSorEst(), new SharedOneColumnFile(fileNameRoot+"shared.sorest"))); - }else if (globaldata->sharedEstimators[i] == "SharedThetaYC") { - cDisplays.push_back(new CollectDisplay(new SharedThetaYC(), new SharedOneColumnFile(fileNameRoot+"shared.thetayc"))); - }else if (globaldata->sharedEstimators[i] == "SharedThetaN") { - cDisplays.push_back(new CollectDisplay(new SharedThetaN(), new SharedOneColumnFile(fileNameRoot+"shared.thetan"))); + for (i=0; iEstimators.size(); i++) { + if (validCalculator->isValidCalculator("shared", globaldata->Estimators[i]) == true) { + if (globaldata->Estimators[i] == "sharedchao") { + cDisplays.push_back(new CollectDisplay(new SharedChao1(), new SharedOneColumnFile(fileNameRoot+"shared.chao"))); + }else if (globaldata->Estimators[i] == "sharedsobs") { + cDisplays.push_back(new CollectDisplay(new SharedSobsCS(), new SharedOneColumnFile(fileNameRoot+"shared.sobs"))); + }else if (globaldata->Estimators[i] == "sharedace") { + cDisplays.push_back(new CollectDisplay(new SharedAce(), new SharedOneColumnFile(fileNameRoot+"shared.ace"))); + }else if (globaldata->Estimators[i] == "sharedjabund") { + cDisplays.push_back(new CollectDisplay(new SharedJAbund(), new SharedOneColumnFile(fileNameRoot+"shared.jabund"))); + }else if (globaldata->Estimators[i] == "sharedsorensonabund") { + cDisplays.push_back(new CollectDisplay(new SharedSorAbund(), new SharedOneColumnFile(fileNameRoot+"shared.sorabund"))); + }else if (globaldata->Estimators[i] == "sharedjclass") { + cDisplays.push_back(new CollectDisplay(new SharedJclass(), new SharedOneColumnFile(fileNameRoot+"shared.jclass"))); + }else if (globaldata->Estimators[i] == "sharedsorclass") { + cDisplays.push_back(new CollectDisplay(new SharedSorClass(), new SharedOneColumnFile(fileNameRoot+"shared.sorclass"))); + }else if (globaldata->Estimators[i] == "sharedjest") { + cDisplays.push_back(new CollectDisplay(new SharedJest(), new SharedOneColumnFile(fileNameRoot+"shared.jest"))); + }else if (globaldata->Estimators[i] == "sharedsorest") { + cDisplays.push_back(new CollectDisplay(new SharedSorEst(), new SharedOneColumnFile(fileNameRoot+"shared.sorest"))); + }else if (globaldata->Estimators[i] == "sharedthetayc") { + 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"))); + } } } + + //reset calc for next command + globaldata->setCalc(""); + } catch(exception& e) { cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function CollectSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; @@ -82,12 +89,25 @@ CollectSharedCommand::~CollectSharedCommand(){ int CollectSharedCommand::execute(){ try { int count = 1; - read = new ReadPhilFile(globaldata->inputFileName); - read->read(&*globaldata); - input = globaldata->ginput; - SharedList = globaldata->gSharedList; - order = SharedList->getSharedOrderVector(); + //if the users entered no valid calculators don't execute command + if (cDisplays.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(); + } while(order != NULL){ @@ -102,14 +122,20 @@ int CollectSharedCommand::execute(){ cout << order->getLabel() << '\t' << count << endl; } - 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++; } for(int i=0;i cDisplays; int freq; + string format; }; diff --git a/commandfactory.cpp b/commandfactory.cpp index dbcfb54..0c1b3e0 100644 --- a/commandfactory.cpp +++ b/commandfactory.cpp @@ -10,6 +10,7 @@ #include "command.hpp" #include "readdistcommand.h" #include "readtreecommand.h" +#include "readsharedcommand.h" #include "readotucommand.h" #include "clustercommand.h" #include "parselistcommand.h" @@ -55,6 +56,7 @@ Command* CommandFactory::getCommand(string commandName){ if(commandName == "read.dist") { command = new ReadDistCommand(); } else if(commandName == "read.otu") { command = new ReadOtuCommand(); } else if(commandName == "read.tree") { command = new ReadTreeCommand(); } + else if(commandName == "read.shared") { command = new ReadSharedCommand(); } else if(commandName == "cluster") { command = new ClusterCommand(); } else if(commandName == "deconvolute") { command = new DeconvoluteCommand(); } else if(commandName == "parsimony") { command = new ParsimonyCommand(); } diff --git a/errorchecking.cpp b/errorchecking.cpp index 067d246..8556c27 100644 --- a/errorchecking.cpp +++ b/errorchecking.cpp @@ -17,7 +17,6 @@ ErrorCheck::ErrorCheck() { globaldata = GlobalData::getInstance(); validCommand = new ValidCommands(); validParameter = new ValidParameters(); - validCalculator = new ValidCalculators(); } /*******************************************************/ @@ -38,6 +37,7 @@ void ErrorCheck::refresh() { format = globaldata->getFormat(); method = globaldata->getMethod(); randomtree = globaldata->getRandomTree(); + sharedfile = globaldata->getSharedFile(); } /*******************************************************/ @@ -76,8 +76,8 @@ bool ErrorCheck::checkInput(string input) { //reads in parameters and values if((optionText != "") && (commandName != "help")){ while((optionText.find_first_of(',') != -1) && (errorFree)) { //while there are parameters - globaldata->splitAtComma(value, optionText); - globaldata->splitAtEquals(parameter, value); + splitAtComma(value, optionText); + splitAtEquals(parameter, value); //is it a valid parameter if (validParameter->isValidParameter(parameter) != true) { return false; } @@ -92,6 +92,7 @@ bool ErrorCheck::checkInput(string input) { if (parameter == "fasta" ) { fastafile = value; } if (parameter == "tree" ) { treefile = value; } if (parameter == "group" ) { groupfile = value; } + if (parameter == "shared" ) { sharedfile = value; } if (parameter == "cutoff" ) { cutoff = value; } if (parameter == "precision" ) { precision = value; } if (parameter == "iters" ) { iters = value; } @@ -103,52 +104,12 @@ bool ErrorCheck::checkInput(string input) { if (parameter == "label" ) { label = value; } if (parameter == "randomtree" ) { randomtree = value; } - if (parameter == "single") {//stores estimators in a vector - singleEsimators.clear(); //clears out old values - globaldata->splitAtDash(value, singleEsimators); - for (int i = 0; i < singleEsimators.size(); i++) { //loop through estimators - //is it a valid calculator - if (validCalculator->isValidCalculator(parameter, singleEsimators[i]) != true) { return false; } - } - } - if (parameter == "rarefaction") {//stores estimators in a vector - rareEstimators.clear(); //clears out old values - globaldata->splitAtDash(value, rareEstimators); - for (int i = 0; i < rareEstimators.size(); i++) { //loop through estimators - //is it a valid calculator - if (validCalculator->isValidCalculator(parameter, rareEstimators[i]) != true) { return false; } - } - } - if (parameter == "shared") {//stores estimators in a vector - sharedEstimators.clear(); //clears out old values - globaldata->splitAtDash(value, sharedEstimators); - for (int i = 0; i < sharedEstimators.size(); i++) { //loop through estimators - //is it a valid calculator - if (validCalculator->isValidCalculator(parameter, sharedEstimators[i]) != true) { return false; } - } - } - if (parameter == "summary") { //stores summaries to be used in a vector - summaryEstimators.clear(); //clears out old values - globaldata->splitAtDash(value, summaryEstimators); - for (int i = 0; i < summaryEstimators.size(); i++) { //loop through estimators - //is it a valid calculator - if (validCalculator->isValidCalculator(parameter, summaryEstimators[i]) != true) { return false; } - } - } - if (parameter == "sharedrarefaction") { //stores summaries to be used in a vector - sharedRareEstimators.clear(); //clears out old values - globaldata->splitAtDash(value, sharedRareEstimators); - for (int i = 0; i < sharedRareEstimators.size(); i++) { //loop through estimators - //is it a valid calculator - if (validCalculator->isValidCalculator(parameter, sharedRareEstimators[i]) != true) { return false; } - } - } } //gets the last parameter and value if (errorFree) { //gets the last parameter and value value = optionText; - globaldata->splitAtEquals(parameter, value); + splitAtEquals(parameter, value); //is it a valid parameter if (validParameter->isValidParameter(parameter) != true) { return false; } @@ -160,6 +121,7 @@ bool ErrorCheck::checkInput(string input) { if (parameter == "name" ) { namefile = value; } if (parameter == "order" ) { orderfile = value; } if (parameter == "group" ) { groupfile = value; } + if (parameter == "shared" ) { sharedfile = value; } if (parameter == "fasta" ) { fastafile = value; } if (parameter == "tree" ) { treefile = value; } if (parameter == "cutoff" ) { cutoff = value; } @@ -173,47 +135,6 @@ bool ErrorCheck::checkInput(string input) { if (parameter == "label" ) { label = value; } if (parameter == "randomtree" ) { randomtree = value; } - if (parameter == "single") {//stores estimators in a vector - singleEsimators.clear(); //clears out old values - globaldata->splitAtDash(value, singleEsimators); - for (int i = 0; i < singleEsimators.size(); i++) { //loop through estimators - //is it a valid calculator - if (validCalculator->isValidCalculator(parameter, singleEsimators[i]) != true) { return false; } - } - } - if (parameter == "rarefaction") {//stores estimators in a vector - rareEstimators.clear(); //clears out old values - globaldata->splitAtDash(value, rareEstimators); - for (int i = 0; i < rareEstimators.size(); i++) { //loop through estimators - //is it a valid calculator - if (validCalculator->isValidCalculator(parameter, rareEstimators[i]) != true) { return false; } - } - } - if (parameter == "shared") {//stores estimators in a vector - sharedEstimators.clear(); //clears out old values - globaldata->splitAtDash(value, sharedEstimators); - for (int i = 0; i < sharedEstimators.size(); i++) { //loop through estimators - //is it a valid calculator - if (validCalculator->isValidCalculator(parameter, sharedEstimators[i]) != true) { return false; } - } - } - if (parameter == "summary") { //stores summaries to be used in a vector - summaryEstimators.clear(); //clears out old values - globaldata->splitAtDash(value, summaryEstimators); - for (int i = 0; i < summaryEstimators.size(); i++) { //loop through estimators - //is it a valid calculator - if (validCalculator->isValidCalculator(parameter, summaryEstimators[i]) != true) { return false; } - } - } - if (parameter == "sharedrarefaction") { //stores summaries to be used in a vector - sharedRareEstimators.clear(); //clears out old values - globaldata->splitAtDash(value, sharedRareEstimators); - for (int i = 0; i < sharedRareEstimators.size(); i++) { //loop through estimators - //is it a valid calculator - if (validCalculator->isValidCalculator(parameter, sharedRareEstimators[i]) != true) { return false; } - } - } - } } @@ -232,6 +153,9 @@ bool ErrorCheck::checkInput(string input) { validateReadFiles(); validateReadPhil(); } + }else if (commandName == "read.shared") { + //you want to do shared commands with just the shared file + validateReadFiles(); }else if (commandName == "read.tree") { validateTreeFiles(); //checks the treefile and groupfile parameters }else if (commandName == "deconvolute") { @@ -270,11 +194,12 @@ bool ErrorCheck::checkInput(string input) { } if ((commandName == "collect.shared") || (commandName == "rarefaction.shared") || (commandName == "summary.shared") ){ - if (globaldata->getListFile() == "") { cout << "You must read a list and a group before you can use the collect.shared, rarefaction.shared or summary.shared commands." << endl; return false; } - else if (globaldata->getGroupFile() == "") { cout << "You must read a list and a group before you can use the collect.shared, rarefaction.shared or summary.shared commands." << endl; return false; } + if (globaldata->getSharedFile() == "") { + if (globaldata->getListFile() == "") { cout << "You must read a list and a group, or a shared before you can use the collect.shared, rarefaction.shared or summary.shared commands." << endl; return false; } + else if (globaldata->getGroupFile() == "") { cout << "You must read a list and a group, or a shared before you can use the collect.shared, rarefaction.shared or summary.shared commands." << endl; return false; } + } } - return errorFree; } @@ -330,6 +255,12 @@ void ErrorCheck::validateReadFiles() { //unable to open if (ableToOpen == 1) { errorFree = false; } else { globaldata->inputFileName = fastafile; } + }else if (sharedfile != "") { + ableToOpen = openInputFile(sharedfile, filehandle); + filehandle.close(); + //unable to open + if (ableToOpen == 1) { errorFree = false; } + else { globaldata->inputFileName = sharedfile; } }else{ //no file given errorFree = false; } @@ -515,6 +446,7 @@ void ErrorCheck::clear() { namefile = ""; groupfile = ""; orderfile = ""; + sharedfile = ""; line = ""; label = ""; method = "furthest"; diff --git a/errorchecking.h b/errorchecking.h index 9387bc5..1b023e0 100644 --- a/errorchecking.h +++ b/errorchecking.h @@ -14,7 +14,7 @@ #include "globaldata.hpp" #include "validcommands.h" #include "validparameter.h" -#include "validcalculator.h" +#include "utilities.hpp" class ErrorCheck { public: @@ -26,10 +26,6 @@ class ErrorCheck { GlobalData* globaldata; ValidCommands* validCommand; ValidParameters* validParameter; - ValidCalculators* validCalculator; - void splitAtDash(string&, vector&); - void splitAtDash(string&, set&); - void splitAtDash(string&, set&); void validateReadFiles(); void validateReadDist(); void validateReadPhil(); @@ -37,11 +33,10 @@ class ErrorCheck { void validateTreeFiles(); void clear(); void refresh(); - string phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, orderfile, fastafile, treefile, cutoff, format; + string phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, orderfile, fastafile, treefile, sharedfile, cutoff, format; string precision, method, fileroot, label, line, iters, jumble, freq, single, rarefaction, shared, summary, randomtree; string commandName, optionText; bool errorFree; - vector singleEsimators, sharedEstimators, rareEstimators, summaryEstimators, sharedRareEstimators; }; #endif diff --git a/globaldata.cpp b/globaldata.cpp index e58d191..0348ae6 100644 --- a/globaldata.cpp +++ b/globaldata.cpp @@ -1,20 +1,9 @@ -#include -#include -#include -#include -#include -#include - -using namespace std; - #include "globaldata.hpp" #include "sparsematrix.hpp" #include "tree.h" #include "rabundvector.hpp" #include "sabundvector.hpp" #include "listvector.hpp" -#include -#include /*******************************************************/ @@ -47,7 +36,6 @@ void GlobalData::setListVector(ListVector* lv){ exit(1); } } - /*******************************************************/ /******************************************************/ @@ -69,7 +57,6 @@ void GlobalData::setSparseMatrix(SparseMatrix* sm){ cout << "An unknown error has occurred in the GlobalData class function setSparseMatrix. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; exit(1); } - } /*******************************************************/ @@ -80,9 +67,13 @@ void GlobalData::parseGlobalData(string commandString, string optionText){ allLines = 1; commandName = commandString; //save command name to be used by other classes + //set all non filename paramters to default values + reset(); + //clears out data from previous read - if ((commandName == "read.dist") || (commandName == "read.otu") || (commandName == "read.tree")) { + if ((commandName == "read.dist") || (commandName == "read.otu") || (commandName == "read.tree") || (commandName == "read.shared")) { clear(); + gGroupmap = NULL; } //saves help request @@ -104,6 +95,7 @@ void GlobalData::parseGlobalData(string commandString, string optionText){ if (key == "sabund" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; } if (key == "fasta" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; } if (key == "tree" ) { treefile = value; inputFileName = value; fileroot = value; format = "tree"; } + if (key == "shared" ) { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile"; } if (key == "name" ) { namefile = value; } if (key == "order" ) { orderfile = value; } if (key == "group" ) { groupfile = value; } @@ -116,37 +108,8 @@ void GlobalData::parseGlobalData(string commandString, string optionText){ if (key == "fileroot" ) { fileroot = value; } if (key == "randomtree" ) { randomtree = value; } if (key == "groups" ) { groups = value; } + if (key == "calc") { calc = value; } - if (key == "single") {//stores estimators in a vector - singleEstimators.clear(); //clears out old values - if (value == "default") { value = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-rarefraction"; } - splitAtDash(value, singleEstimators); - } - if (key == "rarefaction") {//stores estimators in a vector - rareEstimators.clear(); //clears out old values - if (value == "default") { value = "rarefraction"; } - splitAtDash(value, rareEstimators); - } - if (key == "shared") {//stores estimators in a vector - sharedEstimators.clear(); //clears out old values - if (value == "default") { value = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; } - splitAtDash(value, sharedEstimators); - } - if (key == "summary") { //stores summaries to be used in a vector - summaryEstimators.clear(); - if (value == "default") { value = "summary-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; } - splitAtDash(value, summaryEstimators); - } - if (key == "sharedsummary") { //stores sharedSummaries to be used in a vector - sharedSummaryEstimators.clear(); - if (value == "default") { value = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; } - splitAtDash(value, sharedSummaryEstimators); - } - if (key == "sharedrarefaction") { //stores sharedrarefaction to be used in a vector - sharedRareEstimators.clear(); - if (value == "default") { value = "sharedobserved"; } - splitAtDash(value, sharedRareEstimators); - } if (key == "line") {//stores lines to be used in a set lines.clear(); line = value; @@ -166,7 +129,6 @@ void GlobalData::parseGlobalData(string commandString, string optionText){ groups = value; splitAtDash(value, Groups); } - } //saves the last parameter @@ -178,7 +140,8 @@ void GlobalData::parseGlobalData(string commandString, string optionText){ if (key == "rabund" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; } if (key == "sabund" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; } if (key == "fasta" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; } - if (key == "tree" ) { treefile = value; inputFileName = value; fileroot = value; format = "tree"; } + if (key == "tree" ) { treefile = value; inputFileName = value; fileroot = value; format = "tree"; } + if (key == "shared" ) { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile"; } if (key == "name" ) { namefile = value; } if (key == "order" ) { orderfile = value; } if (key == "group" ) { groupfile = value; } @@ -191,39 +154,9 @@ void GlobalData::parseGlobalData(string commandString, string optionText){ if (key == "fileroot" ) { fileroot = value; } if (key == "randomtree" ) { randomtree = value; } if (key == "groups" ) { groups = value; } + if (key == "calc") { calc = value; } + - - if (key == "single") {//stores estimators in a vector - singleEstimators.clear(); //clears out old values - if (value == "default") { value = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-rarefraction"; } - splitAtDash(value, singleEstimators); - } - if (key == "rarefaction") {//stores estimators in a vector - rareEstimators.clear(); //clears out old values - if (value == "default") { value = "rarefraction"; } - splitAtDash(value, rareEstimators); - } - if (key == "shared") {//stores estimators in a vector - sharedEstimators.clear(); //clears out old values - if (value == "default") { value = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; } - splitAtDash(value, sharedEstimators); - } - if (key == "summary") { //stores summaries to be used in a vector - summaryEstimators.clear(); - if (value == "default") { value = "summary-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; } - splitAtDash(value, summaryEstimators); - } - if (key == "sharedsummary") { //stores sharedSummaries to be used in a vector - sharedSummaryEstimators.clear(); - if (value == "default") { value = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; } - splitAtDash(value, sharedSummaryEstimators); - } - if (key == "sharedrarefaction") { //stores sharedrarefaction to be used in a vector - sharedRareEstimators.clear(); - if (value == "default") { value = "sharedobserved"; } - splitAtDash(value, sharedRareEstimators); - } - if (key == "line") {//stores lines to be used in a vector lines.clear(); line = value; @@ -243,40 +176,49 @@ void GlobalData::parseGlobalData(string commandString, string optionText){ groups = value; splitAtDash(value, Groups); } - } //set format for shared if ((listfile != "") && (groupfile != "")) { format = "shared"; } - //input defaults + //input defaults for calculators if (commandName == "collect.single") { - if (singleEstimators.size() == 0) { splitAtDash(single, singleEstimators); } + if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; } + Estimators.clear(); + splitAtDash(calc, Estimators); } if (commandName == "rarefaction.single") { - if (rareEstimators.size() == 0) { splitAtDash(rarefaction, rareEstimators); } + if ((calc == "default") || (calc == "")) { calc = "sobs"; } + Estimators.clear(); + splitAtDash(calc, Estimators); } if (commandName == "collect.shared") { - if (sharedEstimators.size() == 0) { splitAtDash(shared, sharedEstimators); } + if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-sharedjabund-sharedsorensonabund-sharedjclass-sharedsorclass-sharedjest-sharedsorest-sharedthetayc-sharedthetan"; } + Estimators.clear(); + splitAtDash(calc, Estimators); } if (commandName == "summary.single") { - if (summaryEstimators.size() == 0) { splitAtDash(summary, summaryEstimators); } + if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; } + Estimators.clear(); + splitAtDash(calc, Estimators); } if (commandName == "summary.shared") { - if (sharedSummaryEstimators.size() == 0) { splitAtDash(sharedsummary, sharedSummaryEstimators); } + if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-sharedjabund-sharedsorensonabund-sharedjclass-sharedsorclass-sharedjest-sharedsorest-sharedthetayc-sharedthetan"; } + Estimators.clear(); + splitAtDash(calc, Estimators); } if (commandName == "rarefaction.shared") { - if (sharedRareEstimators.size() == 0) { splitAtDash(sharedrarefaction, sharedRareEstimators); } + if ((calc == "default") || (calc == "")) { calc = "sharedobserved"; } + Estimators.clear(); + splitAtDash(calc, Estimators); } - //if you have done a read.otu with a groupfile but don't want to use it anymore because you want to do single commands if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single")) { if (listfile != "") { format = "list"; } else if (sabundfile != "") { format = "sabund"; } else if (rabundfile != "") { format = "rabund"; } } - } catch(exception& e) { cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; @@ -286,7 +228,6 @@ void GlobalData::parseGlobalData(string commandString, string optionText){ cout << "An unknown error has occurred in the GlobalData class function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; exit(1); } - } /*******************************************************/ @@ -301,6 +242,7 @@ string GlobalData::getNameFile() { return namefile; } string GlobalData::getGroupFile() { return groupfile; } string GlobalData::getOrderFile() { return orderfile; } string GlobalData::getTreeFile() { return treefile; } +string GlobalData::getSharedFile() { return sharedfile; } string GlobalData::getFastaFile() { return fastafile; } string GlobalData::getCutOff() { return cutoff; } string GlobalData::getFormat() { return format; } @@ -316,16 +258,14 @@ void GlobalData::setRabundFile(string file) { rabundfile = file; inputFileName = void GlobalData::setSabundFile(string file) { sabundfile = file; inputFileName = file;} void GlobalData::setPhylipFile(string file) { phylipfile = file; inputFileName = file;} void GlobalData::setColumnFile(string file) { columnfile = file; inputFileName = file;} -//void GlobalData::setGroupFile(string file) { groupfile = file; } void GlobalData::setNameFile(string file) { namefile = file; } void GlobalData::setFormat(string Format) { format = Format; } void GlobalData::setRandomTree(string Random) { randomtree = Random; } - +void GlobalData::setCalc(string Calc) { calc = Calc; } /*******************************************************/ /******************************************************/ - GlobalData::GlobalData() { //option definitions should go here... helpRequest = ""; @@ -334,7 +274,6 @@ GlobalData::GlobalData() { /*******************************************************/ /******************************************************/ - void GlobalData::clear() { //option definitions should go here... phylipfile = ""; @@ -347,6 +286,7 @@ void GlobalData::clear() { orderfile = ""; fastafile = ""; treefile = ""; + sharedfile = ""; cutoff = "10.00"; format = ""; precision = "100"; @@ -359,17 +299,27 @@ void GlobalData::clear() { freq = "100"; method = "furthest"; fileroot = ""; - single = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-rarefraction"; - rarefaction = "sobs"; - shared = "sharedSobs-sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; - sharedsummary = "sharedSobs-sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; - summary = "summary-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; - sharedrarefaction = "sharedobserved"; + calc = ""; } /*******************************************************/ /******************************************************/ +void GlobalData::reset() { + cutoff = "10.00"; + precision = "100"; + iters = "1000"; + line = ""; + label = ""; + groups = ""; + jumble = "1"; //0 means don't jumble, 1 means jumble. + randomtree = "0"; //0 means user will enter some user trees, 1 means they just want the random tree distribution. + freq = "100"; + method = "furthest"; + calc = ""; +} +/*******************************************************/ +/******************************************************/ GlobalData::~GlobalData() { _uniqueInstance = 0; if(gListVector != NULL) { delete gListVector; } @@ -378,139 +328,5 @@ GlobalData::~GlobalData() { } /*******************************************************/ -/******************************************************/ -//This function parses the estimator options and puts them in a vector -void GlobalData::splitAtDash(string& estim, vector& container) { - try { - string individual; - - while (estim.find_first_of('-') != -1) { - individual = estim.substr(0,estim.find_first_of('-')); - if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string - estim = estim.substr(estim.find_first_of('-')+1, estim.length()); - container.push_back(individual); - } - } - //get last one - container.push_back(estim); - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the GlobalData class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - -} -/*******************************************************/ - -/******************************************************/ -//This function parses the label options and puts them in a set -void GlobalData::splitAtDash(string& estim, set& container) { - try { - string individual; - - while (estim.find_first_of('-') != -1) { - individual = estim.substr(0,estim.find_first_of('-')); - if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string - estim = estim.substr(estim.find_first_of('-')+1, estim.length()); - container.insert(individual); - } - } - //get last one - container.insert(estim); - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the GlobalData class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - -} -/*******************************************************/ - -/******************************************************/ -//This function parses the line options and puts them in a set -void GlobalData::splitAtDash(string& estim, set& container) { - try { - string individual; - int lineNum; - - while (estim.find_first_of('-') != -1) { - individual = estim.substr(0,estim.find_first_of('-')); - if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string - estim = estim.substr(estim.find_first_of('-')+1, estim.length()); - convert(individual, lineNum); //convert the string to int - container.insert(lineNum); - } - } - //get last one - convert(estim, lineNum); //convert the string to int - container.insert(lineNum); - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the GlobalData class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - -} -/*******************************************************/ - /******************************************************/ -//This function splits up the various option parameters -void GlobalData::splitAtComma(string& prefix, string& suffix){ - try { - prefix = suffix.substr(0,suffix.find_first_of(',')); - if ((suffix.find_first_of(',')+2) <= suffix.length()) { //checks to make sure you don't have comma at end of string - suffix = suffix.substr(suffix.find_first_of(',')+2, suffix.length()); - } - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the GlobalData class function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - -} -/*******************************************************/ - -/******************************************************/ -//This function separates the key value from the option value i.e. dist=96_... -void GlobalData::splitAtEquals(string& key, string& value){ - try { - if(value.find_first_of('=') != -1){ - key = value.substr(0,value.find_first_of('=')); - if ((value.find_first_of('=')+1) <= value.length()) { - value = value.substr(value.find_first_of('=')+1, value.length()); - } - }else{ - key = value; - value = 1; - } - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtEquals. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the GlobalData class function splitAtEquals. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - -} -/*******************************************************/ - -/******************************************************/ diff --git a/globaldata.hpp b/globaldata.hpp index 8089167..277d351 100644 --- a/globaldata.hpp +++ b/globaldata.hpp @@ -4,6 +4,13 @@ #include #include #include +#include +#include +#include +#include +#include +#include + #include "groupmap.h" #include "treemap.h" @@ -34,7 +41,7 @@ public: TreeMap* gTreemap; string inputFileName, helpRequest, commandName; bool allLines; - vector singleEstimators, summaryEstimators, sharedEstimators, rareEstimators, sharedRareEstimators, sharedSummaryEstimators; //holds estimators to be used + vector Estimators; //holds estimators to be used set lines; //hold lines to be used set labels; //holds labels to be used vector Groups; @@ -49,6 +56,7 @@ public: string getOrderFile(); string getFastaFile(); string getTreeFile(); + string getSharedFile(); string getCutOff(); string getFormat(); string getPrecision(); @@ -66,22 +74,16 @@ public: void setSabundFile(string); void setFormat(string); void setRandomTree(string); + void setCalc(string); void setListVector(ListVector*); void setSparseMatrix(SparseMatrix*); - void clear(); - void parseGlobalData(string, string); - void splitAtEquals(string&, string&); - void splitAtComma(string&, string&); - void splitAtDash(string&, vector&); - void splitAtDash(string&, set&); - void splitAtDash(string&, set&); - + private: - string phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, orderfile, fastafile, treefile, line, label, randomtree, groups; - string cutoff, format, precision, method, fileroot, iters, jumble, freq, single, rarefaction, shared, summary, sharedsummary, sharedrarefaction; + string phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, orderfile, fastafile, treefile, sharedfile, line, label, randomtree, groups; + string cutoff, format, precision, method, fileroot, iters, jumble, freq, calc; static GlobalData* _uniqueInstance; GlobalData( const GlobalData& ); // Disable copy constructor void operator=( const GlobalData& ); // Disable assignment operator @@ -89,10 +91,11 @@ private: ~GlobalData(); ListVector* gListVector; SparseMatrix* gSparseMatrix; + void clear(); //clears all parameters + void reset(); //clears all non filename parameters + }; -//********************************************************************************************************************** - #endif diff --git a/groupmap.cpp b/groupmap.cpp index 27302db..1f22013 100644 --- a/groupmap.cpp +++ b/groupmap.cpp @@ -37,12 +37,7 @@ void GroupMap::readMap() { fileHandle.close(); } /************************************************************/ - -int GroupMap::getNumGroups() { - - return namesOfGroups.size(); - -} +int GroupMap::getNumGroups() { return namesOfGroups.size(); } /************************************************************/ string GroupMap::getGroup(string sequenceName) { @@ -53,11 +48,13 @@ string GroupMap::getGroup(string sequenceName) { }else { return "not found"; } - } /************************************************************/ - +void GroupMap::setGroup(string sequenceName, string groupN) { + groupmap[sequenceName] = groupN; +} +/************************************************************/ void GroupMap::setNamesOfGroups(string seqGroup) { int i, count; count = 0; diff --git a/groupmap.h b/groupmap.h index a6b6fd7..de69ca4 100644 --- a/groupmap.h +++ b/groupmap.h @@ -20,18 +20,20 @@ class GroupMap { public: + GroupMap() {}; GroupMap(string); ~GroupMap(); void readMap(); int getNumGroups(); string getGroup(string); + void setGroup(string, string); vector namesOfGroups; map groupIndex; //groupname, vectorIndex in namesOfGroups. - used by collectdisplays. private: ifstream fileHandle; string groupFileName; - int numGroups, index; + int index; map::iterator it; void setNamesOfGroups(string); map groupmap; //sequence name and groupname diff --git a/helpcommand.cpp b/helpcommand.cpp index bc17dbe..0abab5a 100644 --- a/helpcommand.cpp +++ b/helpcommand.cpp @@ -11,7 +11,10 @@ //********************************************************************************************************************** -HelpCommand::HelpCommand(){} +HelpCommand::HelpCommand(){ + globaldata = GlobalData::getInstance(); + validCommands = new ValidCommands(); +} //********************************************************************************************************************** @@ -21,8 +24,6 @@ HelpCommand::~HelpCommand(){} int HelpCommand::execute(){ - globaldata = GlobalData::getInstance(); - if (globaldata->helpRequest == "read.dist") { cout << "The read.dist command parameter options are phylip or column, name, cutoff and precision" << "\n"; cout << "The read.dist command should be in the following format: " << "\n"; @@ -47,7 +48,12 @@ int HelpCommand::execute(){ cout << "It also must be run before using the parsimony command, unless you are using the randomtree parameter." << "\n"; cout << "The read.tree command should be in the following format: read.tree(tree=yourTreeFile, group=yourGroupFile)." << "\n"; cout << "The tree and group parameters are both required." << "\n"; - cout << "Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile)." << "\n" << "\n"; + cout << "Note: No spaces between parameter labels (i.e. tree), '=' and parameters (i.e.yourTreefile)." << "\n" << "\n"; + }else if (globaldata->helpRequest == "read.shared") { + cout << "The read.shared must be run before you execute a collect.shared, rarefaction.shared or summary.shared command." << "\n"; + cout << "The read.shared command is used to read a shared file. The read.shared should be entered in the following format:" << "\n"; + cout << "read.shared(shared=yourSharedFile). The shared parameter is required." << "\n"; + cout << "Note: No spaces between parameter labels (i.e. shared), '=' and parameters (i.e.yourSharedfile)." << "\n" << "\n"; }else if (globaldata->helpRequest == "cluster") { cout << "The cluster command can only be executed after a successful read.dist command." << "\n"; cout << "The cluster command parameter options are method, cuttoff and precision. No parameters are required." << "\n"; @@ -64,60 +70,60 @@ int HelpCommand::execute(){ }else if (globaldata->helpRequest == "collect.single") { cout << "The collect.single command can only be executed after a successful read.otu command. WITH ONE EXECEPTION. " << "\n"; cout << "The collect.single command can be executed after a successful cluster command. It will use the .list file from the output of the cluster." << "\n"; - cout << "The collect.single command parameters are label, line, freq, single. No parameters are required, but you may not use " << "\n"; + cout << "The collect.single command parameters are label, line, freq, calc. No parameters are required, but you may not use " << "\n"; cout << "both the line and label parameters at the same time. The collect.single command should be in the following format: " << "\n"; - cout << "collect.single(label=yourLabel, line=yourLines, iters=yourIters, freq=yourFreq, single=yourEstimators)." << "\n"; - cout << "Example collect(label=unique-.01-.03, line=0,5,10, iters=10000, freq=10, single=collect-chao-ace-jack)." << "\n"; - cout << "The default values for freq is 100, and single are sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson." << "\n"; + cout << "collect.single(label=yourLabel, line=yourLines, iters=yourIters, freq=yourFreq, calc=yourEstimators)." << "\n"; + cout << "Example collect(label=unique-.01-.03, line=0,5,10, iters=10000, freq=10, calc=sobs-chao-ace-jack)." << "\n"; + cout << "The default values for freq is 100, and calc are sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson." << "\n"; cout << "The label and line parameters are used to analyze specific lines in your input." << "\n"; - cout << "Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile)." << "\n" << "\n"; + cout << "Note: No spaces between parameter labels (i.e. freq), '=' and parameters (i.e.yourFreq)." << "\n" << "\n"; }else if (globaldata->helpRequest == "collect.shared") { cout << "The collect.shared command can only be executed after a successful read.otu command." << "\n"; - cout << "The collect.shared command parameters are label, line, freq, jumble, shared. No parameters are required, but you may not use " << "\n"; + cout << "The collect.shared command parameters are label, line, freq, jumble, calc. No parameters are required, but you may not use " << "\n"; cout << "both the line and label parameters at the same time. The collect.shared command should be in the following format: " << "\n"; - cout << "collect.shared(label=yourLabel, line=yourLines, freq=yourFreq, jumble=yourJumble, shared=yourEstimators)." << "\n"; - cout << "Example collect.shared(label=unique-.01-.03, line=0,5,10, freq=10, jumble=1, shared=sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN)." << "\n"; - cout << "The default values for jumble is 1 (meaning jumble, if it’s set to 0 then it will not jumble), freq is 100 and shared are sharedsobs-sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN." << "\n"; + cout << "collect.shared(label=yourLabel, line=yourLines, freq=yourFreq, jumble=yourJumble, calc=yourEstimators)." << "\n"; + cout << "Example collect.shared(label=unique-.01-.03, line=0,5,10, freq=10, jumble=1, calc=sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN)." << "\n"; + cout << "The default values for jumble is 1 (meaning jumble, if it’s set to 0 then it will not jumble), freq is 100 and calc are sharedsobs-sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN." << "\n"; cout << "The label and line parameters are used to analyze specific lines in your input." << "\n"; - cout << "Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile)." << "\n" << "\n"; + cout << "Note: No spaces between parameter labels (i.e. freq), '=' and parameters (i.e.yourFreq)." << "\n" << "\n"; }else if (globaldata->helpRequest == "rarefaction.single") { cout << "The rarefaction.single command can only be executed after a successful read.otu WTIH ONE EXECEPTION." << "\n"; cout << "The rarefaction.single command can be executed after a successful cluster command. It will use the .list file from the output of the cluster." << "\n"; - cout << "The rarefaction.single command parameters are label, line, iters, freq, rarefaction. No parameters are required, but you may not use " << "\n"; + cout << "The rarefaction.single command parameters are label, line, iters, freq, calc. No parameters are required, but you may not use " << "\n"; cout << "both the line and label parameters at the same time. The rarefaction.single command should be in the following format: " << "\n"; - cout << "rarefaction.single(label=yourLabel, line=yourLines, iters=yourIters, freq=yourFreq, rarefaction=yourEstimators)." << "\n"; - cout << "Example rarefaction.single(label=unique-.01-.03, line=0,5,10, iters=10000, freq=10, rarefaction=sobs-rchao-race-rjack-rbootstrap-rshannon-rnpshannon-rsimpson)." << "\n"; - cout << "The default values for iters is 1000, freq is 100, and rarefaction is rarefaction which calculates the rarefaction curve for the observed richness." << "\n"; + cout << "rarefaction.single(label=yourLabel, line=yourLines, iters=yourIters, freq=yourFreq, calc=yourEstimators)." << "\n"; + cout << "Example rarefaction.single(label=unique-.01-.03, line=0,5,10, iters=10000, freq=10, calc=sobs-rchao-race-rjack-rbootstrap-rshannon-rnpshannon-rsimpson)." << "\n"; + cout << "The default values for iters is 1000, freq is 100, and calc is rarefaction which calculates the rarefaction curve for the observed richness." << "\n"; cout << "The label and line parameters are used to analyze specific lines in your input." << "\n"; - cout << "Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile)." << "\n" << "\n"; + cout << "Note: No spaces between parameter labels (i.e. freq), '=' and parameters (i.e.yourFreq)." << "\n" << "\n"; }else if (globaldata->helpRequest == "rarefaction.shared") { cout << "The rarefaction.shared command can only be executed after a successful read.otu command." << "\n"; - cout << "The rarefaction.shared command parameters are label, line, iters, jumble and sharedrarefaction. No parameters are required, but you may not use " << "\n"; + cout << "The rarefaction.shared command parameters are label, line, iters, jumble and calc. No parameters are required, but you may not use " << "\n"; cout << "both the line and label parameters at the same time. The rarefaction command should be in the following format: " << "\n"; - cout << "rarefaction.shared(label=yourLabel, line=yourLines, iters=yourIters, jumble=yourJumble, sharedrarefaction=yourEstimators)." << "\n"; - cout << "Example rarefaction.shared(label=unique-.01-.03, line=0,5,10, iters=10000, jumble=1, sharedrarefaction=sharedobserved)." << "\n"; - cout << "The default values for iters is 1000, jumble is 1 (meaning jumble, if it’s set to 0 then it will not jumble), freq is 100, and sharedrarefaction is sharedobserved which calculates the shared rarefaction curve for the observed richness." << "\n"; + cout << "rarefaction.shared(label=yourLabel, line=yourLines, iters=yourIters, jumble=yourJumble, calc=yourEstimators)." << "\n"; + cout << "Example rarefaction.shared(label=unique-.01-.03, line=0,5,10, iters=10000, jumble=1, calc=sharedobserved)." << "\n"; + cout << "The default values for iters is 1000, jumble is 1 (meaning jumble, if it’s set to 0 then it will not jumble), freq is 100, and calc is sharedobserved which calculates the shared rarefaction curve for the observed richness." << "\n"; cout << "The label and line parameters are used to analyze specific lines in your input." << "\n"; - cout << "Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile)." << "\n" << "\n"; + cout << "Note: No spaces between parameter labels (i.e. freq), '=' and parameters (i.e.yourFreq)." << "\n" << "\n"; }else if (globaldata->helpRequest == "summary.single") { cout << "The summary.single command can only be executed after a successful read.otu WTIH ONE EXECEPTION." << "\n"; cout << "The summary.single command can be executed after a successful cluster command. It will use the .list file from the output of the cluster." << "\n"; - cout << "The summary.single command parameters are label, line, summary. No parameters are required, but you may not use " << "\n"; + cout << "The summary.single command parameters are label, line, calc. No parameters are required, but you may not use " << "\n"; cout << "both the line and label parameters at the same time. The summary.single command should be in the following format: " << "\n"; - cout << "summary.single(label=yourLabel, line=yourLines, summary=yourEstimators)." << "\n"; - cout << "Example summary.single(label=unique-.01-.03, line=0,5,10, summary=sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson)." << "\n"; - cout << "The default value summary is sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson" << "\n"; + cout << "summary.single(label=yourLabel, line=yourLines, calc=yourEstimators)." << "\n"; + cout << "Example summary.single(label=unique-.01-.03, line=0,5,10, calc=sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson)." << "\n"; + cout << "The default value calc is sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson" << "\n"; cout << "The label and line parameters are used to analyze specific lines in your input." << "\n"; - cout << "Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile)." << "\n" << "\n"; + cout << "Note: No spaces between parameter labels (i.e. line), '=' and parameters (i.e.yourLines)." << "\n" << "\n"; }else if (globaldata->helpRequest == "summary.shared") { cout << "The summary.shared command can only be executed after a successful read.otu command." << "\n"; - cout << "The summary.shared command parameters are label, line, jumble and sharedsummary. No parameters are required, but you may not use " << "\n"; + cout << "The summary.shared command parameters are label, line, jumble and calc. No parameters are required, but you may not use " << "\n"; cout << "both the line and label parameters at the same time. The summary.shared command should be in the following format: " << "\n"; - cout << "summary.shared(label=yourLabel, line=yourLines, jumble=yourJumble, sharedsummary=yourEstimators)." << "\n"; - cout << "Example summary.shared(label=unique-.01-.03, line=0,5,10, jumble=1, sharedsummary=sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN)." << "\n"; - cout << "The default value for jumble is 1 (meaning jumble, if it’s set to 0 then it will not jumble) and sharedsummary is sharedsobs-sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN" << "\n"; + cout << "summary.shared(label=yourLabel, line=yourLines, jumble=yourJumble, calc=yourEstimators)." << "\n"; + cout << "Example summary.shared(label=unique-.01-.03, line=0,5,10, jumble=1, calc=sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN)." << "\n"; + cout << "The default value for jumble is 1 (meaning jumble, if it’s set to 0 then it will not jumble) and calc is sharedsobs-sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN" << "\n"; cout << "The label and line parameters are used to analyze specific lines in your input." << "\n"; - cout << "Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile)." << "\n" << "\n"; + cout << "Note: No spaces between parameter labels (i.e. line), '=' and parameters (i.e.yourLines)." << "\n" << "\n"; }else if (globaldata->helpRequest == "parsimony") { cout << "The parsimony command can only be executed after a successful read.tree command, unless you use the randomtree parameter." << "\n"; cout << "The parsimony command parameters are randomtree and iters. No parameters are required." << "\n"; @@ -150,7 +156,7 @@ int HelpCommand::execute(){ cout << "The quit command will terminate Dotur and should be in the following format: " << "\n"; cout << "quit()" << "\n" << "\n"; }else if (globaldata->helpRequest == "") { - cout << "Valid commands are read.dist(), read.otu(), read.tree(), cluster(), deconvolute(), collect.single(), rarefaction.single(), summary.single(), collect.shared(), rarefaction.shared(), summary.shared(), parsimony(), unifrac.weighted(), unifrac.unweighted(), quit(), help()." << "\n"; + validCommands->printCommands(cout); cout << "For more information about a specific command type 'help(commandName)' i.e. 'help(read.dist)'" << endl; }else { cout << globaldata->helpRequest << " is not a valid command" << endl; diff --git a/helpcommand.h b/helpcommand.h index 6d95d86..d8f9b14 100644 --- a/helpcommand.h +++ b/helpcommand.h @@ -13,6 +13,7 @@ #include "command.hpp" #include "globaldata.hpp" +#include "validcommands.h" class HelpCommand : public Command { @@ -23,6 +24,7 @@ public: int execute(); private: GlobalData* globaldata; + ValidCommands* validCommands; private: diff --git a/inputdata.cpp b/inputdata.cpp index 4ed9c27..95e9d34 100644 --- a/inputdata.cpp +++ b/inputdata.cpp @@ -89,7 +89,7 @@ ListVector* InputData::getListVector(){ SharedListVector* InputData::getSharedListVector(){ try { if(fileHandle){ - if (format == "shared"){ + if (format == "shared") { SharedList = new SharedListVector(fileHandle); } @@ -110,6 +110,33 @@ SharedListVector* InputData::getSharedListVector(){ } } +/***********************************************************************/ + +SharedOrderVector* InputData::getSharedOrderVector(){ + try { + if(fileHandle){ + if (format == "sharedfile") { + SharedOrder = new SharedOrderVector(fileHandle); + } + + gobble(fileHandle); + return SharedOrder; + + }else{ + return 0; + } + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the InputData class function getSharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} + + /***********************************************************************/ @@ -119,7 +146,7 @@ OrderVector* InputData::getOrderVector(){ if(format == "list") { input = new ListVector(fileHandle); } - else if(format == "shared") { + else if (format == "shared") { input = new SharedListVector(fileHandle); } else if(format == "rabund"){ @@ -138,7 +165,7 @@ OrderVector* InputData::getOrderVector(){ gobble(fileHandle); output = new OrderVector(); *output = (input->getOrderVector()); - //delete input; + return output; } else{ @@ -163,7 +190,7 @@ SAbundVector* InputData::getSAbundVector(){ if (format == "list") { input = new ListVector(fileHandle); } - else if(format == "shared") { + else if (format == "shared") { input = new SharedListVector(fileHandle); } else if(format == "rabund"){ diff --git a/inputdata.h b/inputdata.h index abb343e..b6912b3 100644 --- a/inputdata.h +++ b/inputdata.h @@ -7,6 +7,7 @@ #include #include "ordervector.hpp" #include "sharedlistvector.h" +#include "sharedordervector.h" #include "listvector.hpp" @@ -21,6 +22,7 @@ public: ListVector* getListVector(); SharedListVector* getSharedListVector(); OrderVector* getOrderVector(); + SharedOrderVector* getSharedOrderVector(); SAbundVector* getSAbundVector(); private: @@ -30,6 +32,7 @@ private: ListVector* list; SharedListVector* SharedList; OrderVector* output; + SharedOrderVector* SharedOrder; SAbundVector* sabund; map orderMap; }; diff --git a/rarefactcommand.cpp b/rarefactcommand.cpp index c2204e7..7e4ced5 100644 --- a/rarefactcommand.cpp +++ b/rarefactcommand.cpp @@ -25,28 +25,34 @@ RareFactCommand::RareFactCommand(){ globaldata = GlobalData::getInstance(); string fileNameRoot; fileNameRoot = getRootName(globaldata->inputFileName); + validCalculator = new ValidCalculators(); + int i; - for (i=0; irareEstimators.size(); i++) { - if (globaldata->rareEstimators[i] == "sobs") { - rDisplays.push_back(new RareDisplay(new Sobs(), new ThreeColumnFile(fileNameRoot+"rarefaction"))); - }else if (globaldata->rareEstimators[i] == "chao") { - rDisplays.push_back(new RareDisplay(new Chao1(), new ThreeColumnFile(fileNameRoot+"r_chao"))); - }else if (globaldata->rareEstimators[i] == "ace") { - rDisplays.push_back(new RareDisplay(new Ace(), new ThreeColumnFile(fileNameRoot+"r_ace"))); - }else if (globaldata->rareEstimators[i] == "jack") { - rDisplays.push_back(new RareDisplay(new Jackknife(), new ThreeColumnFile(fileNameRoot+"r_jack"))); - }else if (globaldata->rareEstimators[i] == "shannon") { - rDisplays.push_back(new RareDisplay(new Shannon(), new ThreeColumnFile(fileNameRoot+"r_shannon"))); - }else if (globaldata->rareEstimators[i] == "npshannon") { - rDisplays.push_back(new RareDisplay(new NPShannon(), new ThreeColumnFile(fileNameRoot+"r_npshannon"))); - }else if (globaldata->rareEstimators[i] == "simpson") { - rDisplays.push_back(new RareDisplay(new Simpson(), new ThreeColumnFile(fileNameRoot+"r_simpson"))); - }else if (globaldata->rareEstimators[i] == "bootstrap") { - rDisplays.push_back(new RareDisplay(new Bootstrap(), new ThreeColumnFile(fileNameRoot+"r_bootstrap"))); + for (i=0; iEstimators.size(); i++) { + if (validCalculator->isValidCalculator("rarefaction", globaldata->Estimators[i]) == true) { + if (globaldata->Estimators[i] == "sobs") { + rDisplays.push_back(new RareDisplay(new Sobs(), new ThreeColumnFile(fileNameRoot+"rarefaction"))); + }else if (globaldata->Estimators[i] == "chao") { + rDisplays.push_back(new RareDisplay(new Chao1(), new ThreeColumnFile(fileNameRoot+"r_chao"))); + }else if (globaldata->Estimators[i] == "ace") { + rDisplays.push_back(new RareDisplay(new Ace(), new ThreeColumnFile(fileNameRoot+"r_ace"))); + }else if (globaldata->Estimators[i] == "jack") { + rDisplays.push_back(new RareDisplay(new Jackknife(), new ThreeColumnFile(fileNameRoot+"r_jack"))); + }else if (globaldata->Estimators[i] == "shannon") { + rDisplays.push_back(new RareDisplay(new Shannon(), new ThreeColumnFile(fileNameRoot+"r_shannon"))); + }else if (globaldata->Estimators[i] == "npshannon") { + rDisplays.push_back(new RareDisplay(new NPShannon(), new ThreeColumnFile(fileNameRoot+"r_npshannon"))); + }else if (globaldata->Estimators[i] == "simpson") { + rDisplays.push_back(new RareDisplay(new Simpson(), new ThreeColumnFile(fileNameRoot+"r_simpson"))); + }else if (globaldata->Estimators[i] == "bootstrap") { + rDisplays.push_back(new RareDisplay(new Bootstrap(), new ThreeColumnFile(fileNameRoot+"r_bootstrap"))); + } } } - - + + //reset calc for next command + globaldata->setCalc(""); + } catch(exception& e) { cout << "Standard Error: " << e.what() << " has occurred in the RareFactCommand class Function RareFactCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; @@ -73,6 +79,10 @@ RareFactCommand::~RareFactCommand(){ int RareFactCommand::execute(){ try { int count = 1; + + //if the users entered no valid calculators don't execute command + if (rDisplays.size() == 0) { return 0; } + read = new ReadPhilFile(globaldata->inputFileName); read->read(&*globaldata); diff --git a/rarefactcommand.h b/rarefactcommand.h index 0da5f0c..c81eb6f 100644 --- a/rarefactcommand.h +++ b/rarefactcommand.h @@ -18,6 +18,7 @@ #include "rarefact.h" #include "display.h" #include "readmatrix.hpp" +#include "validcalculator.h" /*The rarefaction() command: @@ -49,6 +50,7 @@ private: ReadMatrix* read; OrderVector* order; InputData* input; + ValidCalculators* validCalculator; Rarefact* rCurve; int freq, nIters; }; diff --git a/rarefactsharedcommand.cpp b/rarefactsharedcommand.cpp index 5e36299..45c2e2e 100644 --- a/rarefactsharedcommand.cpp +++ b/rarefactsharedcommand.cpp @@ -17,13 +17,21 @@ RareFactSharedCommand::RareFactSharedCommand(){ globaldata = GlobalData::getInstance(); string fileNameRoot; fileNameRoot = getRootName(globaldata->inputFileName); + format = globaldata->getFormat(); + validCalculator = new ValidCalculators(); int i; - for (i=0; isharedRareEstimators.size(); i++) { - if (globaldata->sharedRareEstimators[i] == "sharedobserved") { - rDisplays.push_back(new RareDisplay(new SharedSobs(), new SharedThreeColumnFile(fileNameRoot+"shared.rarefaction", ""))); + for (i=0; iEstimators.size(); i++) { + if (validCalculator->isValidCalculator("sharedrarefaction", globaldata->Estimators[i]) == true) { + if (globaldata->Estimators[i] == "sharedobserved") { + rDisplays.push_back(new RareDisplay(new SharedSobs(), new SharedThreeColumnFile(fileNameRoot+"shared.rarefaction", ""))); + } } } + + //reset calc for next command + globaldata->setCalc(""); + } catch(exception& e) { cout << "Standard Error: " << e.what() << " has occurred in the RareFactSharedCommand class Function RareFactSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; @@ -50,12 +58,25 @@ RareFactSharedCommand::~RareFactSharedCommand(){ int RareFactSharedCommand::execute(){ try { int count = 1; - read = new ReadPhilFile(globaldata->inputFileName); - read->read(&*globaldata); - input = globaldata->ginput; - SharedList = globaldata->gSharedList; - order = SharedList->getSharedOrderVector(); + //if the users entered no valid calculators don't execute command + if (rDisplays.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(); + } while(order != NULL){ @@ -71,14 +92,20 @@ int RareFactSharedCommand::execute(){ cout << order->getLabel() << '\t' << count << endl; } - 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++; } for(int i=0;i rDisplays; int freq, nIters; + string format; }; diff --git a/readmatrix.cpp b/readmatrix.cpp index 78a4bd4..72dd799 100644 --- a/readmatrix.cpp +++ b/readmatrix.cpp @@ -346,7 +346,7 @@ void ReadPhilFile::read(GlobalData* globaldata){ //you have two inputs because in the next if statement if you only have one then it moves ahead in the same file. //So when you run the collect or summary commands you miss a line. input = new InputData(philFile, globaldata->getFormat()); //format tells you whether philFile is list, rabund, sabund. - inputSabund = new InputData(philFile, globaldata->getFormat()); //format tells you whether philFile is list, rabund, sabund. + inputSabund = new InputData(philFile, globaldata->getFormat()); //format tells you whether philFile is list, rabund, sabund or shared. }else {//there is an orderfile input = new InputData(philFile, globaldata->getOrderFile(), globaldata->getFormat()); } @@ -358,7 +358,7 @@ void ReadPhilFile::read(GlobalData* globaldata){ sabund = inputSabund->getSAbundVector(); globaldata->sabund = sabund; //saving to be used by summary command. }else if (globaldata->getFormat() == "shared") { - SharedList = input->getSharedListVector(); //you are reading for parselist command, or shared commands. + SharedList = input->getSharedListVector(); //you are reading for collect.shared, rarefaction.shared, summary.shared, parselist command, or shared commands. globaldata->gSharedList = SharedList; } } diff --git a/readsharedcommand.cpp b/readsharedcommand.cpp new file mode 100644 index 0000000..0035156 --- /dev/null +++ b/readsharedcommand.cpp @@ -0,0 +1,52 @@ +/* + * readsharedcommand.cpp + * Mothur + * + * Created by Sarah Westcott on 2/12/09. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. + * + */ + +#include "readsharedcommand.h" + +//********************************************************************************************************************** +ReadSharedCommand::ReadSharedCommand(){ + try { + globaldata = GlobalData::getInstance(); + filename = globaldata->inputFileName; + read = new ReadPhilFile(filename); + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the ReadSharedCommand class Function ReadSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the ReadSharedCommand class function ReadSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} + +//********************************************************************************************************************** + +ReadSharedCommand::~ReadSharedCommand(){ + delete read; +} + +//********************************************************************************************************************** + +int ReadSharedCommand::execute(){ + try { + read->read(&*globaldata); + + return 0; + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the ReadSharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the ReadSharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} +//********************************************************************************************************************** \ No newline at end of file diff --git a/readsharedcommand.h b/readsharedcommand.h new file mode 100644 index 0000000..8e7f290 --- /dev/null +++ b/readsharedcommand.h @@ -0,0 +1,40 @@ +#ifndef READSHAREDCOMMAND_H +#define READSHAREDCOMMAND_H +/* + * readsharedcommand.h + * Mothur + * + * Created by Sarah Westcott on 2/12/09. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. + * + */ +#include +#include +#include "command.hpp" +#include "readmatrix.hpp" +#include "inputdata.h" + +/* The read.shared must be run before you execute a collect.shared, rarefaction.shared or summary.shared command. +The read.shared command is used to read a shared file. The read.shared should be entered in the following format: +read.shared(shared=yourSharedFile). The shared parameter is required. */ + +class GlobalData; + +class ReadSharedCommand : public Command { +public: + ReadSharedCommand(); + ~ReadSharedCommand(); + int execute(); + +private: + GlobalData* globaldata; + ReadMatrix* read; + InputData* input; + string filename; +}; + +#endif + + + + diff --git a/sharedlistvector.cpp b/sharedlistvector.cpp index 62e3788..81dd728 100644 --- a/sharedlistvector.cpp +++ b/sharedlistvector.cpp @@ -32,21 +32,22 @@ SharedListVector::SharedListVector(int n): DataVector(), data(n, "") , maxRank(0 SharedListVector::SharedListVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) { try { globaldata = GlobalData::getInstance(); - + //set up groupmap for later. groupmap = new GroupMap(globaldata->getGroupFile()); groupmap->readMap(); int hold; + string inputData; f >> label >> hold; data.assign(hold, ""); - string inputData = ""; for(int i=0;i> inputData; set(i, inputData); } + } catch(exception& e) { cout << "Standard Error: " << e.what() << " has occurred in the SharedListVector class Function SharedListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; diff --git a/sharedordervector.cpp b/sharedordervector.cpp index 575ae18..6aeb4ce 100644 --- a/sharedordervector.cpp +++ b/sharedordervector.cpp @@ -26,25 +26,74 @@ SharedOrderVector::SharedOrderVector(string id, vector ov) : updateStats(); } -/*********************************************************************** - -//does not work since we don't have a shared order file format yet. +/***********************************************************************/ +//This function is used to read a .shared file for the collect.shared, rarefaction.shared and summary.shared commands +//if you don't use a list and groupfile. SharedOrderVector::SharedOrderVector(ifstream& f) : DataVector() { try { - int hold; - - f >> label; - f >> hold; - - data.assign(hold, -1); - - int inputData; - - for(int i=0;igGroupmap == NULL) { groupmap = new GroupMap(); } + + int num, inputData, pos, count; + count = 0; numSeqs = 0; + string holdLabel, nextLabel, groupN; + individual newguy; + + //read in first row since you know there is at least 1 group. + f >> label >> groupN >> num; + holdLabel = label; + + if (globaldata->gGroupmap == NULL) { + //save group in groupmap + groupmap->namesOfGroups.push_back(groupN); + groupmap->groupIndex[groupN] = 0; + } + + for(int i=0;i> inputData; - set(i, inputData, inputData, group); + for (int j = 0; j < inputData; j++) { + push_back(i+1, i+1, groupN); + numSeqs++; + } } + + //save position in file in case next line is a new label. + pos = f.tellg(); + + if (f.eof() != true) { f >> nextLabel; } + + //read the rest of the groups info in + while ((nextLabel == holdLabel) && (f.eof() != true)) { + f >> groupN >> num; + count++; + + if (globaldata->gGroupmap == NULL) { + //save group in groupmap + groupmap->namesOfGroups.push_back(groupN); + groupmap->groupIndex[groupN] = count; + } + + for(int i=0;i> inputData; + for (int j = 0; j < inputData; j++) { + push_back(i+1, i+1, groupN); + numSeqs++; + } + } + + //save position in file in case next line is a new label. + pos = f.tellg(); + + if (f.eof() != true) { f >> nextLabel; } + + } + + //put file pointer back since you are now at a new distance label + f.seekg(pos, ios::beg); + + if (globaldata->gGroupmap == NULL) { globaldata->gGroupmap = groupmap; } updateStats(); } @@ -57,10 +106,8 @@ SharedOrderVector::SharedOrderVector(ifstream& f) : DataVector() { exit(1); } } - /***********************************************************************/ - int SharedOrderVector::getNumBins(){ if(needToUpdate == 1){ updateStats(); } return numBins; diff --git a/sharedordervector.h b/sharedordervector.h index b1b4a65..94d91c5 100644 --- a/sharedordervector.h +++ b/sharedordervector.h @@ -29,6 +29,8 @@ struct individual { #include "rabundvector.hpp" #include "sharedrabundvector.h" #include "sharedsabundvector.h" +#include "globaldata.hpp" +#include "groupmap.h" class SharedOrderVector : public DataVector { @@ -38,7 +40,7 @@ public: SharedOrderVector(const SharedOrderVector& ov) : DataVector(ov.label), data(ov.data), maxRank(ov.maxRank), numBins(ov.numBins), numSeqs(ov.numSeqs), needToUpdate(ov.needToUpdate) {if(needToUpdate == 1){ updateStats();}}; SharedOrderVector(string, vector); -// SharedOrderVector(ifstream&); + SharedOrderVector(ifstream&); ~SharedOrderVector(){}; void set(int, int, int, string); //index, OTU, abundance, group @@ -63,6 +65,8 @@ public: SharedSAbundVector getSharedSAbundVector(string); //get the sharedSabundvector for a sepecific group private: + GlobalData* globaldata; + GroupMap* groupmap; vector data; map< int, vector >::iterator it; int maxRank; diff --git a/sharedrabundvector.cpp b/sharedrabundvector.cpp index a703e55..a2b7936 100644 --- a/sharedrabundvector.cpp +++ b/sharedrabundvector.cpp @@ -65,10 +65,11 @@ SharedRAbundVector::SharedRAbundVector(string id, vector rav) : Data SharedRAbundVector::SharedRAbundVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) { try { - int i, hold; + int i, num; + string holdLabel, group individual newGuy; - f >> label >> hold; + f >> label >> group >> num; //initialize data for (i=0; isummaryEstimators.size(); i++) { - if(globaldata->summaryEstimators[i] == "sobs"){ - sumCalculators.push_back(new Sobs()); - }else if(globaldata->summaryEstimators[i] == "chao"){ - sumCalculators.push_back(new Chao1()); - }else if(globaldata->summaryEstimators[i] == "ace"){ - sumCalculators.push_back(new Ace()); - }else if(globaldata->summaryEstimators[i] == "jack"){ - sumCalculators.push_back(new Jackknife()); - }else if(globaldata->summaryEstimators[i] == "shannon"){ - sumCalculators.push_back(new Shannon()); - }else if(globaldata->summaryEstimators[i] == "npshannon"){ - sumCalculators.push_back(new NPShannon()); - }else if(globaldata->summaryEstimators[i] == "simpson"){ - sumCalculators.push_back(new Simpson()); - }else if(globaldata->summaryEstimators[i] == "bootstrap"){ - sumCalculators.push_back(new Bootstrap()); + + for (i=0; iEstimators.size(); i++) { + if (validCalculator->isValidCalculator("summary", globaldata->Estimators[i]) == true) { + if(globaldata->Estimators[i] == "sobs"){ + sumCalculators.push_back(new Sobs()); + }else if(globaldata->Estimators[i] == "chao"){ + sumCalculators.push_back(new Chao1()); + }else if(globaldata->Estimators[i] == "ace"){ + sumCalculators.push_back(new Ace()); + }else if(globaldata->Estimators[i] == "jack"){ + sumCalculators.push_back(new Jackknife()); + }else if(globaldata->Estimators[i] == "shannon"){ + sumCalculators.push_back(new Shannon()); + }else if(globaldata->Estimators[i] == "npshannon"){ + sumCalculators.push_back(new NPShannon()); + }else if(globaldata->Estimators[i] == "simpson"){ + sumCalculators.push_back(new Simpson()); + }else if(globaldata->Estimators[i] == "bootstrap"){ + sumCalculators.push_back(new Bootstrap()); + } } } + + //reset calc for next command + globaldata->setCalc(""); + } catch(exception& e) { cout << "Standard Error: " << e.what() << " has occurred in the SummaryCommand class Function SummaryCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; @@ -64,6 +72,10 @@ SummaryCommand::~SummaryCommand(){ int SummaryCommand::execute(){ try { + + //if the users entered no valid calculators don't execute command + if (sumCalculators.size() == 0) { return 0; } + outputFileName = ((getRootName(globaldata->inputFileName)) + "summary"); openOutputFile(outputFileName, outputFileHandle); outputFileHandle << "label"; diff --git a/summarycommand.h b/summarycommand.h index c03a6c6..8e2d74b 100644 --- a/summarycommand.h +++ b/summarycommand.h @@ -17,6 +17,7 @@ #include "inputdata.h" #include "calculator.h" #include "readmatrix.hpp" +#include "validcalculator.h" /* The summary() command: The summary command can only be executed after a successful read.list, read.sabund or read.rabund command, with one exception. @@ -44,6 +45,7 @@ private: ReadMatrix* read; vector sumCalculators; InputData* input; + ValidCalculators* validCalculator; SAbundVector* sabund; string outputFileName; ofstream outputFileHandle; diff --git a/summarysharedcommand.cpp b/summarysharedcommand.cpp index c451ef7..f31f7e1 100644 --- a/summarysharedcommand.cpp +++ b/summarysharedcommand.cpp @@ -25,33 +25,43 @@ 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; isharedSummaryEstimators.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; iEstimators.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()); + } } } + + //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"; @@ -73,23 +83,34 @@ SummarySharedCommand::~SummarySharedCommand(){ 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(); + } + + //output estimator names as column headers outputFileHandle << "label" <<'\t' << "comparison" << '\t'; for(int i=0;igetName(); } 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){ @@ -115,13 +136,19 @@ int SummarySharedCommand::execute(){ } } - 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++; } return 0; diff --git a/summarysharedcommand.h b/summarysharedcommand.h index ab1d7ac..c531b8a 100644 --- a/summarysharedcommand.h +++ b/summarysharedcommand.h @@ -18,6 +18,7 @@ #include "calculator.h" #include "readmatrix.hpp" #include "sharedlistvector.h" +#include "validcalculator.h" /*The summary.shared() command The summary.shared command can only be executed after a successful read.shared command. @@ -50,11 +51,12 @@ private: ReadMatrix* read; vector sumCalculators; InputData* input; + ValidCalculators* validCalculator; SharedListVector* SharedList; SharedOrderVector* order; vector lookup; SharedRAbundVector* shared1, shared2; - string outputFileName; + string outputFileName, format; ofstream outputFileHandle; }; diff --git a/tree.h b/tree.h index 2ef8b23..d7dcc3d 100644 --- a/tree.h +++ b/tree.h @@ -12,14 +12,6 @@ using namespace std; -#include -#include -#include -#include -#include -#include -#include - #include "treenode.h" #include "globaldata.hpp" diff --git a/utilities.hpp b/utilities.hpp index 16e762c..0c67561 100644 --- a/utilities.hpp +++ b/utilities.hpp @@ -10,6 +10,7 @@ using namespace std; #include #include #include +#include typedef unsigned long long ull; @@ -196,4 +197,134 @@ inline int openOutputFile(string fileName, ofstream& fileHandle){ /***********************************************************************/ +//This function parses the estimator options and puts them in a vector +inline void splitAtDash(string& estim, vector& container) { + try { + string individual; + + while (estim.find_first_of('-') != -1) { + individual = estim.substr(0,estim.find_first_of('-')); + if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string + estim = estim.substr(estim.find_first_of('-')+1, estim.length()); + container.push_back(individual); + } + } + //get last one + container.push_back(estim); + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the utilities class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the utilities class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + +} + +/***********************************************************************/ +//This function parses the label options and puts them in a set +inline void splitAtDash(string& estim, set& container) { + try { + string individual; + + while (estim.find_first_of('-') != -1) { + individual = estim.substr(0,estim.find_first_of('-')); + if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string + estim = estim.substr(estim.find_first_of('-')+1, estim.length()); + container.insert(individual); + } + } + //get last one + container.insert(estim); + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the utilities class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the utilities class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + +} +/***********************************************************************/ +//This function parses the line options and puts them in a set +inline void splitAtDash(string& estim, set& container) { + try { + string individual; + int lineNum; + + while (estim.find_first_of('-') != -1) { + individual = estim.substr(0,estim.find_first_of('-')); + if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string + estim = estim.substr(estim.find_first_of('-')+1, estim.length()); + convert(individual, lineNum); //convert the string to int + container.insert(lineNum); + } + } + //get last one + convert(estim, lineNum); //convert the string to int + container.insert(lineNum); + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the utilities class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the utilities class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + +} +/***********************************************************************/ + +//This function splits up the various option parameters +inline void splitAtComma(string& prefix, string& suffix){ + try { + prefix = suffix.substr(0,suffix.find_first_of(',')); + if ((suffix.find_first_of(',')+2) <= suffix.length()) { //checks to make sure you don't have comma at end of string + suffix = suffix.substr(suffix.find_first_of(',')+2, suffix.length()); + } + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the utilities class Function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the utilities class function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + +} +/***********************************************************************/ + +//This function separates the key value from the option value i.e. dist=96_... +inline void splitAtEquals(string& key, string& value){ + try { + if(value.find_first_of('=') != -1){ + key = value.substr(0,value.find_first_of('=')); + if ((value.find_first_of('=')+1) <= value.length()) { + value = value.substr(value.find_first_of('=')+1, value.length()); + } + }else{ + key = value; + value = 1; + } + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the utilities class Function splitAtEquals. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the utilities class function splitAtEquals. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + +} +/*******************************************************/ + + + #endif diff --git a/validcalculator.cpp b/validcalculator.cpp index 1e25fe6..e75613f 100644 --- a/validcalculator.cpp +++ b/validcalculator.cpp @@ -42,37 +42,72 @@ bool ValidCalculators::isValidCalculator(string parameter, string calculator) { //is it valid if ((single.find(calculator)) != (single.end())) { return true; - }else { cout << calculator << " is not a valid single estimator. Valid single estimators are collect-chao-ace-jack-bootstrap-shannon-npshannon-simpson." << endl; return false; } + }else { + cout << calculator << " is not a valid estimator for the collect.single command and will be disregarded. Valid estimators are "; + for (it = single.begin(); it != single.end(); it++) { + cout << it->first << ", "; + } + cout << endl; + return false; } //are you looking for a calculator for a shared parameter }else if (parameter == "shared") { //is it valid if ((shared.find(calculator)) != (shared.end())) { return true; - }else { cout << calculator << " is not a valid shared estimator. Valid shared estimators are sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN." << endl; return false; } + }else { + cout << calculator << " is not a valid estimator for the collect.shared command and will be disregarded. Valid estimators are "; + for (it = shared.begin(); it != shared.end(); it++) { + cout << it->first << ", "; + } + cout << endl; + return false; } //are you looking for a calculator for a rarefaction parameter }else if (parameter == "rarefaction") { //is it valid if ((rarefaction.find(calculator)) != (rarefaction.end())) { return true; - }else { cout << calculator << " is not a valid rarefaction estimator. Valid rarefaction estimators are rarefaction-rchao-race-rjack-rbootstrap-rshannon-rnpshannon-rsimpson." << endl; return false; } + }else { + cout << calculator << " is not a valid estimator for the rarefaction.single command and will be disregarded. Valid estimators are "; + for (it = rarefaction.begin(); it != rarefaction.end(); it++) { + cout << it->first << ", "; + } + cout << endl; + return false; } //are you looking for a calculator for a summary parameter }else if (parameter == "summary") { //is it valid if ((summary.find(calculator)) != (summary.end())) { return true; - }else { cout << calculator << " is not a valid summary estimator. Valid summary estimators are collect-chao-ace-jack-bootstrap-shannon-npshannon-simpson." << endl; return false; } + }else { + cout << calculator << " is not a valid estimator for the summary.shared command and will be disregarded. Valid estimators are "; + for (it = summary.begin(); it != summary.end(); it++) { + cout << it->first << ", "; + } + cout << endl; + return false; } //are you looking for a calculator for a sharedsummary parameter }else if (parameter == "sharedsummary") { //is it valid if ((sharedsummary.find(calculator)) != (sharedsummary.end())) { return true; - }else { cout << calculator << " is not a valid sharedsummary estimator. Valid sharedsummary estimators are: sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN." << endl; return false; } - + }else { + cout << calculator << " is not a valid estimator for the summary.shared command and will be disregarded. Valid estimators are "; + for (it = sharedsummary.begin(); it != sharedsummary.end(); it++) { + cout << it->first << ", "; + } + cout << endl; + return false; } }else if (parameter == "sharedrarefaction") { //is it valid if ((sharedrarefaction.find(calculator)) != (sharedrarefaction.end())) { return true; - }else { cout << calculator << " is not a valid sharedrarefaction estimator. Valid sharedrarefaction estimator is sharedobserved." << endl; return false; } + }else { + cout << calculator << " is not a valid estimator for the rarefaction.shared command and will be disregarded. Valid estimator is "; + for (it = sharedrarefaction.begin(); it != sharedrarefaction.end(); it++) { + cout << it->first << ", "; + } + cout << endl; + return false; } //not a valid paramter }else { return false; } @@ -114,17 +149,17 @@ void ValidCalculators::initialSingle() { /********************************************************************/ void ValidCalculators::initialShared() { try { - shared["sharedSobs"] = "sharedSobs"; - shared["sharedChao"] = "sharedChao"; - shared["sharedAce"] = "sharedAce"; - shared["sharedJabund"] = "sharedJabund"; - shared["sharedSorensonAbund"] = "sharedSorensonAbund"; - shared["sharedJclass"] = "sharedJclass"; - shared["sharedSorClass"] = "sharedSorClass"; - shared["sharedJest"] = "sharedJest"; - shared["sharedSorEst"] = "sharedSorEst"; - shared["SharedThetaYC"] = "SharedThetaYC"; - shared["SharedThetaN"] = "SharedThetaN"; + shared["sharedsobs"] = "sharedsobs"; + shared["sharedchao"] = "sharedchao"; + shared["sharedace"] = "sharedace"; + shared["sharedjabund"] = "sharedjabund"; + shared["sharedsorensonabund"] = "sharedsorensonabund"; + shared["sharedjclass"] = "sharedjclass"; + shared["sharedsorclass"] = "sharedsorclass"; + shared["sharedjest"] = "sharedjest"; + shared["sharedsorest"] = "sharedsorest"; + shared["sharedthetayc"] = "sharedthetayc"; + shared["sharedthetan"] = "sharedthetan"; shared["default"] = "default"; } catch(exception& e) { @@ -187,17 +222,17 @@ void ValidCalculators::initialSummary() { /********************************************************************/ void ValidCalculators::initialSharedSummary() { try { - sharedsummary["sharedSobs"] = "sharedSobs"; - sharedsummary["sharedChao"] = "sharedChao"; - sharedsummary["sharedAce"] = "sharedAce"; - sharedsummary["sharedJabund"] = "sharedJabund"; - sharedsummary["sharedSorensonAbund"] = "sharedSorensonAbund"; - sharedsummary["sharedJclass"] = "sharedJclass"; - sharedsummary["sharedSorClass"] = "sharedSorClass"; - sharedsummary["sharedJest"] = "sharedJest"; - sharedsummary["sharedSorEst"] = "sharedSorEst"; - sharedsummary["SharedThetaYC"] = "SharedThetaYC"; - sharedsummary["SharedThetaN"] = "SharedThetaN"; + sharedsummary["sharedsobs"] = "sharedsobs"; + sharedsummary["sharedchao"] = "sharedchao"; + sharedsummary["sharedace"] = "sharedace"; + sharedsummary["sharedjabund"] = "sharedjabund"; + sharedsummary["sharedsorensonabund"] = "sharedsorensonabund"; + sharedsummary["sharedjclass"] = "sharedjclass"; + sharedsummary["sharedsorclass"] = "sharedsorclass"; + sharedsummary["sharedjest"] = "sharedjest"; + sharedsummary["sharedsorest"] = "sharedsorest"; + sharedsummary["sharedthetayc"] = "sharedthetayc"; + sharedsummary["sharedthetan"] = "sharedthetan"; sharedsummary["default"] = "default"; } catch(exception& e) { diff --git a/validcalculator.h b/validcalculator.h index b23c24f..9d4cef9 100644 --- a/validcalculator.h +++ b/validcalculator.h @@ -33,6 +33,8 @@ class ValidCalculators { map summary; map sharedrarefaction; map sharedsummary; + map::iterator it; + void initialSingle(); void initialShared(); void initialRarefaction(); diff --git a/validcommands.cpp b/validcommands.cpp index 53ee743..79b09d3 100644 --- a/validcommands.cpp +++ b/validcommands.cpp @@ -17,6 +17,7 @@ ValidCommands::ValidCommands() { commands["read.dist"] = "read.dist"; commands["read.otu"] = "read.otu"; commands["read.tree"] = "read.tree"; + commands["read.shared"] = "read.shared"; commands["cluster"] = "cluster"; commands["deconvolute"] = "deconvolute"; commands["parsimony"] = "parsimony"; @@ -55,7 +56,11 @@ bool ValidCommands::isValidCommand(string command) { if ((commands.find(command)) != (commands.end())) { return true; }else{ - cout << command << " is not a valid command in Mothur. Valid commands are read.dist(), read.otu(), read.tree(), cluster(), deconvolute(), collect.single(), collect.shared(), rarefaction.single(), rarefaction.shared(), summary.single(), summary.shared(), parsimony(), unifrac.weighted(), unifrac.unweighted(), quit(), help()." << endl; + cout << command << " is not a valid command in Mothur. Valid commands are "; + for (it = commands.begin(); it != commands.end(); it++) { + cout << it->first << ", "; + } + cout << endl; return false; } @@ -71,3 +76,24 @@ bool ValidCommands::isValidCommand(string command) { } /***********************************************************************/ +void ValidCommands::printCommands(ostream& out) { + try { + out << "Valid commands are "; + for (it = commands.begin(); it != commands.end(); it++) { + out << it->first << ", "; + } + out << endl; + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the ValidCommands class Function printCommands. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the ValidCommands class function printCommands. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} + + + + diff --git a/validcommands.h b/validcommands.h index 1955497..1b83b9b 100644 --- a/validcommands.h +++ b/validcommands.h @@ -25,8 +25,10 @@ class ValidCommands { ValidCommands(); ~ValidCommands(); bool isValidCommand(string); + void printCommands(ostream&); private: map commands; + map::iterator it; }; diff --git a/validparameter.cpp b/validparameter.cpp index fbb368e..1c6cd60 100644 --- a/validparameter.cpp +++ b/validparameter.cpp @@ -42,6 +42,7 @@ ValidParameters::ValidParameters() { parameters["sharedsummary"] = "sharedsummary"; parameters["randomtree"] = "randomtree"; parameters["groups"] = "groups"; + parameters["calc"] = "calc"; } catch(exception& e) { @@ -66,7 +67,12 @@ bool ValidParameters::isValidParameter(string parameter) { if ((parameters.find(parameter)) != (parameters.end())) { return true; }else{ - cout << parameter << " is not a valid parameter in Mothur." << endl; + cout << parameter << " is not a valid parameter in Mothur. Valid parameters are " << endl; + for (it = parameters.begin(); it != parameters.end(); it++) { + cout << it->first << ", "; + } + cout << endl; + return false; } diff --git a/validparameter.h b/validparameter.h index e0477aa..a4dd516 100644 --- a/validparameter.h +++ b/validparameter.h @@ -28,6 +28,7 @@ class ValidParameters { bool isValidParameter(string); private: map parameters; + map::iterator it; }; -- 2.39.2