]> git.donarmstrong.com Git - mothur.git/commitdiff
merged pat's trim seqs edits with sarah's major overhaul of global data; also added...
authorpschloss <pschloss>
Sun, 14 Jun 2009 20:59:57 +0000 (20:59 +0000)
committerpschloss <pschloss>
Sun, 14 Jun 2009 20:59:57 +0000 (20:59 +0000)
85 files changed:
Mothur.xcodeproj/project.pbxproj
aligncommand.cpp
aligncommand.h
binsequencecommand.cpp
binsequencecommand.h
bootstrapsharedcommand.cpp
bootstrapsharedcommand.h
clustercommand.cpp
clustercommand.h
collectcommand.cpp
collectcommand.h
collectsharedcommand.cpp
collectsharedcommand.h
command.hpp
commandfactory.cpp
deconvolutecommand.cpp
deconvolutecommand.h
distancecommand.cpp
distancecommand.h
fileoutput.h
filterseqscommand.cpp
filterseqscommand.h
getlinecommand.cpp
getlinecommand.h
getoturepcommand.cpp
getoturepcommand.h
getrabundcommand.cpp
getrabundcommand.h
getsabundcommand.cpp
getsabundcommand.h
globaldata.cpp
globaldata.hpp
heatmap.cpp
heatmapcommand.cpp
heatmapcommand.h
heatmapsimcommand.cpp
helpcommand.cpp
helpcommand.h
libshuffcommand.cpp
libshuffcommand.h
matrixoutputcommand.cpp
matrixoutputcommand.h
mergefilecommand.cpp [new file with mode: 0644]
mergefilecommand.h [new file with mode: 0644]
optionparser.cpp
optionparser.h
parsimonycommand.cpp
parsimonycommand.h
rarefactcommand.cpp
rarefactcommand.h
rarefactsharedcommand.cpp
rarefactsharedcommand.h
readdistcommand.cpp
readdistcommand.h
readotucommand.cpp
readotucommand.h
readtreecommand.cpp
readtreecommand.h
reversecommand.cpp
reversecommand.h
screenseqscommand.cpp
screenseqscommand.h
seqsummarycommand.cpp
seqsummarycommand.h
sequence.cpp
sequencedb.cpp
sequencedb.h
shen.cpp
shen.h
summarycommand.cpp
summarycommand.h
summarysharedcommand.cpp
tree.h
treegroupscommand.cpp
treegroupscommand.h
trimseqscommand.cpp
trimseqscommand.h
unifracunweightedcommand.cpp
unifracunweightedcommand.h
unifracweightedcommand.cpp
unifracweightedcommand.h
venn.cpp
venn.h
venncommand.cpp
venncommand.h

index 32077f3a2d6e41cf6557aa4162fa9a23c3dee352..6244917530ee18b9f7ac9033bd16e8c5b6ed147b 100644 (file)
                7E412F490F8D21B600381DD0 /* slibshuff.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7E412F480F8D21B600381DD0 /* slibshuff.cpp */; };
                7E412FEA0F8D3E2C00381DD0 /* libshuff.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7E412FE90F8D3E2C00381DD0 /* libshuff.cpp */; };
                7E4130F80F8E58FA00381DD0 /* dlibshuff.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7E4130F60F8E58FA00381DD0 /* dlibshuff.cpp */; };
+               7E5A17AF0FE57292003C6A03 /* mergefilecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7E5A17AE0FE57292003C6A03 /* mergefilecommand.cpp */; };
                7EC3D4550FA0FFF900338DA5 /* coverage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7EC3D4500FA0FFF900338DA5 /* coverage.cpp */; };
                7EC3D4560FA0FFF900338DA5 /* whittaker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7EC3D4530FA0FFF900338DA5 /* whittaker.cpp */; };
                8DD76F6A0486A84900D96B5E /* Mothur.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = C6859E8B029090EE04C91782 /* Mothur.1 */; };
                7E412FE90F8D3E2C00381DD0 /* libshuff.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = libshuff.cpp; sourceTree = SOURCE_ROOT; };
                7E4130F60F8E58FA00381DD0 /* dlibshuff.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = dlibshuff.cpp; sourceTree = SOURCE_ROOT; };
                7E4130F70F8E58FA00381DD0 /* dlibshuff.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = dlibshuff.h; sourceTree = SOURCE_ROOT; };
+               7E5A17AD0FE57292003C6A03 /* mergefilecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mergefilecommand.h; sourceTree = "<group>"; };
+               7E5A17AE0FE57292003C6A03 /* mergefilecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = mergefilecommand.cpp; sourceTree = "<group>"; };
                7EC3D4500FA0FFF900338DA5 /* coverage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = coverage.cpp; sourceTree = SOURCE_ROOT; };
                7EC3D4510FA0FFF900338DA5 /* coverage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = coverage.h; sourceTree = SOURCE_ROOT; };
                7EC3D4520FA0FFF900338DA5 /* sharedanderberg.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedanderberg.h; sourceTree = SOURCE_ROOT; };
                37D928A90F2133E5001D4494 /* commands */ = {
                        isa = PBXGroup;
                        children = (
+                               7E5A17AE0FE57292003C6A03 /* mergefilecommand.cpp */,
+                               7E5A17AD0FE57292003C6A03 /* mergefilecommand.h */,
                                37D927CD0F21331F001D4494 /* command.hpp */,
                                378DC5CD0FBDE1C8003B8607 /* aligncommand.h */,
                                378DC5CE0FBDE1C8003B8607 /* aligncommand.cpp */,
                                378598660FDD497000EF9D03 /* heatmapsimcommand.cpp in Sources */,
                                378598740FDD4C1500EF9D03 /* heatmapsim.cpp in Sources */,
                                378599100FDD7E8E00EF9D03 /* optionparser.cpp in Sources */,
+                               7E5A17AF0FE57292003C6A03 /* mergefilecommand.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 4b9dedc97c0b6003f3d4cb49f76de2bac5f2beab..2811f1fd7e6d404c557dff149cce8860f80f99f0 100644 (file)
  *     allows for a global alignment and not the local alignment provided by bLAst.  Furthermore, it has the potential to
  *     provide a better alignment because of the banding method employed by blast (I'm not sure about this).
  *
- *     to compile type:
- *             make
- *
- *     for basic instructions on how to run nastPlus type:
- *             ./nastPlus
  */
 
 #include "aligncommand.h"
 #include "sequence.hpp"
 
-#include "alignment.hpp"
 #include "gotohoverlap.hpp"
 #include "needlemanoverlap.hpp"
 #include "blastalign.hpp"
 #include "noalign.hpp"
 
-#include "database.hpp"
 #include "kmerdb.hpp"
 #include "suffixdb.hpp"
 #include "blastdb.hpp"
 
 
 //**********************************************************************************************************************
+
 AlignCommand::AlignCommand(string option){
        try {
-               globaldata = GlobalData::getInstance();
+//             globaldata = GlobalData::getInstance();
                abort = false;
                
                //allow user to run help
                if(option == "help") { help(); abort = true; }
                
                else {
+
                        //valid paramters for this command
-                       string AlignArray[] =  {"fasta","candidate","search","ksize","align","match","mismatch","gapopen","gapextend"};
+                       string AlignArray[] =  {"template","candidate","search","ksize","align","match","mismatch","gapopen","gapextend", "processors"};
                        vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
                        
-                       parser = new OptionParser();
-
-                       parser->parse(option, parameters);      delete parser; 
+                       OptionParser parser(option);
+                       map<string, string> parameters = parser.getParameters(); 
                        
-                       ValidParameters* validParameter = new ValidParameters();
+                       ValidParameters validParameter;
                
                        //check to make sure all parameters are valid for command
-                       for (it = parameters.begin(); it != parameters.end(); it++) { 
-                               if (validParameter->isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        //check for required parameters
-                       templateFileName = validParameter->validFile(parameters, "fasta", true);
-                       if (templateFileName == "not found") { cout << "fasta is a required parameter for the align.seqs command." << endl; abort = true; }
+                       templateFileName = validParameter.validFile(parameters, "template", true);
+                       if (templateFileName == "not found") { cout << "template is a required parameter for the align.seqs command." << endl; abort = true; }
                        else if (templateFileName == "not open") { abort = true; }      
-                       else { globaldata->setFastaFile(templateFileName); }
                
-                       candidateFileName = validParameter->validFile(parameters, "candidate", true);
+                       candidateFileName = validParameter.validFile(parameters, "candidate", true);
                        if (candidateFileName == "not found") { cout << "candidate is a required parameter for the align.seqs command." << endl; abort = true; }
                        else if (candidateFileName == "not open") { abort = true; }     
-                       else { 
-                               globaldata->setCandidateFile(candidateFileName);
-                               openInputFile(candidateFileName, in);           
-                       }
                        
-               
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
                        string temp;
-                       temp = validParameter->validFile(parameters, "ksize", false);                   if (temp == "not found") { temp = "8"; }
+                       temp = validParameter.validFile(parameters, "ksize", false);            if (temp == "not found"){       temp = "8";                             }
                        convert(temp, kmerSize); 
                
-                       temp = validParameter->validFile(parameters, "match", false);                   if (temp == "not found") { temp = "1.0"; }
+                       temp = validParameter.validFile(parameters, "match", false);            if (temp == "not found"){       temp = "1.0";                   }
                        convert(temp, match);  
 
-                       temp = validParameter->validFile(parameters, "mismatch", false);                        if (temp == "not found") { temp = "-1.0"; }
+                       temp = validParameter.validFile(parameters, "mismatch", false);         if (temp == "not found"){       temp = "-1.0";                  }
                        convert(temp, misMatch);  
 
-                       temp = validParameter->validFile(parameters, "gapopen", false);                 if (temp == "not found") { temp = "-1.0"; }
+                       temp = validParameter.validFile(parameters, "gapopen", false);          if (temp == "not found"){       temp = "-1.0";                  }
                        convert(temp, gapOpen);  
 
-                       temp = validParameter->validFile(parameters, "gapextend", false);               if (temp == "not found") { temp = "-2.0"; }
+                       temp = validParameter.validFile(parameters, "gapextend", false);        if (temp == "not found"){       temp = "-2.0";                  }
                        convert(temp, gapExtend); 
                
-                       search = validParameter->validFile(parameters, "search", false);                        if (search == "not found")      { search = "kmer";              }
-                       align = validParameter->validFile(parameters, "align", false);                  if (align == "not found")       { align = "needleman";  }
+                       temp = validParameter.validFile(parameters, "processors", false);       if (temp == "not found"){       temp = "1";                             }
+                       convert(temp, processors); 
+
+                       search = validParameter.validFile(parameters, "search", false);         if (search == "not found"){     search = "kmer";                }
                        
-                       delete validParameter;
+                       align = validParameter.validFile(parameters, "align", false);           if (align == "not found"){      align = "needleman";    }
                }
 
        }
@@ -114,9 +104,11 @@ AlignCommand::AlignCommand(string option){
 
 //**********************************************************************************************************************
 
-AlignCommand::~AlignCommand(){
-       
+AlignCommand::~AlignCommand(){                 
+       delete templateDB;
+       delete alignment;
 }
+
 //**********************************************************************************************************************
 
 void AlignCommand::help(){
@@ -155,7 +147,7 @@ int AlignCommand::execute(){
        
                srand( (unsigned)time( NULL ) );  //needed to assign names to temporary files
                
-               Database* templateDB;
+
                if(search == "kmer")                    {       templateDB = new KmerDB(templateFileName, kmerSize);    }
                else if(search == "suffix")             {       templateDB = new SuffixDB(templateFileName);                    }
                else if(search == "blast")              {       templateDB = new BlastDB(templateFileName, gapOpen, gapExtend, match, misMatch);        }
@@ -164,7 +156,6 @@ int AlignCommand::execute(){
                        templateDB = new KmerDB(templateFileName, kmerSize);
                }
        
-               Alignment* alignment;
                if(align == "gotoh")                    {       alignment = new GotohOverlap(gapOpen, gapExtend, match, misMatch, 3000);        }
                else if(align == "needleman")   {       alignment = new NeedlemanOverlap(gapOpen, match, misMatch, 3000);                       }
                else if(align == "blast")               {       alignment = new BlastAlignment(gapOpen, gapExtend, match, misMatch);            }
@@ -173,64 +164,244 @@ int AlignCommand::execute(){
                        cout << align << " is not a valid alignment option. I will run the command using needleman." << endl;
                        alignment = new NeedlemanOverlap(gapOpen, match, misMatch, 3000);
                }
-                               
-               int numFastaSeqs=count(istreambuf_iterator<char>(in),istreambuf_iterator<char>(), '>');
-               in.seekg(0);
-       
-               string candidateAligngmentFName = candidateFileName.substr(0,candidateFileName.find_last_of(".")+1) + "align";
-               ofstream candidateAlignmentFile;
-               openOutputFile(candidateAligngmentFName, candidateAlignmentFile);
+               
+               string alignFileName = candidateFileName.substr(0,candidateFileName.find_last_of(".")+1) + "align";
+               string reportFileName = candidateFileName.substr(0,candidateFileName.find_last_of(".")+1) + "align.report";
+               
+               int numFastaSeqs = 0;
+               int start = time(NULL);
+               
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+               if(processors == 1){
+                       ifstream inFASTA;
+                       openInputFile(candidateFileName, inFASTA);
+                       numFastaSeqs=count(istreambuf_iterator<char>(inFASTA),istreambuf_iterator<char>(), '>');
+                       inFASTA.close();
+                       
+                       lines.push_back(new linePair(0, numFastaSeqs));
+                       
+                       driver(lines[0], alignFileName, reportFileName);
+               }
+               else{
+                       vector<int> positions;
+                       
+                       ifstream inFASTA;
+                       openInputFile(candidateFileName, inFASTA);
 
-               string candidateReportFName = candidateFileName.substr(0,candidateFileName.find_last_of(".")+1) + "align.report";
-               NastReport report(candidateReportFName);
+                       while(!inFASTA.eof()){
+                               char c = inFASTA.get();
+                               if(c == '>'){   positions.push_back(inFASTA.tellg());   }
+                               while (!inFASTA.eof())  {       c = inFASTA.get(); if (c == 10 || c == 13){     break;  }       } // get rest of line if there's any crap there
+                       }
+                       inFASTA.close();
+                       
+                       numFastaSeqs = positions.size();
+                       
+                       int numSeqsPerProcessor = numFastaSeqs / processors;
+                       
+                       for (int i = 0; i < processors; i++) {
+                               int startPos = positions[ i * numSeqsPerProcessor ];
+                               if(i == processors - 1){
+                                       numSeqsPerProcessor = numFastaSeqs - i * numSeqsPerProcessor;
+                               }
+                               lines.push_back(new linePair(startPos, numSeqsPerProcessor));
+                       }
+                       createProcesses(alignFileName, reportFileName); 
 
-               cout << "We are going to align the " << numFastaSeqs << " sequences in " << candidateFileName << "..." << endl;
-               cout.flush();
-       
-               int start = time(NULL);
+                       
+                       //append and remove temp files
+                       map<int, int>::iterator it = processIDS.begin();
+                       rename((alignFileName + toString(it->second) + ".temp").c_str(), alignFileName.c_str());
+                       rename((reportFileName + toString(it->second) + ".temp").c_str(), alignFileName.c_str());
+                       it++;
+                       
+                       for (; it != processIDS.end(); it++) {
+                               appendAlignFiles((alignFileName + toString(it->second) + ".temp"), alignFileName);
+                               remove((alignFileName + toString(it->second) + ".temp").c_str());
 
-               for(int i=0;i<numFastaSeqs;i++){
+                               appendReportFiles((reportFileName + toString(it->second) + ".temp"), reportFileName);
+                               remove((reportFileName + toString(it->second) + ".temp").c_str());
+                       }
+               }
+#else
+               ifstream inFASTA;
+               openInputFile(candidateFileName, inFASTA);
+               numFastaSeqs=count(istreambuf_iterator<char>(inFASTA),istreambuf_iterator<char>(), '>');
+               inFASTA.close();
+               
+               lines.push_back(new linePair(0, numFastaSeqs));
+               
+               driver(lines[0], alignFileName, reportFileName);
+#endif
 
-                       Sequence* candidateSeq = new Sequence(in);
-                       report.setCandidate(candidateSeq);
+               cout << "It took " << time(NULL) - start << " secs to align " << numFastaSeqs << " sequences" << endl;
+               cout << endl;
+
+
+                               
+               return 0;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the AlignCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the AlignCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
 
+//**********************************************************************************************************************
+
+int AlignCommand::driver(linePair* line, string alignFName, string reportFName){
+       try {
+               ofstream alignmentFile;
+               openOutputFile(alignFName, alignmentFile);
+               NastReport report(reportFName);
+               
+               ifstream inFASTA;
+               openInputFile(candidateFileName, inFASTA);
+               inFASTA.seekg(line->start);
+               
+               for(int i=0;i<line->numSeqs;i++){
+                       
+                       Sequence* candidateSeq = new Sequence(inFASTA);
+                       report.setCandidate(candidateSeq);
+                       
                        Sequence* templateSeq = templateDB->findClosestSequence(candidateSeq);
                        report.setTemplate(templateSeq);
                        report.setSearchParameters(search, templateDB->getSearchScore());
                        
-                               
                        Nast nast(alignment, candidateSeq, templateSeq);
                        report.setAlignmentParameters(align, alignment);
                        report.setNastParameters(nast);
+                       
+                       alignmentFile << '>' << candidateSeq->getName() << '\n' << candidateSeq->getAligned() << endl;
+                       
+                       report.print();
+                       
+                       delete candidateSeq;            
+               }
+                       
+               return 1;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the AlignCommand class Function driver. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the AlignCommand class function driver. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
 
-                       candidateAlignmentFile << '>' << candidateSeq->getName() << '\n' << candidateSeq->getAligned() << endl;
-                       candidateAlignmentFile.flush();
+/**************************************************************************************************/
 
-                       if((i+1) % 100 == 0){
-                               cout << "It has taken " << time(NULL) - start << " secs to align " << i+1 << " sequences" << endl;
-                       }
-                       report.print();
+void AlignCommand::createProcesses(string alignFileName, string reportFileName) {
+       try {
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+               int process = 0;
+               processIDS.clear();
                
-                       delete candidateSeq;            
+               //loop through and create all the processes you want
+               while (process != processors) {
+                       int pid = fork();
+                                               
+                       if (pid > 0) {
+                               processIDS[lines[process]->numSeqs] = pid;  //create map from line number to pid so you can append files in correct order later
+                               process++;
+                       }else if (pid == 0){
+                               driver(lines[process], alignFileName + toString(getpid()) + ".temp", reportFileName + toString(getpid()) + ".temp");
+                               exit(0);
+                       }else { cout << "unable to spawn the necessary processes." << endl; exit(0); }
                }
                
-               cout << "It took " << time(NULL) - start << " secs to align " << numFastaSeqs << " sequences" << endl;
-               cout << endl;
+               //force parent to wait until all the processes are done
+               for (map<int, int>::iterator it = processIDS.begin(); it != processIDS.end(); it++) { 
+                       int temp = it->second;
+                       wait(&temp);
+               }
+#endif         
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the AlignCommand class Function createProcesses. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the AlignCommand class function createProcesses. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
 
-               delete templateDB;
-               delete alignment;
+/**************************************************************************************************/
 
-                               
-               return 0;
+void AlignCommand::appendAlignFiles(string temp, string filename) {
+       try{
+               
+               //open output file in append mode
+               ofstream output;
+               openOutputFileAppend(filename, output);
+               
+               //open temp file for reading
+               ifstream input;
+               openInputFile(temp, input);
+               
+               string line;
+               //read input file and write to output file
+               while(input.eof() != true) {
+                       getline(input, line); //getline removes the newline char
+                       if (line != "") {
+                               output << line << endl;   // Appending back newline char 
+                       }
+               }       
+               
+               input.close();
+               output.close();
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the AlignCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               cout << "Standard Error: " << e.what() << " has occurred in the DistanceCommand class Function appendFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
                exit(1);
        }
        catch(...) {
-               cout << "An unknown error has occurred in the AlignCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               cout << "An unknown error has occurred in the DistanceCommand class function appendFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/**************************************************************************************************/
+
+void AlignCommand::appendReportFiles(string temp, string filename) {
+       try{
+               
+               //open output file in append mode
+               ofstream output;
+               openOutputFileAppend(filename, output);
+               
+               //open temp file for reading
+               ifstream input;
+               openInputFile(temp, input);
+               while (!input.eof())    {       char c = input.get(); if (c == 10 || c == 13){  break;  }       } // get header line
+
+               string line;
+               //read input file and write to output file
+               while(input.eof() != true) {
+                       getline(input, line); //getline removes the newline char
+                       if (line != "") {
+                               output << line << endl;   // Appending back newline char 
+                       }
+               }       
+               
+               input.close();
+               output.close();
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the DistanceCommand class Function appendFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the DistanceCommand class function appendFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
                exit(1);
        }       
 }
 
-//**********************************************************************************************************************
\ No newline at end of file
+//**********************************************************************************************************************
index a3ec827c80e1dfa229bf228eb45df61499aef265..62bf3dc100297c2c3f089257329a750e2301f598 100644 (file)
  *
  */
 
+#include "mothur.h"
 #include "command.hpp"
-#include "globaldata.hpp"
-
-
+#include "database.hpp"
+#include "alignment.hpp"
 
 class AlignCommand : public Command {
        
@@ -24,21 +24,27 @@ public:
        void help();    
 
 private:
-       GlobalData* globaldata;
-       OptionParser* parser;
-       map<string, string> parameters;
-       map<string, string>::iterator it;
-       bool abort;
+       struct linePair {
+               int start;
+               int numSeqs;
+               linePair(int i, int j) : start(i), numSeqs(j) {}
+       };
+       map<int, int> processIDS;   //end line, processid
+       vector<linePair*> lines;
+
+       Database* templateDB;
+       Alignment* alignment;
+
+       int driver(linePair*, string, string);
+       void createProcesses(string, string);
+       void appendAlignFiles(string, string); 
+       void appendReportFiles(string, string);
+       
        string candidateFileName, templateFileName, distanceFileName, search, align;
-       int kmerSize;
        float match, misMatch, gapOpen, gapExtend;
-       ofstream out;
-       ifstream in;
-       int ableToOpen;
-       
+       int processors, kmerSize;
 
+       bool abort;
 };
 
-
-
-#endif
\ No newline at end of file
+#endif
index c2fd6fadb9b4bb6b3cffdebd38bc513a68f8b8d7..abe000fbe4ed191b13389420899389e17bcc7cd4 100644 (file)
@@ -26,14 +26,14 @@ BinSeqCommand::BinSeqCommand(string option){
                        string AlignArray[] =  {"fasta","line","label","name", "group"};
                        vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);  delete parser;
+                       OptionParser parser(option);
+                       map<string, string> parameters = parser.getParameters();
                        
-                       ValidParameters* validParameter = new ValidParameters();
+                       ValidParameters validParameter;
                
                        //check to make sure all parameters are valid for command
-                       for (it = parameters.begin(); it != parameters.end(); it++) { 
-                               if (validParameter->isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        //make sure the user has already run the read.otu command
@@ -41,11 +41,10 @@ BinSeqCommand::BinSeqCommand(string option){
                        
                        
                        //check for required parameters
-                       fastafile = validParameter->validFile(parameters, "fasta", true);
+                       fastafile = validParameter.validFile(parameters, "fasta", true);
                        if (fastafile == "not found") { cout << "fasta is a required parameter for the bin.seqs command." << endl; abort = true; }
                        else if (fastafile == "not open") { abort = true; }     
                        else { 
-                               globaldata->setFastaFile(fastafile);
                                openInputFile(fastafile, in);
                                fasta = new FastaMap();
                        }
@@ -53,14 +52,14 @@ BinSeqCommand::BinSeqCommand(string option){
                
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
-                       line = validParameter->validFile(parameters, "line", false);                            
+                       line = validParameter.validFile(parameters, "line", false);                             
                        if (line == "not found") { line = "";  }
                        else { 
                                if(line != "all") {  splitAtDash(line, lines);  allLines = 0;  }
                                else { allLines = 1;  }
                        }
                        
-                       label = validParameter->validFile(parameters, "label", false);                  
+                       label = validParameter.validFile(parameters, "label", false);                   
                        if (label == "not found") { label = ""; }
                        else { 
                                if(label != "all") {  splitAtDash(label, labels);  allLines = 0;  }
@@ -76,11 +75,11 @@ BinSeqCommand::BinSeqCommand(string option){
                                lines = globaldata->lines;
                        }
                        
-                       namesfile = validParameter->validFile(parameters, "name", true);
+                       namesfile = validParameter.validFile(parameters, "name", true);
                        if (namesfile == "not open") { abort = true; }  
                        else if (namesfile == "not found") { namesfile = ""; }
 
-                       groupfile = validParameter->validFile(parameters, "group", true);
+                       groupfile = validParameter.validFile(parameters, "group", true);
                        if (groupfile == "not open") { abort = true; }
                        else if (groupfile == "not found") { groupfile = ""; }
                        else {
@@ -89,7 +88,6 @@ BinSeqCommand::BinSeqCommand(string option){
                                groupMap->readMap();
                        }
        
-                       delete validParameter;
                }
        }
        catch(exception& e) {
@@ -149,7 +147,6 @@ BinSeqCommand::~BinSeqCommand(){
 
 int BinSeqCommand::execute(){
        try {
-       
                if (abort == true) {    return 0;       }
        
                int count = 1;
@@ -159,7 +156,7 @@ int BinSeqCommand::execute(){
                fasta->readFastaFile(in);
                
                //set format to list so input can get listvector
-               globaldata->setFormat("list");
+//             globaldata->setFormat("list");
                
                //if user gave a namesfile then use it
                if (namesfile != "") {
index aceba65da17315de31515750a62fc53f4b7b9a48..6f9f69d3a7b13dbabe73c09e21e787f55dadff81 100644 (file)
@@ -36,9 +36,6 @@ private:
        InputData* input;
        FastaMap* fasta;
        GroupMap* groupMap;
-       OptionParser* parser;
-       map<string, string> parameters;
-       map<string, string>::iterator it;
        bool abort, allLines;
        set<int> lines; //hold lines to be used
        set<string> labels; //holds labels to be used
index 9e3a82de0bfaff9807c653ce0986f96f59b67cba..5e7c0c63c8944d3be0ecc08b9761c334a74520b1 100644 (file)
@@ -40,14 +40,14 @@ BootSharedCommand::BootSharedCommand(string option){
                        string Array[] =  {"line","label","calc","groups","iters"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);  delete parser;
+                       OptionParser parser(option);
+                       map<string,string> parameters = parser.getParameters();
                        
-                       ValidParameters* validParameter = new ValidParameters();
+                       ValidParameters validParameter;
                
                        //check to make sure all parameters are valid for command
-                       for (it = parameters.begin(); it != parameters.end(); it++) { 
-                               if (validParameter->isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        //make sure the user has already run the read.otu command
@@ -58,14 +58,14 @@ BootSharedCommand::BootSharedCommand(string option){
                        
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
-                       line = validParameter->validFile(parameters, "line", false);                            
+                       line = validParameter.validFile(parameters, "line", false);                             
                        if (line == "not found") { line = "";  }
                        else { 
                                if(line != "all") {  splitAtDash(line, lines);  allLines = 0;  }
                                else { allLines = 1;  }
                        }
                        
-                       label = validParameter->validFile(parameters, "label", false);                  
+                       label = validParameter.validFile(parameters, "label", false);                   
                        if (label == "not found") { label = ""; }
                        else { 
                                if(label != "all") {  splitAtDash(label, labels);  allLines = 0;  }
@@ -81,14 +81,14 @@ BootSharedCommand::BootSharedCommand(string option){
                                lines = globaldata->lines;
                        }
                                
-                       groups = validParameter->validFile(parameters, "groups", false);                        
+                       groups = validParameter.validFile(parameters, "groups", false);                 
                        if (groups == "not found") { groups = ""; }
                        else { 
                                splitAtDash(groups, Groups);
                                globaldata->Groups = Groups;
                        }
                                
-                       calc = validParameter->validFile(parameters, "calc", false);                    
+                       calc = validParameter.validFile(parameters, "calc", false);                     
                        if (calc == "not found") { calc = "jclass-thetayc";  }
                        else { 
                                 if (calc == "default")  {  calc = "jclass-thetayc";  }
@@ -96,11 +96,9 @@ BootSharedCommand::BootSharedCommand(string option){
                        splitAtDash(calc, Estimators);
 
                        string temp;
-                       temp = validParameter->validFile(parameters, "iters", false);                   if (temp == "not found") { temp = "1000"; }
+                       temp = validParameter.validFile(parameters, "iters", false);  if (temp == "not found") { temp = "1000"; }
                        convert(temp, iters); 
-       
-                       delete validParameter;
-                       
+                               
                        if (abort == false) {
                        
                                validCalculator = new ValidCalculators();
index 9ff44b377ab90472b8bb5867a9e5bb9a18208068..4d2ebe39fc3a3283ca2aa6ac844d6e2f5865f9e2 100644 (file)
@@ -49,9 +49,7 @@ private:
        ValidCalculators* validCalculator;
        SharedOrderVector* order;
        vector<SharedRAbundVector*> lookup;
-       OptionParser* parser;
-       map<string, string> parameters;
-       map<string, string>::iterator it;
+
        bool abort, allLines;
        set<int> lines; //hold lines to be used
        set<string> labels; //holds labels to be used
index 36fff2242ee65d3cdb1e72868d173c69ed5bc3ff..706ff6735b32d2f93c723a5f4af2d7a402b4bb75 100644 (file)
@@ -24,14 +24,14 @@ ClusterCommand::ClusterCommand(string option){
                        string Array[] =  {"cutoff","precision","method"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);  delete parser;
+                       OptionParser parser(option);
+                       map<string,string> parameters = parser.getParameters();
                        
-                       ValidParameters* validParameter = new ValidParameters();
+                       ValidParameters validParameter;
                
                        //check to make sure all parameters are valid for command
-                       for (it = parameters.begin(); it != parameters.end(); it++) { 
-                               if (validParameter->isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        //error checking to make sure they read a distance file
@@ -43,18 +43,17 @@ ClusterCommand::ClusterCommand(string option){
                        // ...at some point should added some additional type checking...
                        //get user cutoff and precision or use defaults
                        string temp;
-                       temp = validParameter->validFile(parameters, "precision", false);               if (temp == "not found") { temp = "100"; }
+                       temp = validParameter.validFile(parameters, "precision", false);                if (temp == "not found") { temp = "100"; }
                        //saves precision legnth for formatting below
                        length = temp.length();
                        convert(temp, precision); 
                        
-                       temp = validParameter->validFile(parameters, "cutoff", false);                  if (temp == "not found") { temp = "10"; }
+                       temp = validParameter.validFile(parameters, "cutoff", false);                   if (temp == "not found") { temp = "10"; }
                        convert(temp, cutoff); 
                        cutoff += (5 / (precision * 10.0));
                        
-                       method = validParameter->validFile(parameters, "method", false);                        if (method == "not found") { method = "furthest"; }
+                       method = validParameter.validFile(parameters, "method", false);                 if (method == "not found") { method = "furthest"; }
 
-                       delete validParameter;
                        
                        if ((method == "furthest") || (method == "nearest") || (method == "average")) { }
                        else {cout << "Not a valid clustering method.  Valid clustering algorithms are furthest, nearest or average." << endl; abort = true; }
index 37b9edb80224de6d7b7be0f722152e0bdd782b11..44ce6f9f6833a8fd5181bcff64880bfe8f4d4f88 100644 (file)
@@ -44,9 +44,7 @@ private:
        RAbundVector* rabund;
        RAbundVector oldRAbund;
        ListVector oldList;
-       OptionParser* parser;
-       map<string, string> parameters;
-       map<string, string>::iterator it;
+
        bool abort;
 
        string method, fileroot, tag;
index a9048706dfe7e069ff7efb7f56500b4afc2d527b..2dd843f68f83d2eeec882253b8e50cda1ee9236b 100644 (file)
@@ -48,14 +48,14 @@ CollectCommand::CollectCommand(string option){
                        string Array[] =  {"freq","line","label","calc","abund","size"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);  delete parser;
+                       OptionParser parser(option);
+                       map<string,string> parameters = parser.getParameters();
                        
-                       ValidParameters* validParameter = new ValidParameters();
+                       ValidParameters validParameter;
                
                        //check to make sure all parameters are valid for command
-                       for (it = parameters.begin(); it != parameters.end(); it++) { 
-                               if (validParameter->isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        //make sure the user has already run the read.otu command
@@ -63,14 +63,14 @@ CollectCommand::CollectCommand(string option){
                        
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
-                       line = validParameter->validFile(parameters, "line", false);                            
+                       line = validParameter.validFile(parameters, "line", false);                             
                        if (line == "not found") { line = "";  }
                        else { 
                                if(line != "all") {  splitAtDash(line, lines);  allLines = 0;  }
                                else { allLines = 1;  }
                        }
                        
-                       label = validParameter->validFile(parameters, "label", false);                  
+                       label = validParameter.validFile(parameters, "label", false);                   
                        if (label == "not found") { label = ""; }
                        else { 
                                if(label != "all") {  splitAtDash(label, labels);  allLines = 0;  }
@@ -86,7 +86,7 @@ CollectCommand::CollectCommand(string option){
                                lines = globaldata->lines;
                        }
                                
-                       calc = validParameter->validFile(parameters, "calc", false);                    
+                       calc = validParameter.validFile(parameters, "calc", false);                     
                        if (calc == "not found") { calc = "sobs-chao-ace-jack-shannon-npshannon-simpson";  }
                        else { 
                                 if (calc == "default")  {  calc = "sobs-chao-ace-jack-shannon-npshannon-simpson";  }
@@ -94,18 +94,15 @@ CollectCommand::CollectCommand(string option){
                        splitAtDash(calc, Estimators);
 
                        string temp;
-                       temp = validParameter->validFile(parameters, "freq", false);                    if (temp == "not found") { temp = "100"; }
+                       temp = validParameter.validFile(parameters, "freq", false);                     if (temp == "not found") { temp = "100"; }
                        convert(temp, freq); 
                        
-                       temp = validParameter->validFile(parameters, "abund", false);           if (temp == "not found") { temp = "10"; }
+                       temp = validParameter.validFile(parameters, "abund", false);            if (temp == "not found") { temp = "10"; }
                        convert(temp, abund); 
                        
-                       temp = validParameter->validFile(parameters, "size", false);                    if (temp == "not found") { temp = "0"; }
+                       temp = validParameter.validFile(parameters, "size", false);                     if (temp == "not found") { temp = "0"; }
                        convert(temp, size); 
-       
-                       delete validParameter;
-                       
-                       
+                               
                        if (abort == false) {
                                string fileNameRoot = getRootName(globaldata->inputFileName);
                                int i;
index 3b79d7f2144c0c41c6b42f221bd53d2a6dfe07aa..04dcc602628695c5381048dbb67f4bad8be682e3 100644 (file)
@@ -52,9 +52,7 @@ private:
        ValidCalculators* validCalculator;
        vector<Display*> cDisplays;
        int freq, abund, size;
-       OptionParser* parser;
-       map<string, string> parameters;
-       map<string, string>::iterator it;
+
        bool abort, allLines;
        set<int> lines; //hold lines to be used
        set<string> labels; //holds labels to be used
index 2b6cbacd2afed90b8a23674c49171da9654a6033..36b0dc141406286b44130de699fea92f971d167f 100644 (file)
@@ -53,14 +53,14 @@ CollectSharedCommand::CollectSharedCommand(string option){
                        string Array[] =  {"freq","line","label","calc","groups"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);  delete parser;
+                       OptionParser parser(option);
+                       map<string,string> parameters=parser.getParameters();
                        
-                       ValidParameters* validParameter = new ValidParameters();
+                       ValidParameters validParameter;
                
                        //check to make sure all parameters are valid for command
-                       for (it = parameters.begin(); it != parameters.end(); it++) { 
-                               if (validParameter->isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        //make sure the user has already run the read.otu command
@@ -72,14 +72,14 @@ CollectSharedCommand::CollectSharedCommand(string option){
                        
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
-                       line = validParameter->validFile(parameters, "line", false);                            
+                       line = validParameter.validFile(parameters, "line", false);                             
                        if (line == "not found") { line = "";  }
                        else { 
                                if(line != "all") {  splitAtDash(line, lines);  allLines = 0;  }
                                else { allLines = 1;  }
                        }
                        
-                       label = validParameter->validFile(parameters, "label", false);                  
+                       label = validParameter.validFile(parameters, "label", false);                   
                        if (label == "not found") { label = ""; }
                        else { 
                                if(label != "all") {  splitAtDash(label, labels);  allLines = 0;  }
@@ -95,14 +95,14 @@ CollectSharedCommand::CollectSharedCommand(string option){
                                lines = globaldata->lines;
                        }
                                
-                       calc = validParameter->validFile(parameters, "calc", false);                    
+                       calc = validParameter.validFile(parameters, "calc", false);                     
                        if (calc == "not found") { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan";  }
                        else { 
                                 if (calc == "default")  {  calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan";  }
                        }
                        splitAtDash(calc, Estimators);
                        
-                       groups = validParameter->validFile(parameters, "groups", false);                        
+                       groups = validParameter.validFile(parameters, "groups", false);                 
                        if (groups == "not found") { groups = ""; }
                        else { 
                                splitAtDash(groups, Groups);
@@ -110,15 +110,13 @@ CollectSharedCommand::CollectSharedCommand(string option){
                        }
                        
                        string temp;
-                       temp = validParameter->validFile(parameters, "freq", false);                    if (temp == "not found") { temp = "100"; }
+                       temp = validParameter.validFile(parameters, "freq", false);                     if (temp == "not found") { temp = "100"; }
                        convert(temp, freq); 
-                       
-                       delete validParameter;
-                       
+                                               
                        if (abort == false) {
                        
                                string fileNameRoot = getRootName(globaldata->inputFileName);
-                               format = globaldata->getFormat();
+//                             format = globaldata->getFormat();
                                int i;
                                
                                validCalculator = new ValidCalculators();
index 7024d0b5fc1ceecc1700d8592a91b9fe873d52c7..67e8e0c1073dae0a81f5d4d8e88ac7ee4981d708 100644 (file)
@@ -57,9 +57,7 @@ private:
        vector<Display*> cDisplays;
        int freq;
        string format;
-       OptionParser* parser;
-       map<string, string> parameters;
-       map<string, string>::iterator it;
+
        bool abort, allLines;
        set<int> lines; //hold lines to be used
        set<string> labels; //holds labels to be used
index 3e655abb19ed35729792e3f5783f119095c6fc61..27355dddd933834108371d18cf66c27c4a29763b 100644 (file)
@@ -10,7 +10,7 @@
  *
  */
 
-/*This class is a parent to all the command classes.  It has one pure int execute(). */
+/*This class is a parent to all the command classes.  */
 
 
 #include "mothur.h"
index 48a363336be3bea3a482471608cf7e0ce2300b3e..eeaf8ee38ee287691dc8023307f95e098026c9ac 100644 (file)
@@ -33,7 +33,6 @@
 #include "heatmapcommand.h"
 #include "heatmapsimcommand.h"
 #include "filterseqscommand.h"
-#include "mothur.h"
 #include "venncommand.h"
 #include "nocommands.h"
 #include "binsequencecommand.h"
@@ -50,6 +49,7 @@
 #include "screenseqscommand.h"
 #include "reversecommand.h"
 #include "trimseqscommand.h"
+#include "mergefilecommand.h"
 
 /***********************************************************/
 
@@ -111,6 +111,7 @@ Command* CommandFactory::getCommand(string commandName, string optionString){
                else if(commandName == "screen.seqs")                   {       command = new ScreenSeqsCommand(optionString);                  }
                else if(commandName == "reverse.seqs")                  {       command = new ReverseSeqsCommand(optionString);                 }
                else if(commandName == "trim.seqs")                             {       command = new TrimSeqsCommand(optionString);                    }
+               else if(commandName == "merge.files")                   {       command = new MergeFileCommand(optionString);                   }
                else                                                                                    {       command = new NoCommand(optionString);                                  }
 
                return command;
index 96682af26b8bcb1b62c17987c82355856cfaf919..3ec5f734eebb393c6ff630a1adc8d7e94ab6729f 100644 (file)
@@ -12,7 +12,6 @@
 /**************************************************************************************/
 DeconvoluteCommand::DeconvoluteCommand(string option) {        
        try {
-               globaldata = GlobalData::getInstance();
                abort = false;
                
                //allow user to run help
@@ -23,23 +22,21 @@ DeconvoluteCommand::DeconvoluteCommand(string option) {
                        string Array[] =  {"fasta"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);  delete parser;
+                       OptionParser parser(option);
+                       map<string,string> parameters = parser.getParameters();
                        
-                       ValidParameters* validParameter = new ValidParameters();
+                       ValidParameters validParameter;
                
                        //check to make sure all parameters are valid for command
-                       for (it = parameters.begin(); it != parameters.end(); it++) { 
-                               if (validParameter->isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        //check for required parameters
-                       filename = validParameter->validFile(parameters, "fasta", true);
+                       filename = validParameter.validFile(parameters, "fasta", true);
                        if (filename == "not open") { abort = true; }
                        else if (filename == "not found") { filename = ""; cout << "fasta is a required parameter for the unique.seqs command." << endl; abort = true;  }       
-                       else {  globaldata->setFastaFile(filename);  globaldata->setFormat("fasta");    }
                        
-                       delete validParameter;
                }
 
        }
index 0b6eb5e1f8fbce6e0f9ba9c5cccaee56739990dc..b6bda8faa00a274369e7a23803440025c241e612 100644 (file)
@@ -11,7 +11,6 @@
 
 #include "command.hpp"
 #include "fastamap.h"
-#include "globaldata.hpp"
 
 /* The unique.seqs command reads a fasta file, finds the duplicate sequences and outputs a names file
        containing 2 columns.  The first being the groupname and the second the list of identical sequence names. */ 
@@ -26,17 +25,12 @@ public:
        void help();    
        
 private:
-       GlobalData* globaldata;
        FastaMap* fastamap;
        ifstream in;
        ofstream out, outFasta;
        string filename, outputFileName, outFastafile;
-       OptionParser* parser;
-       map<string, string> parameters;
-       map<string, string>::iterator it;
-       bool abort;
-
 
+       bool abort;
 };
 
 #endif
index 7890cb9303cd39e38967a7694203fac8d2d588ab..065c14a1671a8abe78e1dda115208936185f496e 100644 (file)
@@ -18,7 +18,6 @@
 
 DistanceCommand::DistanceCommand(string option){
        try {
-               globaldata = GlobalData::getInstance();
                abort = false;
                Estimators.clear();
                
@@ -30,28 +29,29 @@ DistanceCommand::DistanceCommand(string option){
                        string Array[] =  {"fasta", "phylip", "calc", "countends", "cutoff", "processors"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);  delete parser;
+                       OptionParser parser(option);
+                       map<string, string> parameters = parser.getParameters();
                        
-                       ValidParameters* validParameter = new ValidParameters();
+                       ValidParameters validParameter;
                
                        //check to make sure all parameters are valid for command
-                       for (it2 = parameters.begin(); it2 != parameters.end(); it2++) { 
-                               if (validParameter->isValidParameter(it2->first, myArray, it2->second) != true) {  abort = true;  }
+                       for (map<string, string>::iterator it2 = parameters.begin(); it2 != parameters.end(); it2++) { 
+                               if (validParameter.isValidParameter(it2->first, myArray, it2->second) != true) {  abort = true;  }
                        }
                        
                        //check for required parameters
-                       fastafile = validParameter->validFile(parameters, "fasta", true);
+                       fastafile = validParameter.validFile(parameters, "fasta", true);
                        if (fastafile == "not found") { cout << "fasta is a required parameter for the dist.seqs command." << endl; abort = true; }
                        else if (fastafile == "not open") { abort = true; }     
-                       else { 
-                               globaldata->setFastaFile(fastafile);
-                               openInputFile(fastafile, in);
+                       else{
+                               ifstream inFASTA;
+                               openInputFile(fastafile, inFASTA);
+                               alignDB = SequenceDB(inFASTA); 
                        }
-                       
+
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
-                       calc = validParameter->validFile(parameters, "calc", false);                    
+                       calc = validParameter.validFile(parameters, "calc", false);                     
                        if (calc == "not found") { calc = "onegap";  }
                        else { 
                                 if (calc == "default")  {  calc = "onegap";  }
@@ -59,48 +59,38 @@ DistanceCommand::DistanceCommand(string option){
                        splitAtDash(calc, Estimators);
 
                        string temp;
-                       temp = validParameter->validFile(parameters, "countends", false);                       if (temp == "not found") { temp = "T"; }
+                       temp = validParameter.validFile(parameters, "countends", false);        if(temp == "not found"){        temp = "T";     }
                        convert(temp, countends); 
                        
-                       temp = validParameter->validFile(parameters, "cutoff", false);                          if (temp == "not found") { temp = "1.0"; }
+                       temp = validParameter.validFile(parameters, "cutoff", false);           if(temp == "not found"){        temp = "1.0"; }
                        convert(temp, cutoff); 
                        
-                       temp = validParameter->validFile(parameters, "processors", false);                      if (temp == "not found") { temp = "1"; }
+                       temp = validParameter.validFile(parameters, "processors", false);       if(temp == "not found"){        temp = "1"; }
                        convert(temp, processors); 
                        
-                       phylip = validParameter->validFile(parameters, "phylip", false);                        if (phylip == "not found") { phylip = "F"; }
+                       phylip = validParameter.validFile(parameters, "phylip", false);         if(phylip == "not found"){      phylip = "F"; }
        
-                       delete validParameter;
                        
-                       validCalculator = new ValidCalculators();
+                       ValidCalculators validCalculator;
                        
-                       int i;
                        if (isTrue(countends) == true) {
-                               for (i=0; i<Estimators.size(); i++) {
-                                       if (validCalculator->isValidCalculator("distance", Estimators[i]) == true) { 
-                                               if (Estimators[i] == "nogaps") { 
-                                                       distCalculator = new ignoreGaps();
-                                               }else if (Estimators[i] == "eachgap") { 
-                                                       distCalculator = new eachGapDist();     
-                                               }else if (Estimators[i] == "onegap") {
-                                               distCalculator = new oneGapDist();                                      }
+                               for (int i=0; i<Estimators.size(); i++) {
+                                       if (validCalculator.isValidCalculator("distance", Estimators[i]) == true) { 
+                                               if (Estimators[i] == "nogaps")                  {       distCalculator = new ignoreGaps();      }
+                                               else if (Estimators[i] == "eachgap")    {       distCalculator = new eachGapDist();     }
+                                               else if (Estimators[i] == "onegap")             {       distCalculator = new oneGapDist();      }
                                        }
                                }
                        }else {
-                               for (i=0; i<Estimators.size(); i++) {
-                                       if (validCalculator->isValidCalculator("distance", Estimators[i]) == true) { 
-                                               if (Estimators[i] == "nogaps") { 
-                                                       distCalculator = new ignoreGaps();      
-                                               }else if (Estimators[i] == "eachgap") { 
-                                                       distCalculator = new eachGapIgnoreTermGapDist();
-                                               }else if (Estimators[i] == "onegap") { 
-                                                       distCalculator = new oneGapIgnoreTermGapDist(); 
-                                               }
+                               for (int i=0; i<Estimators.size(); i++) {
+                                       if (validCalculator.isValidCalculator("distance", Estimators[i]) == true) { 
+                                               if (Estimators[i] == "nogaps")          {       distCalculator = new ignoreGaps();                                      }
+                                               else if (Estimators[i] == "eachgap"){   distCalculator = new eachGapIgnoreTermGapDist();        }
+                                               else if (Estimators[i] == "onegap")     {       distCalculator = new oneGapIgnoreTermGapDist();         }
                                        }
                                }
                        }
 
-                       delete validCalculator;
                }
                                
        }
@@ -113,6 +103,17 @@ DistanceCommand::DistanceCommand(string option){
                exit(1);
        }       
 }
+
+//**********************************************************************************************************************
+
+DistanceCommand::~DistanceCommand(){
+       
+       for(int i=0;i<lines.size();i++){
+               delete lines[i];
+       }
+       
+}
+       
 //**********************************************************************************************************************
 
 void DistanceCommand::help(){
@@ -147,10 +148,7 @@ int DistanceCommand::execute(){
                
                if (abort == true) { return 0; }
                
-               //reads fasta file and fills sequenceDB
-               seqDB = new SequenceDB(in); 
-                               
-               int numSeqs = seqDB->getNumSeqs();
+               int numSeqs = alignDB.getNumSeqs();
                cutoff += 0.005;
                
                string outputFile;
@@ -161,9 +159,6 @@ int DistanceCommand::execute(){
                        remove(outputFile.c_str());
                        
                        //output numSeqs to phylip formatted dist file
-                       openOutputFile(outputFile, outFile);
-                       outFile << numSeqs << endl;
-                       outFile.close();
                }else { //user wants column format
                        outputFile = getRootName(fastafile) + "dist";
                        remove(outputFile.c_str());
@@ -178,9 +173,7 @@ int DistanceCommand::execute(){
 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
                //if you don't need to fork anything
                if(processors == 1){
-                       driver(distCalculator, seqDB, 0, numSeqs, outputFile + ".temp", cutoff);
-                       appendFiles((outputFile + ".temp"), outputFile);
-                       remove((outputFile + ".temp").c_str());
+                       driver(0, numSeqs, outputFile, cutoff);
                }else{ //you have multiple processors
                        
                        for (int i = 0; i < processors; i++) {
@@ -189,21 +182,21 @@ int DistanceCommand::execute(){
                                lines[i]->end = int (sqrt(float(i+1)/float(processors)) * numSeqs);
                        }
 
-                       cout << lines[0]->start << '\t' << lines[0]->end << endl;
-                       cout << lines[1]->start << '\t' << lines[1]->end << endl;
-
                        createProcesses(outputFile); 
                
+                       map<int, int>::iterator it = processIDS.begin();
+                       rename((outputFile + toString(it->second) + ".temp").c_str(), outputFile.c_str());
+                       it++;
+                       
                        //append and remove temp files
-                       for (it = processIDS.begin(); it != processIDS.end(); it++) {
+                       for (; it != processIDS.end(); it++) {
                                appendFiles((outputFile + toString(it->second) + ".temp"), outputFile);
                                remove((outputFile + toString(it->second) + ".temp").c_str());
                        }
                }
 #else
-               driver(distCalculator, seqDB, 0, numSeqs, outputFile + ".temp", cutoff);
-               appendFiles((outputFile + ".temp"), outputFile);
-               remove((outputFile + ".temp").c_str());
+               ifstream inFASTA
+               driver(0, numSeqs, outputFile, cutoff);
 #endif
                
                delete distCalculator;
@@ -223,6 +216,7 @@ int DistanceCommand::execute(){
 /**************************************************************************************************/
 void DistanceCommand::createProcesses(string filename) {
        try {
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
                int process = 0;
                processIDS.clear();
                
@@ -234,17 +228,17 @@ void DistanceCommand::createProcesses(string filename) {
                                processIDS[lines[process]->end] = pid;  //create map from line number to pid so you can append files in correct order later
                                process++;
                        }else if (pid == 0){
-                               driver(distCalculator, seqDB, lines[process]->start, lines[process]->end, filename + toString(getpid()) + ".temp", cutoff);
+                               driver(lines[process]->start, lines[process]->end, filename + toString(getpid()) + ".temp", cutoff);
                                exit(0);
                        }else { cout << "unable to spawn the necessary processes." << endl; exit(0); }
                }
        
                //force parent to wait until all the processes are done
-               for (it = processIDS.begin(); it != processIDS.end(); it++) { 
+               for (map<int, int>::iterator it = processIDS.begin(); it != processIDS.end(); it++) { 
                        int temp = it->second;
                        wait(&temp);
                }
-               
+#endif
        }
        catch(exception& e) {
                cout << "Standard Error: " << e.what() << " has occurred in the DistanceCommand class Function createProcesses. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
@@ -258,7 +252,7 @@ void DistanceCommand::createProcesses(string filename) {
 
 /**************************************************************************************************/
 /////// need to fix to work with calcs and sequencedb
-int DistanceCommand::driver(Dist* distCalculator, SequenceDB* align, int startLine, int endLine, string dFileName, float cutoff){
+int DistanceCommand::driver(int startLine, int endLine, string dFileName, float cutoff){
        try {
 
                int startTime = time(NULL);
@@ -268,16 +262,17 @@ int DistanceCommand::driver(Dist* distCalculator, SequenceDB* align, int startLi
                outFile.setf(ios::fixed, ios::showpoint);
                outFile << setprecision(4);
                
+               if(isTrue(phylip) && startLine == 0){   outFile << alignDB.getNumSeqs() << endl;        }
                for(int i=startLine;i<endLine;i++){
-                       
+                       if(isTrue(phylip))      {       outFile << alignDB.get(i).getName() << '\t';    }
                        for(int j=0;j<i;j++){
-                               distCalculator->calcDist(*(align->get(i)), *(align->get(j)));
+                               distCalculator->calcDist(alignDB.get(i), alignDB.get(j));
                                double dist = distCalculator->getDist();
                                
                                if(dist <= cutoff){
-                                       if (isTrue(phylip) != true) { outFile << align->get(i)->getName() << ' ' << align->get(j)->getName() << ' ' << dist << endl; }
+                                       if (!isTrue(phylip)) { outFile << alignDB.get(i).getName() << ' ' << alignDB.get(j).getName() << ' ' << dist << endl; }
                                }
-                               if (isTrue(phylip) == true) {  outFile << dist << '\t'; }
+                               if (isTrue(phylip)) {  outFile << dist << '\t'; }
                                
                        }
                        
@@ -290,8 +285,7 @@ int DistanceCommand::driver(Dist* distCalculator, SequenceDB* align, int startLi
                }
                cout << endLine-1 << '\t' << time(NULL) - startTime << endl;
                
-               //philFile.close();
-               //distFile.close();
+               outFile.close();
                
                return 1;
        }
index 446be04a2a3972976b7e67aba9a97cb277d928a8..6a7ac93fa1d7b28d9fe03e1e27f1e4a1ec3ef491 100644 (file)
 
 #include "mothur.h"
 #include "command.hpp"
-#include "globaldata.hpp"
 #include "validcalculator.h"
 #include "dist.h"
 #include "sequencedb.h"
 
-struct linePair {
-       int start;
-       int end;
-};
 
 class DistanceCommand : public Command {
 
 public:
        DistanceCommand(string);        
-       ~DistanceCommand() {};
+       ~DistanceCommand();
        int execute();  
        void help();
        
 private:
-       GlobalData* globaldata;
-       ValidCalculators* validCalculator;
+       struct linePair {
+               int start;
+               int end;
+       };
+       
        Dist* distCalculator;
-       SequenceDB* seqDB;
-       ofstream out, outFile;
-       ifstream in;
+       SequenceDB alignDB;
+
        string countends, phylip, fastafile, calc;
        int processors;
        float cutoff;
        map<int, int> processIDS;   //end line, processid
-       map<int, int>::iterator it;
        vector<linePair*> lines;
        
-       OptionParser* parser;
-       map<string, string> parameters;
-       map<string, string>::iterator it2;
        bool abort;
        vector<string>  Estimators; //holds estimators to be used
        
        void appendFiles(string, string);
        void createProcesses(string);
-       int driver(Dist*, SequenceDB*, int, int, string, float);
+       int driver(/*Dist*, SequenceDB, */int, int, string, float);
 
 };
 
index 209dd1b1772cc1f58e18cce4826ffcddd541d278..7dfb0c00b48b93e9d6cb121ba905de7cdc8a5dcb 100644 (file)
@@ -2,7 +2,6 @@
 #define FILEOUTPUT_H
 
 #include "mothur.h"
-#include "globaldata.hpp"
 
 /***********************************************************************/
 
@@ -20,7 +19,6 @@ public:
        virtual string getFileName() = 0;
 
 protected:
-       GlobalData* globaldata;
        int renameOk;
 
 };     
@@ -127,7 +125,7 @@ private:
 class ColumnFile : public FileOutput {
        
 public:
-       ColumnFile(string n, string i) : FileOutput(), iters(i), inName(n), counter(0), outName(getPathName(n) + ".temp") { globaldata = GlobalData::getInstance(); };
+       ColumnFile(string n, string i) : FileOutput(), iters(i), inName(n), counter(0), outName(getPathName(n) + ".temp") {};
        ~ColumnFile();
        
        //to make compatible with parent class
index 1363216ffe56267adf628c42fe9ede4065c8f626..95d51f329f30d8a639d0772844e54be5246e5005 100644 (file)
@@ -8,12 +8,12 @@
  */
 
 #include "filterseqscommand.h"
+#include "sequence.hpp"
 
 /**************************************************************************************/
 
 FilterSeqsCommand::FilterSeqsCommand(string option){
        try {
-               globaldata = GlobalData::getInstance();
                abort = false;
                
                //allow user to run help
@@ -24,40 +24,35 @@ FilterSeqsCommand::FilterSeqsCommand(string option){
                        string Array[] =  {"fasta", "trump", "soft", "hard", "vertical"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);  delete parser;
+                       OptionParser parser(option);
+                       map<string,string> parameters = parser.getParameters();
+                       
+                       ValidParameters validParameter;
                        
-                       ValidParameters* validParameter = new ValidParameters();
-               
                        //check to make sure all parameters are valid for command
-                       for (it = parameters.begin(); it != parameters.end(); it++) { 
-                               if (validParameter->isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        //check for required parameters
-                       fastafile = validParameter->validFile(parameters, "fasta", true);
+                       fastafile = validParameter.validFile(parameters, "fasta", true);
                        if (fastafile == "not found") { cout << "fasta is a required parameter for the filter.seqs command." << endl; abort = true; }
                        else if (fastafile == "not open") { abort = true; }     
-                       else { 
-                               globaldata->setFastaFile(fastafile);
-                       }
-                       
+
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
                        
                        string temp;
-                       temp = validParameter->validFile(parameters, "trump", false);                           if (temp == "not found") { temp = "."; }
+                       temp = validParameter.validFile(parameters, "trump", false);                    if (temp == "not found") { temp = "*"; }
                        trump = temp[0];
                        
-                       temp = validParameter->validFile(parameters, "soft", false);                            if (temp == "not found") { soft = 0; }
+                       temp = validParameter.validFile(parameters, "soft", false);                             if (temp == "not found") { soft = 0; }
                        else {  soft = (float)atoi(temp.c_str()) / 100.0;  }
                        
-                       hard = validParameter->validFile(parameters, "hard", true);                                     if (hard == "not found") { hard = ""; }
+                       hard = validParameter.validFile(parameters, "hard", true);                              if (hard == "not found") { hard = ""; }
                        else if (hard == "not open") { abort = true; }  
                        
-                       vertical = validParameter->validFile(parameters, "vertical", false);            if (vertical == "not found") { vertical = "F"; }
-       
-                       delete validParameter;
+                       vertical = validParameter.validFile(parameters, "vertical", false);             if (vertical == "not found") { vertical = "T"; }
                        
                        numSeqs = 0;
                        
@@ -81,10 +76,10 @@ void FilterSeqsCommand::help(){
                cout << "The filter.seqs command reads a file containing sequences and creates a .filter and .filter.fasta file." << "\n";
                cout << "The filter.seqs command parameters are fasta, trump, soft, hard and vertical.  " << "\n";
                cout << "The fasta parameter is required." << "\n";
-               cout << "The trump parameter .... The default is '.'" << "\n";
+               cout << "The trump parameter .... The default is ..." << "\n";
                cout << "The soft parameter .... The default is ...." << "\n";
                cout << "The hard parameter .... The default is ...." << "\n";
-               cout << "The vertical parameter .... The default is F." << "\n";
+               cout << "The vertical parameter .... The default is T." << "\n";
                cout << "The filter.seqs command should be in the following format: " << "\n";
                cout << "filter.seqs(fasta=yourFastaFile, trump=yourTrump, soft=yourSoft, hard=yourHard, vertical=yourVertical) " << "\n";
                cout << "Example filter.seqs(fasta=abrecovery.fasta, trump=..., soft=..., hard=..., vertical=T)." << "\n";
@@ -117,7 +112,7 @@ void FilterSeqsCommand::doHard() {
 void FilterSeqsCommand::doTrump(Sequence seq) {
        
        string curAligned = seq.getAligned();
-       
+
        for(int j = 0; j < alignmentLength; j++) {
                if(curAligned[j] == trump){
                        filter[j] = '0';
@@ -141,15 +136,9 @@ void FilterSeqsCommand::doVertical() {
 void FilterSeqsCommand::doSoft() {
        
        int threshold = int (soft * numSeqs);
-       bool keep = 0;
        
        for(int i=0;i<alignmentLength;i++){
-               if(a[i] >= threshold)           {       keep = 1;       }
-               else if(t[i] >= threshold)      {       keep = 1;       }
-               else if(g[i] >= threshold)      {       keep = 1;       }
-               else if(c[i] >= threshold)      {       keep = 1;       }
-               
-               if(keep == 0)   {       filter[i] = 0;          }
+               if(a[i] < threshold && t[i] < threshold && g[i] < threshold && c[i] < threshold){       filter[i] = 0;  }
        }
 }
 
@@ -194,11 +183,10 @@ int FilterSeqsCommand::execute() {
                if(hard.compare("") != 0)       {       doHard();               }
                else                                            {       filter = string(alignmentLength, '1');  }
 
-               if(isTrue(vertical) || soft != 0){
-               
-                       while(!inFASTA.eof()){
+               if(trump != '*' || isTrue(vertical) || soft != 0){
+                       while(!inFASTA.eof()){  //read through and create the filter...
                                Sequence seq(inFASTA);
-                               doTrump(seq);   
+                               if(trump != '*'){       doTrump(seq);   }
                                if(isTrue(vertical) || soft != 0){      getFreqs(seq);  }
                                numSeqs++;
                                cout.flush();
@@ -253,8 +241,6 @@ int FilterSeqsCommand::execute() {
                cout << "Length of the original alignment: " << alignmentLength << endl;
                cout << "Number of sequences used to construct filter: " << numSeqs << endl;
                
-               globaldata->clear();
-               
                return 0;
                
        }
index 3f1e4c46d349d9da15837466502bd06a2f243883..cfa56b39df6a4001014e1bc42048bed50bede8fa 100644 (file)
@@ -11,9 +11,8 @@
  */
 
 #include "command.hpp"
-#include "globaldata.hpp"
-#include "sequence.hpp"
 
+class Sequence;
 class FilterSeqsCommand : public Command {
 
 public:
@@ -35,11 +34,7 @@ private:
        bool abort;
        float soft;
        int numSeqs;
-       OptionParser* parser;
-       map<string, string> parameters;
-       map<string, string>::iterator it;
        
-       GlobalData* globaldata; 
        vector<int> a, t, g, c, gap;
 
 };
index 5f459bf7e6a8013ee61893502c01e5c6a306c4b1..6802978a0c3e527aed6a30a7a8ecce1726c19b57 100644 (file)
@@ -67,9 +67,8 @@ int GetlineCommand::execute(){
        
                if (abort == true) { return 0; }
        
-               filename = globaldata->inputFileName;
                ifstream in;
-               openInputFile(filename, in);
+               openInputFile(globaldata->inputFileName, in);
                string label;
                int numBins = 0;
                int count = -1;
index 915a09a0744958f7bca8fc4b671c55b1d898487b..68870b36fe7990d9d8da00ae2a213c08ced21e0e 100644 (file)
@@ -24,7 +24,6 @@ public:
        
 private:
        GlobalData* globaldata;
-       string filename;
        bool abort;
 };
 
index 92aab92af537dbb8cbd9cb294e058a5e88115a63..791889996a0ec1d7c726885d22eb7277388d7f14 100644 (file)
@@ -26,14 +26,14 @@ GetOTURepCommand::GetOTURepCommand(string option){
                        string Array[] =  {"fasta","list","line","label","name", "group"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);  delete parser;
+                       OptionParser parser(option);
+                       map<string, string> parameters = parser.getParameters();
                        
-                       ValidParameters* validParameter = new ValidParameters();
+                       ValidParameters validParameter;
                
                        //check to make sure all parameters are valid for command
-                       for (it4 = parameters.begin(); it4 != parameters.end(); it4++) { 
-                               if (validParameter->isValidParameter(it4->first, myArray, it4->second) != true) {  abort = true;  }
+                       for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        //make sure the user has already run the read.otu command
@@ -43,30 +43,24 @@ GetOTURepCommand::GetOTURepCommand(string option){
                        }
                        
                        //check for required parameters
-                       fastafile = validParameter->validFile(parameters, "fasta", true);
+                       fastafile = validParameter.validFile(parameters, "fasta", true);
                        if (fastafile == "not found") { cout << "fasta is a required parameter for the get.oturep command." << endl; abort = true; }
                        else if (fastafile == "not open") { abort = true; }     
-                       else { 
-                               globaldata->setFastaFile(fastafile);
-                       }
                
-                       listfile = validParameter->validFile(parameters, "list", true);
+                       listfile = validParameter.validFile(parameters, "list", true);
                        if (listfile == "not found") { cout << "list is a required parameter for the get.oturep command." << endl; abort = true; }
                        else if (listfile == "not open") { abort = true; }      
-                       else { 
-                               globaldata->setListFile(listfile);
-                       }
 
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
-                       line = validParameter->validFile(parameters, "line", false);                            
+                       line = validParameter.validFile(parameters, "line", false);                             
                        if (line == "not found") { line = "";  }
                        else { 
                                if(line != "all") {  splitAtDash(line, lines);  allLines = 0;  }
                                else { allLines = 1;  }
                        }
                        
-                       label = validParameter->validFile(parameters, "label", false);                  
+                       label = validParameter.validFile(parameters, "label", false);                   
                        if (label == "not found") { label = ""; }
                        else { 
                                if(label != "all") {  splitAtDash(label, labels);  allLines = 0;  }
@@ -82,11 +76,11 @@ GetOTURepCommand::GetOTURepCommand(string option){
                                lines = globaldata->lines;
                        }
                        
-                       namesfile = validParameter->validFile(parameters, "name", true);
+                       namesfile = validParameter.validFile(parameters, "name", true);
                        if (namesfile == "not open") { abort = true; }  
                        else if (namesfile == "not found") { namesfile = ""; }
 
-                       groupfile = validParameter->validFile(parameters, "group", true);
+                       groupfile = validParameter.validFile(parameters, "group", true);
                        if (groupfile == "not open") { abort = true; }
                        else if (groupfile == "not found") { groupfile = ""; }
                        else {
@@ -94,9 +88,7 @@ GetOTURepCommand::GetOTURepCommand(string option){
                                groupMap = new GroupMap(groupfile);
                                groupMap->readMap();
                        }
-       
-                       delete validParameter;
-       
+               
                        if (abort == false) {
                        
                                if(globaldata->gSparseMatrix != NULL)   {       matrix = new SparseMatrix(*globaldata->gSparseMatrix);          }       
@@ -186,7 +178,7 @@ int GetOTURepCommand::execute(){
                fasta->readFastaFile(in);
                
                //set format to list so input can get listvector
-               globaldata->setFormat("list");
+//             globaldata->setFormat("list");
                
                //if user gave a namesfile then use it
                if (namesfile != "") {
@@ -236,9 +228,8 @@ int GetOTURepCommand::execute(){
                }
                
                //output error messages about any remaining user labels
-               set<string>::iterator it;
                bool needToRun = false;
-               for (it = userLabels.begin(); it != userLabels.end(); it++) {  
+               for (set<string>::iterator it = userLabels.begin(); it != userLabels.end(); it++) {  
                        cout << "Your file does not include the label "<< *it; 
                        if (processedLabels.count(lastList->getLabel()) != 1) {
                                cout << ". I will use " << lastList->getLabel() << "." << endl;
@@ -316,7 +307,6 @@ string GetOTURepCommand::FindRep(int bin, string& group, ListVector* thisList) {
        try{
                vector<string> names;
                map<string, float> sums;
-               map<string, float>::iterator it4;
                map<int, string> binMap; //subset of namesToIndex - just member of this bin
                string binnames;
                float min = 10000;
@@ -354,13 +344,13 @@ string GetOTURepCommand::FindRep(int bin, string& group, ListVector* thisList) {
                else {
                        //fill binMap
                        for (int i = 0; i < names.size(); i++) {
-                               for (it3 = nameToIndex.begin(); it3 != nameToIndex.end(); it3++) {
+                               for (map<string, int>::iterator it = nameToIndex.begin(); it != nameToIndex.end(); it++) {
 
-                                       if (it3->first == names[i]) {  
-                                               binMap[it3->second] = it3->first;
+                                       if (it->first == names[i]) {  
+                                               binMap[it->second] = it->first;
 
                                                //initialize sums map
-                                               sums[it3->first] = 0.0;
+                                               sums[it->first] = 0.0;
                                                break;
                                        }
                                }
@@ -369,8 +359,8 @@ string GetOTURepCommand::FindRep(int bin, string& group, ListVector* thisList) {
                        //go through each cell in the sparsematrix
                        for(MatData currentCell = matrix->begin(); currentCell != matrix->end(); currentCell++){
                                //is this a distance between 2 members of this bin
-                               it = binMap.find(currentCell->row);
-                               it2 = binMap.find(currentCell->column);
+                               map<int, string>::iterator it = binMap.find(currentCell->row);
+                               map<int, string>::iterator it2 = binMap.find(currentCell->column);
                                
                                //sum the distance of the sequences in the bin to eachother
                                if ((it != binMap.end()) && (it2 != binMap.end())) {
@@ -381,7 +371,7 @@ string GetOTURepCommand::FindRep(int bin, string& group, ListVector* thisList) {
                        }
                        
                        //smallest sum is the representative
-                       for (it4 = sums.begin(); it4 != sums.end(); it4++) {
+                       for (map<string, float>::iterator it4 = sums.begin(); it4 != sums.end(); it4++) {
                                if (it4->second < min) {
                                        min = it4->second;
                                        minName = it4->first;
index f413d4f51f2a9c45e3a5d17dd0243a825eb71679..37c4194a8c16e0664d7cb834b4777c054b61268d 100644 (file)
@@ -44,16 +44,11 @@ private:
        ofstream out;
        ifstream in, inNames;
        bool groupError;
-       OptionParser* parser;
-       map<string, string> parameters;
-       map<string, string>::iterator it4;
+       
        bool abort, allLines;
        set<int> lines; //hold lines to be used
        set<string> labels; //holds labels to be used
        map<string, int> nameToIndex;  //maps sequence name to index in sparsematrix
-       map<int, string>::iterator it;
-       map<int, string>::iterator it2;
-       map<string, int>::iterator it3;
        
        void readNamesFile();
        int process(ListVector*);
index 9236ba070fa74974a6f6a0972911718475126645..c978bb19439db11e9fada887112ab708d7551fd2 100644 (file)
@@ -27,14 +27,14 @@ GetRAbundCommand::GetRAbundCommand(string option){
                        string Array[] =  {"line","label"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);  delete parser;
+                       OptionParser parser(option);
+                       map<string,string> parameters = parser.getParameters();
+                       
+                       ValidParameters validParameter;
                        
-                       ValidParameters* validParameter = new ValidParameters();
-               
                        //check to make sure all parameters are valid for command
-                       for (it = parameters.begin(); it != parameters.end(); it++) { 
-                               if (validParameter->isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        //make sure the user has already run the read.otu command
@@ -42,14 +42,14 @@ GetRAbundCommand::GetRAbundCommand(string option){
                        
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
-                       line = validParameter->validFile(parameters, "line", false);                            
+                       line = validParameter.validFile(parameters, "line", false);                             
                        if (line == "not found") { line = "";  }
                        else { 
                                if(line != "all") {  splitAtDash(line, lines);  allLines = 0;  }
                                else { allLines = 1;  }
                        }
                        
-                       label = validParameter->validFile(parameters, "label", false);                  
+                       label = validParameter.validFile(parameters, "label", false);                   
                        if (label == "not found") { label = ""; }
                        else { 
                                if(label != "all") {  splitAtDash(label, labels);  allLines = 0;  }
@@ -65,8 +65,6 @@ GetRAbundCommand::GetRAbundCommand(string option){
                                lines = globaldata->lines;
                        }
                                
-                       delete validParameter;
-                       
                        if (abort == false) {
                                filename = getRootName(globaldata->inputFileName) + "rabund";
                                openOutputFile(filename, out);
index 4b2c37f11340e8dfc940f549b2c97a7c8c339b38..38b5ec7643fdd4e79e4d70408c59ba9fe3210be0 100644 (file)
@@ -33,9 +33,7 @@ private:
        InputData* input;
        ListVector* list;
        RAbundVector* rabund;
-       OptionParser* parser;
-       map<string, string> parameters;
-       map<string, string>::iterator it;
+
        bool abort, allLines;
        set<int> lines; //hold lines to be used
        set<string> labels; //holds labels to be used
index b3aa54f77a883579a29c601c2d5e737e1c1cae09..6670980dde157a7740f9984309123b2a63625475 100644 (file)
@@ -27,14 +27,14 @@ GetSAbundCommand::GetSAbundCommand(string option){
                        string Array[] =  {"line","label"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);  delete parser;
+                       OptionParser parser(option);
+                       map<string,string> parameters = parser.getParameters();
+                       
+                       ValidParameters validParameter;
                        
-                       ValidParameters* validParameter = new ValidParameters();
-               
                        //check to make sure all parameters are valid for command
-                       for (it = parameters.begin(); it != parameters.end(); it++) { 
-                               if (validParameter->isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        //make sure the user has already run the read.otu command
@@ -42,14 +42,14 @@ GetSAbundCommand::GetSAbundCommand(string option){
                        
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
-                       line = validParameter->validFile(parameters, "line", false);                            
+                       line = validParameter.validFile(parameters, "line", false);                             
                        if (line == "not found") { line = "";  }
                        else { 
                                if(line != "all") {  splitAtDash(line, lines);  allLines = 0;  }
                                else { allLines = 1;  }
                        }
                        
-                       label = validParameter->validFile(parameters, "label", false);                  
+                       label = validParameter.validFile(parameters, "label", false);                   
                        if (label == "not found") { label = ""; }
                        else { 
                                if(label != "all") {  splitAtDash(label, labels);  allLines = 0;  }
@@ -65,8 +65,6 @@ GetSAbundCommand::GetSAbundCommand(string option){
                                lines = globaldata->lines;
                        }
                                
-                       delete validParameter;
-                       
                        if (abort == false) {
                                filename = getRootName(globaldata->inputFileName) + "sabund";
                                openOutputFile(filename, out);
index cd95d94e915f53d947e37b12127b898d65d43fd8..dcda3aafd7ff5a6c53cd2534a342aabba4a42215 100644 (file)
@@ -34,9 +34,7 @@ private:
        OrderVector* lastOrder;
        InputData* input;
        SAbundVector* sabund;
-       OptionParser* parser;
-       map<string, string> parameters;
-       map<string, string>::iterator it;
+
        bool abort, allLines;
        set<int> lines; //hold lines to be used
        set<string> labels; //holds labels to be used
index 68f7fc389bb70948c1a22255af0cec275ba0ca5a..fe3c11b87dba7519ebec6c1e39168b764563233e 100644 (file)
@@ -1,6 +1,6 @@
+
+
 #include "globaldata.hpp"
-#include "tree.h"
-#include "sparsematrix.hpp"
 
 /*******************************************************/
 
@@ -25,15 +25,12 @@ 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::getFastaFile()            {       return fastafile;               }       
 string GlobalData::getFormat()                 {       return format;                  }
-string GlobalData::getCandidateFile()  {       return candidatefile;   }
-
 
 void GlobalData::setListFile(string file)              {       listfile = file;        inputFileName = file;                                   }
-void GlobalData::setFastaFile(string file)             {       fastafile = file;       inputFileName = file;                                   }
+//void GlobalData::setFastaFile(string file)           {       fastafile = file;       inputFileName = file;                                   }
 void GlobalData::setTreeFile(string file)              {       treefile = file;        inputFileName = file;                                   }
-void GlobalData::setCandidateFile(string file) {       candidatefile = file;                                                                           }
 void GlobalData::setRabundFile(string file)            {       rabundfile = file;      inputFileName = file;                                   }
 void GlobalData::setSabundFile(string file)            {       sabundfile = file;      inputFileName = file;                                   }
 void GlobalData::setPhylipFile(string file)            {       phylipfile = file;    inputFileName = file;                                     }
@@ -59,19 +56,20 @@ GlobalData::GlobalData() {
 /******************************************************/
 void GlobalData::clear() {
        //option definitions should go here...
-       phylipfile              =       "";
-       columnfile              =       "";
+       phylipfile              =       ""; //do we need this?
+       columnfile              =       ""; //do we need this?
        listfile                =       "";
        rabundfile              =       "";
        sabundfile              =       "";
-       namefile                =       "";
-       groupfile               =       ""; 
+       namefile                =       ""; //do we need this?
+       groupfile               =       ""; //do we need this?
        orderfile               =       "";
-       fastafile               =   "";
+//     fastafile               =   ""; //do we need this?
        treefile                =       "";
        sharedfile              =       "";
-       candidatefile   =       "";
 }
+
+
 /*******************************************************/
 
 /******************************************************/
index 1d38d63afc4df198599b77cf725b734c531a33ac..6515521768bfe2291775965e80eb94eac4d7a760 100644 (file)
@@ -7,6 +7,8 @@
 #include "rabundvector.hpp"
 #include "sabundvector.hpp"
 #include "listvector.hpp"
+#include "tree.h"
+#include "sparsematrix.hpp"
 
 class ListVector;
 class SharedListVector;
@@ -49,28 +51,30 @@ public:
        string getListFile();
        string getRabundFile();
        string getSabundFile();
-       string getNameFile();
-       string getGroupFile();
+       string getNameFile();   //do we need this?
+       string getGroupFile();  //do we need this?
        string getOrderFile();
-       string getFastaFile();
+//     string getFastaFile();
        string getTreeFile();
        string getSharedFile();
-       string getFormat();
-       string getCandidateFile();
-               
+       string getFormat();     //do we need this?
+//     string getCandidateFile();
+//     string getTemplateFile();
+
        void setListFile(string);
-       void setFastaFile(string);
+//     void setFastaFile(string);
        void setTreeFile(string);
-       void setCandidateFile(string);
-       void setGroupFile(string);      
+//     void setCandidateFile(string);
+//     void setTemplateFile(string);
+       void setGroupFile(string);              //do we need this?
        void setPhylipFile(string);
        void setColumnFile(string);
-       void setNameFile(string);
+       void setNameFile(string);       //do we need this?
        void setRabundFile(string);
        void setSabundFile(string);
        void setSharedFile(string);
        void setOrderFile(string file);
-       void setFormat(string);
+       void setFormat(string); //do we need this?
        
        void clear(); 
        void clearLabels();
@@ -80,7 +84,7 @@ public:
        
 private:
 
-       string phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, orderfile, fastafile, treefile, sharedfile, format, candidatefile;
+       string phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, orderfile, treefile, sharedfile, format;
 
        static GlobalData* _uniqueInstance;
        GlobalData( const GlobalData& ); // Disable copy constructor
index e707b604a76d204571dc599f7734de817758d7ee..3ed606f17be79024c72cf9834f499128a06d6a2e 100644 (file)
@@ -13,7 +13,7 @@
 HeatMap::HeatMap(string sort, string scale){
        try {
                globaldata = GlobalData::getInstance();
-               format = globaldata->getFormat();
+//             format = globaldata->getFormat();
                sorted = sort;
                scaler = scale;
        }
index b0950419d492eca91c03f263bec08b9217e67d00..766f7da570168ca456b0ca0a9356911fa5c93f80 100644 (file)
@@ -28,14 +28,14 @@ HeatMapCommand::HeatMapCommand(string option){
                        string AlignArray[] =  {"groups","line","label","sorted","scale"};
                        vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);  delete parser;
+                       OptionParser parser(option);
+                       map<string,string> parameters = parser.getParameters();
+                       
+                       ValidParameters validParameter;
                        
-                       ValidParameters* validParameter = new ValidParameters();
-               
                        //check to make sure all parameters are valid for command
-                       for (it = parameters.begin(); it != parameters.end(); it++) { 
-                               if (validParameter->isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        //make sure the user has already run the read.otu command
@@ -45,14 +45,14 @@ HeatMapCommand::HeatMapCommand(string option){
 
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
-                       line = validParameter->validFile(parameters, "line", false);                            
+                       line = validParameter.validFile(parameters, "line", false);                             
                        if (line == "not found") { line = "";  }
                        else { 
                                if(line != "all") {  splitAtDash(line, lines);  allLines = 0;  }
                                else { allLines = 1;  }
                        }
                        
-                       label = validParameter->validFile(parameters, "label", false);                  
+                       label = validParameter.validFile(parameters, "label", false);                   
                        if (label == "not found") { label = ""; }
                        else { 
                                if(label != "all") {  splitAtDash(label, labels);  allLines = 0;  }
@@ -68,19 +68,16 @@ HeatMapCommand::HeatMapCommand(string option){
                                lines = globaldata->lines;
                        }
                        
-                       groups = validParameter->validFile(parameters, "groups", false);                        
+                       groups = validParameter.validFile(parameters, "groups", false);                 
                        if (groups == "not found") { groups = ""; }
                        else { 
                                splitAtDash(groups, Groups);
                                globaldata->Groups = Groups;
                        }
                        
-                       sorted = validParameter->validFile(parameters, "sorted", false);                        if (sorted == "not found") { sorted = "T"; }
+                       sorted = validParameter.validFile(parameters, "sorted", false);                 if (sorted == "not found") { sorted = "T"; }
                 
-                       scale = validParameter->validFile(parameters, "scale", false);                          if (scale == "not found") { scale = "log10"; }
-                 
-
-                       delete validParameter;
+                       scale = validParameter.validFile(parameters, "scale", false);                           if (scale == "not found") { scale = "log10"; }
                        
                        if (abort == false) {
                                heatmap = new HeatMap(sorted, scale);
index 2ae9882db4ff0c5390293cdfd6ea0e2b2c496c11..6d6c1d55020b170d8072b5a860ea7f89a1e50e71 100644 (file)
@@ -36,9 +36,7 @@ private:
        RAbundVector* rabund;
        vector<SharedRAbundVector*> lookup;
        HeatMap* heatmap;
-       OptionParser* parser;
-       map<string, string> parameters;
-       map<string, string>::iterator it;
+
        bool abort, allLines;
        set<int> lines; //hold lines to be used
        set<string> labels; //holds labels to be used
index 0c9502f3845341471bb8e549b516cfe2e16792b8..68076d3dee6e47f40292f63f66d859a24931e569 100644 (file)
@@ -40,14 +40,14 @@ HeatMapSimCommand::HeatMapSimCommand(string option){
                        string AlignArray[] =  {"groups","line","label", "calc"};
                        vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);  delete parser;
+                       OptionParser parser(option);
+                       map<string,string> parameters = parser.getParameters();
+                       
+                       ValidParameters validParameter;
                        
-                       ValidParameters* validParameter = new ValidParameters();
-               
                        //check to make sure all parameters are valid for command
-                       for (it = parameters.begin(); it != parameters.end(); it++) { 
-                               if (validParameter->isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        //make sure the user has already run the read.otu command
@@ -57,14 +57,14 @@ HeatMapSimCommand::HeatMapSimCommand(string option){
 
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
-                       line = validParameter->validFile(parameters, "line", false);                            
+                       line = validParameter.validFile(parameters, "line", false);                             
                        if (line == "not found") { line = "";  }
                        else { 
                                if(line != "all") {  splitAtDash(line, lines);  allLines = 0;  }
                                else { allLines = 1;  }
                        }
                        
-                       label = validParameter->validFile(parameters, "label", false);                  
+                       label = validParameter.validFile(parameters, "label", false);                   
                        if (label == "not found") { label = ""; }
                        else { 
                                if(label != "all") {  splitAtDash(label, labels);  allLines = 0;  }
@@ -80,22 +80,20 @@ HeatMapSimCommand::HeatMapSimCommand(string option){
                                lines = globaldata->lines;
                        }
                        
-                       calc = validParameter->validFile(parameters, "calc", false);                    
+                       calc = validParameter.validFile(parameters, "calc", false);                     
                        if (calc == "not found") { calc = "jclass-thetayc";  }
                        else { 
                                 if (calc == "default")  {  calc = "jclass-thetayc";  }
                        }
                        splitAtDash(calc, Estimators);
                        
-                       groups = validParameter->validFile(parameters, "groups", false);                        
+                       groups = validParameter.validFile(parameters, "groups", false);                 
                        if (groups == "not found") { groups = ""; }
                        else { 
                                splitAtDash(groups, Groups);
                                globaldata->Groups = Groups;
                        }
                        
-                       delete validParameter;
-                       
                        if (abort == false) {
                                validCalculator = new ValidCalculators();
                                heatmap = new HeatMapSim();
index 0acce707e01e6567f9111bd58f83910aa90eba92..4a97342c27f801ea7bb959f0c411ace6f33393dc 100644 (file)
 //**********************************************************************************************************************
 
 HelpCommand::HelpCommand(string option){
-       globaldata = GlobalData::getInstance();
-       
-       if (option != "") { cout << "There are no valid parameters for the help() command." << endl;  }
        
+       if (option != "") { cout << "There are no valid parameters for the help() command." << endl;  } 
        validCommands = new ValidCommands();
-       }
+}
 
 //**********************************************************************************************************************
 
index c303678131df5a937174ed1a2b3e75858e174877..4e68388d278c85b69a9a4fb7be9db6e19a4a1253 100644 (file)
@@ -12,7 +12,6 @@
 /* This class is designed to aid the user in running mothur. */
 
 #include "command.hpp"
-#include "globaldata.hpp"
 #include "validcommands.h"
 
 
@@ -25,7 +24,6 @@ public:
        void help() {};
        
 private:
-       GlobalData* globaldata;
        ValidCommands* validCommands;
        
 private:
index e7e1aa77a49005f553c2657271a7d1ecd6dbac12..9a71a038cd4d0bd29d7eaeeeaae96d9847d81fa8 100644 (file)
@@ -37,14 +37,14 @@ LibShuffCommand::LibShuffCommand(string option){
                        string Array[] =  {"iters","groups","step","form","cutoff"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);  delete parser;
+                       OptionParser parser(option);
+                       map<string, string> parameters = parser.getParameters();
                        
-                       ValidParameters* validParameter = new ValidParameters();
+                       ValidParameters validParameter;
                
                        //check to make sure all parameters are valid for command
-                       for (it = parameters.begin(); it != parameters.end(); it++) { 
-                               if (validParameter->isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        //make sure the user has already run the read.dist command
@@ -54,7 +54,7 @@ LibShuffCommand::LibShuffCommand(string option){
                                                
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
-                       groups = validParameter->validFile(parameters, "groups", false);                        
+                       groups = validParameter.validFile(parameters, "groups", false);                 
                        if (groups == "not found") { groups = ""; savegroups = groups; }
                        else { 
                                savegroups = groups;
@@ -63,18 +63,16 @@ LibShuffCommand::LibShuffCommand(string option){
                        }
                                
                        string temp;
-                       temp = validParameter->validFile(parameters, "iters", false);                           if (temp == "not found") { temp = "10000"; }
+                       temp = validParameter.validFile(parameters, "iters", false);                            if (temp == "not found") { temp = "10000"; }
                        convert(temp, iters); 
                        
-                       temp = validParameter->validFile(parameters, "cutoff", false);                          if (temp == "not found") { temp = "1.0"; }
+                       temp = validParameter.validFile(parameters, "cutoff", false);                           if (temp == "not found") { temp = "1.0"; }
                        convert(temp, cutOff); 
                        
-                       temp = validParameter->validFile(parameters, "step", false);                            if (temp == "not found") { temp = "0.01"; }
+                       temp = validParameter.validFile(parameters, "step", false);                             if (temp == "not found") { temp = "0.01"; }
                        convert(temp, step); 
        
-                       userform = validParameter->validFile(parameters, "form", false);                        if (userform == "not found") { userform = "integral"; }
-                       
-                       delete validParameter;
+                       userform = validParameter.validFile(parameters, "form", false);                 if (userform == "not found") { userform = "integral"; }
                        
                        if (abort == false) {
                        
index 150bdb4aecdfeeae4b91b6e0152eb812dca846ea..1e5726dd770f928b62ca8ef07fa3c24150c0a8b5 100644 (file)
@@ -19,34 +19,32 @@ class GlobalData;
 
 class LibShuffCommand : public Command {
        
-       public:
-               LibShuffCommand(string);        
-               ~LibShuffCommand(){};
-               int execute();
-               void help();    
+public:
+       LibShuffCommand(string);        
+       ~LibShuffCommand(){};
+       int execute();
+       void help();    
+
+private:
+       vector<string> groupNames;
        
-       private:
-               vector<string> groupNames;
-               
-               void setGroups();
-               void printCoverageFile();
-               void printSummaryFile();
-
-               GlobalData* globaldata;
-               FullMatrix* matrix;
-               Libshuff* form;
-               float cutOff, step;
-               int numGroups, numComp, iters;
-               string coverageFile, summaryFile;
-               vector<vector<int> > pValueCounts;
-               vector<vector<double> > savedDXYValues;
-               vector<vector<vector<double> > > savedMinValues;
-               OptionParser* parser;
-               map<string, string> parameters;
-               map<string, string>::iterator it;
-               bool abort;
-               string outputFile, groups, userform, savegroups;
-               vector<string> Groups; //holds groups to be used
+       void setGroups();
+       void printCoverageFile();
+       void printSummaryFile();
+
+       GlobalData* globaldata;
+       FullMatrix* matrix;
+       Libshuff* form;
+       float cutOff, step;
+       int numGroups, numComp, iters;
+       string coverageFile, summaryFile;
+       vector<vector<int> > pValueCounts;
+       vector<vector<double> > savedDXYValues;
+       vector<vector<vector<double> > > savedMinValues;
+
+       bool abort;
+       string outputFile, groups, userform, savegroups;
+       vector<string> Groups; //holds groups to be used
 };
 
 #endif
index 1e4de7597c8dec90d78d48a8cf33e69cea93a086..e848647997c1a522f6a583d2144646ac20f7ac51 100644 (file)
@@ -40,14 +40,14 @@ MatrixOutputCommand::MatrixOutputCommand(string option){
                        string Array[] =  {"line","label","calc","groups"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);  delete parser;
+                       OptionParser parser(option);
+                       map<string,string> parameters  = parser.getParameters();
                        
-                       ValidParameters* validParameter = new ValidParameters();
+                       ValidParameters validParameter;
                
                        //check to make sure all parameters are valid for command
-                       for (it = parameters.begin(); it != parameters.end(); it++) { 
-                               if (validParameter->isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        //make sure the user has already run the read.otu command
@@ -58,14 +58,14 @@ MatrixOutputCommand::MatrixOutputCommand(string option){
                        
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
-                       line = validParameter->validFile(parameters, "line", false);                            
+                       line = validParameter.validFile(parameters, "line", false);                             
                        if (line == "not found") { line = "";  }
                        else { 
                                if(line != "all") {  splitAtDash(line, lines);  allLines = 0;  }
                                else { allLines = 1;  }
                        }
                        
-                       label = validParameter->validFile(parameters, "label", false);                  
+                       label = validParameter.validFile(parameters, "label", false);                   
                        if (label == "not found") { label = ""; }
                        else { 
                                if(label != "all") {  splitAtDash(label, labels);  allLines = 0;  }
@@ -81,23 +81,20 @@ MatrixOutputCommand::MatrixOutputCommand(string option){
                                lines = globaldata->lines;
                        }
                                
-                       groups = validParameter->validFile(parameters, "groups", false);                        
+                       groups = validParameter.validFile(parameters, "groups", false);                 
                        if (groups == "not found") { groups = ""; }
                        else { 
                                splitAtDash(groups, Groups);
                                globaldata->Groups = Groups;
                        }
                                
-                       calc = validParameter->validFile(parameters, "calc", false);                    
+                       calc = validParameter.validFile(parameters, "calc", false);                     
                        if (calc == "not found") { calc = "jclass-thetayc";  }
                        else { 
                                 if (calc == "default")  {  calc = "jclass-thetayc";  }
                        }
                        splitAtDash(calc, Estimators);
 
-                       delete validParameter;
-                       
-                       
                        if (abort == false) {
                        
                                validCalculator = new ValidCalculators();
index d6099326a69ac5ef1daf95ce192bc3cad1fd712f..07743e5b4df6d867323c89c2acd78b241486bd00 100644 (file)
@@ -45,9 +45,7 @@ private:
        string exportFileName;
        int numGroups;
        ofstream out;
-       OptionParser* parser;
-       map<string, string> parameters;
-       map<string, string>::iterator it;
+
        bool abort, allLines;
        set<int> lines; //hold lines to be used
        set<string> labels; //holds labels to be used
diff --git a/mergefilecommand.cpp b/mergefilecommand.cpp
new file mode 100644 (file)
index 0000000..3342c48
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+ *  mergefilecommand.cpp
+ *  Mothur
+ *
+ *  Created by Pat Schloss on 6/14/09.
+ *  Copyright 2009 Patrick D. Schloss. All rights reserved.
+ *
+ */
+
+#include "mergefilecommand.h"
+
+//**********************************************************************************************************************
+
+MergeFileCommand::MergeFileCommand(string option){
+       try {
+               abort = false;
+               
+               if(option == "help") {
+                       help();
+                       abort = true; 
+               }
+               else {
+                       //valid paramters for this command
+                       string Array[] =  {"input", "output"};
+                       vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       
+                       OptionParser parser(option);
+                       map<string,string> parameters = parser.getParameters();
+                       
+                       ValidParameters validParameter;
+                       
+                       //check to make sure all parameters are valid for command
+                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       }
+                       
+                       string fileList = validParameter.validFile(parameters, "input", false);                 
+                       if(fileList == "not found") { cout << "you must enter two or more file names" << endl;  abort=true;  }
+                       else{   splitAtDash(fileList, fileNames);       }
+                       
+                       numInputFiles = fileNames.size();
+                       ifstream testFile;
+                       if(numInputFiles == 0){
+                               cout << "you must enter two or more file names and you entered " << fileNames.size() <<  " file names" << endl;
+                               abort=true;  
+                       }
+                       else{
+                               for(int i=0;i<numInputFiles;i++){
+                                       if(openInputFile(fileNames[i], testFile)){      abort = true;   }
+                                       testFile.close();
+                               }
+                       }   
+                       
+                       outputFileName = validParameter.validFile(parameters, "output", false);                 
+                       if (outputFileName == "not found") { cout << "you must enter an output file name" << endl;  abort=true;  }
+               }
+                       
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the MergeFileCommand class Function MergeFileCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the MergeFileCommand class function MergeFileCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+//**********************************************************************************************************************
+
+MergeFileCommand::~MergeFileCommand()  {       /*      do nothing      */      }
+
+//**********************************************************************************************************************
+
+int MergeFileCommand::execute(){
+       try {
+               if (abort == true) {    return 0;       }
+               
+               ofstream outputFile;
+               openOutputFile(outputFileName, outputFile);
+               
+               ifstream inputFile;
+               char c;
+               for(int i=0;i<numInputFiles;i++){
+                       openInputFile(fileNames[i], inputFile);
+                       
+                       while(!inputFile.eof()){        c = inputFile.get(); outputFile << c;   }
+                       
+                       inputFile.close();
+               }
+               return 0;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the BinSeqCommand class Function BinSeqCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the BinSeqCommand class function BinSeqCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+       
+}
+
+//**********************************************************************************************************************
+
+void MergeFileCommand::help(){
+       try {
+               cout << "The merge.file command..." << endl;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the MergeFileCommand class Function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the MergeFileCommand class function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+       
+}
+
+//**********************************************************************************************************************
diff --git a/mergefilecommand.h b/mergefilecommand.h
new file mode 100644 (file)
index 0000000..bd94d77
--- /dev/null
@@ -0,0 +1,30 @@
+#ifndef MERGEFILECOMMAND_H
+#define MERGEFILECOMMAND_H
+
+/*
+ *  mergefilecommand.h
+ *  Mothur
+ *
+ *  Created by Pat Schloss on 6/14/09.
+ *  Copyright 2009 Patrick D. Schloss. All rights reserved.
+ *
+ */
+
+#include "mothur.h"
+#include "command.hpp"
+
+class MergeFileCommand : public Command {
+public:
+       MergeFileCommand(string);
+       ~MergeFileCommand();
+       int execute();
+       void help();    
+
+private:
+       vector<string> fileNames;
+       string outputFileName;
+       int numInputFiles;
+       bool abort;
+};
+
+#endif
index 7ff6ae7691b0437c1589051778d929307dbe36f1..2de1621bcb9a73ac9c17b02384ee6d9b0f3f5d49 100644 (file)
 #include "optionparser.h"
 
 /***********************************************************************/
-void OptionParser::parse(string option, map<string, string>& container) {
+
+OptionParser::OptionParser(string option) {
        try {
                
                if (option != "") {
-               
+                       
                        string key, value;              
                        //reads in parameters and values
                        while((option.find_first_of(',') != -1)) {  //while there are parameters
-                                       splitAtComma(value, option);
-                                       splitAtEquals(key, value);
-                                       container[key] = value;
+                               splitAtComma(value, option);
+                               splitAtEquals(key, value);
+                               parameters[key] = value;
                        }
-               
+                       
                        //in case there is no comma and to get last parameter after comma
                        splitAtEquals(key, option);
-                       container[key] = option;
+                       parameters[key] = option;
                }
        }
        catch(exception& e) {
@@ -37,4 +38,9 @@ void OptionParser::parse(string option, map<string, string>& container) {
                exit(1);
        }
 }
-/***********************************************************************/
\ No newline at end of file
+
+/***********************************************************************/
+
+map<string, string> OptionParser::getParameters() {    return parameters;      }
+
+/***********************************************************************/
index b4d0dcb8691e103aa5c7259f3733d180e93cf29a..dab14debe385472c35f5f405aa8e12b8b1dabcf0 100644 (file)
 /***********************************************************************/
 
 class OptionParser {
-       public:
-               OptionParser() {}
-               ~OptionParser() {}
-               void parse(string, map<string, string>&);  //pass it an option string and a container
-                                                                                         //fills the container key=parameter name, value=parameter value
+public:
+       OptionParser(string);
+       ~OptionParser() {}
+       map<string, string> getParameters();
+private:
+       map<string, string> parameters;
 };
 
 /***********************************************************************/
index e081279489deb949427f30c5208cec0f8bb50290..266dd3b9a2ad5c3e7730ac6950e7077164b12bb2 100644 (file)
@@ -24,17 +24,17 @@ ParsimonyCommand::ParsimonyCommand(string option) {
                        string Array[] =  {"random","groups","iters"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);  delete parser;
+                       OptionParser parser(option);
+                       map<string, string> parameters = parser.getParameters();
                        
-                       ValidParameters* validParameter = new ValidParameters();
+                       ValidParameters validParameter;
                
                        //check to make sure all parameters are valid for command
-                       for (it4 = parameters.begin(); it4 != parameters.end(); it4++) { 
-                               if (validParameter->isValidParameter(it4->first, myArray, it4->second) != true) {  abort = true;  }
+                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
-                       randomtree = validParameter->validFile(parameters, "random", false);            if (randomtree == "not found") { randomtree = ""; }
+                       randomtree = validParameter.validFile(parameters, "random", false);             if (randomtree == "not found") { randomtree = ""; }
                        
                        //are you trying to use parsimony without reading a tree or saying you want random distribution
                        if (randomtree == "")  {
@@ -44,18 +44,16 @@ ParsimonyCommand::ParsimonyCommand(string option) {
                                                
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
-                       groups = validParameter->validFile(parameters, "groups", false);                        
+                       groups = validParameter.validFile(parameters, "groups", false);                 
                        if (groups == "not found") { groups = ""; }
                        else { 
                                splitAtDash(groups, Groups);
                                globaldata->Groups = Groups;
                        }
                                
-                       itersString = validParameter->validFile(parameters, "iters", false);                    if (itersString == "not found") { itersString = "1000"; }
+                       itersString = validParameter.validFile(parameters, "iters", false);                     if (itersString == "not found") { itersString = "1000"; }
                        convert(itersString, iters); 
-                       
-                       delete validParameter;
-                       
+                                               
                        if (abort == false) {
                                //randomtree will tell us if user had their own treefile or if they just want the random distribution
                                //user has entered their own tree
@@ -149,7 +147,7 @@ int ParsimonyCommand::execute() {
                                for(int k = 0; k < numComp; k++) {
 
                                        //update uscoreFreq
-                                       it = uscoreFreq[k].find(userData[k]);
+                                       map<int,double>::iterator it = uscoreFreq[k].find(userData[k]);
                                        if (it == uscoreFreq[k].end()) {//new score
                                                uscoreFreq[k][userData[k]] = 1;
                                        }else{ uscoreFreq[k][userData[k]]++; }
@@ -175,8 +173,8 @@ int ParsimonyCommand::execute() {
                                        
                                for(int r = 0; r < numComp; r++) {
                                        //add trees pscore to map of scores
-                                       it2 = rscoreFreq[r].find(randomData[r]);
-                                       if (it2 != rscoreFreq[r].end()) {//already have that score
+                                       map<int,double>::iterator it = rscoreFreq[r].find(randomData[r]);
+                                       if (it != rscoreFreq[r].end()) {//already have that score
                                                rscoreFreq[r][randomData[r]]++;
                                        }else{//first time we have seen this score
                                                rscoreFreq[r][randomData[r]] = 1;
@@ -206,8 +204,8 @@ int ParsimonyCommand::execute() {
                        
                                for(int r = 0; r < numComp; r++) {
                                        //add trees pscore to map of scores
-                                       it2 = rscoreFreq[r].find(randomData[r]);
-                                       if (it2 != rscoreFreq[r].end()) {//already have that score
+                                       map<int,double>::iterator it = rscoreFreq[r].find(randomData[r]);
+                                       if (it != rscoreFreq[r].end()) {//already have that score
                                                rscoreFreq[r][randomData[r]]++;
                                        }else{//first time we have seen this score
                                                rscoreFreq[r][randomData[r]] = 1;
@@ -228,9 +226,9 @@ int ParsimonyCommand::execute() {
                        float rcumul = 0.0000;
                        float ucumul = 0.0000;
                        //this loop fills the cumulative maps and put 0.0000 in the score freq map to make it easier to print.
-                       for (it = validScores.begin(); it != validScores.end(); it++) { 
+                       for (map<int,double>::iterator it = validScores.begin(); it != validScores.end(); it++) { 
                                if (randomtree == "") {
-                                       it2 = uscoreFreq[a].find(it->first);
+                                       map<int,double>::iterator it2 = uscoreFreq[a].find(it->first);
                                        //user data has that score 
                                        if (it2 != uscoreFreq[a].end()) { uscoreFreq[a][it->first] /= T.size(); ucumul+= it2->second;  }
                                        else { uscoreFreq[a][it->first] = 0.0000; } //no user trees with that score
@@ -239,7 +237,7 @@ int ParsimonyCommand::execute() {
                                }
                        
                                //make rscoreFreq map and rCumul
-                               it2 = rscoreFreq[a].find(it->first);
+                               map<int,double>::iterator it2 = rscoreFreq[a].find(it->first);
                                //get percentage of random trees with that info
                                if (it2 != rscoreFreq[a].end()) {  rscoreFreq[a][it->first] /= iters; rcumul+= it2->second;  }
                                else { rscoreFreq[a][it->first] = 0.0000; } //no random trees with that score
@@ -298,7 +296,7 @@ void ParsimonyCommand::printParsimonyFile() {
                for(int a = 0; a < numComp; a++) {
                        output->initFile(groupComb[a], tags);
                        //print each line
-                       for (it = validScores.begin(); it != validScores.end(); it++) { 
+                       for (map<int,double>::iterator it = validScores.begin(); it != validScores.end(); it++) { 
                                if (randomtree == "") {
                                        data.push_back(it->first);  data.push_back(uscoreFreq[a][it->first]); data.push_back(uCumul[a][it->first]); data.push_back(rscoreFreq[a][it->first]); data.push_back(rCumul[a][it->first]); 
                                }else{
index bbcd6af5595d186610dae2818836d4d74b15f0f3..63980c254545ea07e7a4ffe71b1d9c496407ecf1 100644 (file)
 class GlobalData;
 
 class ParsimonyCommand : public Command {
+
+public:
+       ParsimonyCommand(string);       
+       ~ParsimonyCommand() { delete pars; delete util; delete output; }
+       int execute();  
+       void help();
+
+private:
+       GlobalData* globaldata;
+       SharedUtil* util;
+       FileOutput* output;
+       vector<Tree*> T;           //user trees
+       Tree* randT;  //random tree
+       Tree* copyUserTree; 
+       TreeMap* tmap; 
+       TreeMap* savetmap;
+       Parsimony* pars;
+       vector<string> groupComb; // AB. AC, BC...
+       string sumFile, randomtree, allGroups;
+       int iters, numGroups, numComp, counter;
+       vector<int> numEachGroup; //vector containing the number of sequences in each group the users wants for random distrib.
+       vector< vector<float> > userTreeScores; //scores for users trees for each comb.
+       vector< vector<float> > UScoreSig;  //tree score signifigance when compared to random trees - percentage of random trees with that score or lower.
+       EstOutput userData;                     //pscore info for user tree
+       EstOutput randomData;           //pscore info for random trees
+       map<int, double>  validScores;  //map contains scores from both user and random
+       vector< map<int, double> > rscoreFreq;  //map <pscore, number of random trees with that score.> -vector entry for each combination.
+       vector< map<int, double> > uscoreFreq;  //map <pscore, number of user trees with that score.> -vector entry for each combination.
+       vector< map<int, double> > rCumul;  //map <pscore, cumulative percentage of number of random trees with that score or lower.> -vector entry for each combination.
+       vector< map<int, double> > uCumul;  //map <pscore, cumulative percentage of number of user trees with that score or lower .> -vector entry for each combination.
        
-       public:
-               ParsimonyCommand(string);       
-               ~ParsimonyCommand() { delete pars; delete util; delete output; }
-               int execute();  
-               void help();
+       ofstream outSum;
        
-       private:
-               GlobalData* globaldata;
-               SharedUtil* util;
-               FileOutput* output;
-               vector<Tree*> T;           //user trees
-               Tree* randT;  //random tree
-               Tree* copyUserTree; 
-               TreeMap* tmap; 
-               TreeMap* savetmap;
-               Parsimony* pars;
-               vector<string> groupComb; // AB. AC, BC...
-               string sumFile, randomtree, allGroups;
-               int iters, numGroups, numComp, counter;
-               vector<int> numEachGroup; //vector containing the number of sequences in each group the users wants for random distrib.
-               vector< vector<float> > userTreeScores; //scores for users trees for each comb.
-               vector< vector<float> > UScoreSig;  //tree score signifigance when compared to random trees - percentage of random trees with that score or lower.
-               EstOutput userData;                     //pscore info for user tree
-               EstOutput randomData;           //pscore info for random trees
-               map<int, double>  validScores;  //map contains scores from both user and random
-               vector< map<int, double> > rscoreFreq;  //map <pscore, number of random trees with that score.> -vector entry for each combination.
-               vector< map<int, double> > uscoreFreq;  //map <pscore, number of user trees with that score.> -vector entry for each combination.
-               vector< map<int, double> > rCumul;  //map <pscore, cumulative percentage of number of random trees with that score or lower.> -vector entry for each combination.
-               vector< map<int, double> > uCumul;  //map <pscore, cumulative percentage of number of user trees with that score or lower .> -vector entry for each combination.
-               map<int, double>::iterator it;
-               map<int, double>::iterator it2;
-               
-               ofstream out, outSum;
-               ifstream inFile;
-               
-               OptionParser* parser;
-               map<string, string> parameters;
-               map<string, string>::iterator it4;
-               bool abort;
-               string groups, itersString;
-               vector<string> Groups; //holds groups to be used
 
-               void printParsimonyFile();  
-               void printUSummaryFile();
-               void getUserInput();
-               
+       bool abort;
+       string groups, itersString;
+       vector<string> Groups; //holds groups to be used
+
+       void printParsimonyFile();  
+       void printUSummaryFile();
+       void getUserInput();
+       
 };
 
 
index 680f68c1e6694557edac00e259449d0d53169400..6bf42fc8a2e7d33374f73ba04d0df4f8eff57e1a 100644 (file)
@@ -39,14 +39,14 @@ RareFactCommand::RareFactCommand(string option){
                        string Array[] =  {"iters","freq","line","label","calc","abund"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);  delete parser;
+                       OptionParser parser(option);
+                       map<string,string> parameters = parser.getParameters();
                        
-                       ValidParameters* validParameter = new ValidParameters();
+                       ValidParameters validParameter;
                
                        //check to make sure all parameters are valid for command
-                       for (it = parameters.begin(); it != parameters.end(); it++) { 
-                               if (validParameter->isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        //make sure the user has already run the read.otu command
@@ -54,14 +54,14 @@ RareFactCommand::RareFactCommand(string option){
                        
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
-                       line = validParameter->validFile(parameters, "line", false);                            
+                       line = validParameter.validFile(parameters, "line", false);                             
                        if (line == "not found") { line = "";  }
                        else { 
                                if(line != "all") {  splitAtDash(line, lines);  allLines = 0;  }
                                else { allLines = 1;  }
                        }
                        
-                       label = validParameter->validFile(parameters, "label", false);                  
+                       label = validParameter.validFile(parameters, "label", false);                   
                        if (label == "not found") { label = ""; }
                        else { 
                                if(label != "all") {  splitAtDash(label, labels);  allLines = 0;  }
@@ -77,7 +77,7 @@ RareFactCommand::RareFactCommand(string option){
                                lines = globaldata->lines;
                        }
                                
-                       calc = validParameter->validFile(parameters, "calc", false);                    
+                       calc = validParameter.validFile(parameters, "calc", false);                     
                        if (calc == "not found") { calc = "sobs";  }
                        else { 
                                 if (calc == "default")  {  calc = "sobs";  }
@@ -85,16 +85,14 @@ RareFactCommand::RareFactCommand(string option){
                        splitAtDash(calc, Estimators);
 
                        string temp;
-                       temp = validParameter->validFile(parameters, "freq", false);                    if (temp == "not found") { temp = "100"; }
+                       temp = validParameter.validFile(parameters, "freq", false);                     if (temp == "not found") { temp = "100"; }
                        convert(temp, freq); 
                        
-                       temp = validParameter->validFile(parameters, "abund", false);                   if (temp == "not found") { temp = "10"; }
+                       temp = validParameter.validFile(parameters, "abund", false);                    if (temp == "not found") { temp = "10"; }
                        convert(temp, abund); 
                        
-                       temp = validParameter->validFile(parameters, "iters", false);                   if (temp == "not found") { temp = "1000"; }
+                       temp = validParameter.validFile(parameters, "iters", false);                    if (temp == "not found") { temp = "1000"; }
                        convert(temp, nIters); 
-       
-                       delete validParameter;
                        
                        if (abort == false) {
                        
index ea867f091415354864af382505df75e97d67294a..1bcb0cf490dda8358a6ba55f042e689abc51bf69 100644 (file)
@@ -51,9 +51,7 @@ private:
        ValidCalculators* validCalculator;
        Rarefact* rCurve;
        int freq, nIters, abund;
-       OptionParser* parser;
-       map<string, string> parameters;
-       map<string, string>::iterator it;
+
        bool abort, allLines;
        set<int> lines; //hold lines to be used
        set<string> labels; //holds labels to be used
index 66ef6ddf24d6132bd355663c3dbdd24d5662c18c..d0179be91a5b2eac505632797a8ebb3f74232282 100644 (file)
@@ -30,14 +30,14 @@ RareFactSharedCommand::RareFactSharedCommand(string option){
                        string Array[] =  {"iters","line","label","calc","groups"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);  delete parser;
+                       OptionParser parser(option);
+                       map<string,string> parameters = parser.getParameters();
+                       
+                       ValidParameters validParameter;
                        
-                       ValidParameters* validParameter = new ValidParameters();
-               
                        //check to make sure all parameters are valid for command
-                       for (it = parameters.begin(); it != parameters.end(); it++) { 
-                               if (validParameter->isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        //make sure the user has already run the read.otu command
@@ -49,14 +49,14 @@ RareFactSharedCommand::RareFactSharedCommand(string option){
                        
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
-                       line = validParameter->validFile(parameters, "line", false);                            
+                       line = validParameter.validFile(parameters, "line", false);                             
                        if (line == "not found") { line = "";  }
                        else { 
                                if(line != "all") {  splitAtDash(line, lines);  allLines = 0;  }
                                else { allLines = 1;  }
                        }
                        
-                       label = validParameter->validFile(parameters, "label", false);                  
+                       label = validParameter.validFile(parameters, "label", false);                   
                        if (label == "not found") { label = ""; }
                        else { 
                                if(label != "all") {  splitAtDash(label, labels);  allLines = 0;  }
@@ -72,14 +72,14 @@ RareFactSharedCommand::RareFactSharedCommand(string option){
                                lines = globaldata->lines;
                        }
                                
-                       calc = validParameter->validFile(parameters, "calc", false);                    
+                       calc = validParameter.validFile(parameters, "calc", false);                     
                        if (calc == "not found") { calc = "sharedobserved";  }
                        else { 
                                 if (calc == "default")  {  calc = "sharedobserved";  }
                        }
                        splitAtDash(calc, Estimators);
                        
-                       groups = validParameter->validFile(parameters, "groups", false);                        
+                       groups = validParameter.validFile(parameters, "groups", false);                 
                        if (groups == "not found") { groups = ""; }
                        else { 
                                splitAtDash(groups, Groups);
@@ -87,20 +87,18 @@ RareFactSharedCommand::RareFactSharedCommand(string option){
                        }
                        
                        string temp;
-                       temp = validParameter->validFile(parameters, "iters", false);                   if (temp == "not found") { temp = "1000"; }
+                       temp = validParameter.validFile(parameters, "iters", false);                    if (temp == "not found") { temp = "1000"; }
                        convert(temp, nIters); 
                        
-                       delete validParameter;
-                       
                        if (abort == false) {
                        
                                string fileNameRoot = getRootName(globaldata->inputFileName);
-                               format = globaldata->getFormat();
-                               int i;
+//                             format = globaldata->getFormat();
+
                                
                                validCalculator = new ValidCalculators();
                                
-                               for (i=0; i<Estimators.size(); i++) {
+                               for (int i=0; i<Estimators.size(); i++) {
                                        if (validCalculator->isValidCalculator("sharedrarefaction", Estimators[i]) == true) { 
                                                if (Estimators[i] == "sharedobserved") { 
                                                        rDisplays.push_back(new RareDisplay(new SharedSobs(), new SharedThreeColumnFile(fileNameRoot+"shared.rarefaction", "")));
index d81ff6dc2d1c6588d86f9cccbb0251778bd85011..c7290f4d85ec4f8bd671d4df914cd2738dd3c4c0 100644 (file)
@@ -48,9 +48,7 @@ private:
        vector<Display*> rDisplays;
        int freq, nIters;
        string format;
-       OptionParser* parser;
-       map<string, string> parameters;
-       map<string, string>::iterator it;
+
        bool abort, allLines;
        set<int> lines; //hold lines to be used
        set<string> labels; //holds labels to be used
index 31d8308414755601166268f6088dd7142f7dfaad..b03f12e7f711c471043f879cb172cf7e99a60929 100644 (file)
@@ -22,33 +22,33 @@ ReadDistCommand::ReadDistCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"phylip","column", "name","cutoff","precision", "group"};
+                       string Array[] =  {"phylip", "column", "name", "cutoff", "precision", "group"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);  delete parser;
+                       OptionParser parser(option);
+                       map<string, string> parameters = parser.getParameters();
                        
-                       ValidParameters* validParameter = new ValidParameters();
+                       ValidParameters validParameter;
                
                        //check to make sure all parameters are valid for command
-                       for (it = parameters.begin(); it != parameters.end(); it++) { 
-                               if (validParameter->isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        globaldata->newRead();
                        
                        //check for required parameters
-                       phylipfile = validParameter->validFile(parameters, "phylip", true);
+                       phylipfile = validParameter.validFile(parameters, "phylip", true);
                        if (phylipfile == "not open") { abort = true; }
                        else if (phylipfile == "not found") { phylipfile = ""; }        
                        else {  globaldata->setPhylipFile(phylipfile);  globaldata->setFormat("phylip");        }
                        
-                       columnfile = validParameter->validFile(parameters, "column", true);
+                       columnfile = validParameter.validFile(parameters, "column", true);
                        if (columnfile == "not open") { abort = true; } 
                        else if (columnfile == "not found") { columnfile = ""; }
                        else {  globaldata->setColumnFile(columnfile); globaldata->setFormat("column"); }
                        
-                       groupfile = validParameter->validFile(parameters, "group", true);
+                       groupfile = validParameter.validFile(parameters, "group", true);
                        if (groupfile == "not open") { abort = true; }  
                        else if (groupfile == "not found") { groupfile = ""; }
                        else {  
@@ -56,15 +56,16 @@ ReadDistCommand::ReadDistCommand(string option){
                                groupMap = new GroupMap(groupfile);
                                groupMap->readMap();
                        }
-                       
-                       namefile = validParameter->validFile(parameters, "name", true);
+
+                       namefile = validParameter.validFile(parameters, "name", true);
                        if (namefile == "not open") { abort = true; }   
                        else if (namefile == "not found") { namefile = ""; }
                        else {  globaldata->setNameFile(namefile);      }
 
                        
                        //you are doing a list and group shared
-                       if ((phylipfile != "") && (groupfile != "")) { globaldata->setFormat("matrix"); }
+                       if ((phylipfile != "") && (groupfile != "")) { 
+                       globaldata->setFormat("matrix"); }
                        
                        if ((phylipfile == "") && (columnfile == "")) { cout << "When executing a read.dist command you must enter a phylip or a column." << endl; abort = true; }
                        else if ((phylipfile != "") && (columnfile != "")) { cout << "When executing a read.dist command you must enter ONLY ONE of the following: phylip or column." << endl; abort = true; }
@@ -77,21 +78,19 @@ ReadDistCommand::ReadDistCommand(string option){
                        // ...at some point should added some additional type checking...
                        //get user cutoff and precision or use defaults
                        string temp;
-                       temp = validParameter->validFile(parameters, "precision", false);                       if (temp == "not found") { temp = "100"; }
+                       temp = validParameter.validFile(parameters, "precision", false);                        if (temp == "not found") { temp = "100"; }
                        convert(temp, precision); 
                        
-                       temp = validParameter->validFile(parameters, "cutoff", false);                  if (temp == "not found") { temp = "10"; }
+                       temp = validParameter.validFile(parameters, "cutoff", false);                   if (temp == "not found") { temp = "10"; }
                        convert(temp, cutoff); 
                        cutoff += (5 / (precision * 10.0));
-
-                       delete validParameter;
                        
                        if (abort == false) {
-                               filename = globaldata->inputFileName;
+                               distFileName = globaldata->inputFileName;
                                format = globaldata->getFormat();       
                
-                               if (format == "column") { read = new ReadColumnMatrix(filename); }      
-                               else if (format == "phylip") { read = new ReadPhylipMatrix(filename); }
+                               if (format == "column") { read = new ReadColumnMatrix(distFileName); }  
+                               else if (format == "phylip") { read = new ReadPhylipMatrix(distFileName); }
                                else if (format == "matrix") { 
                                        groupMap = new GroupMap(groupfile);
                                        groupMap->readMap();
@@ -149,6 +148,7 @@ void ReadDistCommand::help(){
 }
 
 //**********************************************************************************************************************
+
 ReadDistCommand::~ReadDistCommand(){
        delete read;
        delete nameMap;
@@ -162,7 +162,7 @@ int ReadDistCommand::execute(){
                
                if (format == "matrix") {
                        ifstream in;
-                       openInputFile(filename, in);
+                       openInputFile(distFileName, in);
                        matrix = new FullMatrix(in); //reads the matrix file
                        //memory leak prevention
                        //if (globaldata->gMatrix != NULL) { delete globaldata->gMatrix;  }
index b6e3ae44de298a115ce9a72de193b51ff951ea34..868d72e6bd5184b11253dc5c9aacded459f0ee3d 100644 (file)
@@ -38,12 +38,10 @@ private:
        ReadMatrix* read;
        FullMatrix* matrix;
        GroupMap* groupMap;
-       string filename, format, method;
+       string distFileName, format, method;
        string phylipfile, columnfile, namefile, groupfile;
        NameAssignment* nameMap;
-       OptionParser* parser;
-       map<string, string> parameters;
-       map<string, string>::iterator it;
+
        bool abort;
 
 };
index 1f1ad971738596854650363ef01672aa19e0748b..7c3e1995ecf9315839b5f26ab9f7768d59e6ca08 100644 (file)
@@ -24,40 +24,40 @@ ReadOtuCommand::ReadOtuCommand(string option){
                        string Array[] =  {"list","order","shared", "line", "label","group","sabund", "rabund"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);  delete parser;
+                       OptionParser parser(option);
+                       map<string, string> parameters = parser.getParameters();
                        
-                       ValidParameters* validParameter = new ValidParameters();
+                       ValidParameters validParameter;
                
                        //check to make sure all parameters are valid for command
-                       for (it = parameters.begin(); it != parameters.end(); it++) { 
-                               if (validParameter->isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        globaldata->newRead();
                        
                        //check for required parameters
-                       listfile = validParameter->validFile(parameters, "list", true);
+                       listfile = validParameter.validFile(parameters, "list", true);
                        if (listfile == "not open") { abort = true; }
                        else if (listfile == "not found") { listfile = ""; }    
                        else {  globaldata->setListFile(listfile);  globaldata->setFormat("list");      }
                        
-                       sabundfile = validParameter->validFile(parameters, "sabund", true);
+                       sabundfile = validParameter.validFile(parameters, "sabund", true);
                        if (sabundfile == "not open") { abort = true; } 
                        else if (sabundfile == "not found") { sabundfile = ""; }
                        else {  globaldata->setSabundFile(sabundfile); globaldata->setFormat("sabund"); }
 
-                       rabundfile = validParameter->validFile(parameters, "rabund", true);
+                       rabundfile = validParameter.validFile(parameters, "rabund", true);
                        if (rabundfile == "not open") { abort = true; } 
                        else if (rabundfile == "not found") { rabundfile = ""; }
                        else {  globaldata->setRabundFile(rabundfile);  globaldata->setFormat("rabund");}
                        
-                       sharedfile = validParameter->validFile(parameters, "shared", true);
+                       sharedfile = validParameter.validFile(parameters, "shared", true);
                        if (sharedfile == "not open") { abort = true; } 
                        else if (sharedfile == "not found") { sharedfile = ""; }
                        else {  globaldata->setSharedFile(sharedfile); globaldata->setFormat("sharedfile");     }
                        
-                       groupfile = validParameter->validFile(parameters, "group", true);
+                       groupfile = validParameter.validFile(parameters, "group", true);
                        if (groupfile == "not open") { abort = true; }  
                        else if (groupfile == "not found") { groupfile = ""; }
                        else {  
@@ -76,7 +76,7 @@ ReadOtuCommand::ReadOtuCommand(string option){
                
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
-                       line = validParameter->validFile(parameters, "line", false);                            
+                       line = validParameter.validFile(parameters, "line", false);                             
                        if (line == "not found") { line = ""; }
                        else { 
                                if(line != "all") {  splitAtDash(line, lines);  allLines = 0;  }
@@ -84,7 +84,7 @@ ReadOtuCommand::ReadOtuCommand(string option){
                                globaldata->lines = lines;
                        }
                        
-                       label = validParameter->validFile(parameters, "label", false);                  
+                       label = validParameter.validFile(parameters, "label", false);                   
                        if (label == "not found") { label = ""; }
                        else { 
                                if(label != "all") {  splitAtDash(label, labels);  allLines = 0;  }
@@ -97,12 +97,11 @@ ReadOtuCommand::ReadOtuCommand(string option){
                        //make sure user did not use both the line and label parameters
                        if ((line != "") && (label != "")) { cout << "You cannot use both the line and label parameters at the same time. " << endl; abort = true; }
                        
-                       orderfile = validParameter->validFile(parameters, "order", true);
+                       orderfile = validParameter.validFile(parameters, "order", true);
                        if (orderfile == "not open") { abort = true; }  
                        else if (orderfile == "not found") { orderfile = ""; }
                        else {  globaldata->setOrderFile(orderfile);    }
                        
-                       delete validParameter;
                        
                        if (abort == false) {
                                //gets whichever one of the above is set
index 586e6ef36e5ca3ab015db96b493c191612a9330a..c38d0a5f3d38916681db8b254fe11b5c9eec03f2 100644 (file)
@@ -46,9 +46,7 @@ private:
        Command* parselist;
        GroupMap* groupMap;
        string filename, listfile, orderfile, sharedfile, line, label, groupfile, sabundfile, rabundfile, format;
-       OptionParser* parser;
-       map<string, string> parameters;
-       map<string, string>::iterator it;
+
        bool abort, allLines;
        set<int> lines; //hold lines to be used
        set<string> labels; //holds labels to be used
index 6e5742ddbbc35cdc6d01b9d57b3d58a8c7856816..b030542ef8f7e5933f2bf32c4c6bf6ba9e051ee0 100644 (file)
@@ -23,25 +23,25 @@ ReadTreeCommand::ReadTreeCommand(string option){
                        string Array[] =  {"tree","group"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);  delete parser;
+                       OptionParser parser(option);
+                       map<string, string> parameters = parser.getParameters();
                        
-                       ValidParameters* validParameter = new ValidParameters();
+                       ValidParameters validParameter;
                
                        //check to make sure all parameters are valid for command
-                       for (it = parameters.begin(); it != parameters.end(); it++) { 
-                               if (validParameter->isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        globaldata->newRead();
                        
                        //check for required parameters
-                       treefile = validParameter->validFile(parameters, "tree", true);
+                       treefile = validParameter.validFile(parameters, "tree", true);
                        if (treefile == "not open") { abort = true; }
                        else if (treefile == "not found") { treefile = ""; cout << "tree is a required parameter for the read.tree command." << endl; abort = true;  }  
-                       else {  globaldata->setTreeFile(treefile);  globaldata->setFormat("tree");      }
+//                     else {  globaldata->setTreeFile(treefile);  globaldata->setFormat("tree");      }
                        
-                       groupfile = validParameter->validFile(parameters, "group", true);
+                       groupfile = validParameter.validFile(parameters, "group", true);
                        if (groupfile == "not open") { abort = true; }  
                        else if (groupfile == "not found") { groupfile = ""; cout << "group is a required parameter for the read.tree command." << endl; abort = true;  }
                        else {  
@@ -57,7 +57,6 @@ ReadTreeCommand::ReadTreeCommand(string option){
                                read = new ReadNewickTree(filename);
                        }
                                                
-                       delete validParameter;
                }
        }
        catch(exception& e) {
index ca9f3b8c581d7b72f277332a1b70936d9f095854..99ddc380bd8d1dd4a2ac1a7eaa3e3bb5fd17e787 100644 (file)
@@ -28,9 +28,6 @@ private:
        ReadTree* read;
        TreeMap* treeMap;
        string filename, treefile, groupfile;
-       OptionParser* parser;
-       map<string, string> parameters;
-       map<string, string>::iterator it;
        bool abort;
 
 };
index b8ccc0747d54300f4fbc655729d9ce58b6f2d112..9e2a08b2a493fec7ed717505d7d02112a8530b49 100644 (file)
@@ -15,7 +15,6 @@
 
 ReverseSeqsCommand::ReverseSeqsCommand(string option){
        try {
-               globaldata = GlobalData::getInstance();
                abort = false;
                
                //allow user to run help
@@ -26,23 +25,21 @@ ReverseSeqsCommand::ReverseSeqsCommand(string option){
                        string Array[] =  {"fasta"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);  delete parser;
+                       OptionParser parser(option);
+                       map<string,string> parameters = parser.getParameters();
                        
-                       ValidParameters* validParameter = new ValidParameters();
+                       ValidParameters validParameter;
                
                        //check to make sure all parameters are valid for command
-                       for (it = parameters.begin(); it != parameters.end(); it++) { 
-                               if (validParameter->isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        //check for required parameters
-                       fasta = validParameter->validFile(parameters, "fasta", true);
+                       fasta = validParameter.validFile(parameters, "fasta", true);
                        if (fasta == "not open") { abort = true; }
                        else if (fasta == "not found") { fasta = ""; cout << "fasta is a required parameter for the reverse.seqs command." << endl; abort = true;  }    
-                       else {  globaldata->setFastaFile(fasta);  globaldata->setFormat("fasta");       }
                        
-                       delete validParameter;
                }
        }
        catch(exception& e) {
index 2a996e9fe02d6e05511ea543ef0d9dd4e507fbdb..b47ee3a51d614c84f746a1f231894809059bcad3 100644 (file)
@@ -12,7 +12,6 @@
 
 #include "mothur.h"
 #include "command.hpp"
-#include "globaldata.hpp"
 
 class ReverseSeqsCommand : public Command {
 public:
@@ -22,13 +21,9 @@ public:
        void help();
        
 private:
-       GlobalData* globaldata; 
-       OptionParser* parser;
-       map<string, string> parameters;
-       map<string, string>::iterator it;
+
        bool abort;
        string fasta;
-
        
 };
 
index 31b6bb7137579796c3a6652b283858bff435731a..5789fd0665f849822ec8d8c365de3a26e65b77ef 100644 (file)
@@ -14,7 +14,6 @@
 
 ScreenSeqsCommand::ScreenSeqsCommand(string option){
        try {
-               globaldata = GlobalData::getInstance();
                abort = false;
                
                //allow user to run help
@@ -25,59 +24,50 @@ ScreenSeqsCommand::ScreenSeqsCommand(string option){
                        string AlignArray[] =  {"fasta", "start", "end", "maxambig", "maxhomop", "minlength", "maxlength", "name", "group"};
                        vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);      delete parser; 
+                       OptionParser parser(option);
+                       map<string,string> parameters = parser.getParameters();
+                       
+                       ValidParameters validParameter;
                        
-                       ValidParameters* validParameter = new ValidParameters();
-               
                        //check to make sure all parameters are valid for command
-                       for (it = parameters.begin(); it != parameters.end(); it++) { 
-                               if (validParameter->isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        //check for required parameters
-                       fastafile = validParameter->validFile(parameters, "fasta", true);
+                       fastafile = validParameter.validFile(parameters, "fasta", true);
                        if (fastafile == "not found") { cout << "fasta is a required parameter for the screen.seqs command." << endl; abort = true; }
                        else if (fastafile == "not open") { abort = true; }     
-                       else { globaldata->setFastaFile(fastafile); }
                
-                       groupfile = validParameter->validFile(parameters, "group", true);
+                       groupfile = validParameter.validFile(parameters, "group", true);
                        if (groupfile == "not open") { abort = true; }  
                        else if (groupfile == "not found") { groupfile = ""; }
-                       else { 
-                               globaldata->setGroupFile(groupfile);
-                       }
                        
-                       namefile = validParameter->validFile(parameters, "name", true);
+                       namefile = validParameter.validFile(parameters, "name", true);
                        if (namefile == "not open") { abort = true; }
                        else if (namefile == "not found") { namefile = ""; }    
-                       else { 
-                               globaldata->setNameFile(namefile);
-                       }
 
                
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
                        string temp;
-                       temp = validParameter->validFile(parameters, "start", false);                   if (temp == "not found") { temp = "-1"; }
+                       temp = validParameter.validFile(parameters, "start", false);                    if (temp == "not found") { temp = "-1"; }
                        convert(temp, startPos); 
                
-                       temp = validParameter->validFile(parameters, "end", false);                             if (temp == "not found") { temp = "-1"; }
+                       temp = validParameter.validFile(parameters, "end", false);                              if (temp == "not found") { temp = "-1"; }
                        convert(temp, endPos);  
 
-                       temp = validParameter->validFile(parameters, "maxambig", false);                if (temp == "not found") { temp = "-1"; }
+                       temp = validParameter.validFile(parameters, "maxambig", false);         if (temp == "not found") { temp = "-1"; }
                        convert(temp, maxAmbig);  
 
-                       temp = validParameter->validFile(parameters, "maxhomop", false);                if (temp == "not found") { temp = "-1"; }
+                       temp = validParameter.validFile(parameters, "maxhomop", false);         if (temp == "not found") { temp = "-1"; }
                        convert(temp, maxHomoP);  
 
-                       temp = validParameter->validFile(parameters, "minlength", false);               if (temp == "not found") { temp = "-1"; }
+                       temp = validParameter.validFile(parameters, "minlength", false);                if (temp == "not found") { temp = "-1"; }
                        convert(temp, minLength); 
                        
-                       temp = validParameter->validFile(parameters, "maxlength", false);               if (temp == "not found") { temp = "-1"; }
+                       temp = validParameter.validFile(parameters, "maxlength", false);                if (temp == "not found") { temp = "-1"; }
                        convert(temp, maxLength); 
-               
-                       delete validParameter;
                }
 
        }
@@ -187,13 +177,13 @@ int ScreenSeqsCommand::execute(){
 void ScreenSeqsCommand::screenNameGroupFile(set<string> badSeqNames){
 
        ifstream inputNames;
-       openInputFile(globaldata->getNameFile(), inputNames);
+       openInputFile(namefile, inputNames);
        set<string> badSeqGroups;
        string seqName, seqList, group;
        set<string>::iterator it;
 
-       string goodNameFile = getRootName(globaldata->getNameFile()) + "good" + getExtension(globaldata->getNameFile());
-       string badNameFile = getRootName(globaldata->getNameFile()) + "bad" + getExtension(globaldata->getNameFile());
+       string goodNameFile = getRootName(namefile) + "good" + getExtension(namefile);
+       string badNameFile = getRootName(namefile) + "bad" + getExtension(namefile);
        
        ofstream goodNameOut;   openOutputFile(goodNameFile, goodNameOut);
        ofstream badNameOut;    openOutputFile(badNameFile, badNameOut);                
@@ -205,7 +195,7 @@ void ScreenSeqsCommand::screenNameGroupFile(set<string> badSeqNames){
                if(it != badSeqNames.end()){
                        badSeqNames.erase(it);
                        badNameOut << seqName << '\t' << seqList << endl;
-                       if(globaldata->getNameFile() != ""){
+                       if(namefile != ""){
                                int start = 0;
                                for(int i=0;i<seqList.length();i++){
                                        if(seqList[i] == ','){
@@ -225,13 +215,13 @@ void ScreenSeqsCommand::screenNameGroupFile(set<string> badSeqNames){
        goodNameOut.close();
        badNameOut.close();
        
-       if(globaldata->getGroupFile() != ""){
+       if(groupfile != ""){
                
                ifstream inputGroups;
-               openInputFile(globaldata->getGroupFile(), inputGroups);
+               openInputFile(groupfile, inputGroups);
 
-               string goodGroupFile = getRootName(globaldata->getGroupFile()) + "good" + getExtension(globaldata->getGroupFile());
-               string badGroupFile = getRootName(globaldata->getGroupFile()) + "bad" + getExtension(globaldata->getGroupFile());
+               string goodGroupFile = getRootName(groupfile) + "good" + getExtension(groupfile);
+               string badGroupFile = getRootName(groupfile) + "bad" + getExtension(groupfile);
                
                ofstream goodGroupOut;  openOutputFile(goodGroupFile, goodGroupOut);
                ofstream badGroupOut;   openOutputFile(badGroupFile, badGroupOut);              
@@ -261,12 +251,12 @@ void ScreenSeqsCommand::screenNameGroupFile(set<string> badSeqNames){
 void ScreenSeqsCommand::screenGroupFile(set<string> badSeqNames){
 
        ifstream inputGroups;
-       openInputFile(globaldata->getGroupFile(), inputGroups);
+       openInputFile(groupfile, inputGroups);
        string seqName, group;
        set<string>::iterator it;
        
-       string goodGroupFile = getRootName(globaldata->getGroupFile()) + "good" + getExtension(globaldata->getGroupFile());
-       string badGroupFile = getRootName(globaldata->getGroupFile()) + "bad" + getExtension(globaldata->getGroupFile());
+       string goodGroupFile = getRootName(groupfile) + "good" + getExtension(groupfile);
+       string badGroupFile = getRootName(groupfile) + "bad" + getExtension(groupfile);
        
        ofstream goodGroupOut;  openOutputFile(goodGroupFile, goodGroupOut);
        ofstream badGroupOut;   openOutputFile(badGroupFile, badGroupOut);              
index 97b36155af670c3d038c882e742356a1c6ee9a03..eab66ee23d5c0d07a6498b67ab130fb8a7622f4d 100644 (file)
@@ -11,7 +11,6 @@
  */
 #include "mothur.h"
 #include "command.hpp"
-#include "globaldata.hpp"
 
 class ScreenSeqsCommand : public Command {
        
@@ -25,10 +24,6 @@ private:
        void screenNameGroupFile(set<string>);
        void screenGroupFile(set<string>);
 
-       GlobalData* globaldata; 
-       OptionParser* parser;
-       map<string, string> parameters;
-       map<string, string>::iterator it;
        bool abort;
        string fastafile, namefile, groupfile;
        int startPos, endPos, maxAmbig, maxHomoP, minLength, maxLength;
index c8582b9ae35ed3edce04052f85f53f611235ab88..24ef1d12e08262a335f7c29104120f7cddc81e1b 100644 (file)
@@ -14,7 +14,6 @@
 
 SeqSummaryCommand::SeqSummaryCommand(string option){
        try {
-               globaldata = GlobalData::getInstance();
                abort = false;
                
                //allow user to run help
@@ -25,23 +24,21 @@ SeqSummaryCommand::SeqSummaryCommand(string option){
                        string Array[] =  {"fasta"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);  delete parser;
+                       OptionParser parser(option);
+                       map<string,string> parameters = parser.getParameters();
+                       
+                       ValidParameters validParameter;
                        
-                       ValidParameters* validParameter = new ValidParameters();
-               
                        //check to make sure all parameters are valid for command
-                       for (it = parameters.begin(); it != parameters.end(); it++) { 
-                               if (validParameter->isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        //check for required parameters
-                       fastafile = validParameter->validFile(parameters, "fasta", true);
+                       fastafile = validParameter.validFile(parameters, "fasta", true);
                        if (fastafile == "not open") { abort = true; }
                        else if (fastafile == "not found") { fastafile = ""; cout << "fasta is a required parameter for the summary.seqs command." << endl; abort = true;  }    
-                       else {  globaldata->setFastaFile(fastafile);  globaldata->setFormat("fasta");   }
                        
-                       delete validParameter;
                }
        }
        catch(exception& e) {
index 03ec3e0c101cb2a83f3d38bfd21ce75d044f3fc4..6d48284baeffe974a2c13ddbb16dfaf95704df90 100644 (file)
@@ -12,9 +12,6 @@
 
 #include "mothur.h"
 #include "command.hpp"
-#include "globaldata.hpp"
-
-
 
 class SeqSummaryCommand : public Command {
 public:
@@ -24,14 +21,9 @@ public:
        void help();
        
 private:
-       GlobalData* globaldata; 
-       OptionParser* parser;
-       map<string, string> parameters;
-       map<string, string>::iterator it;
        bool abort;
        string fastafile;
 
-
 };
 
 #endif
index 6a15eb5f7d23f93272811a975beedc649a0d9ce9..580f68ae7706ed15a11f9f460e29a56bd441767b 100644 (file)
@@ -34,10 +34,9 @@ Sequence::Sequence(ifstream& fastaFile){
        initialize();
        fastaFile >> name;
        name = name.substr(1);
-       char c;
-       
-       while ((c = fastaFile.get()) != EOF)    {       if (c == 10){   break;  }       } // get rest of line if there's any crap there
        
+       while (!fastaFile.eof())        {       char c = fastaFile.get(); if (c == 10 || c == 13){      break;  }       } // get rest of line if there's any crap there
+
        char letter;
        string sequence;
        
index e0bd10033459896f10c2d42fb9b3b4f6921add7f..bc8523aa78b5d217fd5cfd12c8bade6bbb630721 100644 (file)
@@ -23,7 +23,7 @@ SequenceDB::~SequenceDB() { clear(); }
 /***********************************************************************/
 
 SequenceDB::SequenceDB(int newSize) {
-       data.resize(newSize, NULL);
+       data.resize(newSize, Sequence());
 }
 
 /***********************************************************************/
@@ -46,7 +46,7 @@ SequenceDB::SequenceDB(ifstream& filehandle) {
                        }else {  cout << "Error fasta in your file. Please correct." << endl; }
 
                        //input sequence info into sequencedb
-                       Sequence* newSequence = new Sequence(name, sequence);
+                       Sequence newSequence(name, sequence);
                        data.push_back(newSequence);
                        
                        //takes care of white space
@@ -134,10 +134,7 @@ int SequenceDB::getNumSeqs() {
 
 void SequenceDB::set(int index, string newUnaligned) {
        try {
-               if (data[index] != NULL) {  delete data[index];  } //free memory
-       
-               Sequence* newSeq = new Sequence(data[index]->getName(), newUnaligned);
-               data[index] = newSeq;
+               data[index] = Sequence(data[index].getName(), newUnaligned);
        }
        catch(exception& e) {
                cout << "Standard Error: " << e.what() << " has occurred in the SequenceDB class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
@@ -151,9 +148,8 @@ void SequenceDB::set(int index, string newUnaligned) {
 
 /***********************************************************************/
 
-void SequenceDB::set(int index, Sequence* newSeq) {
+void SequenceDB::set(int index, Sequence newSeq) {
        try {
-               if (data[index] != NULL) {  delete data[index];  } //free memory
                data[index] = newSeq;
        }
        catch(exception& e) {
@@ -168,7 +164,7 @@ void SequenceDB::set(int index, Sequence* newSeq) {
 
 /***********************************************************************/
 
-Sequence* SequenceDB::get(int index) {
+Sequence SequenceDB::get(int index) {
        return data[index];
 }
 
@@ -176,9 +172,6 @@ Sequence* SequenceDB::get(int index) {
 
 void SequenceDB::resize(int newSize) {
        try {
-               int size = data.size();
-       
-               for (int i = size; i > newSize; i--) {  delete data[i]; }
                data.resize(newSize);
        }
        catch(exception& e) {
@@ -195,7 +188,6 @@ void SequenceDB::resize(int newSize) {
 
 void SequenceDB::clear() {
        try {
-               for (int i = 0; i < data.size(); i++) { delete data[i];  }
                data.clear();
        }
        catch(exception& e) {
@@ -219,7 +211,7 @@ int SequenceDB::size() {
 void SequenceDB::print(ostream& out) {
        try {
                for(int i = 0; i < data.size(); i++) {
-                       data[i]->printSequence(out);
+                       data[i].printSequence(out);
                }
        }
        catch(exception& e) {
@@ -234,7 +226,7 @@ void SequenceDB::print(ostream& out) {
        
 /***********************************************************************/
 
-void SequenceDB::push_back(Sequence* newSequence) {
+void SequenceDB::push_back(Sequence newSequence) {
        try {
                data.push_back(newSequence);
        }
index 88b31e2e5d7adc050c58e3d18cb7ffca7652370b..8c7e649b893339daac20eb8cd1fb9dd0f1833544 100644 (file)
@@ -30,16 +30,16 @@ public:
        int getNumSeqs();
        
        void set(int, string);     //unaligned - should also set length
-       void set(int, Sequence*);   //unaligned - should also set length
-       Sequence* get(int);         //returns sequence name at that location
-       void push_back(Sequence*);        //adds unaligned sequence
+       void set(int, Sequence);   //unaligned - should also set length
+       Sequence get(int);         //returns sequence name at that location
+       void push_back(Sequence);        //adds unaligned sequence
        void resize(int);      //resizes data
        void clear();              //clears data - remeber to loop through and delete the sequences inside or you will have a memory leak
        int size();                //returns datas size
        void print(ostream&);      //loops through data using sequence class print
                
 private:
-       vector<Sequence*> data;
+       vector<Sequence> data;
        string readName(ifstream&);
        string readSequence(ifstream&);
 
index 612a253dfd56ec074ab7bc305c1bf45f5b47e3c5..152a138c279a101038566ced46339d970caef9bd 100644 (file)
--- a/shen.cpp
+++ b/shen.cpp
@@ -15,7 +15,6 @@
 EstOutput Shen::getValues(SAbundVector* rank){
 
        try {
-               globaldata = GlobalData::getInstance();
                
                data.resize(1,0);
                
diff --git a/shen.h b/shen.h
index 59d6c3abe6893685a000562183c8d8052a8fa467..fa8b70030e1e9ae742f86cc4f77e00d3870dedac 100644 (file)
--- a/shen.h
+++ b/shen.h
@@ -11,7 +11,6 @@
  */
 
 #include "calculator.h"
-#include "globaldata.hpp"
 
 /* This class implements the shen calculator on single group. 
  It is a child of the calculator class. */
@@ -27,7 +26,6 @@ public:
 private:
        int m;
        int abund;
-       GlobalData* globaldata;
 };
 
 
index 009c278cd618d03c08f06bbd2f9c240e9390dac4..fa6d11ade6a27c69655e4b383b37f27f4a87f3bc 100644 (file)
@@ -48,14 +48,14 @@ SummaryCommand::SummaryCommand(string option){
                        string Array[] =  {"line","label","calc","abund","size"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);  delete parser;
+                       OptionParser parser(option);
+                       map<string,string> parameters = parser.getParameters();
+                       
+                       ValidParameters validParameter;
                        
-                       ValidParameters* validParameter = new ValidParameters();
-               
                        //check to make sure all parameters are valid for command
-                       for (it = parameters.begin(); it != parameters.end(); it++) { 
-                               if (validParameter->isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        //make sure the user has already run the read.otu command
@@ -63,14 +63,14 @@ SummaryCommand::SummaryCommand(string option){
                        
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
-                       line = validParameter->validFile(parameters, "line", false);                            
+                       line = validParameter.validFile(parameters, "line", false);                             
                        if (line == "not found") { line = "";  }
                        else { 
                                if(line != "all") {  splitAtDash(line, lines);  allLines = 0;  }
                                else { allLines = 1;  }
                        }
                        
-                       label = validParameter->validFile(parameters, "label", false);                  
+                       label = validParameter.validFile(parameters, "label", false);                   
                        if (label == "not found") { label = ""; }
                        else { 
                                if(label != "all") {  splitAtDash(label, labels);  allLines = 0;  }
@@ -86,7 +86,7 @@ SummaryCommand::SummaryCommand(string option){
                                lines = globaldata->lines;
                        }
                                
-                       calc = validParameter->validFile(parameters, "calc", false);                    
+                       calc = validParameter.validFile(parameters, "calc", false);                     
                        if (calc == "not found") { calc = "sobs-chao-ace-jack-shannon-npshannon-simpson";  }
                        else { 
                                 if (calc == "default")  {  calc = "sobs-chao-ace-jack-shannon-npshannon-simpson";  }
@@ -94,14 +94,12 @@ SummaryCommand::SummaryCommand(string option){
                        splitAtDash(calc, Estimators);
 
                        string temp;
-                       temp = validParameter->validFile(parameters, "abund", false);           if (temp == "not found") { temp = "10"; }
+                       temp = validParameter.validFile(parameters, "abund", false);            if (temp == "not found") { temp = "10"; }
                        convert(temp, abund); 
                        
-                       temp = validParameter->validFile(parameters, "size", false);                    if (temp == "not found") { temp = "0"; }
+                       temp = validParameter.validFile(parameters, "size", false);                     if (temp == "not found") { temp = "0"; }
                        convert(temp, size); 
        
-                       delete validParameter;
-                       
                        if (abort == false) {
                        
                                validCalculator = new ValidCalculators();
index 895f9d7429deac952eab6a0bd29ee9fb07dd95a3..b12f76f4e9812b7d26de87769d746167fe3552c1 100644 (file)
@@ -48,9 +48,7 @@ private:
        string outputFileName;
        ofstream outputFileHandle;
        int abund, size;
-       OptionParser* parser;
-       map<string, string> parameters;
-       map<string, string>::iterator it;
+
        bool abort, allLines;
        set<int> lines; //hold lines to be used
        set<string> labels; //holds labels to be used
index 363506c406490e999a2700974e538489616b8d5a..a32b202d827d8df18c5696c3fc9ace85f3ddbf22 100644 (file)
@@ -52,14 +52,14 @@ SummarySharedCommand::SummarySharedCommand(string option){
                        string Array[] =  {"line","label","calc","groups"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);  delete parser;
+                       OptionParser parser(option);
+                       map<string, string> parameters = parser.getParameters();
                        
-                       ValidParameters* validParameter = new ValidParameters();
+                       ValidParameters validParameter;
                
                        //check to make sure all parameters are valid for command
-                       for (it = parameters.begin(); it != parameters.end(); it++) { 
-                               if (validParameter->isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        //make sure the user has already run the read.otu command
@@ -71,14 +71,14 @@ SummarySharedCommand::SummarySharedCommand(string option){
                        
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
-                       line = validParameter->validFile(parameters, "line", false);                            
+                       line = validParameter.validFile(parameters, "line", false);                             
                        if (line == "not found") { line = "";  }
                        else { 
                                if(line != "all") {  splitAtDash(line, lines);  allLines = 0;  }
                                else { allLines = 1;  }
                        }
                        
-                       label = validParameter->validFile(parameters, "label", false);                  
+                       label = validParameter.validFile(parameters, "label", false);                   
                        if (label == "not found") { label = ""; }
                        else { 
                                if(label != "all") {  splitAtDash(label, labels);  allLines = 0;  }
@@ -94,22 +94,20 @@ SummarySharedCommand::SummarySharedCommand(string option){
                                lines = globaldata->lines;
                        }
                                
-                       calc = validParameter->validFile(parameters, "calc", false);                    
+                       calc = validParameter.validFile(parameters, "calc", false);                     
                        if (calc == "not found") { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan";  }
                        else { 
                                 if (calc == "default")  {  calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan";  }
                        }
                        splitAtDash(calc, Estimators);
                        
-                       groups = validParameter->validFile(parameters, "groups", false);                        
+                       groups = validParameter.validFile(parameters, "groups", false);                 
                        if (groups == "not found") { groups = ""; }
                        else { 
                                splitAtDash(groups, Groups);
                                globaldata->Groups = Groups;
                        }
                        
-                       delete validParameter;
-                       
                        if (abort == false) {
                        
                                validCalculator = new ValidCalculators();
@@ -165,7 +163,7 @@ SummarySharedCommand::SummarySharedCommand(string option){
                                
                                outputFileName = ((getRootName(globaldata->inputFileName)) + "shared.summary");
                                openOutputFile(outputFileName, outputFileHandle);
-                               format = globaldata->getFormat();
+//                             format = globaldata->getFormat();
                                mult = false;
                        }
                }
diff --git a/tree.h b/tree.h
index b6d5ea807a38801a872daf96b23557d53a241f4e..a5259552d8fa09f18d1e81b1776ef94f84724748 100644 (file)
--- a/tree.h
+++ b/tree.h
@@ -13,6 +13,7 @@
 #include "treenode.h"
 #include "globaldata.hpp"
 
+class GlobalData;
 /* This class represents the treefile. */
 
 class Tree {
index 7c78a348902e1145af1cd4395fd0e839bf3cb564..484b5536ec668fbf60b94cba6ae5244570d2f111 100644 (file)
@@ -40,33 +40,33 @@ TreeGroupCommand::TreeGroupCommand(string option){
                        string Array[] =  {"line","label","calc","groups", "phylip", "column", "name", "precision","cutoff"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);  delete parser;
+                       OptionParser parser(option);
+                       map<string, string> parameters = parser. getParameters();
                        
-                       ValidParameters* validParameter = new ValidParameters();
+                       ValidParameters validParameter;
                
                        //check to make sure all parameters are valid for command
-                       for (it = parameters.begin(); it != parameters.end(); it++) { 
-                               if (validParameter->isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        //required parameters
-                       phylipfile = validParameter->validFile(parameters, "phylip", true);
+                       phylipfile = validParameter.validFile(parameters, "phylip", true);
                        if (phylipfile == "not open") { abort = true; }
                        else if (phylipfile == "not found") { phylipfile = ""; }        
-                       else {  globaldata->setPhylipFile(phylipfile);  globaldata->setFormat("phylip");        }
+                       else {  format = "phylip";      }
                        
-                       columnfile = validParameter->validFile(parameters, "column", true);
+                       columnfile = validParameter.validFile(parameters, "column", true);
                        if (columnfile == "not open") { abort = true; } 
                        else if (columnfile == "not found") { columnfile = ""; }
-                       else {  globaldata->setColumnFile(columnfile); globaldata->setFormat("column"); }
+                       else {  format = "column";      }
                        
-                       namefile = validParameter->validFile(parameters, "name", true);
+                       namefile = validParameter.validFile(parameters, "name", true);
                        if (namefile == "not open") { abort = true; }   
                        else if (namefile == "not found") { namefile = ""; }
                        else {  globaldata->setNameFile(namefile);      }
                        
-                       format = globaldata->getFormat();
+//                     format = globaldata->getFormat();
                        
                        //error checking on files                       
                        if ((globaldata->getSharedFile() == "") && ((phylipfile == "") && (columnfile == "")))  { cout << "You must run the read.otu command or provide a distance file before running the tree.shared command." << endl; abort = true; }
@@ -78,14 +78,14 @@ TreeGroupCommand::TreeGroupCommand(string option){
 
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
-                       line = validParameter->validFile(parameters, "line", false);                            
+                       line = validParameter.validFile(parameters, "line", false);                             
                        if (line == "not found") { line = "";  }
                        else { 
                                if(line != "all") {  splitAtDash(line, lines);  allLines = 0;  }
                                else { allLines = 1;  }
                        }
                        
-                       label = validParameter->validFile(parameters, "label", false);                  
+                       label = validParameter.validFile(parameters, "label", false);                   
                        if (label == "not found") { label = ""; }
                        else { 
                                if(label != "all") {  splitAtDash(label, labels);  allLines = 0;  }
@@ -101,14 +101,14 @@ TreeGroupCommand::TreeGroupCommand(string option){
                                lines = globaldata->lines;
                        }
                                
-                       groups = validParameter->validFile(parameters, "groups", false);                        
+                       groups = validParameter.validFile(parameters, "groups", false);                 
                        if (groups == "not found") { groups = ""; }
                        else { 
                                splitAtDash(groups, Groups);
                                globaldata->Groups = Groups;
                        }
                                
-                       calc = validParameter->validFile(parameters, "calc", false);                    
+                       calc = validParameter.validFile(parameters, "calc", false);                     
                        if (calc == "not found") { calc = "jclass-thetayc";  }
                        else { 
                                 if (calc == "default")  {  calc = "jclass-thetayc";  }
@@ -116,16 +116,14 @@ TreeGroupCommand::TreeGroupCommand(string option){
                        splitAtDash(calc, Estimators);
 
                        string temp;
-                       temp = validParameter->validFile(parameters, "precision", false);                       if (temp == "not found") { temp = "100"; }
+                       temp = validParameter.validFile(parameters, "precision", false);                        if (temp == "not found") { temp = "100"; }
                        convert(temp, precision); 
                        
-                       temp = validParameter->validFile(parameters, "cutoff", false);                  if (temp == "not found") { temp = "10"; }
+                       temp = validParameter.validFile(parameters, "cutoff", false);                   if (temp == "not found") { temp = "10"; }
                        convert(temp, cutoff); 
                        cutoff += (5 / (precision * 10.0));
 
-       
-                       delete validParameter;
-                       
+                               
                        if (abort == false) {
                        
                                validCalculator = new ValidCalculators();
index 76124f5f7ff3cb2d312eac3091ec1d7b2c727d03..1e1f28480082903227d77b4b92666c0bec021fc3 100644 (file)
@@ -64,9 +64,7 @@ private:
        int numGroups;
        ofstream out;
        float precision, cutoff;
-       OptionParser* parser;
-       map<string, string> parameters;
-       map<string, string>::iterator it;
+
        bool abort, allLines;
        set<int> lines; //hold lines to be used
        set<string> labels; //holds labels to be used
index 77da3a60f7534dca70f65d73c262c27bf9734648..132cc6b767956e2c5b522adb4facb9904fc30a78 100644 (file)
@@ -14,7 +14,6 @@
 TrimSeqsCommand::TrimSeqsCommand(string option){
        try {
                
-               globaldata = GlobalData::getInstance();
                abort = false;
                
                //allow user to run help
@@ -22,51 +21,73 @@ TrimSeqsCommand::TrimSeqsCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string AlignArray[] =  {"fasta", "flip", "oligos", "maxambig", "maxhomop", "minlength", "maxlength"};
+                       string AlignArray[] =  {"fasta", "flip", "oligos", "maxambig", "maxhomop", "minlength", "maxlength", "qfile", "qthreshold", "qaverage", "allfiles"};
+                       
                        vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);      delete parser; 
+                       OptionParser parser(option);
+                       map<string,string> parameters = parser.getParameters();
+                       
+                       ValidParameters validParameter;
                        
-                       ValidParameters* validParameter = new ValidParameters();
-               
                        //check to make sure all parameters are valid for command
-                       for (it = parameters.begin(); it != parameters.end(); it++) { 
-                               if (validParameter->isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        //check for required parameters
-                       fastafile = validParameter->validFile(parameters, "fasta", true);
-                       if (fastafile == "not found") { cout << "fasta is a required parameter for the screen.seqs command." << endl; abort = true; }
-                       else if (fastafile == "not open") { abort = true; }     
-                       else { globaldata->setFastaFile(fastafile); }
+                       fastaFile = validParameter.validFile(parameters, "fasta", true);
+                       if (fastaFile == "not found") { cout << "fasta is a required parameter for the screen.seqs command." << endl; abort = true; }
+                       else if (fastaFile == "not open") { abort = true; }     
                
                
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
                        string temp;
-                       temp = validParameter->validFile(parameters, "flip", false);                    if (temp == "not found") { temp = "0"; }
-                       if(isTrue(temp))        {       flip = 1;       }
+                       temp = validParameter.validFile(parameters, "flip", false);
+                       if (temp == "not found"){       flip = 0;       }
+                       else if(isTrue(temp))   {       flip = 1;       }
                
-                       temp = validParameter->validFile(parameters, "oligos", false);                  if (temp == "not found") { temp = ""; }
-                       if(temp != "")          {       oligos = 1;      } 
-                       else {  oligos = 0;      }
-
-                       temp = validParameter->validFile(parameters, "maxambig", false);                if (temp == "not found") { temp = "-1"; }
+                       temp = validParameter.validFile(parameters, "oligos", true);
+                       if (temp == "not found"){       oligoFile = "";         }
+                       else if(temp == "not open"){    abort = true;   } 
+                       else                                    {       oligoFile = temp;               }
+                       
+                       temp = validParameter.validFile(parameters, "maxambig", false);         if (temp == "not found") { temp = "-1"; }
                        convert(temp, maxAmbig);  
 
-                       temp = validParameter->validFile(parameters, "maxhomop", false);                if (temp == "not found") { temp = "0"; }
+                       temp = validParameter.validFile(parameters, "maxhomop", false);         if (temp == "not found") { temp = "0"; }
                        convert(temp, maxHomoP);  
 
-                       temp = validParameter->validFile(parameters, "minlength", false);               if (temp == "not found") { temp = "0"; }
+                       temp = validParameter.validFile(parameters, "minlength", false);        if (temp == "not found") { temp = "0"; }
                        convert(temp, minLength); 
                        
-                       temp = validParameter->validFile(parameters, "maxlength", false);               if (temp == "not found") { temp = "0"; }
-                       convert(temp, maxLength); 
+                       temp = validParameter.validFile(parameters, "maxlength", false);        if (temp == "not found") { temp = "0"; }
+                       convert(temp, maxLength);
+                       
+                       temp = validParameter.validFile(parameters, "qfile", true);     
+                       if (temp == "not found")        {       qFileName = "";         }
+                       else if(temp == "not open")     {       abort = 0;              }
+                       else                                            {       qFileName = temp;       }
                        
-                       if(!flip && !oligos && !maxLength && !minLength && (maxAmbig==-1) && !maxHomoP ){       cout << "huh?" << endl; }
+                       temp = validParameter.validFile(parameters, "qthreshold", false);       if (temp == "not found") { temp = "0"; }
+                       convert(temp, qThreshold);
+
+                       temp = validParameter.validFile(parameters, "qaverage", false);         if (temp == "not found") { temp = "0"; }
+                       convert(temp, qAverage);
+                       
+                       temp = validParameter.validFile(parameters, "allfiles", false);         if (temp == "not found") { temp = "F"; }
+                       allFiles = isTrue(temp);
+
+                       if(allFiles && oligoFile == ""){
+                               cout << "You selected allfiles, but didn't enter an oligos file.  Ignoring the allfiles request." << endl;
+                       }
+                       
+                       if(!flip && oligoFile=="" && !maxLength && !minLength && (maxAmbig==-1) && !maxHomoP && qFileName == ""){               
+                               cout << "You didn't set any options... quiting command." << endl;
+                               abort = true;
+                       }
                        
-                       delete validParameter;
                }
 
        }
@@ -83,7 +104,7 @@ TrimSeqsCommand::TrimSeqsCommand(string option){
 
 void TrimSeqsCommand::help(){
        try {
-               cout << "The trim.seqs command reads a fastafile and creates ....." << "\n";
+               cout << "The trim.seqs command reads a fastaFile and creates ....." << "\n";
                cout << "The trim.seqs command parameters are fasta, flip, oligos, maxambig, maxhomop, minlength and maxlength." << "\n";
                cout << "The fasta parameter is required." << "\n";
                cout << "The flip parameter .... The default is 0." << "\n";
@@ -121,31 +142,41 @@ int TrimSeqsCommand::execute(){
        
                if (abort == true) { return 0; }
        
-               getOligos();
-               
+               vector<ofstream*> groupFileNames;
+               vector<ofstream*> fastaFileNames;
+               if(oligoFile != "")     {       getOligos(fastaFileNames, groupFileNames);      }
+
                ifstream inFASTA;
-               openInputFile(fastafile, inFASTA);
+               openInputFile(fastaFile, inFASTA);
 
                ofstream outFASTA;
-               string trimSeqFile = getRootName(fastafile) + "trim.fasta";
+               string trimSeqFile = getRootName(fastaFile) + "trim.fasta";
                openOutputFile(trimSeqFile, outFASTA);
                
                ofstream outGroups;
-               string groupFile = getRootName(fastafile) + "groups"; 
+               string groupFile = getRootName(fastaFile) + "groups"; 
                openOutputFile(groupFile, outGroups);
-
+               
                ofstream scrapFASTA;
-               string scrapSeqFile = getRootName(fastafile) + "scrap.fasta";
+               string scrapSeqFile = getRootName(fastaFile) + "scrap.fasta";
                openOutputFile(scrapSeqFile, scrapFASTA);
-
+               
+               ifstream qFile;
+               if(qFileName != "")     {       openInputFile(qFileName, qFile);        }
+               
                bool success;
                
                while(!inFASTA.eof()){
                        Sequence currSeq(inFASTA);
                        string origSeq = currSeq.getUnaligned();
-                       string group;
+                       int group;
                        string trashCode = "";
-
+                       
+                       if(qFileName != ""){
+                               if(qThreshold != 0)             {       success = stripQualThreshold(currSeq, qFile);   }
+                               else if(qAverage != 0)  {       success = cullQualAverage(currSeq, qFile);              }
+                               if(!success)                    {       trashCode += 'q';                                                               }
+                       }
                        if(barcodes.size() != 0){
                                success = stripBarcode(currSeq, group);
                                if(!success){   trashCode += 'b';       }
@@ -172,17 +203,23 @@ int TrimSeqsCommand::execute(){
                        }
                        
                        if(flip){       currSeq.reverseComplement();    }               // should go last                       
-
+                       
                        if(trashCode.length() == 0){
                                currSeq.printSequence(outFASTA);
-                               outGroups << currSeq.getName() << '\t' << group << endl;
+                               if(barcodes.size() != 0){
+                                       outGroups << currSeq.getName() << '\t' << groupVector[group] << endl;
+                                       
+                                       if(allFiles){
+                                               *groupFileNames[group] << currSeq.getName() << '\t' << groupVector[group] << endl;                                      
+                                               currSeq.printSequence(*fastaFileNames[group]);                                  
+                                       }
+                               }
                        }
                        else{
                                currSeq.setName(currSeq.getName() + '|' + trashCode);
                                currSeq.setUnaligned(origSeq);
                                currSeq.printSequence(scrapFASTA);
                        }
-                       
                        gobble(inFASTA);
                }
                inFASTA.close();
@@ -190,6 +227,14 @@ int TrimSeqsCommand::execute(){
                scrapFASTA.close();
                outGroups.close();
                
+               for(int i=0;i<groupFileNames.size();i++){
+                       groupFileNames[i]->close();
+                       delete groupFileNames[i];
+
+                       fastaFileNames[i]->close();
+                       delete fastaFileNames[i];
+               }
+               
                return 0;               
        }
        catch(exception& e) {
@@ -204,56 +249,68 @@ int TrimSeqsCommand::execute(){
 
 //***************************************************************************************************************
 
-void TrimSeqsCommand::getOligos(){
-
+void TrimSeqsCommand::getOligos(vector<ofstream*>& outFASTAVec, vector<ofstream*>& outGroupsVec){
+       
        ifstream inOligos;
-       //openInputFile(globaldata->getOligosFile(), inOligos);
+       openInputFile(oligoFile, inOligos);
 
+       ofstream test;
+       
        string type, oligo, group;
+       int index=0;
        
        while(!inOligos.eof()){
                inOligos >> type;
                
-               if(type == "forward"){
-                       inOligos >> oligo;
-                       forPrimer.push_back(oligo);
+               if(type[0] == '#'){
+                       while (!inOligos.eof()) {       char c = inOligos.get(); if (c == 10 || c == 13){       break;  }       } // get rest of line if there's any crap there
                }
-               else if(type == "reverse"){
+               else{
                        inOligos >> oligo;
-                       revPrimer.push_back(oligo);
-               }
-               else if(type == "barcode"){
-                       inOligos >> oligo >> group;
-                       barcodes[oligo]=group;
-               }
-               else if(type[0] == '#'){
-                       char c;
-                       while ((c = inOligos.get()) != EOF)     {       if (c == 10){   break;  }       } // get rest of line
+                       
+                       for(int i=0;i<oligo.length();i++){
+                               oligo[i] = toupper(oligo[i]);
+                               if(oligo[i] == 'U')     {       oligo[i] = 'T'; }
+                       }
+                       
+                       if(type == "forward"){
+                               forPrimer.push_back(oligo);
+                       }
+                       else if(type == "reverse"){
+                               revPrimer.push_back(oligo);
+                       }
+                       else if(type == "barcode"){
+                               inOligos >> group;
+                               barcodes[oligo]=index++;
+                               groupVector.push_back(group);
+                                       
+                               if(allFiles){
+                                       outFASTAVec.push_back(new ofstream((getRootName(fastaFile) + group + ".fasta").c_str(), ios::ate));
+                                       outGroupsVec.push_back(new ofstream((getRootName(fastaFile) + group + ".groups").c_str(), ios::ate));
+                               }
+                       }
                }
-               
-               gobble(inOligos);
        }
-
+       
        numFPrimers = forPrimer.size();
        numRPrimers = revPrimer.size();
 }
 
 //***************************************************************************************************************
 
-bool TrimSeqsCommand::stripBarcode(Sequence& seq, string& group){
+bool TrimSeqsCommand::stripBarcode(Sequence& seq, int& group){
        
        string rawSequence = seq.getUnaligned();
        bool success = 0;       //guilty until proven innocent
-
-       for(map<string,string>::iterator it=barcodes.begin();it!=barcodes.end();it++){
+       
+       for(map<string,int>::iterator it=barcodes.begin();it!=barcodes.end();it++){
                string oligo = it->first;
-               
                if(rawSequence.length() < oligo.length()){      //let's just assume that the barcodes are the same length
                        success = 0;
                        break;
                }
                
-               if (rawSequence.compare(0,oligo.length(),oligo) == 0){
+               if(compareDNASeq(oligo, rawSequence.substr(0,oligo.length()))){
                        group = it->second;
                        seq.setUnaligned(rawSequence.substr(oligo.length()));
                        success = 1;
@@ -273,13 +330,13 @@ bool TrimSeqsCommand::stripForward(Sequence& seq){
        
        for(int i=0;i<numFPrimers;i++){
                string oligo = forPrimer[i];
-
+               
                if(rawSequence.length() < oligo.length()){
                        success = 0;
                        break;
                }
-               
-               if (rawSequence.compare(0,oligo.length(),oligo) == 0){
+
+               if(compareDNASeq(oligo, rawSequence.substr(0,oligo.length()))){
                        seq.setUnaligned(rawSequence.substr(oligo.length()));
                        success = 1;
                        break;
@@ -305,7 +362,7 @@ bool TrimSeqsCommand::stripReverse(Sequence& seq){
                        break;
                }
                
-               if(rawSequence.compare(rawSequence.length()-oligo.length(),oligo.length(),oligo) == 0){
+               if(compareDNASeq(oligo, rawSequence.substr(rawSequence.length()-oligo.length(),oligo.length()))){
                        seq.setUnaligned(rawSequence.substr(rawSequence.length()-oligo.length()));
                        success = 1;
                        break;
@@ -351,7 +408,7 @@ bool TrimSeqsCommand::cullAmbigs(Sequence& seq){
        int numNs = seq.getAmbigBases();
        bool success = 0;       //guilty until proven innocent
        
-       if(numNs <= maxAmbig){  success = 1;    }
+       if(numNs <= maxAmbig)   {       success = 1;    }
        else                                    {       success = 0;    }
        
        return success;
@@ -359,3 +416,98 @@ bool TrimSeqsCommand::cullAmbigs(Sequence& seq){
 }
 
 //***************************************************************************************************************
+
+bool TrimSeqsCommand::compareDNASeq(string oligo, string seq){
+       
+       bool success = 1;
+       int length = oligo.length();
+       
+       for(int i=0;i<length;i++){
+               
+               if(oligo[i] != seq[i]){
+                       if(oligo[i] == 'A' || oligo[i] == 'T' || oligo[i] == 'G' || oligo[i] == 'C')    {       success = 0;    }
+                       else if((oligo[i] == 'N' || oligo[i] == 'I') && (seq[i] == 'N'))                                {       success = 0;    }
+                       else if(oligo[i] == 'R' && (seq[i] != 'A' && seq[i] != 'G'))                                    {       success = 0;    }
+                       else if(oligo[i] == 'Y' && (seq[i] != 'C' && seq[i] != 'T'))                                    {       success = 0;    }
+                       else if(oligo[i] == 'M' && (seq[i] != 'C' && seq[i] != 'A'))                                    {       success = 0;    }
+                       else if(oligo[i] == 'K' && (seq[i] != 'T' && seq[i] != 'G'))                                    {       success = 0;    }
+                       else if(oligo[i] == 'W' && (seq[i] != 'T' && seq[i] != 'A'))                                    {       success = 0;    }
+                       else if(oligo[i] == 'S' && (seq[i] != 'C' && seq[i] != 'G'))                                    {       success = 0;    }
+                       else if(oligo[i] == 'B' && (seq[i] != 'C' && seq[i] != 'T' && seq[i] != 'G'))   {       success = 0;    }
+                       else if(oligo[i] == 'D' && (seq[i] != 'A' && seq[i] != 'T' && seq[i] != 'G'))   {       success = 0;    }
+                       else if(oligo[i] == 'H' && (seq[i] != 'A' && seq[i] != 'T' && seq[i] != 'C'))   {       success = 0;    }
+                       else if(oligo[i] == 'V' && (seq[i] != 'A' && seq[i] != 'C' && seq[i] != 'G'))   {       success = 0;    }                       
+                       
+                       if(success == 0)        {       break;  }
+               }
+               else{
+                       success = 1;
+               }
+       }
+       
+       return success;
+}
+
+//***************************************************************************************************************
+
+bool TrimSeqsCommand::stripQualThreshold(Sequence& seq, ifstream& qFile){
+       
+       string rawSequence = seq.getUnaligned();
+       int seqLength = rawSequence.length();
+       string name;
+       
+       qFile >> name;
+       if(name.substr(1) != seq.getName())     {       cout << "sequence name mismatch btwn fasta and qual file" << endl;      }
+       while (!qFile.eof())    {       char c = qFile.get(); if (c == 10 || c == 13){  break;  }       }
+       
+       int score;
+       int end = seqLength;
+       
+       for(int i=0;i<seqLength;i++){
+               qFile >> score;
+
+               if(score <= qThreshold){
+                       end = i;
+                       break;
+               }
+       }
+       for(int i=end+1;i<seqLength;i++){
+               qFile >> score;
+       }
+
+       seq.setUnaligned(rawSequence.substr(0,end));
+
+       return 1;
+}
+
+//***************************************************************************************************************
+
+bool TrimSeqsCommand::cullQualAverage(Sequence& seq, ifstream& qFile){
+       
+       string rawSequence = seq.getUnaligned();
+       int seqLength = seq.getNumBases();
+       bool success = 0;       //guilty until proven innocent
+       string name;
+       
+       qFile >> name;
+       if(name.substr(1) != seq.getName())     {       cout << "sequence name mismatch btwn fasta and qual file" << endl;      }
+       while (!qFile.eof())    {       char c = qFile.get(); if (c == 10 || c == 13){  break;  }       }
+       
+       float score;    
+       float average = 0;
+       
+       for(int i=0;i<seqLength;i++){
+               qFile >> score;
+               average += score;
+       }
+       average /= seqLength;
+       
+       if(average >= qAverage) {       success = 1;    }
+       else                                    {       success = 0;    }
+       
+       return success;
+}
+
+//***************************************************************************************************************
+
+
index 03ee1f5745222a1e3fb154c22b4099d26e77d029..ee79d777a8d11ffaa2e279e69463314f9c3b8938 100644 (file)
@@ -12,7 +12,6 @@
 
 #include "mothur.h"
 #include "command.hpp"
-#include "globaldata.hpp"
 #include "sequence.hpp"
 
 class TrimSeqsCommand : public Command {
@@ -23,24 +22,25 @@ public:
        void help();
        
 private:
-       void getOligos();
-       bool stripBarcode(Sequence&, string&);
+       void getOligos(vector<ofstream*>&, vector<ofstream*>&);
+       bool stripQualThreshold(Sequence&, ifstream&);
+       bool cullQualAverage(Sequence&, ifstream&);
+       bool stripBarcode(Sequence&, int&);
        bool stripForward(Sequence&);
        bool stripReverse(Sequence&);
        bool cullLength(Sequence&);
        bool cullHomoP(Sequence&);
        bool cullAmbigs(Sequence&);
-       
-       GlobalData* globaldata;
-       OptionParser* parser;
-       map<string, string> parameters;
-       map<string, string>::iterator it;
+       bool compareDNASeq(string, string);
+
        bool abort;
-       string fastafile;
-       bool oligos, flip;
-       int numFPrimers, numRPrimers, maxAmbig, maxHomoP, minLength, maxLength;
+       string fastaFile, oligoFile, qFileName;
+       
+       bool flip, allFiles;
+       int numFPrimers, numRPrimers, maxAmbig, maxHomoP, minLength, maxLength, qThreshold, qAverage;
        vector<string> forPrimer, revPrimer;
-       map<string, string> barcodes;
+       map<string, int> barcodes;
+       vector<string> groupVector;
 };
 
 #endif
index bc8eb477f088ade4a8e8e0cb4c1c94930d78dc9b..154c528a851eb297a0783e26bb206aae80fc278c 100644 (file)
@@ -24,14 +24,14 @@ UnifracUnweightedCommand::UnifracUnweightedCommand(string option) {
                        string Array[] =  {"groups","iters"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);  delete parser;
+                       OptionParser parser(option);
+                       map<string,string> parameters = parser.getParameters();
                        
-                       ValidParameters* validParameter = new ValidParameters();
+                       ValidParameters validParameter;
                
                        //check to make sure all parameters are valid for command
-                       for (it4 = parameters.begin(); it4 != parameters.end(); it4++) { 
-                               if (validParameter->isValidParameter(it4->first, myArray, it4->second) != true) {  abort = true;  }
+                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        if (globaldata->gTree.size() == 0) {//no trees were read
@@ -39,17 +39,16 @@ UnifracUnweightedCommand::UnifracUnweightedCommand(string option) {
                                                                                
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
-                       groups = validParameter->validFile(parameters, "groups", false);                        
+                       groups = validParameter.validFile(parameters, "groups", false);                 
                        if (groups == "not found") { groups = ""; }
                        else { 
                                splitAtDash(groups, Groups);
                                globaldata->Groups = Groups;
                        }
                                
-                       itersString = validParameter->validFile(parameters, "iters", false);                    if (itersString == "not found") { itersString = "1000"; }
+                       itersString = validParameter.validFile(parameters, "iters", false);                     if (itersString == "not found") { itersString = "1000"; }
                        convert(itersString, iters); 
                        
-                       delete validParameter;
                        
                        if (abort == false) {
                                T = globaldata->gTree;
@@ -146,8 +145,8 @@ int UnifracUnweightedCommand::execute() {
                                
                                for(int k = 0; k < numComp; k++) {      
                                        //add trees unweighted score to map of scores
-                                       it2 = rscoreFreq[k].find(randomData[k]);
-                                       if (it2 != rscoreFreq[k].end()) {//already have that score
+                                       map<float,float>::iterator it = rscoreFreq[k].find(randomData[k]);
+                                       if (it != rscoreFreq[k].end()) {//already have that score
                                                rscoreFreq[k][randomData[k]]++;
                                        }else{//first time we have seen this score
                                                rscoreFreq[k][randomData[k]] = 1;
@@ -162,9 +161,9 @@ int UnifracUnweightedCommand::execute() {
                        for(int a = 0; a < numComp; a++) {
                                float rcumul = 1.0000;
                                //this loop fills the cumulative maps and put 0.0000 in the score freq map to make it easier to print.
-                               for (it = validScores.begin(); it != validScores.end(); it++) { 
+                               for (map<float,float>::iterator it = validScores.begin(); it != validScores.end(); it++) { 
                                        //make rscoreFreq map and rCumul
-                                       it2 = rscoreFreq[a].find(it->first);
+                                       map<float,float>::iterator it2 = rscoreFreq[a].find(it->first);
                                        rCumul[a][it->first] = rcumul;
                                        //get percentage of random trees with that info
                                        if (it2 != rscoreFreq[a].end()) {  rscoreFreq[a][it->first] /= iters; rcumul-= it2->second;  }
@@ -212,7 +211,7 @@ void UnifracUnweightedCommand::printUnweightedFile() {
                for(int a = 0; a < numComp; a++) {
                        output->initFile(groupComb[a], tags);
                        //print each line
-                       for (it = validScores.begin(); it != validScores.end(); it++) { 
+                       for (map<float,float>::iterator it = validScores.begin(); it != validScores.end(); it++) { 
                                data.push_back(it->first);  data.push_back(rscoreFreq[a][it->first]); data.push_back(rCumul[a][it->first]); 
                                output->output(data);
                                data.clear();
index 3c031c66c1da524e5b7f3177cfca7d0743573a7a..7707df4126172061cef898db12a2a10352dee7a8 100644 (file)
@@ -44,12 +44,7 @@ class UnifracUnweightedCommand : public Command {
                map<float, float>  validScores;  //map contains scores from random
                vector< map<float, float> > rscoreFreq;  //map <unweighted score, number of random trees with that score.> -vector entry for each combination.
                vector< map<float, float> > rCumul;  //map <unweighted score, cumulative percentage of number of random trees with that score or higher.> -vector entry for each combination.
-               map<float, float>::iterator it2;
-               map<float, float>::iterator it;
                
-               OptionParser* parser;
-               map<string, string> parameters;
-               map<string, string>::iterator it4;
                bool abort;
                string groups, itersString;
                vector<string> Groups; //holds groups to be used
index a7a41f37b820cb8af77ede45cf31d0b0f4885d84..cf54e6420e6b1e4e2c54c87672142b0fb89dc655 100644 (file)
@@ -24,14 +24,14 @@ UnifracWeightedCommand::UnifracWeightedCommand(string option) {
                        string Array[] =  {"groups","iters"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);  delete parser;
+                       OptionParser parser(option);
+                       map<string,string> parameters=parser.getParameters();
                        
-                       ValidParameters* validParameter = new ValidParameters();
+                       ValidParameters validParameter;
                
                        //check to make sure all parameters are valid for command
-                       for (it4 = parameters.begin(); it4 != parameters.end(); it4++) { 
-                               if (validParameter->isValidParameter(it4->first, myArray, it4->second) != true) {  abort = true;  }
+                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        if (globaldata->gTree.size() == 0) {//no trees were read
@@ -39,17 +39,16 @@ UnifracWeightedCommand::UnifracWeightedCommand(string option) {
                                                                                
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
-                       groups = validParameter->validFile(parameters, "groups", false);                        
+                       groups = validParameter.validFile(parameters, "groups", false);                 
                        if (groups == "not found") { groups = ""; }
                        else { 
                                splitAtDash(groups, Groups);
                                globaldata->Groups = Groups;
                        }
                                
-                       itersString = validParameter->validFile(parameters, "iters", false);                    if (itersString == "not found") { itersString = "1000"; }
+                       itersString = validParameter.validFile(parameters, "iters", false);                     if (itersString == "not found") { itersString = "1000"; }
                        convert(itersString, iters); 
-                       
-                       delete validParameter;
+               
                        
                        if (abort == false) {
                                T = globaldata->gTree;
@@ -222,7 +221,7 @@ void UnifracWeightedCommand::printWeightedFile() {
                for(int a = 0; a < numComp; a++) {
                        output->initFile(groupComb[a], tags);
                        //print each line
-                       for (it = validScores.begin(); it != validScores.end(); it++) { 
+                       for (map<float,float>::iterator it = validScores.begin(); it != validScores.end(); it++) { 
                                data.push_back(it->first);  data.push_back(rScoreFreq[a][it->first]); data.push_back(rCumul[a][it->first]); 
                                output->output(data);
                                data.clear();
@@ -310,7 +309,7 @@ void UnifracWeightedCommand::calculateFreqsCumuls() {
                for (int f = 0; f < numComp; f++) {
                        for (int i = 0; i < rScores[f].size(); i++) { //looks like 0,0,1,1,1,2,4,7...  you want to make a map that say rScoreFreq[0] = 2, rScoreFreq[1] = 3...
                                validScores[rScores[f][i]] = rScores[f][i];
-                               it = rScoreFreq[f].find(rScores[f][i]);
+                               map<float,float>::iterator it = rScoreFreq[f].find(rScores[f][i]);
                                if (it != rScoreFreq[f].end()) {
                                        rScoreFreq[f][rScores[f][i]]++;
                                }else{
@@ -323,9 +322,9 @@ void UnifracWeightedCommand::calculateFreqsCumuls() {
                for(int a = 0; a < numComp; a++) {
                        float rcumul = 1.0000;
                        //this loop fills the cumulative maps and put 0.0000 in the score freq map to make it easier to print.
-                       for (it = validScores.begin(); it != validScores.end(); it++) {
+                       for (map<float,float>::iterator it = validScores.begin(); it != validScores.end(); it++) {
                                //make rscoreFreq map and rCumul
-                               it2 = rScoreFreq[a].find(it->first);
+                               map<float,float>::iterator it2 = rScoreFreq[a].find(it->first);
                                rCumul[a][it->first] = rcumul;
                                //get percentage of random trees with that info
                                if (it2 != rScoreFreq[a].end()) {  rScoreFreq[a][it->first] /= iters; rcumul-= it2->second;  }
index 2d78d57fe827a0678421f39a44c0d2e6fe4cedf0..9ea78baf17370d7c068e40d56014f2f4f6d49010 100644 (file)
@@ -48,19 +48,13 @@ class UnifracWeightedCommand : public Command {
                vector< map<float, float> > rScoreFreq;  //map <weighted score, number of random trees with that score.> -vector entry for each combination.
                vector< map<float, float> > rCumul;  //map <weighted score, cumulative percentage of number of random trees with that score or higher.> -vector entry for each c                                                                
                map<float, float>  validScores;  //map contains scores from random
-               map<float, float>::iterator it2;
-               map<float, float>::iterator it;
                
-               OptionParser* parser;
-               map<string, string> parameters;
-               map<string, string>::iterator it4;
                bool abort;
                string groups, itersString;
                vector<string> Groups; //holds groups to be used
 
                
-               ofstream outSum, out;
-               ifstream inFile;
+               ofstream outSum;
                
                void printWSummaryFile();
                void printWeightedFile();  
index 6402adff9ec9f0787f331e81046ee3ca4569bec7..921c125040d6950aeb773c995b1c0f2cca5d5d60 100644 (file)
--- a/venn.cpp
+++ b/venn.cpp
@@ -19,7 +19,7 @@
 Venn::Venn(){
        try {
                globaldata = GlobalData::getInstance();
-               format = globaldata->getFormat();
+
        }
        catch(exception& e) {
                cout << "Standard Error: " << e.what() << " has occurred in the Venn class Function Venn. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
diff --git a/venn.h b/venn.h
index 8a789c364ac9e6e25bb0bc0312994e4c0e319d34..8902cf4c9298dfe7df40b6739445cc494ebce3eb 100644 (file)
--- a/venn.h
+++ b/venn.h
 /***********************************************************************/
 
 class Venn {
-       
-       public:
-               Venn();
-               ~Venn(){};
-       
-               void getPic(SAbundVector*, vector<Calculator*>);
-               void getPic(vector<SharedRAbundVector*>, vector<Calculator*>);
-
-       private:
-               GlobalData* globaldata;
-               Calculator* singleCalc;
-               string format, groupComb;
-               ofstream outsvg;
-
-                       
+public:
+       Venn();
+       ~Venn(){};
+
+       void getPic(SAbundVector*, vector<Calculator*>);
+       void getPic(vector<SharedRAbundVector*>, vector<Calculator*>);
+
+private:
+       GlobalData* globaldata;
+       Calculator* singleCalc;
+       string groupComb;
+       ofstream outsvg;
 };
+
 /***********************************************************************/
 
 #endif
index 0bed752e08ccb5a7672a5b5e1744569700cf73ab..70c136b8cb56f59aeeef41cba2d1c1fa75e83b54 100644 (file)
@@ -35,14 +35,14 @@ VennCommand::VennCommand(string option){
                        string AlignArray[] =  {"groups","line","label","calc", "abund"};
                        vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);  delete parser;
+                       OptionParser parser(option);
+                       map<string,string> parameters = parser.getParameters();
+                       
+                       ValidParameters validParameter;
                        
-                       ValidParameters* validParameter = new ValidParameters();
-               
                        //check to make sure all parameters are valid for command
-                       for (it = parameters.begin(); it != parameters.end(); it++) { 
-                               if (validParameter->isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        //make sure the user has already run the read.otu command
@@ -52,14 +52,14 @@ VennCommand::VennCommand(string option){
 
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
-                       line = validParameter->validFile(parameters, "line", false);                            
+                       line = validParameter.validFile(parameters, "line", false);                             
                        if (line == "not found") { line = "";  }
                        else { 
                                if(line != "all") {  splitAtDash(line, lines);  allLines = 0;  }
                                else { allLines = 1;  }
                        }
                        
-                       label = validParameter->validFile(parameters, "label", false);                  
+                       label = validParameter.validFile(parameters, "label", false);                   
                        if (label == "not found") { label = ""; }
                        else { 
                                if(label != "all") {  splitAtDash(label, labels);  allLines = 0;  }
@@ -75,7 +75,7 @@ VennCommand::VennCommand(string option){
                                lines = globaldata->lines;
                        }
                        
-                       groups = validParameter->validFile(parameters, "groups", false);                        
+                       groups = validParameter.validFile(parameters, "groups", false);                 
                        if (groups == "not found") { groups = ""; }
                        else { 
                                splitAtDash(groups, Groups);
@@ -83,7 +83,7 @@ VennCommand::VennCommand(string option){
                        }
                        
                        format = globaldata->getFormat();
-                       calc = validParameter->validFile(parameters, "calc", false);                    
+                       calc = validParameter.validFile(parameters, "calc", false);                     
                        if (calc == "not found") { 
                                if(format == "list") { calc = "sobs"; }
                                else { calc = "sharedsobs"; }
@@ -97,11 +97,9 @@ VennCommand::VennCommand(string option){
                        splitAtDash(calc, Estimators);
                        
                        string temp;
-                       temp = validParameter->validFile(parameters, "abund", false);           if (temp == "not found") { temp = "10"; }
+                       temp = validParameter.validFile(parameters, "abund", false);            if (temp == "not found") { temp = "10"; }
                        convert(temp, abund); 
 
-                       delete validParameter;
-                       
                        if (abort == false) {
                                validCalculator = new ValidCalculators();
                
index 3671350072afff05cf0816e66ce649182b00d258..0b891437a51e99ea7c17ae18b5be63be51b6ed20 100644 (file)
@@ -40,9 +40,6 @@ private:
        SAbundVector* sabund;
        int abund;
        
-       OptionParser* parser;
-       map<string, string> parameters;
-       map<string, string>::iterator it;
        bool abort, allLines;
        set<int> lines; //hold lines to be used
        set<string> labels; //holds labels to be used