From c25c956e4a3c7ca3271d48ee6215c72b2ec80c44 Mon Sep 17 00:00:00 2001 From: westcott Date: Mon, 23 Mar 2009 14:51:32 +0000 Subject: [PATCH] put back no command and worked on libshuff --- Mothur.xcodeproj/project.pbxproj | 6 ++++++ commandfactory.cpp | 7 +++++-- errorchecking.cpp | 24 ++++++++++++++++-------- libshuffcommand.cpp | 15 +++++++++++++-- mothur.cpp | 10 +++++----- nocommands.cpp | 29 +++++++++++++++++++++++++++++ nocommands.h | 27 +++++++++++++++++++++++++++ parselistcommand.cpp | 2 +- parsimonycommand.cpp | 4 ++-- readdistcommand.cpp | 4 ++-- readmatrix.cpp | 6 +++--- readotucommand.cpp | 2 +- readtreecommand.cpp | 2 +- 13 files changed, 111 insertions(+), 27 deletions(-) create mode 100644 nocommands.cpp create mode 100644 nocommands.h diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj index b9278ad..57af531 100644 --- a/Mothur.xcodeproj/project.pbxproj +++ b/Mothur.xcodeproj/project.pbxproj @@ -16,6 +16,7 @@ 3746109D0F40657600460C57 /* unifracunweightedcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3746109C0F40657600460C57 /* unifracunweightedcommand.cpp */; }; 374CD63F0F65832000D90B4A /* libshuffcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 374CD63E0F65832000D90B4A /* libshuffcommand.cpp */; }; 374CD6F10F65A4C100D90B4A /* coverage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 374CD6F00F65A4C100D90B4A /* coverage.cpp */; }; + 3765B47A0F77D15900C3EDC5 /* nocommands.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3765B4780F77D15900C3EDC5 /* nocommands.cpp */; }; 3782163D0F616079008E1F6D /* fullmatrix.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3782163C0F616079008E1F6D /* fullmatrix.cpp */; }; 379293C30F2DE73400B9034A /* treemap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 379293C20F2DE73400B9034A /* treemap.cpp */; }; 379294700F2E191800B9034A /* parsimonycommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3792946F0F2E191800B9034A /* parsimonycommand.cpp */; }; @@ -133,6 +134,8 @@ 374CD63E0F65832000D90B4A /* libshuffcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = libshuffcommand.cpp; sourceTree = ""; }; 374CD6EF0F65A4C100D90B4A /* coverage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = coverage.h; sourceTree = ""; }; 374CD6F00F65A4C100D90B4A /* coverage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = coverage.cpp; sourceTree = ""; }; + 3765B4780F77D15900C3EDC5 /* nocommands.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = nocommands.cpp; sourceTree = ""; }; + 3765B4790F77D15900C3EDC5 /* nocommands.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = nocommands.h; sourceTree = ""; }; 3782163B0F616079008E1F6D /* fullmatrix.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fullmatrix.h; sourceTree = ""; }; 3782163C0F616079008E1F6D /* fullmatrix.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = fullmatrix.cpp; sourceTree = ""; }; 379293C10F2DE73400B9034A /* treemap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = treemap.h; sourceTree = ""; }; @@ -485,6 +488,8 @@ 37D927E30F21331F001D4494 /* helpcommand.cpp */, 374CD63D0F65832000D90B4A /* libshuffcommand.h */, 374CD63E0F65832000D90B4A /* libshuffcommand.cpp */, + 3765B4790F77D15900C3EDC5 /* nocommands.h */, + 3765B4780F77D15900C3EDC5 /* nocommands.cpp */, 37D927FA0F21331F001D4494 /* parselistcommand.h */, 37D927F90F21331F001D4494 /* parselistcommand.cpp */, 3792946E0F2E191800B9034A /* parsimonycommand.h */, @@ -709,6 +714,7 @@ 3782163D0F616079008E1F6D /* fullmatrix.cpp in Sources */, 374CD63F0F65832000D90B4A /* libshuffcommand.cpp in Sources */, 374CD6F10F65A4C100D90B4A /* coverage.cpp in Sources */, + 3765B47A0F77D15900C3EDC5 /* nocommands.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/commandfactory.cpp b/commandfactory.cpp index b6f63aa..729895d 100644 --- a/commandfactory.cpp +++ b/commandfactory.cpp @@ -31,13 +31,15 @@ #include "unifracweightedcommand.h" #include "libshuffcommand.h" #include "mothur.h" +#include "nocommand.h" /***********************************************************/ /***********************************************************/ -CommandFactory::CommandFactory(){} - +CommandFactory::CommandFactory(){ + command = new NoCommand(); +} /***********************************************************/ /***********************************************************/ @@ -73,6 +75,7 @@ Command* CommandFactory::getCommand(string commandName){ else if(commandName == "get.label") { command = new GetlabelCommand(); } else if(commandName == "get.line") { command = new GetlineCommand(); } else if(commandName == "libshuff") { command = new LibShuffCommand(); } + else { command = new NoCommand(); } return command; } diff --git a/errorchecking.cpp b/errorchecking.cpp index 9a08462..cb2dce4 100644 --- a/errorchecking.cpp +++ b/errorchecking.cpp @@ -44,7 +44,10 @@ void ErrorCheck::refresh() { /******************************************************/ -ErrorCheck::~ErrorCheck() {} +ErrorCheck::~ErrorCheck() { + delete validCommand; + delete validParameter; +} /*******************************************************/ @@ -80,7 +83,7 @@ bool ErrorCheck::checkInput(string input) { splitAtComma(value, optionText); splitAtEquals(parameter, value); - //is it a valid parameter + //is it a valid parameter for the command if (validParameter->isValidParameter(parameter, commandName) != true) { return false; } if (parameter == "phylip" ) { phylipfile = value; } @@ -111,7 +114,8 @@ bool ErrorCheck::checkInput(string input) { if (errorFree) { //gets the last parameter and value value = optionText; splitAtEquals(parameter, value); - //is it a valid parameter + + //is it a valid parameter for the command if (validParameter->isValidParameter(parameter, commandName) != true) { return false; } if (parameter == "phylip" ) { phylipfile = value; } @@ -142,6 +146,7 @@ bool ErrorCheck::checkInput(string input) { //make sure the user does not use both the line and label parameters if ((line != "") && (label != "")) { cout << "You may use either the line or label parameters, but not both." << endl; return false; } + //check for valid files if (commandName == "read.dist") { validateReadFiles(); validateReadDist(); @@ -149,12 +154,15 @@ bool ErrorCheck::checkInput(string input) { //you want to do shared commands if ((listfile != "") && (groupfile != "")) { validateParseFiles(); //checks the listfile and groupfile parameters - }else if (listfile != "") { //you want to do single commands + //you want to do single commands + }else if ((listfile != "") || (rabundfile != "") || (sabundfile != "")){ validateReadFiles(); validateReadPhil(); - }else if ((listfile == "") && (sharedfile == "")) { - cout << "You must enter either a listfile or a sharedfile with the read.otu command. " << endl; return false; - }else{//you are reading a shared file + //you have not given a file + }else if ((listfile == "") && (sharedfile == "") && (rabundfile == "") && (sabundfile == "")) { + cout << "You must enter either a listfile, rabundfile, sabundfile or a sharedfile with the read.otu command. " << endl; return false; + //you want to do shared commands with a shared file + }else if (sharedfile != "") {//you are reading a shared file validateReadFiles(); } }else if (commandName == "read.tree") { @@ -172,7 +180,7 @@ bool ErrorCheck::checkInput(string input) { } if ((commandName == "libshuff") && ((globaldata->gMatrix == NULL) || (globaldata->gGroupmap == NULL))) { - cout << "You must read in a matrix and groupfile before you use the libshuff command. " << endl; return false; + cout << "You must read in a matrix and groupfile using the read.dist command, before you use the libshuff command. " << endl; return false; } if (commandName == "parsimony") { diff --git a/libshuffcommand.cpp b/libshuffcommand.cpp index a51b327..4b18675 100644 --- a/libshuffcommand.cpp +++ b/libshuffcommand.cpp @@ -105,6 +105,8 @@ int LibShuffCommand::execute(){ coverage->getValues(matrix, cValues, dist, "user"); + float distDiff = dist[0]; + //loop through each distance and load rsumdelta for (int p = 0; p < cValues.size(); p++) { //find delta values @@ -114,12 +116,16 @@ int LibShuffCommand::execute(){ //don't save AA to AA if (i != j) { //(Caa - Cab)^2 - deltaValues[p].push_back((cValues[p][i][i]-cValues[p][i][j]) * (cValues[p][i][i]-cValues[p][i][j])); + deltaValues[p].push_back(((cValues[p][i][i]-cValues[p][i][j]) * (cValues[p][i][i]-cValues[p][i][j])) * distDiff); sumDelta[count] += deltaValues[p][count]; count++; } } } + if (p < cValues.size() - 1) { + distDiff = dist[p+1] - dist[p]; +//cout << distDiff << endl; + } } printCoverageFile(); @@ -143,6 +149,8 @@ int LibShuffCommand::execute(){ coverage->getValues(matrix, cValues, dist, "random"); + distDiff = 1; + //loop through each distance and load rsumdelta for (int p = 0; p < cValues.size(); p++) { //find delta values @@ -152,12 +160,15 @@ int LibShuffCommand::execute(){ //don't save AA to AA if (i != j) { //(Caa - Cab)^2 - rsumDelta[count][m] += ((cValues[p][i][i]-cValues[p][i][j]) * (cValues[p][i][i]-cValues[p][i][j])); + rsumDelta[count][m] += (((cValues[p][i][i]-cValues[p][i][j]) * (cValues[p][i][i]-cValues[p][i][j])) * distDiff); count++; } } } + if (p < cValues.size() - 1) { + distDiff = dist[p+1] - dist[p]; + } } //clear out old Values diff --git a/mothur.cpp b/mothur.cpp index 5142ca2..8c55240 100644 --- a/mothur.cpp +++ b/mothur.cpp @@ -20,19 +20,19 @@ int main(int argc, char *argv[]){ //srand(54321); srand( (unsigned)time( NULL ) ); - Engine* dotur; + Engine* mothur; bool bail = 0; if(argc>1){ - dotur = new BatchEngine(argv[1]); + mothur = new BatchEngine(argv[1]); } else{ - dotur = new InteractEngine(); + mothur = new InteractEngine(); } - while(bail == 0) { bail = dotur->getInput(); } + while(bail == 0) { bail = mothur->getInput(); } - delete dotur; + delete mothur; return 0; } diff --git a/nocommands.cpp b/nocommands.cpp new file mode 100644 index 0000000..974fce4 --- /dev/null +++ b/nocommands.cpp @@ -0,0 +1,29 @@ +/* + * nocommand.cpp + * Dotur + * + * Created by Sarah Westcott on 1/2/09. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. + * + */ + +#include "nocommands.h" + +//********************************************************************************************************************** + +NoCommand::NoCommand(){} + +//********************************************************************************************************************** + +NoCommand::~NoCommand(){} + +//********************************************************************************************************************** + +int NoCommand::execute(){ + //Could choose to give more help here?fdsah + cout << "Invalid command." << "\n"; + cout << "For more information on command parameters use the help() command." << "\n"; + return 0; +} + +//********************************************************************************************************************** diff --git a/nocommands.h b/nocommands.h new file mode 100644 index 0000000..b529392 --- /dev/null +++ b/nocommands.h @@ -0,0 +1,27 @@ +#ifndef NOCOMMAND_H +#define NOCOMMAND_H +/* + * nocommand.h + * Dotur + * + * Created by Sarah Westcott on 1/2/09. + * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. + * + */ + +/* This command is run if the user enters an invalid command. */ + +#include "command.hpp" + +class NoCommand : public Command { + +public: + NoCommand(); + ~NoCommand(); + int execute(); + +private: + +}; + +#endif diff --git a/parselistcommand.cpp b/parselistcommand.cpp index 73fb565..1457c62 100644 --- a/parselistcommand.cpp +++ b/parselistcommand.cpp @@ -135,7 +135,7 @@ int ParseListCommand::execute(){ } //set groupmap for .shared commands - if (globaldata->gGroupmap != NULL) { delete globaldata->gGroupmap; } + //if (globaldata->gGroupmap != NULL) { delete globaldata->gGroupmap; } globaldata->gGroupmap = groupMap; return 0; diff --git a/parsimonycommand.cpp b/parsimonycommand.cpp index 421cac3..493af9b 100644 --- a/parsimonycommand.cpp +++ b/parsimonycommand.cpp @@ -168,7 +168,7 @@ int ParsimonyCommand::execute() { //reset globaldata's treemap if you just did random distrib if (randomtree != "") { //memory leak prevention - if (globaldata->gTreemap != NULL) { delete globaldata->gTreemap; } + //if (globaldata->gTreemap != NULL) { delete globaldata->gTreemap; } globaldata->gTreemap = savetmap; } @@ -298,7 +298,7 @@ void ParsimonyCommand::getUserInput() { //save tmap for later //memory leak prevention - if (globaldata->gTreemap != NULL) { delete globaldata->gTreemap; } + //if (globaldata->gTreemap != NULL) { delete globaldata->gTreemap; } globaldata->gTreemap = tmap; } diff --git a/readdistcommand.cpp b/readdistcommand.cpp index 9db835a..d8c3db1 100644 --- a/readdistcommand.cpp +++ b/readdistcommand.cpp @@ -21,7 +21,7 @@ ReadDistCommand::ReadDistCommand(){ else if (format == "matrix") { groupMap = new GroupMap(globaldata->getGroupFile()); groupMap->readMap(); - if (globaldata->gGroupmap != NULL) { delete globaldata->gGroupmap; } + //if (globaldata->gGroupmap != NULL) { delete globaldata->gGroupmap; } globaldata->gGroupmap = groupMap; } @@ -71,7 +71,7 @@ int ReadDistCommand::execute(){ openInputFile(filename, in); matrix = new FullMatrix(in); //reads the matrix file //memory leak prevention - if (globaldata->gMatrix != NULL) { delete globaldata->gMatrix; } + //if (globaldata->gMatrix != NULL) { delete globaldata->gMatrix; } globaldata->gMatrix = matrix; //save matrix for coverage commands }else { read->read(nameMap); diff --git a/readmatrix.cpp b/readmatrix.cpp index b2a2ffa..529eef5 100644 --- a/readmatrix.cpp +++ b/readmatrix.cpp @@ -348,20 +348,20 @@ void ReadPhilFile::read(GlobalData* globaldata){ } //memory leak prevention - if (globaldata->ginput != NULL) { delete globaldata->ginput; } + //if (globaldata->ginput != NULL) { delete globaldata->ginput; } globaldata->ginput = input; //saving to be used by collector and rarefact commands. if ((globaldata->getFormat() == "list") || (globaldata->getFormat() == "rabund") || (globaldata->getFormat() == "sabund")) {//you are reading a list, rabund or sabund file for collect, rarefaction or summary. order = input->getOrderVector(); //memory leak prevention - if (globaldata->gorder != NULL) { delete globaldata->gorder; } + //if (globaldata->gorder != NULL) { delete globaldata->gorder; } globaldata->gorder = order; //saving to be used by collect and rarefact commands. 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 collect.shared, rarefaction.shared, summary.shared, parselist command, or shared commands. //memory leak prevention - if (globaldata->gSharedList != NULL) { delete globaldata->gSharedList; } + //if (globaldata->gSharedList != NULL) { delete globaldata->gSharedList; } globaldata->gSharedList = SharedList; } } diff --git a/readotucommand.cpp b/readotucommand.cpp index 2a0d33f..7a48f2c 100644 --- a/readotucommand.cpp +++ b/readotucommand.cpp @@ -44,7 +44,7 @@ int ReadOtuCommand::execute(){ if (globaldata->getFormat() == "shared") { groupMap->readMap(); - if (globaldata->gGroupmap != NULL) { delete globaldata->gGroupmap; } + //if (globaldata->gGroupmap != NULL) { delete globaldata->gGroupmap; } globaldata->gGroupmap = groupMap; shared = new SharedCommand(); diff --git a/readtreecommand.cpp b/readtreecommand.cpp index 8124d53..6af28ad 100644 --- a/readtreecommand.cpp +++ b/readtreecommand.cpp @@ -20,7 +20,7 @@ ReadTreeCommand::ReadTreeCommand(){ treeMap->readMap(); //memory leak prevention - if (globaldata->gTreemap != NULL) { delete globaldata->gTreemap; } + //if (globaldata->gTreemap != NULL) { delete globaldata->gTreemap; } globaldata->gTreemap = treeMap; read = new ReadNewickTree(filename); -- 2.39.2