From: pschloss Date: Sun, 14 Jun 2009 20:59:57 +0000 (+0000) Subject: merged pat's trim seqs edits with sarah's major overhaul of global data; also added... X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=cd37904452dc95b183ff313ff05720c562902487 merged pat's trim seqs edits with sarah's major overhaul of global data; also added merge.files --- diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj index 32077f3..6244917 100644 --- a/Mothur.xcodeproj/project.pbxproj +++ b/Mothur.xcodeproj/project.pbxproj @@ -149,6 +149,7 @@ 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 */; }; @@ -479,6 +480,8 @@ 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 = ""; }; + 7E5A17AE0FE57292003C6A03 /* mergefilecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = mergefilecommand.cpp; sourceTree = ""; }; 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; }; @@ -748,6 +751,8 @@ 37D928A90F2133E5001D4494 /* commands */ = { isa = PBXGroup; children = ( + 7E5A17AE0FE57292003C6A03 /* mergefilecommand.cpp */, + 7E5A17AD0FE57292003C6A03 /* mergefilecommand.h */, 37D927CD0F21331F001D4494 /* command.hpp */, 378DC5CD0FBDE1C8003B8607 /* aligncommand.h */, 378DC5CE0FBDE1C8003B8607 /* aligncommand.cpp */, @@ -1115,6 +1120,7 @@ 378598660FDD497000EF9D03 /* heatmapsimcommand.cpp in Sources */, 378598740FDD4C1500EF9D03 /* heatmapsim.cpp in Sources */, 378599100FDD7E8E00EF9D03 /* optionparser.cpp in Sources */, + 7E5A17AF0FE57292003C6A03 /* mergefilecommand.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/aligncommand.cpp b/aligncommand.cpp index 4b9dedc..2811f1f 100644 --- a/aligncommand.cpp +++ b/aligncommand.cpp @@ -12,23 +12,16 @@ * 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" @@ -38,67 +31,64 @@ //********************************************************************************************************************** + 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 myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); - parser = new OptionParser(); - - parser->parse(option, parameters); delete parser; + OptionParser parser(option); + map 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::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(in),istreambuf_iterator(), '>'); - 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(inFASTA),istreambuf_iterator(), '>'); + inFASTA.close(); + + lines.push_back(new linePair(0, numFastaSeqs)); + + driver(lines[0], alignFileName, reportFileName); + } + else{ + vector 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::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;isecond) + ".temp"), reportFileName); + remove((reportFileName + toString(it->second) + ".temp").c_str()); + } + } +#else + ifstream inFASTA; + openInputFile(candidateFileName, inFASTA); + numFastaSeqs=count(istreambuf_iterator(inFASTA),istreambuf_iterator(), '>'); + 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;inumSeqs;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::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 +//********************************************************************************************************************** diff --git a/aligncommand.h b/aligncommand.h index a3ec827..62bf3dc 100644 --- a/aligncommand.h +++ b/aligncommand.h @@ -10,10 +10,10 @@ * */ +#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 parameters; - map::iterator it; - bool abort; + struct linePair { + int start; + int numSeqs; + linePair(int i, int j) : start(i), numSeqs(j) {} + }; + map processIDS; //end line, processid + vector 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 diff --git a/binsequencecommand.cpp b/binsequencecommand.cpp index c2fd6fa..abe000f 100644 --- a/binsequencecommand.cpp +++ b/binsequencecommand.cpp @@ -26,14 +26,14 @@ BinSeqCommand::BinSeqCommand(string option){ string AlignArray[] = {"fasta","line","label","name", "group"}; vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); - parser = new OptionParser(); - parser->parse(option, parameters); delete parser; + OptionParser parser(option); + map 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::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 != "") { diff --git a/binsequencecommand.h b/binsequencecommand.h index aceba65..6f9f69d 100644 --- a/binsequencecommand.h +++ b/binsequencecommand.h @@ -36,9 +36,6 @@ private: InputData* input; FastaMap* fasta; GroupMap* groupMap; - OptionParser* parser; - map parameters; - map::iterator it; bool abort, allLines; set lines; //hold lines to be used set labels; //holds labels to be used diff --git a/bootstrapsharedcommand.cpp b/bootstrapsharedcommand.cpp index 9e3a82d..5e7c0c6 100644 --- a/bootstrapsharedcommand.cpp +++ b/bootstrapsharedcommand.cpp @@ -40,14 +40,14 @@ BootSharedCommand::BootSharedCommand(string option){ string Array[] = {"line","label","calc","groups","iters"}; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - parser = new OptionParser(); - parser->parse(option, parameters); delete parser; + OptionParser parser(option); + map 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::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(); diff --git a/bootstrapsharedcommand.h b/bootstrapsharedcommand.h index 9ff44b3..4d2ebe3 100644 --- a/bootstrapsharedcommand.h +++ b/bootstrapsharedcommand.h @@ -49,9 +49,7 @@ private: ValidCalculators* validCalculator; SharedOrderVector* order; vector lookup; - OptionParser* parser; - map parameters; - map::iterator it; + bool abort, allLines; set lines; //hold lines to be used set labels; //holds labels to be used diff --git a/clustercommand.cpp b/clustercommand.cpp index 36fff22..706ff67 100644 --- a/clustercommand.cpp +++ b/clustercommand.cpp @@ -24,14 +24,14 @@ ClusterCommand::ClusterCommand(string option){ string Array[] = {"cutoff","precision","method"}; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - parser = new OptionParser(); - parser->parse(option, parameters); delete parser; + OptionParser parser(option); + map 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::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; } diff --git a/clustercommand.h b/clustercommand.h index 37b9edb..44ce6f9 100644 --- a/clustercommand.h +++ b/clustercommand.h @@ -44,9 +44,7 @@ private: RAbundVector* rabund; RAbundVector oldRAbund; ListVector oldList; - OptionParser* parser; - map parameters; - map::iterator it; + bool abort; string method, fileroot, tag; diff --git a/collectcommand.cpp b/collectcommand.cpp index a904870..2dd843f 100644 --- a/collectcommand.cpp +++ b/collectcommand.cpp @@ -48,14 +48,14 @@ CollectCommand::CollectCommand(string option){ string Array[] = {"freq","line","label","calc","abund","size"}; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - parser = new OptionParser(); - parser->parse(option, parameters); delete parser; + OptionParser parser(option); + map 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::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; diff --git a/collectcommand.h b/collectcommand.h index 3b79d7f..04dcc60 100644 --- a/collectcommand.h +++ b/collectcommand.h @@ -52,9 +52,7 @@ private: ValidCalculators* validCalculator; vector cDisplays; int freq, abund, size; - OptionParser* parser; - map parameters; - map::iterator it; + bool abort, allLines; set lines; //hold lines to be used set labels; //holds labels to be used diff --git a/collectsharedcommand.cpp b/collectsharedcommand.cpp index 2b6cbac..36b0dc1 100644 --- a/collectsharedcommand.cpp +++ b/collectsharedcommand.cpp @@ -53,14 +53,14 @@ CollectSharedCommand::CollectSharedCommand(string option){ string Array[] = {"freq","line","label","calc","groups"}; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - parser = new OptionParser(); - parser->parse(option, parameters); delete parser; + OptionParser parser(option); + map 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::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(); diff --git a/collectsharedcommand.h b/collectsharedcommand.h index 7024d0b..67e8e0c 100644 --- a/collectsharedcommand.h +++ b/collectsharedcommand.h @@ -57,9 +57,7 @@ private: vector cDisplays; int freq; string format; - OptionParser* parser; - map parameters; - map::iterator it; + bool abort, allLines; set lines; //hold lines to be used set labels; //holds labels to be used diff --git a/command.hpp b/command.hpp index 3e655ab..27355dd 100644 --- a/command.hpp +++ b/command.hpp @@ -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" diff --git a/commandfactory.cpp b/commandfactory.cpp index 48a3633..eeaf8ee 100644 --- a/commandfactory.cpp +++ b/commandfactory.cpp @@ -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; diff --git a/deconvolutecommand.cpp b/deconvolutecommand.cpp index 96682af..3ec5f73 100644 --- a/deconvolutecommand.cpp +++ b/deconvolutecommand.cpp @@ -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 myArray (Array, Array+(sizeof(Array)/sizeof(string))); - parser = new OptionParser(); - parser->parse(option, parameters); delete parser; + OptionParser parser(option); + map 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::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; } } diff --git a/deconvolutecommand.h b/deconvolutecommand.h index 0b6eb5e..b6bda8f 100644 --- a/deconvolutecommand.h +++ b/deconvolutecommand.h @@ -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 parameters; - map::iterator it; - bool abort; - + bool abort; }; #endif diff --git a/distancecommand.cpp b/distancecommand.cpp index 7890cb9..065c14a 100644 --- a/distancecommand.cpp +++ b/distancecommand.cpp @@ -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 myArray (Array, Array+(sizeof(Array)/sizeof(string))); - parser = new OptionParser(); - parser->parse(option, parameters); delete parser; + OptionParser parser(option); + map 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::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; iisValidCalculator("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; iisValidCalculator("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; igetNumSeqs(); + 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::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::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;icalcDist(*(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; } diff --git a/distancecommand.h b/distancecommand.h index 446be04..6a7ac93 100644 --- a/distancecommand.h +++ b/distancecommand.h @@ -12,47 +12,40 @@ #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 processIDS; //end line, processid - map::iterator it; vector lines; - OptionParser* parser; - map parameters; - map::iterator it2; bool abort; vector 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); }; diff --git a/fileoutput.h b/fileoutput.h index 209dd1b..7dfb0c0 100644 --- a/fileoutput.h +++ b/fileoutput.h @@ -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 diff --git a/filterseqscommand.cpp b/filterseqscommand.cpp index 1363216..95d51f3 100644 --- a/filterseqscommand.cpp +++ b/filterseqscommand.cpp @@ -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 myArray (Array, Array+(sizeof(Array)/sizeof(string))); - parser = new OptionParser(); - parser->parse(option, parameters); delete parser; + OptionParser parser(option); + map 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::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= 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; } diff --git a/filterseqscommand.h b/filterseqscommand.h index 3f1e4c4..cfa56b3 100644 --- a/filterseqscommand.h +++ b/filterseqscommand.h @@ -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 parameters; - map::iterator it; - GlobalData* globaldata; vector a, t, g, c, gap; }; diff --git a/getlinecommand.cpp b/getlinecommand.cpp index 5f459bf..6802978 100644 --- a/getlinecommand.cpp +++ b/getlinecommand.cpp @@ -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; diff --git a/getlinecommand.h b/getlinecommand.h index 915a09a..68870b3 100644 --- a/getlinecommand.h +++ b/getlinecommand.h @@ -24,7 +24,6 @@ public: private: GlobalData* globaldata; - string filename; bool abort; }; diff --git a/getoturepcommand.cpp b/getoturepcommand.cpp index 92aab92..7918899 100644 --- a/getoturepcommand.cpp +++ b/getoturepcommand.cpp @@ -26,14 +26,14 @@ GetOTURepCommand::GetOTURepCommand(string option){ string Array[] = {"fasta","list","line","label","name", "group"}; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - parser = new OptionParser(); - parser->parse(option, parameters); delete parser; + OptionParser parser(option); + map 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::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::iterator it; bool needToRun = false; - for (it = userLabels.begin(); it != userLabels.end(); it++) { + for (set::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 names; map sums; - map::iterator it4; map 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::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::iterator it = binMap.find(currentCell->row); + map::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::iterator it4 = sums.begin(); it4 != sums.end(); it4++) { if (it4->second < min) { min = it4->second; minName = it4->first; diff --git a/getoturepcommand.h b/getoturepcommand.h index f413d4f..37c4194 100644 --- a/getoturepcommand.h +++ b/getoturepcommand.h @@ -44,16 +44,11 @@ private: ofstream out; ifstream in, inNames; bool groupError; - OptionParser* parser; - map parameters; - map::iterator it4; + bool abort, allLines; set lines; //hold lines to be used set labels; //holds labels to be used map nameToIndex; //maps sequence name to index in sparsematrix - map::iterator it; - map::iterator it2; - map::iterator it3; void readNamesFile(); int process(ListVector*); diff --git a/getrabundcommand.cpp b/getrabundcommand.cpp index 9236ba0..c978bb1 100644 --- a/getrabundcommand.cpp +++ b/getrabundcommand.cpp @@ -27,14 +27,14 @@ GetRAbundCommand::GetRAbundCommand(string option){ string Array[] = {"line","label"}; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - parser = new OptionParser(); - parser->parse(option, parameters); delete parser; + OptionParser parser(option); + map 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::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); diff --git a/getrabundcommand.h b/getrabundcommand.h index 4b2c37f..38b5ec7 100644 --- a/getrabundcommand.h +++ b/getrabundcommand.h @@ -33,9 +33,7 @@ private: InputData* input; ListVector* list; RAbundVector* rabund; - OptionParser* parser; - map parameters; - map::iterator it; + bool abort, allLines; set lines; //hold lines to be used set labels; //holds labels to be used diff --git a/getsabundcommand.cpp b/getsabundcommand.cpp index b3aa54f..6670980 100644 --- a/getsabundcommand.cpp +++ b/getsabundcommand.cpp @@ -27,14 +27,14 @@ GetSAbundCommand::GetSAbundCommand(string option){ string Array[] = {"line","label"}; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - parser = new OptionParser(); - parser->parse(option, parameters); delete parser; + OptionParser parser(option); + map 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::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); diff --git a/getsabundcommand.h b/getsabundcommand.h index cd95d94..dcda3aa 100644 --- a/getsabundcommand.h +++ b/getsabundcommand.h @@ -34,9 +34,7 @@ private: OrderVector* lastOrder; InputData* input; SAbundVector* sabund; - OptionParser* parser; - map parameters; - map::iterator it; + bool abort, allLines; set lines; //hold lines to be used set labels; //holds labels to be used diff --git a/globaldata.cpp b/globaldata.cpp index 68f7fc3..fe3c11b 100644 --- a/globaldata.cpp +++ b/globaldata.cpp @@ -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 = ""; } + + /*******************************************************/ /******************************************************/ diff --git a/globaldata.hpp b/globaldata.hpp index 1d38d63..6515521 100644 --- a/globaldata.hpp +++ b/globaldata.hpp @@ -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 diff --git a/heatmap.cpp b/heatmap.cpp index e707b60..3ed606f 100644 --- a/heatmap.cpp +++ b/heatmap.cpp @@ -13,7 +13,7 @@ HeatMap::HeatMap(string sort, string scale){ try { globaldata = GlobalData::getInstance(); - format = globaldata->getFormat(); +// format = globaldata->getFormat(); sorted = sort; scaler = scale; } diff --git a/heatmapcommand.cpp b/heatmapcommand.cpp index b095041..766f7da 100644 --- a/heatmapcommand.cpp +++ b/heatmapcommand.cpp @@ -28,14 +28,14 @@ HeatMapCommand::HeatMapCommand(string option){ string AlignArray[] = {"groups","line","label","sorted","scale"}; vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); - parser = new OptionParser(); - parser->parse(option, parameters); delete parser; + OptionParser parser(option); + map 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::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); diff --git a/heatmapcommand.h b/heatmapcommand.h index 2ae9882..6d6c1d5 100644 --- a/heatmapcommand.h +++ b/heatmapcommand.h @@ -36,9 +36,7 @@ private: RAbundVector* rabund; vector lookup; HeatMap* heatmap; - OptionParser* parser; - map parameters; - map::iterator it; + bool abort, allLines; set lines; //hold lines to be used set labels; //holds labels to be used diff --git a/heatmapsimcommand.cpp b/heatmapsimcommand.cpp index 0c9502f..68076d3 100644 --- a/heatmapsimcommand.cpp +++ b/heatmapsimcommand.cpp @@ -40,14 +40,14 @@ HeatMapSimCommand::HeatMapSimCommand(string option){ string AlignArray[] = {"groups","line","label", "calc"}; vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); - parser = new OptionParser(); - parser->parse(option, parameters); delete parser; + OptionParser parser(option); + map 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::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(); diff --git a/helpcommand.cpp b/helpcommand.cpp index 0acce70..4a97342 100644 --- a/helpcommand.cpp +++ b/helpcommand.cpp @@ -12,12 +12,10 @@ //********************************************************************************************************************** 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(); - } +} //********************************************************************************************************************** diff --git a/helpcommand.h b/helpcommand.h index c303678..4e68388 100644 --- a/helpcommand.h +++ b/helpcommand.h @@ -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: diff --git a/libshuffcommand.cpp b/libshuffcommand.cpp index e7e1aa7..9a71a03 100644 --- a/libshuffcommand.cpp +++ b/libshuffcommand.cpp @@ -37,14 +37,14 @@ LibShuffCommand::LibShuffCommand(string option){ string Array[] = {"iters","groups","step","form","cutoff"}; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - parser = new OptionParser(); - parser->parse(option, parameters); delete parser; + OptionParser parser(option); + map 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::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) { diff --git a/libshuffcommand.h b/libshuffcommand.h index 150bdb4..1e5726d 100644 --- a/libshuffcommand.h +++ b/libshuffcommand.h @@ -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 groupNames; - private: - vector groupNames; - - void setGroups(); - void printCoverageFile(); - void printSummaryFile(); - - GlobalData* globaldata; - FullMatrix* matrix; - Libshuff* form; - float cutOff, step; - int numGroups, numComp, iters; - string coverageFile, summaryFile; - vector > pValueCounts; - vector > savedDXYValues; - vector > > savedMinValues; - OptionParser* parser; - map parameters; - map::iterator it; - bool abort; - string outputFile, groups, userform, savegroups; - vector 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 > pValueCounts; + vector > savedDXYValues; + vector > > savedMinValues; + + bool abort; + string outputFile, groups, userform, savegroups; + vector Groups; //holds groups to be used }; #endif diff --git a/matrixoutputcommand.cpp b/matrixoutputcommand.cpp index 1e4de75..e848647 100644 --- a/matrixoutputcommand.cpp +++ b/matrixoutputcommand.cpp @@ -40,14 +40,14 @@ MatrixOutputCommand::MatrixOutputCommand(string option){ string Array[] = {"line","label","calc","groups"}; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - parser = new OptionParser(); - parser->parse(option, parameters); delete parser; + OptionParser parser(option); + map 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::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(); diff --git a/matrixoutputcommand.h b/matrixoutputcommand.h index d609932..07743e5 100644 --- a/matrixoutputcommand.h +++ b/matrixoutputcommand.h @@ -45,9 +45,7 @@ private: string exportFileName; int numGroups; ofstream out; - OptionParser* parser; - map parameters; - map::iterator it; + bool abort, allLines; set lines; //hold lines to be used set labels; //holds labels to be used diff --git a/mergefilecommand.cpp b/mergefilecommand.cpp new file mode 100644 index 0000000..3342c48 --- /dev/null +++ b/mergefilecommand.cpp @@ -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 myArray (Array, Array+(sizeof(Array)/sizeof(string))); + + OptionParser parser(option); + map parameters = parser.getParameters(); + + ValidParameters validParameter; + + //check to make sure all parameters are valid for command + for (map::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 fileNames; + string outputFileName; + int numInputFiles; + bool abort; +}; + +#endif diff --git a/optionparser.cpp b/optionparser.cpp index 7ff6ae7..2de1621 100644 --- a/optionparser.cpp +++ b/optionparser.cpp @@ -10,22 +10,23 @@ #include "optionparser.h" /***********************************************************************/ -void OptionParser::parse(string option, map& 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& container) { exit(1); } } -/***********************************************************************/ \ No newline at end of file + +/***********************************************************************/ + +map OptionParser::getParameters() { return parameters; } + +/***********************************************************************/ diff --git a/optionparser.h b/optionparser.h index b4d0dcb..dab14de 100644 --- a/optionparser.h +++ b/optionparser.h @@ -18,11 +18,12 @@ /***********************************************************************/ class OptionParser { - public: - OptionParser() {} - ~OptionParser() {} - void parse(string, map&); //pass it an option string and a container - //fills the container key=parameter name, value=parameter value +public: + OptionParser(string); + ~OptionParser() {} + map getParameters(); +private: + map parameters; }; /***********************************************************************/ diff --git a/parsimonycommand.cpp b/parsimonycommand.cpp index e081279..266dd3b 100644 --- a/parsimonycommand.cpp +++ b/parsimonycommand.cpp @@ -24,17 +24,17 @@ ParsimonyCommand::ParsimonyCommand(string option) { string Array[] = {"random","groups","iters"}; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - parser = new OptionParser(); - parser->parse(option, parameters); delete parser; + OptionParser parser(option); + map 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::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::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::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::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::iterator it = validScores.begin(); it != validScores.end(); it++) { if (randomtree == "") { - it2 = uscoreFreq[a].find(it->first); + map::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::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::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{ diff --git a/parsimonycommand.h b/parsimonycommand.h index bbcd6af..63980c2 100644 --- a/parsimonycommand.h +++ b/parsimonycommand.h @@ -20,53 +20,48 @@ 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 T; //user trees + Tree* randT; //random tree + Tree* copyUserTree; + TreeMap* tmap; + TreeMap* savetmap; + Parsimony* pars; + vector groupComb; // AB. AC, BC... + string sumFile, randomtree, allGroups; + int iters, numGroups, numComp, counter; + vector numEachGroup; //vector containing the number of sequences in each group the users wants for random distrib. + vector< vector > userTreeScores; //scores for users trees for each comb. + vector< vector > 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 validScores; //map contains scores from both user and random + vector< map > rscoreFreq; //map -vector entry for each combination. + vector< map > uscoreFreq; //map -vector entry for each combination. + vector< map > rCumul; //map -vector entry for each combination. + vector< map > uCumul; //map -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 T; //user trees - Tree* randT; //random tree - Tree* copyUserTree; - TreeMap* tmap; - TreeMap* savetmap; - Parsimony* pars; - vector groupComb; // AB. AC, BC... - string sumFile, randomtree, allGroups; - int iters, numGroups, numComp, counter; - vector numEachGroup; //vector containing the number of sequences in each group the users wants for random distrib. - vector< vector > userTreeScores; //scores for users trees for each comb. - vector< vector > 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 validScores; //map contains scores from both user and random - vector< map > rscoreFreq; //map -vector entry for each combination. - vector< map > uscoreFreq; //map -vector entry for each combination. - vector< map > rCumul; //map -vector entry for each combination. - vector< map > uCumul; //map -vector entry for each combination. - map::iterator it; - map::iterator it2; - - ofstream out, outSum; - ifstream inFile; - - OptionParser* parser; - map parameters; - map::iterator it4; - bool abort; - string groups, itersString; - vector Groups; //holds groups to be used - void printParsimonyFile(); - void printUSummaryFile(); - void getUserInput(); - + bool abort; + string groups, itersString; + vector Groups; //holds groups to be used + + void printParsimonyFile(); + void printUSummaryFile(); + void getUserInput(); + }; diff --git a/rarefactcommand.cpp b/rarefactcommand.cpp index 680f68c..6bf42fc 100644 --- a/rarefactcommand.cpp +++ b/rarefactcommand.cpp @@ -39,14 +39,14 @@ RareFactCommand::RareFactCommand(string option){ string Array[] = {"iters","freq","line","label","calc","abund"}; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - parser = new OptionParser(); - parser->parse(option, parameters); delete parser; + OptionParser parser(option); + map 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::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) { diff --git a/rarefactcommand.h b/rarefactcommand.h index ea867f0..1bcb0cf 100644 --- a/rarefactcommand.h +++ b/rarefactcommand.h @@ -51,9 +51,7 @@ private: ValidCalculators* validCalculator; Rarefact* rCurve; int freq, nIters, abund; - OptionParser* parser; - map parameters; - map::iterator it; + bool abort, allLines; set lines; //hold lines to be used set labels; //holds labels to be used diff --git a/rarefactsharedcommand.cpp b/rarefactsharedcommand.cpp index 66ef6dd..d0179be 100644 --- a/rarefactsharedcommand.cpp +++ b/rarefactsharedcommand.cpp @@ -30,14 +30,14 @@ RareFactSharedCommand::RareFactSharedCommand(string option){ string Array[] = {"iters","line","label","calc","groups"}; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - parser = new OptionParser(); - parser->parse(option, parameters); delete parser; + OptionParser parser(option); + map 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::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; iisValidCalculator("sharedrarefaction", Estimators[i]) == true) { if (Estimators[i] == "sharedobserved") { rDisplays.push_back(new RareDisplay(new SharedSobs(), new SharedThreeColumnFile(fileNameRoot+"shared.rarefaction", ""))); diff --git a/rarefactsharedcommand.h b/rarefactsharedcommand.h index d81ff6d..c7290f4 100644 --- a/rarefactsharedcommand.h +++ b/rarefactsharedcommand.h @@ -48,9 +48,7 @@ private: vector rDisplays; int freq, nIters; string format; - OptionParser* parser; - map parameters; - map::iterator it; + bool abort, allLines; set lines; //hold lines to be used set labels; //holds labels to be used diff --git a/readdistcommand.cpp b/readdistcommand.cpp index 31d8308..b03f12e 100644 --- a/readdistcommand.cpp +++ b/readdistcommand.cpp @@ -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 myArray (Array, Array+(sizeof(Array)/sizeof(string))); - parser = new OptionParser(); - parser->parse(option, parameters); delete parser; + OptionParser parser(option); + map 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::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; } diff --git a/readdistcommand.h b/readdistcommand.h index b6e3ae4..868d72e 100644 --- a/readdistcommand.h +++ b/readdistcommand.h @@ -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 parameters; - map::iterator it; + bool abort; }; diff --git a/readotucommand.cpp b/readotucommand.cpp index 1f1ad97..7c3e199 100644 --- a/readotucommand.cpp +++ b/readotucommand.cpp @@ -24,40 +24,40 @@ ReadOtuCommand::ReadOtuCommand(string option){ string Array[] = {"list","order","shared", "line", "label","group","sabund", "rabund"}; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - parser = new OptionParser(); - parser->parse(option, parameters); delete parser; + OptionParser parser(option); + map 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::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 diff --git a/readotucommand.h b/readotucommand.h index 586e6ef..c38d0a5 100644 --- a/readotucommand.h +++ b/readotucommand.h @@ -46,9 +46,7 @@ private: Command* parselist; GroupMap* groupMap; string filename, listfile, orderfile, sharedfile, line, label, groupfile, sabundfile, rabundfile, format; - OptionParser* parser; - map parameters; - map::iterator it; + bool abort, allLines; set lines; //hold lines to be used set labels; //holds labels to be used diff --git a/readtreecommand.cpp b/readtreecommand.cpp index 6e5742d..b030542 100644 --- a/readtreecommand.cpp +++ b/readtreecommand.cpp @@ -23,25 +23,25 @@ ReadTreeCommand::ReadTreeCommand(string option){ string Array[] = {"tree","group"}; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - parser = new OptionParser(); - parser->parse(option, parameters); delete parser; + OptionParser parser(option); + map 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::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) { diff --git a/readtreecommand.h b/readtreecommand.h index ca9f3b8..99ddc38 100644 --- a/readtreecommand.h +++ b/readtreecommand.h @@ -28,9 +28,6 @@ private: ReadTree* read; TreeMap* treeMap; string filename, treefile, groupfile; - OptionParser* parser; - map parameters; - map::iterator it; bool abort; }; diff --git a/reversecommand.cpp b/reversecommand.cpp index b8ccc07..9e2a08b 100644 --- a/reversecommand.cpp +++ b/reversecommand.cpp @@ -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 myArray (Array, Array+(sizeof(Array)/sizeof(string))); - parser = new OptionParser(); - parser->parse(option, parameters); delete parser; + OptionParser parser(option); + map 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::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) { diff --git a/reversecommand.h b/reversecommand.h index 2a996e9..b47ee3a 100644 --- a/reversecommand.h +++ b/reversecommand.h @@ -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 parameters; - map::iterator it; + bool abort; string fasta; - }; diff --git a/screenseqscommand.cpp b/screenseqscommand.cpp index 31b6bb7..5789fd0 100644 --- a/screenseqscommand.cpp +++ b/screenseqscommand.cpp @@ -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 myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); - parser = new OptionParser(); - parser->parse(option, parameters); delete parser; + OptionParser parser(option); + map 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::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 badSeqNames){ ifstream inputNames; - openInputFile(globaldata->getNameFile(), inputNames); + openInputFile(namefile, inputNames); set badSeqGroups; string seqName, seqList, group; set::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 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 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 badSeqNames){ void ScreenSeqsCommand::screenGroupFile(set badSeqNames){ ifstream inputGroups; - openInputFile(globaldata->getGroupFile(), inputGroups); + openInputFile(groupfile, inputGroups); string seqName, group; set::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); diff --git a/screenseqscommand.h b/screenseqscommand.h index 97b3615..eab66ee 100644 --- a/screenseqscommand.h +++ b/screenseqscommand.h @@ -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); void screenGroupFile(set); - GlobalData* globaldata; - OptionParser* parser; - map parameters; - map::iterator it; bool abort; string fastafile, namefile, groupfile; int startPos, endPos, maxAmbig, maxHomoP, minLength, maxLength; diff --git a/seqsummarycommand.cpp b/seqsummarycommand.cpp index c8582b9..24ef1d1 100644 --- a/seqsummarycommand.cpp +++ b/seqsummarycommand.cpp @@ -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 myArray (Array, Array+(sizeof(Array)/sizeof(string))); - parser = new OptionParser(); - parser->parse(option, parameters); delete parser; + OptionParser parser(option); + map 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::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) { diff --git a/seqsummarycommand.h b/seqsummarycommand.h index 03ec3e0..6d48284 100644 --- a/seqsummarycommand.h +++ b/seqsummarycommand.h @@ -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 parameters; - map::iterator it; bool abort; string fastafile; - }; #endif diff --git a/sequence.cpp b/sequence.cpp index 6a15eb5..580f68a 100644 --- a/sequence.cpp +++ b/sequence.cpp @@ -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; diff --git a/sequencedb.cpp b/sequencedb.cpp index e0bd100..bc8523a 100644 --- a/sequencedb.cpp +++ b/sequencedb.cpp @@ -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); } diff --git a/sequencedb.h b/sequencedb.h index 88b31e2..8c7e649 100644 --- a/sequencedb.h +++ b/sequencedb.h @@ -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 data; + vector data; string readName(ifstream&); string readSequence(ifstream&); diff --git a/shen.cpp b/shen.cpp index 612a253..152a138 100644 --- 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 59d6c3a..fa8b700 100644 --- 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; }; diff --git a/summarycommand.cpp b/summarycommand.cpp index 009c278..fa6d11a 100644 --- a/summarycommand.cpp +++ b/summarycommand.cpp @@ -48,14 +48,14 @@ SummaryCommand::SummaryCommand(string option){ string Array[] = {"line","label","calc","abund","size"}; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - parser = new OptionParser(); - parser->parse(option, parameters); delete parser; + OptionParser parser(option); + map 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::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(); diff --git a/summarycommand.h b/summarycommand.h index 895f9d7..b12f76f 100644 --- a/summarycommand.h +++ b/summarycommand.h @@ -48,9 +48,7 @@ private: string outputFileName; ofstream outputFileHandle; int abund, size; - OptionParser* parser; - map parameters; - map::iterator it; + bool abort, allLines; set lines; //hold lines to be used set labels; //holds labels to be used diff --git a/summarysharedcommand.cpp b/summarysharedcommand.cpp index 363506c..a32b202 100644 --- a/summarysharedcommand.cpp +++ b/summarysharedcommand.cpp @@ -52,14 +52,14 @@ SummarySharedCommand::SummarySharedCommand(string option){ string Array[] = {"line","label","calc","groups"}; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - parser = new OptionParser(); - parser->parse(option, parameters); delete parser; + OptionParser parser(option); + map 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::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 b6d5ea8..a525955 100644 --- 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 { diff --git a/treegroupscommand.cpp b/treegroupscommand.cpp index 7c78a34..484b553 100644 --- a/treegroupscommand.cpp +++ b/treegroupscommand.cpp @@ -40,33 +40,33 @@ TreeGroupCommand::TreeGroupCommand(string option){ string Array[] = {"line","label","calc","groups", "phylip", "column", "name", "precision","cutoff"}; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - parser = new OptionParser(); - parser->parse(option, parameters); delete parser; + OptionParser parser(option); + map 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::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(); diff --git a/treegroupscommand.h b/treegroupscommand.h index 76124f5..1e1f284 100644 --- a/treegroupscommand.h +++ b/treegroupscommand.h @@ -64,9 +64,7 @@ private: int numGroups; ofstream out; float precision, cutoff; - OptionParser* parser; - map parameters; - map::iterator it; + bool abort, allLines; set lines; //hold lines to be used set labels; //holds labels to be used diff --git a/trimseqscommand.cpp b/trimseqscommand.cpp index 77da3a6..132cc6b 100644 --- a/trimseqscommand.cpp +++ b/trimseqscommand.cpp @@ -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 myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); - parser = new OptionParser(); - parser->parse(option, parameters); delete parser; + OptionParser parser(option); + map 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::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 groupFileNames; + vector 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;iclose(); + 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& outFASTAVec, vector& 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> 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::iterator it=barcodes.begin();it!=barcodes.end();it++){ + + for(map::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> 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> score; + + if(score <= qThreshold){ + end = i; + break; + } + } + for(int i=end+1;i> 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> score; + average += score; + } + average /= seqLength; + + if(average >= qAverage) { success = 1; } + else { success = 0; } + + return success; +} + +//*************************************************************************************************************** + + diff --git a/trimseqscommand.h b/trimseqscommand.h index 03ee1f5..ee79d77 100644 --- a/trimseqscommand.h +++ b/trimseqscommand.h @@ -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&, vector&); + 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 parameters; - map::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 forPrimer, revPrimer; - map barcodes; + map barcodes; + vector groupVector; }; #endif diff --git a/unifracunweightedcommand.cpp b/unifracunweightedcommand.cpp index bc8eb47..154c528 100644 --- a/unifracunweightedcommand.cpp +++ b/unifracunweightedcommand.cpp @@ -24,14 +24,14 @@ UnifracUnweightedCommand::UnifracUnweightedCommand(string option) { string Array[] = {"groups","iters"}; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - parser = new OptionParser(); - parser->parse(option, parameters); delete parser; + OptionParser parser(option); + map 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::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::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::iterator it = validScores.begin(); it != validScores.end(); it++) { //make rscoreFreq map and rCumul - it2 = rscoreFreq[a].find(it->first); + map::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::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(); diff --git a/unifracunweightedcommand.h b/unifracunweightedcommand.h index 3c031c6..7707df4 100644 --- a/unifracunweightedcommand.h +++ b/unifracunweightedcommand.h @@ -44,12 +44,7 @@ class UnifracUnweightedCommand : public Command { map validScores; //map contains scores from random vector< map > rscoreFreq; //map -vector entry for each combination. vector< map > rCumul; //map -vector entry for each combination. - map::iterator it2; - map::iterator it; - OptionParser* parser; - map parameters; - map::iterator it4; bool abort; string groups, itersString; vector Groups; //holds groups to be used diff --git a/unifracweightedcommand.cpp b/unifracweightedcommand.cpp index a7a41f3..cf54e64 100644 --- a/unifracweightedcommand.cpp +++ b/unifracweightedcommand.cpp @@ -24,14 +24,14 @@ UnifracWeightedCommand::UnifracWeightedCommand(string option) { string Array[] = {"groups","iters"}; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - parser = new OptionParser(); - parser->parse(option, parameters); delete parser; + OptionParser parser(option); + map 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::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::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::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::iterator it = validScores.begin(); it != validScores.end(); it++) { //make rscoreFreq map and rCumul - it2 = rScoreFreq[a].find(it->first); + map::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; } diff --git a/unifracweightedcommand.h b/unifracweightedcommand.h index 2d78d57..9ea78ba 100644 --- a/unifracweightedcommand.h +++ b/unifracweightedcommand.h @@ -48,19 +48,13 @@ class UnifracWeightedCommand : public Command { vector< map > rScoreFreq; //map -vector entry for each combination. vector< map > rCumul; //map -vector entry for each c map validScores; //map contains scores from random - map::iterator it2; - map::iterator it; - OptionParser* parser; - map parameters; - map::iterator it4; bool abort; string groups, itersString; vector Groups; //holds groups to be used - ofstream outSum, out; - ifstream inFile; + ofstream outSum; void printWSummaryFile(); void printWeightedFile(); diff --git a/venn.cpp b/venn.cpp index 6402adf..921c125 100644 --- 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 8a789c3..8902cf4 100644 --- a/venn.h +++ b/venn.h @@ -19,22 +19,20 @@ /***********************************************************************/ class Venn { - - public: - Venn(); - ~Venn(){}; - - void getPic(SAbundVector*, vector); - void getPic(vector, vector); - - private: - GlobalData* globaldata; - Calculator* singleCalc; - string format, groupComb; - ofstream outsvg; - - +public: + Venn(); + ~Venn(){}; + + void getPic(SAbundVector*, vector); + void getPic(vector, vector); + +private: + GlobalData* globaldata; + Calculator* singleCalc; + string groupComb; + ofstream outsvg; }; + /***********************************************************************/ #endif diff --git a/venncommand.cpp b/venncommand.cpp index 0bed752..70c136b 100644 --- a/venncommand.cpp +++ b/venncommand.cpp @@ -35,14 +35,14 @@ VennCommand::VennCommand(string option){ string AlignArray[] = {"groups","line","label","calc", "abund"}; vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); - parser = new OptionParser(); - parser->parse(option, parameters); delete parser; + OptionParser parser(option); + map 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::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(); diff --git a/venncommand.h b/venncommand.h index 3671350..0b89143 100644 --- a/venncommand.h +++ b/venncommand.h @@ -40,9 +40,6 @@ private: SAbundVector* sabund; int abund; - OptionParser* parser; - map parameters; - map::iterator it; bool abort, allLines; set lines; //hold lines to be used set labels; //holds labels to be used