From 986663e2220f6b043ee83d1699cfa081dc49cbed Mon Sep 17 00:00:00 2001 From: pschloss Date: Sat, 6 Jun 2009 10:35:06 +0000 Subject: [PATCH] added reverse.seqs command --- Mothur.xcodeproj/project.pbxproj | 6 +++ commandfactory.cpp | 3 +- filterseqscommand.cpp | 1 - reversecommand.cpp | 69 ++++++++++++++++++++++++++++++++ reversecommand.h | 28 +++++++++++++ screenseqscommand.cpp | 10 ++++- validcommands.cpp | 1 + validparameter.cpp | 3 ++ 8 files changed, 117 insertions(+), 4 deletions(-) create mode 100644 reversecommand.cpp create mode 100644 reversecommand.h diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj index 8d362b6..bed134c 100644 --- a/Mothur.xcodeproj/project.pbxproj +++ b/Mothur.xcodeproj/project.pbxproj @@ -142,6 +142,7 @@ 37D9289F0F21331F001D4494 /* validparameter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928530F21331F001D4494 /* validparameter.cpp */; }; 37E5F3E30F29FD4200F8D827 /* treenode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37E5F3E20F29FD4200F8D827 /* treenode.cpp */; }; 37E5F4920F2A3DA800F8D827 /* readtreecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37E5F4910F2A3DA800F8D827 /* readtreecommand.cpp */; }; + 7E09C5140FDA79C5002ECAE5 /* reversecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7E09C5130FDA79C5002ECAE5 /* reversecommand.cpp */; }; 7E412F490F8D21B600381DD0 /* slibshuff.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7E412F480F8D21B600381DD0 /* slibshuff.cpp */; }; 7E412FEA0F8D3E2C00381DD0 /* libshuff.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7E412FE90F8D3E2C00381DD0 /* libshuff.cpp */; }; 7E4130F80F8E58FA00381DD0 /* dlibshuff.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7E4130F60F8E58FA00381DD0 /* dlibshuff.cpp */; }; @@ -461,6 +462,8 @@ 37E5F3E20F29FD4200F8D827 /* treenode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = treenode.cpp; sourceTree = SOURCE_ROOT; }; 37E5F4900F2A3DA800F8D827 /* readtreecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readtreecommand.h; sourceTree = SOURCE_ROOT; }; 37E5F4910F2A3DA800F8D827 /* readtreecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readtreecommand.cpp; sourceTree = SOURCE_ROOT; }; + 7E09C5120FDA79C5002ECAE5 /* reversecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = reversecommand.h; sourceTree = ""; }; + 7E09C5130FDA79C5002ECAE5 /* reversecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = reversecommand.cpp; sourceTree = ""; }; 7E412F420F8D213C00381DD0 /* libshuff.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = libshuff.h; sourceTree = SOURCE_ROOT; }; 7E412F470F8D21B600381DD0 /* slibshuff.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = slibshuff.h; sourceTree = SOURCE_ROOT; }; 7E412F480F8D21B600381DD0 /* slibshuff.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = slibshuff.cpp; sourceTree = SOURCE_ROOT; }; @@ -732,6 +735,8 @@ 37D928A90F2133E5001D4494 /* commands */ = { isa = PBXGroup; children = ( + 7E09C5120FDA79C5002ECAE5 /* reversecommand.h */, + 7E09C5130FDA79C5002ECAE5 /* reversecommand.cpp */, 37D927CD0F21331F001D4494 /* command.hpp */, 378DC5CD0FBDE1C8003B8607 /* aligncommand.h */, 378DC5CE0FBDE1C8003B8607 /* aligncommand.cpp */, @@ -1091,6 +1096,7 @@ 3799A9500FD6A58C00E33EDE /* distancedb.cpp in Sources */, 3799A9510FD6A58C00E33EDE /* seqsummarycommand.cpp in Sources */, 371B30B40FD7EE67000414CA /* screenseqscommand.cpp in Sources */, + 7E09C5140FDA79C5002ECAE5 /* reversecommand.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/commandfactory.cpp b/commandfactory.cpp index c9a3e6a..a559c81 100644 --- a/commandfactory.cpp +++ b/commandfactory.cpp @@ -47,7 +47,7 @@ #include "getrabundcommand.h" #include "seqsummarycommand.h" #include "screenseqscommand.h" - +#include "reversecommand.h" /***********************************************************/ @@ -105,6 +105,7 @@ Command* CommandFactory::getCommand(string commandName){ else if(commandName == "align.seqs") { command = new AlignCommand(); } else if(commandName == "summary.seqs") { command = new SeqSummaryCommand(); } else if(commandName == "screen.seqs") { command = new ScreenSeqsCommand(); } + else if(commandName == "reverse.seqs") { command = new ReverseSeqsCommand(); } else { command = new NoCommand(); } return command; diff --git a/filterseqscommand.cpp b/filterseqscommand.cpp index e493cbf..e024a24 100644 --- a/filterseqscommand.cpp +++ b/filterseqscommand.cpp @@ -74,7 +74,6 @@ void FilterSeqsCommand::doSoft() { if(keep == 0) { filter[i] = 0; } } - } /**************************************************************************************/ diff --git a/reversecommand.cpp b/reversecommand.cpp new file mode 100644 index 0000000..9be2915 --- /dev/null +++ b/reversecommand.cpp @@ -0,0 +1,69 @@ +/* + * reversecommand.cpp + * Mothur + * + * Created by Pat Schloss on 6/6/09. + * Copyright 2009 Patrick D. Schloss. All rights reserved. + * + */ + +#include "reversecommand.h" +#include "sequence.hpp" + + +//*************************************************************************************************************** + +ReverseSeqsCommand::ReverseSeqsCommand(){ + try { + globaldata = GlobalData::getInstance(); + if(globaldata->getFastaFile() == "") { cout << "you need to at least enter a fasta file name" << endl; } + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the SeqCoordCommand class Function SeqCoordCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the SeqCoordCommand class function SeqCoordCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} + +//*************************************************************************************************************** + +ReverseSeqsCommand::~ReverseSeqsCommand(){ /* do nothing */ } + +//*************************************************************************************************************** + + +int ReverseSeqsCommand::execute(){ + try{ + + ifstream inFASTA; + openInputFile(globaldata->getFastaFile(), inFASTA); + + ofstream outFASTA; + string reverseFile = getRootName(globaldata->getFastaFile()) + "rc" + getExtension(globaldata->getFastaFile()); + openOutputFile(reverseFile, outFASTA); + + while(!inFASTA.eof()){ + Sequence currSeq(inFASTA); + currSeq.reverseComplement(); + currSeq.printSequence(outFASTA); + } + inFASTA.close(); + outFASTA.close(); + + return 0; + + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the FilterSeqsCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the FilterSeqsCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} + +//*************************************************************************************************************** diff --git a/reversecommand.h b/reversecommand.h new file mode 100644 index 0000000..46211a5 --- /dev/null +++ b/reversecommand.h @@ -0,0 +1,28 @@ +#ifndef REVERSECOMMAND_H +#define REVERSECOMMAND_H + +/* + * reversecommand.h + * Mothur + * + * Created by Pat Schloss on 6/6/09. + * Copyright 2009 Patrick D. Schloss. All rights reserved. + * + */ + +#include "mothur.h" +#include "command.hpp" +#include "globaldata.hpp" + +class ReverseSeqsCommand : public Command { +public: + ReverseSeqsCommand(); + ~ReverseSeqsCommand(); + int execute(); + +private: + GlobalData* globaldata; + +}; + +#endif diff --git a/screenseqscommand.cpp b/screenseqscommand.cpp index 0538907..3ad8479 100644 --- a/screenseqscommand.cpp +++ b/screenseqscommand.cpp @@ -48,8 +48,8 @@ int ScreenSeqsCommand::execute(){ set badSeqNames; - string goodSeqFile = getRootName(globaldata->inputFileName) + "good" + getExtension(globaldata->inputFileName); - string badSeqFile = getRootName(globaldata->inputFileName) + "bad" + getExtension(globaldata->inputFileName); + string goodSeqFile = getRootName(globaldata->getFastaFile()) + "good" + getExtension(globaldata->getFastaFile()); + string badSeqFile = getRootName(globaldata->getFastaFile()) + "bad" + getExtension(globaldata->getFastaFile()); ofstream goodSeqOut; openOutputFile(goodSeqFile, goodSeqOut); ofstream badSeqOut; openOutputFile(badSeqFile, badSeqOut); @@ -73,6 +73,12 @@ int ScreenSeqsCommand::execute(){ } gobble(inFASTA); } + if(globaldata->getNameFile() != ""){ + screenNameGroupFile(badSeqNames); + } + else if(globaldata->getGroupFile() != ""){ + screenGroupFile(badSeqNames); + } return 0; } diff --git a/validcommands.cpp b/validcommands.cpp index ec60b3b..a12bacc 100644 --- a/validcommands.cpp +++ b/validcommands.cpp @@ -48,6 +48,7 @@ ValidCommands::ValidCommands() { commands["align.seqs"] = "align.seqs"; commands["summary.seqs"] = "summary.seqs"; commands["screen.seqs"] = "screen.seqs"; + commands["reverse.seqs"] = "reverse.seqs"; commands["quit"] = "quit"; diff --git a/validparameter.cpp b/validparameter.cpp index c8144d0..05cdb1a 100644 --- a/validparameter.cpp +++ b/validparameter.cpp @@ -282,6 +282,9 @@ void ValidParameters::initCommandParameters() { string screenseqsArray[] = {"fasta", "start", "end", "maxambig", "maxhomop", "minlength", "maxlength", "name", "group"}; commandParameters["screen.seqs"] = addParameters(screenseqsArray, sizeof(screenseqsArray)/sizeof(string)); + string reverseseqsArray[] = {"fasta"}; + commandParameters["reverse.seqs"] = addParameters(reverseseqsArray, sizeof(reverseseqsArray)/sizeof(string)); + string vennArray[] = {"groups","line","label","calc"}; commandParameters["venn"] = addParameters(vennArray, sizeof(vennArray)/sizeof(string)); -- 2.39.2