7E412F490F8D21B600381DD0 /* slibshuff.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7E412F480F8D21B600381DD0 /* slibshuff.cpp */; };
7E412FEA0F8D3E2C00381DD0 /* libshuff.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7E412FE90F8D3E2C00381DD0 /* libshuff.cpp */; };
7E4130F80F8E58FA00381DD0 /* dlibshuff.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7E4130F60F8E58FA00381DD0 /* dlibshuff.cpp */; };
+ 7E5A17AF0FE57292003C6A03 /* mergefilecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7E5A17AE0FE57292003C6A03 /* mergefilecommand.cpp */; };
7EC3D4550FA0FFF900338DA5 /* coverage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7EC3D4500FA0FFF900338DA5 /* coverage.cpp */; };
7EC3D4560FA0FFF900338DA5 /* whittaker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7EC3D4530FA0FFF900338DA5 /* whittaker.cpp */; };
8DD76F6A0486A84900D96B5E /* Mothur.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = C6859E8B029090EE04C91782 /* Mothur.1 */; };
7E412FE90F8D3E2C00381DD0 /* libshuff.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = libshuff.cpp; sourceTree = SOURCE_ROOT; };
7E4130F60F8E58FA00381DD0 /* dlibshuff.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = dlibshuff.cpp; sourceTree = SOURCE_ROOT; };
7E4130F70F8E58FA00381DD0 /* dlibshuff.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = dlibshuff.h; sourceTree = SOURCE_ROOT; };
+ 7E5A17AD0FE57292003C6A03 /* mergefilecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mergefilecommand.h; sourceTree = "<group>"; };
+ 7E5A17AE0FE57292003C6A03 /* mergefilecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = mergefilecommand.cpp; sourceTree = "<group>"; };
7EC3D4500FA0FFF900338DA5 /* coverage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = coverage.cpp; sourceTree = SOURCE_ROOT; };
7EC3D4510FA0FFF900338DA5 /* coverage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = coverage.h; sourceTree = SOURCE_ROOT; };
7EC3D4520FA0FFF900338DA5 /* sharedanderberg.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedanderberg.h; sourceTree = SOURCE_ROOT; };
37D928A90F2133E5001D4494 /* commands */ = {
isa = PBXGroup;
children = (
+ 7E5A17AE0FE57292003C6A03 /* mergefilecommand.cpp */,
+ 7E5A17AD0FE57292003C6A03 /* mergefilecommand.h */,
37D927CD0F21331F001D4494 /* command.hpp */,
378DC5CD0FBDE1C8003B8607 /* aligncommand.h */,
378DC5CE0FBDE1C8003B8607 /* aligncommand.cpp */,
378598660FDD497000EF9D03 /* heatmapsimcommand.cpp in Sources */,
378598740FDD4C1500EF9D03 /* heatmapsim.cpp in Sources */,
378599100FDD7E8E00EF9D03 /* optionparser.cpp in Sources */,
+ 7E5A17AF0FE57292003C6A03 /* mergefilecommand.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
* allows for a global alignment and not the local alignment provided by bLAst. Furthermore, it has the potential to
* provide a better alignment because of the banding method employed by blast (I'm not sure about this).
*
- * to compile type:
- * make
- *
- * for basic instructions on how to run nastPlus type:
- * ./nastPlus
*/
#include "aligncommand.h"
#include "sequence.hpp"
-#include "alignment.hpp"
#include "gotohoverlap.hpp"
#include "needlemanoverlap.hpp"
#include "blastalign.hpp"
#include "noalign.hpp"
-#include "database.hpp"
#include "kmerdb.hpp"
#include "suffixdb.hpp"
#include "blastdb.hpp"
//**********************************************************************************************************************
+
AlignCommand::AlignCommand(string option){
try {
- globaldata = GlobalData::getInstance();
+// globaldata = GlobalData::getInstance();
abort = false;
//allow user to run help
if(option == "help") { help(); abort = true; }
else {
+
//valid paramters for this command
- string AlignArray[] = {"fasta","candidate","search","ksize","align","match","mismatch","gapopen","gapextend"};
+ string AlignArray[] = {"template","candidate","search","ksize","align","match","mismatch","gapopen","gapextend", "processors"};
vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
- parser = new OptionParser();
-
- parser->parse(option, parameters); delete parser;
+ OptionParser parser(option);
+ map<string, string> parameters = parser.getParameters();
- ValidParameters* validParameter = new ValidParameters();
+ ValidParameters validParameter;
//check to make sure all parameters are valid for command
- for (it = parameters.begin(); it != parameters.end(); it++) {
- if (validParameter->isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
+ for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
//check for required parameters
- templateFileName = validParameter->validFile(parameters, "fasta", true);
- if (templateFileName == "not found") { cout << "fasta is a required parameter for the align.seqs command." << endl; abort = true; }
+ templateFileName = validParameter.validFile(parameters, "template", true);
+ if (templateFileName == "not found") { cout << "template is a required parameter for the align.seqs command." << endl; abort = true; }
else if (templateFileName == "not open") { abort = true; }
- else { globaldata->setFastaFile(templateFileName); }
- candidateFileName = validParameter->validFile(parameters, "candidate", true);
+ candidateFileName = validParameter.validFile(parameters, "candidate", true);
if (candidateFileName == "not found") { cout << "candidate is a required parameter for the align.seqs command." << endl; abort = true; }
else if (candidateFileName == "not open") { abort = true; }
- else {
- globaldata->setCandidateFile(candidateFileName);
- openInputFile(candidateFileName, in);
- }
-
//check for optional parameter and set defaults
// ...at some point should added some additional type checking...
string temp;
- temp = validParameter->validFile(parameters, "ksize", false); if (temp == "not found") { temp = "8"; }
+ temp = validParameter.validFile(parameters, "ksize", false); if (temp == "not found"){ temp = "8"; }
convert(temp, kmerSize);
- temp = validParameter->validFile(parameters, "match", false); if (temp == "not found") { temp = "1.0"; }
+ temp = validParameter.validFile(parameters, "match", false); if (temp == "not found"){ temp = "1.0"; }
convert(temp, match);
- temp = validParameter->validFile(parameters, "mismatch", false); if (temp == "not found") { temp = "-1.0"; }
+ temp = validParameter.validFile(parameters, "mismatch", false); if (temp == "not found"){ temp = "-1.0"; }
convert(temp, misMatch);
- temp = validParameter->validFile(parameters, "gapopen", false); if (temp == "not found") { temp = "-1.0"; }
+ temp = validParameter.validFile(parameters, "gapopen", false); if (temp == "not found"){ temp = "-1.0"; }
convert(temp, gapOpen);
- temp = validParameter->validFile(parameters, "gapextend", false); if (temp == "not found") { temp = "-2.0"; }
+ temp = validParameter.validFile(parameters, "gapextend", false); if (temp == "not found"){ temp = "-2.0"; }
convert(temp, gapExtend);
- search = validParameter->validFile(parameters, "search", false); if (search == "not found") { search = "kmer"; }
- align = validParameter->validFile(parameters, "align", false); if (align == "not found") { align = "needleman"; }
+ temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = "1"; }
+ convert(temp, processors);
+
+ search = validParameter.validFile(parameters, "search", false); if (search == "not found"){ search = "kmer"; }
- delete validParameter;
+ align = validParameter.validFile(parameters, "align", false); if (align == "not found"){ align = "needleman"; }
}
}
//**********************************************************************************************************************
-AlignCommand::~AlignCommand(){
-
+AlignCommand::~AlignCommand(){
+ delete templateDB;
+ delete alignment;
}
+
//**********************************************************************************************************************
void AlignCommand::help(){
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); }
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); }
cout << align << " is not a valid alignment option. I will run the command using needleman." << endl;
alignment = new NeedlemanOverlap(gapOpen, match, misMatch, 3000);
}
-
- int numFastaSeqs=count(istreambuf_iterator<char>(in),istreambuf_iterator<char>(), '>');
- in.seekg(0);
-
- string candidateAligngmentFName = candidateFileName.substr(0,candidateFileName.find_last_of(".")+1) + "align";
- ofstream candidateAlignmentFile;
- openOutputFile(candidateAligngmentFName, candidateAlignmentFile);
+
+ string alignFileName = candidateFileName.substr(0,candidateFileName.find_last_of(".")+1) + "align";
+ string reportFileName = candidateFileName.substr(0,candidateFileName.find_last_of(".")+1) + "align.report";
+
+ int numFastaSeqs = 0;
+ int start = time(NULL);
+
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+ if(processors == 1){
+ ifstream inFASTA;
+ openInputFile(candidateFileName, inFASTA);
+ numFastaSeqs=count(istreambuf_iterator<char>(inFASTA),istreambuf_iterator<char>(), '>');
+ inFASTA.close();
+
+ lines.push_back(new linePair(0, numFastaSeqs));
+
+ driver(lines[0], alignFileName, reportFileName);
+ }
+ else{
+ vector<int> positions;
+
+ ifstream inFASTA;
+ openInputFile(candidateFileName, inFASTA);
- string candidateReportFName = candidateFileName.substr(0,candidateFileName.find_last_of(".")+1) + "align.report";
- NastReport report(candidateReportFName);
+ while(!inFASTA.eof()){
+ char c = inFASTA.get();
+ if(c == '>'){ positions.push_back(inFASTA.tellg()); }
+ while (!inFASTA.eof()) { c = inFASTA.get(); if (c == 10 || c == 13){ break; } } // get rest of line if there's any crap there
+ }
+ inFASTA.close();
+
+ numFastaSeqs = positions.size();
+
+ int numSeqsPerProcessor = numFastaSeqs / processors;
+
+ for (int i = 0; i < processors; i++) {
+ int startPos = positions[ i * numSeqsPerProcessor ];
+ if(i == processors - 1){
+ numSeqsPerProcessor = numFastaSeqs - i * numSeqsPerProcessor;
+ }
+ lines.push_back(new linePair(startPos, numSeqsPerProcessor));
+ }
+ createProcesses(alignFileName, reportFileName);
- cout << "We are going to align the " << numFastaSeqs << " sequences in " << candidateFileName << "..." << endl;
- cout.flush();
-
- int start = time(NULL);
+
+ //append and remove temp files
+ map<int, int>::iterator it = processIDS.begin();
+ rename((alignFileName + toString(it->second) + ".temp").c_str(), alignFileName.c_str());
+ rename((reportFileName + toString(it->second) + ".temp").c_str(), alignFileName.c_str());
+ it++;
+
+ for (; it != processIDS.end(); it++) {
+ appendAlignFiles((alignFileName + toString(it->second) + ".temp"), alignFileName);
+ remove((alignFileName + toString(it->second) + ".temp").c_str());
- for(int i=0;i<numFastaSeqs;i++){
+ appendReportFiles((reportFileName + toString(it->second) + ".temp"), reportFileName);
+ remove((reportFileName + toString(it->second) + ".temp").c_str());
+ }
+ }
+#else
+ ifstream inFASTA;
+ openInputFile(candidateFileName, inFASTA);
+ numFastaSeqs=count(istreambuf_iterator<char>(inFASTA),istreambuf_iterator<char>(), '>');
+ inFASTA.close();
+
+ lines.push_back(new linePair(0, numFastaSeqs));
+
+ driver(lines[0], alignFileName, reportFileName);
+#endif
- Sequence* candidateSeq = new Sequence(in);
- report.setCandidate(candidateSeq);
+ cout << "It took " << time(NULL) - start << " secs to align " << numFastaSeqs << " sequences" << endl;
+ cout << endl;
+
+
+
+ return 0;
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the AlignCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the AlignCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+
+int AlignCommand::driver(linePair* line, string alignFName, string reportFName){
+ try {
+ ofstream alignmentFile;
+ openOutputFile(alignFName, alignmentFile);
+ NastReport report(reportFName);
+
+ ifstream inFASTA;
+ openInputFile(candidateFileName, inFASTA);
+ inFASTA.seekg(line->start);
+
+ for(int i=0;i<line->numSeqs;i++){
+
+ Sequence* candidateSeq = new Sequence(inFASTA);
+ report.setCandidate(candidateSeq);
+
Sequence* templateSeq = templateDB->findClosestSequence(candidateSeq);
report.setTemplate(templateSeq);
report.setSearchParameters(search, templateDB->getSearchScore());
-
Nast nast(alignment, candidateSeq, templateSeq);
report.setAlignmentParameters(align, alignment);
report.setNastParameters(nast);
+
+ alignmentFile << '>' << candidateSeq->getName() << '\n' << candidateSeq->getAligned() << endl;
+
+ report.print();
+
+ delete candidateSeq;
+ }
+
+ return 1;
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the AlignCommand class Function driver. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the AlignCommand class function driver. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
- candidateAlignmentFile << '>' << candidateSeq->getName() << '\n' << candidateSeq->getAligned() << endl;
- candidateAlignmentFile.flush();
+/**************************************************************************************************/
- if((i+1) % 100 == 0){
- cout << "It has taken " << time(NULL) - start << " secs to align " << i+1 << " sequences" << endl;
- }
- report.print();
+void AlignCommand::createProcesses(string alignFileName, string reportFileName) {
+ try {
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+ int process = 0;
+ processIDS.clear();
- delete candidateSeq;
+ //loop through and create all the processes you want
+ while (process != processors) {
+ int pid = fork();
+
+ if (pid > 0) {
+ processIDS[lines[process]->numSeqs] = pid; //create map from line number to pid so you can append files in correct order later
+ process++;
+ }else if (pid == 0){
+ driver(lines[process], alignFileName + toString(getpid()) + ".temp", reportFileName + toString(getpid()) + ".temp");
+ exit(0);
+ }else { cout << "unable to spawn the necessary processes." << endl; exit(0); }
}
- cout << "It took " << time(NULL) - start << " secs to align " << numFastaSeqs << " sequences" << endl;
- cout << endl;
+ //force parent to wait until all the processes are done
+ for (map<int, int>::iterator it = processIDS.begin(); it != processIDS.end(); it++) {
+ int temp = it->second;
+ wait(&temp);
+ }
+#endif
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the AlignCommand class Function createProcesses. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the AlignCommand class function createProcesses. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
- delete templateDB;
- delete alignment;
+/**************************************************************************************************/
-
- return 0;
+void AlignCommand::appendAlignFiles(string temp, string filename) {
+ try{
+
+ //open output file in append mode
+ ofstream output;
+ openOutputFileAppend(filename, output);
+
+ //open temp file for reading
+ ifstream input;
+ openInputFile(temp, input);
+
+ string line;
+ //read input file and write to output file
+ while(input.eof() != true) {
+ getline(input, line); //getline removes the newline char
+ if (line != "") {
+ output << line << endl; // Appending back newline char
+ }
+ }
+
+ input.close();
+ output.close();
}
catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the AlignCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ cout << "Standard Error: " << e.what() << " has occurred in the DistanceCommand class Function appendFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
exit(1);
}
catch(...) {
- cout << "An unknown error has occurred in the AlignCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ cout << "An unknown error has occurred in the DistanceCommand class function appendFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
+
+/**************************************************************************************************/
+
+void AlignCommand::appendReportFiles(string temp, string filename) {
+ try{
+
+ //open output file in append mode
+ ofstream output;
+ openOutputFileAppend(filename, output);
+
+ //open temp file for reading
+ ifstream input;
+ openInputFile(temp, input);
+ while (!input.eof()) { char c = input.get(); if (c == 10 || c == 13){ break; } } // get header line
+
+ string line;
+ //read input file and write to output file
+ while(input.eof() != true) {
+ getline(input, line); //getline removes the newline char
+ if (line != "") {
+ output << line << endl; // Appending back newline char
+ }
+ }
+
+ input.close();
+ output.close();
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the DistanceCommand class Function appendFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the DistanceCommand class function appendFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
exit(1);
}
}
-//**********************************************************************************************************************
\ No newline at end of file
+//**********************************************************************************************************************
*
*/
+#include "mothur.h"
#include "command.hpp"
-#include "globaldata.hpp"
-
-
+#include "database.hpp"
+#include "alignment.hpp"
class AlignCommand : public Command {
void help();
private:
- GlobalData* globaldata;
- OptionParser* parser;
- map<string, string> parameters;
- map<string, string>::iterator it;
- bool abort;
+ struct linePair {
+ int start;
+ int numSeqs;
+ linePair(int i, int j) : start(i), numSeqs(j) {}
+ };
+ map<int, int> processIDS; //end line, processid
+ vector<linePair*> lines;
+
+ Database* templateDB;
+ Alignment* alignment;
+
+ int driver(linePair*, string, string);
+ void createProcesses(string, string);
+ void appendAlignFiles(string, string);
+ void appendReportFiles(string, string);
+
string candidateFileName, templateFileName, distanceFileName, search, align;
- int kmerSize;
float match, misMatch, gapOpen, gapExtend;
- ofstream out;
- ifstream in;
- int ableToOpen;
-
+ int processors, kmerSize;
+ bool abort;
};
-
-
-#endif
\ No newline at end of file
+#endif
string AlignArray[] = {"fasta","line","label","name", "group"};
vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
- parser = new OptionParser();
- parser->parse(option, parameters); delete parser;
+ OptionParser parser(option);
+ map<string, string> parameters = parser.getParameters();
- ValidParameters* validParameter = new ValidParameters();
+ ValidParameters validParameter;
//check to make sure all parameters are valid for command
- for (it = parameters.begin(); it != parameters.end(); it++) {
- if (validParameter->isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
+ for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
//make sure the user has already run the read.otu command
//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();
}
//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; }
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 {
groupMap->readMap();
}
- delete validParameter;
}
}
catch(exception& e) {
int BinSeqCommand::execute(){
try {
-
if (abort == true) { return 0; }
int count = 1;
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 != "") {
InputData* input;
FastaMap* fasta;
GroupMap* groupMap;
- OptionParser* parser;
- map<string, string> parameters;
- map<string, string>::iterator it;
bool abort, allLines;
set<int> lines; //hold lines to be used
set<string> labels; //holds labels to be used
string Array[] = {"line","label","calc","groups","iters"};
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
- parser = new OptionParser();
- parser->parse(option, parameters); delete parser;
+ OptionParser parser(option);
+ map<string,string> parameters = parser.getParameters();
- ValidParameters* validParameter = new ValidParameters();
+ ValidParameters validParameter;
//check to make sure all parameters are valid for command
- for (it = parameters.begin(); it != parameters.end(); it++) {
- if (validParameter->isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
+ for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
//make sure the user has already run the read.otu command
//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; }
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);
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();
ValidCalculators* validCalculator;
SharedOrderVector* order;
vector<SharedRAbundVector*> lookup;
- OptionParser* parser;
- map<string, string> parameters;
- map<string, string>::iterator it;
+
bool abort, allLines;
set<int> lines; //hold lines to be used
set<string> labels; //holds labels to be used
string Array[] = {"cutoff","precision","method"};
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
- parser = new OptionParser();
- parser->parse(option, parameters); delete parser;
+ OptionParser parser(option);
+ map<string,string> parameters = parser.getParameters();
- ValidParameters* validParameter = new ValidParameters();
+ ValidParameters validParameter;
//check to make sure all parameters are valid for command
- for (it = parameters.begin(); it != parameters.end(); it++) {
- if (validParameter->isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
+ for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
//error checking to make sure they read a distance file
// ...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; }
RAbundVector* rabund;
RAbundVector oldRAbund;
ListVector oldList;
- OptionParser* parser;
- map<string, string> parameters;
- map<string, string>::iterator it;
+
bool abort;
string method, fileroot, tag;
string Array[] = {"freq","line","label","calc","abund","size"};
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
- parser = new OptionParser();
- parser->parse(option, parameters); delete parser;
+ OptionParser parser(option);
+ map<string,string> parameters = parser.getParameters();
- ValidParameters* validParameter = new ValidParameters();
+ ValidParameters validParameter;
//check to make sure all parameters are valid for command
- for (it = parameters.begin(); it != parameters.end(); it++) {
- if (validParameter->isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
+ for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
//make sure the user has already run the read.otu command
//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; }
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"; }
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;
ValidCalculators* validCalculator;
vector<Display*> cDisplays;
int freq, abund, size;
- OptionParser* parser;
- map<string, string> parameters;
- map<string, string>::iterator it;
+
bool abort, allLines;
set<int> lines; //hold lines to be used
set<string> labels; //holds labels to be used
string Array[] = {"freq","line","label","calc","groups"};
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
- parser = new OptionParser();
- parser->parse(option, parameters); delete parser;
+ OptionParser parser(option);
+ map<string,string> parameters=parser.getParameters();
- ValidParameters* validParameter = new ValidParameters();
+ ValidParameters validParameter;
//check to make sure all parameters are valid for command
- for (it = parameters.begin(); it != parameters.end(); it++) {
- if (validParameter->isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
+ for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
//make sure the user has already run the read.otu command
//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; }
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);
}
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();
vector<Display*> cDisplays;
int freq;
string format;
- OptionParser* parser;
- map<string, string> parameters;
- map<string, string>::iterator it;
+
bool abort, allLines;
set<int> lines; //hold lines to be used
set<string> labels; //holds labels to be used
*
*/
-/*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"
#include "heatmapcommand.h"
#include "heatmapsimcommand.h"
#include "filterseqscommand.h"
-#include "mothur.h"
#include "venncommand.h"
#include "nocommands.h"
#include "binsequencecommand.h"
#include "screenseqscommand.h"
#include "reversecommand.h"
#include "trimseqscommand.h"
+#include "mergefilecommand.h"
/***********************************************************/
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;
/**************************************************************************************/
DeconvoluteCommand::DeconvoluteCommand(string option) {
try {
- globaldata = GlobalData::getInstance();
abort = false;
//allow user to run help
string Array[] = {"fasta"};
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
- parser = new OptionParser();
- parser->parse(option, parameters); delete parser;
+ OptionParser parser(option);
+ map<string,string> parameters = parser.getParameters();
- ValidParameters* validParameter = new ValidParameters();
+ ValidParameters validParameter;
//check to make sure all parameters are valid for command
- for (it = parameters.begin(); it != parameters.end(); it++) {
- if (validParameter->isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
+ for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
//check for required parameters
- filename = validParameter->validFile(parameters, "fasta", true);
+ filename = validParameter.validFile(parameters, "fasta", true);
if (filename == "not open") { abort = true; }
else if (filename == "not found") { filename = ""; cout << "fasta is a required parameter for the unique.seqs command." << endl; abort = true; }
- else { globaldata->setFastaFile(filename); globaldata->setFormat("fasta"); }
- delete validParameter;
}
}
#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. */
void help();
private:
- GlobalData* globaldata;
FastaMap* fastamap;
ifstream in;
ofstream out, outFasta;
string filename, outputFileName, outFastafile;
- OptionParser* parser;
- map<string, string> parameters;
- map<string, string>::iterator it;
- bool abort;
-
+ bool abort;
};
#endif
DistanceCommand::DistanceCommand(string option){
try {
- globaldata = GlobalData::getInstance();
abort = false;
Estimators.clear();
string Array[] = {"fasta", "phylip", "calc", "countends", "cutoff", "processors"};
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
- parser = new OptionParser();
- parser->parse(option, parameters); delete parser;
+ OptionParser parser(option);
+ map<string, string> parameters = parser.getParameters();
- ValidParameters* validParameter = new ValidParameters();
+ ValidParameters validParameter;
//check to make sure all parameters are valid for command
- for (it2 = parameters.begin(); it2 != parameters.end(); it2++) {
- if (validParameter->isValidParameter(it2->first, myArray, it2->second) != true) { abort = true; }
+ for (map<string, string>::iterator it2 = parameters.begin(); it2 != parameters.end(); it2++) {
+ if (validParameter.isValidParameter(it2->first, myArray, it2->second) != true) { abort = true; }
}
//check for required parameters
- fastafile = validParameter->validFile(parameters, "fasta", true);
+ fastafile = validParameter.validFile(parameters, "fasta", true);
if (fastafile == "not found") { cout << "fasta is a required parameter for the dist.seqs command." << endl; abort = true; }
else if (fastafile == "not open") { abort = true; }
- else {
- globaldata->setFastaFile(fastafile);
- openInputFile(fastafile, in);
+ else{
+ ifstream inFASTA;
+ openInputFile(fastafile, inFASTA);
+ alignDB = SequenceDB(inFASTA);
}
-
+
//check for optional parameter and set defaults
// ...at some point should added some additional type checking...
- calc = validParameter->validFile(parameters, "calc", false);
+ calc = validParameter.validFile(parameters, "calc", false);
if (calc == "not found") { calc = "onegap"; }
else {
if (calc == "default") { calc = "onegap"; }
splitAtDash(calc, Estimators);
string temp;
- temp = validParameter->validFile(parameters, "countends", false); if (temp == "not found") { temp = "T"; }
+ temp = validParameter.validFile(parameters, "countends", false); if(temp == "not found"){ temp = "T"; }
convert(temp, countends);
- temp = validParameter->validFile(parameters, "cutoff", false); if (temp == "not found") { temp = "1.0"; }
+ temp = validParameter.validFile(parameters, "cutoff", false); if(temp == "not found"){ temp = "1.0"; }
convert(temp, cutoff);
- temp = validParameter->validFile(parameters, "processors", false); if (temp == "not found") { temp = "1"; }
+ temp = validParameter.validFile(parameters, "processors", false); if(temp == "not found"){ temp = "1"; }
convert(temp, processors);
- phylip = validParameter->validFile(parameters, "phylip", false); if (phylip == "not found") { phylip = "F"; }
+ phylip = validParameter.validFile(parameters, "phylip", false); if(phylip == "not found"){ phylip = "F"; }
- delete validParameter;
- validCalculator = new ValidCalculators();
+ ValidCalculators validCalculator;
- int i;
if (isTrue(countends) == true) {
- for (i=0; i<Estimators.size(); i++) {
- if (validCalculator->isValidCalculator("distance", Estimators[i]) == true) {
- if (Estimators[i] == "nogaps") {
- distCalculator = new ignoreGaps();
- }else if (Estimators[i] == "eachgap") {
- distCalculator = new eachGapDist();
- }else if (Estimators[i] == "onegap") {
- distCalculator = new oneGapDist(); }
+ for (int i=0; i<Estimators.size(); i++) {
+ if (validCalculator.isValidCalculator("distance", Estimators[i]) == true) {
+ if (Estimators[i] == "nogaps") { distCalculator = new ignoreGaps(); }
+ else if (Estimators[i] == "eachgap") { distCalculator = new eachGapDist(); }
+ else if (Estimators[i] == "onegap") { distCalculator = new oneGapDist(); }
}
}
}else {
- for (i=0; i<Estimators.size(); i++) {
- if (validCalculator->isValidCalculator("distance", Estimators[i]) == true) {
- if (Estimators[i] == "nogaps") {
- distCalculator = new ignoreGaps();
- }else if (Estimators[i] == "eachgap") {
- distCalculator = new eachGapIgnoreTermGapDist();
- }else if (Estimators[i] == "onegap") {
- distCalculator = new oneGapIgnoreTermGapDist();
- }
+ for (int i=0; i<Estimators.size(); i++) {
+ if (validCalculator.isValidCalculator("distance", Estimators[i]) == true) {
+ if (Estimators[i] == "nogaps") { distCalculator = new ignoreGaps(); }
+ else if (Estimators[i] == "eachgap"){ distCalculator = new eachGapIgnoreTermGapDist(); }
+ else if (Estimators[i] == "onegap") { distCalculator = new oneGapIgnoreTermGapDist(); }
}
}
}
- delete validCalculator;
}
}
exit(1);
}
}
+
+//**********************************************************************************************************************
+
+DistanceCommand::~DistanceCommand(){
+
+ for(int i=0;i<lines.size();i++){
+ delete lines[i];
+ }
+
+}
+
//**********************************************************************************************************************
void DistanceCommand::help(){
if (abort == true) { return 0; }
- //reads fasta file and fills sequenceDB
- seqDB = new SequenceDB(in);
-
- int numSeqs = seqDB->getNumSeqs();
+ int numSeqs = alignDB.getNumSeqs();
cutoff += 0.005;
string outputFile;
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());
#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++) {
lines[i]->end = int (sqrt(float(i+1)/float(processors)) * numSeqs);
}
- cout << lines[0]->start << '\t' << lines[0]->end << endl;
- cout << lines[1]->start << '\t' << lines[1]->end << endl;
-
createProcesses(outputFile);
+ map<int, int>::iterator it = processIDS.begin();
+ rename((outputFile + toString(it->second) + ".temp").c_str(), outputFile.c_str());
+ it++;
+
//append and remove temp files
- for (it = processIDS.begin(); it != processIDS.end(); it++) {
+ for (; it != processIDS.end(); it++) {
appendFiles((outputFile + toString(it->second) + ".temp"), outputFile);
remove((outputFile + toString(it->second) + ".temp").c_str());
}
}
#else
- driver(distCalculator, seqDB, 0, numSeqs, outputFile + ".temp", cutoff);
- appendFiles((outputFile + ".temp"), outputFile);
- remove((outputFile + ".temp").c_str());
+ ifstream inFASTA
+ driver(0, numSeqs, outputFile, cutoff);
#endif
delete distCalculator;
/**************************************************************************************************/
void DistanceCommand::createProcesses(string filename) {
try {
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
int process = 0;
processIDS.clear();
processIDS[lines[process]->end] = pid; //create map from line number to pid so you can append files in correct order later
process++;
}else if (pid == 0){
- driver(distCalculator, seqDB, lines[process]->start, lines[process]->end, filename + toString(getpid()) + ".temp", cutoff);
+ driver(lines[process]->start, lines[process]->end, filename + toString(getpid()) + ".temp", cutoff);
exit(0);
}else { cout << "unable to spawn the necessary processes." << endl; exit(0); }
}
//force parent to wait until all the processes are done
- for (it = processIDS.begin(); it != processIDS.end(); it++) {
+ for (map<int, int>::iterator it = processIDS.begin(); it != processIDS.end(); it++) {
int temp = it->second;
wait(&temp);
}
-
+#endif
}
catch(exception& e) {
cout << "Standard Error: " << e.what() << " has occurred in the DistanceCommand class Function createProcesses. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
/**************************************************************************************************/
/////// 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);
outFile.setf(ios::fixed, ios::showpoint);
outFile << setprecision(4);
+ if(isTrue(phylip) && startLine == 0){ outFile << alignDB.getNumSeqs() << endl; }
for(int i=startLine;i<endLine;i++){
-
+ if(isTrue(phylip)) { outFile << alignDB.get(i).getName() << '\t'; }
for(int j=0;j<i;j++){
- distCalculator->calcDist(*(align->get(i)), *(align->get(j)));
+ distCalculator->calcDist(alignDB.get(i), alignDB.get(j));
double dist = distCalculator->getDist();
if(dist <= cutoff){
- if (isTrue(phylip) != true) { outFile << align->get(i)->getName() << ' ' << align->get(j)->getName() << ' ' << dist << endl; }
+ if (!isTrue(phylip)) { outFile << alignDB.get(i).getName() << ' ' << alignDB.get(j).getName() << ' ' << dist << endl; }
}
- if (isTrue(phylip) == true) { outFile << dist << '\t'; }
+ if (isTrue(phylip)) { outFile << dist << '\t'; }
}
}
cout << endLine-1 << '\t' << time(NULL) - startTime << endl;
- //philFile.close();
- //distFile.close();
+ outFile.close();
return 1;
}
#include "mothur.h"
#include "command.hpp"
-#include "globaldata.hpp"
#include "validcalculator.h"
#include "dist.h"
#include "sequencedb.h"
-struct linePair {
- int start;
- int end;
-};
class DistanceCommand : public Command {
public:
DistanceCommand(string);
- ~DistanceCommand() {};
+ ~DistanceCommand();
int execute();
void help();
private:
- GlobalData* globaldata;
- ValidCalculators* validCalculator;
+ struct linePair {
+ int start;
+ int end;
+ };
+
Dist* distCalculator;
- SequenceDB* seqDB;
- ofstream out, outFile;
- ifstream in;
+ SequenceDB alignDB;
+
string countends, phylip, fastafile, calc;
int processors;
float cutoff;
map<int, int> processIDS; //end line, processid
- map<int, int>::iterator it;
vector<linePair*> lines;
- OptionParser* parser;
- map<string, string> parameters;
- map<string, string>::iterator it2;
bool abort;
vector<string> Estimators; //holds estimators to be used
void appendFiles(string, string);
void createProcesses(string);
- int driver(Dist*, SequenceDB*, int, int, string, float);
+ int driver(/*Dist*, SequenceDB, */int, int, string, float);
};
#define FILEOUTPUT_H
#include "mothur.h"
-#include "globaldata.hpp"
/***********************************************************************/
virtual string getFileName() = 0;
protected:
- GlobalData* globaldata;
int renameOk;
};
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
*/
#include "filterseqscommand.h"
+#include "sequence.hpp"
/**************************************************************************************/
FilterSeqsCommand::FilterSeqsCommand(string option){
try {
- globaldata = GlobalData::getInstance();
abort = false;
//allow user to run help
string Array[] = {"fasta", "trump", "soft", "hard", "vertical"};
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
- parser = new OptionParser();
- parser->parse(option, parameters); delete parser;
+ OptionParser parser(option);
+ map<string,string> parameters = parser.getParameters();
+
+ ValidParameters validParameter;
- ValidParameters* validParameter = new ValidParameters();
-
//check to make sure all parameters are valid for command
- for (it = parameters.begin(); it != parameters.end(); it++) {
- if (validParameter->isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
+ for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
//check for required parameters
- fastafile = validParameter->validFile(parameters, "fasta", true);
+ fastafile = validParameter.validFile(parameters, "fasta", true);
if (fastafile == "not found") { cout << "fasta is a required parameter for the filter.seqs command." << endl; abort = true; }
else if (fastafile == "not open") { abort = true; }
- else {
- globaldata->setFastaFile(fastafile);
- }
-
+
//check for optional parameter and set defaults
// ...at some point should added some additional type checking...
string temp;
- temp = validParameter->validFile(parameters, "trump", false); if (temp == "not found") { temp = "."; }
+ temp = validParameter.validFile(parameters, "trump", false); if (temp == "not found") { temp = "*"; }
trump = temp[0];
- temp = validParameter->validFile(parameters, "soft", false); if (temp == "not found") { soft = 0; }
+ temp = validParameter.validFile(parameters, "soft", false); if (temp == "not found") { soft = 0; }
else { soft = (float)atoi(temp.c_str()) / 100.0; }
- hard = validParameter->validFile(parameters, "hard", true); if (hard == "not found") { hard = ""; }
+ hard = validParameter.validFile(parameters, "hard", true); if (hard == "not found") { hard = ""; }
else if (hard == "not open") { abort = true; }
- vertical = validParameter->validFile(parameters, "vertical", false); if (vertical == "not found") { vertical = "F"; }
-
- delete validParameter;
+ vertical = validParameter.validFile(parameters, "vertical", false); if (vertical == "not found") { vertical = "T"; }
numSeqs = 0;
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";
void FilterSeqsCommand::doTrump(Sequence seq) {
string curAligned = seq.getAligned();
-
+
for(int j = 0; j < alignmentLength; j++) {
if(curAligned[j] == trump){
filter[j] = '0';
void FilterSeqsCommand::doSoft() {
int threshold = int (soft * numSeqs);
- bool keep = 0;
for(int i=0;i<alignmentLength;i++){
- if(a[i] >= threshold) { keep = 1; }
- else if(t[i] >= threshold) { keep = 1; }
- else if(g[i] >= threshold) { keep = 1; }
- else if(c[i] >= threshold) { keep = 1; }
-
- if(keep == 0) { filter[i] = 0; }
+ if(a[i] < threshold && t[i] < threshold && g[i] < threshold && c[i] < threshold){ filter[i] = 0; }
}
}
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();
cout << "Length of the original alignment: " << alignmentLength << endl;
cout << "Number of sequences used to construct filter: " << numSeqs << endl;
- globaldata->clear();
-
return 0;
}
*/
#include "command.hpp"
-#include "globaldata.hpp"
-#include "sequence.hpp"
+class Sequence;
class FilterSeqsCommand : public Command {
public:
bool abort;
float soft;
int numSeqs;
- OptionParser* parser;
- map<string, string> parameters;
- map<string, string>::iterator it;
- GlobalData* globaldata;
vector<int> a, t, g, c, gap;
};
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;
private:
GlobalData* globaldata;
- string filename;
bool abort;
};
string Array[] = {"fasta","list","line","label","name", "group"};
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
- parser = new OptionParser();
- parser->parse(option, parameters); delete parser;
+ OptionParser parser(option);
+ map<string, string> parameters = parser.getParameters();
- ValidParameters* validParameter = new ValidParameters();
+ ValidParameters validParameter;
//check to make sure all parameters are valid for command
- for (it4 = parameters.begin(); it4 != parameters.end(); it4++) {
- if (validParameter->isValidParameter(it4->first, myArray, it4->second) != true) { abort = true; }
+ for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
//make sure the user has already run the read.otu command
}
//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; }
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 {
groupMap = new GroupMap(groupfile);
groupMap->readMap();
}
-
- delete validParameter;
-
+
if (abort == false) {
if(globaldata->gSparseMatrix != NULL) { matrix = new SparseMatrix(*globaldata->gSparseMatrix); }
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 != "") {
}
//output error messages about any remaining user labels
- set<string>::iterator it;
bool needToRun = false;
- for (it = userLabels.begin(); it != userLabels.end(); it++) {
+ for (set<string>::iterator it = userLabels.begin(); it != userLabels.end(); it++) {
cout << "Your file does not include the label "<< *it;
if (processedLabels.count(lastList->getLabel()) != 1) {
cout << ". I will use " << lastList->getLabel() << "." << endl;
try{
vector<string> names;
map<string, float> sums;
- map<string, float>::iterator it4;
map<int, string> binMap; //subset of namesToIndex - just member of this bin
string binnames;
float min = 10000;
else {
//fill binMap
for (int i = 0; i < names.size(); i++) {
- for (it3 = nameToIndex.begin(); it3 != nameToIndex.end(); it3++) {
+ for (map<string, int>::iterator it = nameToIndex.begin(); it != nameToIndex.end(); it++) {
- if (it3->first == names[i]) {
- binMap[it3->second] = it3->first;
+ if (it->first == names[i]) {
+ binMap[it->second] = it->first;
//initialize sums map
- sums[it3->first] = 0.0;
+ sums[it->first] = 0.0;
break;
}
}
//go through each cell in the sparsematrix
for(MatData currentCell = matrix->begin(); currentCell != matrix->end(); currentCell++){
//is this a distance between 2 members of this bin
- it = binMap.find(currentCell->row);
- it2 = binMap.find(currentCell->column);
+ map<int, string>::iterator it = binMap.find(currentCell->row);
+ map<int, string>::iterator it2 = binMap.find(currentCell->column);
//sum the distance of the sequences in the bin to eachother
if ((it != binMap.end()) && (it2 != binMap.end())) {
}
//smallest sum is the representative
- for (it4 = sums.begin(); it4 != sums.end(); it4++) {
+ for (map<string, float>::iterator it4 = sums.begin(); it4 != sums.end(); it4++) {
if (it4->second < min) {
min = it4->second;
minName = it4->first;
ofstream out;
ifstream in, inNames;
bool groupError;
- OptionParser* parser;
- map<string, string> parameters;
- map<string, string>::iterator it4;
+
bool abort, allLines;
set<int> lines; //hold lines to be used
set<string> labels; //holds labels to be used
map<string, int> nameToIndex; //maps sequence name to index in sparsematrix
- map<int, string>::iterator it;
- map<int, string>::iterator it2;
- map<string, int>::iterator it3;
void readNamesFile();
int process(ListVector*);
string Array[] = {"line","label"};
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
- parser = new OptionParser();
- parser->parse(option, parameters); delete parser;
+ OptionParser parser(option);
+ map<string,string> parameters = parser.getParameters();
+
+ ValidParameters validParameter;
- ValidParameters* validParameter = new ValidParameters();
-
//check to make sure all parameters are valid for command
- for (it = parameters.begin(); it != parameters.end(); it++) {
- if (validParameter->isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
+ for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
//make sure the user has already run the read.otu command
//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; }
lines = globaldata->lines;
}
- delete validParameter;
-
if (abort == false) {
filename = getRootName(globaldata->inputFileName) + "rabund";
openOutputFile(filename, out);
InputData* input;
ListVector* list;
RAbundVector* rabund;
- OptionParser* parser;
- map<string, string> parameters;
- map<string, string>::iterator it;
+
bool abort, allLines;
set<int> lines; //hold lines to be used
set<string> labels; //holds labels to be used
string Array[] = {"line","label"};
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
- parser = new OptionParser();
- parser->parse(option, parameters); delete parser;
+ OptionParser parser(option);
+ map<string,string> parameters = parser.getParameters();
+
+ ValidParameters validParameter;
- ValidParameters* validParameter = new ValidParameters();
-
//check to make sure all parameters are valid for command
- for (it = parameters.begin(); it != parameters.end(); it++) {
- if (validParameter->isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
+ for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
//make sure the user has already run the read.otu command
//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; }
lines = globaldata->lines;
}
- delete validParameter;
-
if (abort == false) {
filename = getRootName(globaldata->inputFileName) + "sabund";
openOutputFile(filename, out);
OrderVector* lastOrder;
InputData* input;
SAbundVector* sabund;
- OptionParser* parser;
- map<string, string> parameters;
- map<string, string>::iterator it;
+
bool abort, allLines;
set<int> lines; //hold lines to be used
set<string> labels; //holds labels to be used
+
+
#include "globaldata.hpp"
-#include "tree.h"
-#include "sparsematrix.hpp"
/*******************************************************/
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; }
/******************************************************/
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 = "";
}
+
+
/*******************************************************/
/******************************************************/
#include "rabundvector.hpp"
#include "sabundvector.hpp"
#include "listvector.hpp"
+#include "tree.h"
+#include "sparsematrix.hpp"
class ListVector;
class SharedListVector;
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();
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
HeatMap::HeatMap(string sort, string scale){
try {
globaldata = GlobalData::getInstance();
- format = globaldata->getFormat();
+// format = globaldata->getFormat();
sorted = sort;
scaler = scale;
}
string AlignArray[] = {"groups","line","label","sorted","scale"};
vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
- parser = new OptionParser();
- parser->parse(option, parameters); delete parser;
+ OptionParser parser(option);
+ map<string,string> parameters = parser.getParameters();
+
+ ValidParameters validParameter;
- ValidParameters* validParameter = new ValidParameters();
-
//check to make sure all parameters are valid for command
- for (it = parameters.begin(); it != parameters.end(); it++) {
- if (validParameter->isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
+ for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
//make sure the user has already run the read.otu command
//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; }
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);
RAbundVector* rabund;
vector<SharedRAbundVector*> lookup;
HeatMap* heatmap;
- OptionParser* parser;
- map<string, string> parameters;
- map<string, string>::iterator it;
+
bool abort, allLines;
set<int> lines; //hold lines to be used
set<string> labels; //holds labels to be used
string AlignArray[] = {"groups","line","label", "calc"};
vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
- parser = new OptionParser();
- parser->parse(option, parameters); delete parser;
+ OptionParser parser(option);
+ map<string,string> parameters = parser.getParameters();
+
+ ValidParameters validParameter;
- ValidParameters* validParameter = new ValidParameters();
-
//check to make sure all parameters are valid for command
- for (it = parameters.begin(); it != parameters.end(); it++) {
- if (validParameter->isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
+ for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
//make sure the user has already run the read.otu command
//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; }
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();
//**********************************************************************************************************************
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();
- }
+}
//**********************************************************************************************************************
/* This class is designed to aid the user in running mothur. */
#include "command.hpp"
-#include "globaldata.hpp"
#include "validcommands.h"
void help() {};
private:
- GlobalData* globaldata;
ValidCommands* validCommands;
private:
string Array[] = {"iters","groups","step","form","cutoff"};
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
- parser = new OptionParser();
- parser->parse(option, parameters); delete parser;
+ OptionParser parser(option);
+ map<string, string> parameters = parser.getParameters();
- ValidParameters* validParameter = new ValidParameters();
+ ValidParameters validParameter;
//check to make sure all parameters are valid for command
- for (it = parameters.begin(); it != parameters.end(); it++) {
- if (validParameter->isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
+ for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
//make sure the user has already run the read.dist command
//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;
}
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) {
class LibShuffCommand : public Command {
- public:
- LibShuffCommand(string);
- ~LibShuffCommand(){};
- int execute();
- void help();
+public:
+ LibShuffCommand(string);
+ ~LibShuffCommand(){};
+ int execute();
+ void help();
+
+private:
+ vector<string> groupNames;
- private:
- vector<string> groupNames;
-
- void setGroups();
- void printCoverageFile();
- void printSummaryFile();
-
- GlobalData* globaldata;
- FullMatrix* matrix;
- Libshuff* form;
- float cutOff, step;
- int numGroups, numComp, iters;
- string coverageFile, summaryFile;
- vector<vector<int> > pValueCounts;
- vector<vector<double> > savedDXYValues;
- vector<vector<vector<double> > > savedMinValues;
- OptionParser* parser;
- map<string, string> parameters;
- map<string, string>::iterator it;
- bool abort;
- string outputFile, groups, userform, savegroups;
- vector<string> Groups; //holds groups to be used
+ void setGroups();
+ void printCoverageFile();
+ void printSummaryFile();
+
+ GlobalData* globaldata;
+ FullMatrix* matrix;
+ Libshuff* form;
+ float cutOff, step;
+ int numGroups, numComp, iters;
+ string coverageFile, summaryFile;
+ vector<vector<int> > pValueCounts;
+ vector<vector<double> > savedDXYValues;
+ vector<vector<vector<double> > > savedMinValues;
+
+ bool abort;
+ string outputFile, groups, userform, savegroups;
+ vector<string> Groups; //holds groups to be used
};
#endif
string Array[] = {"line","label","calc","groups"};
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
- parser = new OptionParser();
- parser->parse(option, parameters); delete parser;
+ OptionParser parser(option);
+ map<string,string> parameters = parser.getParameters();
- ValidParameters* validParameter = new ValidParameters();
+ ValidParameters validParameter;
//check to make sure all parameters are valid for command
- for (it = parameters.begin(); it != parameters.end(); it++) {
- if (validParameter->isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
+ for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
//make sure the user has already run the read.otu command
//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; }
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();
string exportFileName;
int numGroups;
ofstream out;
- OptionParser* parser;
- map<string, string> parameters;
- map<string, string>::iterator it;
+
bool abort, allLines;
set<int> lines; //hold lines to be used
set<string> labels; //holds labels to be used
--- /dev/null
+/*
+ * mergefilecommand.cpp
+ * Mothur
+ *
+ * Created by Pat Schloss on 6/14/09.
+ * Copyright 2009 Patrick D. Schloss. All rights reserved.
+ *
+ */
+
+#include "mergefilecommand.h"
+
+//**********************************************************************************************************************
+
+MergeFileCommand::MergeFileCommand(string option){
+ try {
+ abort = false;
+
+ if(option == "help") {
+ help();
+ abort = true;
+ }
+ else {
+ //valid paramters for this command
+ string Array[] = {"input", "output"};
+ vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+
+ OptionParser parser(option);
+ map<string,string> parameters = parser.getParameters();
+
+ ValidParameters validParameter;
+
+ //check to make sure all parameters are valid for command
+ for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
+ }
+
+ string fileList = validParameter.validFile(parameters, "input", false);
+ if(fileList == "not found") { cout << "you must enter two or more file names" << endl; abort=true; }
+ else{ splitAtDash(fileList, fileNames); }
+
+ numInputFiles = fileNames.size();
+ ifstream testFile;
+ if(numInputFiles == 0){
+ cout << "you must enter two or more file names and you entered " << fileNames.size() << " file names" << endl;
+ abort=true;
+ }
+ else{
+ for(int i=0;i<numInputFiles;i++){
+ if(openInputFile(fileNames[i], testFile)){ abort = true; }
+ testFile.close();
+ }
+ }
+
+ outputFileName = validParameter.validFile(parameters, "output", false);
+ if (outputFileName == "not found") { cout << "you must enter an output file name" << endl; abort=true; }
+ }
+
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the MergeFileCommand class Function MergeFileCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the MergeFileCommand class function MergeFileCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
+
+//**********************************************************************************************************************
+
+MergeFileCommand::~MergeFileCommand() { /* do nothing */ }
+
+//**********************************************************************************************************************
+
+int MergeFileCommand::execute(){
+ try {
+ if (abort == true) { return 0; }
+
+ ofstream outputFile;
+ openOutputFile(outputFileName, outputFile);
+
+ ifstream inputFile;
+ char c;
+ for(int i=0;i<numInputFiles;i++){
+ openInputFile(fileNames[i], inputFile);
+
+ while(!inputFile.eof()){ c = inputFile.get(); outputFile << c; }
+
+ inputFile.close();
+ }
+ return 0;
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the BinSeqCommand class Function BinSeqCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the BinSeqCommand class function BinSeqCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+
+}
+
+//**********************************************************************************************************************
+
+void MergeFileCommand::help(){
+ try {
+ cout << "The merge.file command..." << endl;
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the MergeFileCommand class Function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the MergeFileCommand class function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+
+}
+
+//**********************************************************************************************************************
--- /dev/null
+#ifndef MERGEFILECOMMAND_H
+#define MERGEFILECOMMAND_H
+
+/*
+ * mergefilecommand.h
+ * Mothur
+ *
+ * Created by Pat Schloss on 6/14/09.
+ * Copyright 2009 Patrick D. Schloss. All rights reserved.
+ *
+ */
+
+#include "mothur.h"
+#include "command.hpp"
+
+class MergeFileCommand : public Command {
+public:
+ MergeFileCommand(string);
+ ~MergeFileCommand();
+ int execute();
+ void help();
+
+private:
+ vector<string> fileNames;
+ string outputFileName;
+ int numInputFiles;
+ bool abort;
+};
+
+#endif
#include "optionparser.h"
/***********************************************************************/
-void OptionParser::parse(string option, map<string, string>& container) {
+
+OptionParser::OptionParser(string option) {
try {
if (option != "") {
-
+
string key, value;
//reads in parameters and values
while((option.find_first_of(',') != -1)) { //while there are parameters
- splitAtComma(value, option);
- splitAtEquals(key, value);
- container[key] = value;
+ splitAtComma(value, option);
+ splitAtEquals(key, value);
+ parameters[key] = value;
}
-
+
//in case there is no comma and to get last parameter after comma
splitAtEquals(key, option);
- container[key] = option;
+ parameters[key] = option;
}
}
catch(exception& e) {
exit(1);
}
}
-/***********************************************************************/
\ No newline at end of file
+
+/***********************************************************************/
+
+map<string, string> OptionParser::getParameters() { return parameters; }
+
+/***********************************************************************/
/***********************************************************************/
class OptionParser {
- public:
- OptionParser() {}
- ~OptionParser() {}
- void parse(string, map<string, string>&); //pass it an option string and a container
- //fills the container key=parameter name, value=parameter value
+public:
+ OptionParser(string);
+ ~OptionParser() {}
+ map<string, string> getParameters();
+private:
+ map<string, string> parameters;
};
/***********************************************************************/
string Array[] = {"random","groups","iters"};
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
- parser = new OptionParser();
- parser->parse(option, parameters); delete parser;
+ OptionParser parser(option);
+ map<string, string> parameters = parser.getParameters();
- ValidParameters* validParameter = new ValidParameters();
+ ValidParameters validParameter;
//check to make sure all parameters are valid for command
- for (it4 = parameters.begin(); it4 != parameters.end(); it4++) {
- if (validParameter->isValidParameter(it4->first, myArray, it4->second) != true) { abort = true; }
+ for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
- randomtree = validParameter->validFile(parameters, "random", false); if (randomtree == "not found") { randomtree = ""; }
+ randomtree = validParameter.validFile(parameters, "random", false); if (randomtree == "not found") { randomtree = ""; }
//are you trying to use parsimony without reading a tree or saying you want random distribution
if (randomtree == "") {
//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
for(int k = 0; k < numComp; k++) {
//update uscoreFreq
- it = uscoreFreq[k].find(userData[k]);
+ map<int,double>::iterator it = uscoreFreq[k].find(userData[k]);
if (it == uscoreFreq[k].end()) {//new score
uscoreFreq[k][userData[k]] = 1;
}else{ uscoreFreq[k][userData[k]]++; }
for(int r = 0; r < numComp; r++) {
//add trees pscore to map of scores
- it2 = rscoreFreq[r].find(randomData[r]);
- if (it2 != rscoreFreq[r].end()) {//already have that score
+ map<int,double>::iterator it = rscoreFreq[r].find(randomData[r]);
+ if (it != rscoreFreq[r].end()) {//already have that score
rscoreFreq[r][randomData[r]]++;
}else{//first time we have seen this score
rscoreFreq[r][randomData[r]] = 1;
for(int r = 0; r < numComp; r++) {
//add trees pscore to map of scores
- it2 = rscoreFreq[r].find(randomData[r]);
- if (it2 != rscoreFreq[r].end()) {//already have that score
+ map<int,double>::iterator it = rscoreFreq[r].find(randomData[r]);
+ if (it != rscoreFreq[r].end()) {//already have that score
rscoreFreq[r][randomData[r]]++;
}else{//first time we have seen this score
rscoreFreq[r][randomData[r]] = 1;
float rcumul = 0.0000;
float ucumul = 0.0000;
//this loop fills the cumulative maps and put 0.0000 in the score freq map to make it easier to print.
- for (it = validScores.begin(); it != validScores.end(); it++) {
+ for (map<int,double>::iterator it = validScores.begin(); it != validScores.end(); it++) {
if (randomtree == "") {
- it2 = uscoreFreq[a].find(it->first);
+ map<int,double>::iterator it2 = uscoreFreq[a].find(it->first);
//user data has that score
if (it2 != uscoreFreq[a].end()) { uscoreFreq[a][it->first] /= T.size(); ucumul+= it2->second; }
else { uscoreFreq[a][it->first] = 0.0000; } //no user trees with that score
}
//make rscoreFreq map and rCumul
- it2 = rscoreFreq[a].find(it->first);
+ map<int,double>::iterator it2 = rscoreFreq[a].find(it->first);
//get percentage of random trees with that info
if (it2 != rscoreFreq[a].end()) { rscoreFreq[a][it->first] /= iters; rcumul+= it2->second; }
else { rscoreFreq[a][it->first] = 0.0000; } //no random trees with that score
for(int a = 0; a < numComp; a++) {
output->initFile(groupComb[a], tags);
//print each line
- for (it = validScores.begin(); it != validScores.end(); it++) {
+ for (map<int,double>::iterator it = validScores.begin(); it != validScores.end(); it++) {
if (randomtree == "") {
data.push_back(it->first); data.push_back(uscoreFreq[a][it->first]); data.push_back(uCumul[a][it->first]); data.push_back(rscoreFreq[a][it->first]); data.push_back(rCumul[a][it->first]);
}else{
class GlobalData;
class ParsimonyCommand : public Command {
+
+public:
+ ParsimonyCommand(string);
+ ~ParsimonyCommand() { delete pars; delete util; delete output; }
+ int execute();
+ void help();
+
+private:
+ GlobalData* globaldata;
+ SharedUtil* util;
+ FileOutput* output;
+ vector<Tree*> T; //user trees
+ Tree* randT; //random tree
+ Tree* copyUserTree;
+ TreeMap* tmap;
+ TreeMap* savetmap;
+ Parsimony* pars;
+ vector<string> groupComb; // AB. AC, BC...
+ string sumFile, randomtree, allGroups;
+ int iters, numGroups, numComp, counter;
+ vector<int> numEachGroup; //vector containing the number of sequences in each group the users wants for random distrib.
+ vector< vector<float> > userTreeScores; //scores for users trees for each comb.
+ vector< vector<float> > UScoreSig; //tree score signifigance when compared to random trees - percentage of random trees with that score or lower.
+ EstOutput userData; //pscore info for user tree
+ EstOutput randomData; //pscore info for random trees
+ map<int, double> validScores; //map contains scores from both user and random
+ vector< map<int, double> > rscoreFreq; //map <pscore, number of random trees with that score.> -vector entry for each combination.
+ vector< map<int, double> > uscoreFreq; //map <pscore, number of user trees with that score.> -vector entry for each combination.
+ vector< map<int, double> > rCumul; //map <pscore, cumulative percentage of number of random trees with that score or lower.> -vector entry for each combination.
+ vector< map<int, double> > uCumul; //map <pscore, cumulative percentage of number of user trees with that score or lower .> -vector entry for each combination.
- public:
- ParsimonyCommand(string);
- ~ParsimonyCommand() { delete pars; delete util; delete output; }
- int execute();
- void help();
+ ofstream outSum;
- private:
- GlobalData* globaldata;
- SharedUtil* util;
- FileOutput* output;
- vector<Tree*> T; //user trees
- Tree* randT; //random tree
- Tree* copyUserTree;
- TreeMap* tmap;
- TreeMap* savetmap;
- Parsimony* pars;
- vector<string> groupComb; // AB. AC, BC...
- string sumFile, randomtree, allGroups;
- int iters, numGroups, numComp, counter;
- vector<int> numEachGroup; //vector containing the number of sequences in each group the users wants for random distrib.
- vector< vector<float> > userTreeScores; //scores for users trees for each comb.
- vector< vector<float> > UScoreSig; //tree score signifigance when compared to random trees - percentage of random trees with that score or lower.
- EstOutput userData; //pscore info for user tree
- EstOutput randomData; //pscore info for random trees
- map<int, double> validScores; //map contains scores from both user and random
- vector< map<int, double> > rscoreFreq; //map <pscore, number of random trees with that score.> -vector entry for each combination.
- vector< map<int, double> > uscoreFreq; //map <pscore, number of user trees with that score.> -vector entry for each combination.
- vector< map<int, double> > rCumul; //map <pscore, cumulative percentage of number of random trees with that score or lower.> -vector entry for each combination.
- vector< map<int, double> > uCumul; //map <pscore, cumulative percentage of number of user trees with that score or lower .> -vector entry for each combination.
- map<int, double>::iterator it;
- map<int, double>::iterator it2;
-
- ofstream out, outSum;
- ifstream inFile;
-
- OptionParser* parser;
- map<string, string> parameters;
- map<string, string>::iterator it4;
- bool abort;
- string groups, itersString;
- vector<string> Groups; //holds groups to be used
- void printParsimonyFile();
- void printUSummaryFile();
- void getUserInput();
-
+ bool abort;
+ string groups, itersString;
+ vector<string> Groups; //holds groups to be used
+
+ void printParsimonyFile();
+ void printUSummaryFile();
+ void getUserInput();
+
};
string Array[] = {"iters","freq","line","label","calc","abund"};
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
- parser = new OptionParser();
- parser->parse(option, parameters); delete parser;
+ OptionParser parser(option);
+ map<string,string> parameters = parser.getParameters();
- ValidParameters* validParameter = new ValidParameters();
+ ValidParameters validParameter;
//check to make sure all parameters are valid for command
- for (it = parameters.begin(); it != parameters.end(); it++) {
- if (validParameter->isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
+ for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
//make sure the user has already run the read.otu command
//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; }
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"; }
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) {
ValidCalculators* validCalculator;
Rarefact* rCurve;
int freq, nIters, abund;
- OptionParser* parser;
- map<string, string> parameters;
- map<string, string>::iterator it;
+
bool abort, allLines;
set<int> lines; //hold lines to be used
set<string> labels; //holds labels to be used
string Array[] = {"iters","line","label","calc","groups"};
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
- parser = new OptionParser();
- parser->parse(option, parameters); delete parser;
+ OptionParser parser(option);
+ map<string,string> parameters = parser.getParameters();
+
+ ValidParameters validParameter;
- ValidParameters* validParameter = new ValidParameters();
-
//check to make sure all parameters are valid for command
- for (it = parameters.begin(); it != parameters.end(); it++) {
- if (validParameter->isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
+ for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
//make sure the user has already run the read.otu command
//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; }
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);
}
string temp;
- temp = validParameter->validFile(parameters, "iters", false); if (temp == "not found") { temp = "1000"; }
+ temp = validParameter.validFile(parameters, "iters", false); if (temp == "not found") { temp = "1000"; }
convert(temp, nIters);
- delete validParameter;
-
if (abort == false) {
string fileNameRoot = getRootName(globaldata->inputFileName);
- format = globaldata->getFormat();
- int i;
+// format = globaldata->getFormat();
+
validCalculator = new ValidCalculators();
- for (i=0; i<Estimators.size(); i++) {
+ for (int i=0; i<Estimators.size(); i++) {
if (validCalculator->isValidCalculator("sharedrarefaction", Estimators[i]) == true) {
if (Estimators[i] == "sharedobserved") {
rDisplays.push_back(new RareDisplay(new SharedSobs(), new SharedThreeColumnFile(fileNameRoot+"shared.rarefaction", "")));
vector<Display*> rDisplays;
int freq, nIters;
string format;
- OptionParser* parser;
- map<string, string> parameters;
- map<string, string>::iterator it;
+
bool abort, allLines;
set<int> lines; //hold lines to be used
set<string> labels; //holds labels to be used
else {
//valid paramters for this command
- string Array[] = {"phylip","column", "name","cutoff","precision", "group"};
+ string Array[] = {"phylip", "column", "name", "cutoff", "precision", "group"};
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
- parser = new OptionParser();
- parser->parse(option, parameters); delete parser;
+ OptionParser parser(option);
+ map<string, string> parameters = parser.getParameters();
- ValidParameters* validParameter = new ValidParameters();
+ ValidParameters validParameter;
//check to make sure all parameters are valid for command
- for (it = parameters.begin(); it != parameters.end(); it++) {
- if (validParameter->isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
+ for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
globaldata->newRead();
//check for required parameters
- phylipfile = validParameter->validFile(parameters, "phylip", true);
+ phylipfile = validParameter.validFile(parameters, "phylip", true);
if (phylipfile == "not open") { abort = true; }
else if (phylipfile == "not found") { phylipfile = ""; }
else { globaldata->setPhylipFile(phylipfile); globaldata->setFormat("phylip"); }
- columnfile = validParameter->validFile(parameters, "column", true);
+ columnfile = validParameter.validFile(parameters, "column", true);
if (columnfile == "not open") { abort = true; }
else if (columnfile == "not found") { columnfile = ""; }
else { globaldata->setColumnFile(columnfile); globaldata->setFormat("column"); }
- groupfile = validParameter->validFile(parameters, "group", true);
+ groupfile = validParameter.validFile(parameters, "group", true);
if (groupfile == "not open") { abort = true; }
else if (groupfile == "not found") { groupfile = ""; }
else {
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; }
// ...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();
}
//**********************************************************************************************************************
+
ReadDistCommand::~ReadDistCommand(){
delete read;
delete nameMap;
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; }
ReadMatrix* read;
FullMatrix* matrix;
GroupMap* groupMap;
- string filename, format, method;
+ string distFileName, format, method;
string phylipfile, columnfile, namefile, groupfile;
NameAssignment* nameMap;
- OptionParser* parser;
- map<string, string> parameters;
- map<string, string>::iterator it;
+
bool abort;
};
string Array[] = {"list","order","shared", "line", "label","group","sabund", "rabund"};
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
- parser = new OptionParser();
- parser->parse(option, parameters); delete parser;
+ OptionParser parser(option);
+ map<string, string> parameters = parser.getParameters();
- ValidParameters* validParameter = new ValidParameters();
+ ValidParameters validParameter;
//check to make sure all parameters are valid for command
- for (it = parameters.begin(); it != parameters.end(); it++) {
- if (validParameter->isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
+ for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
globaldata->newRead();
//check for required parameters
- listfile = validParameter->validFile(parameters, "list", true);
+ listfile = validParameter.validFile(parameters, "list", true);
if (listfile == "not open") { abort = true; }
else if (listfile == "not found") { listfile = ""; }
else { globaldata->setListFile(listfile); globaldata->setFormat("list"); }
- sabundfile = validParameter->validFile(parameters, "sabund", true);
+ sabundfile = validParameter.validFile(parameters, "sabund", true);
if (sabundfile == "not open") { abort = true; }
else if (sabundfile == "not found") { sabundfile = ""; }
else { globaldata->setSabundFile(sabundfile); globaldata->setFormat("sabund"); }
- rabundfile = validParameter->validFile(parameters, "rabund", true);
+ rabundfile = validParameter.validFile(parameters, "rabund", true);
if (rabundfile == "not open") { abort = true; }
else if (rabundfile == "not found") { rabundfile = ""; }
else { globaldata->setRabundFile(rabundfile); globaldata->setFormat("rabund");}
- sharedfile = validParameter->validFile(parameters, "shared", true);
+ sharedfile = validParameter.validFile(parameters, "shared", true);
if (sharedfile == "not open") { abort = true; }
else if (sharedfile == "not found") { sharedfile = ""; }
else { globaldata->setSharedFile(sharedfile); globaldata->setFormat("sharedfile"); }
- groupfile = validParameter->validFile(parameters, "group", true);
+ groupfile = validParameter.validFile(parameters, "group", true);
if (groupfile == "not open") { abort = true; }
else if (groupfile == "not found") { groupfile = ""; }
else {
//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; }
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; }
//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
Command* parselist;
GroupMap* groupMap;
string filename, listfile, orderfile, sharedfile, line, label, groupfile, sabundfile, rabundfile, format;
- OptionParser* parser;
- map<string, string> parameters;
- map<string, string>::iterator it;
+
bool abort, allLines;
set<int> lines; //hold lines to be used
set<string> labels; //holds labels to be used
string Array[] = {"tree","group"};
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
- parser = new OptionParser();
- parser->parse(option, parameters); delete parser;
+ OptionParser parser(option);
+ map<string, string> parameters = parser.getParameters();
- ValidParameters* validParameter = new ValidParameters();
+ ValidParameters validParameter;
//check to make sure all parameters are valid for command
- for (it = parameters.begin(); it != parameters.end(); it++) {
- if (validParameter->isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
+ for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
globaldata->newRead();
//check for required parameters
- treefile = validParameter->validFile(parameters, "tree", true);
+ treefile = validParameter.validFile(parameters, "tree", true);
if (treefile == "not open") { abort = true; }
else if (treefile == "not found") { treefile = ""; cout << "tree is a required parameter for the read.tree command." << endl; abort = true; }
- else { globaldata->setTreeFile(treefile); globaldata->setFormat("tree"); }
+// else { globaldata->setTreeFile(treefile); globaldata->setFormat("tree"); }
- groupfile = validParameter->validFile(parameters, "group", true);
+ groupfile = validParameter.validFile(parameters, "group", true);
if (groupfile == "not open") { abort = true; }
else if (groupfile == "not found") { groupfile = ""; cout << "group is a required parameter for the read.tree command." << endl; abort = true; }
else {
read = new ReadNewickTree(filename);
}
- delete validParameter;
}
}
catch(exception& e) {
ReadTree* read;
TreeMap* treeMap;
string filename, treefile, groupfile;
- OptionParser* parser;
- map<string, string> parameters;
- map<string, string>::iterator it;
bool abort;
};
ReverseSeqsCommand::ReverseSeqsCommand(string option){
try {
- globaldata = GlobalData::getInstance();
abort = false;
//allow user to run help
string Array[] = {"fasta"};
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
- parser = new OptionParser();
- parser->parse(option, parameters); delete parser;
+ OptionParser parser(option);
+ map<string,string> parameters = parser.getParameters();
- ValidParameters* validParameter = new ValidParameters();
+ ValidParameters validParameter;
//check to make sure all parameters are valid for command
- for (it = parameters.begin(); it != parameters.end(); it++) {
- if (validParameter->isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
+ for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
//check for required parameters
- fasta = validParameter->validFile(parameters, "fasta", true);
+ fasta = validParameter.validFile(parameters, "fasta", true);
if (fasta == "not open") { abort = true; }
else if (fasta == "not found") { fasta = ""; cout << "fasta is a required parameter for the reverse.seqs command." << endl; abort = true; }
- else { globaldata->setFastaFile(fasta); globaldata->setFormat("fasta"); }
- delete validParameter;
}
}
catch(exception& e) {
#include "mothur.h"
#include "command.hpp"
-#include "globaldata.hpp"
class ReverseSeqsCommand : public Command {
public:
void help();
private:
- GlobalData* globaldata;
- OptionParser* parser;
- map<string, string> parameters;
- map<string, string>::iterator it;
+
bool abort;
string fasta;
-
};
ScreenSeqsCommand::ScreenSeqsCommand(string option){
try {
- globaldata = GlobalData::getInstance();
abort = false;
//allow user to run help
string AlignArray[] = {"fasta", "start", "end", "maxambig", "maxhomop", "minlength", "maxlength", "name", "group"};
vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
- parser = new OptionParser();
- parser->parse(option, parameters); delete parser;
+ OptionParser parser(option);
+ map<string,string> parameters = parser.getParameters();
+
+ ValidParameters validParameter;
- ValidParameters* validParameter = new ValidParameters();
-
//check to make sure all parameters are valid for command
- for (it = parameters.begin(); it != parameters.end(); it++) {
- if (validParameter->isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
+ for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
//check for required parameters
- fastafile = validParameter->validFile(parameters, "fasta", true);
+ fastafile = validParameter.validFile(parameters, "fasta", true);
if (fastafile == "not found") { cout << "fasta is a required parameter for the screen.seqs command." << endl; abort = true; }
else if (fastafile == "not open") { abort = true; }
- else { globaldata->setFastaFile(fastafile); }
- groupfile = validParameter->validFile(parameters, "group", true);
+ groupfile = validParameter.validFile(parameters, "group", true);
if (groupfile == "not open") { abort = true; }
else if (groupfile == "not found") { groupfile = ""; }
- else {
- globaldata->setGroupFile(groupfile);
- }
- namefile = validParameter->validFile(parameters, "name", true);
+ namefile = validParameter.validFile(parameters, "name", true);
if (namefile == "not open") { abort = true; }
else if (namefile == "not found") { namefile = ""; }
- else {
- globaldata->setNameFile(namefile);
- }
//check for optional parameter and set defaults
// ...at some point should added some additional type checking...
string temp;
- temp = validParameter->validFile(parameters, "start", false); if (temp == "not found") { temp = "-1"; }
+ temp = validParameter.validFile(parameters, "start", false); if (temp == "not found") { temp = "-1"; }
convert(temp, startPos);
- temp = validParameter->validFile(parameters, "end", false); if (temp == "not found") { temp = "-1"; }
+ temp = validParameter.validFile(parameters, "end", false); if (temp == "not found") { temp = "-1"; }
convert(temp, endPos);
- temp = validParameter->validFile(parameters, "maxambig", false); if (temp == "not found") { temp = "-1"; }
+ temp = validParameter.validFile(parameters, "maxambig", false); if (temp == "not found") { temp = "-1"; }
convert(temp, maxAmbig);
- temp = validParameter->validFile(parameters, "maxhomop", false); if (temp == "not found") { temp = "-1"; }
+ temp = validParameter.validFile(parameters, "maxhomop", false); if (temp == "not found") { temp = "-1"; }
convert(temp, maxHomoP);
- temp = validParameter->validFile(parameters, "minlength", false); if (temp == "not found") { temp = "-1"; }
+ temp = validParameter.validFile(parameters, "minlength", false); if (temp == "not found") { temp = "-1"; }
convert(temp, minLength);
- temp = validParameter->validFile(parameters, "maxlength", false); if (temp == "not found") { temp = "-1"; }
+ temp = validParameter.validFile(parameters, "maxlength", false); if (temp == "not found") { temp = "-1"; }
convert(temp, maxLength);
-
- delete validParameter;
}
}
void ScreenSeqsCommand::screenNameGroupFile(set<string> badSeqNames){
ifstream inputNames;
- openInputFile(globaldata->getNameFile(), inputNames);
+ openInputFile(namefile, inputNames);
set<string> badSeqGroups;
string seqName, seqList, group;
set<string>::iterator it;
- string goodNameFile = getRootName(globaldata->getNameFile()) + "good" + getExtension(globaldata->getNameFile());
- string badNameFile = getRootName(globaldata->getNameFile()) + "bad" + getExtension(globaldata->getNameFile());
+ string goodNameFile = getRootName(namefile) + "good" + getExtension(namefile);
+ string badNameFile = getRootName(namefile) + "bad" + getExtension(namefile);
ofstream goodNameOut; openOutputFile(goodNameFile, goodNameOut);
ofstream badNameOut; openOutputFile(badNameFile, badNameOut);
if(it != badSeqNames.end()){
badSeqNames.erase(it);
badNameOut << seqName << '\t' << seqList << endl;
- if(globaldata->getNameFile() != ""){
+ if(namefile != ""){
int start = 0;
for(int i=0;i<seqList.length();i++){
if(seqList[i] == ','){
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);
void ScreenSeqsCommand::screenGroupFile(set<string> badSeqNames){
ifstream inputGroups;
- openInputFile(globaldata->getGroupFile(), inputGroups);
+ openInputFile(groupfile, inputGroups);
string seqName, group;
set<string>::iterator it;
- string goodGroupFile = getRootName(globaldata->getGroupFile()) + "good" + getExtension(globaldata->getGroupFile());
- string badGroupFile = getRootName(globaldata->getGroupFile()) + "bad" + getExtension(globaldata->getGroupFile());
+ string goodGroupFile = getRootName(groupfile) + "good" + getExtension(groupfile);
+ string badGroupFile = getRootName(groupfile) + "bad" + getExtension(groupfile);
ofstream goodGroupOut; openOutputFile(goodGroupFile, goodGroupOut);
ofstream badGroupOut; openOutputFile(badGroupFile, badGroupOut);
*/
#include "mothur.h"
#include "command.hpp"
-#include "globaldata.hpp"
class ScreenSeqsCommand : public Command {
void screenNameGroupFile(set<string>);
void screenGroupFile(set<string>);
- GlobalData* globaldata;
- OptionParser* parser;
- map<string, string> parameters;
- map<string, string>::iterator it;
bool abort;
string fastafile, namefile, groupfile;
int startPos, endPos, maxAmbig, maxHomoP, minLength, maxLength;
SeqSummaryCommand::SeqSummaryCommand(string option){
try {
- globaldata = GlobalData::getInstance();
abort = false;
//allow user to run help
string Array[] = {"fasta"};
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
- parser = new OptionParser();
- parser->parse(option, parameters); delete parser;
+ OptionParser parser(option);
+ map<string,string> parameters = parser.getParameters();
+
+ ValidParameters validParameter;
- ValidParameters* validParameter = new ValidParameters();
-
//check to make sure all parameters are valid for command
- for (it = parameters.begin(); it != parameters.end(); it++) {
- if (validParameter->isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
+ for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
//check for required parameters
- fastafile = validParameter->validFile(parameters, "fasta", true);
+ fastafile = validParameter.validFile(parameters, "fasta", true);
if (fastafile == "not open") { abort = true; }
else if (fastafile == "not found") { fastafile = ""; cout << "fasta is a required parameter for the summary.seqs command." << endl; abort = true; }
- else { globaldata->setFastaFile(fastafile); globaldata->setFormat("fasta"); }
- delete validParameter;
}
}
catch(exception& e) {
#include "mothur.h"
#include "command.hpp"
-#include "globaldata.hpp"
-
-
class SeqSummaryCommand : public Command {
public:
void help();
private:
- GlobalData* globaldata;
- OptionParser* parser;
- map<string, string> parameters;
- map<string, string>::iterator it;
bool abort;
string fastafile;
-
};
#endif
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;
/***********************************************************************/
SequenceDB::SequenceDB(int newSize) {
- data.resize(newSize, NULL);
+ data.resize(newSize, Sequence());
}
/***********************************************************************/
}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
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";
/***********************************************************************/
-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) {
/***********************************************************************/
-Sequence* SequenceDB::get(int index) {
+Sequence SequenceDB::get(int index) {
return data[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) {
void SequenceDB::clear() {
try {
- for (int i = 0; i < data.size(); i++) { delete data[i]; }
data.clear();
}
catch(exception& e) {
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) {
/***********************************************************************/
-void SequenceDB::push_back(Sequence* newSequence) {
+void SequenceDB::push_back(Sequence newSequence) {
try {
data.push_back(newSequence);
}
int getNumSeqs();
void set(int, string); //unaligned - should also set length
- void set(int, Sequence*); //unaligned - should also set length
- Sequence* get(int); //returns sequence name at that location
- void push_back(Sequence*); //adds unaligned sequence
+ void set(int, Sequence); //unaligned - should also set length
+ Sequence get(int); //returns sequence name at that location
+ void push_back(Sequence); //adds unaligned sequence
void resize(int); //resizes data
void clear(); //clears data - remeber to loop through and delete the sequences inside or you will have a memory leak
int size(); //returns datas size
void print(ostream&); //loops through data using sequence class print
private:
- vector<Sequence*> data;
+ vector<Sequence> data;
string readName(ifstream&);
string readSequence(ifstream&);
EstOutput Shen::getValues(SAbundVector* rank){
try {
- globaldata = GlobalData::getInstance();
data.resize(1,0);
*/
#include "calculator.h"
-#include "globaldata.hpp"
/* This class implements the shen calculator on single group.
It is a child of the calculator class. */
private:
int m;
int abund;
- GlobalData* globaldata;
};
string Array[] = {"line","label","calc","abund","size"};
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
- parser = new OptionParser();
- parser->parse(option, parameters); delete parser;
+ OptionParser parser(option);
+ map<string,string> parameters = parser.getParameters();
+
+ ValidParameters validParameter;
- ValidParameters* validParameter = new ValidParameters();
-
//check to make sure all parameters are valid for command
- for (it = parameters.begin(); it != parameters.end(); it++) {
- if (validParameter->isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
+ for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
//make sure the user has already run the read.otu command
//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; }
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"; }
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();
string outputFileName;
ofstream outputFileHandle;
int abund, size;
- OptionParser* parser;
- map<string, string> parameters;
- map<string, string>::iterator it;
+
bool abort, allLines;
set<int> lines; //hold lines to be used
set<string> labels; //holds labels to be used
string Array[] = {"line","label","calc","groups"};
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
- parser = new OptionParser();
- parser->parse(option, parameters); delete parser;
+ OptionParser parser(option);
+ map<string, string> parameters = parser.getParameters();
- ValidParameters* validParameter = new ValidParameters();
+ ValidParameters validParameter;
//check to make sure all parameters are valid for command
- for (it = parameters.begin(); it != parameters.end(); it++) {
- if (validParameter->isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
+ for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
//make sure the user has already run the read.otu command
//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; }
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();
outputFileName = ((getRootName(globaldata->inputFileName)) + "shared.summary");
openOutputFile(outputFileName, outputFileHandle);
- format = globaldata->getFormat();
+// format = globaldata->getFormat();
mult = false;
}
}
#include "treenode.h"
#include "globaldata.hpp"
+class GlobalData;
/* This class represents the treefile. */
class Tree {
string Array[] = {"line","label","calc","groups", "phylip", "column", "name", "precision","cutoff"};
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
- parser = new OptionParser();
- parser->parse(option, parameters); delete parser;
+ OptionParser parser(option);
+ map<string, string> parameters = parser. getParameters();
- ValidParameters* validParameter = new ValidParameters();
+ ValidParameters validParameter;
//check to make sure all parameters are valid for command
- for (it = parameters.begin(); it != parameters.end(); it++) {
- if (validParameter->isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
+ for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
//required parameters
- phylipfile = validParameter->validFile(parameters, "phylip", true);
+ phylipfile = validParameter.validFile(parameters, "phylip", true);
if (phylipfile == "not open") { abort = true; }
else if (phylipfile == "not found") { phylipfile = ""; }
- else { globaldata->setPhylipFile(phylipfile); globaldata->setFormat("phylip"); }
+ else { format = "phylip"; }
- columnfile = validParameter->validFile(parameters, "column", true);
+ columnfile = validParameter.validFile(parameters, "column", true);
if (columnfile == "not open") { abort = true; }
else if (columnfile == "not found") { columnfile = ""; }
- else { globaldata->setColumnFile(columnfile); globaldata->setFormat("column"); }
+ else { format = "column"; }
- namefile = validParameter->validFile(parameters, "name", true);
+ namefile = validParameter.validFile(parameters, "name", true);
if (namefile == "not open") { abort = true; }
else if (namefile == "not found") { namefile = ""; }
else { globaldata->setNameFile(namefile); }
- format = globaldata->getFormat();
+// format = globaldata->getFormat();
//error checking on files
if ((globaldata->getSharedFile() == "") && ((phylipfile == "") && (columnfile == ""))) { cout << "You must run the read.otu command or provide a distance file before running the tree.shared command." << endl; abort = true; }
//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; }
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);
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();
int numGroups;
ofstream out;
float precision, cutoff;
- OptionParser* parser;
- map<string, string> parameters;
- map<string, string>::iterator it;
+
bool abort, allLines;
set<int> lines; //hold lines to be used
set<string> labels; //holds labels to be used
TrimSeqsCommand::TrimSeqsCommand(string option){
try {
- globaldata = GlobalData::getInstance();
abort = false;
//allow user to run help
else {
//valid paramters for this command
- string AlignArray[] = {"fasta", "flip", "oligos", "maxambig", "maxhomop", "minlength", "maxlength"};
+ string AlignArray[] = {"fasta", "flip", "oligos", "maxambig", "maxhomop", "minlength", "maxlength", "qfile", "qthreshold", "qaverage", "allfiles"};
+
vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
- parser = new OptionParser();
- parser->parse(option, parameters); delete parser;
+ OptionParser parser(option);
+ map<string,string> parameters = parser.getParameters();
+
+ ValidParameters validParameter;
- ValidParameters* validParameter = new ValidParameters();
-
//check to make sure all parameters are valid for command
- for (it = parameters.begin(); it != parameters.end(); it++) {
- if (validParameter->isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
+ for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
//check for required parameters
- fastafile = validParameter->validFile(parameters, "fasta", true);
- if (fastafile == "not found") { cout << "fasta is a required parameter for the screen.seqs command." << endl; abort = true; }
- else if (fastafile == "not open") { abort = true; }
- else { globaldata->setFastaFile(fastafile); }
+ fastaFile = validParameter.validFile(parameters, "fasta", true);
+ if (fastaFile == "not found") { cout << "fasta is a required parameter for the screen.seqs command." << endl; abort = true; }
+ else if (fastaFile == "not open") { abort = true; }
//check for optional parameter and set defaults
// ...at some point should added some additional type checking...
string temp;
- temp = validParameter->validFile(parameters, "flip", false); if (temp == "not found") { temp = "0"; }
- if(isTrue(temp)) { flip = 1; }
+ temp = validParameter.validFile(parameters, "flip", false);
+ if (temp == "not found"){ flip = 0; }
+ else if(isTrue(temp)) { flip = 1; }
- temp = validParameter->validFile(parameters, "oligos", false); if (temp == "not found") { temp = ""; }
- if(temp != "") { oligos = 1; }
- else { oligos = 0; }
-
- temp = validParameter->validFile(parameters, "maxambig", false); if (temp == "not found") { temp = "-1"; }
+ temp = validParameter.validFile(parameters, "oligos", true);
+ if (temp == "not found"){ oligoFile = ""; }
+ else if(temp == "not open"){ abort = true; }
+ else { oligoFile = temp; }
+
+ temp = validParameter.validFile(parameters, "maxambig", false); if (temp == "not found") { temp = "-1"; }
convert(temp, maxAmbig);
- temp = validParameter->validFile(parameters, "maxhomop", false); if (temp == "not found") { temp = "0"; }
+ temp = validParameter.validFile(parameters, "maxhomop", false); if (temp == "not found") { temp = "0"; }
convert(temp, maxHomoP);
- temp = validParameter->validFile(parameters, "minlength", false); if (temp == "not found") { temp = "0"; }
+ temp = validParameter.validFile(parameters, "minlength", false); if (temp == "not found") { temp = "0"; }
convert(temp, minLength);
- temp = validParameter->validFile(parameters, "maxlength", false); if (temp == "not found") { temp = "0"; }
- convert(temp, maxLength);
+ temp = validParameter.validFile(parameters, "maxlength", false); if (temp == "not found") { temp = "0"; }
+ convert(temp, maxLength);
+
+ temp = validParameter.validFile(parameters, "qfile", true);
+ if (temp == "not found") { qFileName = ""; }
+ else if(temp == "not open") { abort = 0; }
+ else { qFileName = temp; }
- if(!flip && !oligos && !maxLength && !minLength && (maxAmbig==-1) && !maxHomoP ){ cout << "huh?" << endl; }
+ temp = validParameter.validFile(parameters, "qthreshold", false); if (temp == "not found") { temp = "0"; }
+ convert(temp, qThreshold);
+
+ temp = validParameter.validFile(parameters, "qaverage", false); if (temp == "not found") { temp = "0"; }
+ convert(temp, qAverage);
+
+ temp = validParameter.validFile(parameters, "allfiles", false); if (temp == "not found") { temp = "F"; }
+ allFiles = isTrue(temp);
+
+ if(allFiles && oligoFile == ""){
+ cout << "You selected allfiles, but didn't enter an oligos file. Ignoring the allfiles request." << endl;
+ }
+
+ if(!flip && oligoFile=="" && !maxLength && !minLength && (maxAmbig==-1) && !maxHomoP && qFileName == ""){
+ cout << "You didn't set any options... quiting command." << endl;
+ abort = true;
+ }
- delete validParameter;
}
}
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";
if (abort == true) { return 0; }
- getOligos();
-
+ vector<ofstream*> groupFileNames;
+ vector<ofstream*> fastaFileNames;
+ if(oligoFile != "") { getOligos(fastaFileNames, groupFileNames); }
+
ifstream inFASTA;
- openInputFile(fastafile, inFASTA);
+ openInputFile(fastaFile, inFASTA);
ofstream outFASTA;
- string trimSeqFile = getRootName(fastafile) + "trim.fasta";
+ string trimSeqFile = getRootName(fastaFile) + "trim.fasta";
openOutputFile(trimSeqFile, outFASTA);
ofstream outGroups;
- string groupFile = getRootName(fastafile) + "groups";
+ string groupFile = getRootName(fastaFile) + "groups";
openOutputFile(groupFile, outGroups);
-
+
ofstream scrapFASTA;
- string scrapSeqFile = getRootName(fastafile) + "scrap.fasta";
+ string scrapSeqFile = getRootName(fastaFile) + "scrap.fasta";
openOutputFile(scrapSeqFile, scrapFASTA);
-
+
+ ifstream qFile;
+ if(qFileName != "") { openInputFile(qFileName, qFile); }
+
bool success;
while(!inFASTA.eof()){
Sequence currSeq(inFASTA);
string origSeq = currSeq.getUnaligned();
- string group;
+ int group;
string trashCode = "";
-
+
+ if(qFileName != ""){
+ if(qThreshold != 0) { success = stripQualThreshold(currSeq, qFile); }
+ else if(qAverage != 0) { success = cullQualAverage(currSeq, qFile); }
+ if(!success) { trashCode += 'q'; }
+ }
if(barcodes.size() != 0){
success = stripBarcode(currSeq, group);
if(!success){ trashCode += 'b'; }
}
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();
scrapFASTA.close();
outGroups.close();
+ for(int i=0;i<groupFileNames.size();i++){
+ groupFileNames[i]->close();
+ delete groupFileNames[i];
+
+ fastaFileNames[i]->close();
+ delete fastaFileNames[i];
+ }
+
return 0;
}
catch(exception& e) {
//***************************************************************************************************************
-void TrimSeqsCommand::getOligos(){
-
+void TrimSeqsCommand::getOligos(vector<ofstream*>& outFASTAVec, vector<ofstream*>& outGroupsVec){
+
ifstream inOligos;
- //openInputFile(globaldata->getOligosFile(), inOligos);
+ openInputFile(oligoFile, inOligos);
+ ofstream test;
+
string type, oligo, group;
+ int index=0;
while(!inOligos.eof()){
inOligos >> type;
- if(type == "forward"){
- inOligos >> oligo;
- forPrimer.push_back(oligo);
+ if(type[0] == '#'){
+ while (!inOligos.eof()) { char c = inOligos.get(); if (c == 10 || c == 13){ break; } } // get rest of line if there's any crap there
}
- else if(type == "reverse"){
+ else{
inOligos >> oligo;
- revPrimer.push_back(oligo);
- }
- else if(type == "barcode"){
- inOligos >> oligo >> group;
- barcodes[oligo]=group;
- }
- else if(type[0] == '#'){
- char c;
- while ((c = inOligos.get()) != EOF) { if (c == 10){ break; } } // get rest of line
+
+ for(int i=0;i<oligo.length();i++){
+ oligo[i] = toupper(oligo[i]);
+ if(oligo[i] == 'U') { oligo[i] = 'T'; }
+ }
+
+ if(type == "forward"){
+ forPrimer.push_back(oligo);
+ }
+ else if(type == "reverse"){
+ revPrimer.push_back(oligo);
+ }
+ else if(type == "barcode"){
+ inOligos >> group;
+ barcodes[oligo]=index++;
+ groupVector.push_back(group);
+
+ if(allFiles){
+ outFASTAVec.push_back(new ofstream((getRootName(fastaFile) + group + ".fasta").c_str(), ios::ate));
+ outGroupsVec.push_back(new ofstream((getRootName(fastaFile) + group + ".groups").c_str(), ios::ate));
+ }
+ }
}
-
- gobble(inOligos);
}
-
+
numFPrimers = forPrimer.size();
numRPrimers = revPrimer.size();
}
//***************************************************************************************************************
-bool TrimSeqsCommand::stripBarcode(Sequence& seq, string& group){
+bool TrimSeqsCommand::stripBarcode(Sequence& seq, int& group){
string rawSequence = seq.getUnaligned();
bool success = 0; //guilty until proven innocent
-
- for(map<string,string>::iterator it=barcodes.begin();it!=barcodes.end();it++){
+
+ for(map<string,int>::iterator it=barcodes.begin();it!=barcodes.end();it++){
string oligo = it->first;
-
if(rawSequence.length() < oligo.length()){ //let's just assume that the barcodes are the same length
success = 0;
break;
}
- if (rawSequence.compare(0,oligo.length(),oligo) == 0){
+ if(compareDNASeq(oligo, rawSequence.substr(0,oligo.length()))){
group = it->second;
seq.setUnaligned(rawSequence.substr(oligo.length()));
success = 1;
for(int i=0;i<numFPrimers;i++){
string oligo = forPrimer[i];
-
+
if(rawSequence.length() < oligo.length()){
success = 0;
break;
}
-
- if (rawSequence.compare(0,oligo.length(),oligo) == 0){
+
+ if(compareDNASeq(oligo, rawSequence.substr(0,oligo.length()))){
seq.setUnaligned(rawSequence.substr(oligo.length()));
success = 1;
break;
break;
}
- if(rawSequence.compare(rawSequence.length()-oligo.length(),oligo.length(),oligo) == 0){
+ if(compareDNASeq(oligo, rawSequence.substr(rawSequence.length()-oligo.length(),oligo.length()))){
seq.setUnaligned(rawSequence.substr(rawSequence.length()-oligo.length()));
success = 1;
break;
int numNs = seq.getAmbigBases();
bool success = 0; //guilty until proven innocent
- if(numNs <= maxAmbig){ success = 1; }
+ if(numNs <= maxAmbig) { success = 1; }
else { success = 0; }
return success;
}
//***************************************************************************************************************
+
+bool TrimSeqsCommand::compareDNASeq(string oligo, string seq){
+
+ bool success = 1;
+ int length = oligo.length();
+
+ for(int i=0;i<length;i++){
+
+ if(oligo[i] != seq[i]){
+ if(oligo[i] == 'A' || oligo[i] == 'T' || oligo[i] == 'G' || oligo[i] == 'C') { success = 0; }
+ else if((oligo[i] == 'N' || oligo[i] == 'I') && (seq[i] == 'N')) { success = 0; }
+ else if(oligo[i] == 'R' && (seq[i] != 'A' && seq[i] != 'G')) { success = 0; }
+ else if(oligo[i] == 'Y' && (seq[i] != 'C' && seq[i] != 'T')) { success = 0; }
+ else if(oligo[i] == 'M' && (seq[i] != 'C' && seq[i] != 'A')) { success = 0; }
+ else if(oligo[i] == 'K' && (seq[i] != 'T' && seq[i] != 'G')) { success = 0; }
+ else if(oligo[i] == 'W' && (seq[i] != 'T' && seq[i] != 'A')) { success = 0; }
+ else if(oligo[i] == 'S' && (seq[i] != 'C' && seq[i] != 'G')) { success = 0; }
+ else if(oligo[i] == 'B' && (seq[i] != 'C' && seq[i] != 'T' && seq[i] != 'G')) { success = 0; }
+ else if(oligo[i] == 'D' && (seq[i] != 'A' && seq[i] != 'T' && seq[i] != 'G')) { success = 0; }
+ else if(oligo[i] == 'H' && (seq[i] != 'A' && seq[i] != 'T' && seq[i] != 'C')) { success = 0; }
+ else if(oligo[i] == 'V' && (seq[i] != 'A' && seq[i] != 'C' && seq[i] != 'G')) { success = 0; }
+
+ if(success == 0) { break; }
+ }
+ else{
+ success = 1;
+ }
+ }
+
+ return success;
+}
+
+//***************************************************************************************************************
+
+bool TrimSeqsCommand::stripQualThreshold(Sequence& seq, ifstream& qFile){
+
+ string rawSequence = seq.getUnaligned();
+ int seqLength = rawSequence.length();
+ string name;
+
+ qFile >> name;
+ if(name.substr(1) != seq.getName()) { cout << "sequence name mismatch btwn fasta and qual file" << endl; }
+ while (!qFile.eof()) { char c = qFile.get(); if (c == 10 || c == 13){ break; } }
+
+ int score;
+ int end = seqLength;
+
+ for(int i=0;i<seqLength;i++){
+ qFile >> score;
+
+ if(score <= qThreshold){
+ end = i;
+ break;
+ }
+ }
+ for(int i=end+1;i<seqLength;i++){
+ qFile >> score;
+ }
+
+ seq.setUnaligned(rawSequence.substr(0,end));
+
+ return 1;
+}
+
+//***************************************************************************************************************
+
+bool TrimSeqsCommand::cullQualAverage(Sequence& seq, ifstream& qFile){
+
+ string rawSequence = seq.getUnaligned();
+ int seqLength = seq.getNumBases();
+ bool success = 0; //guilty until proven innocent
+ string name;
+
+ qFile >> name;
+ if(name.substr(1) != seq.getName()) { cout << "sequence name mismatch btwn fasta and qual file" << endl; }
+ while (!qFile.eof()) { char c = qFile.get(); if (c == 10 || c == 13){ break; } }
+
+ float score;
+ float average = 0;
+
+ for(int i=0;i<seqLength;i++){
+ qFile >> score;
+ average += score;
+ }
+ average /= seqLength;
+
+ if(average >= qAverage) { success = 1; }
+ else { success = 0; }
+
+ return success;
+}
+
+//***************************************************************************************************************
+
+
#include "mothur.h"
#include "command.hpp"
-#include "globaldata.hpp"
#include "sequence.hpp"
class TrimSeqsCommand : public Command {
void help();
private:
- void getOligos();
- bool stripBarcode(Sequence&, string&);
+ void getOligos(vector<ofstream*>&, vector<ofstream*>&);
+ bool stripQualThreshold(Sequence&, ifstream&);
+ bool cullQualAverage(Sequence&, ifstream&);
+ bool stripBarcode(Sequence&, int&);
bool stripForward(Sequence&);
bool stripReverse(Sequence&);
bool cullLength(Sequence&);
bool cullHomoP(Sequence&);
bool cullAmbigs(Sequence&);
-
- GlobalData* globaldata;
- OptionParser* parser;
- map<string, string> parameters;
- map<string, string>::iterator it;
+ bool compareDNASeq(string, string);
+
bool abort;
- string fastafile;
- bool oligos, flip;
- int numFPrimers, numRPrimers, maxAmbig, maxHomoP, minLength, maxLength;
+ string fastaFile, oligoFile, qFileName;
+
+ bool flip, allFiles;
+ int numFPrimers, numRPrimers, maxAmbig, maxHomoP, minLength, maxLength, qThreshold, qAverage;
vector<string> forPrimer, revPrimer;
- map<string, string> barcodes;
+ map<string, int> barcodes;
+ vector<string> groupVector;
};
#endif
string Array[] = {"groups","iters"};
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
- parser = new OptionParser();
- parser->parse(option, parameters); delete parser;
+ OptionParser parser(option);
+ map<string,string> parameters = parser.getParameters();
- ValidParameters* validParameter = new ValidParameters();
+ ValidParameters validParameter;
//check to make sure all parameters are valid for command
- for (it4 = parameters.begin(); it4 != parameters.end(); it4++) {
- if (validParameter->isValidParameter(it4->first, myArray, it4->second) != true) { abort = true; }
+ for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
if (globaldata->gTree.size() == 0) {//no trees were read
//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;
for(int k = 0; k < numComp; k++) {
//add trees unweighted score to map of scores
- it2 = rscoreFreq[k].find(randomData[k]);
- if (it2 != rscoreFreq[k].end()) {//already have that score
+ map<float,float>::iterator it = rscoreFreq[k].find(randomData[k]);
+ if (it != rscoreFreq[k].end()) {//already have that score
rscoreFreq[k][randomData[k]]++;
}else{//first time we have seen this score
rscoreFreq[k][randomData[k]] = 1;
for(int a = 0; a < numComp; a++) {
float rcumul = 1.0000;
//this loop fills the cumulative maps and put 0.0000 in the score freq map to make it easier to print.
- for (it = validScores.begin(); it != validScores.end(); it++) {
+ for (map<float,float>::iterator it = validScores.begin(); it != validScores.end(); it++) {
//make rscoreFreq map and rCumul
- it2 = rscoreFreq[a].find(it->first);
+ map<float,float>::iterator it2 = rscoreFreq[a].find(it->first);
rCumul[a][it->first] = rcumul;
//get percentage of random trees with that info
if (it2 != rscoreFreq[a].end()) { rscoreFreq[a][it->first] /= iters; rcumul-= it2->second; }
for(int a = 0; a < numComp; a++) {
output->initFile(groupComb[a], tags);
//print each line
- for (it = validScores.begin(); it != validScores.end(); it++) {
+ for (map<float,float>::iterator it = validScores.begin(); it != validScores.end(); it++) {
data.push_back(it->first); data.push_back(rscoreFreq[a][it->first]); data.push_back(rCumul[a][it->first]);
output->output(data);
data.clear();
map<float, float> validScores; //map contains scores from random
vector< map<float, float> > rscoreFreq; //map <unweighted score, number of random trees with that score.> -vector entry for each combination.
vector< map<float, float> > rCumul; //map <unweighted score, cumulative percentage of number of random trees with that score or higher.> -vector entry for each combination.
- map<float, float>::iterator it2;
- map<float, float>::iterator it;
- OptionParser* parser;
- map<string, string> parameters;
- map<string, string>::iterator it4;
bool abort;
string groups, itersString;
vector<string> Groups; //holds groups to be used
string Array[] = {"groups","iters"};
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
- parser = new OptionParser();
- parser->parse(option, parameters); delete parser;
+ OptionParser parser(option);
+ map<string,string> parameters=parser.getParameters();
- ValidParameters* validParameter = new ValidParameters();
+ ValidParameters validParameter;
//check to make sure all parameters are valid for command
- for (it4 = parameters.begin(); it4 != parameters.end(); it4++) {
- if (validParameter->isValidParameter(it4->first, myArray, it4->second) != true) { abort = true; }
+ for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
if (globaldata->gTree.size() == 0) {//no trees were read
//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;
for(int a = 0; a < numComp; a++) {
output->initFile(groupComb[a], tags);
//print each line
- for (it = validScores.begin(); it != validScores.end(); it++) {
+ for (map<float,float>::iterator it = validScores.begin(); it != validScores.end(); it++) {
data.push_back(it->first); data.push_back(rScoreFreq[a][it->first]); data.push_back(rCumul[a][it->first]);
output->output(data);
data.clear();
for (int f = 0; f < numComp; f++) {
for (int i = 0; i < rScores[f].size(); i++) { //looks like 0,0,1,1,1,2,4,7... you want to make a map that say rScoreFreq[0] = 2, rScoreFreq[1] = 3...
validScores[rScores[f][i]] = rScores[f][i];
- it = rScoreFreq[f].find(rScores[f][i]);
+ map<float,float>::iterator it = rScoreFreq[f].find(rScores[f][i]);
if (it != rScoreFreq[f].end()) {
rScoreFreq[f][rScores[f][i]]++;
}else{
for(int a = 0; a < numComp; a++) {
float rcumul = 1.0000;
//this loop fills the cumulative maps and put 0.0000 in the score freq map to make it easier to print.
- for (it = validScores.begin(); it != validScores.end(); it++) {
+ for (map<float,float>::iterator it = validScores.begin(); it != validScores.end(); it++) {
//make rscoreFreq map and rCumul
- it2 = rScoreFreq[a].find(it->first);
+ map<float,float>::iterator it2 = rScoreFreq[a].find(it->first);
rCumul[a][it->first] = rcumul;
//get percentage of random trees with that info
if (it2 != rScoreFreq[a].end()) { rScoreFreq[a][it->first] /= iters; rcumul-= it2->second; }
vector< map<float, float> > rScoreFreq; //map <weighted score, number of random trees with that score.> -vector entry for each combination.
vector< map<float, float> > rCumul; //map <weighted score, cumulative percentage of number of random trees with that score or higher.> -vector entry for each c
map<float, float> validScores; //map contains scores from random
- map<float, float>::iterator it2;
- map<float, float>::iterator it;
- OptionParser* parser;
- map<string, string> parameters;
- map<string, string>::iterator it4;
bool abort;
string groups, itersString;
vector<string> Groups; //holds groups to be used
- ofstream outSum, out;
- ifstream inFile;
+ ofstream outSum;
void printWSummaryFile();
void printWeightedFile();
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";
/***********************************************************************/
class Venn {
-
- public:
- Venn();
- ~Venn(){};
-
- void getPic(SAbundVector*, vector<Calculator*>);
- void getPic(vector<SharedRAbundVector*>, vector<Calculator*>);
-
- private:
- GlobalData* globaldata;
- Calculator* singleCalc;
- string format, groupComb;
- ofstream outsvg;
-
-
+public:
+ Venn();
+ ~Venn(){};
+
+ void getPic(SAbundVector*, vector<Calculator*>);
+ void getPic(vector<SharedRAbundVector*>, vector<Calculator*>);
+
+private:
+ GlobalData* globaldata;
+ Calculator* singleCalc;
+ string groupComb;
+ ofstream outsvg;
};
+
/***********************************************************************/
#endif
string AlignArray[] = {"groups","line","label","calc", "abund"};
vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
- parser = new OptionParser();
- parser->parse(option, parameters); delete parser;
+ OptionParser parser(option);
+ map<string,string> parameters = parser.getParameters();
+
+ ValidParameters validParameter;
- ValidParameters* validParameter = new ValidParameters();
-
//check to make sure all parameters are valid for command
- for (it = parameters.begin(); it != parameters.end(); it++) {
- if (validParameter->isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
+ for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
//make sure the user has already run the read.otu command
//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; }
lines = globaldata->lines;
}
- groups = validParameter->validFile(parameters, "groups", false);
+ groups = validParameter.validFile(parameters, "groups", false);
if (groups == "not found") { groups = ""; }
else {
splitAtDash(groups, Groups);
}
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"; }
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();
SAbundVector* sabund;
int abund;
- OptionParser* parser;
- map<string, string> parameters;
- map<string, string>::iterator it;
bool abort, allLines;
set<int> lines; //hold lines to be used
set<string> labels; //holds labels to be used