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){
20 //allow user to run help
21 if(option == "help") { help(); abort = true; }
24 //valid paramters for this command
25 string Array[] = {"fasta"};
26 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
28 OptionParser parser(option);
29 map<string,string> parameters = parser.getParameters();
31 ValidParameters validParameter;
33 //check to make sure all parameters are valid for command
34 for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
35 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
38 //check for required parameters
39 fasta = validParameter.validFile(parameters, "fasta", true);
40 if (fasta == "not open") { abort = true; }
41 else if (fasta == "not found") { fasta = ""; cout << "fasta is a required parameter for the reverse.seqs command." << endl; abort = true; }
46 cout << "Standard Error: " << e.what() << " has occurred in the ReverseSeqsCommand class Function ReverseSeqsCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
50 cout << "An unknown error has occurred in the ReverseSeqsCommand class function ReverseSeqsCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
54 //**********************************************************************************************************************
56 void ReverseSeqsCommand::help(){
58 cout << "The reverse.seqs command reads a fastafile and ...." << "\n";
59 cout << "The reverse.seqs command parameter is fasta and it is required." << "\n";
60 cout << "The reverse.seqs command should be in the following format: " << "\n";
61 cout << "reverse.seqs(fasta=yourFastaFile) " << "\n";
64 cout << "Standard Error: " << e.what() << " has occurred in the ReverseSeqsCommand class Function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
68 cout << "An unknown error has occurred in the ReverseSeqsCommand class function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
73 //***************************************************************************************************************
75 ReverseSeqsCommand::~ReverseSeqsCommand(){ /* do nothing */ }
77 //***************************************************************************************************************
80 int ReverseSeqsCommand::execute(){
83 if (abort == true) { return 0; }
86 openInputFile(fasta, inFASTA);
89 string reverseFile = getRootName(fasta) + "rc" + getExtension(fasta);
90 openOutputFile(reverseFile, outFASTA);
92 while(!inFASTA.eof()){
93 Sequence currSeq(inFASTA);
94 currSeq.reverseComplement();
95 currSeq.printSequence(outFASTA);
103 catch(exception& e) {
104 cout << "Standard Error: " << e.what() << " has occurred in the ReverseSeqsCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
108 cout << "An unknown error has occurred in the ReverseSeqsCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
113 //***************************************************************************************************************