]> git.donarmstrong.com Git - mothur.git/commitdiff
put back no command and worked on libshuff
authorwestcott <westcott>
Mon, 23 Mar 2009 14:51:32 +0000 (14:51 +0000)
committerwestcott <westcott>
Mon, 23 Mar 2009 14:51:32 +0000 (14:51 +0000)
13 files changed:
Mothur.xcodeproj/project.pbxproj
commandfactory.cpp
errorchecking.cpp
libshuffcommand.cpp
mothur.cpp
nocommands.cpp [new file with mode: 0644]
nocommands.h [new file with mode: 0644]
parselistcommand.cpp
parsimonycommand.cpp
readdistcommand.cpp
readmatrix.cpp
readotucommand.cpp
readtreecommand.cpp

index b9278ad0feee18aa9fe4ee14cda0d093d7e8a9c9..57af531c164b323c10eef636b574d969a7c7ee48 100644 (file)
@@ -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 */; };
                374CD63E0F65832000D90B4A /* libshuffcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = libshuffcommand.cpp; sourceTree = "<group>"; };
                374CD6EF0F65A4C100D90B4A /* coverage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = coverage.h; sourceTree = "<group>"; };
                374CD6F00F65A4C100D90B4A /* coverage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = coverage.cpp; sourceTree = "<group>"; };
+               3765B4780F77D15900C3EDC5 /* nocommands.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = nocommands.cpp; sourceTree = "<group>"; };
+               3765B4790F77D15900C3EDC5 /* nocommands.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = nocommands.h; sourceTree = "<group>"; };
                3782163B0F616079008E1F6D /* fullmatrix.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fullmatrix.h; sourceTree = "<group>"; };
                3782163C0F616079008E1F6D /* fullmatrix.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = fullmatrix.cpp; sourceTree = "<group>"; };
                379293C10F2DE73400B9034A /* treemap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = treemap.h; sourceTree = "<group>"; };
                                37D927E30F21331F001D4494 /* helpcommand.cpp */,
                                374CD63D0F65832000D90B4A /* libshuffcommand.h */,
                                374CD63E0F65832000D90B4A /* libshuffcommand.cpp */,
+                               3765B4790F77D15900C3EDC5 /* nocommands.h */,
+                               3765B4780F77D15900C3EDC5 /* nocommands.cpp */,
                                37D927FA0F21331F001D4494 /* parselistcommand.h */,
                                37D927F90F21331F001D4494 /* parselistcommand.cpp */,
                                3792946E0F2E191800B9034A /* parsimonycommand.h */,
                                3782163D0F616079008E1F6D /* fullmatrix.cpp in Sources */,
                                374CD63F0F65832000D90B4A /* libshuffcommand.cpp in Sources */,
                                374CD6F10F65A4C100D90B4A /* coverage.cpp in Sources */,
+                               3765B47A0F77D15900C3EDC5 /* nocommands.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index b6f63aa8f873296ef0bc146e2bb0cdcf9edb835c..729895d853957e820a5bc6224ed3898873c3a336 100644 (file)
 #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;
        }
index 9a0846214bb97a9f4cce7fa42540b0e4a642dda0..cb2dce42fbf4f40e4c5e2a5107a6e1d33c1b89c7 100644 (file)
@@ -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") {
index a51b3270f855062a0e2ee92fab63779b38b50877..4b186754a6cd7876aebb17b5eb4c33691d7b4fff 100644 (file)
@@ -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
index 5142ca22eabb2d6a3121e6dc2701cb4a04fe9f1f..8c55240965b5481bae5a551488c6e3ac957ee494 100644 (file)
@@ -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 (file)
index 0000000..974fce4
--- /dev/null
@@ -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 (file)
index 0000000..b529392
--- /dev/null
@@ -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
index 73fb56593c781bcd0cee4e432318fd9ba82b1577..1457c62f383308fdfac0e4d9748c9797ba5af01f 100644 (file)
@@ -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;
index 421cac363feb5380787c8a52fe4e5ad2fe60c9f9..493af9b867e5542ee4c4c93acfa6c40a9c95fc5a 100644 (file)
@@ -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;
                
        }
index 9db835a2fb5ffe492b145e64213191fa8d901baa..d8c3db1c896b53c2f0d270a5c2d4df1ac9eed626 100644 (file)
@@ -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);
index b2a2ffac57ef83c9449172baa62856d78deca4a2..529eef5c7cf8b70e12f30dde6b4c2b661a01207f 100644 (file)
@@ -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;
                }
        }
index 2a0d33fe352b8e6f4621fd5d336b63ccfb5824b4..7a48f2c5b3b0146c4397325ca531c0bad9005146 100644 (file)
@@ -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();
index 8124d53415bda6035a3f6686d8ebc50a3ecb1419..6af28ad7788a351e1a320aaf433c800c2c529f1b 100644 (file)
@@ -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);