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 = ""; mothurOut("fasta is a required parameter for the reverse.seqs command."); mothurOutEndLine(); abort = true; }
46 errorOut(e, "ReverseSeqsCommand", "ReverseSeqsCommand");
50 //**********************************************************************************************************************
52 void ReverseSeqsCommand::help(){
54 mothurOut("The reverse.seqs command reads a fastafile and ....\n");
55 mothurOut("The reverse.seqs command parameter is fasta and it is required.\n");
56 mothurOut("The reverse.seqs command should be in the following format: \n");
57 mothurOut("reverse.seqs(fasta=yourFastaFile) \n");
60 errorOut(e, "ReverseSeqsCommand", "help");
65 //***************************************************************************************************************
67 ReverseSeqsCommand::~ReverseSeqsCommand(){ /* do nothing */ }
69 //***************************************************************************************************************
72 int ReverseSeqsCommand::execute(){
75 if (abort == true) { return 0; }
78 openInputFile(fasta, inFASTA);
81 string reverseFile = getRootName(fasta) + "rc" + getExtension(fasta);
82 openOutputFile(reverseFile, outFASTA);
84 while(!inFASTA.eof()){
85 Sequence currSeq(inFASTA);
86 currSeq.reverseComplement();
87 currSeq.printSequence(outFASTA);
96 errorOut(e, "ReverseSeqsCommand", "execute");
101 //***************************************************************************************************************