]> git.donarmstrong.com Git - mothur.git/blob - reversecommand.cpp
added logfile feature
[mothur.git] / reversecommand.cpp
1 /*
2  *  reversecommand.cpp
3  *  Mothur
4  *
5  *  Created by Pat Schloss on 6/6/09.
6  *  Copyright 2009 Patrick D. Schloss. All rights reserved.
7  *
8  */
9
10 #include "reversecommand.h"
11 #include "sequence.hpp"
12
13
14 //***************************************************************************************************************
15
16 ReverseSeqsCommand::ReverseSeqsCommand(string option){
17         try {
18                 abort = false;
19                 
20                 //allow user to run help
21                 if(option == "help") { help(); abort = true; }
22                 
23                 else {
24                         //valid paramters for this command
25                         string Array[] =  {"fasta"};
26                         vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
27                         
28                         OptionParser parser(option);
29                         map<string,string> parameters = parser.getParameters();
30                         
31                         ValidParameters validParameter;
32                 
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;  }
36                         }
37                         
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;  }     
42                         
43                 }
44         }
45         catch(exception& e) {
46                 errorOut(e, "ReverseSeqsCommand", "ReverseSeqsCommand");
47                 exit(1);
48         }
49 }
50 //**********************************************************************************************************************
51
52 void ReverseSeqsCommand::help(){
53         try {
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");      
58         }
59         catch(exception& e) {
60                 errorOut(e, "ReverseSeqsCommand", "help");
61                 exit(1);
62         }
63 }
64
65 //***************************************************************************************************************
66
67 ReverseSeqsCommand::~ReverseSeqsCommand(){      /*      do nothing      */      }
68
69 //***************************************************************************************************************
70
71
72 int ReverseSeqsCommand::execute(){
73         try{
74                 
75                 if (abort == true) { return 0; }
76                 
77                 ifstream inFASTA;
78                 openInputFile(fasta, inFASTA);
79                 
80                 ofstream outFASTA;
81                 string reverseFile = getRootName(fasta) + "rc" + getExtension(fasta);
82                 openOutputFile(reverseFile, outFASTA);
83                 
84                 while(!inFASTA.eof()){
85                         Sequence currSeq(inFASTA);
86                         currSeq.reverseComplement();
87                         currSeq.printSequence(outFASTA);
88                 }
89                 inFASTA.close();
90                 outFASTA.close();
91                 
92                 return 0;
93                 
94         }
95         catch(exception& e) {
96                 errorOut(e, "ReverseSeqsCommand", "execute");
97                 exit(1);
98         }
99 }
100
101 //***************************************************************************************************************