]> git.donarmstrong.com Git - mothur.git/blob - reversecommand.cpp
added reverse.seqs command
[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(){
17         try {
18                 globaldata = GlobalData::getInstance();
19                 if(globaldata->getFastaFile() == "")            {       cout << "you need to at least enter a fasta file name" << endl; }
20         }
21         catch(exception& e) {
22                 cout << "Standard Error: " << e.what() << " has occurred in the SeqCoordCommand class Function SeqCoordCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
23                 exit(1);
24         }
25         catch(...) {
26                 cout << "An unknown error has occurred in the SeqCoordCommand class function SeqCoordCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
27                 exit(1);
28         }       
29 }
30
31 //***************************************************************************************************************
32
33 ReverseSeqsCommand::~ReverseSeqsCommand(){      /*      do nothing      */      }
34
35 //***************************************************************************************************************
36
37
38 int ReverseSeqsCommand::execute(){
39         try{
40                 
41                 ifstream inFASTA;
42                 openInputFile(globaldata->getFastaFile(), inFASTA);
43                 
44                 ofstream outFASTA;
45                 string reverseFile = getRootName(globaldata->getFastaFile()) + "rc" + getExtension(globaldata->getFastaFile());
46                 openOutputFile(reverseFile, outFASTA);
47                 
48                 while(!inFASTA.eof()){
49                         Sequence currSeq(inFASTA);
50                         currSeq.reverseComplement();
51                         currSeq.printSequence(outFASTA);
52                 }
53                 inFASTA.close();
54                 outFASTA.close();
55                 
56                 return 0;
57                 
58         }
59         catch(exception& e) {
60                 cout << "Standard Error: " << e.what() << " has occurred in the FilterSeqsCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
61                 exit(1);
62         }
63         catch(...) {
64                 cout << "An unknown error has occurred in the FilterSeqsCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
65                 exit(1);
66         }
67 }
68
69 //***************************************************************************************************************