From: westcott Date: Fri, 15 Oct 2010 16:46:19 +0000 (+0000) Subject: added pipeline commands which involved change to command factory and command class... X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=8bc3e5b38c2317a1715f53be22fa96455868c281 added pipeline commands which involved change to command factory and command class. fixed bug in unifrac.unwieghted --- diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj index e2673fc..5e84c7e 100644 --- a/Mothur.xcodeproj/project.pbxproj +++ b/Mothur.xcodeproj/project.pbxproj @@ -43,6 +43,8 @@ A72B3A63118B37FD004B9F8D /* phylodiversitycommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = phylodiversitycommand.cpp; sourceTree = ""; }; A72B3A7B118B4D1B004B9F8D /* phylodiversity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = phylodiversity.h; sourceTree = ""; }; A72B3A7C118B4D1B004B9F8D /* phylodiversity.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = phylodiversity.cpp; sourceTree = ""; }; + A72C66A1125B356F0058C2F9 /* pipelinepdscommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pipelinepdscommand.h; sourceTree = ""; }; + A72C66A2125B356F0058C2F9 /* pipelinepdscommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = pipelinepdscommand.cpp; sourceTree = ""; }; A732505E11E49EF100484B90 /* sffinfocommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sffinfocommand.h; sourceTree = ""; }; A732505F11E49EF100484B90 /* sffinfocommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sffinfocommand.cpp; sourceTree = ""; }; A73953DA11987ED100B0B160 /* chopseqscommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = chopseqscommand.h; sourceTree = ""; }; @@ -730,12 +732,12 @@ A7DA1FEE113FECD400BF472F /* aligncommand.cpp */, A7DA1FFE113FECD400BF472F /* binsequencecommand.h */, A7DA1FFD113FECD400BF472F /* binsequencecommand.cpp */, - A7DA2007113FECD400BF472F /* bootstrapsharedcommand.cpp */, A7DA2008113FECD400BF472F /* bootstrapsharedcommand.h */, + A7DA2007113FECD400BF472F /* bootstrapsharedcommand.cpp */, A7D216061199C47F00F13F13 /* catchallcommand.h */, A7D216071199C47F00F13F13 /* catchallcommand.cpp */, - A7DA2017113FECD400BF472F /* chimeraseqscommand.cpp */, A7DA2018113FECD400BF472F /* chimeraseqscommand.h */, + A7DA2017113FECD400BF472F /* chimeraseqscommand.cpp */, A7825502116519F70002E2DD /* chimerabellerophoncommand.h */, A7825503116519F70002E2DD /* chimerabellerophoncommand.cpp */, A747E79B1163442A00FB9042 /* chimeracheckcommand.h */, @@ -754,88 +756,90 @@ A7BBDA7C11B5694E006E6551 /* classifyotucommand.cpp */, A7D215C811996C6E00F13F13 /* clearcutcommand.h */, A7D215C911996C6E00F13F13 /* clearcutcommand.cpp */, - A7DA2021113FECD400BF472F /* clustercommand.cpp */, A7DA2022113FECD400BF472F /* clustercommand.h */, + A7DA2021113FECD400BF472F /* clustercommand.cpp */, A74A9C03124B72DB000D5D25 /* clusterfragmentscommand.h */, A74A9C04124B72DB000D5D25 /* clusterfragmentscommand.cpp */, A71D924311AEB42400D00CBC /* clustersplitcommand.h */, A71D924211AEB42400D00CBC /* clustersplitcommand.cpp */, A7DA2026113FECD400BF472F /* collectcommand.h */, A7DA2025113FECD400BF472F /* collectcommand.cpp */, - A7DA2029113FECD400BF472F /* collectsharedcommand.cpp */, A7DA202A113FECD400BF472F /* collectsharedcommand.h */, - A7DA2031113FECD400BF472F /* consensuscommand.cpp */, + A7DA2029113FECD400BF472F /* collectsharedcommand.cpp */, A7DA2032113FECD400BF472F /* consensuscommand.h */, + A7DA2031113FECD400BF472F /* consensuscommand.cpp */, A7118EE511CFCAC000CFDE03 /* degapseqscommand.h */, A7118EE611CFCAC000CFDE03 /* degapseqscommand.cpp */, - A7DA203A113FECD400BF472F /* deconvolutecommand.cpp */, A7DA203B113FECD400BF472F /* deconvolutecommand.h */, - A7DA203E113FECD400BF472F /* distancecommand.cpp */, + A7DA203A113FECD400BF472F /* deconvolutecommand.cpp */, A7DA203F113FECD400BF472F /* distancecommand.h */, - A7DA204F113FECD400BF472F /* filterseqscommand.cpp */, + A7DA203E113FECD400BF472F /* distancecommand.cpp */, A7DA2050113FECD400BF472F /* filterseqscommand.h */, - A7DA205A113FECD400BF472F /* getgroupcommand.cpp */, + A7DA204F113FECD400BF472F /* filterseqscommand.cpp */, A7DA205B113FECD400BF472F /* getgroupcommand.h */, - A7DA205C113FECD400BF472F /* getlabelcommand.cpp */, + A7DA205A113FECD400BF472F /* getgroupcommand.cpp */, A7DA205D113FECD400BF472F /* getlabelcommand.h */, + A7DA205C113FECD400BF472F /* getlabelcommand.cpp */, A787A24F124CB46C0076EB84 /* getlineagecommand.h */, A787A250124CB46C0076EB84 /* getlineagecommand.cpp */, A7DA205F113FECD400BF472F /* getlistcountcommand.h */, A7DA205E113FECD400BF472F /* getlistcountcommand.cpp */, A7DA2061113FECD400BF472F /* getoturepcommand.h */, A7DA2060113FECD400BF472F /* getoturepcommand.cpp */, - A7DA2062113FECD400BF472F /* getrabundcommand.cpp */, A7DA2063113FECD400BF472F /* getrabundcommand.h */, + A7DA2062113FECD400BF472F /* getrabundcommand.cpp */, A7118F0F11CFD5DC00CFDE03 /* getrelabundcommand.h */, A7118F1011CFD5DC00CFDE03 /* getrelabundcommand.cpp */, - A7DA2064113FECD400BF472F /* getsabundcommand.cpp */, A7DA2065113FECD400BF472F /* getsabundcommand.h */, + A7DA2064113FECD400BF472F /* getsabundcommand.cpp */, A7DA2067113FECD400BF472F /* getseqscommand.h */, A7DA2066113FECD400BF472F /* getseqscommand.cpp */, - A7DA2068113FECD400BF472F /* getsharedotucommand.cpp */, A7DA2069113FECD400BF472F /* getsharedotucommand.h */, - A7DA2074113FECD400BF472F /* hclustercommand.cpp */, + A7DA2068113FECD400BF472F /* getsharedotucommand.cpp */, A7DA2075113FECD400BF472F /* hclustercommand.h */, - A7DA2078113FECD400BF472F /* heatmapcommand.cpp */, + A7DA2074113FECD400BF472F /* hclustercommand.cpp */, A7DA2079113FECD400BF472F /* heatmapcommand.h */, - A7DA207C113FECD400BF472F /* heatmapsimcommand.cpp */, + A7DA2078113FECD400BF472F /* heatmapcommand.cpp */, A7DA207D113FECD400BF472F /* heatmapsimcommand.h */, - A7DA207E113FECD400BF472F /* helpcommand.cpp */, + A7DA207C113FECD400BF472F /* heatmapsimcommand.cpp */, A7DA207F113FECD400BF472F /* helpcommand.h */, + A7DA207E113FECD400BF472F /* helpcommand.cpp */, A7DA208E113FECD400BF472F /* libshuffcommand.h */, A7DA208D113FECD400BF472F /* libshuffcommand.cpp */, A7DA2090113FECD400BF472F /* listseqscommand.h */, A7DA208F113FECD400BF472F /* listseqscommand.cpp */, A703FE931194645F002C397E /* makegroupcommand.h */, A703FE941194645F002C397E /* makegroupcommand.cpp */, - A7DA2098113FECD400BF472F /* matrixoutputcommand.cpp */, A7DA2099113FECD400BF472F /* matrixoutputcommand.h */, - A7DA209A113FECD400BF472F /* mergefilecommand.cpp */, + A7DA2098113FECD400BF472F /* matrixoutputcommand.cpp */, A7DA209B113FECD400BF472F /* mergefilecommand.h */, + A7DA209A113FECD400BF472F /* mergefilecommand.cpp */, A7F6C8EA12423C0300299875 /* metastatscommand.h */, A7F6C8EB12423C0300299875 /* metastatscommand.cpp */, - A7DA209C113FECD400BF472F /* mgclustercommand.cpp */, A7DA209D113FECD400BF472F /* mgclustercommand.h */, - A7DA20AC113FECD400BF472F /* nocommands.cpp */, + A7DA209C113FECD400BF472F /* mgclustercommand.cpp */, A7DA20AD113FECD400BF472F /* nocommands.h */, + A7DA20AC113FECD400BF472F /* nocommands.cpp */, A798626D1240D91B005FC847 /* normalizesharedcommand.h */, A798626E1240D91B005FC847 /* normalizesharedcommand.cpp */, - A7DA20B8113FECD400BF472F /* otuhierarchycommand.cpp */, A7DA20B9113FECD400BF472F /* otuhierarchycommand.h */, + A7DA20B8113FECD400BF472F /* otuhierarchycommand.cpp */, A724C2B61254961E006BB1C7 /* parsefastaqcommand.h */, A724C2B71254961E006BB1C7 /* parsefastaqcommand.cpp */, - A7DA20BC113FECD400BF472F /* parselistscommand.cpp */, A7DA20BD113FECD400BF472F /* parselistscommand.h */, + A7DA20BC113FECD400BF472F /* parselistscommand.cpp */, A7E8338C115BBDAA00739EC4 /* parsesffcommand.h */, A7E8338B115BBDAA00739EC4 /* parsesffcommand.cpp */, - A7DA20C0113FECD400BF472F /* parsimonycommand.cpp */, A7DA20C1113FECD400BF472F /* parsimonycommand.h */, + A7DA20C0113FECD400BF472F /* parsimonycommand.cpp */, A7DA20C3113FECD400BF472F /* pcacommand.h */, A7DA20C2113FECD400BF472F /* pcacommand.cpp */, A72B3A62118B37FD004B9F8D /* phylodiversitycommand.h */, A72B3A63118B37FD004B9F8D /* phylodiversitycommand.cpp */, A7DA20C7113FECD400BF472F /* phylotypecommand.h */, A7DA20C6113FECD400BF472F /* phylotypecommand.cpp */, + A72C66A1125B356F0058C2F9 /* pipelinepdscommand.h */, + A72C66A2125B356F0058C2F9 /* pipelinepdscommand.cpp */, A7DA20CB113FECD400BF472F /* preclustercommand.h */, A7DA20CA113FECD400BF472F /* preclustercommand.cpp */, A7DA20D1113FECD400BF472F /* quitcommand.h */, diff --git a/aligncommand.cpp b/aligncommand.cpp index ccf5eeb..b4af28a 100644 --- a/aligncommand.cpp +++ b/aligncommand.cpp @@ -27,10 +27,57 @@ //********************************************************************************************************************** - +vector AlignCommand::getValidParameters(){ + try { + string AlignArray[] = {"template","candidate","search","ksize","align","match","mismatch","gapopen","gapextend", "processors","flip","threshold","outputdir","inputdir"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "AlignCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector AlignCommand::getRequiredParameters(){ + try { + string AlignArray[] = {"template","candidate"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "AlignCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector AlignCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "AlignCommand", "getRequiredFiles"); + exit(1); + } +} +//********************************************************************************************************************** +AlignCommand::AlignCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["alignreport"] = tempOutNames; + outputTypes["accnos"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "AlignCommand", "AlignCommand"); + exit(1); + } +} +//********************************************************************************************************************** AlignCommand::AlignCommand(string option) { try { - abort = false; //allow user to run help @@ -52,7 +99,13 @@ AlignCommand::AlignCommand(string option) { for (it = parameters.begin(); it != parameters.end(); it++) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } - + + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["alignreport"] = tempOutNames; + outputTypes["accnos"] = tempOutNames; + //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; } @@ -112,6 +165,17 @@ AlignCommand::AlignCommand(string option) { candidateFileNames[i] = tryPath; } } + + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getOutputDir() != "") { //default path is set + string tryPath = m->getOutputDir() + m->getSimpleName(candidateFileNames[i]); + m->mothurOut("Unable to open " + candidateFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); + candidateFileNames[i] = tryPath; + } + } + in.close(); if (ableToOpen == 1) { @@ -165,7 +229,6 @@ AlignCommand::AlignCommand(string option) { exit(1); } } - //********************************************************************************************************************** AlignCommand::~AlignCommand(){ @@ -225,10 +288,9 @@ int AlignCommand::execute(){ m->mothurOutEndLine(); alignment = new NeedlemanOverlap(gapOpen, match, misMatch, longestBase); } - vector outputNames; for (int s = 0; s < candidateFileNames.size(); s++) { - if (m->control_pressed) { return 0; } + if (m->control_pressed) { outputTypes.clear(); return 0; } m->mothurOut("Aligning sequences from " + candidateFileNames[s] + " ..." ); m->mothurOutEndLine(); @@ -277,7 +339,7 @@ int AlignCommand::execute(){ MPI_File_open(MPI_COMM_WORLD, outReportFilename, outMode, MPI_INFO_NULL, &outMPIReport); MPI_File_open(MPI_COMM_WORLD, outAccnosFilename, outMode, MPI_INFO_NULL, &outMPIAccnos); - if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPIAlign); MPI_File_close(&outMPIReport); MPI_File_close(&outMPIAccnos); return 0; } + if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPIAlign); MPI_File_close(&outMPIReport); MPI_File_close(&outMPIAccnos); outputTypes.clear(); return 0; } if (pid == 0) { //you are the root process @@ -297,7 +359,7 @@ int AlignCommand::execute(){ //align your part driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPIAlign, outMPIReport, outMPIAccnos, MPIPos); - if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPIAlign); MPI_File_close(&outMPIReport); MPI_File_close(&outMPIAccnos); return 0; } + if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPIAlign); MPI_File_close(&outMPIReport); MPI_File_close(&outMPIAccnos); outputTypes.clear(); return 0; } for (int i = 1; i < processors; i++) { bool tempResult; @@ -319,7 +381,7 @@ int AlignCommand::execute(){ //align your part driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPIAlign, outMPIReport, outMPIAccnos, MPIPos); - if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPIAlign); MPI_File_close(&outMPIReport); MPI_File_close(&outMPIAccnos); return 0; } + if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPIAlign); MPI_File_close(&outMPIReport); MPI_File_close(&outMPIAccnos); outputTypes.clear(); return 0; } MPI_Send(&MPIWroteAccnos, 1, MPI_INT, 0, tag, MPI_COMM_WORLD); } @@ -357,7 +419,7 @@ int AlignCommand::execute(){ if(processors == 1){ numFastaSeqs = driver(lines[0], alignFileName, reportFileName, accnosFileName, candidateFileNames[s]); - if (m->control_pressed) { remove(accnosFileName.c_str()); remove(alignFileName.c_str()); remove(reportFileName.c_str()); return 0; } + if (m->control_pressed) { remove(accnosFileName.c_str()); remove(alignFileName.c_str()); remove(reportFileName.c_str()); outputTypes.clear(); return 0; } //delete accnos file if its blank else report to user if (m->isBlank(accnosFileName)) { remove(accnosFileName.c_str()); hasAccnos = false; } @@ -408,12 +470,12 @@ int AlignCommand::execute(){ m->mothurOutEndLine(); }else{ hasAccnos = false; } - if (m->control_pressed) { remove(accnosFileName.c_str()); remove(alignFileName.c_str()); remove(reportFileName.c_str()); return 0; } + if (m->control_pressed) { remove(accnosFileName.c_str()); remove(alignFileName.c_str()); remove(reportFileName.c_str()); outputTypes.clear(); return 0; } } #else numFastaSeqs = driver(lines[0], alignFileName, reportFileName, accnosFileName, candidateFileNames[s]); - if (m->control_pressed) { remove(accnosFileName.c_str()); remove(alignFileName.c_str()); remove(reportFileName.c_str()); return 0; } + if (m->control_pressed) { remove(accnosFileName.c_str()); remove(alignFileName.c_str()); remove(reportFileName.c_str()); outputTypes.clear(); return 0; } //delete accnos file if its blank else report to user if (m->isBlank(accnosFileName)) { remove(accnosFileName.c_str()); hasAccnos = false; } @@ -436,9 +498,9 @@ int AlignCommand::execute(){ if (pid == 0) { //only one process should output to screen #endif - outputNames.push_back(alignFileName); - outputNames.push_back(reportFileName); - if (hasAccnos) { outputNames.push_back(accnosFileName); } + outputNames.push_back(alignFileName); outputTypes["fasta"].push_back(alignFileName); + outputNames.push_back(reportFileName); outputTypes["alignreport"].push_back(reportFileName); + if (hasAccnos) { outputNames.push_back(accnosFileName); outputTypes["accnos"].push_back(accnosFileName); } #ifdef USE_MPI } diff --git a/aligncommand.h b/aligncommand.h index 1167c93..1410626 100644 --- a/aligncommand.h +++ b/aligncommand.h @@ -20,7 +20,12 @@ class AlignCommand : public Command { public: AlignCommand(string); + AlignCommand(); ~AlignCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -33,6 +38,7 @@ private: vector processIDS; //processid vector lines; bool MPIWroteAccnos; + map > outputTypes; AlignmentDB* templateDB; Alignment* alignment; @@ -50,6 +56,7 @@ private: float match, misMatch, gapOpen, gapExtend, threshold; int processors, kmerSize; vector candidateFileNames; + vector outputNames; bool abort, flip; }; diff --git a/bayesian.cpp b/bayesian.cpp index 531abc5..8051866 100644 --- a/bayesian.cpp +++ b/bayesian.cpp @@ -76,9 +76,9 @@ Classify(), kmerSize(ksize), confidenceThreshold(cutoff), iters(i) { //initialze probabilities wordGenusProb.resize(numKmers); - + cout << numKmers << '\t' << genusNodes.size() << endl; for (int j = 0; j < wordGenusProb.size(); j++) { wordGenusProb[j].resize(genusNodes.size()); } - + cout << numKmers << '\t' << genusNodes.size() << endl; ofstream out; ofstream out2; diff --git a/binsequencecommand.cpp b/binsequencecommand.cpp index a761d5a..a1c965b 100644 --- a/binsequencecommand.cpp +++ b/binsequencecommand.cpp @@ -9,6 +9,54 @@ #include "binsequencecommand.h" +//********************************************************************************************************************** +vector BinSeqCommand::getValidParameters(){ + try { + string AlignArray[] = {"fasta","label","name", "group","outputdir","inputdir"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "BinSeqCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector BinSeqCommand::getRequiredParameters(){ + try { + string AlignArray[] = {"fasta"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "BinSeqCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector BinSeqCommand::getRequiredFiles(){ + try { + string AlignArray[] = {"list"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "BinSeqCommand", "getRequiredFiles"); + exit(1); + } +} +//********************************************************************************************************************** +BinSeqCommand::BinSeqCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "BinSeqCommand", "BinSeqCommand"); + exit(1); + } +} //********************************************************************************************************************** BinSeqCommand::BinSeqCommand(string option) { try { @@ -36,6 +84,10 @@ BinSeqCommand::BinSeqCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; @@ -316,7 +368,7 @@ int BinSeqCommand::process(ListVector* list) { m->openOutputFile(outputFileName, out); //save to output list of output file names - outputNames.push_back(outputFileName); + outputNames.push_back(outputFileName); outputTypes["fasta"].push_back(outputFileName); m->mothurOut(list->getLabel()); m->mothurOutEndLine(); diff --git a/binsequencecommand.h b/binsequencecommand.h index 6ea7305..df7ea75 100644 --- a/binsequencecommand.h +++ b/binsequencecommand.h @@ -25,7 +25,12 @@ class BinSeqCommand : public Command { public: BinSeqCommand(string); + BinSeqCommand(); ~BinSeqCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -42,6 +47,7 @@ private: ofstream out; ifstream in, inNames; vector outputNames; + map > outputTypes; void readNamesFile(); int process(ListVector*); diff --git a/bootstrapsharedcommand.cpp b/bootstrapsharedcommand.cpp index 9424347..2b7232d 100644 --- a/bootstrapsharedcommand.cpp +++ b/bootstrapsharedcommand.cpp @@ -19,9 +19,54 @@ #include "sharedmorisitahorn.h" #include "sharedbraycurtis.h" - //********************************************************************************************************************** - +vector BootSharedCommand::getValidParameters(){ + try { + string AlignArray[] = {"label","calc","groups","iters","outputdir","inputdir"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "BootSharedCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +BootSharedCommand::BootSharedCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["tree"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "BootSharedCommand", "BootSharedCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector BootSharedCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "BootSharedCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector BootSharedCommand::getRequiredFiles(){ + try { + string AlignArray[] = {"shared"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "BootSharedCommand", "getRequiredFiles"); + exit(1); + } +} +//********************************************************************************************************************** BootSharedCommand::BootSharedCommand(string option) { try { globaldata = GlobalData::getInstance(); @@ -49,6 +94,10 @@ BootSharedCommand::BootSharedCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["tree"] = tempOutNames; + //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; @@ -410,7 +459,7 @@ int BootSharedCommand::process(SharedOrderVector* order) { //create a new filename outputFile = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + treeCalculators[z]->getName() + ".boot" + order->getLabel() + ".tre"; m->openOutputFile(outputFile, *(out[z])); - outputNames.push_back(outputFile); + outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile); } m->mothurOut("Generating bootstrap trees..."); cout.flush(); diff --git a/bootstrapsharedcommand.h b/bootstrapsharedcommand.h index be4a764..53f6a26 100644 --- a/bootstrapsharedcommand.h +++ b/bootstrapsharedcommand.h @@ -27,7 +27,12 @@ class BootSharedCommand : public Command { public: BootSharedCommand(string); + BootSharedCommand(); ~BootSharedCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -59,6 +64,7 @@ private: string outputFile, calc, groups, label, outputDir; int numGroups, iters; vector Estimators, Groups, outputNames; //holds estimators to be used + map< string, vector > outputTypes; }; diff --git a/catchallcommand.cpp b/catchallcommand.cpp index b185b9f..d6264db 100644 --- a/catchallcommand.cpp +++ b/catchallcommand.cpp @@ -10,6 +10,53 @@ #include "catchallcommand.h" #include "globaldata.hpp" +//********************************************************************************************************************** +vector CatchAllCommand::getValidParameters(){ + try { + string AlignArray[] = {"sabund","label","inputdir","outputdir"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "CatchAllCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +CatchAllCommand::CatchAllCommand(){ + try { + //initialize outputTypes + + //need to determine outputFIles and types + } + catch(exception& e) { + m->errorOut(e, "CatchAllCommand", "CatchAllCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector CatchAllCommand::getRequiredParameters(){ + try { + string AlignArray[] = {"sabund"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "CatchAllCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector CatchAllCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "CatchAllCommand", "getRequiredFiles"); + exit(1); + } +} /**************************************************************************************/ CatchAllCommand::CatchAllCommand(string option) { try { @@ -36,6 +83,11 @@ CatchAllCommand::CatchAllCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + + //initialize outputTypes + //need to determine outputFIles and types + + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -53,7 +105,7 @@ CatchAllCommand::CatchAllCommand(string option) { //check for required parameters sabundfile = validParameter.validFile(parameters, "sabund", true); if (sabundfile == "not open") { sabundfile = ""; abort = true; } - else if (sabundfile == "not found") { sabundfile = ""; m->mothurOut("You must provide either a sabund file for the catchall command."); m->mothurOutEndLine(); abort=true; } + else if (sabundfile == "not found") { sabundfile = ""; m->mothurOut("You must provide a sabund file for the catchall command."); m->mothurOutEndLine(); abort=true; } else { globaldata->setSabundFile(sabundfile); globaldata->setFormat("sabund"); } string label = validParameter.validFile(parameters, "label", false); @@ -99,8 +151,6 @@ int CatchAllCommand::execute() { if (abort == true) { return 0; } - vector outputNames; - //prepare full output directory outputDir = m->getFullPathName(outputDir); diff --git a/catchallcommand.h b/catchallcommand.h index ac9f115..186185d 100644 --- a/catchallcommand.h +++ b/catchallcommand.h @@ -26,7 +26,12 @@ class CatchAllCommand : public Command { public: CatchAllCommand(string); - ~CatchAllCommand() {}; + CatchAllCommand(); + ~CatchAllCommand() {} + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map< string, vector > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -39,6 +44,8 @@ private: string outputDir, sabundfile, rabundfile, listfile, format; bool abort, allLines; set labels; + vector outputNames; + map< string, vector > outputTypes; string process(SAbundVector*); }; diff --git a/chimerabellerophoncommand.cpp b/chimerabellerophoncommand.cpp index 5972c62..6d0a116 100644 --- a/chimerabellerophoncommand.cpp +++ b/chimerabellerophoncommand.cpp @@ -10,8 +10,55 @@ #include "chimerabellerophoncommand.h" #include "bellerophon.h" +//********************************************************************************************************************** +vector ChimeraBellerophonCommand::getValidParameters(){ + try { + string AlignArray[] = {"fasta","filter","correction","processors","window","increment","outputdir","inputdir"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ChimeraBellerophonCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ChimeraBellerophonCommand::getRequiredParameters(){ + try { + string AlignArray[] = {"fasta"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ChimeraBellerophonCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ChimeraBellerophonCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ChimeraBellerophonCommand", "getRequiredFiles"); + exit(1); + } +} +//********************************************************************************************************************** +ChimeraBellerophonCommand::ChimeraBellerophonCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["chimera"] = tempOutNames; + outputTypes["accnos"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "ChimeraBellerophonCommand", "ChimeraBellerophonCommand"); + exit(1); + } +} //*************************************************************************************************************** - ChimeraBellerophonCommand::ChimeraBellerophonCommand(string option) { try { abort = false; @@ -35,6 +82,11 @@ ChimeraBellerophonCommand::ChimeraBellerophonCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["chimera"] = tempOutNames; + outputTypes["accnos"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -66,6 +118,17 @@ ChimeraBellerophonCommand::ChimeraBellerophonCommand(string option) { fastaFileNames[i] = tryPath; } } + + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getOutputDir() != "") { //default path is set + string tryPath = m->getOutputDir() + m->getSimpleName(fastaFileNames[i]); + m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); + fastaFileNames[i] = tryPath; + } + } + in.close(); if (ableToOpen == 1) { @@ -156,7 +219,7 @@ int ChimeraBellerophonCommand::execute(){ chimera->getChimeras(); - if (m->control_pressed) { delete chimera; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { delete chimera; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); return 0; } #ifdef USE_MPI MPI_File outMPI; @@ -192,12 +255,12 @@ int ChimeraBellerophonCommand::execute(){ #endif - if (m->control_pressed) { remove(accnosFileName.c_str()); remove(outputFileName.c_str()); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } delete chimera; return 0; } + if (m->control_pressed) { remove(accnosFileName.c_str()); remove(outputFileName.c_str()); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); delete chimera; return 0; } m->mothurOutEndLine(); m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(numSeqs) + " sequences."); m->mothurOutEndLine(); m->mothurOutEndLine(); - outputNames.push_back(outputFileName); - outputNames.push_back(accnosFileName); + outputNames.push_back(outputFileName); outputTypes["chimera"].push_back(outputFileName); + outputNames.push_back(accnosFileName); outputTypes["accnos"].push_back(accnosFileName); delete chimera; } diff --git a/chimerabellerophoncommand.h b/chimerabellerophoncommand.h index 4ff7f79..6e1ae50 100644 --- a/chimerabellerophoncommand.h +++ b/chimerabellerophoncommand.h @@ -20,7 +20,12 @@ class ChimeraBellerophonCommand : public Command { public: ChimeraBellerophonCommand(string); + ChimeraBellerophonCommand(); ~ChimeraBellerophonCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map< string, vector > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -31,6 +36,7 @@ private: int processors, window, increment, numSeqs; Chimera* chimera; vector outputNames; + map > outputTypes; vector fastaFileNames; }; diff --git a/chimeraccodecommand.cpp b/chimeraccodecommand.cpp index ab10eb8..1f6a5a5 100644 --- a/chimeraccodecommand.cpp +++ b/chimeraccodecommand.cpp @@ -10,8 +10,55 @@ #include "chimeraccodecommand.h" #include "ccode.h" +//********************************************************************************************************************** +vector ChimeraCcodeCommand::getValidParameters(){ + try { + string AlignArray[] = {"fasta", "filter", "processors", "window", "template", "mask", "numwanted", "outputdir","inputdir" }; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ChimeraCcodeCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +ChimeraCcodeCommand::ChimeraCcodeCommand(){ + try { + vector tempOutNames; + outputTypes["chimera"] = tempOutNames; + outputTypes["mapinfo"] = tempOutNames; + outputTypes["accnos"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "ChimeraCcodeCommand", "ChimeraCcodeCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector ChimeraCcodeCommand::getRequiredParameters(){ + try { + string AlignArray[] = {"template","fasta"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ChimeraCcodeCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ChimeraCcodeCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ChimeraCcodeCommand", "getRequiredFiles"); + exit(1); + } +} //*************************************************************************************************************** - ChimeraCcodeCommand::ChimeraCcodeCommand(string option) { try { abort = false; @@ -21,7 +68,7 @@ ChimeraCcodeCommand::ChimeraCcodeCommand(string option) { else { //valid paramters for this command - string Array[] = {"fasta", "filter", "processors", "window", "template", "mask", "numwanted", "outputdir","inputdir", }; + string Array[] = {"fasta", "filter", "processors", "window", "template", "mask", "numwanted", "outputdir","inputdir" }; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); OptionParser parser(option); @@ -35,6 +82,11 @@ ChimeraCcodeCommand::ChimeraCcodeCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + vector tempOutNames; + outputTypes["chimera"] = tempOutNames; + outputTypes["mapinfo"] = tempOutNames; + outputTypes["accnos"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -77,6 +129,17 @@ ChimeraCcodeCommand::ChimeraCcodeCommand(string option) { fastaFileNames[i] = tryPath; } } + + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getOutputDir() != "") { //default path is set + string tryPath = m->getOutputDir() + m->getSimpleName(fastaFileNames[i]); + m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); + fastaFileNames[i] = tryPath; + } + } + in.close(); if (ableToOpen == 1) { @@ -201,7 +264,7 @@ int ChimeraCcodeCommand::execute(){ string mapInfo = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "mapinfo"; - if (m->control_pressed) { delete chimera; for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } return 0; } + if (m->control_pressed) { delete chimera; for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } outputTypes.clear(); return 0; } #ifdef USE_MPI @@ -233,7 +296,7 @@ int ChimeraCcodeCommand::execute(){ MPI_File_open(MPI_COMM_WORLD, outFilename, outMode, MPI_INFO_NULL, &outMPI); MPI_File_open(MPI_COMM_WORLD, outAccnosFilename, outMode, MPI_INFO_NULL, &outMPIAccnos); - if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPI); MPI_File_close(&outMPIAccnos); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } delete chimera; return 0; } + if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPI); MPI_File_close(&outMPIAccnos); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } outputTypes.clear(); delete chimera; return 0; } if (pid == 0) { //you are the root process string outTemp = "For full window mapping info refer to " + mapInfo + "\n\n"; @@ -263,7 +326,7 @@ int ChimeraCcodeCommand::execute(){ //align your part driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPI, outMPIAccnos, MPIPos); - if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPI); MPI_File_close(&outMPIAccnos); remove(outputFileName.c_str()); remove(accnosFileName.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } delete chimera; return 0; } + if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPI); MPI_File_close(&outMPIAccnos); remove(outputFileName.c_str()); remove(accnosFileName.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } outputTypes.clear(); delete chimera; return 0; } }else{ //you are a child process MPI_Recv(&numSeqs, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status); @@ -279,7 +342,7 @@ int ChimeraCcodeCommand::execute(){ //align your part driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPI, outMPIAccnos, MPIPos); - if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPI); MPI_File_close(&outMPIAccnos); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } delete chimera; return 0; } + if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPI); MPI_File_close(&outMPIAccnos); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } outputTypes.clear(); delete chimera; return 0; } } //close files @@ -310,7 +373,7 @@ int ChimeraCcodeCommand::execute(){ numSeqs = driver(lines[0], outputFileName, fastaFileNames[s], accnosFileName); - if (m->control_pressed) { remove(outputFileName.c_str()); remove(tempHeader.c_str()); remove(accnosFileName.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); delete chimera; return 0; } + if (m->control_pressed) { remove(outputFileName.c_str()); remove(tempHeader.c_str()); remove(accnosFileName.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } for (int i = 0; i < lines.size(); i++) { delete lines[i]; } outputTypes.clear(); lines.clear(); delete chimera; return 0; } }else{ processIDS.resize(0); @@ -335,7 +398,7 @@ int ChimeraCcodeCommand::execute(){ if (m->control_pressed) { remove(outputFileName.c_str()); remove(accnosFileName.c_str()); - for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } + for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } outputTypes.clear(); for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); delete chimera; return 0; @@ -346,7 +409,7 @@ int ChimeraCcodeCommand::execute(){ #else numSeqs = driver(lines[0], outputFileName, fastaFileNames[s], accnosFileName); - if (m->control_pressed) { remove(outputFileName.c_str()); remove(tempHeader.c_str()); remove(accnosFileName.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); delete chimera; return 0; } + if (m->control_pressed) { remove(outputFileName.c_str()); remove(tempHeader.c_str()); remove(accnosFileName.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } for (int i = 0; i < lines.size(); i++) { delete lines[i]; } outputTypes.clear(); lines.clear(); delete chimera; return 0; } #endif @@ -358,10 +421,10 @@ int ChimeraCcodeCommand::execute(){ delete chimera; - outputNames.push_back(outputFileName); - outputNames.push_back(mapInfo); - outputNames.push_back(accnosFileName); - + outputNames.push_back(outputFileName); outputTypes["chimera"].push_back(outputFileName); + outputNames.push_back(mapInfo); outputTypes["mapinfo"].push_back(mapInfo); + outputNames.push_back(accnosFileName); outputTypes["accnos"].push_back(accnosFileName); + for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); m->mothurOutEndLine(); m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(numSeqs) + " sequences."); m->mothurOutEndLine(); diff --git a/chimeraccodecommand.h b/chimeraccodecommand.h index d980288..a9ed223 100644 --- a/chimeraccodecommand.h +++ b/chimeraccodecommand.h @@ -20,7 +20,12 @@ class ChimeraCcodeCommand : public Command { public: ChimeraCcodeCommand(string); + ChimeraCcodeCommand(); ~ChimeraCcodeCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -47,6 +52,7 @@ private: Chimera* chimera; vector fastaFileNames; vector outputNames; + map > outputTypes; }; diff --git a/chimeracheckcommand.cpp b/chimeracheckcommand.cpp index ac09208..2591460 100644 --- a/chimeracheckcommand.cpp +++ b/chimeracheckcommand.cpp @@ -9,8 +9,53 @@ #include "chimeracheckcommand.h" +//********************************************************************************************************************** +vector ChimeraCheckCommand::getValidParameters(){ + try { + string AlignArray[] = {"fasta","processors","increment","template","ksize","svg", "name","outputdir","inputdir" }; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ChimeraCheckCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ChimeraCheckCommand::getRequiredParameters(){ + try { + string AlignArray[] = {"template","fasta"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ChimeraCheckCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ChimeraCheckCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ChimeraCheckCommand", "getRequiredFiles"); + exit(1); + } +} +//********************************************************************************************************************** +ChimeraCheckCommand::ChimeraCheckCommand(){ + try { + vector tempOutNames; + outputTypes["chimera"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "ChimeraCheckCommand", "ChimeraCheckCommand"); + exit(1); + } +} //*************************************************************************************************************** - ChimeraCheckCommand::ChimeraCheckCommand(string option) { try { abort = false; @@ -34,6 +79,9 @@ ChimeraCheckCommand::ChimeraCheckCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + vector tempOutNames; + outputTypes["chimera"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -75,6 +123,17 @@ ChimeraCheckCommand::ChimeraCheckCommand(string option) { fastaFileNames[i] = tryPath; } } + + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getOutputDir() != "") { //default path is set + string tryPath = m->getOutputDir() + m->getSimpleName(fastaFileNames[i]); + m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); + fastaFileNames[i] = tryPath; + } + } + in.close(); if (ableToOpen == 1) { @@ -123,6 +182,17 @@ ChimeraCheckCommand::ChimeraCheckCommand(string option) { nameFileNames[i] = tryPath; } } + + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getOutputDir() != "") { //default path is set + string tryPath = m->getOutputDir() + m->getSimpleName(nameFileNames[i]); + m->mothurOut("Unable to open " + nameFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); + nameFileNames[i] = tryPath; + } + } + in.close(); if (ableToOpen == 1) { @@ -219,7 +289,7 @@ int ChimeraCheckCommand::execute(){ if (outputDir == "") { outputDir = m->hasPath(fastaFileNames[i]); }//if user entered a file with a path then preserve it string outputFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[i])) + "chimeracheck.chimeras"; - outputNames.push_back(outputFileName); + outputNames.push_back(outputFileName); outputTypes["chimera"].push_back(outputFileName); #ifdef USE_MPI @@ -246,7 +316,7 @@ int ChimeraCheckCommand::execute(){ MPI_File_open(MPI_COMM_WORLD, inFileName, inMode, MPI_INFO_NULL, &inMPI); //comm, filename, mode, info, filepointer MPI_File_open(MPI_COMM_WORLD, outFilename, outMode, MPI_INFO_NULL, &outMPI); - if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPI); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } delete chimera; return 0; } + if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPI); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } outputTypes.clear(); delete chimera; return 0; } if (pid == 0) { //you are the root process MPIPos = m->setFilePosFasta(fastaFileNames[i], numSeqs); //fills MPIPos, returns numSeqs @@ -266,7 +336,7 @@ int ChimeraCheckCommand::execute(){ //align your part driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPI, MPIPos); - if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPI); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } delete chimera; return 0; } + if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPI); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } outputTypes.clear(); delete chimera; return 0; } //wait on chidren for(int j = 1; j < processors; j++) { @@ -286,7 +356,7 @@ int ChimeraCheckCommand::execute(){ //align your part driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPI, MPIPos); - if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPI); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } delete chimera; return 0; } + if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPI); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } outputTypes.clear(); delete chimera; return 0; } //tell parent you are done. char buf[5]; @@ -311,7 +381,7 @@ int ChimeraCheckCommand::execute(){ if(processors == 1){ numSeqs = driver(lines[0], outputFileName, fastaFileNames[i]); - if (m->control_pressed) { for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } for (int j = 0; j < lines.size(); j++) { delete lines[j]; } lines.clear(); delete chimera; return 0; } + if (m->control_pressed) { for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } for (int j = 0; j < lines.size(); j++) { delete lines[j]; } outputTypes.clear(); lines.clear(); delete chimera; return 0; } }else{ processIDS.resize(0); @@ -327,7 +397,7 @@ int ChimeraCheckCommand::execute(){ } if (m->control_pressed) { - for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } + for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } outputTypes.clear(); for (int j = 0; j < lines.size(); j++) { delete lines[j]; } lines.clear(); delete chimera; return 0; @@ -337,7 +407,7 @@ int ChimeraCheckCommand::execute(){ #else numSeqs = driver(lines[0], outputFileName, fastaFileNames[i]); - if (m->control_pressed) { for (int j = 0; j < lines.size(); j++) { delete lines[j]; } lines.clear(); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } delete chimera; return 0; } + if (m->control_pressed) { for (int j = 0; j < lines.size(); j++) { delete lines[j]; } lines.clear(); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } outputTypes.clear(); delete chimera; return 0; } #endif #endif delete chimera; diff --git a/chimeracheckcommand.h b/chimeracheckcommand.h index 71e1f0c..6e81812 100644 --- a/chimeracheckcommand.h +++ b/chimeracheckcommand.h @@ -21,7 +21,12 @@ class ChimeraCheckCommand : public Command { public: ChimeraCheckCommand(string); + ChimeraCheckCommand(); ~ChimeraCheckCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -51,6 +56,7 @@ private: vector fastaFileNames; vector nameFileNames; vector outputNames; + map > outputTypes; }; diff --git a/chimerapintailcommand.cpp b/chimerapintailcommand.cpp index 3013650..2dccd49 100644 --- a/chimerapintailcommand.cpp +++ b/chimerapintailcommand.cpp @@ -10,8 +10,54 @@ #include "chimerapintailcommand.h" #include "pintail.h" +//********************************************************************************************************************** +vector ChimeraPintailCommand::getValidParameters(){ + try { + string AlignArray[] = {"fasta","filter","processors","window" ,"increment","template","conservation","quantile","mask","outputdir","inputdir"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ChimeraPintailCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +ChimeraPintailCommand::ChimeraPintailCommand(){ + try { + vector tempOutNames; + outputTypes["chimera"] = tempOutNames; + outputTypes["accnos"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "ChimeraPintailCommand", "ChimeraPintailCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector ChimeraPintailCommand::getRequiredParameters(){ + try { + string AlignArray[] = {"template","fasta"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ChimeraPintailCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ChimeraPintailCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ChimeraPintailCommand", "getRequiredFiles"); + exit(1); + } +} //*************************************************************************************************************** - ChimeraPintailCommand::ChimeraPintailCommand(string option) { try { abort = false; @@ -35,6 +81,10 @@ ChimeraPintailCommand::ChimeraPintailCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + vector tempOutNames; + outputTypes["chimera"] = tempOutNames; + outputTypes["accnos"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -94,6 +144,16 @@ ChimeraPintailCommand::ChimeraPintailCommand(string option) { fastaFileNames[i] = tryPath; } } + + if (ableToOpen == 1) { + if (m->getOutputDir() != "") { //default path is set + string tryPath = m->getOutputDir() + m->getSimpleName(fastaFileNames[i]); + m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); + fastaFileNames[i] = tryPath; + } + } + in.close(); if (ableToOpen == 1) { @@ -140,7 +200,17 @@ ChimeraPintailCommand::ChimeraPintailCommand(string option) { maskfile = tryPath; } } - in.close(); + + if (ableToOpen == 1) { + if (m->getOutputDir() != "") { //default path is set + string tryPath = m->getOutputDir() + m->getSimpleName(maskfile); + m->mothurOut("Unable to open " + maskfile + ". Trying output directory " + tryPath); m->mothurOutEndLine(); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); + maskfile = tryPath; + } + } + + in.close(); if (ableToOpen == 1) { m->mothurOut("Unable to open " + maskfile + "."); m->mothurOutEndLine(); @@ -332,7 +402,7 @@ int ChimeraPintailCommand::execute(){ MPI_File_open(MPI_COMM_WORLD, outFilename, outMode, MPI_INFO_NULL, &outMPI); MPI_File_open(MPI_COMM_WORLD, outAccnosFilename, outMode, MPI_INFO_NULL, &outMPIAccnos); - if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPI); MPI_File_close(&outMPIAccnos); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } delete chimera; return 0; } + if (m->control_pressed) { outputTypes.clear(); MPI_File_close(&inMPI); MPI_File_close(&outMPI); MPI_File_close(&outMPIAccnos); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } delete chimera; return 0; } if (pid == 0) { //you are the root process @@ -352,7 +422,7 @@ int ChimeraPintailCommand::execute(){ //do your part driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPI, outMPIAccnos, MPIPos); - if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPI); MPI_File_close(&outMPIAccnos); remove(outputFileName.c_str()); remove(accnosFileName.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } delete chimera; return 0; } + if (m->control_pressed) { outputTypes.clear(); MPI_File_close(&inMPI); MPI_File_close(&outMPI); MPI_File_close(&outMPIAccnos); remove(outputFileName.c_str()); remove(accnosFileName.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } delete chimera; return 0; } }else{ //you are a child process MPI_Recv(&numSeqs, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status); @@ -367,7 +437,7 @@ int ChimeraPintailCommand::execute(){ //do your part driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPI, outMPIAccnos, MPIPos); - if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPI); MPI_File_close(&outMPIAccnos); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } delete chimera; return 0; } + if (m->control_pressed) { outputTypes.clear(); MPI_File_close(&inMPI); MPI_File_close(&outMPI); MPI_File_close(&outMPIAccnos); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } delete chimera; return 0; } } //close files @@ -388,7 +458,7 @@ int ChimeraPintailCommand::execute(){ numSeqs = driver(lines[0], outputFileName, fastaFileNames[s], accnosFileName); - if (m->control_pressed) { remove(outputFileName.c_str()); remove(accnosFileName.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); delete chimera; return 0; } + if (m->control_pressed) { outputTypes.clear(); remove(outputFileName.c_str()); remove(accnosFileName.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); delete chimera; return 0; } }else{ processIDS.resize(0); @@ -413,7 +483,7 @@ int ChimeraPintailCommand::execute(){ if (m->control_pressed) { remove(outputFileName.c_str()); remove(accnosFileName.c_str()); - for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } + for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } outputTypes.clear(); for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); delete chimera; return 0; @@ -423,7 +493,7 @@ int ChimeraPintailCommand::execute(){ #else numSeqs = driver(lines[0], outputFileName, fastaFileNames[s], accnosFileName); - if (m->control_pressed) { remove(outputFileName.c_str()); remove(accnosFileName.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); delete chimera; return 0; } + if (m->control_pressed) { outputTypes.clear(); remove(outputFileName.c_str()); remove(accnosFileName.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); delete chimera; return 0; } #endif #endif @@ -431,8 +501,8 @@ int ChimeraPintailCommand::execute(){ delete chimera; for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); - outputNames.push_back(outputFileName); - outputNames.push_back(accnosFileName); + outputNames.push_back(outputFileName); outputTypes["chimera"].push_back(outputFileName); + outputNames.push_back(accnosFileName); outputTypes["accnos"].push_back(accnosFileName); m->mothurOutEndLine(); m->mothurOutEndLine(); m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(numSeqs) + " sequences."); m->mothurOutEndLine(); diff --git a/chimerapintailcommand.h b/chimerapintailcommand.h index 9082204..d2b2e03 100644 --- a/chimerapintailcommand.h +++ b/chimerapintailcommand.h @@ -22,7 +22,12 @@ class ChimeraPintailCommand : public Command { public: ChimeraPintailCommand(string); + ChimeraPintailCommand(); ~ChimeraPintailCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -49,6 +54,7 @@ private: int processors, window, increment, numSeqs, templateSeqsLength; Chimera* chimera; vector outputNames; + map > outputTypes; vector fastaFileNames; diff --git a/chimeraseqscommand.cpp b/chimeraseqscommand.cpp index 663b894..9013e7d 100644 --- a/chimeraseqscommand.cpp +++ b/chimeraseqscommand.cpp @@ -9,6 +9,39 @@ #include "chimeraseqscommand.h" +//********************************************************************************************************************** +vector ChimeraSeqsCommand::getValidParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ChimeraSeqsCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ChimeraSeqsCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ChimeraSeqsCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ChimeraSeqsCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ChimeraSeqsCommand", "getRequiredFiles"); + exit(1); + } +} //*************************************************************************************************************** ChimeraSeqsCommand::ChimeraSeqsCommand(string option) {} diff --git a/chimeraseqscommand.h b/chimeraseqscommand.h index afbc259..7e51748 100644 --- a/chimeraseqscommand.h +++ b/chimeraseqscommand.h @@ -18,12 +18,19 @@ class ChimeraSeqsCommand : public Command { public: ChimeraSeqsCommand(string); + ChimeraSeqsCommand() {} ~ChimeraSeqsCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map< string, vector > getOutputFiles() { return outputTypes; } int execute(); void help(); private: + vector outputNames; + map< string, vector > outputTypes; }; diff --git a/chimeraslayercommand.cpp b/chimeraslayercommand.cpp index d2f3067..2172369 100644 --- a/chimeraslayercommand.cpp +++ b/chimeraslayercommand.cpp @@ -10,9 +10,55 @@ #include "chimeraslayercommand.h" #include "chimeraslayer.h" - +//********************************************************************************************************************** +vector ChimeraSlayerCommand::getValidParameters(){ + try { + string AlignArray[] = {"fasta", "processors", "window", "template","numwanted", "ksize", "match","mismatch", + "divergence", "minsim","mincov","minbs", "minsnp","parents", "iters","outputdir","inputdir", "search","realign" }; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ChimeraSlayerCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +ChimeraSlayerCommand::ChimeraSlayerCommand(){ + try { + vector tempOutNames; + outputTypes["chimera"] = tempOutNames; + outputTypes["accnos"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "ChimeraSlayerCommand", "ChimeraSlayerCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector ChimeraSlayerCommand::getRequiredParameters(){ + try { + string AlignArray[] = {"template","fasta"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ChimeraSlayerCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ChimeraSlayerCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ChimeraSlayerCommand", "getRequiredFiles"); + exit(1); + } +} //*************************************************************************************************************** - ChimeraSlayerCommand::ChimeraSlayerCommand(string option) { try { abort = false; @@ -37,6 +83,10 @@ ChimeraSlayerCommand::ChimeraSlayerCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + vector tempOutNames; + outputTypes["chimera"] = tempOutNames; + outputTypes["accnos"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -80,6 +130,16 @@ ChimeraSlayerCommand::ChimeraSlayerCommand(string option) { fastaFileNames[i] = tryPath; } } + + if (ableToOpen == 1) { + if (m->getOutputDir() != "") { //default path is set + string tryPath = m->getOutputDir() + m->getSimpleName(fastaFileNames[i]); + m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); + fastaFileNames[i] = tryPath; + } + } + in.close(); if (ableToOpen == 1) { @@ -258,7 +318,7 @@ int ChimeraSlayerCommand::execute(){ MPI_File_open(MPI_COMM_WORLD, outFilename, outMode, MPI_INFO_NULL, &outMPI); MPI_File_open(MPI_COMM_WORLD, outAccnosFilename, outMode, MPI_INFO_NULL, &outMPIAccnos); - if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPI); MPI_File_close(&outMPIAccnos); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } delete chimera; return 0; } + if (m->control_pressed) { outputTypes.clear(); MPI_File_close(&inMPI); MPI_File_close(&outMPI); MPI_File_close(&outMPIAccnos); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } delete chimera; return 0; } if (pid == 0) { //you are the root process m->mothurOutEndLine(); @@ -291,7 +351,7 @@ int ChimeraSlayerCommand::execute(){ //do your part driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPI, outMPIAccnos, MPIPos); - if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPI); MPI_File_close(&outMPIAccnos); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } remove(outputFileName.c_str()); remove(accnosFileName.c_str()); delete chimera; return 0; } + if (m->control_pressed) { outputTypes.clear(); MPI_File_close(&inMPI); MPI_File_close(&outMPI); MPI_File_close(&outMPIAccnos); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } remove(outputFileName.c_str()); remove(accnosFileName.c_str()); delete chimera; return 0; } }else{ //you are a child process MPI_Recv(&numSeqs, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status); @@ -306,7 +366,7 @@ int ChimeraSlayerCommand::execute(){ //do your part driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPI, outMPIAccnos, MPIPos); - if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPI); MPI_File_close(&outMPIAccnos); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } delete chimera; return 0; } + if (m->control_pressed) { outputTypes.clear(); MPI_File_close(&inMPI); MPI_File_close(&outMPI); MPI_File_close(&outMPIAccnos); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } delete chimera; return 0; } } //close files @@ -334,7 +394,7 @@ int ChimeraSlayerCommand::execute(){ if(processors == 1){ numSeqs = driver(lines[0], outputFileName, fastaFileNames[s], accnosFileName); - if (m->control_pressed) { remove(outputFileName.c_str()); remove(tempHeader.c_str()); remove(accnosFileName.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); delete chimera; return 0; } + if (m->control_pressed) { outputTypes.clear(); remove(outputFileName.c_str()); remove(tempHeader.c_str()); remove(accnosFileName.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); delete chimera; return 0; } }else{ processIDS.resize(0); @@ -356,13 +416,13 @@ int ChimeraSlayerCommand::execute(){ remove((accnosFileName + toString(processIDS[i]) + ".temp").c_str()); } - if (m->control_pressed) { remove(outputFileName.c_str()); remove(accnosFileName.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); delete chimera; return 0; } + if (m->control_pressed) { outputTypes.clear(); remove(outputFileName.c_str()); remove(accnosFileName.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); delete chimera; return 0; } } #else numSeqs = driver(lines[0], outputFileName, fastaFileNames[s], accnosFileName); - if (m->control_pressed) { remove(outputFileName.c_str()); remove(tempHeader.c_str()); remove(accnosFileName.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); delete chimera; return 0; } + if (m->control_pressed) { outputTypes.clear(); remove(outputFileName.c_str()); remove(tempHeader.c_str()); remove(accnosFileName.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); delete chimera; return 0; } #endif @@ -377,8 +437,8 @@ int ChimeraSlayerCommand::execute(){ for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); - outputNames.push_back(outputFileName); - outputNames.push_back(accnosFileName); + outputNames.push_back(outputFileName); outputTypes["chimera"].push_back(outputFileName); + outputNames.push_back(accnosFileName); outputTypes["accnos"].push_back(accnosFileName); m->mothurOutEndLine(); m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(numSeqs) + " sequences."); m->mothurOutEndLine(); } diff --git a/chimeraslayercommand.h b/chimeraslayercommand.h index c5ef888..aa9b5e7 100644 --- a/chimeraslayercommand.h +++ b/chimeraslayercommand.h @@ -20,7 +20,12 @@ class ChimeraSlayerCommand : public Command { public: ChimeraSlayerCommand(string); + ChimeraSlayerCommand(); ~ChimeraSlayerCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -50,6 +55,7 @@ private: Chimera* chimera; vector outputNames; + map > outputTypes; vector fastaFileNames; }; diff --git a/chopseqscommand.cpp b/chopseqscommand.cpp index b281074..fc2d9a7 100644 --- a/chopseqscommand.cpp +++ b/chopseqscommand.cpp @@ -11,7 +11,54 @@ #include "sequence.hpp" //********************************************************************************************************************** - +vector ChopSeqsCommand::getValidParameters(){ + try { + string AlignArray[] = {"fasta","numbases","countgaps","keep","outputdir","inputdir"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ChopSeqsCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +ChopSeqsCommand::ChopSeqsCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["accnos"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "ChopSeqsCommand", "ChopSeqsCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector ChopSeqsCommand::getRequiredParameters(){ + try { + string Array[] = {"fasta","numbases"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ChopSeqsCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ChopSeqsCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ChopSeqsCommand", "getRequiredFiles"); + exit(1); + } +} +//********************************************************************************************************************** ChopSeqsCommand::ChopSeqsCommand(string option) { try { abort = false; @@ -35,6 +82,11 @@ ChopSeqsCommand::ChopSeqsCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["accnos"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -118,7 +170,7 @@ int ChopSeqsCommand::execute(){ Sequence seq(in); - if (m->control_pressed) { in.close(); out.close(); outAcc.close(); remove(outputFileName.c_str()); remove(outputFileNameAccnos.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); in.close(); out.close(); outAcc.close(); remove(outputFileName.c_str()); remove(outputFileNameAccnos.c_str()); return 0; } if (seq.getName() != "") { string newSeqString = getChopped(seq); @@ -138,9 +190,9 @@ int ChopSeqsCommand::execute(){ m->mothurOutEndLine(); m->mothurOut("Output File Name: "); m->mothurOutEndLine(); - m->mothurOut(outputFileName); m->mothurOutEndLine(); + m->mothurOut(outputFileName); m->mothurOutEndLine(); outputNames.push_back(outputFileName); outputTypes["fasta"].push_back(outputFileName); - if (wroteAccnos) { m->mothurOut(outputFileNameAccnos); m->mothurOutEndLine(); } + if (wroteAccnos) { m->mothurOut(outputFileNameAccnos); m->mothurOutEndLine(); outputNames.push_back(outputFileNameAccnos); outputTypes["accnos"].push_back(outputFileNameAccnos); } else { remove(outputFileNameAccnos.c_str()); } m->mothurOutEndLine(); diff --git a/chopseqscommand.h b/chopseqscommand.h index 6049064..8e007ff 100644 --- a/chopseqscommand.h +++ b/chopseqscommand.h @@ -18,8 +18,13 @@ class ChopSeqsCommand : public Command { public: - ChopSeqsCommand(string); + ChopSeqsCommand(string); + ChopSeqsCommand(); ~ChopSeqsCommand(){}; + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -27,9 +32,12 @@ class ChopSeqsCommand : public Command { string fastafile, outputDir, keep; bool abort, countGaps; int numbases; + vector outputNames; + map > outputTypes; string getChopped(Sequence); + }; #endif diff --git a/classifyotucommand.cpp b/classifyotucommand.cpp index d27a881..cedc1f2 100644 --- a/classifyotucommand.cpp +++ b/classifyotucommand.cpp @@ -10,7 +10,53 @@ #include "classifyotucommand.h" #include "phylotree.h" - +//********************************************************************************************************************** +vector ClassifyOtuCommand::getValidParameters(){ + try { + string AlignArray[] = {"list","label","name","taxonomy","cutoff","probs","outputdir","inputdir"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ClassifyOtuCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +ClassifyOtuCommand::ClassifyOtuCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["constaxonomy"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "ClassifyOtuCommand", "ClassifyOtuCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector ClassifyOtuCommand::getRequiredParameters(){ + try { + string Array[] = {"list","taxonomy"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ClassifyOtuCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ClassifyOtuCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ClassifyOtuCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** ClassifyOtuCommand::ClassifyOtuCommand(string option) { try{ @@ -37,6 +83,10 @@ ClassifyOtuCommand::ClassifyOtuCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["constaxonomy"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -157,7 +207,7 @@ int ClassifyOtuCommand::execute(){ set processedLabels; set userLabels = labels; - if (m->control_pressed) { delete input; delete list; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { outputTypes.clear(); delete input; delete list; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { @@ -165,7 +215,7 @@ int ClassifyOtuCommand::execute(){ m->mothurOut(list->getLabel() + "\t" + toString(list->size())); m->mothurOutEndLine(); process(list); - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } delete input; delete list; return 0; } + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } delete input; delete list; return 0; } processedLabels.insert(list->getLabel()); userLabels.erase(list->getLabel()); @@ -180,7 +230,7 @@ int ClassifyOtuCommand::execute(){ process(list); - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } delete input; delete list; return 0; } + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } delete input; delete list; return 0; } processedLabels.insert(list->getLabel()); userLabels.erase(list->getLabel()); @@ -216,12 +266,12 @@ int ClassifyOtuCommand::execute(){ process(list); delete list; - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } delete input; delete list; return 0; } + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } delete input; delete list; return 0; } } delete input; - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); @@ -424,7 +474,9 @@ int ClassifyOtuCommand::process(ListVector* processList) { ofstream out; string outputFile = outputDir + m->getRootName(m->getSimpleName(listfile)) + processList->getLabel() + ".cons.taxonomy"; m->openOutputFile(outputFile, out); - outputNames.push_back(outputFile); + outputNames.push_back(outputFile); outputTypes["constaxonomy"].push_back(outputFile); + + out << "OTU\tSize\tTaxonomy" << endl; //for each bin in the list vector for (int i = 0; i < processList->getNumBins(); i++) { diff --git a/classifyotucommand.h b/classifyotucommand.h index 1077781..60bfb29 100644 --- a/classifyotucommand.h +++ b/classifyotucommand.h @@ -19,7 +19,12 @@ class ClassifyOtuCommand : public Command { public: ClassifyOtuCommand(string); + ClassifyOtuCommand(); ~ClassifyOtuCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -34,6 +39,7 @@ private: vector outputNames; map nameMap; map taxMap; + map > outputTypes; int readNamesFile(); int readTaxonomyFile(); diff --git a/classifyseqscommand.cpp b/classifyseqscommand.cpp index 33f49e5..9f05eda 100644 --- a/classifyseqscommand.cpp +++ b/classifyseqscommand.cpp @@ -14,8 +14,57 @@ #include "phylosummary.h" #include "knn.h" -//********************************************************************************************************************** +//********************************************************************************************************************** +vector ClassifySeqsCommand::getValidParameters(){ + try { + string AlignArray[] = {"template","fasta","name","group","search","ksize","method","processors","taxonomy","match","mismatch","gapopen","gapextend","numwanted","cutoff","probs","iters", "outputdir","inputdir"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ClassifySeqsCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +ClassifySeqsCommand::ClassifySeqsCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["taxonomy"] = tempOutNames; + outputTypes["taxsummary"] = tempOutNames; + outputTypes["matchdist"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "ClassifySeqsCommand", "ClassifySeqsCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector ClassifySeqsCommand::getRequiredParameters(){ + try { + string Array[] = {"fasta","template","taxonomy"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ClassifySeqsCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ClassifySeqsCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ClassifySeqsCommand", "getRequiredFiles"); + exit(1); + } +} +//********************************************************************************************************************** ClassifySeqsCommand::ClassifySeqsCommand(string option) { try { abort = false; @@ -40,6 +89,12 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["taxonomy"] = tempOutNames; + outputTypes["taxsummary"] = tempOutNames; + outputTypes["matchdist"] = tempOutNames; + //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; } @@ -110,6 +165,16 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option) { fastaFileNames[i] = tryPath; } } + + if (ableToOpen == 1) { + if (m->getOutputDir() != "") { //default path is set + string tryPath = m->getOutputDir() + m->getSimpleName(fastaFileNames[i]); + m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); + fastaFileNames[i] = tryPath; + } + } + in.close(); if (ableToOpen == 1) { @@ -162,6 +227,15 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option) { namefileNames[i] = tryPath; } } + + if (ableToOpen == 1) { + if (m->getOutputDir() != "") { //default path is set + string tryPath = m->getOutputDir() + m->getSimpleName(namefileNames[i]); + m->mothurOut("Unable to open " + namefileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); + namefileNames[i] = tryPath; + } + } in.close(); if (ableToOpen == 1) { @@ -204,6 +278,16 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option) { groupfileNames[i] = tryPath; } } + + if (ableToOpen == 1) { + if (m->getOutputDir() != "") { //default path is set + string tryPath = m->getOutputDir() + m->getSimpleName(groupfileNames[i]); + m->mothurOut("Unable to open " + groupfileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); + groupfileNames[i] = tryPath; + } + } + in.close(); if (ableToOpen == 1) { @@ -336,7 +420,6 @@ int ClassifySeqsCommand::execute(){ if (m->control_pressed) { delete classify; return 0; } - vector outputNames; for (int s = 0; s < fastaFileNames.size(); s++) { @@ -354,11 +437,11 @@ int ClassifySeqsCommand::execute(){ if ((method == "knn") && (search == "distance")) { string DistName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "match.dist"; - classify->setDistName(DistName); outputNames.push_back(DistName); + classify->setDistName(DistName); outputNames.push_back(DistName); outputTypes["matchdist"].push_back(DistName); } - outputNames.push_back(newTaxonomyFile); - outputNames.push_back(taxSummary); + outputNames.push_back(newTaxonomyFile); outputTypes["taxonomy"].push_back(newTaxonomyFile); + outputNames.push_back(taxSummary); outputTypes["taxsummary"].push_back(taxSummary); int start = time(NULL); int numFastaSeqs = 0; @@ -380,20 +463,11 @@ int ClassifySeqsCommand::execute(){ int outMode=MPI_MODE_CREATE|MPI_MODE_WRONLY; int inMode=MPI_MODE_RDONLY; - //char* outNewTax = new char[newTaxonomyFile.length()]; - //memcpy(outNewTax, newTaxonomyFile.c_str(), newTaxonomyFile.length()); - char outNewTax[1024]; strcpy(outNewTax, newTaxonomyFile.c_str()); - - //char* outTempTax = new char[tempTaxonomyFile.length()]; - //memcpy(outTempTax, tempTaxonomyFile.c_str(), tempTaxonomyFile.length()); char outTempTax[1024]; strcpy(outTempTax, tempTaxonomyFile.c_str()); - - //char* inFileName = new char[fastaFileNames[s].length()]; - //memcpy(inFileName, fastaFileNames[s].c_str(), fastaFileNames[s].length()); char inFileName[1024]; strcpy(inFileName, fastaFileNames[s].c_str()); @@ -402,11 +476,7 @@ int ClassifySeqsCommand::execute(){ MPI_File_open(MPI_COMM_WORLD, outNewTax, outMode, MPI_INFO_NULL, &outMPINewTax); MPI_File_open(MPI_COMM_WORLD, outTempTax, outMode, MPI_INFO_NULL, &outMPITempTax); - //delete outNewTax; - //delete outTempTax; - //delete inFileName; - - if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPINewTax); MPI_File_close(&outMPITempTax); delete classify; return 0; } + if (m->control_pressed) { outputTypes.clear(); MPI_File_close(&inMPI); MPI_File_close(&outMPINewTax); MPI_File_close(&outMPITempTax); delete classify; return 0; } if (pid == 0) { //you are the root process @@ -427,7 +497,7 @@ int ClassifySeqsCommand::execute(){ //align your part driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPINewTax, outMPITempTax, MPIPos); - if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPINewTax); MPI_File_close(&outMPITempTax); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } delete classify; return 0; } + if (m->control_pressed) { outputTypes.clear(); MPI_File_close(&inMPI); MPI_File_close(&outMPINewTax); MPI_File_close(&outMPITempTax); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } delete classify; return 0; } for (int i = 1; i < processors; i++) { int done; @@ -447,7 +517,7 @@ int ClassifySeqsCommand::execute(){ //align your part driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPINewTax, outMPITempTax, MPIPos); - if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPINewTax); MPI_File_close(&outMPITempTax); delete classify; return 0; } + if (m->control_pressed) { outputTypes.clear(); MPI_File_close(&inMPI); MPI_File_close(&outMPINewTax); MPI_File_close(&outMPITempTax); delete classify; return 0; } int done = 0; MPI_Send(&done, 1, MPI_INT, 0, tag, MPI_COMM_WORLD); @@ -532,7 +602,7 @@ int ClassifySeqsCommand::execute(){ PhyloSummary taxaSum(taxonomyFileName, group); - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } delete classify; return 0; } + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } delete classify; return 0; } if (namefile == "") { taxaSum.summarize(tempTaxonomyFile); } else { @@ -561,7 +631,7 @@ int ClassifySeqsCommand::execute(){ } remove(tempTaxonomyFile.c_str()); - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } delete classify; return 0; } + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } delete classify; return 0; } //print summary file ofstream outTaxTree; @@ -583,7 +653,7 @@ int ClassifySeqsCommand::execute(){ //read taxfile - this reading and rewriting is done to preserve the confidence scores. string name, taxon; while (!inTax.eof()) { - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } remove(unclass.c_str()); delete classify; return 0; } + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } remove(unclass.c_str()); delete classify; return 0; } inTax >> name >> taxon; m->gobble(inTax); diff --git a/classifyseqscommand.h b/classifyseqscommand.h index 84f5f9f..1654913 100644 --- a/classifyseqscommand.h +++ b/classifyseqscommand.h @@ -29,7 +29,12 @@ class ClassifySeqsCommand : public Command { public: ClassifySeqsCommand(string); + ClassifySeqsCommand(); ~ClassifySeqsCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -45,8 +50,10 @@ private: vector fastaFileNames; vector namefileNames; vector groupfileNames; + vector outputNames; map > nameMap; map >::iterator itNames; + map > outputTypes; Classify* classify; diff --git a/clearcutcommand.cpp b/clearcutcommand.cpp index c76de38..0d2da75 100644 --- a/clearcutcommand.cpp +++ b/clearcutcommand.cpp @@ -10,7 +10,54 @@ #include "clearcutcommand.h" #include "clearcut.h" - +//********************************************************************************************************************** +vector ClearcutCommand::getValidParameters(){ + try { + string AlignArray[] = {"fasta","phylip","version","verbose","quiet","seed","norandom","shuffle","neighbor","expblen", + "expdist","ntrees","matrixout","stdout","kimura","jukes","protein","DNA","outputdir","inputdir"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ClearcutCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +ClearcutCommand::ClearcutCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["tree"] = tempOutNames; + outputTypes["matrixout"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "ClearcutCommand", "ClearcutCommand"); + exit(1); + } +}//********************************************************************************************************************** +vector ClearcutCommand::getRequiredParameters(){ + try { + string Array[] = {"fasta","phylip","or"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ClearcutCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ClearcutCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ClearcutCommand", "getRequiredFiles"); + exit(1); + } +} /**************************************************************************************/ ClearcutCommand::ClearcutCommand(string option) { try { @@ -36,6 +83,11 @@ ClearcutCommand::ClearcutCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["tree"] = tempOutNames; + outputTypes["matrixout"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -177,6 +229,7 @@ int ClearcutCommand::execute() { //prepare filename string outputName = outputDir + m->getRootName(m->getSimpleName(inputFile)) + "tre"; + outputNames.push_back(outputName); outputTypes["tree"].push_back(outputName); vector cPara; @@ -226,6 +279,8 @@ int ClearcutCommand::execute() { char* temp = new char[tempMatrix.length()]; strcpy(temp, tempMatrix.c_str()); cPara.push_back(temp); + outputNames.push_back((outputDir + matrixout)); + outputTypes["matrixout"].push_back((outputDir + matrixout)); } if (ntrees != "1") { @@ -252,8 +307,7 @@ int ClearcutCommand::execute() { if (!stdoutWanted) { m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); - m->mothurOut(outputName); m->mothurOutEndLine(); - if (matrixout != "") { m->mothurOut(outputDir+matrixout); m->mothurOutEndLine(); } + for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); } m->mothurOutEndLine(); } diff --git a/clearcutcommand.h b/clearcutcommand.h index 980431b..ea6e279 100644 --- a/clearcutcommand.h +++ b/clearcutcommand.h @@ -25,7 +25,12 @@ class ClearcutCommand : public Command { public: ClearcutCommand(string); + ClearcutCommand(); ~ClearcutCommand() {}; + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -33,6 +38,8 @@ private: string outputDir, phylipfile, fastafile, matrixout, inputFile, seed, ntrees; bool version, verbose, quiet, norandom, shuffle, neighbor, expblen, expdist, stdoutWanted, kimura, jukes, protein, DNA; bool abort; + vector outputNames; + map > outputTypes; }; /****************************************************************************/ diff --git a/clustercommand.cpp b/clustercommand.cpp index 2f9c36e..8a1d120 100644 --- a/clustercommand.cpp +++ b/clustercommand.cpp @@ -9,6 +9,55 @@ #include "clustercommand.h" +//********************************************************************************************************************** +vector ClusterCommand::getValidParameters(){ + try { + string AlignArray[] = {"cutoff","precision","method","showabund","timing","hard","outputdir","inputdir"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ClusterCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +ClusterCommand::ClusterCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["list"] = tempOutNames; + outputTypes["rabund"] = tempOutNames; + outputTypes["sabund"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "ClusterCommand", "ClusterCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector ClusterCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ClusterCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ClusterCommand::getRequiredFiles(){ + try { + string Array[] = {"phylip","column","or"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ClusterCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** //This function checks to make sure the cluster command has no errors and then clusters based on the method chosen. ClusterCommand::ClusterCommand(string option) { @@ -37,6 +86,12 @@ ClusterCommand::ClusterCommand(string option) { } } + //initialize outputTypes + vector tempOutNames; + outputTypes["list"] = tempOutNames; + outputTypes["rabund"] = tempOutNames; + outputTypes["sabund"] = tempOutNames; + //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; } @@ -101,9 +156,9 @@ ClusterCommand::ClusterCommand(string option) { m->openOutputFile(fileroot+ tag + ".rabund", rabundFile); m->openOutputFile(fileroot+ tag + ".list", listFile); - outputNames.push_back(fileroot+ tag + ".sabund"); - outputNames.push_back(fileroot+ tag + ".rabund"); - outputNames.push_back(fileroot+ tag + ".list"); + outputNames.push_back(fileroot+ tag + ".sabund"); outputTypes["sabund"].push_back(fileroot+ tag + ".sabund"); + outputNames.push_back(fileroot+ tag + ".rabund"); outputTypes["rabund"].push_back(fileroot+ tag + ".rabund"); + outputNames.push_back(fileroot+ tag + ".list"); outputTypes["list"].push_back(fileroot+ tag + ".list"); } } } @@ -158,14 +213,14 @@ int ClusterCommand::execute(){ double saveCutoff = cutoff; while (matrix->getSmallDist() < cutoff && matrix->getNNodes() > 0){ - cout << matrix->getSmallDist() << '\t' << cutoff << '\t' << matrix->getNNodes() << endl; + if (m->control_pressed) { //clean up delete globaldata->gSparseMatrix; globaldata->gSparseMatrix = NULL; delete globaldata->gListVector; globaldata->gListVector = NULL; if (globaldata->getFormat() == "phylip") { globaldata->setPhylipFile(""); } else if (globaldata->getFormat() == "column") { globaldata->setColumnFile(""); } sabundFile.close();rabundFile.close();listFile.close(); - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); return 0; } diff --git a/clustercommand.h b/clustercommand.h index c8e0174..787f835 100644 --- a/clustercommand.h +++ b/clustercommand.h @@ -30,7 +30,12 @@ class ClusterCommand : public Command { public: ClusterCommand(string); + ClusterCommand(); ~ClusterCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -57,6 +62,7 @@ private: void printData(string label); vector outputNames; + map > outputTypes; }; #endif diff --git a/clusterfragmentscommand.cpp b/clusterfragmentscommand.cpp index 0c4dec3..b5681db 100644 --- a/clusterfragmentscommand.cpp +++ b/clusterfragmentscommand.cpp @@ -25,6 +25,54 @@ inline bool comparePriority(seqRNode first, seqRNode second) { return better; } //********************************************************************************************************************** +vector ClusterFragmentsCommand::getValidParameters(){ + try { + string AlignArray[] = {"fasta","name","outputdir","inputdir"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ClusterFragmentsCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +ClusterFragmentsCommand::ClusterFragmentsCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["name"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "ClusterFragmentsCommand", "ClusterFragmentsCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector ClusterFragmentsCommand::getRequiredParameters(){ + try { + string Array[] = {"fasta"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ClusterFragmentsCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ClusterFragmentsCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ClusterFragmentsCommand", "getRequiredFiles"); + exit(1); + } +} +//********************************************************************************************************************** ClusterFragmentsCommand::ClusterFragmentsCommand(string option) { try { abort = false; @@ -48,6 +96,11 @@ ClusterFragmentsCommand::ClusterFragmentsCommand(string option) { if (validParameter.isValidParameter(it2->first, myArray, it2->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["name"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -193,6 +246,7 @@ int ClusterFragmentsCommand::execute(){ m->mothurOut("Output File Names: "); m->mothurOutEndLine(); m->mothurOut(newFastaFile); m->mothurOutEndLine(); m->mothurOut(newNamesFile); m->mothurOutEndLine(); + outputNames.push_back(newFastaFile); outputNames.push_back(newNamesFile); outputTypes["fasta"].push_back(newFastaFile); outputTypes["name"].push_back(newNamesFile); m->mothurOutEndLine(); return 0; diff --git a/clusterfragmentscommand.h b/clusterfragmentscommand.h index 9bdbc44..842485e 100644 --- a/clusterfragmentscommand.h +++ b/clusterfragmentscommand.h @@ -31,7 +31,12 @@ class ClusterFragmentsCommand : public Command { public: ClusterFragmentsCommand(string); + ClusterFragmentsCommand(); ~ClusterFragmentsCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -42,6 +47,8 @@ private: map names; //represents the names file first column maps to second column map sizes; //this map a seq name to the number of identical seqs in the names file map::iterator itSize; + vector outputNames; + map > outputTypes; int readFASTA(); void readNameFile(); diff --git a/clustersplitcommand.cpp b/clustersplitcommand.cpp index 10579a3..3c957a6 100644 --- a/clustersplitcommand.cpp +++ b/clustersplitcommand.cpp @@ -15,6 +15,56 @@ #include "readmatrix.hpp" #include "inputdata.h" + +//********************************************************************************************************************** +vector ClusterSplitCommand::getValidParameters(){ + try { + string AlignArray[] = {"fasta","phylip","column","name","cutoff","precision","method","splitmethod","taxonomy","taxlevel","large","showabund","timing","hard","processors","outputdir","inputdir"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ClusterSplitCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +ClusterSplitCommand::ClusterSplitCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["list"] = tempOutNames; + outputTypes["rabund"] = tempOutNames; + outputTypes["sabund"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "ClusterSplitCommand", "ClusterSplitCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector ClusterSplitCommand::getRequiredParameters(){ + try { + string Array[] = {"fasta","phylip","column","or"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ClusterSplitCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ClusterSplitCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ClusterSplitCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** //This function checks to make sure the cluster command has no errors and then clusters based on the method chosen. ClusterSplitCommand::ClusterSplitCommand(string option) { @@ -44,6 +94,12 @@ ClusterSplitCommand::ClusterSplitCommand(string option) { } } + //initialize outputTypes + vector tempOutNames; + outputTypes["list"] = tempOutNames; + outputTypes["rabund"] = tempOutNames; + outputTypes["sabund"] = tempOutNames; + globaldata->newRead(); //if the user changes the output directory command factory will send this info to us in the output parameter @@ -292,7 +348,7 @@ int ClusterSplitCommand::execute(){ SplitMatrix* split; if (splitmethod == "distance") { split = new SplitMatrix(distfile, namefile, taxFile, cutoff, splitmethod, large); } else if (splitmethod == "classify") { split = new SplitMatrix(distfile, namefile, taxFile, taxLevelCutoff, splitmethod, large); } - else if (splitmethod == "fasta") { split = new SplitMatrix(fastafile, namefile, taxFile, taxLevelCutoff, splitmethod, processors, outputDir); } + else if (splitmethod == "fasta") { split = new SplitMatrix(fastafile, namefile, taxFile, taxLevelCutoff, cutoff, splitmethod, processors, outputDir); } else { m->mothurOut("Not a valid splitting method. Valid splitting algorithms are distance, classify or fasta."); m->mothurOutEndLine(); return 0; } split->split(); @@ -696,9 +752,9 @@ int ClusterSplitCommand::mergeLists(vector listNames, map us m->openOutputFile(fileroot+ tag + ".rabund", outRabund); m->openOutputFile(fileroot+ tag + ".list", outList); - outputNames.push_back(fileroot+ tag + ".sabund"); - outputNames.push_back(fileroot+ tag + ".rabund"); - outputNames.push_back(fileroot+ tag + ".list"); + outputNames.push_back(fileroot+ tag + ".sabund"); outputTypes["list"].push_back(fileroot+ tag + ".list"); + outputNames.push_back(fileroot+ tag + ".rabund"); outputTypes["rabund"].push_back(fileroot+ tag + ".rabund"); + outputNames.push_back(fileroot+ tag + ".list"); outputTypes["sabund"].push_back(fileroot+ tag + ".sabund"); map::iterator itLabel; diff --git a/clustersplitcommand.h b/clustersplitcommand.h index dc46f99..07ddaf9 100644 --- a/clustersplitcommand.h +++ b/clustersplitcommand.h @@ -23,7 +23,12 @@ class ClusterSplitCommand : public Command { public: ClusterSplitCommand(string); + ClusterSplitCommand(); ~ClusterSplitCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -31,6 +36,7 @@ private: GlobalData* globaldata; vector processIDS; //processid vector outputNames; + map > outputTypes; string method, fileroot, tag, outputDir, phylipfile, columnfile, namefile, distfile, format, showabund, timing, splitmethod, taxFile, fastafile; double cutoff, splitcutoff; diff --git a/collectcommand.cpp b/collectcommand.cpp index 2d952fa..3dd2436 100644 --- a/collectcommand.cpp +++ b/collectcommand.cpp @@ -34,7 +34,77 @@ #include "shen.h" #include "coverage.h" - +//********************************************************************************************************************** +vector CollectCommand::getValidParameters(){ + try { + string AlignArray[] = {"freq","label","calc","abund","size","outputdir","inputdir"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "CollectCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector CollectCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "CollectCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector CollectCommand::getRequiredFiles(){ + try { + string AlignArray[] = {"shared","list","rabund","sabund","or"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "CollectCommand", "getRequiredFiles"); + exit(1); + } +} +//********************************************************************************************************************** +CollectCommand::CollectCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["sobs"] = tempOutNames; + outputTypes["chao"] = tempOutNames; + outputTypes["nseqs"] = tempOutNames; + outputTypes["coverage"] = tempOutNames; + outputTypes["ace"] = tempOutNames; + outputTypes["jack"] = tempOutNames; + outputTypes["shannon"] = tempOutNames; + outputTypes["shannoneven"] = tempOutNames; + outputTypes["np_shannon"] = tempOutNames; + outputTypes["heip"] = tempOutNames; + outputTypes["smithwilson"] = tempOutNames; + outputTypes["simpson"] = tempOutNames; + outputTypes["simpsoneven"] = tempOutNames; + outputTypes["invsimpson"] = tempOutNames; + outputTypes["bootstrap"] = tempOutNames; + outputTypes["geometric"] = tempOutNames; + outputTypes["qstat"] = tempOutNames; + outputTypes["logseries"] = tempOutNames; + outputTypes["bergerparker"] = tempOutNames; + outputTypes["bstick"] = tempOutNames; + outputTypes["goodscoverage"] = tempOutNames; + outputTypes["efron"] = tempOutNames; + outputTypes["boneh"] = tempOutNames; + outputTypes["solow"] = tempOutNames; + outputTypes["shen"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "CollectCommand", "CollectCommand"); + exit(1); + } +} //********************************************************************************************************************** CollectCommand::CollectCommand(string option) { try { @@ -62,6 +132,34 @@ CollectCommand::CollectCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["sobs"] = tempOutNames; + outputTypes["chao"] = tempOutNames; + outputTypes["nseqs"] = tempOutNames; + outputTypes["coverage"] = tempOutNames; + outputTypes["ace"] = tempOutNames; + outputTypes["jack"] = tempOutNames; + outputTypes["shannon"] = tempOutNames; + outputTypes["shannoneven"] = tempOutNames; + outputTypes["np_shannon"] = tempOutNames; + outputTypes["heip"] = tempOutNames; + outputTypes["smithwilson"] = tempOutNames; + outputTypes["simpson"] = tempOutNames; + outputTypes["simpsoneven"] = tempOutNames; + outputTypes["invsimpson"] = tempOutNames; + outputTypes["bootstrap"] = tempOutNames; + outputTypes["geometric"] = tempOutNames; + outputTypes["qstat"] = tempOutNames; + outputTypes["logseries"] = tempOutNames; + outputTypes["bergerparker"] = tempOutNames; + outputTypes["bstick"] = tempOutNames; + outputTypes["goodscoverage"] = tempOutNames; + outputTypes["efron"] = tempOutNames; + outputTypes["boneh"] = tempOutNames; + outputTypes["solow"] = tempOutNames; + outputTypes["shen"] = tempOutNames; + //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; } @@ -140,15 +238,13 @@ int CollectCommand::execute(){ if (abort == true) { return 0; } - vector outputNames; - string hadShared = ""; if ((globaldata->getFormat() != "sharedfile")) { inputFileNames.push_back(globaldata->inputFileName); } else { hadShared = globaldata->getSharedFile(); inputFileNames = parseSharedFile(globaldata->getSharedFile()); globaldata->setFormat("rabund"); } for (int p = 0; p < inputFileNames.size(); p++) { - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); if (hadShared != "") { globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile"); } return 0; } + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); if (hadShared != "") { globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile"); } return 0; } if (outputDir == "") { outputDir += m->hasPath(inputFileNames[p]); } string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p])); @@ -164,79 +260,79 @@ int CollectCommand::execute(){ if (validCalculator->isValidCalculator("single", Estimators[i]) == true) { if (Estimators[i] == "sobs") { cDisplays.push_back(new CollectDisplay(new Sobs(), new OneColumnFile(fileNameRoot+"sobs"))); - outputNames.push_back(fileNameRoot+"sobs"); + outputNames.push_back(fileNameRoot+"sobs"); outputTypes["sobs"].push_back(fileNameRoot+"sobs"); }else if (Estimators[i] == "chao") { cDisplays.push_back(new CollectDisplay(new Chao1(), new ThreeColumnFile(fileNameRoot+"chao"))); - outputNames.push_back(fileNameRoot+"chao"); + outputNames.push_back(fileNameRoot+"chao"); outputTypes["chao"].push_back(fileNameRoot+"chao"); }else if (Estimators[i] == "nseqs") { cDisplays.push_back(new CollectDisplay(new NSeqs(), new OneColumnFile(fileNameRoot+"nseqs"))); - outputNames.push_back(fileNameRoot+"nseqs"); + outputNames.push_back(fileNameRoot+"nseqs"); outputTypes["nseqs"].push_back(fileNameRoot+"nseqs"); }else if (Estimators[i] == "coverage") { cDisplays.push_back(new CollectDisplay(new Coverage(), new OneColumnFile(fileNameRoot+"coverage"))); - outputNames.push_back(fileNameRoot+"coverage"); + outputNames.push_back(fileNameRoot+"coverage"); outputTypes["coverage"].push_back(fileNameRoot+"coverage"); }else if (Estimators[i] == "ace") { cDisplays.push_back(new CollectDisplay(new Ace(abund), new ThreeColumnFile(fileNameRoot+"ace"))); - outputNames.push_back(fileNameRoot+"ace"); + outputNames.push_back(fileNameRoot+"ace"); outputTypes["ace"].push_back(fileNameRoot+"ace"); }else if (Estimators[i] == "jack") { cDisplays.push_back(new CollectDisplay(new Jackknife(), new ThreeColumnFile(fileNameRoot+"jack"))); - outputNames.push_back(fileNameRoot+"jack"); + outputNames.push_back(fileNameRoot+"jack"); outputTypes["jack"].push_back(fileNameRoot+"jack"); }else if (Estimators[i] == "shannon") { cDisplays.push_back(new CollectDisplay(new Shannon(), new ThreeColumnFile(fileNameRoot+"shannon"))); - outputNames.push_back(fileNameRoot+"shannon"); + outputNames.push_back(fileNameRoot+"shannon"); outputTypes["shannon"].push_back(fileNameRoot+"shannon"); }else if (Estimators[i] == "shannoneven") { cDisplays.push_back(new CollectDisplay(new ShannonEven(), new OneColumnFile(fileNameRoot+"shannoneven"))); - outputNames.push_back(fileNameRoot+"shannoneven"); + outputNames.push_back(fileNameRoot+"shannoneven"); outputTypes["shannoneven"].push_back(fileNameRoot+"shannoneven"); }else if (Estimators[i] == "npshannon") { cDisplays.push_back(new CollectDisplay(new NPShannon(), new OneColumnFile(fileNameRoot+"np_shannon"))); - outputNames.push_back(fileNameRoot+"np_shannon"); + outputNames.push_back(fileNameRoot+"np_shannon"); outputTypes["np_shannon"].push_back(fileNameRoot+"np_shannon"); }else if (Estimators[i] == "heip") { cDisplays.push_back(new CollectDisplay(new Heip(), new OneColumnFile(fileNameRoot+"heip"))); - outputNames.push_back(fileNameRoot+"heip"); + outputNames.push_back(fileNameRoot+"heip"); outputTypes["heip"].push_back(fileNameRoot+"heip"); }else if (Estimators[i] == "smithwilson") { cDisplays.push_back(new CollectDisplay(new SmithWilson(), new OneColumnFile(fileNameRoot+"smithwilson"))); - outputNames.push_back(fileNameRoot+"smithwilson"); + outputNames.push_back(fileNameRoot+"smithwilson"); outputTypes["smithwilson"].push_back(fileNameRoot+"smithwilson"); }else if (Estimators[i] == "simpson") { cDisplays.push_back(new CollectDisplay(new Simpson(), new ThreeColumnFile(fileNameRoot+"simpson"))); - outputNames.push_back(fileNameRoot+"simpson"); + outputNames.push_back(fileNameRoot+"simpson"); outputTypes["simpson"].push_back(fileNameRoot+"simpson"); }else if (Estimators[i] == "simpsoneven") { cDisplays.push_back(new CollectDisplay(new SimpsonEven(), new OneColumnFile(fileNameRoot+"simpsoneven"))); - outputNames.push_back(fileNameRoot+"simpsoneven"); + outputNames.push_back(fileNameRoot+"simpsoneven"); outputTypes["simpsoneven"].push_back(fileNameRoot+"simpsoneven"); }else if (Estimators[i] == "invsimpson") { cDisplays.push_back(new CollectDisplay(new InvSimpson(), new ThreeColumnFile(fileNameRoot+"invsimpson"))); - outputNames.push_back(fileNameRoot+"invsimpson"); + outputNames.push_back(fileNameRoot+"invsimpson"); outputTypes["invsimpson"].push_back(fileNameRoot+"invsimpson"); }else if (Estimators[i] == "bootstrap") { cDisplays.push_back(new CollectDisplay(new Bootstrap(), new OneColumnFile(fileNameRoot+"bootstrap"))); - outputNames.push_back(fileNameRoot+"bootstrap"); + outputNames.push_back(fileNameRoot+"bootstrap"); outputTypes["bootstrap"].push_back(fileNameRoot+"bootstrap"); }else if (Estimators[i] == "geometric") { cDisplays.push_back(new CollectDisplay(new Geom(), new OneColumnFile(fileNameRoot+"geometric"))); - outputNames.push_back(fileNameRoot+"geometric"); + outputNames.push_back(fileNameRoot+"geometric"); outputTypes["geometric"].push_back(fileNameRoot+"geometric"); }else if (Estimators[i] == "qstat") { cDisplays.push_back(new CollectDisplay(new QStat(), new OneColumnFile(fileNameRoot+"qstat"))); - outputNames.push_back(fileNameRoot+"qstat"); + outputNames.push_back(fileNameRoot+"qstat"); outputTypes["qstat"].push_back(fileNameRoot+"qstat"); }else if (Estimators[i] == "logseries") { cDisplays.push_back(new CollectDisplay(new LogSD(), new OneColumnFile(fileNameRoot+"logseries"))); - outputNames.push_back(fileNameRoot+"logseries"); + outputNames.push_back(fileNameRoot+"logseries"); outputTypes["logseries"].push_back(fileNameRoot+"logseries"); }else if (Estimators[i] == "bergerparker") { cDisplays.push_back(new CollectDisplay(new BergerParker(), new OneColumnFile(fileNameRoot+"bergerparker"))); - outputNames.push_back(fileNameRoot+"bergerparker"); + outputNames.push_back(fileNameRoot+"bergerparker"); outputTypes["bergerparker"].push_back(fileNameRoot+"bergerparker"); }else if (Estimators[i] == "bstick") { cDisplays.push_back(new CollectDisplay(new BStick(), new ThreeColumnFile(fileNameRoot+"bstick"))); - outputNames.push_back(fileNameRoot+"bstick"); + outputNames.push_back(fileNameRoot+"bstick"); outputTypes["bstick"].push_back(fileNameRoot+"bstick"); }else if (Estimators[i] == "goodscoverage") { cDisplays.push_back(new CollectDisplay(new GoodsCoverage(), new OneColumnFile(fileNameRoot+"goodscoverage"))); - outputNames.push_back(fileNameRoot+"goodscoverage"); + outputNames.push_back(fileNameRoot+"goodscoverage"); outputTypes["goodscoverage"].push_back(fileNameRoot+"goodscoverage"); }else if (Estimators[i] == "efron") { cDisplays.push_back(new CollectDisplay(new Efron(size), new OneColumnFile(fileNameRoot+"efron"))); - outputNames.push_back(fileNameRoot+"efron"); + outputNames.push_back(fileNameRoot+"efron"); outputTypes["efron"].push_back(fileNameRoot+"efron"); }else if (Estimators[i] == "boneh") { cDisplays.push_back(new CollectDisplay(new Boneh(size), new OneColumnFile(fileNameRoot+"boneh"))); - outputNames.push_back(fileNameRoot+"boneh"); + outputNames.push_back(fileNameRoot+"boneh"); outputTypes["boneh"].push_back(fileNameRoot+"boneh"); }else if (Estimators[i] == "solow") { cDisplays.push_back(new CollectDisplay(new Solow(size), new OneColumnFile(fileNameRoot+"solow"))); - outputNames.push_back(fileNameRoot+"solow"); + outputNames.push_back(fileNameRoot+"solow"); outputTypes["solow"].push_back(fileNameRoot+"solow"); }else if (Estimators[i] == "shen") { cDisplays.push_back(new CollectDisplay(new Shen(size, abund), new OneColumnFile(fileNameRoot+"shen"))); - outputNames.push_back(fileNameRoot+"shen"); + outputNames.push_back(fileNameRoot+"shen"); outputTypes["shen"].push_back(fileNameRoot+"shen"); } } } @@ -257,7 +353,7 @@ int CollectCommand::execute(){ if (m->control_pressed) { for(int i=0;iginput = NULL; delete read; delete order; globaldata->gorder = NULL; @@ -272,7 +368,7 @@ int CollectCommand::execute(){ if (m->control_pressed) { for(int i=0;iginput = NULL; delete read; delete order; globaldata->gorder = NULL; @@ -324,7 +420,7 @@ int CollectCommand::execute(){ if (m->control_pressed) { for(int i=0;iginput = NULL; delete read; delete validCalculator; @@ -359,7 +455,7 @@ int CollectCommand::execute(){ if (m->control_pressed) { for(int i=0;iginput = NULL; delete read; delete order; globaldata->gorder = NULL; diff --git a/collectcommand.h b/collectcommand.h index 773bdae..20c863b 100644 --- a/collectcommand.h +++ b/collectcommand.h @@ -38,7 +38,12 @@ class CollectCommand : public Command { public: CollectCommand(string); + CollectCommand(); ~CollectCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -52,6 +57,8 @@ private: vector cDisplays; int abund, size; float freq; + vector outputNames; + map > outputTypes; bool abort, allLines; set labels; //holds labels to be used diff --git a/collectsharedcommand.cpp b/collectsharedcommand.cpp index c0b8248..8719489 100644 --- a/collectsharedcommand.cpp +++ b/collectsharedcommand.cpp @@ -33,9 +33,75 @@ #include "whittaker.h" - //********************************************************************************************************************** - +vector CollectSharedCommand::getValidParameters(){ + try { + string AlignArray[] = {"freq","label","calc","groups","all","outputdir","inputdir"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "CollectSharedCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector CollectSharedCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "CollectSharedCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector CollectSharedCommand::getRequiredFiles(){ + try { + string AlignArray[] = {"shared"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "CollectSharedCommand", "getRequiredFiles"); + exit(1); + } +} +//********************************************************************************************************************** +CollectSharedCommand::CollectSharedCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["sharedchao"] = tempOutNames; + outputTypes["sharedsobs"] = tempOutNames; + outputTypes["sharedace"] = tempOutNames; + outputTypes["jabund"] = tempOutNames; + outputTypes["sorabund"] = tempOutNames; + outputTypes["jclass"] = tempOutNames; + outputTypes["sorclass"] = tempOutNames; + outputTypes["jest"] = tempOutNames; + outputTypes["sorest"] = tempOutNames; + outputTypes["thetayc"] = tempOutNames; + outputTypes["thetan"] = tempOutNames; + outputTypes["kstest"] = tempOutNames; + outputTypes["whittaker"] = tempOutNames; + outputTypes["sharednseqs"] = tempOutNames; + outputTypes["ochiai"] = tempOutNames; + outputTypes["anderberg"] = tempOutNames; + outputTypes["skulczynski"] = tempOutNames; + outputTypes["kulczynskicody"] = tempOutNames; + outputTypes["lennon"] = tempOutNames; + outputTypes["morisitahorn"] = tempOutNames; + outputTypes["braycurtis"] = tempOutNames; + + } + catch(exception& e) { + m->errorOut(e, "CollectSharedCommand", "CollectSharedCommand"); + exit(1); + } +} +//********************************************************************************************************************** CollectSharedCommand::CollectSharedCommand(string option) { try { globaldata = GlobalData::getInstance(); @@ -63,6 +129,31 @@ CollectSharedCommand::CollectSharedCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["sharedchao"] = tempOutNames; + outputTypes["sharedsobs"] = tempOutNames; + outputTypes["sharedace"] = tempOutNames; + outputTypes["jabund"] = tempOutNames; + outputTypes["sorabund"] = tempOutNames; + outputTypes["jclass"] = tempOutNames; + outputTypes["sorclass"] = tempOutNames; + outputTypes["jest"] = tempOutNames; + outputTypes["sorest"] = tempOutNames; + outputTypes["thetayc"] = tempOutNames; + outputTypes["thetan"] = tempOutNames; + outputTypes["kstest"] = tempOutNames; + outputTypes["whittaker"] = tempOutNames; + outputTypes["sharednseqs"] = tempOutNames; + outputTypes["ochiai"] = tempOutNames; + outputTypes["anderberg"] = tempOutNames; + outputTypes["skulczynski"] = tempOutNames; + outputTypes["kulczynskicody"] = tempOutNames; + outputTypes["lennon"] = tempOutNames; + outputTypes["morisitahorn"] = tempOutNames; + outputTypes["braycurtis"] = tempOutNames; + + //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; } @@ -124,67 +215,67 @@ CollectSharedCommand::CollectSharedCommand(string option) { if (validCalculator->isValidCalculator("shared", Estimators[i]) == true) { if (Estimators[i] == "sharedchao") { cDisplays.push_back(new CollectDisplay(new SharedChao1(), new SharedOneColumnFile(fileNameRoot+"shared.chao"))); - outputNames.push_back(fileNameRoot+"shared.chao"); + outputNames.push_back(fileNameRoot+"shared.chao"); outputTypes["sharedchao"].push_back(fileNameRoot+"shared.chao"); }else if (Estimators[i] == "sharedsobs") { cDisplays.push_back(new CollectDisplay(new SharedSobsCS(), new SharedOneColumnFile(fileNameRoot+"shared.sobs"))); - outputNames.push_back(fileNameRoot+"shared.sobs"); + outputNames.push_back(fileNameRoot+"shared.sobs"); outputTypes["sharedsobs"].push_back(fileNameRoot+"shared.sobs"); }else if (Estimators[i] == "sharedace") { cDisplays.push_back(new CollectDisplay(new SharedAce(), new SharedOneColumnFile(fileNameRoot+"shared.ace"))); - outputNames.push_back(fileNameRoot+"shared.ace"); + outputNames.push_back(fileNameRoot+"shared.ace"); outputTypes["sharedace"].push_back(fileNameRoot+"shared.ace"); }else if (Estimators[i] == "jabund") { cDisplays.push_back(new CollectDisplay(new JAbund(), new SharedOneColumnFile(fileNameRoot+"jabund"))); - outputNames.push_back(fileNameRoot+"jabund"); + outputNames.push_back(fileNameRoot+"jabund"); outputTypes["jabund"].push_back(fileNameRoot+"jabund"); }else if (Estimators[i] == "sorabund") { cDisplays.push_back(new CollectDisplay(new SorAbund(), new SharedOneColumnFile(fileNameRoot+"sorabund"))); - outputNames.push_back(fileNameRoot+"sorabund"); + outputNames.push_back(fileNameRoot+"sorabund"); outputTypes["sorabund"].push_back(fileNameRoot+"sorabund"); }else if (Estimators[i] == "jclass") { cDisplays.push_back(new CollectDisplay(new Jclass(), new SharedOneColumnFile(fileNameRoot+"jclass"))); - outputNames.push_back(fileNameRoot+"jclass"); + outputNames.push_back(fileNameRoot+"jclass"); outputTypes["jclass"].push_back(fileNameRoot+"jclass"); }else if (Estimators[i] == "sorclass") { cDisplays.push_back(new CollectDisplay(new SorClass(), new SharedOneColumnFile(fileNameRoot+"sorclass"))); - outputNames.push_back(fileNameRoot+"sorclass"); + outputNames.push_back(fileNameRoot+"sorclass"); outputTypes["sorclass"].push_back(fileNameRoot+"sorclass"); }else if (Estimators[i] == "jest") { cDisplays.push_back(new CollectDisplay(new Jest(), new SharedOneColumnFile(fileNameRoot+"jest"))); - outputNames.push_back(fileNameRoot+"jest"); + outputNames.push_back(fileNameRoot+"jest"); outputTypes["jest"].push_back(fileNameRoot+"jest"); }else if (Estimators[i] == "sorest") { cDisplays.push_back(new CollectDisplay(new SorEst(), new SharedOneColumnFile(fileNameRoot+"sorest"))); - outputNames.push_back(fileNameRoot+"sorest"); + outputNames.push_back(fileNameRoot+"sorest"); outputTypes["sorest"].push_back(fileNameRoot+"sorest"); }else if (Estimators[i] == "thetayc") { cDisplays.push_back(new CollectDisplay(new ThetaYC(), new SharedOneColumnFile(fileNameRoot+"thetayc"))); - outputNames.push_back(fileNameRoot+"thetayc"); + outputNames.push_back(fileNameRoot+"thetayc"); outputTypes["thetayc"].push_back(fileNameRoot+"thetayc"); }else if (Estimators[i] == "thetan") { cDisplays.push_back(new CollectDisplay(new ThetaN(), new SharedOneColumnFile(fileNameRoot+"thetan"))); - outputNames.push_back(fileNameRoot+"thetan"); + outputNames.push_back(fileNameRoot+"thetan"); outputTypes["thetan"].push_back(fileNameRoot+"thetan"); }else if (Estimators[i] == "kstest") { cDisplays.push_back(new CollectDisplay(new KSTest(), new SharedOneColumnFile(fileNameRoot+"kstest"))); - outputNames.push_back(fileNameRoot+"kstest"); + outputNames.push_back(fileNameRoot+"kstest"); outputTypes["kstest"].push_back(fileNameRoot+"kstest"); }else if (Estimators[i] == "whittaker") { cDisplays.push_back(new CollectDisplay(new Whittaker(), new SharedOneColumnFile(fileNameRoot+"whittaker"))); - outputNames.push_back(fileNameRoot+"whittaker"); + outputNames.push_back(fileNameRoot+"whittaker"); outputTypes["whittaker"].push_back(fileNameRoot+"whittaker"); }else if (Estimators[i] == "sharednseqs") { cDisplays.push_back(new CollectDisplay(new SharedNSeqs(), new SharedOneColumnFile(fileNameRoot+"shared.nseqs"))); - outputNames.push_back(fileNameRoot+"shared.nseqs"); + outputNames.push_back(fileNameRoot+"shared.nseqs"); outputTypes["shared.nseqs"].push_back(fileNameRoot+"shared.nseqs"); }else if (Estimators[i] == "ochiai") { cDisplays.push_back(new CollectDisplay(new Ochiai(), new SharedOneColumnFile(fileNameRoot+"ochiai"))); - outputNames.push_back(fileNameRoot+"ochiai"); + outputNames.push_back(fileNameRoot+"ochiai"); outputTypes["ochiai"].push_back(fileNameRoot+"ochiai"); }else if (Estimators[i] == "anderberg") { cDisplays.push_back(new CollectDisplay(new Anderberg(), new SharedOneColumnFile(fileNameRoot+"anderberg"))); - outputNames.push_back(fileNameRoot+"anderberg"); + outputNames.push_back(fileNameRoot+"anderberg"); outputTypes["anderberg"].push_back(fileNameRoot+"anderberg"); }else if (Estimators[i] == "skulczynski") { cDisplays.push_back(new CollectDisplay(new Kulczynski(), new SharedOneColumnFile(fileNameRoot+"kulczynski"))); - outputNames.push_back(fileNameRoot+"kulczynski"); + outputNames.push_back(fileNameRoot+"kulczynski"); outputTypes["kulczynski"].push_back(fileNameRoot+"kulczynski"); }else if (Estimators[i] == "kulczynskicody") { cDisplays.push_back(new CollectDisplay(new KulczynskiCody(), new SharedOneColumnFile(fileNameRoot+"kulczynskicody"))); - outputNames.push_back(fileNameRoot+"kulczynskicody"); + outputNames.push_back(fileNameRoot+"kulczynskicody"); outputTypes["kulczynskicody"].push_back(fileNameRoot+"kulczynskicody"); }else if (Estimators[i] == "lennon") { cDisplays.push_back(new CollectDisplay(new Lennon(), new SharedOneColumnFile(fileNameRoot+"lennon"))); - outputNames.push_back(fileNameRoot+"lennon"); + outputNames.push_back(fileNameRoot+"lennon"); outputTypes["lennon"].push_back(fileNameRoot+"lennon"); }else if (Estimators[i] == "morisitahorn") { cDisplays.push_back(new CollectDisplay(new MorHorn(), new SharedOneColumnFile(fileNameRoot+"morisitahorn"))); - outputNames.push_back(fileNameRoot+"morisitahorn"); + outputNames.push_back(fileNameRoot+"morisitahorn"); outputTypes["morisitahorn"].push_back(fileNameRoot+"morisitahorn"); }else if (Estimators[i] == "braycurtis") { cDisplays.push_back(new CollectDisplay(new BrayCurtis(), new SharedOneColumnFile(fileNameRoot+"braycurtis"))); - outputNames.push_back(fileNameRoot+"braycurtis"); + outputNames.push_back(fileNameRoot+"braycurtis"); outputTypes["braycurtis"].push_back(fileNameRoot+"braycurtis"); } } } @@ -263,7 +354,7 @@ int CollectSharedCommand::execute(){ while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { if (m->control_pressed) { - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); for(int i=0;iGroups.clear(); @@ -311,7 +402,7 @@ int CollectSharedCommand::execute(){ } if (m->control_pressed) { - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); for(int i=0;iGroups.clear(); return 0; @@ -341,7 +432,7 @@ int CollectSharedCommand::execute(){ delete cCurve; if (m->control_pressed) { - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); for(int i=0;iGroups.clear(); diff --git a/collectsharedcommand.h b/collectsharedcommand.h index b7a4941..327ce5d 100644 --- a/collectsharedcommand.h +++ b/collectsharedcommand.h @@ -27,7 +27,12 @@ class CollectSharedCommand : public Command { public: CollectSharedCommand(string); + CollectSharedCommand(); ~CollectSharedCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -49,6 +54,7 @@ private: set labels; //holds labels to be used string label, calc, groups, outputDir; vector Estimators, Groups, outputNames; + map > outputTypes; }; diff --git a/command.hpp b/command.hpp index b6bf5cd..97701aa 100644 --- a/command.hpp +++ b/command.hpp @@ -22,6 +22,10 @@ class Command { public: Command() { m = MothurOut::getInstance(); } + virtual vector getValidParameters() = 0; + virtual vector getRequiredParameters() = 0; //adding "or" as the last element indicates one of the previous is needed + virtual vector getRequiredFiles() = 0; //adding "or" as the last element indicates one of the previous is needed + virtual map > getOutputFiles() = 0; //file type to names virtual int execute() = 0; virtual void help() = 0; virtual ~Command() { } diff --git a/commandfactory.cpp b/commandfactory.cpp index 6912bbb..917ab96 100644 --- a/commandfactory.cpp +++ b/commandfactory.cpp @@ -92,6 +92,7 @@ #include "getlineagecommand.h" #include "removelineagecommand.h" #include "parsefastaqcommand.h" +#include "pipelinepdscommand.h" /*******************************************************/ @@ -116,6 +117,8 @@ CommandFactory::CommandFactory(){ m = MothurOut::getInstance(); command = new NoCommand(s); + shellcommand = new NoCommand(s); + pipecommand = new NoCommand(s); outputDir = ""; inputDir = ""; logFileName = ""; @@ -188,6 +191,7 @@ CommandFactory::CommandFactory(){ commands["get.lineage"] = "get.lineage"; commands["remove.lineage"] = "remove.lineage"; commands["fastq.info"] = "fastq.info"; + commands["pipeline.pds"] = "MPIEnabled"; commands["classify.seqs"] = "MPIEnabled"; commands["dist.seqs"] = "MPIEnabled"; commands["filter.seqs"] = "MPIEnabled"; @@ -223,6 +227,8 @@ bool CommandFactory::MPIEnabled(string commandName) { CommandFactory::~CommandFactory(){ _uniqueInstance = 0; delete command; + delete shellcommand; + delete pipecommand; } /***********************************************************/ @@ -327,6 +333,7 @@ Command* CommandFactory::getCommand(string commandName, string optionString){ else if(commandName == "get.lineage") { command = new GetLineageCommand(optionString); } else if(commandName == "remove.lineage") { command = new RemoveLineageCommand(optionString); } else if(commandName == "fastq.info") { command = new ParseFastaQCommand(optionString); } + else if(commandName == "pipeline.pds") { command = new PipelineCommand(optionString); } else { command = new NoCommand(optionString); } return command; @@ -337,6 +344,216 @@ Command* CommandFactory::getCommand(string commandName, string optionString){ } } /***********************************************************/ + +/***********************************************************/ +//This function calls the appropriate command fucntions based on user input. +Command* CommandFactory::getCommand(string commandName, string optionString, string mode){ + try { + delete pipecommand; //delete the old command + + //user has opted to redirect output from dir where input files are located to some other place + if (outputDir != "") { + if (optionString != "") { optionString += ", outputdir=" + outputDir; } + else { optionString += "outputdir=" + outputDir; } + } + + //user has opted to redirect input from dir where mothur.exe is located to some other place + if (inputDir != "") { + if (optionString != "") { optionString += ", inputdir=" + inputDir; } + else { optionString += "inputdir=" + inputDir; } + } + + if(commandName == "read.dist") { pipecommand = new ReadDistCommand(optionString); } + else if(commandName == "read.otu") { pipecommand = new ReadOtuCommand(optionString); } + else if(commandName == "read.tree") { pipecommand = new ReadTreeCommand(optionString); } + else if(commandName == "cluster") { pipecommand = new ClusterCommand(optionString); } + else if(commandName == "unique.seqs") { pipecommand = new DeconvoluteCommand(optionString); } + else if(commandName == "parsimony") { pipecommand = new ParsimonyCommand(optionString); } + else if(commandName == "help") { pipecommand = new HelpCommand(optionString); } + else if(commandName == "quit") { pipecommand = new QuitCommand(optionString); } + else if(commandName == "collect.single") { pipecommand = new CollectCommand(optionString); } + else if(commandName == "collect.shared") { pipecommand = new CollectSharedCommand(optionString); } + else if(commandName == "rarefaction.single") { pipecommand = new RareFactCommand(optionString); } + else if(commandName == "rarefaction.shared") { pipecommand = new RareFactSharedCommand(optionString); } + else if(commandName == "summary.single") { pipecommand = new SummaryCommand(optionString); } + else if(commandName == "summary.shared") { pipecommand = new SummarySharedCommand(optionString); } + else if(commandName == "unifrac.weighted") { pipecommand = new UnifracWeightedCommand(optionString); } + else if(commandName == "unifrac.unweighted") { pipecommand = new UnifracUnweightedCommand(optionString); } + else if(commandName == "get.group") { pipecommand = new GetgroupCommand(optionString); } + else if(commandName == "get.label") { pipecommand = new GetlabelCommand(optionString); } + else if(commandName == "get.sabund") { pipecommand = new GetSAbundCommand(optionString); } + else if(commandName == "get.rabund") { pipecommand = new GetRAbundCommand(optionString); } + else if(commandName == "libshuff") { pipecommand = new LibShuffCommand(optionString); } + else if(commandName == "heatmap.bin") { pipecommand = new HeatMapCommand(optionString); } + else if(commandName == "heatmap.sim") { pipecommand = new HeatMapSimCommand(optionString); } + else if(commandName == "filter.seqs") { pipecommand = new FilterSeqsCommand(optionString); } + else if(commandName == "venn") { pipecommand = new VennCommand(optionString); } + else if(commandName == "bin.seqs") { pipecommand = new BinSeqCommand(optionString); } + else if(commandName == "get.oturep") { pipecommand = new GetOTURepCommand(optionString); } + else if(commandName == "tree.shared") { pipecommand = new TreeGroupCommand(optionString); } + else if(commandName == "dist.shared") { pipecommand = new MatrixOutputCommand(optionString); } + else if(commandName == "bootstrap.shared") { pipecommand = new BootSharedCommand(optionString); } + else if(commandName == "consensus") { pipecommand = new ConcensusCommand(optionString); } + else if(commandName == "dist.seqs") { pipecommand = new DistanceCommand(optionString); } + else if(commandName == "align.seqs") { pipecommand = new AlignCommand(optionString); } + else if(commandName == "summary.seqs") { pipecommand = new SeqSummaryCommand(optionString); } + else if(commandName == "screen.seqs") { pipecommand = new ScreenSeqsCommand(optionString); } + else if(commandName == "reverse.seqs") { pipecommand = new ReverseSeqsCommand(optionString); } + else if(commandName == "trim.seqs") { pipecommand = new TrimSeqsCommand(optionString); } + else if(commandName == "chimera.seqs") { pipecommand = new ChimeraSeqsCommand(optionString); } + else if(commandName == "list.seqs") { pipecommand = new ListSeqsCommand(optionString); } + else if(commandName == "get.seqs") { pipecommand = new GetSeqsCommand(optionString); } + else if(commandName == "remove.seqs") { pipecommand = new RemoveSeqsCommand(optionString); } + else if(commandName == "merge.files") { pipecommand = new MergeFileCommand(optionString); } + else if(commandName == "system") { pipecommand = new SystemCommand(optionString); } + else if(commandName == "align.check") { pipecommand = new AlignCheckCommand(optionString); } + else if(commandName == "get.sharedseqs") { pipecommand = new GetSharedOTUCommand(optionString); } + else if(commandName == "get.otulist") { pipecommand = new GetListCountCommand(optionString); } + else if(commandName == "hcluster") { pipecommand = new HClusterCommand(optionString); } + else if(commandName == "classify.seqs") { pipecommand = new ClassifySeqsCommand(optionString); } + else if(commandName == "chimera.ccode") { pipecommand = new ChimeraCcodeCommand(optionString); } + else if(commandName == "chimera.check") { pipecommand = new ChimeraCheckCommand(optionString); } + else if(commandName == "chimera.slayer") { pipecommand = new ChimeraSlayerCommand(optionString); } + else if(commandName == "chimera.pintail") { pipecommand = new ChimeraPintailCommand(optionString); } + else if(commandName == "chimera.bellerophon") { pipecommand = new ChimeraBellerophonCommand(optionString); } + else if(commandName == "phylotype") { pipecommand = new PhylotypeCommand(optionString); } + else if(commandName == "mgcluster") { pipecommand = new MGClusterCommand(optionString); } + else if(commandName == "pre.cluster") { pipecommand = new PreClusterCommand(optionString); } + else if(commandName == "pcoa") { pipecommand = new PCACommand(optionString); } + else if(commandName == "otu.hierarchy") { pipecommand = new OtuHierarchyCommand(optionString); } + else if(commandName == "set.dir") { pipecommand = new SetDirectoryCommand(optionString); } + else if(commandName == "set.logfile") { pipecommand = new SetLogFileCommand(optionString); } + else if(commandName == "parse.list") { pipecommand = new ParseListCommand(optionString); } + else if(commandName == "parse.sff") { pipecommand = new ParseSFFCommand(optionString); } + else if(commandName == "phylo.diversity") { pipecommand = new PhyloDiversityCommand(optionString); } + else if(commandName == "make.group") { pipecommand = new MakeGroupCommand(optionString); } + else if(commandName == "chop.seqs") { pipecommand = new ChopSeqsCommand(optionString); } + else if(commandName == "clearcut") { pipecommand = new ClearcutCommand(optionString); } + else if(commandName == "catchall") { pipecommand = new CatchAllCommand(optionString); } + else if(commandName == "split.abund") { pipecommand = new SplitAbundCommand(optionString); } + else if(commandName == "cluster.split") { pipecommand = new ClusterSplitCommand(optionString); } + else if(commandName == "classify.otu") { pipecommand = new ClassifyOtuCommand(optionString); } + else if(commandName == "degap.seqs") { pipecommand = new DegapSeqsCommand(optionString); } + else if(commandName == "get.relabund") { pipecommand = new GetRelAbundCommand(optionString); } + else if(commandName == "sens.spec") { pipecommand = new SensSpecCommand(optionString); } + else if(commandName == "seq.error") { pipecommand = new SeqErrorCommand(optionString); } + else if(commandName == "sffinfo") { pipecommand = new SffInfoCommand(optionString); } + else if(commandName == "normalize.shared") { pipecommand = new NormalizeSharedCommand(optionString); } + else if(commandName == "metastats") { pipecommand = new MetaStatsCommand(optionString); } + else if(commandName == "split.groups") { pipecommand = new SplitGroupCommand(optionString); } + else if(commandName == "cluster.fragments") { pipecommand = new ClusterFragmentsCommand(optionString); } + else if(commandName == "get.lineage") { pipecommand = new GetLineageCommand(optionString); } + else if(commandName == "remove.lineage") { pipecommand = new RemoveLineageCommand(optionString); } + else if(commandName == "fastq.info") { pipecommand = new ParseFastaQCommand(optionString); } + else { pipecommand = new NoCommand(optionString); } + + return pipecommand; + } + catch(exception& e) { + m->errorOut(e, "CommandFactory", "getCommand"); + exit(1); + } +} +/***********************************************************/ + +/***********************************************************/ +//This function calls the appropriate command fucntions based on user input, this is used by the pipeline command to check a users piepline for errors before running +Command* CommandFactory::getCommand(string commandName){ + try { + delete shellcommand; //delete the old command + + if(commandName == "read.dist") { shellcommand = new ReadDistCommand(); } + else if(commandName == "read.otu") { shellcommand = new ReadOtuCommand(); } + else if(commandName == "read.tree") { shellcommand = new ReadTreeCommand(); } + else if(commandName == "cluster") { shellcommand = new ClusterCommand(); } + else if(commandName == "unique.seqs") { shellcommand = new DeconvoluteCommand(); } + else if(commandName == "parsimony") { shellcommand = new ParsimonyCommand(); } + else if(commandName == "help") { shellcommand = new HelpCommand(); } + else if(commandName == "quit") { shellcommand = new QuitCommand(); } + else if(commandName == "collect.single") { shellcommand = new CollectCommand(); } + else if(commandName == "collect.shared") { shellcommand = new CollectSharedCommand(); } + else if(commandName == "rarefaction.single") { shellcommand = new RareFactCommand(); } + else if(commandName == "rarefaction.shared") { shellcommand = new RareFactSharedCommand(); } + else if(commandName == "summary.single") { shellcommand = new SummaryCommand(); } + else if(commandName == "summary.shared") { shellcommand = new SummarySharedCommand(); } + else if(commandName == "unifrac.weighted") { shellcommand = new UnifracWeightedCommand(); } + else if(commandName == "unifrac.unweighted") { shellcommand = new UnifracUnweightedCommand(); } + else if(commandName == "get.group") { shellcommand = new GetgroupCommand(); } + else if(commandName == "get.label") { shellcommand = new GetlabelCommand(); } + else if(commandName == "get.sabund") { shellcommand = new GetSAbundCommand(); } + else if(commandName == "get.rabund") { shellcommand = new GetRAbundCommand(); } + else if(commandName == "libshuff") { shellcommand = new LibShuffCommand(); } + else if(commandName == "heatmap.bin") { shellcommand = new HeatMapCommand(); } + else if(commandName == "heatmap.sim") { shellcommand = new HeatMapSimCommand(); } + else if(commandName == "filter.seqs") { shellcommand = new FilterSeqsCommand(); } + else if(commandName == "venn") { shellcommand = new VennCommand(); } + else if(commandName == "bin.seqs") { shellcommand = new BinSeqCommand(); } + else if(commandName == "get.oturep") { shellcommand = new GetOTURepCommand(); } + else if(commandName == "tree.shared") { shellcommand = new TreeGroupCommand(); } + else if(commandName == "dist.shared") { shellcommand = new MatrixOutputCommand(); } + else if(commandName == "bootstrap.shared") { shellcommand = new BootSharedCommand(); } + else if(commandName == "consensus") { shellcommand = new ConcensusCommand(); } + else if(commandName == "dist.seqs") { shellcommand = new DistanceCommand(); } + else if(commandName == "align.seqs") { shellcommand = new AlignCommand(); } + else if(commandName == "summary.seqs") { shellcommand = new SeqSummaryCommand(); } + else if(commandName == "screen.seqs") { shellcommand = new ScreenSeqsCommand(); } + else if(commandName == "reverse.seqs") { shellcommand = new ReverseSeqsCommand(); } + else if(commandName == "trim.seqs") { shellcommand = new TrimSeqsCommand(); } + else if(commandName == "chimera.seqs") { shellcommand = new ChimeraSeqsCommand(); } + else if(commandName == "list.seqs") { shellcommand = new ListSeqsCommand(); } + else if(commandName == "get.seqs") { shellcommand = new GetSeqsCommand(); } + else if(commandName == "remove.seqs") { shellcommand = new RemoveSeqsCommand(); } + else if(commandName == "merge.files") { shellcommand = new MergeFileCommand(); } + else if(commandName == "system") { shellcommand = new SystemCommand(); } + else if(commandName == "align.check") { shellcommand = new AlignCheckCommand(); } + else if(commandName == "get.sharedseqs") { shellcommand = new GetSharedOTUCommand(); } + else if(commandName == "get.otulist") { shellcommand = new GetListCountCommand(); } + else if(commandName == "hcluster") { shellcommand = new HClusterCommand(); } + else if(commandName == "classify.seqs") { shellcommand = new ClassifySeqsCommand(); } + else if(commandName == "chimera.ccode") { shellcommand = new ChimeraCcodeCommand(); } + else if(commandName == "chimera.check") { shellcommand = new ChimeraCheckCommand(); } + else if(commandName == "chimera.slayer") { shellcommand = new ChimeraSlayerCommand(); } + else if(commandName == "chimera.pintail") { shellcommand = new ChimeraPintailCommand(); } + else if(commandName == "chimera.bellerophon") { shellcommand = new ChimeraBellerophonCommand(); } + else if(commandName == "phylotype") { shellcommand = new PhylotypeCommand(); } + else if(commandName == "mgcluster") { shellcommand = new MGClusterCommand(); } + else if(commandName == "pre.cluster") { shellcommand = new PreClusterCommand(); } + else if(commandName == "pcoa") { shellcommand = new PCACommand(); } + else if(commandName == "otu.hierarchy") { shellcommand = new OtuHierarchyCommand(); } + else if(commandName == "set.dir") { shellcommand = new SetDirectoryCommand(); } + else if(commandName == "set.logfile") { shellcommand = new SetLogFileCommand(); } + else if(commandName == "parse.list") { shellcommand = new ParseListCommand(); } + else if(commandName == "parse.sff") { shellcommand = new ParseSFFCommand(); } + else if(commandName == "phylo.diversity") { shellcommand = new PhyloDiversityCommand(); } + else if(commandName == "make.group") { shellcommand = new MakeGroupCommand(); } + else if(commandName == "chop.seqs") { shellcommand = new ChopSeqsCommand(); } + else if(commandName == "clearcut") { shellcommand = new ClearcutCommand(); } + else if(commandName == "catchall") { shellcommand = new CatchAllCommand(); } + else if(commandName == "split.abund") { shellcommand = new SplitAbundCommand(); } + else if(commandName == "cluster.split") { shellcommand = new ClusterSplitCommand(); } + else if(commandName == "classify.otu") { shellcommand = new ClassifyOtuCommand(); } + else if(commandName == "degap.seqs") { shellcommand = new DegapSeqsCommand(); } + else if(commandName == "get.relabund") { shellcommand = new GetRelAbundCommand(); } + else if(commandName == "sens.spec") { shellcommand = new SensSpecCommand(); } + else if(commandName == "seq.error") { shellcommand = new SeqErrorCommand(); } + else if(commandName == "sffinfo") { shellcommand = new SffInfoCommand(); } + else if(commandName == "normalize.shared") { shellcommand = new NormalizeSharedCommand(); } + else if(commandName == "metastats") { shellcommand = new MetaStatsCommand(); } + else if(commandName == "split.groups") { shellcommand = new SplitGroupCommand(); } + else if(commandName == "cluster.fragments") { shellcommand = new ClusterFragmentsCommand(); } + else if(commandName == "get.lineage") { shellcommand = new GetLineageCommand(); } + else if(commandName == "remove.lineage") { shellcommand = new RemoveLineageCommand(); } + else if(commandName == "fastq.info") { shellcommand = new ParseFastaQCommand(); } + else { shellcommand = new NoCommand(); } + + return shellcommand; + } + catch(exception& e) { + m->errorOut(e, "CommandFactory", "getCommand"); + exit(1); + } +} +/*********************************************************** //This function is used to interrupt a command Command* CommandFactory::getCommand(){ try { @@ -374,7 +591,23 @@ bool CommandFactory::isValidCommand(string command) { exit(1); } } - +/***********************************************************************/ +bool CommandFactory::isValidCommand(string command, string noError) { + try { + + //is the command in the map + if ((commands.find(command)) != (commands.end())) { + return true; + }else{ + return false; + } + + } + catch(exception& e) { + m->errorOut(e, "CommandFactory", "isValidCommand"); + exit(1); + } +} /***********************************************************************/ void CommandFactory::printCommands(ostream& out) { try { diff --git a/commandfactory.hpp b/commandfactory.hpp index 44e78fd..a6dc5b7 100644 --- a/commandfactory.hpp +++ b/commandfactory.hpp @@ -18,11 +18,14 @@ class Command; class CommandFactory { public: static CommandFactory* getInstance(); + Command* getCommand(string, string, string); Command* getCommand(string, string); - Command* getCommand(); + Command* getCommand(string); + //Command* getCommand(); bool isValidCommand(string); + bool isValidCommand(string, string); void printCommands(ostream&); - void setOutputDirectory(string o) { outputDir = o; } + void setOutputDirectory(string o) { outputDir = o; m->setOutputDir(o); } void setInputDirectory(string i) { inputDir = i; } void setLogfileName(string n, bool a) { logFileName = n; append = a; } string getLogfileName() { return logFileName; } @@ -32,6 +35,8 @@ public: private: Command* command; + Command* shellcommand; + Command* pipecommand; MothurOut* m; map commands; map::iterator it; diff --git a/consensuscommand.cpp b/consensuscommand.cpp index a65d56f..a746990 100644 --- a/consensuscommand.cpp +++ b/consensuscommand.cpp @@ -9,6 +9,53 @@ #include "consensuscommand.h" +//********************************************************************************************************************** +vector ConcensusCommand::getValidParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ConcensusCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ConcensusCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ConcensusCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ConcensusCommand::getRequiredFiles(){ + try { + string AlignArray[] = {"tree","group"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ConcensusCommand", "getRequiredFiles"); + exit(1); + } +} +//********************************************************************************************************************** +ConcensusCommand::ConcensusCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["tree"] = tempOutNames; + outputTypes["nodepairs"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "ConcensusCommand", "ConcensusCommand"); + exit(1); + } +} //********************************************************************************************************************** ConcensusCommand::ConcensusCommand(string fileroot) { @@ -16,6 +63,11 @@ ConcensusCommand::ConcensusCommand(string fileroot) { globaldata = GlobalData::getInstance(); abort = false; + //initialize outputTypes + vector tempOutNames; + outputTypes["tree"] = tempOutNames; + outputTypes["nodepairs"] = tempOutNames; + filename = fileroot; t = globaldata->gTree; @@ -67,7 +119,7 @@ int ConcensusCommand::execute(){ if (m->control_pressed) { return 0; } //open file for pairing not included in the tree - notIncluded = filename + ".cons.pairs"; + notIncluded = filename + ".cons.pairs"; outputNames.push_back(notIncluded); outputTypes["nodepairs"].push_back(notIncluded); m->openOutputFile(notIncluded, out2); consensusTree = new Tree(); @@ -150,7 +202,7 @@ int ConcensusCommand::execute(){ out2 << '\t' << it2->second << endl; } - outputFile = filename + ".cons.tre"; + outputFile = filename + ".cons.tre"; outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile); m->openOutputFile(outputFile, out); consensusTree->printForBoot(out); diff --git a/consensuscommand.h b/consensuscommand.h index 7a79607..d5072da 100644 --- a/consensuscommand.h +++ b/consensuscommand.h @@ -20,7 +20,12 @@ class ConcensusCommand : public Command { public: ConcensusCommand(string); + ConcensusCommand(); ~ConcensusCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -43,6 +48,8 @@ private: string outputFile, notIncluded, filename; ofstream out, out2; int numNodes, numLeaves, count; //count is the next available spot in the tree vector + vector outputNames; + map > outputTypes; int getSets(); int getSubgroupRating(vector); diff --git a/deconvolutecommand.cpp b/deconvolutecommand.cpp index b3fa7dd..3129ea0 100644 --- a/deconvolutecommand.cpp +++ b/deconvolutecommand.cpp @@ -9,6 +9,54 @@ #include "deconvolutecommand.h" +//********************************************************************************************************************** +vector DeconvoluteCommand::getValidParameters(){ + try { + string Array[] = {"fasta", "name","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "DeconvoluteCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +DeconvoluteCommand::DeconvoluteCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["name"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "DeconvoluteCommand", "DeconvoluteCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector DeconvoluteCommand::getRequiredParameters(){ + try { + string Array[] = {"fasta"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "DeconvoluteCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector DeconvoluteCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "DeconvoluteCommand", "getRequiredFiles"); + exit(1); + } +} /**************************************************************************************/ DeconvoluteCommand::DeconvoluteCommand(string option) { try { @@ -33,6 +81,11 @@ DeconvoluteCommand::DeconvoluteCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["name"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -115,12 +168,13 @@ int DeconvoluteCommand::execute() { fastamap.printCondensedFasta(outFastaFile); fastamap.printNamesFile(outNameFile); - if (m->control_pressed) { remove(outFastaFile.c_str()); remove(outNameFile.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); remove(outFastaFile.c_str()); remove(outNameFile.c_str()); return 0; } m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); m->mothurOut(outFastaFile); m->mothurOutEndLine(); m->mothurOut(outNameFile); m->mothurOutEndLine(); + outputNames.push_back(outFastaFile); outputNames.push_back(outNameFile); outputTypes["fasta"].push_back(outFastaFile); outputTypes["name"].push_back(outNameFile); m->mothurOutEndLine(); diff --git a/deconvolutecommand.h b/deconvolutecommand.h index 9c8fd22..88b7a38 100644 --- a/deconvolutecommand.h +++ b/deconvolutecommand.h @@ -20,12 +20,19 @@ class DeconvoluteCommand : public Command { public: DeconvoluteCommand(string); - ~DeconvoluteCommand() { }; + DeconvoluteCommand(); + ~DeconvoluteCommand() {} + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); private: string inFastaName, oldNameMapFName, outputDir; + vector outputNames; + map > outputTypes; bool abort; }; diff --git a/degapseqscommand.cpp b/degapseqscommand.cpp index e475727..290d5dc 100644 --- a/degapseqscommand.cpp +++ b/degapseqscommand.cpp @@ -10,8 +10,54 @@ #include "degapseqscommand.h" #include "sequence.hpp" +//********************************************************************************************************************** +vector DegapSeqsCommand::getValidParameters(){ + try { + string Array[] = {"fasta", "outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "DegapSeqsCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +DegapSeqsCommand::DegapSeqsCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "DegapSeqsCommand", "DegapSeqsCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector DegapSeqsCommand::getRequiredParameters(){ + try { + string Array[] = {"fasta"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "DegapSeqsCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector DegapSeqsCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "DegapSeqsCommand", "getRequiredFiles"); + exit(1); + } +} //*************************************************************************************************************** - DegapSeqsCommand::DegapSeqsCommand(string option) { try { abort = false; @@ -35,6 +81,11 @@ DegapSeqsCommand::DegapSeqsCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -65,6 +116,17 @@ DegapSeqsCommand::DegapSeqsCommand(string option) { fastaFileNames[i] = tryPath; } } + + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getOutputDir() != "") { //default path is set + string tryPath = m->getOutputDir() + m->getSimpleName(fastaFileNames[i]); + m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); + fastaFileNames[i] = tryPath; + } + } + in.close(); if (ableToOpen == 1) { @@ -137,7 +199,7 @@ int DegapSeqsCommand::execute(){ m->openOutputFile(degapFile, outFASTA); while(!inFASTA.eof()){ - if (m->control_pressed) { inFASTA.close(); outFASTA.close(); remove(degapFile.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } return 0; } + if (m->control_pressed) { outputTypes.clear(); inFASTA.close(); outFASTA.close(); remove(degapFile.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } return 0; } Sequence currSeq(inFASTA); m->gobble(inFASTA); if (currSeq.getName() != "") { @@ -148,9 +210,9 @@ int DegapSeqsCommand::execute(){ inFASTA.close(); outFASTA.close(); - outputNames.push_back(degapFile); + outputNames.push_back(degapFile); outputTypes["fasta"].push_back(degapFile); - if (m->control_pressed) { remove(degapFile.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } return 0; } + if (m->control_pressed) { outputTypes.clear(); remove(degapFile.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } return 0; } } m->mothurOutEndLine(); diff --git a/degapseqscommand.h b/degapseqscommand.h index 192d6eb..5501d49 100644 --- a/degapseqscommand.h +++ b/degapseqscommand.h @@ -16,7 +16,12 @@ class DegapSeqsCommand : public Command { public: DegapSeqsCommand(string); + DegapSeqsCommand(); ~DegapSeqsCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -26,7 +31,7 @@ private: string fastafile, outputDir; vector outputNames; vector fastaFileNames; - + map > outputTypes; }; #endif diff --git a/distancecommand.cpp b/distancecommand.cpp index 60e9050..ce8aeb7 100644 --- a/distancecommand.cpp +++ b/distancecommand.cpp @@ -15,7 +15,54 @@ #include "onegapignore.h" //********************************************************************************************************************** - +vector DistanceCommand::getValidParameters(){ + try { + string Array[] = {"fasta","oldfasta","column", "output", "calc", "countends", "cutoff", "processors", "outputdir","inputdir","compress"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "DistanceCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +DistanceCommand::DistanceCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["phylip"] = tempOutNames; + outputTypes["column"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "DistanceCommand", "DistanceCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector DistanceCommand::getRequiredParameters(){ + try { + string Array[] = {"fasta"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ChopSeqsCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector DistanceCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "DistanceCommand", "getRequiredFiles"); + exit(1); + } +} +//********************************************************************************************************************** DistanceCommand::DistanceCommand(string option) { try { abort = false; @@ -41,6 +88,11 @@ DistanceCommand::DistanceCommand(string option) { if (validParameter.isValidParameter(it2->first, myArray, it2->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["phylip"] = tempOutNames; + outputTypes["column"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -213,11 +265,12 @@ int DistanceCommand::execute(){ if (output == "lt") { //does the user want lower triangle phylip formatted file outputFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "phylip.dist"; - remove(outputFile.c_str()); + remove(outputFile.c_str()); outputTypes["phylip"].push_back(outputFile); //output numSeqs to phylip formatted dist file }else if (output == "column") { //user wants column format outputFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "dist"; + outputTypes["column"].push_back(outputFile); //so we don't accidentally overwrite if (outputFile == column) { @@ -229,6 +282,7 @@ int DistanceCommand::execute(){ }else { //assume square outputFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "square.dist"; remove(outputFile.c_str()); + outputTypes["phylip"].push_back(outputFile); } @@ -270,11 +324,11 @@ int DistanceCommand::execute(){ driverMPI(start, end, outMPI, cutoff); - if (m->control_pressed) { MPI_File_close(&outMPI); delete distCalculator; return 0; } + if (m->control_pressed) { outputTypes.clear(); MPI_File_close(&outMPI); delete distCalculator; return 0; } //wait on chidren for(int i = 1; i < processors; i++) { - if (m->control_pressed) { MPI_File_close(&outMPI); delete distCalculator; return 0; } + if (m->control_pressed) { outputTypes.clear(); MPI_File_close(&outMPI); delete distCalculator; return 0; } char buf[5]; MPI_Recv(buf, 5, MPI_CHAR, i, tag, MPI_COMM_WORLD, &status); @@ -283,7 +337,7 @@ int DistanceCommand::execute(){ //do your part driverMPI(start, end, outMPI, cutoff); - if (m->control_pressed) { MPI_File_close(&outMPI); delete distCalculator; return 0; } + if (m->control_pressed) { outputTypes.clear(); MPI_File_close(&outMPI); delete distCalculator; return 0; } char buf[5]; strcpy(buf, "done"); @@ -303,7 +357,7 @@ int DistanceCommand::execute(){ if (output != "square"){ driverMPI(start, end, outputFile, mySize); } else { driverMPI(start, end, outputFile, mySize, output); } - if (m->control_pressed) { delete distCalculator; return 0; } + if (m->control_pressed) { outputTypes.clear(); delete distCalculator; return 0; } int amode=MPI_MODE_APPEND|MPI_MODE_WRONLY|MPI_MODE_CREATE; // MPI_File outMPI; @@ -322,7 +376,7 @@ int DistanceCommand::execute(){ for(int b = 1; b < processors; b++) { unsigned long int fileSize; - if (m->control_pressed) { MPI_File_close(&outMPI); delete distCalculator; return 0; } + if (m->control_pressed) { outputTypes.clear(); MPI_File_close(&outMPI); delete distCalculator; return 0; } MPI_Recv(&fileSize, 1, MPI_LONG, b, tag, MPI_COMM_WORLD, &status); @@ -398,7 +452,7 @@ int DistanceCommand::execute(){ #endif #endif - if (m->control_pressed) { delete distCalculator; remove(outputFile.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); delete distCalculator; remove(outputFile.c_str()); return 0; } #ifdef USE_MPI MPI_Comm_rank(MPI_COMM_WORLD, &pid); @@ -441,7 +495,7 @@ int DistanceCommand::execute(){ } #endif - if (m->control_pressed) { delete distCalculator; remove(outputFile.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); delete distCalculator; remove(outputFile.c_str()); return 0; } delete distCalculator; @@ -456,7 +510,8 @@ int DistanceCommand::execute(){ m->mothurOut("Compressing..."); m->mothurOutEndLine(); m->mothurOut("(Replacing " + outputFile + " with " + outputFile + ".gz)"); m->mothurOutEndLine(); system(("gzip -v " + outputFile).c_str()); - } + outputNames.push_back(outputFile + ".gz"); + }else { outputNames.push_back(outputFile); } return 0; diff --git a/distancecommand.h b/distancecommand.h index bf463a0..3b2d345 100644 --- a/distancecommand.h +++ b/distancecommand.h @@ -21,7 +21,12 @@ class DistanceCommand : public Command { public: DistanceCommand(string); + DistanceCommand(); ~DistanceCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -42,7 +47,8 @@ private: vector lines; bool abort; - vector Estimators; //holds estimators to be used + vector Estimators, outputNames; //holds estimators to be used + map > outputTypes; //void m->appendFiles(string, string); void createProcesses(string); diff --git a/eachgapignore.h b/eachgapignore.h index f6824cf..824a8b8 100644 --- a/eachgapignore.h +++ b/eachgapignore.h @@ -23,6 +23,7 @@ public: int length = 0; int start = 0; int end = 0; + bool overlap = false; string seqA = A.getAligned(); string seqB = B.getAligned(); @@ -32,6 +33,7 @@ public: if(seqA[i] != '.' && seqB[i] != '.' && seqA[i] != '-' && seqB[i] != '-' ){ start = i; // cout << "start: " << start << endl; + overlap = true; break; } } @@ -39,6 +41,7 @@ public: if(seqA[i] != '.' && seqB[i] != '.' && seqA[i] != '-' && seqB[i] != '-' ){ end = i; // cout << "end: " << end << endl; + overlap = true; break; } } @@ -55,6 +58,9 @@ public: } } + //non-overlapping sequences + if (!overlap) { length = 0; } + if(length == 0) { dist = 1.0000; } else { dist = ((double)diff / (double)length); } diff --git a/fastamap.cpp b/fastamap.cpp index 95d3f3c..25860e1 100644 --- a/fastamap.cpp +++ b/fastamap.cpp @@ -19,7 +19,9 @@ void FastaMap::readFastaFile(string inFileName) { string name, sequence, line; sequence = ""; string temp; - + map::iterator itName; + + while(!in.eof()){ if (m->control_pressed) { break; } @@ -30,7 +32,10 @@ void FastaMap::readFastaFile(string inFileName) { if(currSeq.getIsAligned()) { sequence = currSeq.getAligned(); } else { sequence = currSeq.getUnaligned(); } - seqmap[name] = sequence; + itName = seqmap.find(name); + if (itName == seqmap.end()) { seqmap[name] = sequence; } + else { m->mothurOut("You already have a sequence named " + name + ", sequence names must be unique, please correct."); m->mothurOutEndLine(); } + map::iterator it = data.find(sequence); if (it == data.end()) { //it's unique. data[sequence].groupname = name; //group name will be the name of the first duplicate sequence found. diff --git a/filterseqscommand.cpp b/filterseqscommand.cpp index a12058e..c463cd2 100644 --- a/filterseqscommand.cpp +++ b/filterseqscommand.cpp @@ -10,8 +10,55 @@ #include "filterseqscommand.h" #include "sequence.hpp" +//********************************************************************************************************************** +vector FilterSeqsCommand::getValidParameters(){ + try { + string Array[] = {"fasta", "trump", "soft", "hard", "vertical", "outputdir","inputdir", "processors"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "FilterSeqsCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +FilterSeqsCommand::FilterSeqsCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["filter"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "FilterSeqsCommand", "FilterSeqsCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector FilterSeqsCommand::getRequiredParameters(){ + try { + string Array[] = {"fasta"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "FilterSeqsCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector FilterSeqsCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "FilterSeqsCommand", "getRequiredFiles"); + exit(1); + } +} /**************************************************************************************/ - FilterSeqsCommand::FilterSeqsCommand(string option) { try { abort = false; @@ -36,6 +83,11 @@ FilterSeqsCommand::FilterSeqsCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["filter"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -84,6 +136,17 @@ FilterSeqsCommand::FilterSeqsCommand(string option) { fastafileNames[i] = tryPath; } } + + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getOutputDir() != "") { //default path is set + string tryPath = m->getOutputDir() + m->getSimpleName(fastafileNames[i]); + m->mothurOut("Unable to open " + fastafileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); + fastafileNames[i] = tryPath; + } + } + in.close(); if (ableToOpen == 1) { @@ -188,7 +251,7 @@ int FilterSeqsCommand::execute() { m->mothurOutEndLine(); m->mothurOutEndLine(); - if (m->control_pressed) { return 0; } + if (m->control_pressed) { outputTypes.clear(); return 0; } #ifdef USE_MPI int pid; @@ -207,7 +270,7 @@ int FilterSeqsCommand::execute() { m->openOutputFile(filterFile, outFilter); outFilter << filter << endl; outFilter.close(); - outputNames.push_back(filterFile); + outputNames.push_back(filterFile); outputTypes["filter"].push_back(filterFile); #ifdef USE_MPI } @@ -226,7 +289,7 @@ int FilterSeqsCommand::execute() { if(filter[i] == '1'){ filteredLength++; } } - if (m->control_pressed) { for(int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { outputTypes.clear(); for(int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } m->mothurOutEndLine(); @@ -373,7 +436,7 @@ int FilterSeqsCommand::filterSequences() { if (m->control_pressed) { return 1; } #endif #endif - outputNames.push_back(filteredFasta); + outputNames.push_back(filteredFasta); outputTypes["fasta"].push_back(filteredFasta); } return 0; diff --git a/filterseqscommand.h b/filterseqscommand.h index cb02732..c670f37 100644 --- a/filterseqscommand.h +++ b/filterseqscommand.h @@ -18,7 +18,12 @@ class FilterSeqsCommand : public Command { public: FilterSeqsCommand(string); + FilterSeqsCommand(); ~FilterSeqsCommand() {}; + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -37,6 +42,7 @@ private: int alignmentLength, processors; vector bufferSizes; vector outputNames; + map > outputTypes; char trump; bool abort; diff --git a/getgroupcommand.cpp b/getgroupcommand.cpp index cf47661..40bfb26 100644 --- a/getgroupcommand.cpp +++ b/getgroupcommand.cpp @@ -9,6 +9,53 @@ #include "getgroupcommand.h" +//********************************************************************************************************************** +vector GetgroupCommand::getValidParameters(){ + try { + string Array[] = {"outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetgroupCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +GetgroupCommand::GetgroupCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["bootgroup"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "GetgroupCommand", "GetgroupCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector GetgroupCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetgroupCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector GetgroupCommand::getRequiredFiles(){ + try { + string Array[] = {"shared"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetgroupCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** GetgroupCommand::GetgroupCommand(string option) { try { @@ -32,6 +79,10 @@ GetgroupCommand::GetgroupCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["bootgroup"] = tempOutNames; + //if the user changes the output directory command factory will send this info to us in the output parameter string outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; } @@ -102,13 +153,13 @@ int GetgroupCommand::execute(){ in >> inputData; } - if (m->control_pressed) { in.close(); out.close(); remove(outputFile.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); in.close(); out.close(); remove(outputFile.c_str()); return 0; } if (in.eof() != true) { in >> nextLabel; } //read the rest of the groups info in while ((nextLabel == holdLabel) && (in.eof() != true)) { - if (m->control_pressed) { in.close(); out.close(); remove(outputFile.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); in.close(); out.close(); remove(outputFile.c_str()); return 0; } in >> groupN >> num; count++; @@ -132,7 +183,7 @@ int GetgroupCommand::execute(){ m->mothurOutEndLine(); m->mothurOut("Output File Name: "); m->mothurOutEndLine(); - m->mothurOut(outputFile); m->mothurOutEndLine(); + m->mothurOut(outputFile); m->mothurOutEndLine(); outputNames.push_back(outputFile); outputTypes["bootgroup"].push_back(outputFile); m->mothurOutEndLine(); return 0; diff --git a/getgroupcommand.h b/getgroupcommand.h index bc805bd..fb3e810 100644 --- a/getgroupcommand.h +++ b/getgroupcommand.h @@ -16,7 +16,12 @@ class GetgroupCommand : public Command { public: GetgroupCommand(string); + GetgroupCommand(); ~GetgroupCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -24,6 +29,8 @@ private: GlobalData* globaldata; GroupMap* groupMap; string outputFile, sharedfile; + vector outputNames; + map > outputTypes; ofstream out; ifstream in; bool abort; diff --git a/getlabelcommand.cpp b/getlabelcommand.cpp index 971feb4..fe4387a 100644 --- a/getlabelcommand.cpp +++ b/getlabelcommand.cpp @@ -9,6 +9,41 @@ #include "getlabelcommand.h" +//********************************************************************************************************************** +vector GetlabelCommand::getValidParameters(){ + try { + string Array[] = {"outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetlabelCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector GetlabelCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetlabelCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector GetlabelCommand::getRequiredFiles(){ + try { + string Array[] = {"list","rabund","sabund", "or"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetlabelCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** GetlabelCommand::GetlabelCommand(string option) { diff --git a/getlabelcommand.h b/getlabelcommand.h index 3e18026..00945e1 100644 --- a/getlabelcommand.h +++ b/getlabelcommand.h @@ -18,7 +18,12 @@ class GlobalData; class GetlabelCommand : public Command { public: GetlabelCommand(string); + GetlabelCommand(){} ~GetlabelCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -26,6 +31,8 @@ private: GlobalData* globaldata; string filename; bool abort; + vector outputNames; + map > outputTypes; }; #endif diff --git a/getlineagecommand.cpp b/getlineagecommand.cpp index 5ace2a1..a1d4485 100644 --- a/getlineagecommand.cpp +++ b/getlineagecommand.cpp @@ -11,8 +11,60 @@ #include "sequence.hpp" #include "listvector.hpp" -//********************************************************************************************************************** +//********************************************************************************************************************** +vector GetLineageCommand::getValidParameters(){ + try { + string Array[] = {"fasta","name", "group", "alignreport", "taxon", "dups", "list","taxonomy","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetLineageCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +GetLineageCommand::GetLineageCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["taxonomy"] = tempOutNames; + outputTypes["name"] = tempOutNames; + outputTypes["group"] = tempOutNames; + outputTypes["alignreport"] = tempOutNames; + outputTypes["list"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "GetLineageCommand", "GetLineageCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector GetLineageCommand::getRequiredParameters(){ + try { + string Array[] = {"taxonomy"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetLineageCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector GetLineageCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetLineageCommand", "getRequiredFiles"); + exit(1); + } +} +//********************************************************************************************************************** GetLineageCommand::GetLineageCommand(string option) { try { abort = false; @@ -36,6 +88,15 @@ GetLineageCommand::GetLineageCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["taxonomy"] = tempOutNames; + outputTypes["name"] = tempOutNames; + outputTypes["group"] = tempOutNames; + outputTypes["alignreport"] = tempOutNames; + outputTypes["list"] = tempOutNames; + //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; } @@ -183,7 +244,7 @@ int GetLineageCommand::execute(){ if (listfile != "") { readList(); } - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } if (outputNames.size() != 0) { m->mothurOutEndLine(); @@ -238,7 +299,7 @@ int GetLineageCommand::readFasta(){ out.close(); if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); } - outputNames.push_back(outputFileName); + outputNames.push_back(outputFileName); outputTypes["fasta"].push_back(outputFileName); return 0; @@ -310,7 +371,7 @@ int GetLineageCommand::readList(){ out.close(); if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); } - outputNames.push_back(outputFileName); + outputNames.push_back(outputFileName); outputTypes["list"].push_back(outputFileName); return 0; @@ -403,7 +464,7 @@ int GetLineageCommand::readName(){ out.close(); if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); } - outputNames.push_back(outputFileName); + outputNames.push_back(outputFileName); outputTypes["name"].push_back(outputFileName); return 0; @@ -451,7 +512,7 @@ int GetLineageCommand::readGroup(){ out.close(); if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); } - outputNames.push_back(outputFileName); + outputNames.push_back(outputFileName); outputTypes["group"].push_back(outputFileName); return 0; @@ -504,7 +565,7 @@ int GetLineageCommand::readTax(){ out.close(); if (names.size() == 0) { m->mothurOut("Your taxonomy file does not contain any sequences from " + taxons + "."); m->mothurOutEndLine(); } - outputNames.push_back(outputFileName); + outputNames.push_back(outputFileName); outputTypes["taxonomy"].push_back(outputFileName); return 0; @@ -595,7 +656,7 @@ int GetLineageCommand::readAlign(){ out.close(); if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); } - outputNames.push_back(outputFileName); + outputNames.push_back(outputFileName); outputTypes["alignreport"].push_back(outputFileName); return 0; diff --git a/getlineagecommand.h b/getlineagecommand.h index 0d07ac6..84f773d 100644 --- a/getlineagecommand.h +++ b/getlineagecommand.h @@ -17,7 +17,12 @@ class GetLineageCommand : public Command { public: GetLineageCommand(string); + GetLineageCommand(); ~GetLineageCommand(){}; + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -26,6 +31,7 @@ class GetLineageCommand : public Command { vector outputNames; string fastafile, namefile, groupfile, alignfile, listfile, taxfile, outputDir, taxons; bool abort, dups; + map > outputTypes; int readFasta(); int readName(); diff --git a/getlistcountcommand.cpp b/getlistcountcommand.cpp index 23c0eaf..31b1748 100644 --- a/getlistcountcommand.cpp +++ b/getlistcountcommand.cpp @@ -9,6 +9,53 @@ #include "getlistcountcommand.h" +//********************************************************************************************************************** +vector GetListCountCommand::getValidParameters(){ + try { + string Array[] = {"list","label","sort","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetListCountCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +GetListCountCommand::GetListCountCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["otu"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "GetListCountCommand", "GetListCountCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector GetListCountCommand::getRequiredParameters(){ + try { + string Array[] = {"list"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetListCountCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector GetListCountCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetListCountCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** GetListCountCommand::GetListCountCommand(string option) { try { @@ -36,6 +83,10 @@ GetListCountCommand::GetListCountCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["otu"] = tempOutNames; + string ranRead = globaldata->getListFile(); //if the user changes the input directory command factory will send this info to us in the output parameter @@ -152,7 +203,7 @@ int GetListCountCommand::execute(){ delete input; delete list; globaldata->gListVector = NULL; - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); return 0; } @@ -173,7 +224,7 @@ int GetListCountCommand::execute(){ delete input; delete list; globaldata->gListVector = NULL; - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); return 0; } @@ -216,7 +267,7 @@ int GetListCountCommand::execute(){ delete input; delete list; globaldata->gListVector = NULL; - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); return 0; } @@ -248,7 +299,7 @@ void GetListCountCommand::process(ListVector* list) { if (outputDir == "") { outputDir += m->hasPath(listfile); } string outputFileName = outputDir + m->getRootName(m->getSimpleName(listfile)) + list->getLabel() + ".otu"; m->openOutputFile(outputFileName, out); - outputNames.push_back(outputFileName); + outputNames.push_back(outputFileName); outputTypes["otu"].push_back(outputFileName); m->mothurOut(list->getLabel()); m->mothurOutEndLine(); diff --git a/getlistcountcommand.h b/getlistcountcommand.h index e238cf5..60d28cc 100644 --- a/getlistcountcommand.h +++ b/getlistcountcommand.h @@ -21,8 +21,13 @@ class GlobalData; class GetListCountCommand : public Command { public: - GetListCountCommand(string); + GetListCountCommand(string); + GetListCountCommand(); ~GetListCountCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -37,6 +42,7 @@ private: string label, listfile, outputDir, sort; ofstream out; vector outputNames; + map > outputTypes; void process(ListVector*); }; diff --git a/getoturepcommand.cpp b/getoturepcommand.cpp index 6b2570c..1e09dba 100644 --- a/getoturepcommand.cpp +++ b/getoturepcommand.cpp @@ -36,6 +36,54 @@ inline bool compareGroup(repStruct left, repStruct right){ return (left.group < right.group); } //********************************************************************************************************************** +GetOTURepCommand::GetOTURepCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["name"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "GetOTURepCommand", "GetOTURepCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector GetOTURepCommand::getValidParameters(){ + try { + string Array[] = {"fasta","list","label","name", "group", "sorted", "phylip","column","large","cutoff","precision","groups","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetOTURepCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector GetOTURepCommand::getRequiredParameters(){ + try { + string Array[] = {"fasta","list"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetOTURepCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector GetOTURepCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetOTURepCommand", "getRequiredFiles"); + exit(1); + } +} +//********************************************************************************************************************** GetOTURepCommand::GetOTURepCommand(string option) { try{ globaldata = GlobalData::getInstance(); @@ -62,6 +110,11 @@ GetOTURepCommand::GetOTURepCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["name"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -378,7 +431,7 @@ int GetOTURepCommand::execute(){ if (m->control_pressed) { if (large) { inRow.close(); remove(distFile.c_str()); } - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); delete read; delete input; delete list; globaldata->gListVector = NULL; return 0; } @@ -397,7 +450,7 @@ int GetOTURepCommand::execute(){ if (m->control_pressed) { if (large) { inRow.close(); remove(distFile.c_str()); } - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); delete read; delete input; delete list; globaldata->gListVector = NULL; return 0; } @@ -437,7 +490,7 @@ int GetOTURepCommand::execute(){ if (m->control_pressed) { if (large) { inRow.close(); remove(distFile.c_str()); } - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); delete read; delete input; delete list; globaldata->gListVector = NULL; return 0; } } @@ -607,7 +660,7 @@ int GetOTURepCommand::process(ListVector* processList) { if (Groups.size() == 0) { //you don't want to use groups outputNamesFile = outputDir + m->getRootName(m->getSimpleName(listfile)) + processList->getLabel() + ".rep.names"; m->openOutputFile(outputNamesFile, newNamesOutput); - outputNames.push_back(outputNamesFile); + outputNames.push_back(outputNamesFile); outputTypes["name"].push_back(outputNamesFile); outputNameFiles[outputNamesFile] = processList->getLabel(); }else{ //you want to use groups ofstream* temp; @@ -617,7 +670,7 @@ int GetOTURepCommand::process(ListVector* processList) { outputNamesFile = outputDir + m->getRootName(m->getSimpleName(listfile)) + processList->getLabel() + "." + Groups[i] + ".rep.names"; m->openOutputFile(outputNamesFile, *(temp)); - outputNames.push_back(outputNamesFile); + outputNames.push_back(outputNamesFile); outputTypes["name"].push_back(outputNamesFile); outputNameFiles[outputNamesFile] = processList->getLabel() + "." + Groups[i]; } } @@ -705,7 +758,7 @@ int GetOTURepCommand::processNames(string filename, string label) { string outputFileName = outputDir + m->getRootName(m->getSimpleName(listfile)) + label + ".rep.fasta"; m->openOutputFile(outputFileName, out); vector reps; - outputNames.push_back(outputFileName); + outputNames.push_back(outputFileName); outputTypes["fasta"].push_back(outputFileName); ofstream out2; string tempNameFile = filename + ".temp"; diff --git a/getoturepcommand.h b/getoturepcommand.h index 8099a39..874e43c 100644 --- a/getoturepcommand.h +++ b/getoturepcommand.h @@ -39,7 +39,12 @@ class GetOTURepCommand : public Command { public: GetOTURepCommand(string); + GetOTURepCommand(); ~GetOTURepCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -66,6 +71,7 @@ private: vector seqVec; // contains maps with sequence index and distance // for all distances related to a certain sequence vector rowPositions; + map > outputTypes; void readNamesFile(); int process(ListVector*); diff --git a/getrabundcommand.cpp b/getrabundcommand.cpp index b7dd715..a38aeb3 100644 --- a/getrabundcommand.cpp +++ b/getrabundcommand.cpp @@ -10,7 +10,54 @@ #include "getrabundcommand.h" //********************************************************************************************************************** - +vector GetRAbundCommand::getValidParameters(){ + try { + string Array[] = {"label","sorted","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetRAbundCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +GetRAbundCommand::GetRAbundCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["rabund"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "GetRAbundCommand", "GetRAbundCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector GetRAbundCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetRAbundCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector GetRAbundCommand::getRequiredFiles(){ + try { + string Array[] = {"list"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetRAbundCommand", "getRequiredFiles"); + exit(1); + } +} +//********************************************************************************************************************** GetRAbundCommand::GetRAbundCommand(string option) { try { globaldata = GlobalData::getInstance(); @@ -42,6 +89,10 @@ GetRAbundCommand::GetRAbundCommand(string option) { outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it } + //initialize outputTypes + vector tempOutNames; + outputTypes["rabund"] = tempOutNames; + //make sure the user has already run the read.otu command if (globaldata->getListFile() == "") { m->mothurOut("You must read a listfile before you can use the get.rabund command."); m->mothurOutEndLine(); abort = true; } @@ -120,7 +171,7 @@ int GetRAbundCommand::execute(){ set processedLabels; set userLabels = labels; - if (m->control_pressed) { out.close(); remove(filename.c_str()); delete list; globaldata->gListVector = NULL; return 0; } + if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete list; globaldata->gListVector = NULL; return 0; } while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { @@ -129,7 +180,7 @@ int GetRAbundCommand::execute(){ rabund = new RAbundVector(); *rabund = (list->getRAbundVector()); - if (m->control_pressed) { out.close(); remove(filename.c_str()); delete list; delete rabund; globaldata->gListVector = NULL; return 0; } + if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete list; delete rabund; globaldata->gListVector = NULL; return 0; } if(sorted) { rabund->print(out); } @@ -151,7 +202,7 @@ int GetRAbundCommand::execute(){ rabund = new RAbundVector(); *rabund = (list->getRAbundVector()); - if (m->control_pressed) { out.close(); remove(filename.c_str()); delete list; delete rabund; globaldata->gListVector = NULL; return 0; } + if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete list; delete rabund; globaldata->gListVector = NULL; return 0; } if(sorted) { rabund->print(out); } else { rabund->nonSortedPrint(out); } @@ -193,7 +244,7 @@ int GetRAbundCommand::execute(){ rabund = new RAbundVector(); *rabund = (list->getRAbundVector()); - if (m->control_pressed) { out.close(); remove(filename.c_str()); delete list; delete rabund; globaldata->gListVector = NULL; return 0; } + if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete list; delete rabund; globaldata->gListVector = NULL; return 0; } if(sorted) { rabund->print(out); } else { rabund->nonSortedPrint(out); } @@ -204,7 +255,7 @@ int GetRAbundCommand::execute(){ m->mothurOutEndLine(); m->mothurOut("Output File Name: "); m->mothurOutEndLine(); - m->mothurOut(filename); m->mothurOutEndLine(); + m->mothurOut(filename); m->mothurOutEndLine(); outputNames.push_back(filename); outputTypes["rabund"].push_back(filename); m->mothurOutEndLine(); out.close(); diff --git a/getrabundcommand.h b/getrabundcommand.h index ed51be1..e853ac5 100644 --- a/getrabundcommand.h +++ b/getrabundcommand.h @@ -21,7 +21,12 @@ class GlobalData; class GetRAbundCommand : public Command { public: GetRAbundCommand(string); + GetRAbundCommand(); ~GetRAbundCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -33,6 +38,8 @@ private: InputData* input; ListVector* list; RAbundVector* rabund; + vector outputNames; + map > outputTypes; bool abort, allLines, sorted; set labels; //holds labels to be used diff --git a/getrelabundcommand.cpp b/getrelabundcommand.cpp index 4c79b21..5b9327b 100644 --- a/getrelabundcommand.cpp +++ b/getrelabundcommand.cpp @@ -10,7 +10,53 @@ #include "getrelabundcommand.h" //********************************************************************************************************************** - +vector GetRelAbundCommand::getValidParameters(){ + try { + string Array[] = {"groups","label","scale","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetRelAbundCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +GetRelAbundCommand::GetRelAbundCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["relabund"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "GetRelAbundCommand", "GetRelAbundCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector GetRelAbundCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetRelAbundCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector GetRelAbundCommand::getRequiredFiles(){ + try { + string Array[] = {"shared"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetRelAbundCommand", "getRequiredFiles"); + exit(1); + } +} +//********************************************************************************************************************** GetRelAbundCommand::GetRelAbundCommand(string option) { try { globaldata = GlobalData::getInstance(); @@ -36,6 +82,10 @@ GetRelAbundCommand::GetRelAbundCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["relabund"] = tempOutNames; + //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; @@ -136,7 +186,7 @@ int GetRelAbundCommand::execute(){ //as long as you are not at the end of the file or done wih the lines you want while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } globaldata->Groups.clear(); delete read; out.close(); remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } globaldata->Groups.clear(); delete read; out.close(); remove(outputFileName.c_str()); return 0; } if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ @@ -167,13 +217,13 @@ int GetRelAbundCommand::execute(){ //prevent memory leak for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } - if (m->control_pressed) { globaldata->Groups.clear(); delete read; out.close(); remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); globaldata->Groups.clear(); delete read; out.close(); remove(outputFileName.c_str()); return 0; } //get next line to process lookup = input->getSharedRAbundVectors(); } - if (m->control_pressed) { globaldata->Groups.clear(); delete read; out.close(); remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); globaldata->Groups.clear(); delete read; out.close(); remove(outputFileName.c_str()); return 0; } //output error messages about any remaining user labels set::iterator it; @@ -206,11 +256,11 @@ int GetRelAbundCommand::execute(){ delete read; out.close(); - if (m->control_pressed) { remove(outputFileName.c_str()); return 0;} + if (m->control_pressed) { outputTypes.clear(); remove(outputFileName.c_str()); return 0;} m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); - m->mothurOut(outputFileName); m->mothurOutEndLine(); + m->mothurOut(outputFileName); m->mothurOutEndLine(); outputNames.push_back(outputFileName); outputTypes["relabund"].push_back(outputFileName); m->mothurOutEndLine(); return 0; diff --git a/getrelabundcommand.h b/getrelabundcommand.h index 9725a31..3a5f6ad 100644 --- a/getrelabundcommand.h +++ b/getrelabundcommand.h @@ -21,7 +21,12 @@ class GetRelAbundCommand : public Command { public: GetRelAbundCommand(string); + GetRelAbundCommand(); ~GetRelAbundCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -34,7 +39,8 @@ private: bool abort, allLines, pickedGroups; set labels; //holds labels to be used string groups, label, outputDir, scale; - vector Groups; + vector Groups, outputNames; + map > outputTypes; int getRelAbundance(vector&, ofstream&); int eliminateZeroOTUS(vector& thislookup); diff --git a/getsabundcommand.cpp b/getsabundcommand.cpp index ba05ea1..8ad8b4b 100644 --- a/getsabundcommand.cpp +++ b/getsabundcommand.cpp @@ -10,7 +10,53 @@ #include "getsabundcommand.h" //********************************************************************************************************************** - +vector GetSAbundCommand::getValidParameters(){ + try { + string Array[] = {"label","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetSAbundCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +GetSAbundCommand::GetSAbundCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["sabund"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "GetSAbundCommand", "GetSAbundCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector GetSAbundCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetSAbundCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector GetSAbundCommand::getRequiredFiles(){ + try { + string Array[] = {"list","rabund"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetSAbundCommand", "getRequiredFiles"); + exit(1); + } +} +//********************************************************************************************************************** GetSAbundCommand::GetSAbundCommand(string option) { try { globaldata = GlobalData::getInstance(); @@ -36,6 +82,10 @@ GetSAbundCommand::GetSAbundCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["sabund"] = tempOutNames; + //if the user changes the output directory command factory will send this info to us in the output parameter string outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; @@ -115,7 +165,7 @@ int GetSAbundCommand::execute(){ set processedLabels; set userLabels = labels; - if (m->control_pressed) { out.close(); remove(filename.c_str()); delete order; globaldata->gorder = NULL; return 0; } + if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete order; globaldata->gorder = NULL; return 0; } while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { @@ -127,7 +177,7 @@ int GetSAbundCommand::execute(){ sabund->print(out); delete sabund; - if (m->control_pressed) { out.close(); remove(filename.c_str()); delete order; globaldata->gorder = NULL; return 0; } + if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete order; globaldata->gorder = NULL; return 0; } processedLabels.insert(order->getLabel()); userLabels.erase(order->getLabel()); @@ -145,7 +195,7 @@ int GetSAbundCommand::execute(){ sabund->print(out); delete sabund; - if (m->control_pressed) { out.close(); remove(filename.c_str()); delete order; globaldata->gorder = NULL; return 0; } + if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete order; globaldata->gorder = NULL; return 0; } processedLabels.insert(order->getLabel()); userLabels.erase(order->getLabel()); @@ -185,7 +235,7 @@ int GetSAbundCommand::execute(){ sabund->print(out); delete sabund; - if (m->control_pressed) { out.close(); remove(filename.c_str()); delete order; globaldata->gorder = NULL; return 0; } + if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete order; globaldata->gorder = NULL; return 0; } delete order; } @@ -195,7 +245,7 @@ int GetSAbundCommand::execute(){ m->mothurOutEndLine(); m->mothurOut("Output File Name: "); m->mothurOutEndLine(); - m->mothurOut(filename); m->mothurOutEndLine(); + m->mothurOut(filename); m->mothurOutEndLine(); outputNames.push_back(filename); outputTypes["sabund"].push_back(filename); m->mothurOutEndLine(); return 0; diff --git a/getsabundcommand.h b/getsabundcommand.h index e2ea5d2..b5363e1 100644 --- a/getsabundcommand.h +++ b/getsabundcommand.h @@ -21,7 +21,12 @@ class GlobalData; class GetSAbundCommand : public Command { public: GetSAbundCommand(string); + GetSAbundCommand(); ~GetSAbundCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -33,6 +38,8 @@ private: OrderVector* order; InputData* input; SAbundVector* sabund; + vector outputNames; + map > outputTypes; bool abort, allLines; set labels; //holds labels to be used diff --git a/getseqscommand.cpp b/getseqscommand.cpp index 1926ae0..34788b8 100644 --- a/getseqscommand.cpp +++ b/getseqscommand.cpp @@ -12,7 +12,58 @@ #include "listvector.hpp" //********************************************************************************************************************** - +vector GetSeqsCommand::getValidParameters(){ + try { + string Array[] = {"fasta","name", "group", "alignreport", "accnos", "dups", "list","taxonomy","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetSeqsCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +GetSeqsCommand::GetSeqsCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["taxonomy"] = tempOutNames; + outputTypes["name"] = tempOutNames; + outputTypes["group"] = tempOutNames; + outputTypes["alignreport"] = tempOutNames; + outputTypes["list"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "GetSeqsCommand", "GetSeqsCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector GetSeqsCommand::getRequiredParameters(){ + try { + string Array[] = {"accnos"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetSeqsCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector GetSeqsCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetSeqsCommand", "getRequiredFiles"); + exit(1); + } +} +//********************************************************************************************************************** GetSeqsCommand::GetSeqsCommand(string option) { try { abort = false; @@ -36,6 +87,15 @@ GetSeqsCommand::GetSeqsCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["taxonomy"] = tempOutNames; + outputTypes["name"] = tempOutNames; + outputTypes["group"] = tempOutNames; + outputTypes["alignreport"] = tempOutNames; + outputTypes["list"] = tempOutNames; + //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; } @@ -185,7 +245,7 @@ int GetSeqsCommand::execute(){ if (listfile != "") { readList(); } if (taxfile != "") { readTax(); } - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } if (outputNames.size() != 0) { m->mothurOutEndLine(); @@ -240,7 +300,7 @@ int GetSeqsCommand::readFasta(){ out.close(); if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); } - outputNames.push_back(outputFileName); + outputNames.push_back(outputFileName); outputTypes["fasta"].push_back(outputFileName); return 0; @@ -312,7 +372,7 @@ int GetSeqsCommand::readList(){ out.close(); if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); } - outputNames.push_back(outputFileName); + outputNames.push_back(outputFileName); outputTypes["list"].push_back(outputFileName); return 0; @@ -405,7 +465,7 @@ int GetSeqsCommand::readName(){ out.close(); if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); } - outputNames.push_back(outputFileName); + outputNames.push_back(outputFileName); outputTypes["name"].push_back(outputFileName); return 0; @@ -453,7 +513,7 @@ int GetSeqsCommand::readGroup(){ out.close(); if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); } - outputNames.push_back(outputFileName); + outputNames.push_back(outputFileName); outputTypes["group"].push_back(outputFileName); return 0; @@ -498,7 +558,7 @@ int GetSeqsCommand::readTax(){ out.close(); if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); } - outputNames.push_back(outputFileName); + outputNames.push_back(outputFileName); outputTypes["taxonomy"].push_back(outputFileName); return 0; @@ -566,7 +626,7 @@ int GetSeqsCommand::readAlign(){ out.close(); if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); } - outputNames.push_back(outputFileName); + outputNames.push_back(outputFileName); outputTypes["alignreport"].push_back(outputFileName); return 0; diff --git a/getseqscommand.h b/getseqscommand.h index 4f4c809..ea93b5a 100644 --- a/getseqscommand.h +++ b/getseqscommand.h @@ -17,7 +17,12 @@ class GetSeqsCommand : public Command { public: GetSeqsCommand(string); + GetSeqsCommand(); ~GetSeqsCommand(){}; + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -26,6 +31,7 @@ class GetSeqsCommand : public Command { vector outputNames; string accnosfile, fastafile, namefile, groupfile, alignfile, listfile, taxfile, outputDir; bool abort, dups; + map > outputTypes; int readFasta(); int readName(); diff --git a/getsharedotucommand.cpp b/getsharedotucommand.cpp index 492195d..f8c245f 100644 --- a/getsharedotucommand.cpp +++ b/getsharedotucommand.cpp @@ -9,8 +9,57 @@ #include "getsharedotucommand.h" -//********************************************************************************************************************** +//********************************************************************************************************************** +vector GetSharedOTUCommand::getValidParameters(){ + try { + string Array[] = {"label","unique","shared","fasta","list","group","output","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetSharedOTUCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +GetSharedOTUCommand::GetSharedOTUCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["accnos"] = tempOutNames; + outputTypes["sharedseqs"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "GetSharedOTUCommand", "GetSharedOTUCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector GetSharedOTUCommand::getRequiredParameters(){ + try { + string Array[] = {"list","group"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetSharedOTUCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector GetSharedOTUCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetSharedOTUCommand", "getRequiredFiles"); + exit(1); + } +} +//********************************************************************************************************************** GetSharedOTUCommand::GetSharedOTUCommand(string option) { try { @@ -39,6 +88,12 @@ GetSharedOTUCommand::GetSharedOTUCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["accnos"] = tempOutNames; + outputTypes["sharedseqs"] = tempOutNames; + //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; } @@ -191,7 +246,7 @@ int GetSharedOTUCommand::execute(){ m->openInputFile(fastafile, inFasta); while(!inFasta.eof()) { - if (m->control_pressed) { inFasta.close(); delete groupMap; return 0; } + if (m->control_pressed) { outputTypes.clear(); inFasta.close(); delete groupMap; return 0; } Sequence seq(inFasta); m->gobble(inFasta); if (seq.getName() != "") { seqs.push_back(seq); } @@ -214,7 +269,7 @@ int GetSharedOTUCommand::execute(){ if (m->control_pressed) { if (lastlist != NULL) { delete lastlist; } - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); delete groupMap; return 0; } @@ -277,7 +332,7 @@ int GetSharedOTUCommand::execute(){ if (lastlist != NULL) { delete lastlist; } - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } delete groupMap; return 0; } + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } delete groupMap; return 0; } m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); @@ -406,6 +461,8 @@ int GetSharedOTUCommand::process(ListVector* shared) { }else { m->mothurOut("\t" + toString(num)); m->mothurOutEndLine(); outputNames.push_back(outputFileNames); + if (output != "accnos") { outputTypes["sharedseqs"].push_back(outputFileNames); } + else { outputTypes["accnos"].push_back(outputFileNames); } } //if fasta file provided output new fasta file @@ -414,7 +471,7 @@ int GetSharedOTUCommand::process(ListVector* shared) { string outputFileFasta = outputDir + m->getRootName(m->getSimpleName(fastafile)) + shared->getLabel() + userGroups + ".shared.fasta"; ofstream outFasta; m->openOutputFile(outputFileFasta, outFasta); - outputNames.push_back(outputFileFasta); + outputNames.push_back(outputFileFasta); outputTypes["fasta"].push_back(outputFileFasta); for (int k = 0; k < seqs.size(); k++) { if (m->control_pressed) { outFasta.close(); return 0; } diff --git a/getsharedotucommand.h b/getsharedotucommand.h index 30a5cd2..0e25721 100644 --- a/getsharedotucommand.h +++ b/getsharedotucommand.h @@ -22,7 +22,12 @@ class GetSharedOTUCommand : public Command { public: GetSharedOTUCommand(string); + GetSharedOTUCommand(); ~GetSharedOTUCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -40,6 +45,7 @@ class GetSharedOTUCommand : public Command { map::iterator it; vector seqs; vector outputNames; + map > outputTypes; int process(ListVector*); diff --git a/hclustercommand.cpp b/hclustercommand.cpp index fd95323..e236d86 100644 --- a/hclustercommand.cpp +++ b/hclustercommand.cpp @@ -9,6 +9,55 @@ #include "hclustercommand.h" +//********************************************************************************************************************** +vector HClusterCommand::getValidParameters(){ + try { + string Array[] = {"cutoff","hard","precision","method","phylip","column","name","sorted","showabund","timing","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "HClusterCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +HClusterCommand::HClusterCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["list"] = tempOutNames; + outputTypes["rabund"] = tempOutNames; + outputTypes["sabund"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "HClusterCommand", "HClusterCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector HClusterCommand::getRequiredParameters(){ + try { + string Array[] = {"phylip","column","or"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "HClusterCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector HClusterCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "HClusterCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** //This function checks to make sure the cluster command has no errors and then clusters based on the method chosen. HClusterCommand::HClusterCommand(string option) { @@ -37,6 +86,12 @@ HClusterCommand::HClusterCommand(string option) { } } + //initialize outputTypes + vector tempOutNames; + outputTypes["list"] = tempOutNames; + outputTypes["rabund"] = tempOutNames; + outputTypes["sabund"] = tempOutNames; + globaldata->newRead(); //if the user changes the input directory command factory will send this info to us in the output parameter @@ -142,9 +197,9 @@ HClusterCommand::HClusterCommand(string option) { m->openOutputFile(fileroot+ tag + ".rabund", rabundFile); m->openOutputFile(fileroot+ tag + ".list", listFile); - outputNames.push_back(fileroot+ tag + ".sabund"); - outputNames.push_back(fileroot+ tag + ".rabund"); - outputNames.push_back(fileroot+ tag + ".list"); + outputNames.push_back(fileroot+ tag + ".sabund"); outputTypes["sabund"].push_back(fileroot+ tag + ".sabund"); + outputNames.push_back(fileroot+ tag + ".rabund"); outputTypes["rabund"].push_back(fileroot+ tag + ".rabund"); + outputNames.push_back(fileroot+ tag + ".list"); outputTypes["list"].push_back(fileroot+ tag + ".list"); } } } @@ -201,7 +256,7 @@ int HClusterCommand::execute(){ sabundFile.close(); rabundFile.close(); listFile.close(); - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); return 0; } @@ -217,7 +272,7 @@ int HClusterCommand::execute(){ sabundFile.close(); rabundFile.close(); listFile.close(); - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); return 0; } @@ -247,7 +302,7 @@ int HClusterCommand::execute(){ sabundFile.close(); rabundFile.close(); listFile.close(); - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); return 0; } @@ -261,7 +316,7 @@ int HClusterCommand::execute(){ sabundFile.close(); rabundFile.close(); listFile.close(); - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); return 0; } @@ -275,7 +330,7 @@ int HClusterCommand::execute(){ sabundFile.close(); rabundFile.close(); listFile.close(); - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); return 0; } @@ -308,7 +363,7 @@ int HClusterCommand::execute(){ sabundFile.close(); rabundFile.close(); listFile.close(); - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); return 0; } @@ -336,7 +391,7 @@ int HClusterCommand::execute(){ delete cluster; if (m->control_pressed) { - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); return 0; } diff --git a/hclustercommand.h b/hclustercommand.h index 1aae49d..fc03331 100644 --- a/hclustercommand.h +++ b/hclustercommand.h @@ -32,8 +32,13 @@ class HClusterCommand : public Command { public: - HClusterCommand(string); + HClusterCommand(string); + HClusterCommand(); ~HClusterCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -54,6 +59,7 @@ private: time_t start; unsigned long loops; vector outputNames; + map > outputTypes; void printData(string label); }; diff --git a/heatmapcommand.cpp b/heatmapcommand.cpp index bb82702..dc4fec2 100644 --- a/heatmapcommand.cpp +++ b/heatmapcommand.cpp @@ -9,7 +9,53 @@ #include "heatmapcommand.h" - +//********************************************************************************************************************** +vector HeatMapCommand::getValidParameters(){ + try { + string Array[] = {"groups","label","sorted","scale","fontsize","numotu","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "HeatMapCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +HeatMapCommand::HeatMapCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["svg"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "HeatMapCommand", "HeatMapCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector HeatMapCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "HeatMapCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector HeatMapCommand::getRequiredFiles(){ + try { + string Array[] = {"list","sabund","rabund","shared","relabund","or"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "HeatMapCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** HeatMapCommand::HeatMapCommand(string option) { @@ -37,6 +83,10 @@ HeatMapCommand::HeatMapCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["svg"] = tempOutNames; + //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; @@ -168,7 +218,7 @@ int HeatMapCommand::execute(){ while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } - for (int i = 0; i < outputNames.size(); i++) { if (outputNames[i] != "control") { remove(outputNames[i].c_str()); } } + for (int i = 0; i < outputNames.size(); i++) { if (outputNames[i] != "control") { remove(outputNames[i].c_str()); } } outputTypes.clear(); globaldata->Groups.clear(); delete read; delete heatmap; return 0; } @@ -176,7 +226,8 @@ int HeatMapCommand::execute(){ if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); - outputNames.push_back(heatmap->getPic(lookup)); + string outputFileName = heatmap->getPic(lookup); + outputNames.push_back(outputFileName); outputTypes["svg"].push_back(outputFileName); processedLabels.insert(lookup[0]->getLabel()); userLabels.erase(lookup[0]->getLabel()); @@ -190,7 +241,8 @@ int HeatMapCommand::execute(){ lookup = input->getSharedRAbundVectors(lastLabel); m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); - outputNames.push_back(heatmap->getPic(lookup)); + string outputFileName = heatmap->getPic(lookup); + outputNames.push_back(outputFileName); outputTypes["svg"].push_back(outputFileName); processedLabels.insert(lookup[0]->getLabel()); userLabels.erase(lookup[0]->getLabel()); @@ -209,7 +261,7 @@ int HeatMapCommand::execute(){ if (m->control_pressed) { - for (int i = 0; i < outputNames.size(); i++) { if (outputNames[i] != "control") { remove(outputNames[i].c_str()); } } + for (int i = 0; i < outputNames.size(); i++) { if (outputNames[i] != "control") { remove(outputNames[i].c_str()); } } outputTypes.clear(); globaldata->Groups.clear(); delete read; delete heatmap; return 0; } @@ -233,7 +285,8 @@ int HeatMapCommand::execute(){ lookup = input->getSharedRAbundVectors(lastLabel); m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); - outputNames.push_back(heatmap->getPic(lookup)); + string outputFileName = heatmap->getPic(lookup); + outputNames.push_back(outputFileName); outputTypes["svg"].push_back(outputFileName); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } } @@ -244,14 +297,15 @@ int HeatMapCommand::execute(){ while((rabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { if (m->control_pressed) { - for (int i = 0; i < outputNames.size(); i++) { if (outputNames[i] != "control") { remove(outputNames[i].c_str()); } } + for (int i = 0; i < outputNames.size(); i++) { if (outputNames[i] != "control") { remove(outputNames[i].c_str()); } } outputTypes.clear(); delete rabund; delete read; delete heatmap; return 0; } if(allLines == 1 || labels.count(rabund->getLabel()) == 1){ m->mothurOut(rabund->getLabel()); m->mothurOutEndLine(); - outputNames.push_back(heatmap->getPic(rabund)); + string outputFileName = heatmap->getPic(rabund); + outputNames.push_back(outputFileName); outputTypes["svg"].push_back(outputFileName); processedLabels.insert(rabund->getLabel()); userLabels.erase(rabund->getLabel()); @@ -264,7 +318,8 @@ int HeatMapCommand::execute(){ rabund = input->getRAbundVector(lastLabel); m->mothurOut(rabund->getLabel()); m->mothurOutEndLine(); - outputNames.push_back(heatmap->getPic(rabund)); + string outputFileName = heatmap->getPic(rabund); + outputNames.push_back(outputFileName); outputTypes["svg"].push_back(outputFileName); processedLabels.insert(rabund->getLabel()); userLabels.erase(rabund->getLabel()); @@ -281,7 +336,7 @@ int HeatMapCommand::execute(){ } if (m->control_pressed) { - for (int i = 0; i < outputNames.size(); i++) { if (outputNames[i] != "control") { remove(outputNames[i].c_str()); } } + for (int i = 0; i < outputNames.size(); i++) { if (outputNames[i] != "control") { remove(outputNames[i].c_str()); } } outputTypes.clear(); delete read; delete heatmap; return 0; } @@ -305,7 +360,8 @@ int HeatMapCommand::execute(){ rabund = input->getRAbundVector(lastLabel); m->mothurOut(rabund->getLabel()); m->mothurOutEndLine(); - outputNames.push_back(heatmap->getPic(rabund)); + string outputFileName = heatmap->getPic(rabund); + outputNames.push_back(outputFileName); outputTypes["svg"].push_back(outputFileName); delete rabund; globaldata->rabund = NULL; } @@ -315,7 +371,7 @@ int HeatMapCommand::execute(){ while((lookupFloat[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { if (m->control_pressed) { for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } - for (int i = 0; i < outputNames.size(); i++) { if (outputNames[i] != "control") { remove(outputNames[i].c_str()); } } + for (int i = 0; i < outputNames.size(); i++) { if (outputNames[i] != "control") { remove(outputNames[i].c_str()); } } outputTypes.clear(); globaldata->Groups.clear(); delete read; delete heatmap; return 0; } @@ -323,7 +379,8 @@ int HeatMapCommand::execute(){ if(allLines == 1 || labels.count(lookupFloat[0]->getLabel()) == 1){ m->mothurOut(lookupFloat[0]->getLabel()); m->mothurOutEndLine(); - outputNames.push_back(heatmap->getPic(lookupFloat)); + string outputFileName = heatmap->getPic(lookupFloat); + outputNames.push_back(outputFileName); outputTypes["svg"].push_back(outputFileName); processedLabels.insert(lookupFloat[0]->getLabel()); userLabels.erase(lookupFloat[0]->getLabel()); @@ -336,7 +393,8 @@ int HeatMapCommand::execute(){ lookupFloat = input->getSharedRAbundFloatVectors(lastLabel); m->mothurOut(lookupFloat[0]->getLabel()); m->mothurOutEndLine(); - outputNames.push_back(heatmap->getPic(lookupFloat)); + string outputFileName = heatmap->getPic(lookupFloat); + outputNames.push_back(outputFileName); outputTypes["svg"].push_back(outputFileName); processedLabels.insert(lookupFloat[0]->getLabel()); userLabels.erase(lookupFloat[0]->getLabel()); @@ -355,7 +413,7 @@ int HeatMapCommand::execute(){ if (m->control_pressed) { - for (int i = 0; i < outputNames.size(); i++) { if (outputNames[i] != "control") { remove(outputNames[i].c_str()); } } + for (int i = 0; i < outputNames.size(); i++) { if (outputNames[i] != "control") { remove(outputNames[i].c_str()); } } outputTypes.clear(); globaldata->Groups.clear(); delete read; delete heatmap; return 0; } @@ -379,7 +437,8 @@ int HeatMapCommand::execute(){ lookupFloat = input->getSharedRAbundFloatVectors(lastLabel); m->mothurOut(lookupFloat[0]->getLabel()); m->mothurOutEndLine(); - outputNames.push_back(heatmap->getPic(lookupFloat)); + string outputFileName = heatmap->getPic(lookupFloat); + outputNames.push_back(outputFileName); outputTypes["svg"].push_back(outputFileName); for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } } @@ -392,7 +451,7 @@ int HeatMapCommand::execute(){ delete input; globaldata->ginput = NULL; if (m->control_pressed) { - for (int i = 0; i < outputNames.size(); i++) { if (outputNames[i] != "control") { remove(outputNames[i].c_str()); } } + for (int i = 0; i < outputNames.size(); i++) { if (outputNames[i] != "control") { remove(outputNames[i].c_str()); } } outputTypes.clear(); delete read; delete heatmap; return 0; } diff --git a/heatmapcommand.h b/heatmapcommand.h index f3ae012..a85d510 100644 --- a/heatmapcommand.h +++ b/heatmapcommand.h @@ -24,7 +24,12 @@ class HeatMapCommand : public Command { public: HeatMapCommand(string); + HeatMapCommand(); ~HeatMapCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -42,6 +47,7 @@ private: set labels; //holds labels to be used string format, groups, sorted, scale, label, outputDir; vector Groups, outputNames; + map > outputTypes; int numOTU, fontSize; diff --git a/heatmapsimcommand.cpp b/heatmapsimcommand.cpp index 7e77980..1eb3cee 100644 --- a/heatmapsimcommand.cpp +++ b/heatmapsimcommand.cpp @@ -19,7 +19,52 @@ #include "sharedmorisitahorn.h" #include "sharedbraycurtis.h" - +//********************************************************************************************************************** +vector HeatMapSimCommand::getValidParameters(){ + try { + string Array[] = {"groups","label", "calc","phylip","column","name","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "HeatMapSimCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +HeatMapSimCommand::HeatMapSimCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["svg"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "HeatMapSimCommand", "HeatMapSimCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector HeatMapSimCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "HeatMapSimCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector HeatMapSimCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "HeatMapSimCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** HeatMapSimCommand::HeatMapSimCommand(string option) { @@ -50,6 +95,10 @@ HeatMapSimCommand::HeatMapSimCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["svg"] = tempOutNames; + format = ""; //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; } @@ -240,7 +289,7 @@ int HeatMapSimCommand::execute(){ delete heatmap; delete validCalculator; - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); return 0; } m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); @@ -286,7 +335,7 @@ int HeatMapSimCommand::runCommandShared() { m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); vector outfilenames = heatmap->getPic(lookup, heatCalculators); - for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); } + for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]); } processedLabels.insert(lookup[0]->getLabel()); userLabels.erase(lookup[0]->getLabel()); @@ -300,7 +349,7 @@ int HeatMapSimCommand::runCommandShared() { m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); vector outfilenames = heatmap->getPic(lookup, heatCalculators); - for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); } + for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]); } processedLabels.insert(lookup[0]->getLabel()); userLabels.erase(lookup[0]->getLabel()); @@ -344,7 +393,7 @@ int HeatMapSimCommand::runCommandShared() { m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); vector outfilenames = heatmap->getPic(lookup, heatCalculators); - for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); } + for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]); } for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } } @@ -482,8 +531,10 @@ int HeatMapSimCommand::runCommandDist() { delete nameMap; } - - outputNames.push_back(heatmap->getPic(matrix, names)); //vector>, vector + + string outputFileName = heatmap->getPic(matrix, names); + outputNames.push_back(outputFileName); //vector>, vector + outputTypes["svg"].push_back(outputFileName); return 0; } diff --git a/heatmapsimcommand.h b/heatmapsimcommand.h index a260180..cd12c17 100644 --- a/heatmapsimcommand.h +++ b/heatmapsimcommand.h @@ -22,7 +22,12 @@ class HeatMapSimCommand : public Command { public: HeatMapSimCommand(string); + HeatMapSimCommand(); ~HeatMapSimCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -41,6 +46,7 @@ private: set labels; //holds labels to be used string format, groups, label, calc, phylipfile, columnfile, namefile, outputDir; vector Estimators, Groups, outputNames; + map > outputTypes; int runCommandShared(); int runCommandDist(); diff --git a/helpcommand.cpp b/helpcommand.cpp index 36ce2b7..24d587b 100644 --- a/helpcommand.cpp +++ b/helpcommand.cpp @@ -9,6 +9,40 @@ #include "helpcommand.h" +//********************************************************************************************************************** +vector HelpCommand::getValidParameters(){ + try { + + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "HelpCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector HelpCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "HelpCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector HelpCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "HelpCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** HelpCommand::HelpCommand(string option) { diff --git a/helpcommand.h b/helpcommand.h index 7a19ee6..d4e7b1f 100644 --- a/helpcommand.h +++ b/helpcommand.h @@ -18,12 +18,19 @@ class HelpCommand : public Command { public: HelpCommand(string); + HelpCommand() {} ~HelpCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help() {}; private: CommandFactory* validCommands; + vector outputNames; + map > outputTypes; private: diff --git a/ignoregaps.h b/ignoregaps.h index e81ab92..d4e5ee5 100644 --- a/ignoregaps.h +++ b/ignoregaps.h @@ -24,6 +24,7 @@ public: int diff = 0; int length = 0; int start = 0; + bool overlap = false; string seqA = A.getAligned(); string seqB = B.getAligned(); @@ -32,6 +33,7 @@ public: for(int i=0;i LibShuffCommand::getValidParameters(){ + try { + string Array[] = {"iters","groups","step","form","cutoff","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "LibShuffCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +LibShuffCommand::LibShuffCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["coverage"] = tempOutNames; + outputTypes["libshuffsummary"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "LibShuffCommand", "LibShuffCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector LibShuffCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "LibShuffCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector LibShuffCommand::getRequiredFiles(){ + try { + string Array[] = {"phylip","group"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "LibShuffCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** LibShuffCommand::LibShuffCommand(string option) { @@ -44,6 +92,11 @@ LibShuffCommand::LibShuffCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["coverage"] = tempOutNames; + outputTypes["libshuffsummary"] = tempOutNames; + //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; @@ -147,14 +200,14 @@ int LibShuffCommand::execute(){ pValueCounts[i].assign(numGroups, 0); } - if (m->control_pressed) { delete form; globaldata->Groups.clear(); delete globaldata->gMatrix; globaldata->gMatrix = NULL; return 0; } + if (m->control_pressed) { outputTypes.clear(); delete form; globaldata->Groups.clear(); delete globaldata->gMatrix; globaldata->gMatrix = NULL; return 0; } Progress* reading = new Progress(); for(int i=0;icontrol_pressed) { delete form; globaldata->Groups.clear(); delete globaldata->gMatrix; globaldata->gMatrix = NULL; delete reading; return 0; } + if (m->control_pressed) { outputTypes.clear(); delete form; globaldata->Groups.clear(); delete globaldata->gMatrix; globaldata->gMatrix = NULL; delete reading; return 0; } reading->newLine(groupNames[i]+'-'+groupNames[j], iters); int spoti = globaldata->gGroupmap->groupIndex[groupNames[i]]; //neccessary in case user selects groups so you know where they are in the matrix @@ -162,13 +215,13 @@ int LibShuffCommand::execute(){ for(int p=0;pcontrol_pressed) { delete form; globaldata->Groups.clear(); delete globaldata->gMatrix; globaldata->gMatrix = NULL; delete reading; return 0; } + if (m->control_pressed) { outputTypes.clear(); delete form; globaldata->Groups.clear(); delete globaldata->gMatrix; globaldata->gMatrix = NULL; delete reading; return 0; } form->randomizeGroups(spoti,spotj); if(form->evaluatePair(spoti,spotj) >= savedDXYValues[spoti][spotj]) { pValueCounts[i][j]++; } if(form->evaluatePair(spotj,spoti) >= savedDXYValues[spotj][spoti]) { pValueCounts[j][i]++; } - if (m->control_pressed) { delete form; globaldata->Groups.clear(); delete globaldata->gMatrix; globaldata->gMatrix = NULL; delete reading; return 0; } + if (m->control_pressed) { outputTypes.clear(); delete form; globaldata->Groups.clear(); delete globaldata->gMatrix; globaldata->gMatrix = NULL; delete reading; return 0; } reading->update(p); } @@ -177,7 +230,7 @@ int LibShuffCommand::execute(){ } } - if (m->control_pressed) { delete form; globaldata->Groups.clear(); delete globaldata->gMatrix; globaldata->gMatrix = NULL; delete reading; return 0; } + if (m->control_pressed) { outputTypes.clear(); delete form; globaldata->Groups.clear(); delete globaldata->gMatrix; globaldata->gMatrix = NULL; delete reading; return 0; } reading->finish(); delete reading; @@ -193,7 +246,7 @@ int LibShuffCommand::execute(){ //delete globaldata's copy of the gmatrix to free up memory delete globaldata->gMatrix; globaldata->gMatrix = NULL; - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } m->mothurOutEndLine(); @@ -217,7 +270,7 @@ int LibShuffCommand::printCoverageFile() { ofstream outCov; summaryFile = outputDir + m->getRootName(m->getSimpleName(globaldata->getPhylipFile())) + "libshuff.coverage"; m->openOutputFile(summaryFile, outCov); - outputNames.push_back(summaryFile); + outputNames.push_back(summaryFile); outputTypes["coverage"].push_back(summaryFile); outCov.setf(ios::fixed, ios::floatfield); outCov.setf(ios::showpoint); //cout.setf(ios::fixed, ios::floatfield); cout.setf(ios::showpoint); @@ -313,7 +366,7 @@ int LibShuffCommand::printSummaryFile() { ofstream outSum; summaryFile = outputDir + m->getRootName(m->getSimpleName(globaldata->getPhylipFile())) + "libshuff.summary"; m->openOutputFile(summaryFile, outSum); - outputNames.push_back(summaryFile); + outputNames.push_back(summaryFile); outputTypes["libshuffsummary"].push_back(summaryFile); outSum.setf(ios::fixed, ios::floatfield); outSum.setf(ios::showpoint); cout.setf(ios::fixed, ios::floatfield); cout.setf(ios::showpoint); diff --git a/libshuffcommand.h b/libshuffcommand.h index 1c8fbc4..3240860 100644 --- a/libshuffcommand.h +++ b/libshuffcommand.h @@ -20,8 +20,13 @@ class GlobalData; class LibShuffCommand : public Command { public: - LibShuffCommand(string); + LibShuffCommand(string); + LibShuffCommand(); ~LibShuffCommand(){}; + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -45,6 +50,7 @@ private: bool abort; string outputFile, groups, userform, savegroups, outputDir; vector Groups, outputNames; //holds groups to be used + map > outputTypes; }; #endif diff --git a/listseqscommand.cpp b/listseqscommand.cpp index d85d5be..c8c8297 100644 --- a/listseqscommand.cpp +++ b/listseqscommand.cpp @@ -11,6 +11,53 @@ #include "sequence.hpp" #include "listvector.hpp" +//********************************************************************************************************************** +vector ListSeqsCommand::getValidParameters(){ + try { + string Array[] = {"fasta","name", "group", "alignreport","list","taxonomy","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ListSeqsCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +ListSeqsCommand::ListSeqsCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["accnos"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "ListSeqsCommand", "ListSeqsCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector ListSeqsCommand::getRequiredParameters(){ + try { + string Array[] = {"fasta","name", "group", "alignreport","list","taxonomy","or"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ListSeqsCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ListSeqsCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ListSeqsCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** ListSeqsCommand::ListSeqsCommand(string option) { @@ -36,6 +83,10 @@ ListSeqsCommand::ListSeqsCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["accnos"] = tempOutNames; + //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; } @@ -164,7 +215,7 @@ int ListSeqsCommand::execute(){ else if (listfile != "") { inputFileName = listfile; readList(); } else if (taxfile != "") { inputFileName = taxfile; readTax(); } - if (m->control_pressed) { return 0; } + if (m->control_pressed) { outputTypes.clear(); return 0; } //sort in alphabetical order sort(names.begin(), names.end()); @@ -179,17 +230,17 @@ int ListSeqsCommand::execute(){ //output to .accnos file for (int i = 0; i < names.size(); i++) { - if (m->control_pressed) { out.close(); remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); out.close(); remove(outputFileName.c_str()); return 0; } out << names[i] << endl; } out.close(); - if (m->control_pressed) { remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); remove(outputFileName.c_str()); return 0; } m->mothurOutEndLine(); m->mothurOut("Output File Name: "); m->mothurOutEndLine(); - m->mothurOut(outputFileName); m->mothurOutEndLine(); + m->mothurOut(outputFileName); m->mothurOutEndLine(); outputNames.push_back(outputFileName); outputTypes["accnos"].push_back(outputFileName); m->mothurOutEndLine(); return 0; diff --git a/listseqscommand.h b/listseqscommand.h index 6a210a1..889b373 100644 --- a/listseqscommand.h +++ b/listseqscommand.h @@ -16,13 +16,19 @@ class ListSeqsCommand : public Command { public: - ListSeqsCommand(string); - ~ListSeqsCommand(){}; + ListSeqsCommand(string); + ListSeqsCommand(); + ~ListSeqsCommand(){} + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); private: - vector names; + vector names, outputNames; + map > outputTypes; string fastafile, namefile, groupfile, alignfile, inputFileName, outputDir, listfile, taxfile; bool abort; diff --git a/makegroupcommand.cpp b/makegroupcommand.cpp index 8dd1d67..fd68b80 100644 --- a/makegroupcommand.cpp +++ b/makegroupcommand.cpp @@ -10,6 +10,53 @@ #include "makegroupcommand.h" #include "sequence.hpp" +//********************************************************************************************************************** +vector MakeGroupCommand::getValidParameters(){ + try { + string Array[] = {"fasta", "groups","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "MakeGroupCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +MakeGroupCommand::MakeGroupCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["group"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "MakeGroupCommand", "MakeGroupCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector MakeGroupCommand::getRequiredParameters(){ + try { + string Array[] = {"fasta","groups"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "MakeGroupCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector MakeGroupCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "MakeGroupCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** MakeGroupCommand::MakeGroupCommand(string option) { @@ -36,7 +83,11 @@ MakeGroupCommand::MakeGroupCommand(string option) { for (it = parameters.begin(); it != parameters.end(); it++) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } - + + //initialize outputTypes + vector tempOutNames; + outputTypes["group"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -68,6 +119,16 @@ MakeGroupCommand::MakeGroupCommand(string option) { fastaFileNames[i] = tryPath; } } + + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getOutputDir() != "") { //default path is set + string tryPath = m->getOutputDir() + m->getSimpleName(fastaFileNames[i]); + m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); + fastaFileNames[i] = tryPath; + } + } in.close(); if (ableToOpen == 1) { @@ -140,7 +201,7 @@ int MakeGroupCommand::execute(){ for (int i = 0; i < fastaFileNames.size(); i++) { - if (m->control_pressed) { out.close(); remove(filename.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); return 0; } ifstream in; m->openInputFile(fastaFileNames[i], in); @@ -149,7 +210,7 @@ int MakeGroupCommand::execute(){ Sequence seq(in, "no align"); m->gobble(in); - if (m->control_pressed) { in.close(); out.close(); remove(filename.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); in.close(); out.close(); remove(filename.c_str()); return 0; } if (seq.getName() != "") { out << seq.getName() << '\t' << groupsNames[i] << endl; } } @@ -159,7 +220,7 @@ int MakeGroupCommand::execute(){ out.close(); m->mothurOutEndLine(); - m->mothurOut("Output File Name: " + filename); m->mothurOutEndLine(); + m->mothurOut("Output File Name: " + filename); m->mothurOutEndLine(); outputNames.push_back(filename); outputTypes["group"].push_back(filename); m->mothurOutEndLine(); return 0; diff --git a/makegroupcommand.h b/makegroupcommand.h index 23d4598..260deaa 100644 --- a/makegroupcommand.h +++ b/makegroupcommand.h @@ -15,8 +15,13 @@ class MakeGroupCommand : public Command { public: - MakeGroupCommand(string); + MakeGroupCommand(string); + MakeGroupCommand(); ~MakeGroupCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -24,7 +29,8 @@ private: string fastaFileName, groups, outputDir, filename; vector fastaFileNames; - vector groupsNames; + vector groupsNames, outputNames; + map > outputTypes; bool abort; }; diff --git a/matrixoutputcommand.cpp b/matrixoutputcommand.cpp index a55edd0..020ccff 100644 --- a/matrixoutputcommand.cpp +++ b/matrixoutputcommand.cpp @@ -19,7 +19,53 @@ #include "sharedmorisitahorn.h" #include "sharedbraycurtis.h" - +//********************************************************************************************************************** +vector MatrixOutputCommand::getValidParameters(){ + try { + string Array[] = {"label","calc","groups","outputdir","inputdir", "output"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "MatrixOutputCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +MatrixOutputCommand::MatrixOutputCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["phylip"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "MatrixOutputCommand", "MatrixOutputCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector MatrixOutputCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "MatrixOutputCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector MatrixOutputCommand::getRequiredFiles(){ + try { + string Array[] = {"shared"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "MatrixOutputCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** MatrixOutputCommand::MatrixOutputCommand(string option) { @@ -49,6 +95,10 @@ MatrixOutputCommand::MatrixOutputCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["phylip"] = tempOutNames; + //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; @@ -199,7 +249,7 @@ int MatrixOutputCommand::execute(){ //as long as you are not at the end of the file or done wih the lines you want while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0; } + if (m->control_pressed) { outputTypes.clear(); delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0; } if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); @@ -232,7 +282,7 @@ int MatrixOutputCommand::execute(){ lookup = input->getSharedRAbundVectors(); } - if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0; } + if (m->control_pressed) { outputTypes.clear(); delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0; } //output error messages about any remaining user labels set::iterator it; @@ -247,7 +297,7 @@ int MatrixOutputCommand::execute(){ } } - if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0; } + if (m->control_pressed) { outputTypes.clear(); delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0; } //run last label if you need to if (needToRun == true) { @@ -259,7 +309,7 @@ int MatrixOutputCommand::execute(){ for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } } - if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0; } + if (m->control_pressed) { outputTypes.clear(); delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0; } //reset groups parameter globaldata->Groups.clear(); @@ -349,7 +399,7 @@ int MatrixOutputCommand::process(vector thisLookup){ exportFileName = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + matrixCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + output + ".dist"; m->openOutputFile(exportFileName, out); - outputNames.push_back(exportFileName); + outputNames.push_back(exportFileName); outputTypes["phylip"].push_back(exportFileName); printSims(out); out.close(); diff --git a/matrixoutputcommand.h b/matrixoutputcommand.h index 537f791..2a79081 100644 --- a/matrixoutputcommand.h +++ b/matrixoutputcommand.h @@ -26,8 +26,13 @@ class GlobalData; class MatrixOutputCommand : public Command { public: - MatrixOutputCommand(string); + MatrixOutputCommand(string); + MatrixOutputCommand(); ~MatrixOutputCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -50,6 +55,7 @@ private: set labels; //holds labels to be used string outputFile, calc, groups, label, outputDir; vector Estimators, Groups, outputNames; //holds estimators to be used + map > outputTypes; }; diff --git a/mergefilecommand.cpp b/mergefilecommand.cpp index 098da00..d431dd3 100644 --- a/mergefilecommand.cpp +++ b/mergefilecommand.cpp @@ -9,6 +9,53 @@ #include "mergefilecommand.h" +//********************************************************************************************************************** +vector MergeFileCommand::getValidParameters(){ + try { + string Array[] = {"input", "output","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "MergeFileCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +MergeFileCommand::MergeFileCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["merge"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "MergeFileCommand", "MergeFileCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector MergeFileCommand::getRequiredParameters(){ + try { + string Array[] = {"input","output"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "MergeFileCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector MergeFileCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "MergeFileCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** MergeFileCommand::MergeFileCommand(string option) { @@ -34,6 +81,10 @@ MergeFileCommand::MergeFileCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["merge"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -67,7 +118,7 @@ MergeFileCommand::MergeFileCommand(string option) { outputFileName = validParameter.validFile(parameters, "output", false); if (outputFileName == "not found") { m->mothurOut("you must enter an output file name"); m->mothurOutEndLine(); abort=true; } - else if (outputDir != "") { outputFileName = outputDir + m->getSimpleName(outputFileName); } + else if (outputDir != "") { outputFileName = outputDir + m->getSimpleName(outputFileName); } } } @@ -97,7 +148,7 @@ int MergeFileCommand::execute(){ m->openInputFile(fileNames[i], inputFile); while(!inputFile.eof()){ - if (m->control_pressed) { inputFile.close(); outputFile.close(); remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); inputFile.close(); outputFile.close(); remove(outputFileName.c_str()); return 0; } c = inputFile.get(); //-1 is eof char @@ -109,11 +160,11 @@ int MergeFileCommand::execute(){ outputFile.close(); - if (m->control_pressed) { remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); remove(outputFileName.c_str()); return 0; } m->mothurOutEndLine(); m->mothurOut("Output File Name: "); m->mothurOutEndLine(); - m->mothurOut(outputFileName); m->mothurOutEndLine(); + m->mothurOut(outputFileName); m->mothurOutEndLine(); outputNames.push_back(outputFileName); outputTypes["merge"].push_back(outputFileName); m->mothurOutEndLine(); return 0; diff --git a/mergefilecommand.h b/mergefilecommand.h index bd94d77..56da315 100644 --- a/mergefilecommand.h +++ b/mergefilecommand.h @@ -16,12 +16,18 @@ class MergeFileCommand : public Command { public: MergeFileCommand(string); + MergeFileCommand(); ~MergeFileCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); private: - vector fileNames; + vector fileNames, outputNames; + map > outputTypes; string outputFileName; int numInputFiles; bool abort; diff --git a/metastatscommand.cpp b/metastatscommand.cpp index 7d1f4df..08c94ba 100644 --- a/metastatscommand.cpp +++ b/metastatscommand.cpp @@ -11,6 +11,54 @@ #include "metastats.h" #include "sharedutilities.h" +//********************************************************************************************************************** +vector MetaStatsCommand::getValidParameters(){ + try { + string Array[] = {"groups","label","outputdir","iters","threshold","g","design","sets","processors","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "MetaStatsCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +MetaStatsCommand::MetaStatsCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["metastats"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "MetaStatsCommand", "MetaStatsCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector MetaStatsCommand::getRequiredParameters(){ + try { + string Array[] = {"design"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "MetaStatsCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector MetaStatsCommand::getRequiredFiles(){ + try { + string Array[] = {"shared"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "MetaStatsCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** MetaStatsCommand::MetaStatsCommand(string option) { @@ -39,6 +87,10 @@ MetaStatsCommand::MetaStatsCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["metastats"] = tempOutNames; + //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; @@ -206,7 +258,7 @@ int MetaStatsCommand::execute(){ //as long as you are not at the end of the file or done wih the lines you want while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } globaldata->Groups.clear(); delete read; delete designMap; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } globaldata->Groups.clear(); delete read; delete designMap; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ @@ -237,13 +289,13 @@ int MetaStatsCommand::execute(){ //prevent memory leak for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } - if (m->control_pressed) { globaldata->Groups.clear(); delete read; delete designMap; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { outputTypes.clear(); globaldata->Groups.clear(); delete read; delete designMap; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } //get next line to process lookup = input->getSharedRAbundVectors(); } - if (m->control_pressed) { globaldata->Groups.clear(); delete read; delete designMap; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { outputTypes.clear(); globaldata->Groups.clear(); delete read; delete designMap; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } //output error messages about any remaining user labels set::iterator it; @@ -276,7 +328,7 @@ int MetaStatsCommand::execute(){ delete read; delete designMap; - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0;} + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0;} m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); @@ -350,7 +402,7 @@ int MetaStatsCommand::driver(int start, int num, vector& th //get filename string outputFileName = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + thisLookUp[0]->getLabel() + "." + setA + "-" + setB + ".metastats"; - outputNames.push_back(outputFileName); + outputNames.push_back(outputFileName); outputTypes["metastats"].push_back(outputFileName); int nameLength = outputFileName.length(); char * output = new char[nameLength]; strcpy(output, outputFileName.c_str()); diff --git a/metastatscommand.h b/metastatscommand.h index 1c3f10c..a38f3a7 100644 --- a/metastatscommand.h +++ b/metastatscommand.h @@ -21,7 +21,12 @@ class MetaStatsCommand : public Command { public: MetaStatsCommand(string); + MetaStatsCommand(); ~MetaStatsCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -38,6 +43,7 @@ private: ReadOTUFile* read; InputData* input; vector lookup; + map > outputTypes; bool abort, allLines, pickedGroups; set labels; //holds labels to be used diff --git a/mgclustercommand.cpp b/mgclustercommand.cpp index eef54ef..e5dd1a3 100644 --- a/mgclustercommand.cpp +++ b/mgclustercommand.cpp @@ -9,6 +9,56 @@ #include "mgclustercommand.h" + +//********************************************************************************************************************** +vector MGClusterCommand::getValidParameters(){ + try { + string Array[] = {"blast", "method", "name", "hard", "cutoff", "precision", "length", "min", "penalty", "hcluster","merge","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "MGClusterCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +MGClusterCommand::MGClusterCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["list"] = tempOutNames; + outputTypes["rabund"] = tempOutNames; + outputTypes["sabund"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "MGClusterCommand", "MGClusterCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector MGClusterCommand::getRequiredParameters(){ + try { + string Array[] = {"blast"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "MGClusterCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector MGClusterCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "MGClusterCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** MGClusterCommand::MGClusterCommand(string option) { try { @@ -34,6 +84,12 @@ MGClusterCommand::MGClusterCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["list"] = tempOutNames; + outputTypes["rabund"] = tempOutNames; + outputTypes["sabund"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -167,7 +223,7 @@ int MGClusterCommand::execute(){ list = new ListVector(nameMap->getListVector()); RAbundVector* rabund = new RAbundVector(list->getRAbundVector()); - if (m->control_pressed) { delete nameMap; delete read; delete list; delete rabund; return 0; } + if (m->control_pressed) { outputTypes.clear(); delete nameMap; delete read; delete list; delete rabund; return 0; } start = time(NULL); oldList = *list; @@ -186,6 +242,7 @@ int MGClusterCommand::execute(){ if (m->control_pressed) { delete nameMap; delete read; delete list; delete rabund; listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str()); + outputTypes.clear(); return 0; } @@ -206,6 +263,7 @@ int MGClusterCommand::execute(){ if (m->control_pressed) { delete nameMap; delete distMatrix; delete list; delete rabund; delete cluster; listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str()); + outputTypes.clear(); return 0; } @@ -217,6 +275,7 @@ int MGClusterCommand::execute(){ if (m->control_pressed) { delete nameMap; delete distMatrix; delete list; delete rabund; delete cluster; listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str()); + outputTypes.clear(); return 0; } @@ -239,6 +298,7 @@ int MGClusterCommand::execute(){ if (m->control_pressed) { delete nameMap; delete distMatrix; delete list; delete rabund; delete cluster; delete temp; listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str()); + outputTypes.clear(); return 0; } @@ -269,6 +329,7 @@ int MGClusterCommand::execute(){ if (m->control_pressed) { delete nameMap; delete distMatrix; delete list; delete rabund; delete cluster; delete temp; listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str()); + outputTypes.clear(); return 0; } @@ -298,6 +359,7 @@ int MGClusterCommand::execute(){ if (m->control_pressed) { delete nameMap; delete list; delete rabund; listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str()); + outputTypes.clear(); return 0; } @@ -314,6 +376,7 @@ int MGClusterCommand::execute(){ if (m->control_pressed) { delete nameMap; delete list; delete rabund; delete hcluster; listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str()); + outputTypes.clear(); return 0; } @@ -326,6 +389,7 @@ int MGClusterCommand::execute(){ listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str()); remove(distFile.c_str()); remove(overlapFile.c_str()); + outputTypes.clear(); return 0; } @@ -340,6 +404,7 @@ int MGClusterCommand::execute(){ listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str()); remove(distFile.c_str()); remove(overlapFile.c_str()); + outputTypes.clear(); return 0; } @@ -363,6 +428,7 @@ int MGClusterCommand::execute(){ listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str()); remove(distFile.c_str()); remove(overlapFile.c_str()); + outputTypes.clear(); return 0; } @@ -398,6 +464,7 @@ int MGClusterCommand::execute(){ listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str()); remove(distFile.c_str()); remove(overlapFile.c_str()); + outputTypes.clear(); return 0; } @@ -429,14 +496,15 @@ int MGClusterCommand::execute(){ listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str()); globaldata->setListFile(""); globaldata->setFormat(""); + outputTypes.clear(); return 0; } m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); - m->mothurOut(fileroot+ tag + ".list"); m->mothurOutEndLine(); - m->mothurOut(fileroot+ tag + ".rabund"); m->mothurOutEndLine(); - m->mothurOut(fileroot+ tag + ".sabund"); m->mothurOutEndLine(); + m->mothurOut(fileroot+ tag + ".list"); m->mothurOutEndLine(); outputNames.push_back(fileroot+ tag + ".list"); outputTypes["list"].push_back(fileroot+ tag + ".list"); + m->mothurOut(fileroot+ tag + ".rabund"); m->mothurOutEndLine(); outputNames.push_back(fileroot+ tag + ".rabund"); outputTypes["rabund"].push_back(fileroot+ tag + ".rabund"); + m->mothurOut(fileroot+ tag + ".sabund"); m->mothurOutEndLine(); outputNames.push_back(fileroot+ tag + ".sabund"); outputTypes["sabund"].push_back(fileroot+ tag + ".sabund"); m->mothurOutEndLine(); m->mothurOut("It took " + toString(time(NULL) - start) + " seconds to cluster."); m->mothurOutEndLine(); diff --git a/mgclustercommand.h b/mgclustercommand.h index 4ef0bd9..f16a8f0 100644 --- a/mgclustercommand.h +++ b/mgclustercommand.h @@ -24,7 +24,12 @@ class MGClusterCommand : public Command { public: MGClusterCommand(string); + MGClusterCommand(); ~MGClusterCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -37,6 +42,8 @@ private: ListVector* list; ListVector oldList; vector overlapMatrix; + vector outputNames; + map > outputTypes; string blastfile, method, namefile, overlapFile, distFile, outputDir; ofstream sabundFile, rabundFile, listFile; diff --git a/mothur b/mothur index 405237b..f090f30 100755 Binary files a/mothur and b/mothur differ diff --git a/mothurout.cpp b/mothurout.cpp index 67c62c1..cd9e321 100644 --- a/mothurout.cpp +++ b/mothurout.cpp @@ -60,6 +60,16 @@ void MothurOut::setDefaultPath(string pathname) { } } /*********************************************************************************************/ +void MothurOut::setOutputDir(string pathname) { + try { + outputDir = pathname; + } + catch(exception& e) { + errorOut(e, "MothurOut", "setOutputDir"); + exit(1); + } +} +/*********************************************************************************************/ void MothurOut::closeLog() { try { diff --git a/mothurout.h b/mothurout.h index 2244eee..9921a40 100644 --- a/mothurout.h +++ b/mothurout.h @@ -27,6 +27,8 @@ class MothurOut { void closeLog(); string getDefaultPath() { return defaultPath; } void setDefaultPath(string); + string getOutputDir() { return outputDir; } + void setOutputDir(string); string getReleaseDate() { return releaseDate; } void setReleaseDate(string r) { releaseDate = r; } @@ -95,7 +97,7 @@ class MothurOut { ~MothurOut(); string logFileName; - string defaultPath; + string defaultPath, outputDir; string releaseDate, version; ofstream out; diff --git a/nocommands.cpp b/nocommands.cpp index 1a01d37..eab873b 100644 --- a/nocommands.cpp +++ b/nocommands.cpp @@ -9,6 +9,39 @@ #include "nocommands.h" +//********************************************************************************************************************** +vector NoCommand::getValidParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "NoCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector NoCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "NoCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector NoCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "NoCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** NoCommand::NoCommand(string option) {} diff --git a/nocommands.h b/nocommands.h index 5b84b65..f11673f 100644 --- a/nocommands.h +++ b/nocommands.h @@ -18,11 +18,18 @@ class NoCommand : public Command { public: NoCommand(string); + NoCommand() {} ~NoCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help() {} private: + vector outputNames; + map > outputTypes; }; diff --git a/normalizesharedcommand.cpp b/normalizesharedcommand.cpp index 4a33332..dc5ed19 100644 --- a/normalizesharedcommand.cpp +++ b/normalizesharedcommand.cpp @@ -9,6 +9,53 @@ #include "normalizesharedcommand.h" +//********************************************************************************************************************** +vector NormalizeSharedCommand::getValidParameters(){ + try { + string Array[] = {"groups","label","scale","outputdir","inputdir","norm"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "NormalizeSharedCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +NormalizeSharedCommand::NormalizeSharedCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["shared"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "NormalizeSharedCommand", "NormalizeSharedCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector NormalizeSharedCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "NormalizeSharedCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector NormalizeSharedCommand::getRequiredFiles(){ + try { + string Array[] = {"shared"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "NormalizeSharedCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** NormalizeSharedCommand::NormalizeSharedCommand(string option) { @@ -36,6 +83,10 @@ NormalizeSharedCommand::NormalizeSharedCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["shared"] = tempOutNames; + //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; @@ -150,7 +201,7 @@ int NormalizeSharedCommand::execute(){ //as long as you are not at the end of the file or done wih the lines you want while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } globaldata->Groups.clear(); delete read; out.close(); remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } globaldata->Groups.clear(); delete read; out.close(); remove(outputFileName.c_str()); return 0; } if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ @@ -181,13 +232,13 @@ int NormalizeSharedCommand::execute(){ //prevent memory leak for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } - if (m->control_pressed) { globaldata->Groups.clear(); delete read; out.close(); remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); globaldata->Groups.clear(); delete read; out.close(); remove(outputFileName.c_str()); return 0; } //get next line to process lookup = input->getSharedRAbundVectors(); } - if (m->control_pressed) { globaldata->Groups.clear(); delete read; out.close(); remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); globaldata->Groups.clear(); delete read; out.close(); remove(outputFileName.c_str()); return 0; } //output error messages about any remaining user labels set::iterator it; @@ -220,11 +271,11 @@ int NormalizeSharedCommand::execute(){ delete read; out.close(); - if (m->control_pressed) { remove(outputFileName.c_str()); return 0;} + if (m->control_pressed) { outputTypes.clear(); remove(outputFileName.c_str()); return 0;} m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); - m->mothurOut(outputFileName); m->mothurOutEndLine(); + m->mothurOut(outputFileName); m->mothurOutEndLine(); outputNames.push_back(outputFileName); outputTypes["shared"].push_back(outputFileName); m->mothurOutEndLine(); return 0; diff --git a/normalizesharedcommand.h b/normalizesharedcommand.h index fcfc727..22158bd 100644 --- a/normalizesharedcommand.h +++ b/normalizesharedcommand.h @@ -21,7 +21,12 @@ class NormalizeSharedCommand : public Command { public: NormalizeSharedCommand(string); + NormalizeSharedCommand(); ~NormalizeSharedCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -35,7 +40,8 @@ private: set labels; //holds labels to be used string groups, label, outputDir, method; int norm; - vector Groups; + vector Groups, outputNames; + map > outputTypes; int normalize(vector&, ofstream&); int eliminateZeroOTUS(vector& thislookup); diff --git a/onegapignore.h b/onegapignore.h index 785272e..32818e3 100644 --- a/onegapignore.h +++ b/onegapignore.h @@ -25,6 +25,7 @@ public: int minLength = 0; int start = 0; int end = 0; + bool overlap = false; string seqA = A.getAligned(); string seqB = B.getAligned(); @@ -35,6 +36,7 @@ public: if(seqA[i] != '.' && seqB[i] != '.' && seqA[i] != '-' && seqB[i] != '-' ){ start = i; // cout << "start: " << start << endl; + overlap = true; break; } } @@ -42,6 +44,7 @@ public: if(seqA[i] != '.' && seqB[i] != '.' && seqA[i] != '-' && seqB[i] != '-' ){ end = i; // cout << "end: " << end << endl; + overlap = true; break; } } @@ -73,7 +76,10 @@ public: openGapB = 0; } } - + + //non-overlapping sequences + if (!overlap) { minLength = 0; } + if(minLength == 0) { dist = 1.0000; } else { dist = (double)difference / minLength; } } diff --git a/otuhierarchycommand.cpp b/otuhierarchycommand.cpp index 2c71cd5..022ff3a 100644 --- a/otuhierarchycommand.cpp +++ b/otuhierarchycommand.cpp @@ -9,6 +9,53 @@ #include "otuhierarchycommand.h" +//********************************************************************************************************************** +vector OtuHierarchyCommand::getValidParameters(){ + try { + string Array[] = {"list","label","output","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "OtuHierarchyCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +OtuHierarchyCommand::OtuHierarchyCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["otuheirarchy"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "OtuHierarchyCommand", "OtuHierarchyCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector OtuHierarchyCommand::getRequiredParameters(){ + try { + string Array[] = {"list","label"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "OtuHierarchyCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector OtuHierarchyCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "OtuHierarchyCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** OtuHierarchyCommand::OtuHierarchyCommand(string option) { try { @@ -33,6 +80,10 @@ OtuHierarchyCommand::OtuHierarchyCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["otuheirarchy"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -110,7 +161,7 @@ int OtuHierarchyCommand::execute(){ //get listvectors that correspond to labels requested, (or use smart distancing to get closest listvector) vector lists = getListVectors(); - if (m->control_pressed) { return 0; } + if (m->control_pressed) { outputTypes.clear(); return 0; } //determine which is little and which is big, putting little first if (lists.size() == 2) { @@ -148,7 +199,7 @@ int OtuHierarchyCommand::execute(){ //go through each bin in "big" otu and output the bins in "little" otu which created it for (int i = 0; i < lists[1].getNumBins(); i++) { - if (m->control_pressed) { out.close(); remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); out.close(); remove(outputFileName.c_str()); return 0; } string names = lists[1].get(i); @@ -181,11 +232,11 @@ int OtuHierarchyCommand::execute(){ out.close(); - if (m->control_pressed) { remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); remove(outputFileName.c_str()); return 0; } m->mothurOutEndLine(); m->mothurOut("Output File Name: "); m->mothurOutEndLine(); - m->mothurOut(outputFileName); m->mothurOutEndLine(); + m->mothurOut(outputFileName); m->mothurOutEndLine(); outputNames.push_back(outputFileName); outputTypes["otuheirarchy"].push_back(outputFileName); m->mothurOutEndLine(); return 0; diff --git a/otuhierarchycommand.h b/otuhierarchycommand.h index 1cd427f..dd5f3a7 100644 --- a/otuhierarchycommand.h +++ b/otuhierarchycommand.h @@ -18,7 +18,12 @@ class OtuHierarchyCommand : public Command { public: OtuHierarchyCommand(string); + OtuHierarchyCommand(); ~OtuHierarchyCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -26,6 +31,8 @@ private: bool abort; set labels; //holds labels to be used string label, listFile, outputDir, output; + vector outputNames; + map > outputTypes; vector getListVectors(); diff --git a/parsefastaqcommand.cpp b/parsefastaqcommand.cpp index e808b9b..31de119 100644 --- a/parsefastaqcommand.cpp +++ b/parsefastaqcommand.cpp @@ -10,6 +10,54 @@ #include "parsefastaqcommand.h" #include "sequence.hpp" +//********************************************************************************************************************** +vector ParseFastaQCommand::getValidParameters(){ + try { + string Array[] = {"fastq", "outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ParseFastaQCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +ParseFastaQCommand::ParseFastaQCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["qual"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "ParseFastaQCommand", "ParseFastaQCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector ParseFastaQCommand::getRequiredParameters(){ + try { + string Array[] = {"fastq"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ParseFastaQCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ParseFastaQCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ParseFastaQCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** ParseFastaQCommand::ParseFastaQCommand(string option){ try { @@ -33,6 +81,11 @@ ParseFastaQCommand::ParseFastaQCommand(string option){ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["qual"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -92,8 +145,8 @@ int ParseFastaQCommand::execute(){ string fastaFile = outputDir + m->getRootName(m->getSimpleName(fastaQFile)) + "fasta"; string qualFile = outputDir + m->getRootName(m->getSimpleName(fastaQFile)) + "qual"; ofstream outFasta, outQual; - m->openOutputFile(fastaFile, outFasta); outputNames.push_back(fastaFile); - m->openOutputFile(qualFile, outQual); outputNames.push_back(qualFile); + m->openOutputFile(fastaFile, outFasta); outputNames.push_back(fastaFile); outputTypes["fasta"].push_back(fastaFile); + m->openOutputFile(qualFile, outQual); outputNames.push_back(qualFile); outputTypes["qual"].push_back(qualFile); ifstream in; m->openInputFile(fastaQFile, in); @@ -139,7 +192,7 @@ int ParseFastaQCommand::execute(){ outFasta.close(); outQual.close(); - if (m->control_pressed) { remove(fastaFile.c_str()); remove(qualFile.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); remove(fastaFile.c_str()); remove(qualFile.c_str()); return 0; } m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); diff --git a/parsefastaqcommand.h b/parsefastaqcommand.h index 0710775..c45405f 100644 --- a/parsefastaqcommand.h +++ b/parsefastaqcommand.h @@ -17,13 +17,19 @@ class ParseFastaQCommand : public Command { public: ParseFastaQCommand(string); + ParseFastaQCommand(); ~ParseFastaQCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); private: vector outputNames; + map > outputTypes; string outputDir, fastaQFile; bool abort; diff --git a/parselistscommand.cpp b/parselistscommand.cpp index 4b24236..84d9104 100644 --- a/parselistscommand.cpp +++ b/parselistscommand.cpp @@ -9,6 +9,54 @@ #include "parselistscommand.h" +//********************************************************************************************************************** +vector ParseListCommand::getValidParameters(){ + try { + string Array[] = {"list","group", "label", "outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ParseListCommand", "getValidParameters"); + exit(1); + } +} + +//********************************************************************************************************************** +ParseListCommand::ParseListCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["list"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "ParseListCommand", "ParseListCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector ParseListCommand::getRequiredParameters(){ + try { + string Array[] = {"list","group"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ParseListCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ParseListCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ParseListCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** ParseListCommand::ParseListCommand(string option) { try { @@ -33,7 +81,11 @@ ParseListCommand::ParseListCommand(string option) { for (it = parameters.begin(); it != parameters.end(); it++) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } - + + //initialize outputTypes + vector tempOutNames; + outputTypes["list"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -121,7 +173,6 @@ int ParseListCommand::execute(){ //set fileroot string fileroot = outputDir + m->getRootName(m->getSimpleName(listfile)); - vector outputNames; //fill filehandles with neccessary ofstreams int i; @@ -131,7 +182,7 @@ int ParseListCommand::execute(){ filehandles[groupMap->namesOfGroups[i]] = temp; string filename = fileroot + groupMap->namesOfGroups[i] + ".list"; - outputNames.push_back(filename); + outputNames.push_back(filename); outputTypes["list"].push_back(filename); m->openOutputFile(filename, *temp); } @@ -146,7 +197,7 @@ int ParseListCommand::execute(){ if (m->control_pressed) { delete input; delete list; delete groupMap; for (i=0; inamesOfGroups.size(); i++) { (*(filehandles[groupMap->namesOfGroups[i]])).close(); delete filehandles[groupMap->namesOfGroups[i]]; } - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); return 0; } @@ -155,7 +206,7 @@ int ParseListCommand::execute(){ if (m->control_pressed) { delete input; delete list; delete groupMap; for (i=0; inamesOfGroups.size(); i++) { (*(filehandles[groupMap->namesOfGroups[i]])).close(); delete filehandles[groupMap->namesOfGroups[i]]; } - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); return 0; } @@ -194,7 +245,7 @@ int ParseListCommand::execute(){ if (m->control_pressed) { delete input; delete groupMap; for (i=0; inamesOfGroups.size(); i++) { (*(filehandles[groupMap->namesOfGroups[i]])).close(); delete filehandles[groupMap->namesOfGroups[i]]; } - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); return 0; } @@ -215,7 +266,7 @@ int ParseListCommand::execute(){ if (m->control_pressed) { delete input; delete groupMap; for (i=0; inamesOfGroups.size(); i++) { (*(filehandles[groupMap->namesOfGroups[i]])).close(); delete filehandles[groupMap->namesOfGroups[i]]; } - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); return 0; } @@ -240,7 +291,7 @@ int ParseListCommand::execute(){ delete input; if (m->control_pressed) { - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); return 0; } diff --git a/parselistscommand.h b/parselistscommand.h index c765bcd..5ecc7ab 100644 --- a/parselistscommand.h +++ b/parselistscommand.h @@ -19,8 +19,13 @@ class ParseListCommand : public Command { public: - ParseListCommand(string); + ParseListCommand(string); + ParseListCommand(); ~ParseListCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -35,6 +40,8 @@ private: string outputDir, listfile, groupfile, label; set labels; bool abort, allLines; + vector outputNames; + map > outputTypes; map filehandles; map::iterator it3; diff --git a/parsesffcommand.cpp b/parsesffcommand.cpp index 03d8e96..c636ec9 100644 --- a/parsesffcommand.cpp +++ b/parsesffcommand.cpp @@ -10,6 +10,53 @@ #include "parsesffcommand.h" #include "sequence.hpp" +//********************************************************************************************************************** +vector ParseSFFCommand::getValidParameters(){ + try { + string Array[] = {"sff", "oligos", "minlength", "outputdir", "inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ParseSFFCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +ParseSFFCommand::ParseSFFCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["flow"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "ParseSFFCommand", "ParseSFFCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector ParseSFFCommand::getRequiredParameters(){ + try { + string Array[] = {"sff"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ParseSFFCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ParseSFFCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ParseSFFCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** ParseSFFCommand::ParseSFFCommand(string option){ @@ -36,6 +83,10 @@ ParseSFFCommand::ParseSFFCommand(string option){ if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["flow"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -115,7 +166,7 @@ int ParseSFFCommand::execute(){ } else{ flowFileNames.push_back(new ofstream((outputDir + m->getRootName(m->getSimpleName(sffFile)) + "flow").c_str(), ios::ate)); - outputNames.push_back((outputDir + m->getRootName(m->getSimpleName(sffFile)) + "flow")); + outputNames.push_back((outputDir + m->getRootName(m->getSimpleName(sffFile)) + "flow")); outputTypes["flow"].push_back((outputDir + m->getRootName(m->getSimpleName(sffFile)) + "flow")); } for(int i=0;icontrol_pressed) { for(int i=0;iclose(); } return 0; } + if (m->control_pressed) { outputTypes.clear(); for(int i=0;iclose(); } return 0; } // ofstream fastaFile; // m->openOutputFile(m->getRootName(sffFile) + "fasta", fastaFile); @@ -151,7 +202,7 @@ int ParseSFFCommand::execute(){ for(int i=0;icontrol_pressed) { for(int i=0;iclose(); } return 0; } + if (m->control_pressed) { outputTypes.clear(); for(int i=0;iclose(); } return 0; } inSFF >> seqName; seqName = seqName.substr(1); @@ -282,6 +333,7 @@ void ParseSFFCommand::getOligos(vector& outSFFFlowVec){ outSFFFlowVec.push_back(new ofstream((outputDir + m->getRootName(m->getSimpleName(sffFile)) + group + ".flow").c_str(), ios::ate)); outputNames.push_back((outputDir + m->getRootName(m->getSimpleName(sffFile)) + group + "flow")); + outputTypes["flow"].push_back((outputDir + m->getRootName(m->getSimpleName(sffFile)) + group + "flow")); } } m->gobble(inOligos); diff --git a/parsesffcommand.h b/parsesffcommand.h index 5714e0d..9dfa083 100644 --- a/parsesffcommand.h +++ b/parsesffcommand.h @@ -16,7 +16,12 @@ class ParseSFFCommand : public Command { public: ParseSFFCommand(string); + ParseSFFCommand(); ~ParseSFFCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -42,6 +47,7 @@ private: map barcodes; vector groupVector; vector outputNames; + map > outputTypes; // string stripSeqQual(string, int, int); // string stripQualQual(string, int, int); diff --git a/parsimonycommand.cpp b/parsimonycommand.cpp index 3295de2..b879395 100644 --- a/parsimonycommand.cpp +++ b/parsimonycommand.cpp @@ -9,6 +9,53 @@ #include "parsimonycommand.h" +//********************************************************************************************************************** +vector ParsimonyCommand::getValidParameters(){ + try { + string Array[] = {"random","groups","iters","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ParsimonyCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +ParsimonyCommand::ParsimonyCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["parsimony"] = tempOutNames; + outputTypes["psummary"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "ParsimonyCommand", "ParsimonyCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector ParsimonyCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ParsimonyCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ParsimonyCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ParsimonyCommand", "getRequiredFiles"); + exit(1); + } +} /***********************************************************/ ParsimonyCommand::ParsimonyCommand(string option) { try { @@ -34,6 +81,11 @@ ParsimonyCommand::ParsimonyCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["parsimony"] = tempOutNames; + outputTypes["psummary"] = tempOutNames; + 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 @@ -67,10 +119,12 @@ ParsimonyCommand::ParsimonyCommand(string option) { if(outputDir == "") { outputDir += m->hasPath(globaldata->getTreeFile()); } output = new ColumnFile(outputDir + m->getSimpleName(globaldata->getTreeFile()) + ".parsimony", itersString); outputNames.push_back(outputDir + m->getSimpleName(globaldata->getTreeFile()) + ".parsimony"); + outputTypes["parsimony"].push_back(outputDir + m->getSimpleName(globaldata->getTreeFile()) + ".parsimony"); sumFile = outputDir + m->getSimpleName(globaldata->getTreeFile()) + ".psummary"; m->openOutputFile(sumFile, outSum); outputNames.push_back(sumFile); + outputTypes["psummary"].push_back(sumFile); }else { //user wants random distribution savetmap = globaldata->gTreemap; getUserInput(); @@ -78,6 +132,7 @@ ParsimonyCommand::ParsimonyCommand(string option) { if(outputDir == "") { outputDir += m->hasPath(randomtree); } output = new ColumnFile(outputDir+ m->getSimpleName(randomtree), itersString); outputNames.push_back(outputDir+ m->getSimpleName(randomtree)); + outputTypes["parsimony"].push_back(outputDir+ m->getSimpleName(randomtree)); } //set users groups to analyze @@ -134,7 +189,7 @@ int ParsimonyCommand::execute() { if (m->control_pressed) { delete reading; delete pars; delete util; delete output; if (randomtree == "") { outSum.close(); } - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); globaldata->Groups.clear(); return 0; } @@ -158,7 +213,7 @@ int ParsimonyCommand::execute() { if (m->control_pressed) { delete reading; delete pars; delete util; delete output; if (randomtree == "") { outSum.close(); } - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); globaldata->Groups.clear(); return 0; } @@ -196,7 +251,7 @@ int ParsimonyCommand::execute() { if (m->control_pressed) { delete reading; delete pars; delete util; delete output; delete randT; if (randomtree == "") { outSum.close(); } - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); globaldata->Groups.clear(); return 0; } @@ -233,7 +288,7 @@ int ParsimonyCommand::execute() { if (m->control_pressed) { delete reading; delete pars; delete util; delete output; delete randT; globaldata->gTreemap = savetmap; - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); globaldata->Groups.clear(); return 0; } @@ -245,7 +300,7 @@ int ParsimonyCommand::execute() { if (m->control_pressed) { delete reading; delete pars; delete util; delete output; delete randT; globaldata->gTreemap = savetmap; - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); globaldata->Groups.clear(); return 0; } @@ -302,7 +357,7 @@ int ParsimonyCommand::execute() { delete reading; delete pars; delete util; delete output; if (randomtree == "") { outSum.close(); } else { globaldata->gTreemap = savetmap; } - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); globaldata->Groups.clear(); return 0; } @@ -327,7 +382,7 @@ int ParsimonyCommand::execute() { if (m->control_pressed) { delete pars; delete util; delete output; - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); return 0; } diff --git a/parsimonycommand.h b/parsimonycommand.h index 6fa1914..04acd30 100644 --- a/parsimonycommand.h +++ b/parsimonycommand.h @@ -23,7 +23,12 @@ class ParsimonyCommand : public Command { public: ParsimonyCommand(string); + ParsimonyCommand(); ~ParsimonyCommand() { if (abort == false) { delete pars; delete util; delete output; } } + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -57,6 +62,7 @@ private: bool abort; string groups, itersString; vector Groups, outputNames; //holds groups to be used + map > outputTypes; void printParsimonyFile(); int printUSummaryFile(); diff --git a/pcacommand.cpp b/pcacommand.cpp index 51e3c31..4a4e55e 100644 --- a/pcacommand.cpp +++ b/pcacommand.cpp @@ -10,6 +10,54 @@ #include "pcacommand.h" +//********************************************************************************************************************** +vector PCACommand::getValidParameters(){ + try { + string Array[] = {"phylip", "outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "PCACommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +PCACommand::PCACommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["pcoa"] = tempOutNames; + outputTypes["loadings"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "PCACommand", "PCACommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector PCACommand::getRequiredParameters(){ + try { + string Array[] = {"phylip"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "PCACommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector PCACommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "PCACommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** PCACommand::PCACommand(string option) { @@ -47,7 +95,12 @@ PCACommand::PCACommand(string option) { if (path == "") { parameters["phylip"] = inputDir + it->second; } } } - + + //initialize outputTypes + vector tempOutNames; + outputTypes["pcoa"] = tempOutNames; + outputTypes["loadings"] = tempOutNames; + //required parameters phylipfile = validParameter.validFile(parameters, "phylip", true); if (phylipfile == "not open") { abort = true; } @@ -516,11 +569,13 @@ void PCACommand::output(string fnameRoot, vector name_list, vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -28,6 +33,7 @@ private: string phylipfile, columnfile, namefile, format, filename, fbase, outputDir; float cutoff, precision; vector outputNames; + map > outputTypes; void get_comment(istream&, char, char); int read_phylip(istream&, int, vector&, vector >&); diff --git a/phylodiversitycommand.cpp b/phylodiversitycommand.cpp index 6e9e7b1..6198f13 100644 --- a/phylodiversitycommand.cpp +++ b/phylodiversitycommand.cpp @@ -9,6 +9,55 @@ #include "phylodiversitycommand.h" +//********************************************************************************************************************** +vector PhyloDiversityCommand::getValidParameters(){ + try { + string Array[] = {"freq","rarefy","iters","groups","processors","summary","collect","scale","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "PhyloDiversityCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +PhyloDiversityCommand::PhyloDiversityCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["phylodiv"] = tempOutNames; + outputTypes["rarefy"] = tempOutNames; + outputTypes["summary"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "PhyloDiversityCommand", "PhyloDiversityCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector PhyloDiversityCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "PhyloDiversityCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector PhyloDiversityCommand::getRequiredFiles(){ + try { + string Array[] = {"tree","group"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "PhyloDiversityCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** PhyloDiversityCommand::PhyloDiversityCommand(string option) { try { @@ -33,6 +82,12 @@ PhyloDiversityCommand::PhyloDiversityCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["phylodiv"] = tempOutNames; + outputTypes["rarefy"] = tempOutNames; + outputTypes["summary"] = tempOutNames; + //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = m->hasPath(globaldata->getTreeFile()); } @@ -132,9 +187,9 @@ int PhyloDiversityCommand::execute(){ string outRareFile = outputDir + m->getRootName(m->getSimpleName(globaldata->getTreeFile())) + toString(i+1) + ".phylodiv.rarefaction"; string outCollectFile = outputDir + m->getRootName(m->getSimpleName(globaldata->getTreeFile())) + toString(i+1) + ".phylodiv"; - if (summary) { m->openOutputFile(outSumFile, outSum); outputNames.push_back(outSumFile); } - if (rarefy) { m->openOutputFile(outRareFile, outRare); outputNames.push_back(outRareFile); } - if (collect) { m->openOutputFile(outCollectFile, outCollect); outputNames.push_back(outCollectFile); } + if (summary) { m->openOutputFile(outSumFile, outSum); outputNames.push_back(outSumFile); outputTypes["summary"].push_back(outSumFile); } + if (rarefy) { m->openOutputFile(outRareFile, outRare); outputNames.push_back(outRareFile); outputTypes["rarefy"].push_back(outRareFile); } + if (collect) { m->openOutputFile(outCollectFile, outCollect); outputNames.push_back(outCollectFile); outputTypes["phylodiv"].push_back(outCollectFile); } int numLeafNodes = trees[i]->getNumLeaves(); diff --git a/phylodiversitycommand.h b/phylodiversitycommand.h index 7d4b2d8..f6c3bbe 100644 --- a/phylodiversitycommand.h +++ b/phylodiversitycommand.h @@ -18,7 +18,12 @@ class PhyloDiversityCommand : public Command { public: PhyloDiversityCommand(string); + PhyloDiversityCommand(); ~PhyloDiversityCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -30,6 +35,7 @@ class PhyloDiversityCommand : public Command { bool abort, rarefy, summary, collect, scale; string groups, outputDir; vector Groups, outputNames; //holds groups to be used, and outputFile names + map > outputTypes; void printData(set&, map< string, vector >&, ofstream&, int); void printSumData(map< string, vector >&, ofstream&, int); diff --git a/phylotypecommand.cpp b/phylotypecommand.cpp index c4f367a..c4751b5 100644 --- a/phylotypecommand.cpp +++ b/phylotypecommand.cpp @@ -13,6 +13,55 @@ #include "rabundvector.hpp" #include "sabundvector.hpp" +//********************************************************************************************************************** +vector PhylotypeCommand::getValidParameters(){ + try { + string Array[] = {"taxonomy","cutoff","label","name","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "PhylotypeCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +PhylotypeCommand::PhylotypeCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["list"] = tempOutNames; + outputTypes["sabund"] = tempOutNames; + outputTypes["rabund"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "PhylotypeCommand", "PhylotypeCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector PhylotypeCommand::getRequiredParameters(){ + try { + string Array[] = {"taxonomy"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "PhylotypeCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector PhylotypeCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "PhylotypeCommand", "getRequiredFiles"); + exit(1); + } +} /**********************************************************************************************************************/ PhylotypeCommand::PhylotypeCommand(string option) { try { @@ -38,6 +87,12 @@ PhylotypeCommand::PhylotypeCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["list"] = tempOutNames; + outputTypes["sabund"] = tempOutNames; + outputTypes["rabund"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -127,8 +182,6 @@ int PhylotypeCommand::execute(){ if (abort == true) { return 0; } - vector outputNames; - //reads in taxonomy file and makes all the taxonomies the same length //by appending the last taxon to a given taxonomy as many times as needed to //make it as long as the longest taxonomy in the file @@ -164,9 +217,9 @@ int PhylotypeCommand::execute(){ string outputRabundFile = fileroot + "tx.rabund"; m->openOutputFile(outputRabundFile, outRabund); - outputNames.push_back(outputListFile); - outputNames.push_back(outputSabundFile); - outputNames.push_back(outputRabundFile); + outputNames.push_back(outputListFile); outputTypes["list"].push_back(outputListFile); + outputNames.push_back(outputSabundFile); outputTypes["sabund"].push_back(outputSabundFile); + outputNames.push_back(outputRabundFile); outputTypes["rabund"].push_back(outputRabundFile); int count = 1; //start at leaves of tree and work towards root, processing the labels the user wants diff --git a/phylotypecommand.h b/phylotypecommand.h index c5aea71..e45e21b 100644 --- a/phylotypecommand.h +++ b/phylotypecommand.h @@ -20,7 +20,12 @@ class PhylotypeCommand : public Command { public: PhylotypeCommand(string); + PhylotypeCommand(); ~PhylotypeCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -30,6 +35,8 @@ private: set labels; //holds labels to be used int cutoff; map namemap; + vector outputNames; + map > outputTypes; map currentNodes; map parentNodes; diff --git a/pipelinepdscommand.cpp b/pipelinepdscommand.cpp new file mode 100644 index 0000000..46081df --- /dev/null +++ b/pipelinepdscommand.cpp @@ -0,0 +1,787 @@ +/* + * pipelinepdscommand.cpp + * Mothur + * + * Created by westcott on 10/5/10. + * Copyright 2010 Schloss Lab. All rights reserved. + * + */ + +#include "pipelinepdscommand.h" +#include "sffinfocommand.h" +#include "commandoptionparser.hpp" + +//********************************************************************************************************************** +vector PipelineCommand::getValidParameters(){ + try { + string Array[] = {"sff","oligos","align","chimera","classify","taxonomy","pipeline","processors","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "PipelineCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector PipelineCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "PipelineCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector PipelineCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "PipelineCommand", "getRequiredFiles"); + exit(1); + } +} +//********************************************************************************************************************** +PipelineCommand::PipelineCommand(string option) { + try { + cFactory = CommandFactory::getInstance(); + abort = false; + + //allow user to run help + if(option == "help") { help(); abort = true; } + + else { + + //valid paramters for this command + string AlignArray[] = {"sff","oligos","align","chimera","classify","taxonomy","pipeline","processors","outputdir","inputdir"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + + OptionParser parser(option); + map parameters = parser.getParameters(); + + ValidParameters validParameter; + map::iterator it; + + //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; } + } + + //if the user changes the input directory command factory will send this info to us in the output parameter + string inputDir = validParameter.validFile(parameters, "inputdir", false); + if (inputDir == "not found"){ inputDir = ""; } + else { + string path; + it = parameters.find("sff"); + //user has given a template file + if(it != parameters.end()){ + path = m->hasPath(it->second); + //if the user has not given a path then, add inputdir. else leave path alone. + if (path == "") { parameters["sff"] = inputDir + it->second; } + } + + it = parameters.find("oligos"); + //user has given a template file + if(it != parameters.end()){ + path = m->hasPath(it->second); + //if the user has not given a path then, add inputdir. else leave path alone. + if (path == "") { parameters["oligos"] = inputDir + it->second; } + } + + it = parameters.find("align"); + //user has given a template file + if(it != parameters.end()){ + path = m->hasPath(it->second); + //if the user has not given a path then, add inputdir. else leave path alone. + if (path == "") { parameters["align"] = inputDir + it->second; } + } + + it = parameters.find("chimera"); + //user has given a template file + if(it != parameters.end()){ + path = m->hasPath(it->second); + //if the user has not given a path then, add inputdir. else leave path alone. + if (path == "") { parameters["chimera"] = inputDir + it->second; } + } + + it = parameters.find("classify"); + //user has given a template file + if(it != parameters.end()){ + path = m->hasPath(it->second); + //if the user has not given a path then, add inputdir. else leave path alone. + if (path == "") { parameters["classify"] = inputDir + it->second; } + } + + it = parameters.find("taxonomy"); + //user has given a template file + if(it != parameters.end()){ + path = m->hasPath(it->second); + //if the user has not given a path then, add inputdir. else leave path alone. + if (path == "") { parameters["taxonomy"] = inputDir + it->second; } + } + + it = parameters.find("pipeline"); + //user has given a template file + if(it != parameters.end()){ + path = m->hasPath(it->second); + //if the user has not given a path then, add inputdir. else leave path alone. + if (path == "") { parameters["pipeline"] = inputDir + it->second; } + } + } + + outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; } + + pipeFilename = validParameter.validFile(parameters, "pipeline", true); + if (pipeFilename == "not found") { pipeFilename = ""; } + else if (pipeFilename == "not open") { pipeFilename = ""; abort = true; } + + string temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = "1"; } + convert(temp, processors); + + if (pipeFilename != "") { + abort = readUsersPipeline(); + }else{ + sffFile = validParameter.validFile(parameters, "sff", true); + if (sffFile == "not found") { m->mothurOut("sff is a required parameter for the pipeline command."); m->mothurOutEndLine(); abort = true; } + else if (sffFile == "not open") { sffFile = ""; abort = true; } + + oligosFile = validParameter.validFile(parameters, "oligos", true); + if (oligosFile == "not found") { m->mothurOut("oligos is a required parameter for the pipeline command."); m->mothurOutEndLine(); abort = true; } + else if (oligosFile == "not open") { oligosFile = ""; abort = true; } + + alignFile = validParameter.validFile(parameters, "align", true); + if (alignFile == "not found") { m->mothurOut("align is a required parameter for the pipeline command. Please provide the template to align with."); m->mothurOutEndLine(); abort = true; } + else if (alignFile == "not open") { alignFile = ""; abort = true; } + + chimeraFile = validParameter.validFile(parameters, "chimera", true); + if (chimeraFile == "not found") { m->mothurOut("chimera is a required parameter for the pipeline command. Please provide the template to check for chimeras with."); m->mothurOutEndLine(); abort = true; } + else if (chimeraFile == "not open") { chimeraFile = ""; abort = true; } + + classifyFile = validParameter.validFile(parameters, "classify", true); + if (classifyFile == "not found") { m->mothurOut("classify is a required parameter for the pipeline command. Please provide the template to use with the classifier."); m->mothurOutEndLine(); abort = true; } + else if (classifyFile == "not open") { classifyFile = ""; abort = true; } + + taxonomyFile = validParameter.validFile(parameters, "taxonomy", true); + if (taxonomyFile == "not found") { m->mothurOut("taxonomy is a required parameter for the pipeline command."); m->mothurOutEndLine(); abort = true; } + else if (taxonomyFile == "not open") { taxonomyFile = ""; abort = true; } + } + } + + } + catch(exception& e) { + m->errorOut(e, "PipelineCommand", "PipelineCommand"); + exit(1); + } +} +//********************************************************************************************************************** + +void PipelineCommand::help(){ + try { + m->mothurOut("The pipeline command is designed to guide you through your analysis using mothur.\n"); + m->mothurOut("The pipeline command parameters are pipeline, sff, oligos, align, chimera, classify, taxonomy and processors.\n"); + m->mothurOut("The sff parameter allows you to enter your sff file. It is required.\n"); + m->mothurOut("The oligos parameter allows you to enter your oligos file. It is required.\n"); + m->mothurOut("The align parameter allows you to enter a template to use with the aligner. It is required.\n"); + m->mothurOut("The chimera parameter allows you to enter a template to use for chimera detection. It is required.\n"); + m->mothurOut("The classify parameter allows you to enter a template to use for classification. It is required.\n"); + m->mothurOut("The taxonomy parameter allows you to enter a taxonomy file for the classify template to use for classification. It is required.\n"); + m->mothurOut("The processors parameter allows you to specify the number of processors to use. The default is 1.\n"); + m->mothurOut("The pipeline parameter allows you to enter your own pipeline file. This file should look like a mothur batchfile, but where you would be using a mothur generated file, you can use mothurmade instead.\n"); + m->mothurOut("First column contains the command name, and the second column contains the parameter options or 'defaults', meaning use defaults. You may leave out file options.\n"); + m->mothurOut("Example: trim.seqs(processors=8, allfiles=T, maxambig=0, maxhomop=8, flip=T, bdiffs=1, pdiffs=2, qwindowaverage=35, qwindowsize=50, fasta=may1.v13.fasta, oligos=may1.v13.oligos, qfile=may1.v13.qual)\n"); + m->mothurOut("then, you could enter unique.seqs(fasta=mothurmade), and mothur would use the .trim.fasta file from the trim.seqs command. \n"); + m->mothurOut("then you could enter align.seqs(candidate=mothurmade, template=silva.v13.align, processors=8). , and mothur would use the .trim.unique.fasta file from the unique.seqs command. \n"); + m->mothurOut("If no pipeline file is given then mothur will use Pat's pipeline. \n\n"); + m->mothurOut("Here is a list of the commands used in Pat's pipeline.\n"); + m->mothurOut("All paralellized commands will use the processors you entered.\n"); + m->mothurOut("The sffinfo command takes your sff file and extracts the fasta and quality files.\n"); + m->mothurOut("The trim.seqs command uses your oligos file and the quality and fasta files generated by sffinfo.\n"); + m->mothurOut("The trim.seqs command sets the following parameters: allfiles=T, maxambig=0, maxhomop=8, flip=T, bdiffs=1, pdiffs=2, qwindowaverage=35, qwindowsize=50.\n"); + m->mothurOut("The unique.seqs command uses the trimmed fasta file and removes redundant sequences, don't worry the names file generated by unique.seqs will be used in the pipeline to make sure they are included.\n"); + m->mothurOut("The align.seqs command aligns the unique sequences using the aligners default options. \n"); + m->mothurOut("The screen.seqs command screens the sequences using optimize=end-minlength. \n"); + m->mothurOut("The pipeline uses chimera.slayer to detect chimeras using the default options. \n"); + m->mothurOut("The pipeline removes all sequences determined to be chimeric by chimera.slayer. \n"); + m->mothurOut("The filter.seqs command filters the sequences using vertical=T, trump=. \n"); + m->mothurOut("The unique.seqs command uses the filtered fasta file and name file to remove sequences that have become redundant after filtering.\n"); + m->mothurOut("The pre.cluster command clusters sequences that have no more than 2 differences.\n"); + m->mothurOut("The dist.seqs command is used to generate a column and phylip formatted distance matrix using cutoff=0.20 for column.\n"); + m->mothurOut("The pipeline uses cluster with method=average, hard=T. \n"); + m->mothurOut("The classify.seqs command is used to classify the sequences using the bayesian method with a cutoff of 80.\n"); + m->mothurOut("The phylotype command is used to cluster the sequences based on their classification.\n"); + m->mothurOut("The clearcut command is used to generate a tree using neighbor=T. \n"); + m->mothurOut("The summary.single and summary.shared commands are run on the otu files from cluster and phylotype commands. \n"); + m->mothurOut("The summary.shared command uses calc=sharednseqs-sharedsobs-sharedchao-sharedace-anderberg-jclass-jest-kulczynski-kulczynskicody-lennon-ochiai-sorclass-sorest-whittaker-braycurtis-jabund-morisitahorn-sorabund-thetan-thetayc. \n"); + m->mothurOut("The summary.single command uses calc=nseqs-sobs-coverage-bergerparker-chao-ace-jack-bootstrap-boneh-efron-shen-solow-shannon-npshannon-invsimpson-qstat-simpsoneven-shannoneven-heip-smithwilson. \n"); + m->mothurOut("The classify.otu command is used to get the concensus taxonomy for otu files from cluster and phylotype commands. \n"); + m->mothurOut("The phylo.diversity command run on the tree generated by clearcut with rarefy=T, iters=100. \n"); + m->mothurOut("The unifrac commands are also run on the tree generated by clearcut with random=F, distance=T. \n"); + m->mothurOut("\n\n"); + } + catch(exception& e) { + m->errorOut(e, "PipelineCommand", "help"); + exit(1); + } +} + +//********************************************************************************************************************** + +PipelineCommand::~PipelineCommand(){} + +//********************************************************************************************************************** + +int PipelineCommand::execute(){ + try { + if (abort == true) { return 0; } + + if (pipeFilename == "") { + createPatsPipeline(); + + //run Pats pipeline + for (int i = 0; i < commands.size(); i++) { + m->mothurOutEndLine(); m->mothurOut("mothur > " + commands[i]); m->mothurOutEndLine(); + + if (m->control_pressed) { return 0; } + + CommandOptionParser parser(commands[i]); + string commandName = parser.getCommandString(); + string options = parser.getOptionString(); + + #ifdef USE_MPI + int pid; + MPI_Comm_rank(MPI_COMM_WORLD, &pid); + + if ((cFactory->MPIEnabled(commandName)) || (pid == 0)) { + #endif + + //executes valid command + Command* command = cFactory->getCommand(commandName, options, "pipe"); + command->execute(); + + //add output files to list + map > thisCommandsFile = command->getOutputFiles(); + map >::iterator itMade; + for (itMade = thisCommandsFile.begin(); itMade != thisCommandsFile.end(); itMade++) { + vector temp = itMade->second; + for (int j = 0; j < temp.size(); j++) { outputNames.push_back(temp[j]); } + } + + #ifdef USE_MPI + } + #endif + } + + }else { runUsersPipeline(); } + + if (m->control_pressed) { return 0; } + + m->mothurOutEndLine(); + m->mothurOut("Output File Names: "); m->mothurOutEndLine(); + for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); } + m->mothurOutEndLine(); + + return 0; + } + catch(exception& e) { + m->errorOut(e, "PipelineCommand", "execute"); + exit(1); + } +} +//********************************************************************************************************************** + +bool PipelineCommand::readUsersPipeline(){ + try { + + ifstream in; + m->openInputFile(pipeFilename, in); + + string nextCommand = ""; + + map > mothurMadeFiles; + + while(!in.eof()) { + nextCommand = m->getline(in); m->gobble(in); + + if (nextCommand[0] != '#') { + bool error = false; + + string commandName, options; + error = parseCommand(nextCommand, commandName, options); + + if (error) { in.close(); return error; } + if (commandName == "pipeline.pds") { m->mothurOut("Cannot run the pipeline.pds command from inside the pipeline.pds command."); m->mothurOutEndLine(); in.close(); return true; } + + error = checkForValidAndRequiredParameters(commandName, options, mothurMadeFiles); + + if (error) { in.close(); return error; } + } + } + + in.close(); + + return false; + } + catch(exception& e) { + m->errorOut(e, "PipelineCommand", "readUsersPipeline"); + exit(1); + } +} +//********************************************************************************************************************** + +bool PipelineCommand::parseCommand(string nextCommand, string& name, string& options){ + try { + CommandOptionParser parser(nextCommand); + name = parser.getCommandString(); + options = parser.getOptionString(); + + if (name == "") { return true; } //name == "" if () are not right + + return false; + } + catch(exception& e) { + m->errorOut(e, "PipelineCommand", "parseCommand"); + exit(1); + } +} +//********************************************************************************************************************** + +bool PipelineCommand::checkForValidAndRequiredParameters(string name, string options, map >& mothurMadeFiles){ + try { + + //get shell of the command so we can check to make sure its valid without running it + Command* command = cFactory->getCommand(name); + + //check to make sure all parameters are valid for command + vector validParameters = command->getValidParameters(); + + OptionParser parser(options); + map parameters = parser.getParameters(); + + ValidParameters validParameter; + map::iterator it; + map >::iterator itMade; + + for (it = parameters.begin(); it != parameters.end(); it++) { + if (validParameter.isValidParameter(it->first, validParameters, it->second) != true) { return true; } // not valid + if (it->second == "mothurmade") { + itMade = mothurMadeFiles.find(it->first); + + if (itMade == mothurMadeFiles.end()) { + m->mothurOut("You have the " + it->first + " listed as a mothurmade file for the " + name + " command, but it seems mothur will not make that file in your current pipeline, please correct."); m->mothurOutEndLine(); + return true; + } + } + } + + //is the command missing any required + vector requiredParameters = command->getRequiredParameters(); + + //check for or + bool hasOr = false; + int numFound = 0; + if (requiredParameters.size() > 2) { + if (requiredParameters[(requiredParameters.size()-1)] == "or") { hasOr = true; } + } + + for (int i = 0; i < requiredParameters.size(); i++) { + it = parameters.find(requiredParameters[i]); + + if (it != parameters.end()) { numFound++; } + else { + if (!hasOr) { m->mothurOut(name + " requires the " + requiredParameters[i] + " parameter, please correct."); m->mothurOutEndLine(); } + } + } + + // if all are needed and not all are found + if ((!hasOr) && (numFound != requiredParameters.size())) { return true; } + //if one is needed and none are found + else if ((hasOr) && (numFound == 0)) { return true; } + + //update MothurMade + map > thisCommandsFile = command->getOutputFiles(); + for (itMade = thisCommandsFile.begin(); itMade != thisCommandsFile.end(); itMade++) { + mothurMadeFiles[itMade->first] = itMade->second; //adds any new types + } + + return false; + } + catch(exception& e) { + m->errorOut(e, "PipelineCommand", "checkForValidAndRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +int PipelineCommand::runUsersPipeline(){ + try { + ifstream in; + m->openInputFile(pipeFilename, in); + + string nextCommand = ""; + + map > mothurMadeFiles; + + while(!in.eof()) { + nextCommand = m->getline(in); m->gobble(in); + + if (nextCommand[0] != '#') { + CommandOptionParser parser(nextCommand); + string commandName = parser.getCommandString(); + string options = parser.getOptionString(); + + if (options != "") { + bool error = fillInMothurMade(options, mothurMadeFiles); + if (error) { in.close(); return 0; } + } + + m->mothurOutEndLine(); m->mothurOut("mothur > " + commandName + "(" + options + ")"); m->mothurOutEndLine(); + + if (m->control_pressed) { return 0; } + + #ifdef USE_MPI + int pid; + MPI_Comm_rank(MPI_COMM_WORLD, &pid); + + if ((cFactory->MPIEnabled(commandName)) || (pid == 0)) { + #endif + + //executes valid command + Command* command = cFactory->getCommand(commandName, options, "pipe"); + command->execute(); + + //add output files to list + map > thisCommandsFile = command->getOutputFiles(); + map >::iterator itMade; + map >::iterator it; + for (itMade = thisCommandsFile.begin(); itMade != thisCommandsFile.end(); itMade++) { + + vector temp = itMade->second; + for (int k = 0; k < temp.size(); k++) { outputNames.push_back(temp[k]); } // + + //update Mothur Made for each file + it = mothurMadeFiles.find(itMade->first); + + if (it == mothurMadeFiles.end()) { //new type + + mothurMadeFiles[itMade->first] = temp; + + }else{ //update existing type + vector oldFileNames = it->second; + //look at new files, see if an old version of the file exists, if so update, else just add. + //for example you may have abrecovery.fasta and amazon.fasta as old files and you created a new amazon.trim.fasta. + + for (int k = 0; k < temp.size(); k++) { + + //get base name + string root = m->getSimpleName(temp[k]); + string individual = ""; + for(int i=0;ifirst][spot] = temp[k]; + }else{ + mothurMadeFiles[it->first].push_back(temp[k]); + } + } + } + } + + #ifdef USE_MPI + } + #endif + } + } + + in.close(); + } + catch(exception& e) { + m->errorOut(e, "PipelineCommand", "runUsersPipeline"); + exit(1); + } +} +//********************************************************************************************************************** +bool PipelineCommand::fillInMothurMade(string& options, map > mothurMadeFiles){ + try { + OptionParser parser(options); + map parameters = parser.getParameters(); + map::iterator it; + map >::iterator itMade; + + options = ""; + + //fill in mothurmade filenames + for (it = parameters.begin(); it != parameters.end(); it++) { + if (it->second == "mothurmade") { + itMade = mothurMadeFiles.find(it->first); + + if (itMade == mothurMadeFiles.end()) { + m->mothurOut("Looking for a mothurmade " + it->first + " file, but it seems mothur has not made that file type in your current pipeline, please correct."); m->mothurOutEndLine(); + return true; + }else{ + vector temp = itMade->second; + + if (temp.size() > 1) { + //ask user which file to use + m->mothurOut("More than one file has been created for the " + it->first + " parameter. "); m->mothurOutEndLine(); + for (int i = 0; i < temp.size(); i++) { + m->mothurOut(toString(i) + " - " + temp[i]); m->mothurOutEndLine(); + } + m->mothurOut("Please select the number of the file you would like to use: "); + int num = 0; + cin >> num; + m->mothurOutJustToLog(toString(num)); m->mothurOutEndLine(); + + if ((num < 0) || (num > (temp.size()-1))) { m->mothurOut("Not a valid response, quitting."); m->mothurOutEndLine(); return true; } + else { + parameters[it->first] = temp[num]; + } + + //clears buffer so next command doesn't have error + string s; + getline(cin, s); + + }else if (temp.size() == 0){ + m->mothurOut("Sorry, we seem to think you created a " + it->first + " file, but it seems mothur doesn't have a filename."); m->mothurOutEndLine(); + return true; + }else{ + parameters[it->first] = temp[0]; + } + } + } + + options += it->first + "=" + parameters[it->first] + ", "; + } + + //rip off extra comma + options = options.substr(0, (options.length()-2)); + + return false; + } + catch(exception& e) { + m->errorOut(e, "PipelineCommand", "fillInMothurMade"); + exit(1); + } +} + +//********************************************************************************************************************** +void PipelineCommand::createPatsPipeline(){ + try { + + //sff.info command + string thisCommand = "sffinfo(sff=" + sffFile + ")"; + commands.push_back(thisCommand); + + //trim.seqs command + string fastaFile = m->getRootName(m->getSimpleName(sffFile)) + "fasta"; + string qualFile = m->getRootName(m->getSimpleName(sffFile)) + "qual"; + thisCommand = "trim.seqs(processors=" + toString(processors) + ", fasta=" + fastaFile + ", allfiles=F, maxambig=0, maxhomop=8, flip=T, bdiffs=1, pdiffs=2, qwindowaverage=35, qwindowsize=50, oligos=" + oligosFile + ", qfile=" + qualFile + ")"; + commands.push_back(thisCommand); + + //unique.seqs + string groupFile = m->getRootName(m->getSimpleName(fastaFile)) + "groups"; + qualFile = m->getRootName(m->getSimpleName(fastaFile)) + "trim.qual"; + fastaFile = m->getRootName(m->getSimpleName(fastaFile)) + "trim.fasta"; + thisCommand = "unique.seqs(fasta=" + fastaFile + ")"; + commands.push_back(thisCommand); + + //align.seqs + string nameFile = m->getRootName(m->getSimpleName(fastaFile)) + "names"; + fastaFile = m->getRootName(m->getSimpleName(fastaFile)) + "unique" + m->getExtension(fastaFile); + thisCommand = "align.seqs(processors=" + toString(processors) + ", candidate=" + fastaFile + ", template=" + alignFile + ")"; + commands.push_back(thisCommand); + + //screen.seqs + fastaFile = m->getRootName(m->getSimpleName(fastaFile)) + "align"; + thisCommand = "screen.seqs(processors=" + toString(processors) + ", fasta=" + fastaFile + ", name=" + nameFile + "group=" + groupFile + ", optimize=end-minlength)"; + commands.push_back(thisCommand); + + //chimera.slayer + fastaFile = m->getRootName(m->getSimpleName(fastaFile)) + "good" + m->getExtension(fastaFile); + nameFile = m->getRootName(m->getSimpleName(nameFile)) + "good" + m->getExtension(nameFile); + groupFile = m->getRootName(m->getSimpleName(groupFile)) + "good" + m->getExtension(groupFile); + thisCommand = "chimera.slayer(processors=" + toString(processors) + ", fasta=" + fastaFile + ", template=" + chimeraFile + ")"; + commands.push_back(thisCommand); + + //remove.seqs + string accnosFile = m->getRootName(m->getSimpleName(fastaFile)) + "slayer.accnos"; + fastaFile = m->getRootName(m->getSimpleName(fastaFile)) + "slayer.chimeras"; + thisCommand = "remove.seqs(fasta=" + fastaFile + ", name=" + nameFile + ", group=" + groupFile + ", accnos=" + accnosFile + ", dups=T)"; + commands.push_back(thisCommand); + + //filter.seqs + nameFile = m->getRootName(m->getSimpleName(nameFile)) + "pick" + m->getExtension(nameFile); + groupFile = m->getRootName(m->getSimpleName(groupFile)) + "pick" + m->getExtension(groupFile); + fastaFile = m->getRootName(m->getSimpleName(fastaFile)) + "pick" + m->getExtension(fastaFile); + thisCommand = "filter.seqs(processors=" + toString(processors) + ", fasta=" + fastaFile + ", vertical=T, trump=.)"; + commands.push_back(thisCommand); + + //unique.seqs + fastaFile = m->getRootName(m->getSimpleName(fastaFile)) + "filter.fasta"; + thisCommand = "unique.seqs(fasta=" + fastaFile + ", name=" + nameFile + ")"; + commands.push_back(thisCommand); + + //pre.cluster + nameFile = m->getRootName(m->getSimpleName(fastaFile)) + "names"; + fastaFile = m->getRootName(m->getSimpleName(fastaFile)) + "unique" + m->getExtension(fastaFile); + thisCommand = "pre.cluster(fasta=" + fastaFile + ", name=" + nameFile + ", diffs=2)"; + commands.push_back(thisCommand); + + //dist.seqs + nameFile = m->getRootName(m->getSimpleName(fastaFile)) + "precluster.names"; + fastaFile = m->getRootName(m->getSimpleName(fastaFile)) + "precluster" + m->getExtension(fastaFile); + thisCommand = "dist.seqs(processors=" + toString(processors) + ", fasta=" + fastaFile + ", cutoff=0.20)"; + commands.push_back(thisCommand); + + //dist.seqs + string columnFile = m->getRootName(m->getSimpleName(fastaFile)) + "dist"; + thisCommand = "dist.seqs(processors=" + toString(processors) + ", fasta=" + fastaFile + ", output=lt)"; + commands.push_back(thisCommand); + + //read.dist + string phylipFile = m->getRootName(m->getSimpleName(fastaFile)) + "phylip.dist"; + thisCommand = "read.dist(column=" + columnFile + ", name=" + nameFile + ")"; + commands.push_back(thisCommand); + + //cluster + thisCommand = "cluster(method=average, hard=T)"; + commands.push_back(thisCommand); + + string listFile = m->getRootName(m->getSimpleName(columnFile)) + "an.list"; + string rabundFile = m->getRootName(m->getSimpleName(columnFile)) + "an.rabund"; + + //degap.seqs + thisCommand = "degap.seqs(fasta=" + fastaFile + ")"; + commands.push_back(thisCommand); + + //classify.seqs + fastaFile = m->getRootName(m->getSimpleName(fastaFile)) + "ng.fasta"; + thisCommand = "classify.seqs(processors=" + toString(processors) + ", fasta=" + fastaFile + ", name=" + nameFile + ", template=" + classifyFile + ", taxonomy=" + taxonomyFile + ", cutoff=80)"; + commands.push_back(thisCommand); + + string RippedTaxName = m->getRootName(m->getSimpleName(taxonomyFile)); + RippedTaxName = m->getExtension(RippedTaxName.substr(0, RippedTaxName.length()-1)); + if (RippedTaxName[0] == '.') { RippedTaxName = RippedTaxName.substr(1, RippedTaxName.length()); } + RippedTaxName += "."; + + string fastaTaxFile = m->getRootName(m->getSimpleName(fastaFile)) + RippedTaxName + "taxonomy"; + string taxSummaryFile = m->getRootName(m->getSimpleName(fastaFile)) + RippedTaxName + "tax.summary"; + + //phylotype + thisCommand = "phylotype(taxonomy=" + fastaTaxFile + ", name=" + nameFile + ")"; + commands.push_back(thisCommand); + + string phyloListFile = m->getRootName(m->getSimpleName(fastaTaxFile)) + "tx.list"; + string phyloRabundFile = m->getRootName(m->getSimpleName(fastaTaxFile)) + "tx.rabund"; + + //clearcut + thisCommand = "clearcut(phylip=" + phylipFile + ", neighbor=T)"; + commands.push_back(thisCommand); + + string treeFile = m->getRootName(m->getSimpleName(phylipFile)) + "tre"; + + //read.otu + thisCommand = "read.otu(list=" + listFile + ", group=" + groupFile + ", label=0.03)"; + commands.push_back(thisCommand); + + string sharedFile = m->getRootName(m->getSimpleName(listFile)) + "shared"; + + //read.otu + thisCommand = "read.otu(list=" + phyloListFile + ", group=" + groupFile + ", label=1)"; + commands.push_back(thisCommand); + + string phyloSharedFile = m->getRootName(m->getSimpleName(phyloListFile)) + "shared"; + + //read.otu + thisCommand = "read.otu(shared=" + sharedFile + ")"; + commands.push_back(thisCommand); + + //summary.single + thisCommand = "summary.single(calc=nseqs-sobs-coverage-bergerparker-chao-ace-jack-bootstrap-boneh-efron-shen-solow-shannon-npshannon-invsimpson-qstat-simpsoneven-shannoneven-heip-smithwilson, size=5000)"; + commands.push_back(thisCommand); + + //summary.shared + thisCommand = "summary.shared(calc=sharednseqs-sharedsobs-sharedchao-sharedace-anderberg-jclass-jest-kulczynski-kulczynskicody-lennon-ochiai-sorclass-sorest-whittaker-braycurtis-jabund-morisitahorn-sorabund-thetan-thetayc)"; + commands.push_back(thisCommand); + + //read.otu + thisCommand = "read.otu(rabund=" + rabundFile + ", label=0.03)"; + commands.push_back(thisCommand); + + //summary.single + thisCommand = "summary.single(calc=nseqs-sobs-coverage-bergerparker-chao-ace-jack-bootstrap-boneh-efron-shen-solow-shannon-npshannon-invsimpson-qstat-simpsoneven-shannoneven-heip-smithwilson, size=5000)"; + commands.push_back(thisCommand); + + //read.otu + thisCommand = "read.otu(shared=" + phyloSharedFile + ")"; + commands.push_back(thisCommand); + + //summary.single + thisCommand = "summary.single(calc=nseqs-sobs-coverage-bergerparker-chao-ace-jack-bootstrap-boneh-efron-shen-solow-shannon-npshannon-invsimpson-qstat-simpsoneven-shannoneven-heip-smithwilson, size=5000)"; + commands.push_back(thisCommand); + + //summary.shared + thisCommand = "summary.shared(calc=sharednseqs-sharedsobs-sharedchao-sharedace-anderberg-jclass-jest-kulczynski-kulczynskicody-lennon-ochiai-sorclass-sorest-whittaker-braycurtis-jabund-morisitahorn-sorabund-thetan-thetayc)"; + commands.push_back(thisCommand); + + //read.otu + thisCommand = "read.otu(rabund=" + phyloRabundFile + ", label=1)"; + commands.push_back(thisCommand); + + //summary.single + thisCommand = "summary.single(calc=nseqs-sobs-coverage-bergerparker-chao-ace-jack-bootstrap-boneh-efron-shen-solow-shannon-npshannon-invsimpson-qstat-simpsoneven-shannoneven-heip-smithwilson, size=5000)"; + commands.push_back(thisCommand); + + //classify.otu + thisCommand = "classify.otu(taxonomy=" + fastaTaxFile + ", name=" + nameFile + ", list=" + listFile + ", cutoff=51, label=0.03)"; + commands.push_back(thisCommand); + + //classify.otu + thisCommand = "classify.otu(taxonomy=" + fastaTaxFile + ", name=" + nameFile + ", list=" + phyloListFile + ", cutoff=51, label=1)"; + commands.push_back(thisCommand); + + //read.tree + thisCommand = "read.tree(tree=" + treeFile + ", name=" + nameFile + ", group=" + groupFile + ")"; + commands.push_back(thisCommand); + + //phylo.diversity + thisCommand = "phylo.diversity(iters=100,rarefy=T)"; + commands.push_back(thisCommand); + + //unifrac.weighted + thisCommand = "unifrac.weighted(random=false, distance=true, groups=all, processors=" + toString(processors) + ")"; + commands.push_back(thisCommand); + + //unifrac.unweighted + thisCommand = "unifrac.unweighted(random=false, distance=true, processors=" + toString(processors) + ")"; + commands.push_back(thisCommand); + + + } + catch(exception& e) { + m->errorOut(e, "PipelineCommand", "createPatsPipeline"); + exit(1); + } +} + +//********************************************************************************************************************** diff --git a/pipelinepdscommand.h b/pipelinepdscommand.h new file mode 100644 index 0000000..8a8a195 --- /dev/null +++ b/pipelinepdscommand.h @@ -0,0 +1,52 @@ +#ifndef PIPELINEPDSCOMMAND_H +#define PIPELINEPDSCOMMAND_H + +/* + * pipelinepdscommand.h + * Mothur + * + * Created by westcott on 10/5/10. + * Copyright 2010 Schloss Lab. All rights reserved. + * + */ + + +#include "command.hpp" +#include "commandfactory.hpp" + +/****************************************************/ + +class PipelineCommand : public Command { + +public: + PipelineCommand(string); + PipelineCommand() {} + ~PipelineCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } //empty + int execute(); + void help(); + +private: + bool abort; + CommandFactory* cFactory; + vector outputNames; + map > outputTypes; + vector commands; + string outputDir, sffFile, alignFile, oligosFile, taxonomyFile, pipeFilename, classifyFile, chimeraFile; + int processors; + + bool readUsersPipeline(); + int runUsersPipeline(); + void createPatsPipeline(); + bool parseCommand(string, string&, string&); + bool checkForValidAndRequiredParameters(string, string, map >&); + bool fillInMothurMade(string&, map >); +}; + +/****************************************************/ + +#endif + diff --git a/preclustercommand.cpp b/preclustercommand.cpp index a7f2113..e6ccc9b 100644 --- a/preclustercommand.cpp +++ b/preclustercommand.cpp @@ -12,6 +12,54 @@ //********************************************************************************************************************** inline bool comparePriority(seqPNode first, seqPNode second) { return (first.numIdentical > second.numIdentical); } //********************************************************************************************************************** +vector PreClusterCommand::getValidParameters(){ + try { + string Array[] = {"fasta", "name", "diffs", "outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "PreClusterCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +PreClusterCommand::PreClusterCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["name"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "PreClusterCommand", "PreClusterCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector PreClusterCommand::getRequiredParameters(){ + try { + string Array[] = {"fasta"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "PreClusterCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector PreClusterCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "PreClusterCommand", "getRequiredFiles"); + exit(1); + } +} +//********************************************************************************************************************** PreClusterCommand::PreClusterCommand(string option) { try { @@ -36,6 +84,11 @@ PreClusterCommand::PreClusterCommand(string option) { if (validParameter.isValidParameter(it2->first, myArray, it2->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["name"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -189,8 +242,8 @@ int PreClusterCommand::execute(){ m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); - m->mothurOut(newFastaFile); m->mothurOutEndLine(); - m->mothurOut(newNamesFile); m->mothurOutEndLine(); + m->mothurOut(newFastaFile); m->mothurOutEndLine(); outputNames.push_back(newFastaFile); outputTypes["fasta"].push_back(newFastaFile); + m->mothurOut(newNamesFile); m->mothurOutEndLine(); outputNames.push_back(newNamesFile); outputTypes["name"].push_back(newNamesFile); m->mothurOutEndLine(); return 0; diff --git a/preclustercommand.h b/preclustercommand.h index de6a572..7bbb5a7 100644 --- a/preclustercommand.h +++ b/preclustercommand.h @@ -31,7 +31,12 @@ class PreClusterCommand : public Command { public: PreClusterCommand(string); + PreClusterCommand(); ~PreClusterCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -44,6 +49,8 @@ private: map sizes; //this map a seq name to the number of identical seqs in the names file map::iterator itSize; // map active; //maps sequence name to whether it has already been merged or not. + vector outputNames; + map > outputTypes; int readFASTA(); void readNameFile(); diff --git a/quitcommand.cpp b/quitcommand.cpp index 8e6fd15..0dd2dec 100644 --- a/quitcommand.cpp +++ b/quitcommand.cpp @@ -9,6 +9,39 @@ #include "quitcommand.h" +//********************************************************************************************************************** +vector QuitCommand::getValidParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "QuitCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector QuitCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "QuitCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector QuitCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "QuitCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** QuitCommand::QuitCommand(string option) { diff --git a/quitcommand.h b/quitcommand.h index 8b89306..f901b17 100644 --- a/quitcommand.h +++ b/quitcommand.h @@ -20,12 +20,19 @@ class QuitCommand : public Command { public: QuitCommand(string); + QuitCommand() {} ~QuitCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); private: bool abort; + vector outputNames; + map > outputTypes; }; #endif diff --git a/rarefactcommand.cpp b/rarefactcommand.cpp index ae28d23..d430ffc 100644 --- a/rarefactcommand.cpp +++ b/rarefactcommand.cpp @@ -25,8 +25,67 @@ #include "coverage.h" //********************************************************************************************************************** - - +vector RareFactCommand::getValidParameters(){ + try { + string Array[] = {"iters","freq","label","calc","abund","processors","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "RareFactCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector RareFactCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "RareFactCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector RareFactCommand::getRequiredFiles(){ + try { + string AlignArray[] = {"shared","list","rabund","sabund","or"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "RareFactCommand", "getRequiredFiles"); + exit(1); + } +} +//********************************************************************************************************************** +RareFactCommand::RareFactCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["rarefaction"] = tempOutNames; + outputTypes["r_chao"] = tempOutNames; + outputTypes["r_ace"] = tempOutNames; + outputTypes["r_jack"] = tempOutNames; + outputTypes["r_shannon"] = tempOutNames; + outputTypes["r_shannoneven"] = tempOutNames; + outputTypes["r_heip"] = tempOutNames; + outputTypes["r_smithwilson"] = tempOutNames; + outputTypes["r_npshannon"] = tempOutNames; + outputTypes["r_simpson"] = tempOutNames; + outputTypes["r_simpsoneven"] = tempOutNames; + outputTypes["r_invsimpson"] = tempOutNames; + outputTypes["r_bootstrap"] = tempOutNames; + outputTypes["r_coverage"] = tempOutNames; + outputTypes["r_nseqs"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "RareFactCommand", "RareFactCommand"); + exit(1); + } +} +//********************************************************************************************************************** RareFactCommand::RareFactCommand(string option) { try { globaldata = GlobalData::getInstance(); @@ -53,6 +112,24 @@ RareFactCommand::RareFactCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["rarefaction"] = tempOutNames; + outputTypes["r_chao"] = tempOutNames; + outputTypes["r_ace"] = tempOutNames; + outputTypes["r_jack"] = tempOutNames; + outputTypes["r_shannon"] = tempOutNames; + outputTypes["r_shannoneven"] = tempOutNames; + outputTypes["r_heip"] = tempOutNames; + outputTypes["r_smithwilson"] = tempOutNames; + outputTypes["r_npshannon"] = tempOutNames; + outputTypes["r_simpson"] = tempOutNames; + outputTypes["r_simpsoneven"] = tempOutNames; + outputTypes["r_invsimpson"] = tempOutNames; + outputTypes["r_bootstrap"] = tempOutNames; + outputTypes["r_coverage"] = tempOutNames; + outputTypes["r_nseqs"] = tempOutNames; + //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; @@ -138,8 +215,6 @@ int RareFactCommand::execute(){ if (abort == true) { return 0; } - vector outputNames; - string hadShared = ""; if ((globaldata->getFormat() != "sharedfile")) { inputFileNames.push_back(globaldata->inputFileName); } else { hadShared = globaldata->getSharedFile(); inputFileNames = parseSharedFile(globaldata->getSharedFile()); globaldata->setFormat("rabund"); } @@ -164,51 +239,51 @@ int RareFactCommand::execute(){ if (validCalculator->isValidCalculator("rarefaction", Estimators[i]) == true) { if (Estimators[i] == "sobs") { rDisplays.push_back(new RareDisplay(new Sobs(), new ThreeColumnFile(fileNameRoot+"rarefaction"))); - outputNames.push_back(fileNameRoot+"rarefaction"); + outputNames.push_back(fileNameRoot+"rarefaction"); outputTypes["rarefaction"].push_back(fileNameRoot+"rarefaction"); }else if (Estimators[i] == "chao") { rDisplays.push_back(new RareDisplay(new Chao1(), new ThreeColumnFile(fileNameRoot+"r_chao"))); - outputNames.push_back(fileNameRoot+"r_chao"); + outputNames.push_back(fileNameRoot+"r_chao"); outputTypes["r_chao"].push_back(fileNameRoot+"r_chao"); }else if (Estimators[i] == "ace") { if(abund < 5) abund = 10; rDisplays.push_back(new RareDisplay(new Ace(abund), new ThreeColumnFile(fileNameRoot+"r_ace"))); - outputNames.push_back(fileNameRoot+"r_ace"); + outputNames.push_back(fileNameRoot+"r_ace"); outputTypes["r_ace"].push_back(fileNameRoot+"r_ace"); }else if (Estimators[i] == "jack") { rDisplays.push_back(new RareDisplay(new Jackknife(), new ThreeColumnFile(fileNameRoot+"r_jack"))); - outputNames.push_back(fileNameRoot+"r_jack"); + outputNames.push_back(fileNameRoot+"r_jack"); outputTypes["r_jack"].push_back(fileNameRoot+"r_jack"); }else if (Estimators[i] == "shannon") { rDisplays.push_back(new RareDisplay(new Shannon(), new ThreeColumnFile(fileNameRoot+"r_shannon"))); - outputNames.push_back(fileNameRoot+"r_shannon"); + outputNames.push_back(fileNameRoot+"r_shannon"); outputTypes["r_shannon"].push_back(fileNameRoot+"r_shannon"); }else if (Estimators[i] == "shannoneven") { rDisplays.push_back(new RareDisplay(new ShannonEven(), new ThreeColumnFile(fileNameRoot+"r_shannoneven"))); - outputNames.push_back(fileNameRoot+"r_shannoneven"); + outputNames.push_back(fileNameRoot+"r_shannoneven"); outputTypes["r_shannoneven"].push_back(fileNameRoot+"r_shannoneven"); }else if (Estimators[i] == "heip") { rDisplays.push_back(new RareDisplay(new Heip(), new ThreeColumnFile(fileNameRoot+"r_heip"))); - outputNames.push_back(fileNameRoot+"r_heip"); + outputNames.push_back(fileNameRoot+"r_heip"); outputTypes["r_heip"].push_back(fileNameRoot+"r_heip"); }else if (Estimators[i] == "smithwilson") { rDisplays.push_back(new RareDisplay(new SmithWilson(), new ThreeColumnFile(fileNameRoot+"r_smithwilson"))); - outputNames.push_back(fileNameRoot+"r_smithwilson"); + outputNames.push_back(fileNameRoot+"r_smithwilson"); outputTypes["r_smithwilson"].push_back(fileNameRoot+"r_smithwilson"); }else if (Estimators[i] == "npshannon") { rDisplays.push_back(new RareDisplay(new NPShannon(), new ThreeColumnFile(fileNameRoot+"r_npshannon"))); - outputNames.push_back(fileNameRoot+"r_npshannon"); + outputNames.push_back(fileNameRoot+"r_npshannon"); outputTypes["r_npshannon"].push_back(fileNameRoot+"r_npshannon"); }else if (Estimators[i] == "simpson") { rDisplays.push_back(new RareDisplay(new Simpson(), new ThreeColumnFile(fileNameRoot+"r_simpson"))); - outputNames.push_back(fileNameRoot+"r_simpson"); + outputNames.push_back(fileNameRoot+"r_simpson"); outputTypes["r_simpson"].push_back(fileNameRoot+"r_simpson"); }else if (Estimators[i] == "simpsoneven") { rDisplays.push_back(new RareDisplay(new SimpsonEven(), new ThreeColumnFile(fileNameRoot+"r_simpsoneven"))); - outputNames.push_back(fileNameRoot+"r_simpsoneven"); + outputNames.push_back(fileNameRoot+"r_simpsoneven"); outputTypes["r_simpsoneven"].push_back(fileNameRoot+"r_simpsoneven"); }else if (Estimators[i] == "invsimpson") { rDisplays.push_back(new RareDisplay(new InvSimpson(), new ThreeColumnFile(fileNameRoot+"r_invsimpson"))); - outputNames.push_back(fileNameRoot+"r_invsimpson"); + outputNames.push_back(fileNameRoot+"r_invsimpson"); outputTypes["r_invsimpson"].push_back(fileNameRoot+"r_invsimpson"); }else if (Estimators[i] == "bootstrap") { rDisplays.push_back(new RareDisplay(new Bootstrap(), new ThreeColumnFile(fileNameRoot+"r_bootstrap"))); - outputNames.push_back(fileNameRoot+"r_bootstrap"); + outputNames.push_back(fileNameRoot+"r_bootstrap"); outputTypes["r_bootstrap"].push_back(fileNameRoot+"r_bootstrap"); }else if (Estimators[i] == "coverage") { rDisplays.push_back(new RareDisplay(new Coverage(), new ThreeColumnFile(fileNameRoot+"r_coverage"))); - outputNames.push_back(fileNameRoot+"r_coverage"); + outputNames.push_back(fileNameRoot+"r_coverage"); outputTypes["r_coverage"].push_back(fileNameRoot+"r_coverage"); }else if (Estimators[i] == "nseqs") { rDisplays.push_back(new RareDisplay(new NSeqs(), new ThreeColumnFile(fileNameRoot+"r_nseqs"))); - outputNames.push_back(fileNameRoot+"r_nseqs"); + outputNames.push_back(fileNameRoot+"r_nseqs"); outputTypes["r_nseqs"].push_back(fileNameRoot+"r_nseqs"); } } } diff --git a/rarefactcommand.h b/rarefactcommand.h index 3cf0ef7..7da0b2f 100644 --- a/rarefactcommand.h +++ b/rarefactcommand.h @@ -23,8 +23,13 @@ class GlobalData; class RareFactCommand : public Command { public: - RareFactCommand(string); + RareFactCommand(string); + RareFactCommand(); ~RareFactCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -43,8 +48,9 @@ private: set labels; //holds labels to be used string label, calc; vector Estimators; - vector inputFileNames; + vector inputFileNames, outputNames; vector groups; + map > outputTypes; string outputDir; vector parseSharedFile(string); diff --git a/rarefactsharedcommand.cpp b/rarefactsharedcommand.cpp index c0f5ec0..0be8141 100644 --- a/rarefactsharedcommand.cpp +++ b/rarefactsharedcommand.cpp @@ -11,6 +11,54 @@ #include "sharedsobs.h" #include "sharednseqs.h" +//********************************************************************************************************************** +vector RareFactSharedCommand::getValidParameters(){ + try { + string Array[] = {"iters","freq","label","calc","groups", "jumble","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "RareFactSharedCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +RareFactSharedCommand::RareFactSharedCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["sharedrarefaction"] = tempOutNames; + outputTypes["sharedr_nseqs"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "RareFactSharedCommand", "RareFactSharedCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector RareFactSharedCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "RareFactSharedCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector RareFactSharedCommand::getRequiredFiles(){ + try { + string Array[] = {"shared"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "RareFactSharedCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** RareFactSharedCommand::RareFactSharedCommand(string option) { @@ -41,6 +89,11 @@ RareFactSharedCommand::RareFactSharedCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["sharedrarefaction"] = tempOutNames; + outputTypes["sharedr_nseqs"] = tempOutNames; + //make sure the user has already run the read.otu command if (globaldata->getSharedFile() == "") { if (globaldata->getListFile() == "") { m->mothurOut("You must read a list and a group, or a shared before you can use the collect.shared command."); m->mothurOutEndLine(); abort = true; } @@ -107,10 +160,10 @@ RareFactSharedCommand::RareFactSharedCommand(string option) { if (validCalculator->isValidCalculator("sharedrarefaction", Estimators[i]) == true) { if (Estimators[i] == "sharedobserved") { rDisplays.push_back(new RareDisplay(new SharedSobs(), new SharedThreeColumnFile(fileNameRoot+"shared.rarefaction", ""))); - outputNames.push_back(fileNameRoot+"shared.rarefaction"); + outputNames.push_back(fileNameRoot+"shared.rarefaction"); outputTypes["sharedrarefaction"].push_back(fileNameRoot+"shared.rarefaction"); }else if (Estimators[i] == "sharednseqs") { rDisplays.push_back(new RareDisplay(new SharedNSeqs(), new SharedThreeColumnFile(fileNameRoot+"shared.r_nseqs", ""))); - outputNames.push_back(fileNameRoot+"shared.r_nseqs"); + outputNames.push_back(fileNameRoot+"shared.r_nseqs"); outputTypes["sharedr_nseqs"].push_back(fileNameRoot+"shared.r_nseqs"); } } } diff --git a/rarefactsharedcommand.h b/rarefactsharedcommand.h index 1bcddb5..ee16221 100644 --- a/rarefactsharedcommand.h +++ b/rarefactsharedcommand.h @@ -22,7 +22,12 @@ class RareFactSharedCommand : public Command { public: RareFactSharedCommand(string); + RareFactSharedCommand(); ~RareFactSharedCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -42,6 +47,7 @@ private: set labels; //holds labels to be used string label, calc, groups, outputDir; vector Estimators, Groups, outputNames; + map > outputTypes; }; diff --git a/readdistcommand.cpp b/readdistcommand.cpp index 0445eec..c600eb8 100644 --- a/readdistcommand.cpp +++ b/readdistcommand.cpp @@ -12,6 +12,42 @@ #include "readcolumn.h" #include "readmatrix.hpp" +//********************************************************************************************************************** +vector ReadDistCommand::getValidParameters(){ + try { + string Array[] = {"phylip", "column", "name", "cutoff", "precision", "group","outputdir","inputdir","sim"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ReadDistCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ReadDistCommand::getRequiredParameters(){ + try { + string Array[] = {"phylip","column","or"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ReadDistCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ReadDistCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ReadDistCommand", "getRequiredFiles"); + exit(1); + } +} +//********************************************************************************************************************** ReadDistCommand::ReadDistCommand(string option) { try { globaldata = GlobalData::getInstance(); @@ -208,8 +244,6 @@ int ReadDistCommand::execute(){ time_t start = time(NULL); size_t numDists = 0; - vector outputNames; - if (format == "matrix") { ifstream in; m->openInputFile(distFileName, in); diff --git a/readdistcommand.h b/readdistcommand.h index 937ca3f..984b4a7 100644 --- a/readdistcommand.h +++ b/readdistcommand.h @@ -27,7 +27,12 @@ class GlobalData; class ReadDistCommand : public Command { public: ReadDistCommand(string); + ReadDistCommand() {} ~ReadDistCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -41,6 +46,8 @@ private: string distFileName, format, method; string phylipfile, columnfile, namefile, groupfile, outputDir; NameAssignment* nameMap; + vector outputNames; + map > outputTypes; bool abort, sim; diff --git a/readotucommand.cpp b/readotucommand.cpp index efd7073..24a30cb 100644 --- a/readotucommand.cpp +++ b/readotucommand.cpp @@ -9,6 +9,54 @@ #include "readotucommand.h" +//********************************************************************************************************************** +vector ReadOtuCommand::getValidParameters(){ + try { + string Array[] = {"list","order","shared","relabund","label","group","sabund", "rabund","groups","ordergroup","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ReadOtuCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +ReadOtuCommand::ReadOtuCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["rabund"] = tempOutNames; + outputTypes["shared"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "ReadOtuCommand", "ReadOtuCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector ReadOtuCommand::getRequiredParameters(){ + try { + string Array[] = {"list","shared","relabund","sabund","rabund","or"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ChopSeqsCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ReadOtuCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ReadOtuCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** ReadOtuCommand::ReadOtuCommand(string option) { try { @@ -34,7 +82,12 @@ ReadOtuCommand::ReadOtuCommand(string option) { for (it = parameters.begin(); it != parameters.end(); it++) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } - + + //initialize outputTypes + vector tempOutNames; + outputTypes["rabund"] = tempOutNames; + outputTypes["shared"] = tempOutNames; + globaldata->newRead(); //if the user changes the input directory command factory will send this info to us in the output parameter @@ -255,6 +308,8 @@ int ReadOtuCommand::execute(){ //m->mothurOutEndLine(); } + outputTypes = shared->getOutputFiles(); + delete shared; } return 0; diff --git a/readotucommand.h b/readotucommand.h index bf9ccc0..eb0ca8f 100644 --- a/readotucommand.h +++ b/readotucommand.h @@ -20,7 +20,12 @@ class GlobalData; class ReadOtuCommand : public Command { public: ReadOtuCommand(string); + ReadOtuCommand(); ~ReadOtuCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -30,7 +35,8 @@ private: Command* shared; GroupMap* groupMap; string filename, listfile, orderfile, sharedfile, label, groupfile, sabundfile, rabundfile, format, groups, outputDir, ordergroupfile, relAbundfile; - vector Groups; + vector Groups, outputNames; + map > outputTypes; bool abort, allLines; set labels; //holds labels to be used diff --git a/readtreecommand.cpp b/readtreecommand.cpp index 89efc9a..edfdf3b 100644 --- a/readtreecommand.cpp +++ b/readtreecommand.cpp @@ -9,6 +9,41 @@ #include "readtreecommand.h" +//********************************************************************************************************************** +vector ReadTreeCommand::getValidParameters(){ + try { + string Array[] = {"tree","group","name","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ReadTreeCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ReadTreeCommand::getRequiredParameters(){ + try { + string Array[] = {"tree"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ReadTreeCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ReadTreeCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ReadTreeCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** ReadTreeCommand::ReadTreeCommand(string option) { try { @@ -122,7 +157,7 @@ void ReadTreeCommand::help(){ m->mothurOut("It also must be run before using the parsimony command, unless you are using the randomtree parameter.\n"); m->mothurOut("The read.tree command parameters are tree, group and name.\n"); m->mothurOut("The read.tree command should be in the following format: read.tree(tree=yourTreeFile, group=yourGroupFile).\n"); - m->mothurOut("The tree and group parameters are both required.\n"); + m->mothurOut("The tree and group parameters are both required, if no group file is given then one group is assumed.\n"); m->mothurOut("The name parameter allows you to enter a namefile.\n"); m->mothurOut("Note: No spaces between parameter labels (i.e. tree), '=' and parameters (i.e.yourTreefile).\n\n"); } diff --git a/readtreecommand.h b/readtreecommand.h index 5d5b9b5..97391d0 100644 --- a/readtreecommand.h +++ b/readtreecommand.h @@ -19,7 +19,12 @@ class GlobalData; class ReadTreeCommand : public Command { public: ReadTreeCommand(string); + ReadTreeCommand() {} ~ReadTreeCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -30,6 +35,8 @@ private: string filename, treefile, groupfile, namefile; bool abort; map nameMap; + vector outputNames; + map > outputTypes; int readNamesFile(); int numUniquesInName; diff --git a/removelineagecommand.cpp b/removelineagecommand.cpp index d316019..557622d 100644 --- a/removelineagecommand.cpp +++ b/removelineagecommand.cpp @@ -12,7 +12,58 @@ #include "listvector.hpp" //********************************************************************************************************************** - +vector RemoveLineageCommand::getValidParameters(){ + try { + string Array[] = {"fasta","name", "group", "alignreport", "taxon", "dups", "list","taxonomy","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "RemoveLineageCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +RemoveLineageCommand::RemoveLineageCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["taxonomy"] = tempOutNames; + outputTypes["name"] = tempOutNames; + outputTypes["group"] = tempOutNames; + outputTypes["alignreport"] = tempOutNames; + outputTypes["list"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "RemoveLineageCommand", "RemoveLineageCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector RemoveLineageCommand::getRequiredParameters(){ + try { + string Array[] = {"taxonomy"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "RemoveLineageCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector RemoveLineageCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "RemoveLineageCommand", "getRequiredFiles"); + exit(1); + } +} +//********************************************************************************************************************** RemoveLineageCommand::RemoveLineageCommand(string option) { try { abort = false; @@ -36,6 +87,15 @@ RemoveLineageCommand::RemoveLineageCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["taxonomy"] = tempOutNames; + outputTypes["name"] = tempOutNames; + outputTypes["group"] = tempOutNames; + outputTypes["alignreport"] = tempOutNames; + outputTypes["list"] = tempOutNames; + //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; } @@ -237,7 +297,7 @@ int RemoveLineageCommand::readFasta(){ out.close(); if (wroteSomething == false) { m->mothurOut("Your fasta file contains only sequences from " + taxons + "."); m->mothurOutEndLine(); } - outputNames.push_back(outputFileName); + outputTypes["fasta"].push_back(outputFileName); return 0; @@ -308,7 +368,7 @@ int RemoveLineageCommand::readList(){ out.close(); if (wroteSomething == false) { m->mothurOut("Your list file contains only sequences from " + taxons + "."); m->mothurOutEndLine(); } - outputNames.push_back(outputFileName); + outputTypes["list"].push_back(outputFileName); return 0; @@ -394,7 +454,7 @@ int RemoveLineageCommand::readName(){ out.close(); if (wroteSomething == false) { m->mothurOut("Your name file contains only sequences from " + taxons + "."); m->mothurOutEndLine(); } - outputNames.push_back(outputFileName); + outputTypes["name"].push_back(outputFileName); return 0; } @@ -438,7 +498,7 @@ int RemoveLineageCommand::readGroup(){ out.close(); if (wroteSomething == false) { m->mothurOut("Your group file contains only sequences from " + taxons + "."); m->mothurOutEndLine(); } - outputNames.push_back(outputFileName); + outputTypes["group"].push_back(outputFileName); return 0; } @@ -492,7 +552,7 @@ int RemoveLineageCommand::readTax(){ out.close(); if (!wroteSomething) { m->mothurOut("Your taxonomy file contains only sequences from " + taxons + "."); m->mothurOutEndLine(); } - outputNames.push_back(outputFileName); + outputTypes["taxonomy"].push_back(outputFileName); return 0; @@ -582,7 +642,7 @@ int RemoveLineageCommand::readAlign(){ out.close(); if (wroteSomething == false) { m->mothurOut("Your align file contains only sequences from " + taxons + "."); m->mothurOutEndLine(); } - outputNames.push_back(outputFileName); + outputTypes["alignreport"].push_back(outputFileName); return 0; diff --git a/removelineagecommand.h b/removelineagecommand.h index d18fc23..c590ec6 100644 --- a/removelineagecommand.h +++ b/removelineagecommand.h @@ -17,13 +17,19 @@ class RemoveLineageCommand : public Command { public: RemoveLineageCommand(string); + RemoveLineageCommand(); ~RemoveLineageCommand(){}; + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); private: set names; vector outputNames; + map > outputTypes; string fastafile, namefile, groupfile, alignfile, listfile, taxfile, outputDir, taxons; bool abort, dups; diff --git a/removeseqscommand.cpp b/removeseqscommand.cpp index 0ab181b..afba651 100644 --- a/removeseqscommand.cpp +++ b/removeseqscommand.cpp @@ -12,7 +12,58 @@ #include "listvector.hpp" //********************************************************************************************************************** - +vector RemoveSeqsCommand::getValidParameters(){ + try { + string Array[] = {"fasta","name", "group", "alignreport", "accnos", "list","taxonomy","outputdir","inputdir", "dups" }; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "RemoveSeqsCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +RemoveSeqsCommand::RemoveSeqsCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["taxonomy"] = tempOutNames; + outputTypes["name"] = tempOutNames; + outputTypes["group"] = tempOutNames; + outputTypes["alignreport"] = tempOutNames; + outputTypes["list"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "RemoveSeqsCommand", "RemoveSeqsCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector RemoveSeqsCommand::getRequiredParameters(){ + try { + string Array[] = {"accnos"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "RemoveSeqsCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector RemoveSeqsCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "RemoveSeqsCommand", "getRequiredFiles"); + exit(1); + } +} +//********************************************************************************************************************** RemoveSeqsCommand::RemoveSeqsCommand(string option) { try { abort = false; @@ -36,6 +87,15 @@ RemoveSeqsCommand::RemoveSeqsCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["taxonomy"] = tempOutNames; + outputTypes["name"] = tempOutNames; + outputTypes["group"] = tempOutNames; + outputTypes["alignreport"] = tempOutNames; + outputTypes["list"] = tempOutNames; + //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; } @@ -243,7 +303,7 @@ int RemoveSeqsCommand::readFasta(){ out.close(); if (wroteSomething == false) { m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); } - outputNames.push_back(outputFileName); + outputTypes["fasta"].push_back(outputFileName); return 0; @@ -314,7 +374,7 @@ int RemoveSeqsCommand::readList(){ out.close(); if (wroteSomething == false) { m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); } - outputNames.push_back(outputFileName); + outputTypes["list"].push_back(outputFileName); return 0; @@ -400,7 +460,7 @@ int RemoveSeqsCommand::readName(){ out.close(); if (wroteSomething == false) { m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); } - outputNames.push_back(outputFileName); + outputTypes["name"].push_back(outputFileName); return 0; } @@ -444,7 +504,7 @@ int RemoveSeqsCommand::readGroup(){ out.close(); if (wroteSomething == false) { m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); } - outputNames.push_back(outputFileName); + outputTypes["group"].push_back(outputFileName); return 0; } @@ -486,7 +546,7 @@ int RemoveSeqsCommand::readTax(){ out.close(); if (wroteSomething == false) { m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); } - outputNames.push_back(outputFileName); + outputTypes["taxonomy"].push_back(outputFileName); return 0; } @@ -552,7 +612,7 @@ int RemoveSeqsCommand::readAlign(){ out.close(); if (wroteSomething == false) { m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); } - outputNames.push_back(outputFileName); + outputTypes["alignreport"].push_back(outputFileName); return 0; diff --git a/removeseqscommand.h b/removeseqscommand.h index 8238c64..8321212 100644 --- a/removeseqscommand.h +++ b/removeseqscommand.h @@ -17,7 +17,12 @@ class RemoveSeqsCommand : public Command { public: RemoveSeqsCommand(string); - ~RemoveSeqsCommand(){}; + RemoveSeqsCommand(); + ~RemoveSeqsCommand(){} + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -26,6 +31,7 @@ class RemoveSeqsCommand : public Command { string accnosfile, fastafile, namefile, groupfile, alignfile, listfile, taxfile, outputDir; bool abort, dups; vector outputNames; + map > outputTypes; int readFasta(); int readName(); diff --git a/reversecommand.cpp b/reversecommand.cpp index 296c954..d179f0d 100644 --- a/reversecommand.cpp +++ b/reversecommand.cpp @@ -10,7 +10,53 @@ #include "reversecommand.h" #include "sequence.hpp" - +//********************************************************************************************************************** +vector ReverseSeqsCommand::getValidParameters(){ + try { + string Array[] = {"fasta", "outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ReverseSeqsCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +ReverseSeqsCommand::ReverseSeqsCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "ReverseSeqsCommand", "ReverseSeqsCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector ReverseSeqsCommand::getRequiredParameters(){ + try { + string Array[] = {"fasta"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ReverseSeqsCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ReverseSeqsCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ReverseSeqsCommand", "getRequiredFiles"); + exit(1); + } +} //*************************************************************************************************************** ReverseSeqsCommand::ReverseSeqsCommand(string option) { @@ -36,6 +82,10 @@ ReverseSeqsCommand::ReverseSeqsCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -72,7 +122,7 @@ ReverseSeqsCommand::ReverseSeqsCommand(string option) { void ReverseSeqsCommand::help(){ try { - m->mothurOut("The reverse.seqs command reads a fastafile and ....\n"); + m->mothurOut("The reverse.seqs command reads a fastafile and outputs a fasta file containing the reverse compliment.\n"); m->mothurOut("The reverse.seqs command parameter is fasta and it is required.\n"); m->mothurOut("The reverse.seqs command should be in the following format: \n"); m->mothurOut("reverse.seqs(fasta=yourFastaFile) \n"); @@ -118,7 +168,7 @@ int ReverseSeqsCommand::execute(){ m->mothurOutEndLine(); m->mothurOut("Output File Name: "); m->mothurOutEndLine(); - m->mothurOut(reverseFile); m->mothurOutEndLine(); + m->mothurOut(reverseFile); m->mothurOutEndLine(); outputNames.push_back(reverseFile); outputTypes["fasta"].push_back(reverseFile); m->mothurOutEndLine(); diff --git a/reversecommand.h b/reversecommand.h index 874bde6..8b5bcd2 100644 --- a/reversecommand.h +++ b/reversecommand.h @@ -15,7 +15,12 @@ class ReverseSeqsCommand : public Command { public: ReverseSeqsCommand(string); + ReverseSeqsCommand(); ~ReverseSeqsCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -23,6 +28,8 @@ private: bool abort; string fasta, outputDir; + vector outputNames; + map > outputTypes; }; diff --git a/screenseqscommand.cpp b/screenseqscommand.cpp index 581264c..5845b8f 100644 --- a/screenseqscommand.cpp +++ b/screenseqscommand.cpp @@ -10,6 +10,58 @@ #include "screenseqscommand.h" #include "sequence.hpp" +//********************************************************************************************************************** +vector ScreenSeqsCommand::getValidParameters(){ + try { + string Array[] = {"fasta", "start", "end", "maxambig", "maxhomop","optimize","criteria", "minlength", "maxlength", + "name", "group", "alignreport","processors","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ScreenSeqsCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +ScreenSeqsCommand::ScreenSeqsCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["name"] = tempOutNames; + outputTypes["group"] = tempOutNames; + outputTypes["alignreport"] = tempOutNames; + outputTypes["accnos"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "ScreenSeqsCommand", "ScreenSeqsCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector ScreenSeqsCommand::getRequiredParameters(){ + try { + string Array[] = {"fasta"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ScreenSeqsCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ScreenSeqsCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ScreenSeqsCommand", "getRequiredFiles"); + exit(1); + } +} //*************************************************************************************************************** ScreenSeqsCommand::ScreenSeqsCommand(string option) { @@ -21,7 +73,7 @@ ScreenSeqsCommand::ScreenSeqsCommand(string option) { else { //valid paramters for this command - string AlignArray[] = {"fasta", "start", "end", "maxambig", "maxhomop", "minlength", "maxlength", + string AlignArray[] = {"fasta", "start", "end", "maxambig", "maxhomop","optimize","criteria", "minlength", "maxlength", "name", "group", "alignreport","processors","outputdir","inputdir"}; vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); @@ -36,6 +88,14 @@ ScreenSeqsCommand::ScreenSeqsCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["name"] = tempOutNames; + outputTypes["group"] = tempOutNames; + outputTypes["alignreport"] = tempOutNames; + outputTypes["accnos"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -120,7 +180,25 @@ ScreenSeqsCommand::ScreenSeqsCommand(string option) { temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = "1"; } convert(temp, processors); - + + temp = validParameter.validFile(parameters, "optimize", false); //optimizing trumps the optimized values original value + if (temp == "not found"){ temp = ""; } + else { m->splitAtDash(temp, optimize); } + + //check for invalid optimize options + set validOptimizers; + validOptimizers.insert("start"); validOptimizers.insert("end"); validOptimizers.insert("maxambig"); validOptimizers.insert("maxhomop"); validOptimizers.insert("minlength"); validOptimizers.insert("maxlength"); + + for (int i = 0; i < optimize.size(); i++) { + if (validOptimizers.count(optimize[i]) == 0) { + m->mothurOut(optimize[i] + " is not a valid optimizer. Valid options are start, end, maxambig, maxhomop, minlength and maxlength."); m->mothurOutEndLine(); + optimize.erase(optimize.begin()+i); + i--; + } + } + + temp = validParameter.validFile(parameters, "criteria", false); if (temp == "not found"){ temp = "90"; } + convert(temp, criteria); } } @@ -134,7 +212,7 @@ ScreenSeqsCommand::ScreenSeqsCommand(string option) { void ScreenSeqsCommand::help(){ try { m->mothurOut("The screen.seqs command reads a fastafile and creates .....\n"); - m->mothurOut("The screen.seqs command parameters are fasta, start, end, maxambig, maxhomop, minlength, maxlength, name, group and processors.\n"); + m->mothurOut("The screen.seqs command parameters are fasta, start, end, maxambig, maxhomop, minlength, maxlength, name, group, optimize, criteria and processors.\n"); m->mothurOut("The fasta parameter is required.\n"); m->mothurOut("The start parameter .... The default is -1.\n"); m->mothurOut("The end parameter .... The default is -1.\n"); @@ -143,6 +221,8 @@ void ScreenSeqsCommand::help(){ m->mothurOut("The minlength parameter .... The default is -1.\n"); m->mothurOut("The maxlength parameter .... The default is -1.\n"); m->mothurOut("The processors parameter allows you to specify the number of processors to use while running the command. The default is 1.\n"); + m->mothurOut("The optimize and criteria parameters allow you set the start, end, maxabig, maxhomop, minlength and maxlength parameters relative to your set of sequences .\n"); + m->mothurOut("For example optimize=start-end, criteria=90, would set the start and end values to the position 90% of your sequences started and ended.\n"); m->mothurOut("The name parameter allows you to provide a namesfile, and the group parameter allows you to provide a groupfile.\n"); m->mothurOut("The screen.seqs command should be in the following format: \n"); m->mothurOut("screen.seqs(fasta=yourFastaFile, name=youNameFile, group=yourGroupFIle, start=yourStart, end=yourEnd, maxambig=yourMaxambig, \n"); @@ -167,6 +247,16 @@ int ScreenSeqsCommand::execute(){ try{ if (abort == true) { return 0; } + + //if the user want to optimize we need to no the 90% mark + vector positions; + if (optimize.size() != 0) { getSummary(positions); } //get summary is paralellized so we need to divideFile, no need to do this step twice so I moved it here + else { + positions = m->divideFile(fastafile, processors); + for (int i = 0; i < (positions.size()-1); i++) { + lines.push_back(new linePair(positions[i], positions[(i+1)])); + } + } string goodSeqFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "good" + m->getExtension(fastafile); string badAccnosFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "bad.accnos"; @@ -283,11 +373,6 @@ int ScreenSeqsCommand::execute(){ MPI_Barrier(MPI_COMM_WORLD); //make everyone wait - just in case #else - vector positions = m->divideFile(fastafile, processors); - - for (int i = 0; i < (positions.size()-1); i++) { - lines.push_back(new linePair(positions[i], positions[(i+1)])); - } #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) if(processors == 1){ @@ -390,8 +475,8 @@ int ScreenSeqsCommand::execute(){ m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); - m->mothurOut(goodSeqFile); m->mothurOutEndLine(); - m->mothurOut(badAccnosFile); m->mothurOutEndLine(); + m->mothurOut(goodSeqFile); m->mothurOutEndLine(); outputTypes["fasta"].push_back(goodSeqFile); + m->mothurOut(badAccnosFile); m->mothurOutEndLine(); outputTypes["accnos"].push_back(badAccnosFile); for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); } m->mothurOutEndLine(); m->mothurOutEndLine(); @@ -418,7 +503,7 @@ int ScreenSeqsCommand::screenNameGroupFile(set badSeqNames){ set::iterator it; string goodNameFile = outputDir + m->getRootName(m->getSimpleName(namefile)) + "good" + m->getExtension(namefile); - outputNames.push_back(goodNameFile); + outputNames.push_back(goodNameFile); outputTypes["name"].push_back(goodNameFile); ofstream goodNameOut; m->openOutputFile(goodNameFile, goodNameOut); @@ -464,7 +549,7 @@ int ScreenSeqsCommand::screenNameGroupFile(set badSeqNames){ m->openInputFile(groupfile, inputGroups); string goodGroupFile = outputDir + m->getRootName(m->getSimpleName(groupfile)) + "good" + m->getExtension(groupfile); - outputNames.push_back(goodGroupFile); + outputNames.push_back(goodGroupFile); outputTypes["group"].push_back(goodGroupFile); ofstream goodGroupOut; m->openOutputFile(goodGroupFile, goodGroupOut); @@ -503,6 +588,175 @@ int ScreenSeqsCommand::screenNameGroupFile(set badSeqNames){ exit(1); } } +//*************************************************************************************************************** +int ScreenSeqsCommand::getSummary(vector& positions){ + try { + + vector startPosition; + vector endPosition; + vector seqLength; + vector ambigBases; + vector longHomoPolymer; + + vector positions = m->divideFile(fastafile, processors); + + for (int i = 0; i < (positions.size()-1); i++) { + lines.push_back(new linePair(positions[i], positions[(i+1)])); + } + + int numSeqs = 0; + #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) + if(processors == 1){ + numSeqs = driverCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, fastafile, lines[0]); + }else{ + numSeqs = createProcessesCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, fastafile); + } + + if (m->control_pressed) { return 0; } + #else + numSeqs = driverCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, fastafile, lines[0]); + if (m->control_pressed) { return 0; } + #endif + + sort(startPosition.begin(), startPosition.end()); + sort(endPosition.begin(), endPosition.end()); + sort(seqLength.begin(), seqLength.end()); + sort(ambigBases.begin(), ambigBases.end()); + sort(longHomoPolymer.begin(), longHomoPolymer.end()); + + int criteriaPercentile = int(numSeqs * (criteria / (float) 100)); + + for (int i = 0; i < optimize.size(); i++) { + if (optimize[i] == "start") { startPos = startPosition[criteriaPercentile]; m->mothurOut("Optimizing start to " + toString(startPos) + "."); m->mothurOutEndLine(); } + else if (optimize[i] == "end") { int endcriteriaPercentile = int(numSeqs * ((100 - criteria) / (float) 100)); endPos = endPosition[endcriteriaPercentile]; m->mothurOut("Optimizing end to " + toString(endPos) + "."); m->mothurOutEndLine();} + else if (optimize[i] == "maxambig") { maxAmbig = ambigBases[criteriaPercentile]; m->mothurOut("Optimizing maxambig to " + toString(maxAmbig) + "."); m->mothurOutEndLine(); } + else if (optimize[i] == "maxhomop") { maxHomoP = longHomoPolymer[criteriaPercentile]; m->mothurOut("Optimizing maxhomop to " + toString(maxHomoP) + "."); m->mothurOutEndLine(); } + else if (optimize[i] == "minlength") { int mincriteriaPercentile = int(numSeqs * ((100 - criteria) / (float) 100)); minLength = seqLength[mincriteriaPercentile]; m->mothurOut("Optimizing minlength to " + toString(minLength) + "."); m->mothurOutEndLine(); } + else if (optimize[i] == "maxlength") { maxLength = seqLength[criteriaPercentile]; m->mothurOut("Optimizing maxlength to " + toString(maxLength) + "."); m->mothurOutEndLine(); } + } + + return 0; + } + catch(exception& e) { + m->errorOut(e, "ScreenSeqsCommand", "getSummary"); + exit(1); + } +} +/**************************************************************************************/ +int ScreenSeqsCommand::driverCreateSummary(vector& startPosition, vector& endPosition, vector& seqLength, vector& ambigBases, vector& longHomoPolymer, string filename, linePair* filePos) { + try { + + ifstream in; + m->openInputFile(filename, in); + + in.seekg(filePos->start); + + bool done = false; + int count = 0; + + while (!done) { + + if (m->control_pressed) { in.close(); return 1; } + + Sequence current(in); m->gobble(in); + + if (current.getName() != "") { + startPosition.push_back(current.getStartPos()); + endPosition.push_back(current.getEndPos()); + seqLength.push_back(current.getNumBases()); + ambigBases.push_back(current.getAmbigBases()); + longHomoPolymer.push_back(current.getLongHomoPolymer()); + count++; + } + + #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) + unsigned long int pos = in.tellg(); + if ((pos == -1) || (pos >= filePos->end)) { break; } + #else + if (in.eof()) { break; } + #endif + + } + + in.close(); + + return count; + } + catch(exception& e) { + m->errorOut(e, "ScreenSeqsCommand", "driverCreateSummary"); + exit(1); + } +} +/**************************************************************************************************/ +int ScreenSeqsCommand::createProcessesCreateSummary(vector& startPosition, vector& endPosition, vector& seqLength, vector& ambigBases, vector& longHomoPolymer, string filename) { + try { +#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) + int process = 1; + int num = 0; + processIDS.clear(); + + //loop through and create all the processes you want + while (process != processors) { + int pid = fork(); + + if (pid > 0) { + processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later + process++; + }else if (pid == 0){ + num = driverCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, fastafile, lines[process]); + + //pass numSeqs to parent + ofstream out; + string tempFile = fastafile + toString(getpid()) + ".num.temp"; + m->openOutputFile(tempFile, out); + + out << num << endl; + for (int k = 0; k < startPosition.size(); k++) { out << startPosition[k] << '\t'; } out << endl; + for (int k = 0; k < endPosition.size(); k++) { out << endPosition[k] << '\t'; } out << endl; + for (int k = 0; k < seqLength.size(); k++) { out << seqLength[k] << '\t'; } out << endl; + for (int k = 0; k < ambigBases.size(); k++) { out << ambigBases[k] << '\t'; } out << endl; + for (int k = 0; k < longHomoPolymer.size(); k++) { out << longHomoPolymer[k] << '\t'; } out << endl; + + out.close(); + + exit(0); + }else { m->mothurOut("unable to spawn the necessary processes."); m->mothurOutEndLine(); exit(0); } + } + + num = driverCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, fastafile, lines[0]); + + //force parent to wait until all the processes are done + for (int i=0;iopenInputFile(tempFilename, in); + + int temp, tempNum; + in >> tempNum; m->gobble(in); num += tempNum; + for (int k = 0; k < tempNum; k++) { in >> temp; startPosition.push_back(temp); } m->gobble(in); + for (int k = 0; k < tempNum; k++) { in >> temp; endPosition.push_back(temp); } m->gobble(in); + for (int k = 0; k < tempNum; k++) { in >> temp; seqLength.push_back(temp); } m->gobble(in); + for (int k = 0; k < tempNum; k++) { in >> temp; ambigBases.push_back(temp); } m->gobble(in); + for (int k = 0; k < tempNum; k++) { in >> temp; longHomoPolymer.push_back(temp); } m->gobble(in); + + in.close(); + remove(tempFilename.c_str()); + } + + return num; +#endif + } + catch(exception& e) { + m->errorOut(e, "ScreenSeqsCommand", "createProcessesCreateSummary"); + exit(1); + } +} //*************************************************************************************************************** @@ -514,7 +768,7 @@ int ScreenSeqsCommand::screenGroupFile(set badSeqNames){ set::iterator it; string goodGroupFile = outputDir + m->getRootName(m->getSimpleName(groupfile)) + "good" + m->getExtension(groupfile); - outputNames.push_back(goodGroupFile); + outputNames.push_back(goodGroupFile); outputTypes["group"].push_back(goodGroupFile); ofstream goodGroupOut; m->openOutputFile(goodGroupFile, goodGroupOut); while(!inputGroups.eof()){ @@ -566,7 +820,7 @@ int ScreenSeqsCommand::screenAlignReport(set badSeqNames){ set::iterator it; string goodAlignReportFile = outputDir + m->getRootName(m->getSimpleName(alignreport)) + "good" + m->getExtension(alignreport); - outputNames.push_back(goodAlignReportFile); + outputNames.push_back(goodAlignReportFile); outputTypes["alignreport"].push_back(goodAlignReportFile); ofstream goodAlignReportOut; m->openOutputFile(goodAlignReportFile, goodAlignReportOut); while (!inputAlignReport.eof()) { // need to copy header diff --git a/screenseqscommand.h b/screenseqscommand.h index 2c31ba2..81b915e 100644 --- a/screenseqscommand.h +++ b/screenseqscommand.h @@ -16,7 +16,12 @@ class ScreenSeqsCommand : public Command { public: ScreenSeqsCommand(string); + ScreenSeqsCommand(); ~ScreenSeqsCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -44,8 +49,14 @@ private: bool abort; string fastafile, namefile, groupfile, alignreport, outputDir; - int startPos, endPos, maxAmbig, maxHomoP, minLength, maxLength, processors; + int startPos, endPos, maxAmbig, maxHomoP, minLength, maxLength, processors, criteria; vector outputNames; + vector optimize; + map > outputTypes; + + int getSummary(vector&); + int createProcessesCreateSummary(vector&, vector&, vector&, vector&, vector&, string); + int driverCreateSummary(vector&, vector&, vector&, vector&, vector&, string, linePair*); }; #endif diff --git a/secondarystructurecommand.cpp b/secondarystructurecommand.cpp index c08ee6a..36e0f60 100644 --- a/secondarystructurecommand.cpp +++ b/secondarystructurecommand.cpp @@ -10,6 +10,53 @@ #include "secondarystructurecommand.h" #include "sequence.hpp" +//********************************************************************************************************************** +vector AlignCheckCommand::getValidParameters(){ + try { + string Array[] = {"fasta","map", "outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "AlignCheckCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +AlignCheckCommand::AlignCheckCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["aligncheck"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "AlignCheckCommand", "AlignCheckCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector AlignCheckCommand::getRequiredParameters(){ + try { + string Array[] = {"fasta","map"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "AlignCheckCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector AlignCheckCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "AlignCheckCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** AlignCheckCommand::AlignCheckCommand(string option) { @@ -36,6 +83,10 @@ AlignCheckCommand::AlignCheckCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["aligncheck"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -140,7 +191,7 @@ int AlignCheckCommand::execute(){ m->mothurOutEndLine(); m->mothurOut("Output File Name: "); m->mothurOutEndLine(); - m->mothurOut(outfile); m->mothurOutEndLine(); + m->mothurOut(outfile); m->mothurOutEndLine(); outputNames.push_back(outfile); outputTypes["aligncheck"].push_back(outfile); m->mothurOutEndLine(); return 0; diff --git a/secondarystructurecommand.h b/secondarystructurecommand.h index 2e6191c..c1cc057 100644 --- a/secondarystructurecommand.h +++ b/secondarystructurecommand.h @@ -33,7 +33,12 @@ class AlignCheckCommand : public Command { public: AlignCheckCommand(string); - ~AlignCheckCommand(){}; + AlignCheckCommand(); + ~AlignCheckCommand(){} + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -42,6 +47,8 @@ class AlignCheckCommand : public Command { string mapfile, fastafile, outputDir; bool abort; int seqLength, haderror; + vector outputNames; + map > outputTypes; void readMap(); statData getStats(string sequence); diff --git a/sensspeccommand.cpp b/sensspeccommand.cpp index 8489bfe..78dce17 100644 --- a/sensspeccommand.cpp +++ b/sensspeccommand.cpp @@ -9,6 +9,53 @@ #include "sensspeccommand.h" +//********************************************************************************************************************** +vector SensSpecCommand::getValidParameters(){ + try { + string Array[] = {"list", "phylip", "column", "name", "hard", "label", "cutoff", "precision", "outputdir", "inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SensSpecCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +SensSpecCommand::SensSpecCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["sensspec"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "SensSpecCommand", "SensSpecCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector SensSpecCommand::getRequiredParameters(){ + try { + string Array[] = {"list","phylip","column","or"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SensSpecCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector SensSpecCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SensSpecCommand", "getRequiredFiles"); + exit(1); + } +} //*************************************************************************************************************** SensSpecCommand::SensSpecCommand(string option) { @@ -38,6 +85,10 @@ SensSpecCommand::SensSpecCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["sensspec"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -159,6 +210,7 @@ int SensSpecCommand::execute(){ if (abort == true) { return 0; } setUpOutput(); + outputNames.push_back(sensSpecFileName); outputTypes["sensspec"].push_back(sensSpecFileName); if(format == "phylip") { processPhylip(); } else if(format == "column") { processColumn(); } diff --git a/sensspeccommand.h b/sensspeccommand.h index 818667a..687834c 100644 --- a/sensspeccommand.h +++ b/sensspeccommand.h @@ -18,7 +18,12 @@ class SensSpecCommand : public Command { public: SensSpecCommand(string); + SensSpecCommand(); ~SensSpecCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -31,6 +36,8 @@ private: string listFile, distFile, nameFile, sensSpecFileName; string outputDir; string format; + vector outputNames; + map > outputTypes; long int truePositives, falsePositives, trueNegatives, falseNegatives; bool abort; diff --git a/seqerrorcommand.cpp b/seqerrorcommand.cpp index f1b9cd8..1f880f3 100644 --- a/seqerrorcommand.cpp +++ b/seqerrorcommand.cpp @@ -9,6 +9,54 @@ #include "seqerrorcommand.h" +//********************************************************************************************************************** +vector SeqErrorCommand::getValidParameters(){ + try { + string Array[] = {"query", "reference", "name", "threshold", "inputdir", "outputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SeqErrorCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +SeqErrorCommand::SeqErrorCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["error"] = tempOutNames; + outputTypes["count"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "SeqErrorCommand", "SeqErrorCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector SeqErrorCommand::getRequiredParameters(){ + try { + string Array[] = {"query","reference"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SeqErrorCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector SeqErrorCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SeqErrorCommand", "getRequiredFiles"); + exit(1); + } +} //*************************************************************************************************************** SeqErrorCommand::SeqErrorCommand(string option) { @@ -23,7 +71,7 @@ SeqErrorCommand::SeqErrorCommand(string option) { string temp; //valid paramters for this command - string AlignArray[] = {"query", "reference", "name", "threshold"}; + string AlignArray[] = {"query", "reference", "name", "threshold", "inputdir", "outputdir"}; //need to implement name file option @@ -40,6 +88,11 @@ SeqErrorCommand::SeqErrorCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["error"] = tempOutNames; + outputTypes["count"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -97,6 +150,7 @@ SeqErrorCommand::SeqErrorCommand(string option) { errorFileName = queryFileName.substr(0,queryFileName.find_last_of('.')) + ".errors"; m->openOutputFile(errorFileName, errorFile); + outputNames.push_back(errorFileName); outputTypes["error"].push_back(errorFileName); printErrorHeader(); } } @@ -195,6 +249,7 @@ int SeqErrorCommand::execute(){ string errorCountFileName = queryFileName.substr(0,queryFileName.find_last_of('.')) + ".count"; ofstream errorCountFile; m->openOutputFile(errorCountFileName, errorCountFile); + outputNames.push_back(errorCountFileName); outputTypes["count"].push_back(errorCountFileName); m->mothurOut("Overall error rate:\t" + toString((double)(totalBases - totalMatches) / (double)totalBases) + "\n\n"); m->mothurOut("Errors\tSequences\n"); diff --git a/seqerrorcommand.h b/seqerrorcommand.h index 1eb2576..983383b 100644 --- a/seqerrorcommand.h +++ b/seqerrorcommand.h @@ -41,7 +41,12 @@ struct Compare { class SeqErrorCommand : public Command { public: SeqErrorCommand(string); + SeqErrorCommand(); ~SeqErrorCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -58,6 +63,8 @@ private: double threshold; int numRefs; ofstream errorFile; + vector outputNames; + map > outputTypes; vector referenceSeqs; }; diff --git a/seqsummarycommand.cpp b/seqsummarycommand.cpp index a47364a..7d074c4 100644 --- a/seqsummarycommand.cpp +++ b/seqsummarycommand.cpp @@ -10,6 +10,53 @@ #include "seqsummarycommand.h" #include "sequence.hpp" +//********************************************************************************************************************** +vector SeqSummaryCommand::getValidParameters(){ + try { + string Array[] = {"fasta","processors","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SeqSummaryCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +SeqSummaryCommand::SeqSummaryCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["summary"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "SeqSummaryCommand", "SeqSummaryCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector SeqSummaryCommand::getRequiredParameters(){ + try { + string Array[] = {"fasta"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SeqSummaryCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector SeqSummaryCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SeqSummaryCommand", "getRequiredFiles"); + exit(1); + } +} //*************************************************************************************************************** SeqSummaryCommand::SeqSummaryCommand(string option) { @@ -49,6 +96,10 @@ SeqSummaryCommand::SeqSummaryCommand(string option) { } } + //initialize outputTypes + vector tempOutNames; + outputTypes["summary"] = tempOutNames; + //check for required parameters fastafile = validParameter.validFile(parameters, "fasta", true); if (fastafile == "not open") { abort = true; } @@ -289,7 +340,7 @@ int SeqSummaryCommand::execute(){ m->mothurOutEndLine(); m->mothurOut("Output File Name: "); m->mothurOutEndLine(); - m->mothurOut(summaryFile); m->mothurOutEndLine(); + m->mothurOut(summaryFile); m->mothurOutEndLine(); outputNames.push_back(summaryFile); outputTypes["summary"].push_back(summaryFile); m->mothurOutEndLine(); #ifdef USE_MPI diff --git a/seqsummarycommand.h b/seqsummarycommand.h index 6abf06a..305c6e3 100644 --- a/seqsummarycommand.h +++ b/seqsummarycommand.h @@ -16,7 +16,12 @@ class SeqSummaryCommand : public Command { public: SeqSummaryCommand(string); + SeqSummaryCommand(); ~SeqSummaryCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -24,6 +29,8 @@ private: bool abort; string fastafile, outputDir; int processors; + vector outputNames; + map > outputTypes; struct linePair { unsigned long int start; diff --git a/setdircommand.cpp b/setdircommand.cpp index a9ae730..214bd17 100644 --- a/setdircommand.cpp +++ b/setdircommand.cpp @@ -9,6 +9,40 @@ #include "setdircommand.h" +//********************************************************************************************************************** +vector SetDirectoryCommand::getValidParameters(){ + try { + string Array[] = {"output","input","tempdefault","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SetDirectoryCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector SetDirectoryCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SetDirectoryCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector SetDirectoryCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SetDirectoryCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** SetDirectoryCommand::SetDirectoryCommand(string option) { diff --git a/setdircommand.h b/setdircommand.h index 330adf1..1afab07 100644 --- a/setdircommand.h +++ b/setdircommand.h @@ -20,7 +20,12 @@ class SetDirectoryCommand : public Command { public: SetDirectoryCommand(string); + SetDirectoryCommand() {} ~SetDirectoryCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -28,6 +33,8 @@ private: CommandFactory* commandFactory; string output, input, tempdefault; bool abort; + vector outputNames; + map > outputTypes; }; diff --git a/setlogfilecommand.cpp b/setlogfilecommand.cpp index 19f3ed1..b99b833 100644 --- a/setlogfilecommand.cpp +++ b/setlogfilecommand.cpp @@ -9,6 +9,41 @@ #include "setlogfilecommand.h" +//********************************************************************************************************************** +vector SetLogFileCommand::getValidParameters(){ + try { + string Array[] = {"name","append","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SetLogFileCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector SetLogFileCommand::getRequiredParameters(){ + try { + string Array[] = {"name"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SetLogFileCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector SetLogFileCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SetLogFileCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** SetLogFileCommand::SetLogFileCommand(string option) { diff --git a/setlogfilecommand.h b/setlogfilecommand.h index d16bcd6..d2b5c3d 100644 --- a/setlogfilecommand.h +++ b/setlogfilecommand.h @@ -19,7 +19,12 @@ class SetLogFileCommand : public Command { public: SetLogFileCommand(string); + SetLogFileCommand() {} ~SetLogFileCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -27,6 +32,8 @@ private: CommandFactory* commandFactory; string name; bool abort, append; + vector outputNames; + map > outputTypes; }; diff --git a/sffinfocommand.cpp b/sffinfocommand.cpp index a691a40..e51f7f2 100644 --- a/sffinfocommand.cpp +++ b/sffinfocommand.cpp @@ -10,6 +10,56 @@ #include "sffinfocommand.h" #include "endiannessmacros.h" +//********************************************************************************************************************** +vector SffInfoCommand::getValidParameters(){ + try { + string Array[] = {"sff","qfile","fasta","flow","trim","accnos","sfftxt","outputdir","inputdir", "outputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SffInfoCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +SffInfoCommand::SffInfoCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["flow"] = tempOutNames; + outputTypes["sfftxt"] = tempOutNames; + outputTypes["qual"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "SffInfoCommand", "SffInfoCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector SffInfoCommand::getRequiredParameters(){ + try { + string Array[] = {"sff"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SffInfoCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector SffInfoCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SffInfoCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** SffInfoCommand::SffInfoCommand(string option) { @@ -34,6 +84,13 @@ SffInfoCommand::SffInfoCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["flow"] = tempOutNames; + outputTypes["sfftxt"] = tempOutNames; + outputTypes["qual"] = tempOutNames; + //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; } @@ -65,6 +122,17 @@ SffInfoCommand::SffInfoCommand(string option) { filenames[i] = tryPath; } } + + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getOutputDir() != "") { //default path is set + string tryPath = m->getOutputDir() + m->getSimpleName(filenames[i]); + m->mothurOut("Unable to open " + filenames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); + filenames[i] = tryPath; + } + } + in.close(); if (ableToOpen == 1) { @@ -105,6 +173,15 @@ SffInfoCommand::SffInfoCommand(string option) { accnosFileNames[i] = tryPath; } } + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getOutputDir() != "") { //default path is set + string tryPath = m->getOutputDir() + m->getSimpleName(accnosFileNames[i]); + m->mothurOut("Unable to open " + accnosFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); + accnosFileNames[i] = tryPath; + } + } in.close(); if (ableToOpen == 1) { @@ -227,10 +304,10 @@ int SffInfoCommand::extractSffInfo(string input, string accnos){ outQualFileName = outputDir + m->getRootName(m->getSimpleName(input)) + "raw.qual"; } - if (sfftxt) { m->openOutputFile(sfftxtFileName, outSfftxt); outSfftxt.setf(ios::fixed, ios::floatfield); outSfftxt.setf(ios::showpoint); outputNames.push_back(sfftxtFileName); } - if (fasta) { m->openOutputFile(outFastaFileName, outFasta); outputNames.push_back(outFastaFileName); } - if (qual) { m->openOutputFile(outQualFileName, outQual); outputNames.push_back(outQualFileName); } - if (flow) { m->openOutputFile(outFlowFileName, outFlow); outputNames.push_back(outFlowFileName); } + if (sfftxt) { m->openOutputFile(sfftxtFileName, outSfftxt); outSfftxt.setf(ios::fixed, ios::floatfield); outSfftxt.setf(ios::showpoint); outputNames.push_back(sfftxtFileName); outputTypes["sfftxt"].push_back(sfftxtFileName); } + if (fasta) { m->openOutputFile(outFastaFileName, outFasta); outputNames.push_back(outFastaFileName); outputTypes["fasta"].push_back(outFastaFileName); } + if (qual) { m->openOutputFile(outQualFileName, outQual); outputNames.push_back(outQualFileName); outputTypes["qual"].push_back(outQualFileName); } + if (flow) { m->openOutputFile(outFlowFileName, outFlow); outputNames.push_back(outFlowFileName); outputTypes["flow"].push_back(outFlowFileName); } ifstream in; in.open(input.c_str(), ios::binary); diff --git a/sffinfocommand.h b/sffinfocommand.h index 939a1c7..7cf357e 100644 --- a/sffinfocommand.h +++ b/sffinfocommand.h @@ -60,7 +60,12 @@ class SffInfoCommand : public Command { public: SffInfoCommand(string); + SffInfoCommand(); ~SffInfoCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -69,6 +74,7 @@ private: vector filenames, outputNames, accnosFileNames; bool abort, fasta, qual, trim, flow, sfftxt, hasAccnos; set seqNames; + map > outputTypes; int extractSffInfo(string, string); int readCommonHeader(ifstream&, CommonHeader&); diff --git a/sharedcommand.cpp b/sharedcommand.cpp index fb3691e..454bb05 100644 --- a/sharedcommand.cpp +++ b/sharedcommand.cpp @@ -14,17 +14,69 @@ inline bool compareSharedRabunds(SharedRAbundVector* left, SharedRAbundVector* r return (left->getGroup() < right->getGroup()); } //********************************************************************************************************************** +vector SharedCommand::getValidParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SharedCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +SharedCommand::SharedCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["rabund"] = tempOutNames; + outputTypes["shared"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "SharedCommand", "SharedCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector SharedCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SharedCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector SharedCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SharedCommand", "getRequiredFiles"); + exit(1); + } +} +//********************************************************************************************************************** SharedCommand::SharedCommand(string o) : outputDir(o) { try { globaldata = GlobalData::getInstance(); + //initialize outputTypes + vector tempOutNames; + outputTypes["rabund"] = tempOutNames; + outputTypes["shared"] = tempOutNames; + //getting output filename filename = globaldata->inputFileName; if (outputDir == "") { outputDir += m->hasPath(filename); } filename = outputDir + m->getRootName(m->getSimpleName(filename)); filename = filename + "shared"; + outputTypes["shared"].push_back(filename); m->openOutputFile(filename, out); pickedGroups = false; @@ -54,6 +106,7 @@ SharedCommand::SharedCommand(string o) : outputDir(o) { for (int i=0; i getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help() {} @@ -37,6 +42,7 @@ private: int readOrderFile(); bool isValidGroup(string, vector); int eliminateZeroOTUS(vector&); + map > outputTypes; GlobalData* globaldata; ReadOTUFile* read; diff --git a/splitabundcommand.cpp b/splitabundcommand.cpp index 1780963..6070091 100644 --- a/splitabundcommand.cpp +++ b/splitabundcommand.cpp @@ -9,6 +9,57 @@ #include "splitabundcommand.h" +//********************************************************************************************************************** +vector SplitAbundCommand::getValidParameters(){ + try { + string Array[] = {"name","group","list","label","accnos","groups","fasta","cutoff","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SplitAbundCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +SplitAbundCommand::SplitAbundCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["list"] = tempOutNames; + outputTypes["name"] = tempOutNames; + outputTypes["accnos"] = tempOutNames; + outputTypes["group"] = tempOutNames; + outputTypes["fasta"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "SplitAbundCommand", "SplitAbundCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector SplitAbundCommand::getRequiredParameters(){ + try { + string Array[] = {"fasta","list","name","or"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SplitAbundCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector SplitAbundCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SplitAbundCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** SplitAbundCommand::SplitAbundCommand(string option) { try { @@ -33,7 +84,15 @@ SplitAbundCommand::SplitAbundCommand(string option) { for (it = parameters.begin(); it != parameters.end(); it++) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } - + + //initialize outputTypes + vector tempOutNames; + outputTypes["list"] = tempOutNames; + outputTypes["name"] = tempOutNames; + outputTypes["accnos"] = tempOutNames; + outputTypes["group"] = tempOutNames; + outputTypes["fasta"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -186,6 +245,8 @@ int SplitAbundCommand::execute(){ outputNames.push_back((fileroot + "rare.list")); outputNames.push_back((fileroot + "abund.list")); + outputTypes["list"].push_back((fileroot + "rare.list")); + outputTypes["list"].push_back((fileroot + "abund.list")); }else{ for (int i=0; igetRootName(m->getSimpleName(namefile)) + "rare.names"; m->openOutputFile(rare, rout); - outputNames.push_back(rare); + outputNames.push_back(rare); outputTypes["name"].push_back(rare); string abund = outputDir + m->getRootName(m->getSimpleName(namefile)) + "abund.names"; m->openOutputFile(abund, aout); - outputNames.push_back(abund); + outputNames.push_back(abund); outputTypes["name"].push_back(abund); if (rareNames.size() != 0) { for (set::iterator itRare = rareNames.begin(); itRare != rareNames.end(); itRare++) { @@ -642,7 +705,7 @@ int SplitAbundCommand::writeNames() { //namefile for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { (*(filehandles[it3->first])).close(); - outputNames.push_back(fileroot + it3->first + ".names"); + outputNames.push_back(fileroot + it3->first + ".names"); outputTypes["name"].push_back(fileroot + it3->first + ".names"); delete it3->second; } } @@ -669,7 +732,7 @@ int SplitAbundCommand::writeAccnos(string tag) { string rare = outputDir + m->getRootName(m->getSimpleName(inputFile)) + tag + "rare.accnos"; m->openOutputFile(rare, rout); - outputNames.push_back(rare); + outputNames.push_back(rare); outputTypes["accnos"].push_back(rare); for (set::iterator itRare = rareNames.begin(); itRare != rareNames.end(); itRare++) { rout << (*itRare) << endl; @@ -678,7 +741,7 @@ int SplitAbundCommand::writeAccnos(string tag) { string abund = outputDir + m->getRootName(m->getSimpleName(inputFile)) + tag + "abund.accnos"; m->openOutputFile(abund, aout); - outputNames.push_back(abund); + outputNames.push_back(abund); outputTypes["accnos"].push_back(abund); for (set::iterator itAbund = abundNames.begin(); itAbund != abundNames.end(); itAbund++) { aout << (*itAbund) << endl; @@ -723,7 +786,7 @@ int SplitAbundCommand::writeAccnos(string tag) { //close files for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { (*(filehandles[it3->first])).close(); - outputNames.push_back(fileroot + tag + it3->first + ".accnos"); + outputNames.push_back(fileroot + tag + it3->first + ".accnos"); outputTypes["accnos"].push_back(fileroot + tag + it3->first + ".accnos"); delete it3->second; } } @@ -748,11 +811,11 @@ int SplitAbundCommand::parseGroup(string tag) { //namefile string rare = outputDir + m->getRootName(m->getSimpleName(groupfile)) + tag + "rare.groups"; m->openOutputFile(rare, rout); - outputNames.push_back(rare); + outputNames.push_back(rare); outputTypes["group"].push_back(rare); string abund = outputDir + m->getRootName(m->getSimpleName(groupfile)) + tag + "abund.groups"; m->openOutputFile(abund, aout); - outputNames.push_back(abund); + outputNames.push_back(abund); outputTypes["group"].push_back(abund); for (map::iterator itName = nameMap.begin(); itName != nameMap.end(); itName++) { vector names; @@ -817,7 +880,7 @@ int SplitAbundCommand::parseGroup(string tag) { //namefile for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { (*(filehandles[it3->first])).close(); - outputNames.push_back(fileroot + tag + it3->first + ".groups"); + outputNames.push_back(fileroot + tag + it3->first + ".groups"); outputTypes["group"].push_back(fileroot + tag + it3->first + ".groups"); delete it3->second; } } @@ -842,11 +905,11 @@ int SplitAbundCommand::parseFasta(string tag) { //namefile string rare = outputDir + m->getRootName(m->getSimpleName(fastafile)) + tag + "rare.fasta"; m->openOutputFile(rare, rout); - outputNames.push_back(rare); + outputNames.push_back(rare); outputTypes["fasta"].push_back(rare); string abund = outputDir + m->getRootName(m->getSimpleName(fastafile)) + tag + "abund.fasta"; m->openOutputFile(abund, aout); - outputNames.push_back(abund); + outputNames.push_back(abund); outputTypes["fasta"].push_back(abund); //open input file ifstream in; @@ -937,7 +1000,7 @@ int SplitAbundCommand::parseFasta(string tag) { //namefile for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { (*(filehandles[it3->first])).close(); - outputNames.push_back(fileroot + tag + it3->first + ".fasta"); + outputNames.push_back(fileroot + tag + it3->first + ".fasta"); outputTypes["fasta"].push_back(fileroot + tag + it3->first + ".fasta"); delete it3->second; } } diff --git a/splitabundcommand.h b/splitabundcommand.h index df5bd55..02d61f3 100644 --- a/splitabundcommand.h +++ b/splitabundcommand.h @@ -28,7 +28,12 @@ class SplitAbundCommand : public Command { public: SplitAbundCommand(string); + SplitAbundCommand(); ~SplitAbundCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -45,6 +50,7 @@ private: int createNameMap(ListVector*); vector outputNames; + map > outputTypes; ListVector* list; GroupMap* groupMap; InputData* input; diff --git a/splitgroupscommand.cpp b/splitgroupscommand.cpp index 6f8788a..4be7a0e 100644 --- a/splitgroupscommand.cpp +++ b/splitgroupscommand.cpp @@ -10,6 +10,54 @@ #include "splitgroupscommand.h" #include "sharedutilities.h" +//********************************************************************************************************************** +vector SplitGroupCommand::getValidParameters(){ + try { + string Array[] = {"name","group","groups","fasta","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SplitGroupCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector SplitGroupCommand::getRequiredParameters(){ + try { + string Array[] = {"fasta","group"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SplitGroupCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector SplitGroupCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SplitGroupCommand", "getRequiredFiles"); + exit(1); + } +} +//********************************************************************************************************************** +SplitGroupCommand::SplitGroupCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["name"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "SplitGroupCommand", "SplitGroupCommand"); + exit(1); + } +} //********************************************************************************************************************** SplitGroupCommand::SplitGroupCommand(string option) { try { @@ -33,7 +81,12 @@ SplitGroupCommand::SplitGroupCommand(string option) { for (it = parameters.begin(); it != parameters.end(); it++) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } - + + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["name"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -187,13 +240,13 @@ int SplitGroupCommand::splitFasta() { temp = new ofstream; filehandles[Groups[i]+"fasta"] = temp; m->openOutputFile(filerootFasta + Groups[i] + ".fasta", *(filehandles[Groups[i]+"fasta"])); - outputNames.push_back(filerootFasta + Groups[i] + ".fasta"); + outputNames.push_back(filerootFasta + Groups[i] + ".fasta"); outputTypes["fasta"].push_back(filerootFasta + Groups[i] + ".fasta"); if (namefile != "") { temp2 = new ofstream; filehandles[Groups[i]+"name"] = temp2; m->openOutputFile(filerootName + Groups[i] + ".names", *(filehandles[Groups[i]+"name"])); - outputNames.push_back(filerootName + Groups[i] + ".names"); + outputNames.push_back(filerootName + Groups[i] + ".names"); outputTypes["name"].push_back(filerootFasta + Groups[i] + ".names"); } } diff --git a/splitgroupscommand.h b/splitgroupscommand.h index f6e8760..c45c7ff 100644 --- a/splitgroupscommand.h +++ b/splitgroupscommand.h @@ -24,7 +24,12 @@ class SplitGroupCommand : public Command { public: SplitGroupCommand(string); + SplitGroupCommand(); ~SplitGroupCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -34,6 +39,7 @@ private: int splitFasta(); vector outputNames; + map > outputTypes; map > nameMap; map >::iterator itNames; GroupMap* groupMap; diff --git a/splitmatrix.cpp b/splitmatrix.cpp index b7a3b49..dcc5b50 100644 --- a/splitmatrix.cpp +++ b/splitmatrix.cpp @@ -24,12 +24,13 @@ SplitMatrix::SplitMatrix(string distfile, string name, string tax, float c, stri } /***********************************************************************/ -SplitMatrix::SplitMatrix(string ffile, string name, string tax, float c, string t, int p, string output){ +SplitMatrix::SplitMatrix(string ffile, string name, string tax, float c, float cu, string t, int p, string output){ m = MothurOut::getInstance(); fastafile = ffile; namefile = name; taxFile = tax; - cutoff = c; + cutoff = c; //tax level cutoff + distCutoff = cu; //for fasta method if you are creating distance matrix you need a cutoff for that method = t; processors = p; outputDir = output; @@ -181,7 +182,7 @@ int SplitMatrix::createDistanceFilesFromTax(map& seqGroup, int numG //process each distance file for (int i = 0; i < numGroups; i++) { - string options = "fasta=" + (fastafile + "." + toString(i) + ".temp") + ", processors=" + toString(processors) + ", cutoff=" + toString(cutoff); + string options = "fasta=" + (fastafile + "." + toString(i) + ".temp") + ", processors=" + toString(processors) + ", cutoff=" + toString(distCutoff); Command* command = new DistanceCommand(options); command->execute(); diff --git a/splitmatrix.h b/splitmatrix.h index acaa8c5..4ff3160 100644 --- a/splitmatrix.h +++ b/splitmatrix.h @@ -20,7 +20,7 @@ class SplitMatrix { public: SplitMatrix(string, string, string, float, string, bool); //column formatted distance file, namesfile, cutoff, method, large - SplitMatrix(string, string, string, float, string, int, string); //fastafile, namefile, taxFile, cutoff, method, processors, outputDir + SplitMatrix(string, string, string, float, float, string, int, string); //fastafile, namefile, taxFile, taxcutoff, cutoff, method, processors, outputDir ~SplitMatrix(); int split(); @@ -32,7 +32,7 @@ class SplitMatrix { string distFile, namefile, singleton, method, taxFile, fastafile, outputDir; vector< map< string, string> > dists; - float cutoff; + float cutoff, distCutoff; bool large; int processors; diff --git a/summarycommand.cpp b/summarycommand.cpp index 6381195..1725815 100644 --- a/summarycommand.cpp +++ b/summarycommand.cpp @@ -34,6 +34,53 @@ #include "solow.h" #include "shen.h" +//********************************************************************************************************************** +vector SummaryCommand::getValidParameters(){ + try { + string Array[] = {"label","calc","abund","size","outputdir","groupmode","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SummaryCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +SummaryCommand::SummaryCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["summary"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "SummaryCommand", "SummaryCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector SummaryCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SummaryCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector SummaryCommand::getRequiredFiles(){ + try { + string AlignArray[] = {"shared","list","rabund","sabund","or"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SummaryCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** SummaryCommand::SummaryCommand(string option) { @@ -62,6 +109,10 @@ SummaryCommand::SummaryCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["summary"] = tempOutNames; + //make sure the user has already run the read.otu command if ((globaldata->getSharedFile() == "") && (globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { m->mothurOut("You must read a list, sabund, rabund or shared file before you can use the summary.single command."); m->mothurOutEndLine(); abort = true; } @@ -144,8 +195,6 @@ int SummaryCommand::execute(){ if (abort == true) { return 0; } - vector outputNames; - string hadShared = ""; if ((globaldata->getFormat() != "sharedfile")) { inputFileNames.push_back(globaldata->inputFileName); } else { hadShared = globaldata->getSharedFile(); inputFileNames = parseSharedFile(globaldata->getSharedFile()); globaldata->setFormat("rabund"); } @@ -162,7 +211,7 @@ int SummaryCommand::execute(){ string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p])) + "summary"; globaldata->inputFileName = inputFileNames[p]; - outputNames.push_back(fileNameRoot); + outputNames.push_back(fileNameRoot); outputTypes["summary"].push_back(fileNameRoot); if (inputFileNames.size() > 1) { m->mothurOutEndLine(); m->mothurOut("Processing group " + groups[p]); m->mothurOutEndLine(); m->mothurOutEndLine(); diff --git a/summarycommand.h b/summarycommand.h index 7c7ee2c..d225109 100644 --- a/summarycommand.h +++ b/summarycommand.h @@ -22,7 +22,12 @@ class SummaryCommand : public Command { public: SummaryCommand(string); + SummaryCommand(); ~SummaryCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -39,7 +44,8 @@ private: set labels; //holds labels to be used string label, calc, outputDir; vector Estimators; - vector inputFileNames; + vector inputFileNames, outputNames; + map > outputTypes; vector groups; vector parseSharedFile(string); diff --git a/summarysharedcommand.cpp b/summarysharedcommand.cpp index 3069a6f..99c62a5 100644 --- a/summarysharedcommand.cpp +++ b/summarysharedcommand.cpp @@ -32,7 +32,53 @@ #include "sharedjackknife.h" #include "whittaker.h" - +//********************************************************************************************************************** +vector SummarySharedCommand::getValidParameters(){ + try { + string Array[] = {"label","calc","groups","all","outputdir","distance","inputdir", "processors"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SummarySharedCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +SummarySharedCommand::SummarySharedCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["summary"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "SummarySharedCommand", "SummarySharedCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector SummarySharedCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SummarySharedCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector SummarySharedCommand::getRequiredFiles(){ + try { + string Array[] = {"shared"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SummarySharedCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** SummarySharedCommand::SummarySharedCommand(string option) { @@ -66,6 +112,10 @@ SummarySharedCommand::SummarySharedCommand(string option) { m->mothurOut("You must read a list and a group, or a shared before you can use the summary.shared command."); m->mothurOutEndLine(); abort = true; } + //initialize outputTypes + vector tempOutNames; + outputTypes["summary"] = tempOutNames; + //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; @@ -398,8 +448,8 @@ int SummarySharedCommand::execute(){ m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); m->mothurOut(outputFileName); m->mothurOutEndLine(); - if (mult) { m->mothurOut(outAllFileName); m->mothurOutEndLine(); } - for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); } + if (mult) { m->mothurOut(outAllFileName); m->mothurOutEndLine(); outputTypes["summary"].push_back(outAllFileName); } + for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); } outputTypes["summary"].push_back(outputFileName); m->mothurOutEndLine(); return 0; diff --git a/summarysharedcommand.h b/summarysharedcommand.h index c017264..0771812 100644 --- a/summarysharedcommand.h +++ b/summarysharedcommand.h @@ -23,7 +23,12 @@ class SummarySharedCommand : public Command { public: SummarySharedCommand(string); + SummarySharedCommand(); ~SummarySharedCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -43,6 +48,7 @@ private: set labels; //holds labels to be used string label, calc, groups; vector Estimators, Groups, outputNames; + map > outputTypes; vector lookup; string format, outputDir; int numGroups, processors; diff --git a/systemcommand.cpp b/systemcommand.cpp index 708724a..fb250d7 100644 --- a/systemcommand.cpp +++ b/systemcommand.cpp @@ -9,6 +9,39 @@ #include "systemcommand.h" +//********************************************************************************************************************** +vector SystemCommand::getValidParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SystemCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector SystemCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SystemCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector SystemCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SystemCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** SystemCommand::SystemCommand(string option) { diff --git a/systemcommand.h b/systemcommand.h index 410a12e..3b48642 100644 --- a/systemcommand.h +++ b/systemcommand.h @@ -18,13 +18,20 @@ class SystemCommand : public Command { public: SystemCommand(string); - ~SystemCommand(){}; + SystemCommand() {} + ~SystemCommand(){} + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); private: string command; bool abort; + vector outputNames; + map > outputTypes; }; diff --git a/treegroupscommand.cpp b/treegroupscommand.cpp index 3403b99..a36e599 100644 --- a/treegroupscommand.cpp +++ b/treegroupscommand.cpp @@ -19,7 +19,53 @@ #include "sharedmorisitahorn.h" #include "sharedbraycurtis.h" - +//********************************************************************************************************************** +vector TreeGroupCommand::getValidParameters(){ + try { + string Array[] = {"label","calc","groups", "phylip", "column", "name", "precision","cutoff","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "TreeGroupCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +TreeGroupCommand::TreeGroupCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["tree"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "TreeGroupCommand", "TreeGroupCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector TreeGroupCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "TreeGroupCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector TreeGroupCommand::getRequiredFiles(){ + try { + string Array[] = {"phylip","column","shared","or"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "TreeGroupCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** TreeGroupCommand::TreeGroupCommand(string option) { @@ -50,6 +96,10 @@ TreeGroupCommand::TreeGroupCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["tree"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -324,7 +374,7 @@ int TreeGroupCommand::execute(){ //create a new filename outputFile = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + "tre"; - outputNames.push_back(outputFile); + outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile); createTree(); @@ -595,7 +645,7 @@ int TreeGroupCommand::process(vector thisLookup) { //create a new filename outputFile = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".tre"; - outputNames.push_back(outputFile); + outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile); for (int k = 0; k < thisLookup.size(); k++) { for (int l = k; l < thisLookup.size(); l++) { diff --git a/treegroupscommand.h b/treegroupscommand.h index 3e8fbb0..c61c9fb 100644 --- a/treegroupscommand.h +++ b/treegroupscommand.h @@ -35,7 +35,12 @@ class TreeGroupCommand : public Command { public: TreeGroupCommand(string); + TreeGroupCommand(); ~TreeGroupCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -64,6 +69,7 @@ private: int numGroups; ofstream out; float precision, cutoff; + map > outputTypes; bool abort, allLines; set labels; //holds labels to be used diff --git a/trimseqscommand.cpp b/trimseqscommand.cpp index 1d70fb1..1f8dc57 100644 --- a/trimseqscommand.cpp +++ b/trimseqscommand.cpp @@ -10,6 +10,56 @@ #include "trimseqscommand.h" #include "needlemanoverlap.hpp" +//********************************************************************************************************************** +vector TrimSeqsCommand::getValidParameters(){ + try { + string Array[] = {"fasta", "flip", "oligos", "maxambig", "maxhomop", "minlength", "maxlength", "qfile", + "qthreshold", "qwindowaverage", "qstepsize", "qwindowsize", "qaverage", "rollaverage", "allfiles", "qtrim","tdiffs", "pdiffs", "bdiffs", "processors", "outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "TrimSeqsCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +TrimSeqsCommand::TrimSeqsCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["qual"] = tempOutNames; + outputTypes["group"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "TrimSeqsCommand", "TrimSeqsCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector TrimSeqsCommand::getRequiredParameters(){ + try { + string Array[] = {"fasta"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "TrimSeqsCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector TrimSeqsCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "TrimSeqsCommand", "getRequiredFiles"); + exit(1); + } +} //*************************************************************************************************************** TrimSeqsCommand::TrimSeqsCommand(string option) { @@ -39,6 +89,12 @@ TrimSeqsCommand::TrimSeqsCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["qual"] = tempOutNames; + outputTypes["group"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -72,7 +128,7 @@ TrimSeqsCommand::TrimSeqsCommand(string option) { //check for required parameters fastaFile = validParameter.validFile(parameters, "fasta", true); - if (fastaFile == "not found") { m->mothurOut("fasta is a required parameter for the screen.seqs command."); m->mothurOutEndLine(); abort = true; } + if (fastaFile == "not found") { m->mothurOut("fasta is a required parameter for the trim.seqs command."); m->mothurOutEndLine(); abort = true; } else if (fastaFile == "not open") { abort = true; } //if the user changes the output directory command factory will send this info to us in the output parameter @@ -220,18 +276,18 @@ int TrimSeqsCommand::execute(){ numRPrimers = 0; string trimSeqFile = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + "trim.fasta"; - outputNames.push_back(trimSeqFile); + outputNames.push_back(trimSeqFile); outputTypes["fasta"].push_back(trimSeqFile); string scrapSeqFile = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + "scrap.fasta"; - outputNames.push_back(scrapSeqFile); + outputNames.push_back(scrapSeqFile); outputTypes["fasta"].push_back(scrapSeqFile); string trimQualFile = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + "trim.qual"; string scrapQualFile = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + "scrap.qual"; - if (qFileName != "") { outputNames.push_back(trimQualFile); outputNames.push_back(scrapQualFile); } + if (qFileName != "") { outputNames.push_back(trimQualFile); outputNames.push_back(scrapQualFile); outputTypes["qual"].push_back(trimQualFile); outputTypes["qual"].push_back(scrapQualFile); } string groupFile = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + "groups"; vector fastaFileNames; vector qualFileNames; if(oligoFile != ""){ - outputNames.push_back(groupFile); + outputNames.push_back(groupFile); outputTypes["group"].push_back(groupFile); getOligos(fastaFileNames, qualFileNames); } @@ -339,7 +395,7 @@ int TrimSeqsCommand::execute(){ ofstream outGroups; string outGroupFilename = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[i])) + "groups"; m->openOutputFile(outGroupFilename, outGroups); - outputNames.push_back(outGroupFilename); + outputNames.push_back(outGroupFilename); outputTypes["group"].push_back(outGroupFilename); string thisGroup = ""; if (i > comboStarts) { @@ -791,8 +847,10 @@ void TrimSeqsCommand::getOligos(vector& outFASTAVec, vector& out } }else { outputNames.push_back((outputDir + m->getRootName(m->getSimpleName(fastaFile)) + group + ".fasta")); + outputTypes["fasta"].push_back((outputDir + m->getRootName(m->getSimpleName(fastaFile)) + group + ".fasta")); if(qFileName != ""){ outputNames.push_back((outputDir + m->getRootName(m->getSimpleName(qFileName)) + group + ".qual")); + outputTypes["qual"].push_back((outputDir + m->getRootName(m->getSimpleName(qFileName)) + group + ".qual")); } } } @@ -814,11 +872,13 @@ void TrimSeqsCommand::getOligos(vector& outFASTAVec, vector& out groupVector.push_back(group); if(allFiles){ + outputNames.push_back((outputDir + m->getRootName(m->getSimpleName(fastaFile)) + group + ".fasta")); outputNames.push_back((outputDir + m->getRootName(m->getSimpleName(fastaFile)) + group + ".fasta")); outFASTAVec.push_back((outputDir + m->getRootName(m->getSimpleName(fastaFile)) + group + ".fasta")); if(qFileName != ""){ outQualVec.push_back((outputDir + m->getRootName(m->getSimpleName(qFileName)) + group + ".qual")); outputNames.push_back((outputDir + m->getRootName(m->getSimpleName(qFileName)) + group + ".qual")); + outputTypes["qual"].push_back((outputDir + m->getRootName(m->getSimpleName(qFileName)) + group + ".qual")); } } }else{ m->mothurOut(type + " is not recognized as a valid type. Choices are forward, reverse, and barcode. Ignoring " + oligo + "."); m->mothurOutEndLine(); } @@ -835,12 +895,14 @@ void TrimSeqsCommand::getOligos(vector& outFASTAVec, vector& out for (map::iterator itPrime = primers.begin(); itPrime != primers.end(); itPrime++) { if (groupVector[itPrime->second] != "") { //there is a group for this primer outputNames.push_back((outputDir + m->getRootName(m->getSimpleName(qFileName)) + groupVector[itBar->second] + "." + groupVector[itPrime->second] + ".fasta")); + outputTypes["fasta"].push_back((outputDir + m->getRootName(m->getSimpleName(qFileName)) + groupVector[itBar->second] + "." + groupVector[itPrime->second] + ".fasta")); outFASTAVec.push_back((outputDir + m->getRootName(m->getSimpleName(fastaFile)) + groupVector[itBar->second] + "." + groupVector[itPrime->second] + ".fasta")); combos[(groupVector[itBar->second] + "." + groupVector[itPrime->second])] = outFASTAVec.size()-1; if(qFileName != ""){ outQualVec.push_back((outputDir + m->getRootName(m->getSimpleName(qFileName)) + groupVector[itBar->second] + "." + groupVector[itPrime->second] + ".qual")); outputNames.push_back((outputDir + m->getRootName(m->getSimpleName(qFileName)) + groupVector[itBar->second] + "." + groupVector[itPrime->second] + ".qual")); + outputTypes["qual"].push_back((outputDir + m->getRootName(m->getSimpleName(qFileName)) + groupVector[itBar->second] + "." + groupVector[itPrime->second] + ".qual")); } } } diff --git a/trimseqscommand.h b/trimseqscommand.h index 93e8c77..20b11a8 100644 --- a/trimseqscommand.h +++ b/trimseqscommand.h @@ -18,7 +18,12 @@ class TrimSeqsCommand : public Command { public: TrimSeqsCommand(string); + TrimSeqsCommand(); ~TrimSeqsCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -39,6 +44,7 @@ private: bool cullAmbigs(Sequence&); bool compareDNASeq(string, string); int countDiffs(string, string); + map > outputTypes; bool abort; string fastaFile, oligoFile, qFileName, outputDir; diff --git a/unifracunweightedcommand.cpp b/unifracunweightedcommand.cpp index 88df73d..b2d439b 100644 --- a/unifracunweightedcommand.cpp +++ b/unifracunweightedcommand.cpp @@ -9,6 +9,56 @@ #include "unifracunweightedcommand.h" +//********************************************************************************************************************** +vector UnifracUnweightedCommand::getValidParameters(){ + try { + string Array[] = {"groups","iters","distance","random", "processors","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "UnifracUnweightedCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +UnifracUnweightedCommand::UnifracUnweightedCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["unweighted"] = tempOutNames; + outputTypes["uwsummary"] = tempOutNames; + outputTypes["phylip"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "UnifracUnweightedCommand", "UnifracUnweightedCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector UnifracUnweightedCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "UnifracUnweightedCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector UnifracUnweightedCommand::getRequiredFiles(){ + try { + string Array[] = {"tree","group"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + + return myArray; + } + catch(exception& e) { + m->errorOut(e, "UnifracUnweightedCommand", "getRequiredFiles"); + exit(1); + } +} /***********************************************************/ UnifracUnweightedCommand::UnifracUnweightedCommand(string option) { try { @@ -34,6 +84,12 @@ UnifracUnweightedCommand::UnifracUnweightedCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["unweighted"] = tempOutNames; + outputTypes["uwsummary"] = tempOutNames; + outputTypes["phylip"] = tempOutNames; + if (globaldata->gTree.size() == 0) {//no trees were read m->mothurOut("You must execute the read.tree command, before you may execute the unifrac.unweighted command."); m->mothurOutEndLine(); abort = true; } @@ -77,7 +133,7 @@ UnifracUnweightedCommand::UnifracUnweightedCommand(string option) { T = globaldata->gTree; tmap = globaldata->gTreemap; sumFile = outputDir + m->getSimpleName(globaldata->getTreeFile()) + ".uwsummary"; - outputNames.push_back(sumFile); + outputNames.push_back(sumFile); outputTypes["uwsummary"].push_back(sumFile); m->openOutputFile(sumFile, outSum); util = new SharedUtil(); @@ -151,6 +207,7 @@ int UnifracUnweightedCommand::execute() { if (random) { output = new ColumnFile(outputDir + m->getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".unweighted", itersString); outputNames.push_back(outputDir + m->getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".unweighted"); + outputTypes["unweighted"].push_back(outputDir + m->getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".unweighted"); } @@ -316,7 +373,7 @@ void UnifracUnweightedCommand::printUWSummaryFile(int i) { void UnifracUnweightedCommand::createPhylipFile(int i) { try { string phylipFileName = outputDir + m->getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".unweighted.dist"; - outputNames.push_back(phylipFileName); + outputNames.push_back(phylipFileName); outputTypes["phylip"].push_back(phylipFileName); ofstream out; m->openOutputFile(phylipFileName, out); diff --git a/unifracunweightedcommand.h b/unifracunweightedcommand.h index 3e6d835..91f005c 100644 --- a/unifracunweightedcommand.h +++ b/unifracunweightedcommand.h @@ -23,7 +23,12 @@ class UnifracUnweightedCommand : public Command { public: UnifracUnweightedCommand(string); + UnifracUnweightedCommand(); ~UnifracUnweightedCommand() { globaldata->Groups.clear(); if (abort == false) { delete unweighted; delete util; } } + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -48,6 +53,7 @@ class UnifracUnweightedCommand : public Command { bool abort, phylip, random; string groups, itersString, outputDir; vector Groups, outputNames; //holds groups to be used + map > outputTypes; ofstream outSum, out; ifstream inFile; diff --git a/unifracweightedcommand.cpp b/unifracweightedcommand.cpp index e8add90..9f961a9 100644 --- a/unifracweightedcommand.cpp +++ b/unifracweightedcommand.cpp @@ -9,6 +9,56 @@ #include "unifracweightedcommand.h" +//********************************************************************************************************************** +vector UnifracWeightedCommand::getValidParameters(){ + try { + string Array[] = {"groups","iters","distance","random","processors","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "UnifracWeightedCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +UnifracWeightedCommand::UnifracWeightedCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["weighted"] = tempOutNames; + outputTypes["wsummary"] = tempOutNames; + outputTypes["phylip"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "UnifracWeightedCommand", "UnifracWeightedCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector UnifracWeightedCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "UnifracWeightedCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector UnifracWeightedCommand::getRequiredFiles(){ + try { + string Array[] = {"tree","group"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + + return myArray; + } + catch(exception& e) { + m->errorOut(e, "UnifracWeightedCommand", "getRequiredFiles"); + exit(1); + } +} /***********************************************************/ UnifracWeightedCommand::UnifracWeightedCommand(string option) { try { @@ -34,6 +84,12 @@ UnifracWeightedCommand::UnifracWeightedCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["weighted"] = tempOutNames; + outputTypes["wsummary"] = tempOutNames; + outputTypes["phylip"] = tempOutNames; + if (globaldata->gTree.size() == 0) {//no trees were read m->mothurOut("You must execute the read.tree command, before you may execute the unifrac.weighted command."); m->mothurOutEndLine(); abort = true; } @@ -72,7 +128,7 @@ UnifracWeightedCommand::UnifracWeightedCommand(string option) { tmap = globaldata->gTreemap; sumFile = outputDir + m->getSimpleName(globaldata->getTreeFile()) + ".wsummary"; m->openOutputFile(sumFile, outSum); - outputNames.push_back(sumFile); + outputNames.push_back(sumFile); outputTypes["wsummary"].push_back(sumFile); util = new SharedUtil(); string s; //to make work with setgroups @@ -138,6 +194,7 @@ int UnifracWeightedCommand::execute() { if (random) { output = new ColumnFile(outputDir + m->getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".weighted", itersString); outputNames.push_back(outputDir + m->getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".weighted"); + outputTypes["weighted"].push_back(outputDir + m->getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".weighted"); } userData = weighted->getValues(T[i], processors, outputDir); //userData[0] = weightedscore @@ -438,6 +495,7 @@ void UnifracWeightedCommand::createPhylipFile() { string phylipFileName = outputDir + m->getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".weighted.dist"; outputNames.push_back(phylipFileName); + outputTypes["phylip"].push_back(phylipFileName); ofstream out; m->openOutputFile(phylipFileName, out); diff --git a/unifracweightedcommand.h b/unifracweightedcommand.h index 7317c8a..fa87d8f 100644 --- a/unifracweightedcommand.h +++ b/unifracweightedcommand.h @@ -24,7 +24,12 @@ class UnifracWeightedCommand : public Command { public: UnifracWeightedCommand(string); + UnifracWeightedCommand(); ~UnifracWeightedCommand() { if (abort == false) { delete weighted; delete util; } } + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -58,6 +63,7 @@ class UnifracWeightedCommand : public Command { bool abort, phylip, random; string groups, itersString; vector Groups, outputNames; //holds groups to be used + map > outputTypes; int processors; diff --git a/unweighted.cpp b/unweighted.cpp index 2afc4a7..da6ad2c 100644 --- a/unweighted.cpp +++ b/unweighted.cpp @@ -170,10 +170,12 @@ EstOutput Unweighted::driver(Tree* t, vector< vector > namesOfGroupCombo EstOutput results; results.resize(num); int count = 0; + int numLeaves = t->getNumLeaves(); int total = num; int twentyPercent = (total * 0.20); if (twentyPercent == 0) { twentyPercent = 1; } + for (int h = start; h < (start+num); h++) { if (m->control_pressed) { return results; } @@ -181,6 +183,9 @@ EstOutput Unweighted::driver(Tree* t, vector< vector > namesOfGroupCombo double UniqueBL=0.0000; //a branch length is unique if it's chidren are from the same group double totalBL = 0.00; //all branch lengths double UW = 0.00; //Unweighted Value = UniqueBL / totalBL; + map tempTotals; //maps node to total Branch Length + map nodePcountSize; //maps node to pcountSize + map::iterator itCount; for(int i=0;igetNumNodes();i++){ @@ -195,15 +200,38 @@ EstOutput Unweighted::driver(Tree* t, vector< vector > namesOfGroupCombo map::iterator itGroup = t->tree[i].pcount.find(namesOfGroupCombos[h][j]); if (itGroup != t->tree[i].pcount.end()) { pcountSize++; if (pcountSize > 1) { break; } } } + + nodePcountSize[i] = pcountSize; - if (pcountSize == 0) { } - else if ((t->tree[i].getBranchLength() != -1) && (pcountSize == 1)) { UniqueBL += abs(t->tree[i].getBranchLength()); } + if (pcountSize == 0) { ; } + else if ((t->tree[i].getBranchLength() != -1) && (pcountSize == 1)) { UniqueBL += abs(t->tree[i].getBranchLength()); } + + //if you are a leaf from a users group add to total + if (i < numLeaves) { + if ((t->tree[i].getBranchLength() != -1) && pcountSize != 0) { + totalBL += abs(t->tree[i].getBranchLength()); + } + tempTotals[i] = 0.0; //we don't care about you, or we have already added you + }else{ //if you are not a leaf + //do both your chidren have have descendants from the users groups? + int lc = t->tree[i].getLChild(); + int rc = t->tree[i].getRChild(); - if ((t->tree[i].getBranchLength() != -1) && (pcountSize != 0)) { - totalBL += abs(t->tree[i].getBranchLength()); + //if yes, add to total your childrens branchLengths and your childrens tempTotals + if ((nodePcountSize[lc] != 0) && (nodePcountSize[rc] != 0)) { + totalBL += tempTotals[lc] + tempTotals[rc]; + if (t->tree[i].getBranchLength() != -1) { + tempTotals[i] = abs(t->tree[i].getBranchLength()); + }else { + tempTotals[i] = 0.0; + } + //tempTotals[i] = tempTotals[lc] + tempTotals[rc]; + }else { //if no, your tempTotal is your childrens temp totals + tempTotals[i] = tempTotals[lc] + tempTotals[rc] + abs(t->tree[i].getBranchLength()); + } } } - + UW = (UniqueBL / totalBL); if (isnan(UW) || isinf(UW)) { UW = 0; } @@ -384,6 +412,7 @@ EstOutput Unweighted::driver(Tree* t, vector< vector > namesOfGroupCombo int count = 0; int total = num; int twentyPercent = (total * 0.20); + int numLeaves = t->getNumLeaves(); Tree* copyTree = new Tree; @@ -400,6 +429,8 @@ EstOutput Unweighted::driver(Tree* t, vector< vector > namesOfGroupCombo double UniqueBL=0.0000; //a branch length is unique if it's chidren are from the same group double totalBL = 0.00; //all branch lengths double UW = 0.00; //Unweighted Value = UniqueBL / totalBL; + map tempTotals; //maps node to total Branch Length + map nodePcountSize; //maps node to pcountSize for(int i=0;igetNumNodes();i++){ @@ -415,12 +446,36 @@ EstOutput Unweighted::driver(Tree* t, vector< vector > namesOfGroupCombo if (itGroup != copyTree->tree[i].pcount.end()) { pcountSize++; if (pcountSize > 1) { break; } } } + nodePcountSize[i] = pcountSize; + if (pcountSize == 0) { } else if ((copyTree->tree[i].getBranchLength() != -1) && (pcountSize == 1)) { UniqueBL += abs(copyTree->tree[i].getBranchLength()); } + + //if you are a leaf from a users group add to total + if (i < numLeaves) { + if ((copyTree->tree[i].getBranchLength() != -1) && pcountSize != 0) { + totalBL += abs(copyTree->tree[i].getBranchLength()); + } + tempTotals[i] = 0.0; //we don't care about you, or we have already added you + }else{ //if you are not a leaf + //do both your chidren have have descendants from the users groups? + int lc = copyTree->tree[i].getLChild(); + int rc = copyTree->tree[i].getRChild(); - if ((copyTree->tree[i].getBranchLength() != -1) && (pcountSize != 0)) { - totalBL += abs(copyTree->tree[i].getBranchLength()); + //if yes, add to total your childrens branchLengths and your childrens tempTotals + if ((nodePcountSize[lc] != 0) && (nodePcountSize[rc] != 0)) { + totalBL += tempTotals[lc] + tempTotals[rc]; + if (copyTree->tree[i].getBranchLength() != -1) { + tempTotals[i] = abs(copyTree->tree[i].getBranchLength()); + }else { + tempTotals[i] = 0.0; + } + //tempTotals[i] = tempTotals[lc] + tempTotals[rc]; + }else { //if no, your tempTotal is your childrens temp totals + tempTotals[i] = tempTotals[lc] + tempTotals[rc] + abs(copyTree->tree[i].getBranchLength()); + } } + } UW = (UniqueBL / totalBL); diff --git a/validparameter.cpp b/validparameter.cpp index 50cd4e3..cfe9d50 100644 --- a/validparameter.cpp +++ b/validparameter.cpp @@ -245,6 +245,16 @@ string ValidParameters::validFile(map& container, string paramet } } + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getOutputDir() != "") { //default path is set + string tryPath = m->getOutputDir() + m->getSimpleName(it->second); + m->mothurOut("Unable to open " + it->second + ". Trying output directory " + tryPath); m->mothurOutEndLine(); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); + container[parameter] = tryPath; + } + } + in.close(); #ifdef USE_MPI diff --git a/venncommand.cpp b/venncommand.cpp index 852ee8c..ab4f7a2 100644 --- a/venncommand.cpp +++ b/venncommand.cpp @@ -18,6 +18,53 @@ #include "nseqs.h" +//********************************************************************************************************************** +vector VennCommand::getValidParameters(){ + try { + string Array[] = {"groups","label","calc","permute", "abund","nseqs","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "VennCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +VennCommand::VennCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["svg"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "VennCommand", "VennCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector VennCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "VennCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector VennCommand::getRequiredFiles(){ + try { + string Array[] = {"list","shared","or"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "VennCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** VennCommand::VennCommand(string option) { @@ -198,7 +245,6 @@ int VennCommand::execute(){ if (abort == true) { return 0; } string lastLabel; - vector outputNames; if (format == "sharedfile") { //you have groups @@ -247,7 +293,7 @@ int VennCommand::execute(){ for (int i = lookup.size(); i > 4; i--) { lookup.pop_back(); } //no memmory leak because pop_back calls destructor vector outfilenames = venn->getPic(lookup, vennCalculators); - for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); } } + for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]); } } }else if ((lookup.size() > 4) && (perm)) { set< set >::iterator it3; @@ -259,11 +305,11 @@ int VennCommand::execute(){ for (it2 = poss.begin(); it2 != poss.end(); it2++) { subset.push_back(lookup[*it2]); } vector outfilenames = venn->getPic(subset, vennCalculators); - for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); } } + for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]); } } } }else { vector outfilenames = venn->getPic(lookup, vennCalculators); - for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); } } + for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]); } } } } @@ -282,7 +328,7 @@ int VennCommand::execute(){ for (int i = lookup.size(); i > 4; i--) { lookup.pop_back(); } //no memmory leak because pop_back calls destructor vector outfilenames = venn->getPic(lookup, vennCalculators); - for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); } } + for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]); } } }else if ((lookup.size() > 4) && (perm)) { set< set >::iterator it3; @@ -294,11 +340,11 @@ int VennCommand::execute(){ for (it2 = poss.begin(); it2 != poss.end(); it2++) { subset.push_back(lookup[*it2]); } vector outfilenames = venn->getPic(subset, vennCalculators); - for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); } } + for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]); } } } }else { vector outfilenames = venn->getPic(lookup, vennCalculators); - for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); } } + for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]); } } } //restore real lastlabel to save below @@ -348,7 +394,7 @@ int VennCommand::execute(){ for (int i = lookup.size(); i > 4; i--) { lookup.pop_back(); } //no memmory leak because pop_back calls destructor vector outfilenames = venn->getPic(lookup, vennCalculators); - for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); } } + for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]); } } }else if ((lookup.size() > 4) && (perm)) { set< set >::iterator it3; @@ -360,11 +406,11 @@ int VennCommand::execute(){ for (it2 = poss.begin(); it2 != poss.end(); it2++) { subset.push_back(lookup[*it2]); } vector outfilenames = venn->getPic(subset, vennCalculators); - for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); } } + for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]); } } } }else { vector outfilenames = venn->getPic(lookup, vennCalculators); - for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); } } + for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]); } } } for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } @@ -396,7 +442,7 @@ int VennCommand::execute(){ m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); vector outfilenames = venn->getPic(sabund, vennCalculators); - for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); } } + for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]); } } processedLabels.insert(sabund->getLabel()); @@ -411,7 +457,7 @@ int VennCommand::execute(){ m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); vector outfilenames = venn->getPic(sabund, vennCalculators); - for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); } } + for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]); } } processedLabels.insert(sabund->getLabel()); @@ -453,7 +499,7 @@ int VennCommand::execute(){ m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); vector outfilenames = venn->getPic(sabund, vennCalculators); - for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); } } + for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]); } } delete sabund; diff --git a/venncommand.h b/venncommand.h index f6bdf39..29beead 100644 --- a/venncommand.h +++ b/venncommand.h @@ -24,7 +24,12 @@ class VennCommand : public Command { public: VennCommand(string); + VennCommand(); ~VennCommand(); + vector getRequiredParameters(); + vector getValidParameters(); + vector getRequiredFiles(); + map > getOutputFiles() { return outputTypes; } int execute(); void help(); @@ -44,7 +49,8 @@ private: bool abort, allLines, nseqs, perm; set labels; //holds labels to be used string format, groups, calc, label, outputDir; - vector Estimators, Groups; + vector Estimators, Groups, outputNames; + map > outputTypes; set< set > findCombinations(int); int getCombos(set, set< set >&);