]> git.donarmstrong.com Git - mothur.git/commitdiff
fixing bugs while testing
authorwestcott <westcott>
Fri, 8 Apr 2011 13:30:14 +0000 (13:30 +0000)
committerwestcott <westcott>
Fri, 8 Apr 2011 13:30:14 +0000 (13:30 +0000)
15 files changed:
Mothur.xcodeproj/project.pbxproj
amovacommand.cpp
binsequencecommand.cpp
formatphylip.cpp
getlabelcommand.cpp
getlabelcommand.h
getrabundcommand.cpp
getsabundcommand.cpp
inputdata.cpp
mothurout.cpp
mothurout.h
readcluster.cpp
readphylip.cpp
readphylipvector.cpp
validparameter.cpp

index 9d88f25064191eecf67cf4998063737960191634..5a384ce0ad97441e03231aa207b3b0029f5ed96a 100644 (file)
                                A7E9B82412D37EC400DA6239 /* sharedutilities.h */,
                                A7E9B82D12D37EC400DA6239 /* singlelinkage.cpp */,
                                A7E9B83012D37EC400DA6239 /* slibshuff.cpp */,
-                               A7E9B83112D37EC400DA6239 /* slibshuff.h */,
                                A7E9B85112D37EC400DA6239 /* suffixdb.cpp */,
+                               A7E9B83112D37EC400DA6239 /* slibshuff.h */,
                                A7E9B85212D37EC400DA6239 /* suffixdb.hpp */,
                                A7E9B85312D37EC400DA6239 /* suffixnodes.cpp */,
                                A7E9B85412D37EC400DA6239 /* suffixnodes.hpp */,
index af867de3bf4811e00f98904f06935ac95a8313f3..f1e5f61197475b43d52d7dac46dab04cc7f657c2 100644 (file)
@@ -282,7 +282,7 @@ double AmovaCommand::runAMOVA(ofstream& AMOVAFile, map<string, vector<int> > gro
                m->mothurOut("df\t" + toString(dfAmong) + '\t' + toString(dfWithin) + '\t' + toString(dfTotal) + '\n');
 
                AMOVAFile << "MS\t" << MSAmong << '\t' << MSWithin << endl << endl;
-               m->mothurOut("MS\t" + toString(MSAmong) + '\t' + toString(MSWithin) + "\n");
+               m->mothurOut("MS\t" + toString(MSAmong) + '\t' + toString(MSWithin) + "\n\n");
 
                AMOVAFile << "Fs:\t" << Fs << endl;
                m->mothurOut("Fs:\t" + toString(Fs) + '\n');
index 3f9378fbdb4650078cf27091326c0dc5e87c993a..34965f624cc789e830783302f4ccd36993e28ea4 100644 (file)
@@ -281,10 +281,6 @@ int BinSeqCommand::execute(){
                
                if(m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str());         }  return 0; }  
                
-               delete input;  
-               delete fasta; 
-               if (groupfile != "") {  delete groupMap;   } 
-               
                m->mothurOutEndLine();
                m->mothurOut("Output File Names: "); m->mothurOutEndLine();
                for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }
index 60a3b4136810515bc628b334d948fb0d957605d2..0390a806f97c5397d046c1384c1b4356280e78d9 100644 (file)
@@ -24,7 +24,12 @@ int FormatPhylipMatrix::read(NameAssignment* nameMap){
                        string name;
                        ofstream out;
                        
-                       fileHandle >> nseqs >> name;
+                       string numTest;
+                       fileHandle >> numTest >> name;
+                       
+                       if (!m->isContainingOnlyDigits(numTest)) { m->mothurOut("[ERROR]: expected a number and got " + numTest + ", quitting."); m->mothurOutEndLine(); exit(1); }
+                       else { convert(numTest, nseqs); }
+               
                                                
                        list = new ListVector(nseqs);
                        list->set(0, name);
index 236eef24acfdb4c0b82d2802abe63562db53ef4a..381a9508a0222e3bbec90930215513b7048a9770 100644 (file)
@@ -16,7 +16,6 @@ vector<string> GetlabelCommand::setParameters(){
                CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(plist);
                CommandParameter prabund("rabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(prabund);
                CommandParameter psabund("sabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(psabund);
-               CommandParameter pshared("shared", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(pshared);            
                CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
                CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
                
@@ -44,7 +43,7 @@ GetlabelCommand::GetlabelCommand(){
 string GetlabelCommand::getHelpString(){       
        try {
                string helpString = "";
-               helpString += "The get.label command parameters are list, sabund, rabund and shared file. \n";
+               helpString += "The get.label command parameters are list, sabund and rabund file. \n";
                helpString += "The get.label command should be in the following format: \n";
                helpString += "get.label()\n";
                helpString += "Example get.label().\n";
@@ -83,13 +82,6 @@ GetlabelCommand::GetlabelCommand(string option)  {
                        if (inputDir == "not found"){   inputDir = "";          }
                        else {
                                string path;
-                               it = parameters.find("shared");
-                               //user has given a template file
-                               if(it != parameters.end()){ 
-                                       path = m->hasPath(it->second);
-                                       //if the user has not given a path then, add inputdir. else leave path alone.
-                                       if (path == "") {       parameters["shared"] = inputDir + it->second;           }
-                               }
                                
                                it = parameters.find("rabund");
                                //user has given a template file
@@ -132,35 +124,26 @@ GetlabelCommand::GetlabelCommand(string option)  {
                        else if (rabundfile == "not found") { rabundfile = ""; }
                        else {  format = "rabund"; inputfile = rabundfile; }
                        
-                       sharedfile = validParameter.validFile(parameters, "shared", true);
-                       if (sharedfile == "not open") { sharedfile = ""; abort = true; }        
-                       else if (sharedfile == "not found") { sharedfile = ""; }
-                       else {  format = "sharedfile"; inputfile = sharedfile; }
-                       
-                       if ((sharedfile == "") && (listfile == "") && (rabundfile == "") && (sabundfile == "")) { 
+                       if ((listfile == "") && (rabundfile == "") && (sabundfile == "")) { 
                                //is there are current file available for any of these?
-                               //give priority to shared, then list, then rabund, then sabund
+                               //give priority to list, then rabund, then sabund
                                //if there is a current shared file, use it
-                               sharedfile = m->getSharedFile(); 
-                               if (sharedfile != "") { inputfile = sharedfile; format = "sharedfile"; m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); }
+                               
+                               listfile = m->getListFile(); 
+                               if (listfile != "") { inputfile = listfile; format = "list"; m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); }
                                else { 
-                                       listfile = m->getListFile(); 
-                                       if (listfile != "") { inputfile = listfile; format = "list"; m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); }
+                                       rabundfile = m->getRabundFile(); 
+                                       if (rabundfile != "") { inputfile = rabundfile; format = "rabund"; m->mothurOut("Using " + rabundfile + " as input file for the rabund parameter."); m->mothurOutEndLine(); }
                                        else { 
-                                               rabundfile = m->getRabundFile(); 
-                                               if (rabundfile != "") { inputfile = rabundfile; format = "rabund"; m->mothurOut("Using " + rabundfile + " as input file for the rabund parameter."); m->mothurOutEndLine(); }
+                                               sabundfile = m->getSabundFile(); 
+                                               if (sabundfile != "") { inputfile = sabundfile; format = "sabund"; m->mothurOut("Using " + sabundfile + " as input file for the sabund parameter."); m->mothurOutEndLine(); }
                                                else { 
-                                                       sabundfile = m->getSabundFile(); 
-                                                       if (sabundfile != "") { inputfile = sabundfile; format = "sabund"; m->mothurOut("Using " + sabundfile + " as input file for the sabund parameter."); m->mothurOutEndLine(); }
-                                                       else { 
-                                                               m->mothurOut("No valid current files. You must provide a list, sabund, rabund or shared file before you can use the collect.single command."); m->mothurOutEndLine(); 
-                                                               abort = true;
-                                                       }
+                                                       m->mothurOut("No valid current files. You must provide a list, sabund or rabund file."); m->mothurOutEndLine(); 
+                                                       abort = true;
                                                }
                                        }
                                }
                        }
-                       
                }
 
        }
@@ -184,10 +167,10 @@ int GetlabelCommand::execute(){
                        
                        if (m->control_pressed) { delete input;  delete order; return 0; }
                        
-                       m->mothurOut(label); m->mothurOutEndLine();
-                       
                        label = order->getLabel();      
                        
+                       m->mothurOut(label); m->mothurOutEndLine();
+                       
                        delete order;           
                        order = input->getOrderVector();
                }
index 3aaa92d515948f9d927f3ff377629f3e376ff62e..606daf42ab685a4070d8aa54c21a839cdda91773 100644 (file)
@@ -31,7 +31,7 @@ public:
        
        
 private:
-       string inputfile, listfile, rabundfile, sabundfile, sharedfile, format;
+       string inputfile, listfile, rabundfile, sabundfile, format;
        bool abort;
        vector<string> outputNames;
 };
index 65eedaa39f1c2efaccc97ac4b2f44f325ddf6a9f..2f49a3b37181603f88065629ddc73f5194be49d9 100644 (file)
@@ -194,8 +194,6 @@ int GetRAbundCommand::execute(){
                                        
                                        if(sorted)      {   rabund->print(out);                         }
                                        else            {       rabund->nonSortedPrint(out);    }
-                                       
-                                       delete rabund;
                                                                                                                        
                                        processedLabels.insert(rabund->getLabel());
                                        userLabels.erase(rabund->getLabel());
@@ -214,8 +212,6 @@ int GetRAbundCommand::execute(){
                                        if(sorted)      {   rabund->print(out);                         }
                                        else            {       rabund->nonSortedPrint(out);    }
 
-                                       delete rabund;
-
                                        processedLabels.insert(rabund->getLabel());
                                        userLabels.erase(rabund->getLabel());
                                        
index ebfa839161fc3d59cd27f9a2f8e2e24743b85e7e..820868416b7bfc9bebcc27c8f73c24c6ddb7bbb4 100644 (file)
@@ -186,7 +186,6 @@ int GetSAbundCommand::execute(){
                                        m->mothurOut(sabund->getLabel());  m->mothurOutEndLine();
                                        
                                        sabund->print(out);
-                                       delete sabund;
                                        
                                if (m->control_pressed) { outputTypes.clear();  out.close(); remove(filename.c_str());  delete sabund; delete input;  return 0; }
 
@@ -202,7 +201,6 @@ int GetSAbundCommand::execute(){
                                        
                                        m->mothurOut(sabund->getLabel());  m->mothurOutEndLine();
                                        sabund->print(out);
-                                       delete sabund;
                                        
                                        if (m->control_pressed) {  outputTypes.clear(); out.close(); remove(filename.c_str());  delete sabund; delete input;  return 0; }
 
index ec23955513f42c218ed750be5471eb23ee08cd40..08bab60dbd71f4e4c4d0b56472ccb199a026d85b 100644 (file)
@@ -292,7 +292,7 @@ OrderVector* InputData::getOrderVector(){
                        else if(format == "sabund"){
                                input = new SAbundVector(fileHandle);
                        }
-                       
+                                               
                        m->gobble(fileHandle);
                        
                        output = new OrderVector();     
@@ -394,7 +394,7 @@ OrderVector* InputData::getOrderVector(string label){
                                }
 
                        }
-                       
+                                               
                        in.close();             
 
                        output = new OrderVector();
@@ -622,8 +622,7 @@ SAbundVector* InputData::getSAbundVector(){
                        }
                        else if(format == "sabund"){
                                input = new SAbundVector(fileHandle);
-                       }
-                                       
+                       }                                       
                        m->gobble(fileHandle);
 
                        sabund = new SAbundVector();
@@ -762,7 +761,7 @@ RAbundVector* InputData::getRAbundVector(){
                        else if(format == "sabund"){
                                input = new SAbundVector(fileHandle);
                        }
-                                       
+                       
                        m->gobble(fileHandle);
 
                        rabund = new RAbundVector();
@@ -862,7 +861,8 @@ RAbundVector* InputData::getRAbundVector(string label){
                                        
                                }
 
-                       }
+                       }                       
+                       
                        
                        in.close();             
 
index 59e4fdcc080fe91e946dbc7d3b2a66d9e1dc02a0..7309c174c83027437e67026869f53161101e11bc 100644 (file)
@@ -1731,6 +1731,23 @@ bool MothurOut::checkReleaseVersion(ifstream& file, string version) {
        }
 }
 /**************************************************************************************************/
+bool MothurOut::isContainingOnlyDigits(string input) {
+       try{
+               
+               //are you a digit in ascii code
+               for (int i = 0;i < input.length(); i++){
+                       if( input[i]>47 && input[i]<58){}
+                       else { return false; }
+               }
+               
+               return true;
+       }
+       catch(exception& e) {
+               errorOut(e, "MothurOut", "isContainingOnlyDigits");             
+               exit(1);
+       }
+}
+/**************************************************************************************************/
 
 
 
index 6654455063c37b56030a89c09c8d6ee71dcdf4be..f20d5c197df59b06c3f5069709aa4e036436a768 100644 (file)
@@ -75,6 +75,7 @@ class MothurOut {
                int getNumSeqs(ifstream&);
                int getNumNames(string);
                bool isTrue(string);
+               bool isContainingOnlyDigits(string);
        
                
                //string manipulation
index 025d718dea254f909ab57f98706216366aa3e710..497fc804faadc760bdcc1684f1a45a856ddd9ab1 100644 (file)
@@ -60,8 +60,13 @@ int ReadCluster::convertPhylip2Column(NameAssignment* nameMap){
                int square, nseqs;
                string name;
                vector<string> matrixNames;
-        
-               in >> nseqs >> name;
+               
+               string numTest;
+               in >> numTest >> name;
+               
+               if (!m->isContainingOnlyDigits(numTest)) { m->mothurOut("[ERROR]: expected a number and got " + numTest + ", quitting."); m->mothurOutEndLine(); exit(1); }
+               else { convert(numTest, nseqs); }
+               
                rowToName[0] = name;
                matrixNames.push_back(name);
                
index b13dc25c0eded92a950bfc41a782075624e47fdd..1c529b26f15fdfa172c8a0f7ebcf20187e87b03b 100644 (file)
@@ -36,9 +36,13 @@ int ReadPhylipMatrix::read(NameAssignment* nameMap){
                         int square, nseqs;
                         string name;
                         vector<string> matrixNames;
-        
-                        fileHandle >> nseqs >> name;
-
+                                               
+                                               string numTest;
+                                               fileHandle >> numTest >> name;
+                       
+                                               if (!m->isContainingOnlyDigits(numTest)) { m->mothurOut("[ERROR]: expected a number and got " + numTest + ", quitting."); m->mothurOutEndLine(); exit(1); }
+                                               else { convert(numTest, nseqs); }
+                       
                         matrixNames.push_back(name);
 
                         if(nameMap == NULL){
index c3ffccef2aa6c73ef8922a2265d131d52ce40f29..85f4777dde02bd4980411d8d48015d2cf06b0e50 100644 (file)
@@ -34,7 +34,11 @@ vector<string> ReadPhylipVector::read(vector< vector<double> >& matrix) {
                int numSeqs;
                string name;
                
-               in >> numSeqs >> name; 
+               string numTest;
+               in >> numTest >> name;
+               
+               if (!m->isContainingOnlyDigits(numTest)) { m->mothurOut("[ERROR]: expected a number and got " + numTest + ". I suspect you entered a column formatted file as a phylip file, quitting."); m->mothurOutEndLine(); exit(1); }
+               else { convert(numTest, numSeqs); }
                
                while((d=in.get()) != EOF){
                        
index 4b263b491c59c0cd14abaf0d4553ffa20fdd26f6..7855ddedd11f05b8e8c628e2d5c49c82be646a9b 100644 (file)
@@ -291,6 +291,18 @@ string ValidParameters::validFile(map<string, string>& container, string paramet
                                        m->mothurOut("Unable to open " + container[parameter]); m->mothurOutEndLine();
                                        return "not open"; 
                                }
+                               
+                               //check phylip file to make sure its really phylip and not column
+                               if ((it->first == "phylip") && (ableToOpen != 1)) {
+                                       ifstream inPhylip;
+                                       m->openInputFile(it->second, inPhylip);
+                                                                               
+                                       string numTest, name;
+                                       inPhylip >> numTest >> name;
+                                       inPhylip.close();
+                                       
+                                       if (!m->isContainingOnlyDigits(numTest)) { m->mothurOut("[ERROR]: expected a number and got " + numTest + ". I suspect you entered a column formatted file as a phylip file, aborting."); m->mothurOutEndLine(); return "not found"; }
+                               }
                        }
                }else { return "not found"; }