5 * Created by Pat Schloss on 6/6/09.
6 * Copyright 2009 Patrick D. Schloss. All rights reserved.
10 #include "reversecommand.h"
11 #include "sequence.hpp"
14 //***************************************************************************************************************
16 ReverseSeqsCommand::ReverseSeqsCommand(string option){
18 globaldata = GlobalData::getInstance();
21 //allow user to run help
22 if(option == "help") { help(); abort = true; }
25 //valid paramters for this command
26 string Array[] = {"fasta"};
27 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
29 parser = new OptionParser();
30 parser->parse(option, parameters); delete parser;
32 ValidParameters* validParameter = new ValidParameters();
34 //check to make sure all parameters are valid for command
35 for (it = parameters.begin(); it != parameters.end(); it++) {
36 if (validParameter->isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
39 //check for required parameters
40 fasta = validParameter->validFile(parameters, "fasta", true);
41 if (fasta == "not open") { abort = true; }
42 else if (fasta == "not found") { fasta = ""; cout << "fasta is a required parameter for the reverse.seqs command." << endl; abort = true; }
43 else { globaldata->setFastaFile(fasta); globaldata->setFormat("fasta"); }
45 delete validParameter;
49 cout << "Standard Error: " << e.what() << " has occurred in the ReverseSeqsCommand class Function ReverseSeqsCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
53 cout << "An unknown error has occurred in the ReverseSeqsCommand class function ReverseSeqsCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
57 //**********************************************************************************************************************
59 void ReverseSeqsCommand::help(){
61 cout << "The reverse.seqs command reads a fastafile and ...." << "\n";
62 cout << "The reverse.seqs command parameter is fasta and it is required." << "\n";
63 cout << "The reverse.seqs command should be in the following format: " << "\n";
64 cout << "reverse.seqs(fasta=yourFastaFile) " << "\n";
67 cout << "Standard Error: " << e.what() << " has occurred in the ReverseSeqsCommand class Function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
71 cout << "An unknown error has occurred in the ReverseSeqsCommand class function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
76 //***************************************************************************************************************
78 ReverseSeqsCommand::~ReverseSeqsCommand(){ /* do nothing */ }
80 //***************************************************************************************************************
83 int ReverseSeqsCommand::execute(){
86 if (abort == true) { return 0; }
89 openInputFile(fasta, inFASTA);
92 string reverseFile = getRootName(fasta) + "rc" + getExtension(fasta);
93 openOutputFile(reverseFile, outFASTA);
95 while(!inFASTA.eof()){
96 Sequence currSeq(inFASTA);
97 currSeq.reverseComplement();
98 currSeq.printSequence(outFASTA);
106 catch(exception& e) {
107 cout << "Standard Error: " << e.what() << " has occurred in the ReverseSeqsCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
111 cout << "An unknown error has occurred in the ReverseSeqsCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
116 //***************************************************************************************************************